csettingsview_moc.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. auto mainWindow = getMainWindow();
  149. if(mainWindow)
  150. {
  151. bool fontModAvailable = mainWindow->getModView()->isModInstalled("vcmi-extras.truetypefonts");
  152. if(!fontModAvailable)
  153. {
  154. ui->labelTtfFont->hide();
  155. ui->buttonTtfFont->hide();
  156. }
  157. }
  158. loadToggleButtonSettings();
  159. }
  160. void CSettingsView::loadToggleButtonSettings()
  161. {
  162. setCheckbuttonState(ui->buttonShowIntro, settings["video"]["showIntro"].Bool());
  163. setCheckbuttonState(ui->buttonVSync, settings["video"]["vsync"].Bool());
  164. setCheckbuttonState(ui->buttonAutoCheck, settings["launcher"]["autoCheckRepositories"].Bool());
  165. setCheckbuttonState(ui->buttonRepositoryDefault, settings["launcher"]["defaultRepositoryEnabled"].Bool());
  166. setCheckbuttonState(ui->buttonRepositoryExtra, settings["launcher"]["extraRepositoryEnabled"].Bool());
  167. setCheckbuttonState(ui->buttonIgnoreSslErrors, settings["launcher"]["ignoreSslErrors"].Bool());
  168. setCheckbuttonState(ui->buttonAutoSave, settings["general"]["saveFrequency"].Integer() > 0);
  169. setCheckbuttonState(ui->buttonAutoSavePrefix, settings["general"]["useSavePrefix"].Bool());
  170. setCheckbuttonState(ui->buttonRelativeCursorMode, settings["general"]["userRelativePointer"].Bool());
  171. setCheckbuttonState(ui->buttonHapticFeedback, settings["general"]["hapticFeedback"].Bool());
  172. std::string cursorType = settings["video"]["cursor"].String();
  173. int cursorTypeIndex = vstd::find_pos(cursorTypesList, cursorType);
  174. setCheckbuttonState(ui->buttonCursorType, cursorTypeIndex);
  175. auto mainWindow = getMainWindow();
  176. if(mainWindow)
  177. setCheckbuttonState(ui->buttonTtfFont, mainWindow->getModView()->isModEnabled("vcmi-extras.truetypefonts"));
  178. }
  179. void CSettingsView::fillValidResolutions()
  180. {
  181. fillValidResolutionsForScreen(ui->comboBoxDisplayIndex->isVisible() ? ui->comboBoxDisplayIndex->currentIndex() : 0);
  182. }
  183. QSize CSettingsView::getPreferredRenderingResolution()
  184. {
  185. #ifndef VCMI_MOBILE
  186. bool fullscreen = settings["video"]["fullscreen"].Bool();
  187. bool realFullscreen = settings["video"]["realFullscreen"].Bool();
  188. if (!fullscreen || realFullscreen)
  189. {
  190. int resX = settings["video"]["resolution"]["width"].Integer();
  191. int resY = settings["video"]["resolution"]["height"].Integer();
  192. return QSize(resX, resY);
  193. }
  194. #endif
  195. return QApplication::primaryScreen()->geometry().size() * QApplication::primaryScreen()->devicePixelRatio();
  196. }
  197. void CSettingsView::fillValidScalingRange()
  198. {
  199. //FIXME: this code is copy of ScreenHandler::getSupportedScalingRange
  200. // H3 resolution, any resolution smaller than that is not correctly supported
  201. static const QSize minResolution = {800, 600};
  202. // arbitrary limit on *downscaling*. Allow some downscaling, if requested by user. Should be generally limited to 100+ for all but few devices
  203. static const double minimalScaling = 50;
  204. QSize renderResolution = getPreferredRenderingResolution();
  205. double maximalScalingWidth = 100.0 * renderResolution.width() / minResolution.width();
  206. double maximalScalingHeight = 100.0 * renderResolution.height() / minResolution.height();
  207. double maximalScaling = std::min(maximalScalingWidth, maximalScalingHeight);
  208. ui->spinBoxInterfaceScaling->setRange(minimalScaling, maximalScaling);
  209. }
  210. #ifndef VCMI_MOBILE
  211. static QStringList getAvailableRenderingDrivers()
  212. {
  213. SDL_Init(SDL_INIT_VIDEO);
  214. QStringList result;
  215. result += QString(); // empty value for autoselection
  216. int driversCount = SDL_GetNumRenderDrivers();
  217. for(int it = 0; it < driversCount; it++)
  218. {
  219. SDL_RendererInfo info;
  220. if (SDL_GetRenderDriverInfo(it, &info) == 0)
  221. result += QString::fromLatin1(info.name);
  222. }
  223. SDL_Quit();
  224. return result;
  225. }
  226. static QVector<QSize> findAvailableResolutions(int displayIndex)
  227. {
  228. // Ugly workaround since we don't actually need SDL in Launcher
  229. // However Qt at the moment provides no way to query list of available resolutions
  230. QVector<QSize> result;
  231. SDL_Init(SDL_INIT_VIDEO);
  232. int modesCount = SDL_GetNumDisplayModes(displayIndex);
  233. for (int i =0; i < modesCount; ++i)
  234. {
  235. SDL_DisplayMode mode;
  236. if (SDL_GetDisplayMode(displayIndex, i, &mode) != 0)
  237. continue;
  238. QSize resolution(mode.w, mode.h);
  239. result.push_back(resolution);
  240. }
  241. boost::range::sort(result, [](const auto & left, const auto & right)
  242. {
  243. return left.height() * left.width() < right.height() * right.width();
  244. });
  245. result.erase(boost::unique(result).end(), result.end());
  246. SDL_Quit();
  247. return result;
  248. }
  249. void CSettingsView::fillValidResolutionsForScreen(int screenIndex)
  250. {
  251. QSignalBlocker guard(ui->comboBoxResolution); // avoid saving wrong resolution after adding first item from the list
  252. ui->comboBoxResolution->clear();
  253. bool fullscreen = settings["video"]["fullscreen"].Bool();
  254. bool realFullscreen = settings["video"]["realFullscreen"].Bool();
  255. if (!fullscreen || realFullscreen)
  256. {
  257. QVector<QSize> resolutions = findAvailableResolutions(screenIndex);
  258. for(const auto & entry : resolutions)
  259. ui->comboBoxResolution->addItem(resolutionToString(entry));
  260. }
  261. else
  262. {
  263. ui->comboBoxResolution->addItem(resolutionToString(getPreferredRenderingResolution()));
  264. }
  265. ui->comboBoxResolution->setEnabled(ui->comboBoxResolution->count() > 1);
  266. int resX = settings["video"]["resolution"]["width"].Integer();
  267. int resY = settings["video"]["resolution"]["height"].Integer();
  268. int resIndex = ui->comboBoxResolution->findText(resolutionToString({resX, resY}));
  269. ui->comboBoxResolution->setCurrentIndex(resIndex);
  270. // if selected resolution no longer exists, force update value to the largest (last) resolution
  271. if(resIndex == -1)
  272. ui->comboBoxResolution->setCurrentIndex(ui->comboBoxResolution->count() - 1);
  273. }
  274. void CSettingsView::fillValidRenderers()
  275. {
  276. QSignalBlocker guard(ui->comboBoxRendererType); // avoid saving wrong renderer after adding first item from the list
  277. ui->comboBoxRendererType->clear();
  278. auto driversList = getAvailableRenderingDrivers();
  279. ui->comboBoxRendererType->addItems(driversList);
  280. std::string rendererName = settings["video"]["driver"].String();
  281. int index = ui->comboBoxRendererType->findText(QString::fromStdString(rendererName));
  282. ui->comboBoxRendererType->setCurrentIndex(index);
  283. }
  284. #else
  285. void CSettingsView::fillValidResolutionsForScreen(int screenIndex)
  286. {
  287. // resolutions are not selectable on mobile platforms
  288. ui->comboBoxResolution->hide();
  289. ui->labelResolution->hide();
  290. }
  291. void CSettingsView::fillValidRenderers()
  292. {
  293. // untested on mobile platforms
  294. ui->comboBoxRendererType->hide();
  295. ui->labelRendererType->hide();
  296. }
  297. #endif
  298. CSettingsView::CSettingsView(QWidget * parent)
  299. : QWidget(parent), ui(new Ui::CSettingsView)
  300. {
  301. ui->setupUi(this);
  302. Helper::enableScrollBySwiping(ui->settingsScrollArea);
  303. loadSettings();
  304. }
  305. CSettingsView::~CSettingsView()
  306. {
  307. delete ui;
  308. }
  309. void CSettingsView::on_comboBoxResolution_currentTextChanged(const QString & arg1)
  310. {
  311. QStringList list = arg1.split("x");
  312. Settings node = settings.write["video"]["resolution"];
  313. node["width"].Float() = list[0].toInt();
  314. node["height"].Float() = list[1].toInt();
  315. fillValidResolutions();
  316. fillValidScalingRange();
  317. }
  318. void CSettingsView::on_comboBoxFullScreen_currentIndexChanged(int index)
  319. {
  320. Settings nodeFullscreen = settings.write["video"]["fullscreen"];
  321. Settings nodeRealFullscreen = settings.write["video"]["realFullscreen"];
  322. nodeFullscreen->Bool() = (index != 0);
  323. nodeRealFullscreen->Bool() = (index == 2);
  324. fillValidResolutions();
  325. fillValidScalingRange();
  326. }
  327. void CSettingsView::on_buttonAutoCheck_toggled(bool value)
  328. {
  329. Settings node = settings.write["launcher"]["autoCheckRepositories"];
  330. node->Bool() = value;
  331. updateCheckbuttonText(ui->buttonAutoCheck);
  332. }
  333. void CSettingsView::on_comboBoxDisplayIndex_currentIndexChanged(int index)
  334. {
  335. Settings node = settings.write["video"];
  336. node["displayIndex"].Float() = index;
  337. fillValidResolutionsForScreen(index);
  338. }
  339. void CSettingsView::on_comboBoxFriendlyAI_currentTextChanged(const QString & arg1)
  340. {
  341. Settings node = settings.write["server"]["friendlyAI"];
  342. node->String() = arg1.toUtf8().data();
  343. }
  344. void CSettingsView::on_comboBoxNeutralAI_currentTextChanged(const QString & arg1)
  345. {
  346. Settings node = settings.write["server"]["neutralAI"];
  347. node->String() = arg1.toUtf8().data();
  348. }
  349. void CSettingsView::on_comboBoxEnemyAI_currentTextChanged(const QString & arg1)
  350. {
  351. Settings node = settings.write["server"]["enemyAI"];
  352. node->String() = arg1.toUtf8().data();
  353. }
  354. void CSettingsView::on_spinBoxNetworkPort_valueChanged(int arg1)
  355. {
  356. Settings node = settings.write["server"]["port"];
  357. node->Float() = arg1;
  358. }
  359. void CSettingsView::on_buttonShowIntro_toggled(bool value)
  360. {
  361. Settings node = settings.write["video"]["showIntro"];
  362. node->Bool() = value;
  363. updateCheckbuttonText(ui->buttonShowIntro);
  364. }
  365. void CSettingsView::on_buttonAutoSave_toggled(bool value)
  366. {
  367. Settings node = settings.write["general"]["saveFrequency"];
  368. node->Integer() = value ? 1 : 0;
  369. updateCheckbuttonText(ui->buttonAutoSave);
  370. }
  371. void CSettingsView::on_comboBoxLanguage_currentIndexChanged(int index)
  372. {
  373. Settings node = settings.write["general"]["language"];
  374. QString selectedLanguage = ui->comboBoxLanguage->itemData(index).toString();
  375. node->String() = selectedLanguage.toStdString();
  376. getMainWindow()->updateTranslation();
  377. }
  378. void CSettingsView::changeEvent(QEvent *event)
  379. {
  380. if(event->type() == QEvent::LanguageChange)
  381. {
  382. ui->retranslateUi(this);
  383. Languages::fillLanguages(ui->comboBoxLanguage, false);
  384. loadTranslation();
  385. loadToggleButtonSettings();
  386. }
  387. QWidget::changeEvent(event);
  388. }
  389. void CSettingsView::showEvent(QShowEvent * event)
  390. {
  391. loadTranslation();
  392. QWidget::showEvent(event);
  393. }
  394. void CSettingsView::on_buttonCursorType_toggled(bool value)
  395. {
  396. Settings node = settings.write["video"]["cursor"];
  397. node->String() = cursorTypesList[value ? 1 : 0];
  398. updateCheckbuttonText(ui->buttonCursorType);
  399. }
  400. void CSettingsView::loadTranslation()
  401. {
  402. QString baseLanguage = Languages::getHeroesDataLanguage();
  403. auto * mainWindow = getMainWindow();
  404. if (!mainWindow)
  405. return;
  406. QString languageName = QString::fromStdString(settings["general"]["language"].String());
  407. QString modName = mainWindow->getModView()->getTranslationModName(languageName);
  408. bool translationExists = !modName.isEmpty();
  409. bool translationNeeded = languageName != baseLanguage;
  410. bool showTranslation = translationNeeded && translationExists;
  411. ui->labelTranslation->setVisible(showTranslation);
  412. ui->labelTranslationStatus->setVisible(showTranslation);
  413. ui->pushButtonTranslation->setVisible(showTranslation);
  414. if (!translationExists || !translationNeeded)
  415. return;
  416. bool translationAvailable = mainWindow->getModView()->isModAvailable(modName);
  417. bool translationEnabled = mainWindow->getModView()->isModEnabled(modName);
  418. ui->pushButtonTranslation->setVisible(!translationEnabled);
  419. if (translationEnabled)
  420. {
  421. ui->labelTranslationStatus->setText(tr("Active"));
  422. }
  423. if (!translationEnabled && !translationAvailable)
  424. {
  425. ui->labelTranslationStatus->setText(tr("Disabled"));
  426. ui->pushButtonTranslation->setText(tr("Enable"));
  427. }
  428. if (translationAvailable)
  429. {
  430. ui->labelTranslationStatus->setText(tr("Not Installed"));
  431. ui->pushButtonTranslation->setText(tr("Install"));
  432. }
  433. }
  434. void CSettingsView::on_pushButtonTranslation_clicked()
  435. {
  436. auto * mainWindow = getMainWindow();
  437. assert(mainWindow);
  438. if (!mainWindow)
  439. return;
  440. QString languageName = QString::fromStdString(settings["general"]["language"].String());
  441. QString modName = mainWindow->getModView()->getTranslationModName(languageName);
  442. assert(!modName.isEmpty());
  443. if (modName.isEmpty())
  444. return;
  445. if (mainWindow->getModView()->isModAvailable(modName))
  446. {
  447. mainWindow->switchToModsTab();
  448. mainWindow->getModView()->doInstallMod(modName);
  449. }
  450. else
  451. {
  452. mainWindow->getModView()->enableModByName(modName);
  453. }
  454. }
  455. void CSettingsView::on_pushButtonResetTutorialTouchscreen_clicked()
  456. {
  457. Settings node0 = persistentStorage.write["gui"]["tutorialCompleted0"];
  458. node0->Bool() = false;
  459. Settings node1 = persistentStorage.write["gui"]["tutorialCompleted1"];
  460. node1->Bool() = false;
  461. ui->pushButtonResetTutorialTouchscreen->hide();
  462. }
  463. void CSettingsView::on_buttonRepositoryDefault_toggled(bool value)
  464. {
  465. Settings node = settings.write["launcher"]["defaultRepositoryEnabled"];
  466. node->Bool() = value;
  467. ui->lineEditRepositoryDefault->setEnabled(value);
  468. updateCheckbuttonText(ui->buttonRepositoryDefault);
  469. }
  470. void CSettingsView::on_buttonRepositoryExtra_toggled(bool value)
  471. {
  472. Settings node = settings.write["launcher"]["extraRepositoryEnabled"];
  473. node->Bool() = value;
  474. ui->lineEditRepositoryExtra->setEnabled(value);
  475. updateCheckbuttonText(ui->buttonRepositoryExtra);
  476. }
  477. void CSettingsView::on_lineEditRepositoryExtra_textEdited(const QString &arg1)
  478. {
  479. Settings node = settings.write["launcher"]["extraRepositoryURL"];
  480. node->String() = arg1.toStdString();
  481. }
  482. void CSettingsView::on_spinBoxInterfaceScaling_valueChanged(int arg1)
  483. {
  484. Settings node = settings.write["video"]["resolution"]["scaling"];
  485. node->Float() = arg1;
  486. }
  487. void CSettingsView::on_refreshRepositoriesButton_clicked()
  488. {
  489. auto * mainWindow = getMainWindow();
  490. assert(mainWindow);
  491. if (!mainWindow)
  492. return;
  493. mainWindow->getModView()->loadRepositories();
  494. }
  495. void CSettingsView::on_spinBoxFramerateLimit_valueChanged(int arg1)
  496. {
  497. Settings node = settings.write["video"]["targetfps"];
  498. node->Float() = arg1;
  499. }
  500. void CSettingsView::on_buttonVSync_toggled(bool value)
  501. {
  502. Settings node = settings.write["video"]["vsync"];
  503. node->Bool() = value;
  504. ui->spinBoxFramerateLimit->setDisabled(settings["video"]["vsync"].Bool());
  505. updateCheckbuttonText(ui->buttonVSync);
  506. }
  507. void CSettingsView::on_comboBoxEnemyPlayerAI_currentTextChanged(const QString &arg1)
  508. {
  509. Settings node = settings.write["server"]["playerAI"];
  510. node->String() = arg1.toUtf8().data();
  511. }
  512. void CSettingsView::on_comboBoxAlliedPlayerAI_currentTextChanged(const QString &arg1)
  513. {
  514. Settings node = settings.write["server"]["alliedAI"];
  515. node->String() = arg1.toUtf8().data();
  516. }
  517. void CSettingsView::on_buttonAutoSavePrefix_toggled(bool value)
  518. {
  519. Settings node = settings.write["general"]["useSavePrefix"];
  520. node->Bool() = value;
  521. ui->lineEditAutoSavePrefix->setEnabled(value);
  522. updateCheckbuttonText(ui->buttonAutoSavePrefix);
  523. }
  524. void CSettingsView::on_spinBoxAutoSaveLimit_valueChanged(int arg1)
  525. {
  526. Settings node = settings.write["general"]["autosaveCountLimit"];
  527. node->Float() = arg1;
  528. }
  529. void CSettingsView::on_lineEditAutoSavePrefix_textEdited(const QString & arg1)
  530. {
  531. Settings node = settings.write["general"]["savePrefix"];
  532. node->String() = arg1.toStdString();
  533. }
  534. void CSettingsView::on_sliderReservedArea_valueChanged(int arg1)
  535. {
  536. Settings node = settings.write["video"]["reservedWidth"];
  537. node->Float() = float(arg1) / 100; // percentage -> ratio
  538. }
  539. void CSettingsView::on_comboBoxRendererType_currentTextChanged(const QString &arg1)
  540. {
  541. Settings node = settings.write["video"]["driver"];
  542. node->String() = arg1.toStdString();
  543. }
  544. void CSettingsView::on_buttonIgnoreSslErrors_clicked(bool checked)
  545. {
  546. Settings node = settings.write["launcher"]["ignoreSslErrors"];
  547. node->Bool() = checked;
  548. updateCheckbuttonText(ui->buttonIgnoreSslErrors);
  549. }
  550. void CSettingsView::on_comboBoxUpscalingFilter_currentIndexChanged(int index)
  551. {
  552. Settings node = settings.write["video"]["upscalingFilter"];
  553. node->String() = upscalingFilterTypes[index];
  554. }
  555. void CSettingsView::on_comboBoxDownscalingFilter_currentIndexChanged(int index)
  556. {
  557. Settings node = settings.write["video"]["downscalingFilter"];
  558. node->String() = downscalingFilterTypes[index];
  559. }
  560. void CSettingsView::on_sliderMusicVolume_valueChanged(int value)
  561. {
  562. Settings node = settings.write["general"]["music"];
  563. node->Integer() = value;
  564. }
  565. void CSettingsView::on_sliderSoundVolume_valueChanged(int value)
  566. {
  567. Settings node = settings.write["general"]["sound"];
  568. node->Integer() = value;
  569. }
  570. void CSettingsView::on_buttonRelativeCursorMode_toggled(bool value)
  571. {
  572. Settings node = settings.write["general"]["userRelativePointer"];
  573. node->Bool() = value;
  574. updateCheckbuttonText(ui->buttonRelativeCursorMode);
  575. }
  576. void CSettingsView::on_sliderRelativeCursorSpeed_valueChanged(int value)
  577. {
  578. Settings node = settings.write["general"]["relativePointerSpeedMultiplier"];
  579. node->Float() = value / 100.0;
  580. }
  581. void CSettingsView::on_buttonHapticFeedback_toggled(bool value)
  582. {
  583. Settings node = settings.write["general"]["hapticFeedback"];
  584. node->Bool() = value;
  585. updateCheckbuttonText(ui->buttonHapticFeedback);
  586. }
  587. void CSettingsView::on_sliderLongTouchDuration_valueChanged(int value)
  588. {
  589. Settings node = settings.write["general"]["longTouchTimeMilliseconds"];
  590. node->Integer() = value;
  591. }
  592. void CSettingsView::on_slideToleranceDistanceMouse_valueChanged(int value)
  593. {
  594. Settings node = settings.write["input"]["mouseToleranceDistance"];
  595. node->Integer() = value;
  596. }
  597. void CSettingsView::on_sliderToleranceDistanceTouch_valueChanged(int value)
  598. {
  599. Settings node = settings.write["input"]["touchToleranceDistance"];
  600. node->Integer() = value;
  601. }
  602. void CSettingsView::on_sliderToleranceDistanceController_valueChanged(int value)
  603. {
  604. Settings node = settings.write["input"]["shortcutToleranceDistance"];
  605. node->Integer() = value;
  606. }
  607. void CSettingsView::on_lineEditGameLobbyHost_textChanged(const QString & arg1)
  608. {
  609. Settings node = settings.write["lobby"]["hostname"];
  610. node->String() = arg1.toStdString();
  611. }
  612. void CSettingsView::on_spinBoxNetworkPortLobby_valueChanged(int arg1)
  613. {
  614. Settings node = settings.write["lobby"]["port"];
  615. node->Integer() = arg1;
  616. }
  617. void CSettingsView::on_sliderControllerSticksAcceleration_valueChanged(int value)
  618. {
  619. Settings node = settings.write["input"]["controllerAxisScale"];
  620. node->Integer() = value / 100.0;
  621. }
  622. void CSettingsView::on_sliderControllerSticksSensitivity_valueChanged(int value)
  623. {
  624. Settings node = settings.write["input"]["controllerAxisSpeed"];
  625. node->Integer() = value;
  626. }
  627. void CSettingsView::on_buttonTtfFont_toggled(bool value)
  628. {
  629. auto mainWindow = getMainWindow();
  630. if(value)
  631. mainWindow->getModView()->enableModByName("vcmi-extras.truetypefonts");
  632. else
  633. mainWindow->getModView()->disableModByName("vcmi-extras.truetypefonts");
  634. updateCheckbuttonText(ui->buttonTtfFont);
  635. }