csettingsview_moc.cpp 26 KB

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