csettingsview_moc.cpp 26 KB

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