csettingsview_moc.cpp 26 KB

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