csettingsview_moc.cpp 22 KB

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