csettingsview_moc.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  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. auto translationStatus = mainWindow->getTranslationStatus();
  418. bool showTranslation = translationStatus == ETranslationStatus::DISABLED || translationStatus == ETranslationStatus::NOT_INSTALLLED;
  419. ui->labelTranslation->setVisible(showTranslation);
  420. ui->labelTranslationStatus->setVisible(showTranslation);
  421. ui->pushButtonTranslation->setVisible(showTranslation);
  422. ui->pushButtonTranslation->setVisible(translationStatus != ETranslationStatus::ACTIVE);
  423. if (translationStatus == ETranslationStatus::ACTIVE)
  424. {
  425. ui->labelTranslationStatus->setText(tr("Active"));
  426. }
  427. if (translationStatus == ETranslationStatus::DISABLED)
  428. {
  429. ui->labelTranslationStatus->setText(tr("Disabled"));
  430. ui->pushButtonTranslation->setText(tr("Enable"));
  431. }
  432. if (translationStatus == ETranslationStatus::NOT_INSTALLLED)
  433. {
  434. ui->labelTranslationStatus->setText(tr("Not Installed"));
  435. ui->pushButtonTranslation->setText(tr("Install"));
  436. }
  437. }
  438. void CSettingsView::on_pushButtonTranslation_clicked()
  439. {
  440. auto * mainWindow = getMainWindow();
  441. assert(mainWindow);
  442. if (!mainWindow)
  443. return;
  444. QString languageName = QString::fromStdString(settings["general"]["language"].String());
  445. QString modName = mainWindow->getModView()->getTranslationModName(languageName);
  446. assert(!modName.isEmpty());
  447. if (modName.isEmpty())
  448. return;
  449. if (mainWindow->getModView()->isModAvailable(modName))
  450. {
  451. mainWindow->switchToModsTab();
  452. mainWindow->getModView()->doInstallMod(modName);
  453. }
  454. else
  455. {
  456. mainWindow->getModView()->enableModByName(modName);
  457. }
  458. }
  459. void CSettingsView::on_pushButtonResetTutorialTouchscreen_clicked()
  460. {
  461. Settings node0 = persistentStorage.write["gui"]["tutorialCompleted0"];
  462. node0->Bool() = false;
  463. Settings node1 = persistentStorage.write["gui"]["tutorialCompleted1"];
  464. node1->Bool() = false;
  465. ui->pushButtonResetTutorialTouchscreen->hide();
  466. }
  467. void CSettingsView::on_buttonRepositoryDefault_toggled(bool value)
  468. {
  469. Settings node = settings.write["launcher"]["defaultRepositoryEnabled"];
  470. node->Bool() = value;
  471. ui->lineEditRepositoryDefault->setEnabled(value);
  472. updateCheckbuttonText(ui->buttonRepositoryDefault);
  473. }
  474. void CSettingsView::on_buttonRepositoryExtra_toggled(bool value)
  475. {
  476. Settings node = settings.write["launcher"]["extraRepositoryEnabled"];
  477. node->Bool() = value;
  478. ui->lineEditRepositoryExtra->setEnabled(value);
  479. updateCheckbuttonText(ui->buttonRepositoryExtra);
  480. }
  481. void CSettingsView::on_lineEditRepositoryExtra_textEdited(const QString &arg1)
  482. {
  483. Settings node = settings.write["launcher"]["extraRepositoryURL"];
  484. node->String() = arg1.toStdString();
  485. }
  486. void CSettingsView::on_spinBoxInterfaceScaling_valueChanged(int arg1)
  487. {
  488. Settings node = settings.write["video"]["resolution"]["scaling"];
  489. node->Float() = ui->buttonScalingAuto->isChecked() ? 0 : arg1;
  490. }
  491. void CSettingsView::on_refreshRepositoriesButton_clicked()
  492. {
  493. auto * mainWindow = getMainWindow();
  494. assert(mainWindow);
  495. if (!mainWindow)
  496. return;
  497. mainWindow->getModView()->loadRepositories();
  498. }
  499. void CSettingsView::on_spinBoxFramerateLimit_valueChanged(int arg1)
  500. {
  501. Settings node = settings.write["video"]["targetfps"];
  502. node->Float() = arg1;
  503. }
  504. void CSettingsView::on_buttonVSync_toggled(bool value)
  505. {
  506. Settings node = settings.write["video"]["vsync"];
  507. node->Bool() = value;
  508. ui->spinBoxFramerateLimit->setDisabled(settings["video"]["vsync"].Bool());
  509. }
  510. void CSettingsView::on_comboBoxEnemyPlayerAI_currentTextChanged(const QString &arg1)
  511. {
  512. Settings node = settings.write["server"]["playerAI"];
  513. node->String() = arg1.toUtf8().data();
  514. }
  515. void CSettingsView::on_comboBoxAlliedPlayerAI_currentTextChanged(const QString &arg1)
  516. {
  517. Settings node = settings.write["server"]["alliedAI"];
  518. node->String() = arg1.toUtf8().data();
  519. }
  520. void CSettingsView::on_buttonAutoSavePrefix_toggled(bool value)
  521. {
  522. Settings node = settings.write["general"]["useSavePrefix"];
  523. node->Bool() = value;
  524. ui->lineEditAutoSavePrefix->setEnabled(value);
  525. updateCheckbuttonText(ui->buttonAutoSavePrefix);
  526. }
  527. void CSettingsView::on_spinBoxAutoSaveLimit_valueChanged(int arg1)
  528. {
  529. Settings node = settings.write["general"]["autosaveCountLimit"];
  530. node->Float() = arg1;
  531. }
  532. void CSettingsView::on_lineEditAutoSavePrefix_textEdited(const QString & arg1)
  533. {
  534. Settings node = settings.write["general"]["savePrefix"];
  535. node->String() = arg1.toStdString();
  536. }
  537. void CSettingsView::on_sliderReservedArea_valueChanged(int arg1)
  538. {
  539. Settings node = settings.write["video"]["reservedWidth"];
  540. node->Float() = float(arg1) / 100; // percentage -> ratio
  541. }
  542. void CSettingsView::on_comboBoxRendererType_currentTextChanged(const QString &arg1)
  543. {
  544. Settings node = settings.write["video"]["driver"];
  545. node->String() = arg1.toStdString();
  546. }
  547. void CSettingsView::on_buttonIgnoreSslErrors_clicked(bool checked)
  548. {
  549. Settings node = settings.write["launcher"]["ignoreSslErrors"];
  550. node->Bool() = checked;
  551. updateCheckbuttonText(ui->buttonIgnoreSslErrors);
  552. }
  553. void CSettingsView::on_comboBoxUpscalingFilter_currentIndexChanged(int index)
  554. {
  555. Settings node = settings.write["video"]["upscalingFilter"];
  556. node->String() = upscalingFilterTypes[index];
  557. }
  558. void CSettingsView::on_comboBoxDownscalingFilter_currentIndexChanged(int index)
  559. {
  560. Settings node = settings.write["video"]["downscalingFilter"];
  561. node->String() = downscalingFilterTypes[index];
  562. }
  563. void CSettingsView::on_sliderMusicVolume_valueChanged(int value)
  564. {
  565. Settings node = settings.write["general"]["music"];
  566. node->Integer() = value;
  567. }
  568. void CSettingsView::on_sliderSoundVolume_valueChanged(int value)
  569. {
  570. Settings node = settings.write["general"]["sound"];
  571. node->Integer() = value;
  572. }
  573. void CSettingsView::on_buttonRelativeCursorMode_toggled(bool value)
  574. {
  575. Settings node = settings.write["general"]["userRelativePointer"];
  576. node->Bool() = value;
  577. updateCheckbuttonText(ui->buttonRelativeCursorMode);
  578. }
  579. void CSettingsView::on_sliderRelativeCursorSpeed_valueChanged(int value)
  580. {
  581. Settings node = settings.write["general"]["relativePointerSpeedMultiplier"];
  582. node->Float() = value / 100.0;
  583. }
  584. void CSettingsView::on_buttonHapticFeedback_toggled(bool value)
  585. {
  586. Settings node = settings.write["general"]["hapticFeedback"];
  587. node->Bool() = value;
  588. updateCheckbuttonText(ui->buttonHapticFeedback);
  589. }
  590. void CSettingsView::on_sliderLongTouchDuration_valueChanged(int value)
  591. {
  592. Settings node = settings.write["general"]["longTouchTimeMilliseconds"];
  593. node->Integer() = value;
  594. }
  595. void CSettingsView::on_slideToleranceDistanceMouse_valueChanged(int value)
  596. {
  597. Settings node = settings.write["input"]["mouseToleranceDistance"];
  598. node->Integer() = value;
  599. }
  600. void CSettingsView::on_sliderToleranceDistanceTouch_valueChanged(int value)
  601. {
  602. Settings node = settings.write["input"]["touchToleranceDistance"];
  603. node->Integer() = value;
  604. }
  605. void CSettingsView::on_sliderToleranceDistanceController_valueChanged(int value)
  606. {
  607. Settings node = settings.write["input"]["shortcutToleranceDistance"];
  608. node->Integer() = value;
  609. }
  610. void CSettingsView::on_lineEditGameLobbyHost_textChanged(const QString & arg1)
  611. {
  612. Settings node = settings.write["lobby"]["hostname"];
  613. node->String() = arg1.toStdString();
  614. }
  615. void CSettingsView::on_spinBoxNetworkPortLobby_valueChanged(int arg1)
  616. {
  617. Settings node = settings.write["lobby"]["port"];
  618. node->Integer() = arg1;
  619. }
  620. void CSettingsView::on_sliderControllerSticksAcceleration_valueChanged(int value)
  621. {
  622. Settings node = settings.write["input"]["controllerAxisScale"];
  623. node->Integer() = value / 100.0;
  624. }
  625. void CSettingsView::on_sliderControllerSticksSensitivity_valueChanged(int value)
  626. {
  627. Settings node = settings.write["input"]["controllerAxisSpeed"];
  628. node->Integer() = value;
  629. }
  630. void CSettingsView::on_sliderScalingFont_valueChanged(int value)
  631. {
  632. int actualValuePercentage = value * 5;
  633. ui->labelScalingFontValue->setText(QString("%1%").arg(actualValuePercentage));
  634. Settings node = settings.write["video"]["fontScalingFactor"];
  635. node->Float() = actualValuePercentage / 100.0;
  636. }
  637. void CSettingsView::on_buttonFontAuto_clicked(bool checked)
  638. {
  639. Settings node = settings.write["video"]["fontsType"];
  640. node->String() = "auto";
  641. }
  642. void CSettingsView::on_buttonFontScalable_clicked(bool checked)
  643. {
  644. Settings node = settings.write["video"]["fontsType"];
  645. node->String() = "scalable";
  646. }
  647. void CSettingsView::on_buttonFontOriginal_clicked(bool checked)
  648. {
  649. Settings node = settings.write["video"]["fontsType"];
  650. node->String() = "original";
  651. }
  652. void CSettingsView::on_buttonValidationOff_clicked(bool checked)
  653. {
  654. Settings node = settings.write["mods"]["validation"];
  655. node->String() = "off";
  656. }
  657. void CSettingsView::on_buttonValidationBasic_clicked(bool checked)
  658. {
  659. Settings node = settings.write["mods"]["validation"];
  660. node->String() = "basic";
  661. }
  662. void CSettingsView::on_buttonValidationFull_clicked(bool checked)
  663. {
  664. Settings node = settings.write["mods"]["validation"];
  665. node->String() = "full";
  666. }
  667. void CSettingsView::on_sliderScalingCursor_valueChanged(int value)
  668. {
  669. int actualValuePercentage = value * 5;
  670. ui->labelScalingCursorValue->setText(QString("%1%").arg(actualValuePercentage));
  671. Settings node = settings.write["video"]["cursorScalingFactor"];
  672. node->Float() = actualValuePercentage / 100.0;
  673. }
  674. void CSettingsView::on_buttonScalingAuto_toggled(bool checked)
  675. {
  676. if (checked)
  677. {
  678. ui->spinBoxInterfaceScaling->hide();
  679. }
  680. else
  681. {
  682. ui->spinBoxInterfaceScaling->show();
  683. ui->spinBoxInterfaceScaling->setValue(100);
  684. }
  685. Settings node = settings.write["video"]["resolution"]["scaling"];
  686. node->Integer() = checked ? 0 : 100;
  687. }