csettingsview_moc.cpp 24 KB

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