csettingsview_moc.cpp 22 KB

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