csettingsview_moc.cpp 30 KB

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