csettingsview_moc.cpp 27 KB

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