csettingsview_moc.cpp 30 KB

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