csettingsview_moc.cpp 27 KB

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