csettingsview_moc.cpp 23 KB

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