csettingsview_moc.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. /*
  2. * csettingsview_moc.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "csettingsview_moc.h"
  12. #include "ui_csettingsview_moc.h"
  13. #include "mainwindow_moc.h"
  14. #include "configeditordialog_moc.h"
  15. #include "../modManager/cmodlistview_moc.h"
  16. #include "../helper.h"
  17. #include "../vcmiqt/jsonutils.h"
  18. #include "../languages.h"
  19. #include <QFileInfo>
  20. #include <QGuiApplication>
  21. #include "../../lib/CConfigHandler.h"
  22. #ifndef VCMI_MOBILE
  23. #include <SDL2/SDL.h>
  24. #endif
  25. static QString resolutionToString(const QSize & resolution)
  26. {
  27. return QString{"%1x%2"}.arg(resolution.width()).arg(resolution.height());
  28. }
  29. static constexpr std::array cursorTypesList =
  30. {
  31. "hardware",
  32. "software"
  33. };
  34. static constexpr std::array upscalingFilterTypes =
  35. {
  36. "auto",
  37. "none",
  38. "xbrz2",
  39. "xbrz3",
  40. "xbrz4"
  41. };
  42. static constexpr std::array downscalingFilterTypes =
  43. {
  44. "nearest",
  45. "linear",
  46. "best"
  47. };
  48. void CSettingsView::setDisplayList()
  49. {
  50. QStringList list;
  51. for (const auto screen : QGuiApplication::screens())
  52. list << QString{"%1 - %2"}.arg(screen->name(), resolutionToString(screen->size()));
  53. if(list.count() < 2)
  54. {
  55. ui->comboBoxDisplayIndex->hide();
  56. ui->labelDisplayIndex->hide();
  57. fillValidResolutionsForScreen(0);
  58. }
  59. else
  60. {
  61. int displayIndex = settings["video"]["displayIndex"].Integer();
  62. ui->comboBoxDisplayIndex->addItems(list);
  63. // calls fillValidResolutions() in slot
  64. ui->comboBoxDisplayIndex->setCurrentIndex(displayIndex);
  65. }
  66. }
  67. void CSettingsView::setCheckbuttonState(QToolButton * button, bool checked)
  68. {
  69. button->setChecked(checked);
  70. updateCheckbuttonText(button);
  71. }
  72. void CSettingsView::updateCheckbuttonText(QToolButton * button)
  73. {
  74. if (button->isChecked())
  75. button->setText(tr("On"));
  76. else
  77. button->setText(tr("Off"));
  78. }
  79. void CSettingsView::loadSettings()
  80. {
  81. #ifdef VCMI_MOBILE
  82. ui->comboBoxFullScreen->hide();
  83. ui->labelFullScreen->hide();
  84. if(!persistentStorage["gui"]["tutorialCompleted0"].Bool() && !persistentStorage["gui"]["tutorialCompleted1"].Bool())
  85. {
  86. ui->labelResetTutorialTouchscreen->hide();
  87. ui->pushButtonResetTutorialTouchscreen->hide();
  88. }
  89. #else
  90. ui->labelReservedArea->hide();
  91. ui->sliderReservedArea->hide();
  92. ui->labelRelativeCursorMode->hide();
  93. ui->buttonRelativeCursorMode->hide();
  94. ui->sliderRelativeCursorSpeed->hide();
  95. ui->labelRelativeCursorSpeed->hide();
  96. ui->buttonHapticFeedback->hide();
  97. ui->labelHapticFeedback->hide();
  98. ui->labelResetTutorialTouchscreen->hide();
  99. ui->pushButtonResetTutorialTouchscreen->hide();
  100. if (settings["video"]["realFullscreen"].Bool())
  101. ui->comboBoxFullScreen->setCurrentIndex(2);
  102. else
  103. ui->comboBoxFullScreen->setCurrentIndex(settings["video"]["fullscreen"].Bool());
  104. #endif
  105. #ifndef VCMI_ANDROID
  106. ui->buttonHandleBackRightMouseButton->hide();
  107. ui->labelHandleBackRightMouseButton->hide();
  108. ui->buttonAllowPortrait->hide();
  109. ui->labelAllowPortrait->hide();
  110. #endif
  111. #ifndef VCMI_IOS
  112. ui->labelIgnoreMuteSwitch->hide();
  113. ui->buttonIgnoreMuteSwitch->hide();
  114. #endif
  115. fillValidScalingRange();
  116. ui->buttonScalingAuto->setChecked(settings["video"]["resolution"]["scaling"].Integer() == 0);
  117. if (settings["video"]["resolution"]["scaling"].Integer() == 0)
  118. ui->spinBoxInterfaceScaling->setValue(100);
  119. else
  120. ui->spinBoxInterfaceScaling->setValue(settings["video"]["resolution"]["scaling"].Float());
  121. ui->spinBoxFramerateLimit->setValue(settings["video"]["targetfps"].Float());
  122. ui->spinBoxFramerateLimit->setDisabled(settings["video"]["vsync"].Bool());
  123. ui->sliderReservedArea->setValue(std::round(settings["video"]["reservedWidth"].Float() * 100));
  124. ui->comboBoxFriendlyAI->setCurrentText(QString::fromStdString(settings["server"]["friendlyAI"].String()));
  125. ui->comboBoxNeutralAI->setCurrentText(QString::fromStdString(settings["server"]["neutralAI"].String()));
  126. ui->comboBoxEnemyAI->setCurrentText(QString::fromStdString(settings["server"]["enemyAI"].String()));
  127. ui->comboBoxEnemyPlayerAI->setCurrentText(QString::fromStdString(settings["server"]["playerAI"].String()));
  128. ui->comboBoxAlliedPlayerAI->setCurrentText(QString::fromStdString(settings["server"]["alliedAI"].String()));
  129. ui->spinBoxNetworkPort->setValue(settings["server"]["localPort"].Integer());
  130. ui->lineEditRepositoryDefault->setText(QString::fromStdString(settings["launcher"]["defaultRepositoryURL"].String()));
  131. ui->lineEditRepositoryExtra->setText(QString::fromStdString(settings["launcher"]["extraRepositoryURL"].String()));
  132. ui->lineEditRepositoryDefault->setEnabled(settings["launcher"]["defaultRepositoryEnabled"].Bool());
  133. ui->lineEditRepositoryExtra->setEnabled(settings["launcher"]["extraRepositoryEnabled"].Bool());
  134. ui->spinBoxAutoSaveLimit->setValue(settings["general"]["autosaveCountLimit"].Integer());
  135. ui->lineEditAutoSavePrefix->setText(QString::fromStdString(settings["general"]["savePrefix"].String()));
  136. ui->lineEditAutoSavePrefix->setEnabled(settings["general"]["useSavePrefix"].Bool());
  137. Languages::fillLanguages(ui->comboBoxLanguage, false);
  138. fillValidRenderers();
  139. std::string upscalingFilter = settings["video"]["upscalingFilter"].String();
  140. int upscalingFilterIndex = vstd::find_pos(upscalingFilterTypes, upscalingFilter);
  141. ui->comboBoxUpscalingFilter->setCurrentIndex(upscalingFilterIndex);
  142. std::string downscalingFilter = settings["video"]["downscalingFilter"].String();
  143. int downscalingFilterIndex = vstd::find_pos(downscalingFilterTypes, downscalingFilter);
  144. ui->comboBoxDownscalingFilter->setCurrentIndex(downscalingFilterIndex);
  145. ui->sliderMusicVolume->setValue(settings["general"]["music"].Integer());
  146. ui->sliderSoundVolume->setValue(settings["general"]["sound"].Integer());
  147. ui->sliderRelativeCursorSpeed->setValue(settings["general"]["relativePointerSpeedMultiplier"].Integer());
  148. ui->sliderLongTouchDuration->setValue(settings["general"]["longTouchTimeMilliseconds"].Integer());
  149. ui->slideToleranceDistanceMouse->setValue(settings["input"]["mouseToleranceDistance"].Integer());
  150. ui->buttonHandleBackRightMouseButton->setChecked(settings["input"]["handleBackRightMouseButton"].Bool());
  151. ui->sliderToleranceDistanceTouch->setValue(settings["input"]["touchToleranceDistance"].Integer());
  152. ui->sliderToleranceDistanceController->setValue(settings["input"]["shortcutToleranceDistance"].Integer());
  153. ui->sliderControllerSticksSensitivity->setValue(settings["input"]["controllerAxisSpeed"].Integer());
  154. ui->sliderControllerSticksAcceleration->setValue(settings["input"]["controllerAxisScale"].Float() * 100);
  155. ui->lineEditGameLobbyHost->setText(QString::fromStdString(settings["lobby"]["hostname"].String()));
  156. ui->spinBoxNetworkPortLobby->setValue(settings["lobby"]["port"].Integer());
  157. ui->buttonVSync->setChecked(settings["video"]["vsync"].Bool());
  158. if (settings["video"]["fontsType"].String() == "auto")
  159. ui->buttonFontAuto->setChecked(true);
  160. else if (settings["video"]["fontsType"].String() == "original")
  161. ui->buttonFontOriginal->setChecked(true);
  162. else
  163. ui->buttonFontScalable->setChecked(true);
  164. if (settings["mods"]["validation"].String() == "off")
  165. ui->buttonValidationOff->setChecked(true);
  166. else if (settings["mods"]["validation"].String() == "basic")
  167. ui->buttonValidationBasic->setChecked(true);
  168. else
  169. ui->buttonValidationFull->setChecked(true);
  170. loadToggleButtonSettings();
  171. }
  172. void CSettingsView::loadToggleButtonSettings()
  173. {
  174. setCheckbuttonState(ui->buttonShowIntro, settings["video"]["showIntro"].Bool());
  175. setCheckbuttonState(ui->buttonAllowPortrait, settings["video"]["allowPortrait"].Bool());
  176. setCheckbuttonState(ui->buttonAutoCheck, settings["launcher"]["autoCheckRepositories"].Bool());
  177. setCheckbuttonState(ui->buttonRepositoryDefault, settings["launcher"]["defaultRepositoryEnabled"].Bool());
  178. setCheckbuttonState(ui->buttonRepositoryExtra, settings["launcher"]["extraRepositoryEnabled"].Bool());
  179. setCheckbuttonState(ui->buttonIgnoreSslErrors, settings["launcher"]["ignoreSslErrors"].Bool());
  180. setCheckbuttonState(ui->buttonAutoSave, settings["general"]["saveFrequency"].Integer() > 0);
  181. setCheckbuttonState(ui->buttonAutoSavePrefix, settings["general"]["useSavePrefix"].Bool());
  182. setCheckbuttonState(ui->buttonRelativeCursorMode, settings["general"]["userRelativePointer"].Bool());
  183. setCheckbuttonState(ui->buttonHapticFeedback, settings["general"]["hapticFeedback"].Bool());
  184. setCheckbuttonState(ui->buttonHandleBackRightMouseButton, settings["input"]["handleBackRightMouseButton"].Bool());
  185. setCheckbuttonState(ui->buttonIgnoreMuteSwitch, settings["general"]["ignoreMuteSwitch"].Bool());
  186. std::string cursorType = settings["video"]["cursor"].String();
  187. int cursorTypeIndex = vstd::find_pos(cursorTypesList, cursorType);
  188. setCheckbuttonState(ui->buttonCursorType, cursorTypeIndex);
  189. ui->sliderScalingCursor->setDisabled(cursorType == "software"); // Not supported
  190. ui->labelScalingCursorValue->setDisabled(cursorType == "software"); // Not supported
  191. int fontScalingPercentage = settings["video"]["fontScalingFactor"].Float() * 100;
  192. ui->sliderScalingFont->setValue(fontScalingPercentage / 5);
  193. int cursorScalingPercentage = settings["video"]["cursorScalingFactor"].Float() * 100;
  194. ui->sliderScalingCursor->setValue(cursorScalingPercentage / 5);
  195. }
  196. void CSettingsView::fillValidResolutions()
  197. {
  198. fillValidResolutionsForScreen(ui->comboBoxDisplayIndex->isVisible() ? ui->comboBoxDisplayIndex->currentIndex() : 0);
  199. }
  200. QSize CSettingsView::getPreferredRenderingResolution()
  201. {
  202. #ifndef VCMI_MOBILE
  203. bool fullscreen = settings["video"]["fullscreen"].Bool();
  204. bool realFullscreen = settings["video"]["realFullscreen"].Bool();
  205. if (!fullscreen || realFullscreen)
  206. {
  207. int resX = settings["video"]["resolution"]["width"].Integer();
  208. int resY = settings["video"]["resolution"]["height"].Integer();
  209. return QSize(resX, resY);
  210. }
  211. #endif
  212. return QApplication::primaryScreen()->geometry().size() * QApplication::primaryScreen()->devicePixelRatio();
  213. }
  214. void CSettingsView::fillValidScalingRange()
  215. {
  216. //FIXME: this code is copy of ScreenHandler::getSupportedScalingRange
  217. // H3 resolution, any resolution smaller than that is not correctly supported
  218. static const QSize minResolution = {800, 600};
  219. // arbitrary limit on *downscaling*. Allow some downscaling, if requested by user. Should be generally limited to 100+ for all but few devices
  220. static const double minimalScaling = 50;
  221. QSize renderResolution = getPreferredRenderingResolution();
  222. double maximalScalingWidth = 100.0 * renderResolution.width() / minResolution.width();
  223. double maximalScalingHeight = 100.0 * renderResolution.height() / minResolution.height();
  224. double maximalScaling = std::min(maximalScalingWidth, maximalScalingHeight);
  225. ui->spinBoxInterfaceScaling->setRange(minimalScaling, maximalScaling);
  226. }
  227. #ifndef VCMI_MOBILE
  228. static QStringList getAvailableRenderingDrivers()
  229. {
  230. SDL_Init(SDL_INIT_VIDEO);
  231. QStringList result;
  232. result += QString(); // empty value for autoselection
  233. int driversCount = SDL_GetNumRenderDrivers();
  234. for(int it = 0; it < driversCount; it++)
  235. {
  236. SDL_RendererInfo info;
  237. if (SDL_GetRenderDriverInfo(it, &info) == 0)
  238. result += QString::fromLatin1(info.name);
  239. }
  240. SDL_Quit();
  241. return result;
  242. }
  243. static QVector<QSize> findAvailableResolutions(int displayIndex)
  244. {
  245. // Ugly workaround since we don't actually need SDL in Launcher
  246. // However Qt at the moment provides no way to query list of available resolutions
  247. QVector<QSize> result;
  248. SDL_Init(SDL_INIT_VIDEO);
  249. int modesCount = SDL_GetNumDisplayModes(displayIndex);
  250. for (int i =0; i < modesCount; ++i)
  251. {
  252. SDL_DisplayMode mode;
  253. if (SDL_GetDisplayMode(displayIndex, i, &mode) != 0)
  254. continue;
  255. QSize resolution(mode.w, mode.h);
  256. result.push_back(resolution);
  257. }
  258. boost::range::sort(result, [](const auto & left, const auto & right)
  259. {
  260. return left.height() * left.width() < right.height() * right.width();
  261. });
  262. result.erase(boost::unique(result).end(), result.end());
  263. SDL_Quit();
  264. return result;
  265. }
  266. void CSettingsView::fillValidResolutionsForScreen(int screenIndex)
  267. {
  268. QSignalBlocker guard(ui->comboBoxResolution); // avoid saving wrong resolution after adding first item from the list
  269. ui->comboBoxResolution->clear();
  270. bool fullscreen = settings["video"]["fullscreen"].Bool();
  271. bool realFullscreen = settings["video"]["realFullscreen"].Bool();
  272. if (!fullscreen || realFullscreen)
  273. {
  274. QVector<QSize> resolutions = findAvailableResolutions(screenIndex);
  275. for(const auto & entry : resolutions)
  276. ui->comboBoxResolution->addItem(resolutionToString(entry));
  277. }
  278. else
  279. {
  280. ui->comboBoxResolution->addItem(resolutionToString(getPreferredRenderingResolution()));
  281. }
  282. ui->comboBoxResolution->setEnabled(ui->comboBoxResolution->count() > 1);
  283. int resX = settings["video"]["resolution"]["width"].Integer();
  284. int resY = settings["video"]["resolution"]["height"].Integer();
  285. int resIndex = ui->comboBoxResolution->findText(resolutionToString({resX, resY}));
  286. ui->comboBoxResolution->setCurrentIndex(resIndex);
  287. // if selected resolution no longer exists, force update value to the largest (last) resolution
  288. if(resIndex == -1)
  289. ui->comboBoxResolution->setCurrentIndex(ui->comboBoxResolution->count() - 1);
  290. }
  291. void CSettingsView::fillValidRenderers()
  292. {
  293. QSignalBlocker guard(ui->comboBoxRendererType); // avoid saving wrong renderer after adding first item from the list
  294. ui->comboBoxRendererType->clear();
  295. auto driversList = getAvailableRenderingDrivers();
  296. ui->comboBoxRendererType->addItems(driversList);
  297. std::string rendererName = settings["video"]["driver"].String();
  298. int index = ui->comboBoxRendererType->findText(QString::fromStdString(rendererName));
  299. ui->comboBoxRendererType->setCurrentIndex(index);
  300. }
  301. #else
  302. void CSettingsView::fillValidResolutionsForScreen(int screenIndex)
  303. {
  304. // resolutions are not selectable on mobile platforms
  305. ui->comboBoxResolution->hide();
  306. ui->labelResolution->hide();
  307. }
  308. void CSettingsView::fillValidRenderers()
  309. {
  310. // untested on mobile platforms
  311. ui->comboBoxRendererType->hide();
  312. ui->labelRendererType->hide();
  313. }
  314. #endif
  315. CSettingsView::CSettingsView(QWidget * parent)
  316. : QWidget(parent), ui(new Ui::CSettingsView)
  317. {
  318. ui->setupUi(this);
  319. Helper::enableScrollBySwiping(ui->settingsScrollArea);
  320. loadSettings();
  321. }
  322. CSettingsView::~CSettingsView()
  323. {
  324. delete ui;
  325. }
  326. void CSettingsView::on_comboBoxResolution_currentTextChanged(const QString & arg1)
  327. {
  328. QStringList list = arg1.split("x");
  329. Settings node = settings.write["video"]["resolution"];
  330. node["width"].Float() = list[0].toInt();
  331. node["height"].Float() = list[1].toInt();
  332. fillValidResolutions();
  333. fillValidScalingRange();
  334. }
  335. void CSettingsView::on_comboBoxFullScreen_currentIndexChanged(int index)
  336. {
  337. Settings nodeFullscreen = settings.write["video"]["fullscreen"];
  338. Settings nodeRealFullscreen = settings.write["video"]["realFullscreen"];
  339. nodeFullscreen->Bool() = (index != 0);
  340. nodeRealFullscreen->Bool() = (index == 2);
  341. fillValidResolutions();
  342. fillValidScalingRange();
  343. }
  344. void CSettingsView::on_buttonAutoCheck_toggled(bool value)
  345. {
  346. Settings node = settings.write["launcher"]["autoCheckRepositories"];
  347. node->Bool() = value;
  348. updateCheckbuttonText(ui->buttonAutoCheck);
  349. }
  350. void CSettingsView::on_comboBoxDisplayIndex_currentIndexChanged(int index)
  351. {
  352. Settings node = settings.write["video"];
  353. node["displayIndex"].Float() = index;
  354. fillValidResolutionsForScreen(index);
  355. }
  356. void CSettingsView::on_comboBoxFriendlyAI_currentTextChanged(const QString & arg1)
  357. {
  358. Settings node = settings.write["server"]["friendlyAI"];
  359. node->String() = arg1.toUtf8().data();
  360. }
  361. void CSettingsView::on_comboBoxNeutralAI_currentTextChanged(const QString & arg1)
  362. {
  363. Settings node = settings.write["server"]["neutralAI"];
  364. node->String() = arg1.toUtf8().data();
  365. }
  366. void CSettingsView::on_comboBoxEnemyAI_currentTextChanged(const QString & arg1)
  367. {
  368. Settings node = settings.write["server"]["enemyAI"];
  369. node->String() = arg1.toUtf8().data();
  370. }
  371. void CSettingsView::on_spinBoxNetworkPort_valueChanged(int arg1)
  372. {
  373. Settings node = settings.write["server"]["port"];
  374. node->Float() = arg1;
  375. }
  376. void CSettingsView::on_buttonShowIntro_toggled(bool value)
  377. {
  378. Settings node = settings.write["video"]["showIntro"];
  379. node->Bool() = value;
  380. updateCheckbuttonText(ui->buttonShowIntro);
  381. }
  382. void CSettingsView::on_buttonAllowPortrait_toggled(bool value)
  383. {
  384. Settings node = settings.write["video"]["allowPortrait"];
  385. node->Bool() = value;
  386. updateCheckbuttonText(ui->buttonAllowPortrait);
  387. }
  388. void CSettingsView::on_buttonAutoSave_toggled(bool value)
  389. {
  390. Settings node = settings.write["general"]["saveFrequency"];
  391. node->Integer() = value ? 1 : 0;
  392. updateCheckbuttonText(ui->buttonAutoSave);
  393. }
  394. void CSettingsView::on_comboBoxLanguage_currentIndexChanged(int index)
  395. {
  396. Settings node = settings.write["general"]["language"];
  397. QString selectedLanguage = ui->comboBoxLanguage->itemData(index).toString();
  398. node->String() = selectedLanguage.toStdString();
  399. Helper::getMainWindow()->updateTranslation();
  400. }
  401. void CSettingsView::changeEvent(QEvent *event)
  402. {
  403. if(event->type() == QEvent::LanguageChange)
  404. {
  405. ui->retranslateUi(this);
  406. Languages::fillLanguages(ui->comboBoxLanguage, false);
  407. loadTranslation();
  408. loadToggleButtonSettings();
  409. }
  410. QWidget::changeEvent(event);
  411. }
  412. void CSettingsView::showEvent(QShowEvent * event)
  413. {
  414. loadTranslation();
  415. QWidget::showEvent(event);
  416. }
  417. void CSettingsView::on_buttonCursorType_toggled(bool value)
  418. {
  419. Settings node = settings.write["video"]["cursor"];
  420. node->String() = cursorTypesList[value ? 1 : 0];
  421. updateCheckbuttonText(ui->buttonCursorType);
  422. ui->sliderScalingCursor->setDisabled(value == 1); // Not supported
  423. ui->labelScalingCursorValue->setDisabled(value == 1); // Not supported
  424. }
  425. void CSettingsView::loadTranslation()
  426. {
  427. QString baseLanguage = Languages::getHeroesDataLanguage();
  428. auto * mainWindow = Helper::getMainWindow();
  429. if (!mainWindow)
  430. return;
  431. auto translationStatus = mainWindow->getTranslationStatus();
  432. bool showTranslation = translationStatus == ETranslationStatus::DISABLED || translationStatus == ETranslationStatus::NOT_INSTALLLED;
  433. ui->labelTranslation->setVisible(showTranslation);
  434. ui->labelTranslationStatus->setVisible(showTranslation);
  435. ui->pushButtonTranslation->setVisible(showTranslation);
  436. ui->pushButtonTranslation->setVisible(translationStatus != ETranslationStatus::ACTIVE);
  437. if (translationStatus == ETranslationStatus::ACTIVE)
  438. {
  439. ui->labelTranslationStatus->setText(tr("Active"));
  440. }
  441. if (translationStatus == ETranslationStatus::DISABLED)
  442. {
  443. ui->labelTranslationStatus->setText(tr("Disabled"));
  444. ui->pushButtonTranslation->setText(tr("Enable"));
  445. }
  446. if (translationStatus == ETranslationStatus::NOT_INSTALLLED)
  447. {
  448. ui->labelTranslationStatus->setText(tr("Not Installed"));
  449. ui->pushButtonTranslation->setText(tr("Install"));
  450. }
  451. }
  452. void CSettingsView::on_pushButtonTranslation_clicked()
  453. {
  454. auto * mainWindow = Helper::getMainWindow();
  455. assert(mainWindow);
  456. if (!mainWindow)
  457. return;
  458. QString languageName = QString::fromStdString(settings["general"]["language"].String());
  459. QString modName = mainWindow->getModView()->getTranslationModName(languageName);
  460. assert(!modName.isEmpty());
  461. if (modName.isEmpty())
  462. return;
  463. if (mainWindow->getModView()->isModAvailable(modName))
  464. {
  465. mainWindow->switchToModsTab();
  466. mainWindow->getModView()->doInstallMod(modName);
  467. }
  468. else
  469. {
  470. mainWindow->getModView()->enableModByName(modName);
  471. }
  472. }
  473. void CSettingsView::on_pushButtonResetTutorialTouchscreen_clicked()
  474. {
  475. Settings node0 = persistentStorage.write["gui"]["tutorialCompleted0"];
  476. node0->Bool() = false;
  477. Settings node1 = persistentStorage.write["gui"]["tutorialCompleted1"];
  478. node1->Bool() = false;
  479. ui->pushButtonResetTutorialTouchscreen->hide();
  480. }
  481. void CSettingsView::on_buttonRepositoryDefault_toggled(bool value)
  482. {
  483. Settings node = settings.write["launcher"]["defaultRepositoryEnabled"];
  484. node->Bool() = value;
  485. ui->lineEditRepositoryDefault->setEnabled(value);
  486. updateCheckbuttonText(ui->buttonRepositoryDefault);
  487. }
  488. void CSettingsView::on_buttonRepositoryExtra_toggled(bool value)
  489. {
  490. Settings node = settings.write["launcher"]["extraRepositoryEnabled"];
  491. node->Bool() = value;
  492. ui->lineEditRepositoryExtra->setEnabled(value);
  493. updateCheckbuttonText(ui->buttonRepositoryExtra);
  494. }
  495. void CSettingsView::on_lineEditRepositoryExtra_textEdited(const QString &arg1)
  496. {
  497. Settings node = settings.write["launcher"]["extraRepositoryURL"];
  498. node->String() = arg1.toStdString();
  499. }
  500. void CSettingsView::on_spinBoxInterfaceScaling_valueChanged(int arg1)
  501. {
  502. Settings node = settings.write["video"]["resolution"]["scaling"];
  503. node->Float() = ui->buttonScalingAuto->isChecked() ? 0 : arg1;
  504. }
  505. void CSettingsView::on_refreshRepositoriesButton_clicked()
  506. {
  507. auto * mainWindow = Helper::getMainWindow();
  508. assert(mainWindow);
  509. if (!mainWindow)
  510. return;
  511. mainWindow->getModView()->loadRepositories();
  512. }
  513. void CSettingsView::on_buttonConfigEditor_clicked()
  514. {
  515. ConfigEditorDialog::showConfigEditorDialog();
  516. }
  517. void CSettingsView::on_spinBoxFramerateLimit_valueChanged(int arg1)
  518. {
  519. Settings node = settings.write["video"]["targetfps"];
  520. node->Float() = arg1;
  521. }
  522. void CSettingsView::on_buttonVSync_toggled(bool value)
  523. {
  524. Settings node = settings.write["video"]["vsync"];
  525. node->Bool() = value;
  526. ui->spinBoxFramerateLimit->setDisabled(settings["video"]["vsync"].Bool());
  527. }
  528. void CSettingsView::on_comboBoxEnemyPlayerAI_currentTextChanged(const QString &arg1)
  529. {
  530. Settings node = settings.write["server"]["playerAI"];
  531. node->String() = arg1.toUtf8().data();
  532. }
  533. void CSettingsView::on_comboBoxAlliedPlayerAI_currentTextChanged(const QString &arg1)
  534. {
  535. Settings node = settings.write["server"]["alliedAI"];
  536. node->String() = arg1.toUtf8().data();
  537. }
  538. void CSettingsView::on_buttonAutoSavePrefix_toggled(bool value)
  539. {
  540. Settings node = settings.write["general"]["useSavePrefix"];
  541. node->Bool() = value;
  542. ui->lineEditAutoSavePrefix->setEnabled(value);
  543. updateCheckbuttonText(ui->buttonAutoSavePrefix);
  544. }
  545. void CSettingsView::on_spinBoxAutoSaveLimit_valueChanged(int arg1)
  546. {
  547. Settings node = settings.write["general"]["autosaveCountLimit"];
  548. node->Float() = arg1;
  549. }
  550. void CSettingsView::on_lineEditAutoSavePrefix_textEdited(const QString & arg1)
  551. {
  552. Settings node = settings.write["general"]["savePrefix"];
  553. node->String() = arg1.toStdString();
  554. }
  555. void CSettingsView::on_sliderReservedArea_valueChanged(int arg1)
  556. {
  557. Settings node = settings.write["video"]["reservedWidth"];
  558. node->Float() = float(arg1) / 100; // percentage -> ratio
  559. }
  560. void CSettingsView::on_comboBoxRendererType_currentTextChanged(const QString &arg1)
  561. {
  562. Settings node = settings.write["video"]["driver"];
  563. node->String() = arg1.toStdString();
  564. }
  565. void CSettingsView::on_buttonIgnoreSslErrors_clicked(bool checked)
  566. {
  567. Settings node = settings.write["launcher"]["ignoreSslErrors"];
  568. node->Bool() = checked;
  569. updateCheckbuttonText(ui->buttonIgnoreSslErrors);
  570. }
  571. void CSettingsView::on_comboBoxUpscalingFilter_currentIndexChanged(int index)
  572. {
  573. Settings node = settings.write["video"]["upscalingFilter"];
  574. node->String() = upscalingFilterTypes[index];
  575. }
  576. void CSettingsView::on_comboBoxDownscalingFilter_currentIndexChanged(int index)
  577. {
  578. Settings node = settings.write["video"]["downscalingFilter"];
  579. node->String() = downscalingFilterTypes[index];
  580. }
  581. void CSettingsView::on_sliderMusicVolume_valueChanged(int value)
  582. {
  583. Settings node = settings.write["general"]["music"];
  584. node->Integer() = value;
  585. }
  586. void CSettingsView::on_sliderSoundVolume_valueChanged(int value)
  587. {
  588. Settings node = settings.write["general"]["sound"];
  589. node->Integer() = value;
  590. }
  591. void CSettingsView::on_buttonRelativeCursorMode_toggled(bool value)
  592. {
  593. Settings node = settings.write["general"]["userRelativePointer"];
  594. node->Bool() = value;
  595. updateCheckbuttonText(ui->buttonRelativeCursorMode);
  596. }
  597. void CSettingsView::on_sliderRelativeCursorSpeed_valueChanged(int value)
  598. {
  599. Settings node = settings.write["general"]["relativePointerSpeedMultiplier"];
  600. node->Float() = value / 100.0;
  601. }
  602. void CSettingsView::on_buttonHapticFeedback_toggled(bool value)
  603. {
  604. Settings node = settings.write["general"]["hapticFeedback"];
  605. node->Bool() = value;
  606. updateCheckbuttonText(ui->buttonHapticFeedback);
  607. }
  608. void CSettingsView::on_sliderLongTouchDuration_valueChanged(int value)
  609. {
  610. Settings node = settings.write["general"]["longTouchTimeMilliseconds"];
  611. node->Integer() = value;
  612. }
  613. void CSettingsView::on_slideToleranceDistanceMouse_valueChanged(int value)
  614. {
  615. Settings node = settings.write["input"]["mouseToleranceDistance"];
  616. node->Integer() = value;
  617. }
  618. void CSettingsView::on_sliderToleranceDistanceTouch_valueChanged(int value)
  619. {
  620. Settings node = settings.write["input"]["touchToleranceDistance"];
  621. node->Integer() = value;
  622. }
  623. void CSettingsView::on_sliderToleranceDistanceController_valueChanged(int value)
  624. {
  625. Settings node = settings.write["input"]["shortcutToleranceDistance"];
  626. node->Integer() = value;
  627. }
  628. void CSettingsView::on_lineEditGameLobbyHost_textChanged(const QString & arg1)
  629. {
  630. Settings node = settings.write["lobby"]["hostname"];
  631. node->String() = arg1.toStdString();
  632. }
  633. void CSettingsView::on_spinBoxNetworkPortLobby_valueChanged(int arg1)
  634. {
  635. Settings node = settings.write["lobby"]["port"];
  636. node->Integer() = arg1;
  637. }
  638. void CSettingsView::on_sliderControllerSticksAcceleration_valueChanged(int value)
  639. {
  640. Settings node = settings.write["input"]["controllerAxisScale"];
  641. node->Integer() = value / 100.0;
  642. }
  643. void CSettingsView::on_sliderControllerSticksSensitivity_valueChanged(int value)
  644. {
  645. Settings node = settings.write["input"]["controllerAxisSpeed"];
  646. node->Integer() = value;
  647. }
  648. void CSettingsView::on_sliderScalingFont_valueChanged(int value)
  649. {
  650. int actualValuePercentage = value * 5;
  651. ui->labelScalingFontValue->setText(QString("%1%").arg(actualValuePercentage));
  652. Settings node = settings.write["video"]["fontScalingFactor"];
  653. node->Float() = actualValuePercentage / 100.0;
  654. }
  655. void CSettingsView::on_buttonFontAuto_clicked(bool checked)
  656. {
  657. Settings node = settings.write["video"]["fontsType"];
  658. node->String() = "auto";
  659. }
  660. void CSettingsView::on_buttonFontScalable_clicked(bool checked)
  661. {
  662. Settings node = settings.write["video"]["fontsType"];
  663. node->String() = "scalable";
  664. }
  665. void CSettingsView::on_buttonFontOriginal_clicked(bool checked)
  666. {
  667. Settings node = settings.write["video"]["fontsType"];
  668. node->String() = "original";
  669. }
  670. void CSettingsView::on_buttonValidationOff_clicked(bool checked)
  671. {
  672. Settings node = settings.write["mods"]["validation"];
  673. node->String() = "off";
  674. }
  675. void CSettingsView::on_buttonValidationBasic_clicked(bool checked)
  676. {
  677. Settings node = settings.write["mods"]["validation"];
  678. node->String() = "basic";
  679. }
  680. void CSettingsView::on_buttonValidationFull_clicked(bool checked)
  681. {
  682. Settings node = settings.write["mods"]["validation"];
  683. node->String() = "full";
  684. }
  685. void CSettingsView::on_sliderScalingCursor_valueChanged(int value)
  686. {
  687. int actualValuePercentage = value * 5;
  688. ui->labelScalingCursorValue->setText(QString("%1%").arg(actualValuePercentage));
  689. Settings node = settings.write["video"]["cursorScalingFactor"];
  690. node->Float() = actualValuePercentage / 100.0;
  691. }
  692. void CSettingsView::on_buttonScalingAuto_toggled(bool checked)
  693. {
  694. if (checked)
  695. {
  696. ui->spinBoxInterfaceScaling->hide();
  697. }
  698. else
  699. {
  700. ui->spinBoxInterfaceScaling->show();
  701. ui->spinBoxInterfaceScaling->setValue(100);
  702. }
  703. Settings node = settings.write["video"]["resolution"]["scaling"];
  704. node->Integer() = checked ? 0 : 100;
  705. }
  706. void CSettingsView::on_buttonHandleBackRightMouseButton_toggled(bool checked)
  707. {
  708. Settings node = settings.write["input"]["handleBackRightMouseButton"];
  709. node->Bool() = checked;
  710. updateCheckbuttonText(ui->buttonHandleBackRightMouseButton);
  711. }
  712. void CSettingsView::on_buttonIgnoreMuteSwitch_toggled(bool checked)
  713. {
  714. Settings node = settings.write["general"]["ignoreMuteSwitch"];
  715. node->Bool() = checked;
  716. updateCheckbuttonText(ui->buttonIgnoreMuteSwitch);
  717. }