settingswidget.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. #include "ui_settingswidget.h"
  2. #include "models/settings.h"
  3. #include "models/patchlist.h"
  4. #include "widgets/settingswidget.h"
  5. #include "widgets/mainwindow.h"
  6. #include "constants.h"
  7. #include <QDebug>
  8. #include <QScrollBar>
  9. #include <QFileDialog>
  10. #include <QMetaObject>
  11. #include <QMessageBox>
  12. using namespace SettingsWidgetPrivate;
  13. SettingsWidget::SettingsWidget(PatchList *legacy_patches, QWidget *parent)
  14. : QWidget(parent)
  15. , ui(new Ui::SettingsWidget)
  16. , legacy_patches_(legacy_patches)
  17. {
  18. settings_changed_ = false;
  19. ui->setupUi(this);
  20. combobox_scrolling_disabler = new ComboboxScrollingDisabler();
  21. scroller = new SettingsTabsScroller({ui->sub_entry_1,
  22. ui->sub_entry_2,
  23. ui->sub_entry_3,
  24. ui->sub_entry_4
  25. },
  26. ui->content_scroll_area);
  27. ui->lotro_base_language_combobox->installEventFilter(combobox_scrolling_disabler);
  28. ui->interface_scale_combobox->installEventFilter(combobox_scrolling_disabler);
  29. // ui->content_scroll_area->verticalScrollBar()->installEventFilter(scroller);
  30. ui->patch_installing_label->hide();
  31. connect(legacy_patches, &PatchList::patchOperationsStarted, this, &SettingsWidget::onPatchTotalOperationsStarted);
  32. connect(legacy_patches, &PatchList::patchOperationsFinished, this, &SettingsWidget::onPatchTotalOperationsFinished);
  33. ui->apply_changes_button->hide();
  34. ui->apply_changes_label->hide();
  35. ui->patch_installing_label->hide();
  36. settings_backup_ = Settings::createSettingsBackup();
  37. setActualParametersValues();
  38. }
  39. SettingsWidget::~SettingsWidget()
  40. {
  41. delete combobox_scrolling_disabler;
  42. delete scroller;
  43. delete ui;
  44. }
  45. void SettingsWidget::setActualParametersValues()
  46. {
  47. QString game_path = Settings::getValue("Lotro/game_path").toString();
  48. if (game_path == "none") {
  49. game_path = "Путь к файлам игры не выбран";
  50. }
  51. ui->game_folder_path->setText(game_path);
  52. QString original_locale = Settings::getValue("Lotro/original_locale").toString();
  53. int index = 0;
  54. if (original_locale == "English")
  55. index = 0;
  56. if (original_locale == "DE")
  57. index = 1;
  58. if (original_locale == "FR")
  59. index = 2;
  60. ui->lotro_base_language_combobox->setCurrentIndex(index);
  61. ui->skiprawdownload_checkbox->setChecked(Settings::getValue("Lotro/skip_raw_download").toBool());
  62. ui->nosplashscreen_checkbox->setChecked(Settings::getValue("Lotro/no_splash_screen").toBool());
  63. QString backup_status = Settings::getValue("Backup/installed").toBool() ? "Отсутствует" : "Активна";
  64. ui->backup_status_value->setText(backup_status);
  65. ui->backup_path_value->setText(QApplication::applicationDirPath() + Settings::getValue("Backup/path").toString());
  66. QString backup_creation_time = Settings::getValue("Backup/creation_time").toString();
  67. if (backup_creation_time == "none")
  68. backup_creation_time = "-";
  69. ui->backup_creation_time_value->setText(backup_creation_time);
  70. ui->patch_texts_checkbox->setChecked(Settings::getValue("Components/texts_main").toBool());
  71. ui->patch_items_checkbox->setChecked(Settings::getValue("Components/texts_items").toBool());
  72. ui->patch_emotes_checkbox->setChecked(Settings::getValue("Components/texts_emotes").toBool());
  73. ui->patch_maps_checkbox->setChecked(Settings::getValue("Components/maps").toBool());
  74. ui->patch_loadscreens_checkbox->setChecked(Settings::getValue("Components/loadscreens").toBool());
  75. ui->patch_textures_checkbox->setChecked(Settings::getValue("Components/textures").toBool());
  76. ui->patch_sounds_checkbox->setChecked(Settings::getValue("Components/sounds").toBool());
  77. ui->patch_video_checkbox->setChecked(Settings::getValue("Components/videos").toBool());
  78. ui->micropatch_checkbox->setChecked(Settings::getValue("Components/micropatch").toBool());
  79. int interface_scale = Settings::getValue("General/UI_scale").toInt();
  80. int interface_scale_combobox_index = 0;
  81. if (interface_scale == 50)
  82. interface_scale_combobox_index = 0;
  83. if (interface_scale == 75)
  84. interface_scale_combobox_index = 1;
  85. if (interface_scale == 100)
  86. interface_scale_combobox_index = 2;
  87. if (interface_scale == 125)
  88. interface_scale_combobox_index = 3;
  89. if (interface_scale == 150)
  90. interface_scale_combobox_index = 4;
  91. if (interface_scale == 175)
  92. interface_scale_combobox_index = 5;
  93. if (interface_scale == 200)
  94. interface_scale_combobox_index = 6;
  95. ui->interface_scale_combobox->setCurrentIndex(interface_scale_combobox_index);
  96. }
  97. void SettingsWidget::updateFontsSizes()
  98. {
  99. ui->frame_title->setFont(trajan_10pt);
  100. ui->group_label_1->setFont(trajan_9pt);
  101. ui->group_label_2->setFont(trajan_9pt);
  102. ui->group_label_3->setFont(trajan_9pt);
  103. ui->group_label_4->setFont(trajan_9pt);
  104. ui->patch_installing_label->setFont(crimson_12pt);
  105. ui->apply_changes_button->setFont(trajan_10pt);
  106. ui->sub_entry_1_title->setFont(garamond_11pt);
  107. ui->sub_entry_2_title->setFont(garamond_11pt);
  108. ui->sub_entry_3_title->setFont(garamond_11pt);
  109. ui->sub_entry_4_title->setFont(garamond_11pt);
  110. ui->backup_create_button->setFont(trajan_8pt);
  111. ui->backup_restore_button->setFont(trajan_8pt);
  112. ui->backup_remove_button->setFont(trajan_8pt);
  113. ui->game_folder_label->setFont(crimson_11pt);
  114. ui->game_folder_path->setFont(crimson_11pt);
  115. ui->lotro_base_language_label->setFont(crimson_11pt);
  116. ui->lotro_base_language_combobox->setFont(crimson_11pt);
  117. ui->lotro_base_language_combobox->insertItem(ui->lotro_base_language_combobox->count(), ""); // is needed to invoke elements resize
  118. ui->lotro_base_language_combobox->removeItem(ui->lotro_base_language_combobox->count() - 1);
  119. ui->skiprawdownload_checkbox->setFont(crimson_11pt);
  120. ui->nosplashscreen_checkbox->setFont(crimson_11pt);
  121. ui->backup_status_label->setFont(crimson_11pt);
  122. ui->backup_status_value->setFont(crimson_11pt);
  123. ui->backup_creation_time_label->setFont(crimson_11pt);
  124. ui->backup_creation_time_value->setFont(crimson_11pt);
  125. ui->backup_path_label->setFont(crimson_11pt);
  126. ui->backup_path_value->setFont(crimson_11pt);
  127. ui->patch_emotes_checkbox->setFont(crimson_11pt);
  128. ui->patch_items_checkbox->setFont(crimson_11pt);
  129. ui->patch_loadscreens_checkbox->setFont(crimson_11pt);
  130. ui->patch_maps_checkbox->setFont(crimson_11pt);
  131. ui->patch_sounds_checkbox->setFont(crimson_11pt);
  132. ui->patch_textures_checkbox->setFont(crimson_11pt);
  133. ui->patch_video_checkbox->setFont(crimson_11pt);
  134. ui->patch_texts_checkbox->setFont(crimson_11pt);
  135. ui->micropatch_checkbox->setFont(crimson_11pt);
  136. ui->interface_scale_label->setFont(crimson_11pt);
  137. ui->interface_scale_combobox->setFont(crimson_11pt);
  138. ui->interface_scale_combobox->insertItem(ui->interface_scale_combobox->count(), "250%"); // is needed to invoke elements resize
  139. ui->interface_scale_combobox->removeItem(ui->interface_scale_combobox->count() - 1);
  140. ui->texts_block_label->setFont(crimson_12pt);
  141. ui->graphics_block_label->setFont(crimson_12pt);
  142. ui->sounds_block_label->setFont(crimson_12pt);
  143. }
  144. void SettingsWidget::resizeEvent(QResizeEvent *)
  145. {
  146. updateFontsSizes();
  147. double coefficient = window_width / default_window_width;
  148. ui->frame_title->move(QPoint(45, 33) * coefficient);
  149. ui->frame_title->resize(QSize(201, 21) * coefficient);
  150. ui->checkpoints_list->move(QPoint(25, 70) * coefficient);
  151. ui->checkpoints_list->resize(QSize(265, 451) * coefficient);
  152. ui->content_scroll_area->move(QPoint(310, 0) * coefficient);
  153. ui->content_scroll_area->resize(QSize(671, 521) * coefficient);
  154. ui->content_widget->setMinimumWidth(650 * coefficient);
  155. ui->change_folder_button->setMinimumSize(QSize(36, 32) * coefficient);
  156. ui->patch_texts_icon->setMinimumSize(QSize(80, 80) * coefficient);
  157. ui->patch_graphics_icon->setMinimumSize(QSize(80, 80) * coefficient);
  158. ui->patch_sounds_icon->setMinimumSize(QSize(80, 80) * coefficient);
  159. ui->apply_changes_button->setMinimumSize(QSize(160, 60) * coefficient);
  160. }
  161. void SettingsWidget::processParameterChange() {
  162. if (!settings_changed_) {
  163. settings_changed_ = true;
  164. emit SettingsChanged();
  165. ui->apply_changes_label->show();
  166. ui->apply_changes_button->show();
  167. }
  168. }
  169. void SettingsWidget::checkIfParametersWereReset() {
  170. if (settings_changed_ && settings_backup_ == Settings::createSettingsBackup()) {
  171. settings_changed_ = false;
  172. emit SettingsReset();
  173. ui->apply_changes_label->hide();
  174. ui->apply_changes_button->hide();
  175. }
  176. }
  177. void SettingsWidget::on_change_folder_button_clicked()
  178. {
  179. QStringList known_paths = FileSystem::recognizeRegistryLotroPath();
  180. QString template_path = known_paths.empty() ? "" : known_paths[0];
  181. QString str = QFileDialog::getOpenFileName(0, "Расположение игры", template_path, "LotroLauncher.exe");
  182. if (str.isEmpty()) {
  183. return;
  184. }
  185. QString game_folder= str.replace("/LotroLauncher.exe", "").replace("\\", "/").replace("//", "/") + "/";
  186. if (settings_backup_["Lotro/game_path"].toString() == game_folder) {
  187. return;
  188. }
  189. processParameterChange();
  190. settings_backup_["Lotro/game_path"] = game_folder;
  191. ui->game_folder_path->setText(game_folder);
  192. checkIfParametersWereReset();
  193. }
  194. void SettingsWidget::on_lotro_base_language_combobox_currentIndexChanged(int index)
  195. {
  196. QString value = "English";
  197. if (index == 0)
  198. value = "English";
  199. if (index == 1)
  200. value = "DE";
  201. if (index == 2)
  202. value = "FR";
  203. if (settings_backup_["Lotro/original_locale"].toString() == value) {
  204. return;
  205. }
  206. processParameterChange();
  207. settings_backup_["Lotro/original_locale"] = value;
  208. checkIfParametersWereReset();
  209. }
  210. void SettingsWidget::on_skiprawdownload_checkbox_stateChanged(int arg1) {
  211. if (arg1 == Qt::Checked) {
  212. Settings::setValue("Lotro/skip_raw_download", true);
  213. settings_backup_["Lotro/skip_raw_download"] = true;
  214. }
  215. if (arg1 == Qt::Unchecked) {
  216. Settings::setValue("Lotro/skip_raw_download", false);
  217. settings_backup_["Lotro/skip_raw_download"] = false;
  218. }
  219. }
  220. void SettingsWidget::on_nosplashscreen_checkbox_stateChanged(int arg1)
  221. {
  222. if (arg1 == Qt::Checked) {
  223. Settings::setValue("Lotro/no_splash_screen", true);
  224. settings_backup_["Lotro/no_splash_screen"] = true;
  225. }
  226. if (arg1 == Qt::Unchecked) {
  227. Settings::setValue("Lotro/no_splash_screen", false);
  228. settings_backup_["Lotro/no_splash_screen"] = false;
  229. }
  230. }
  231. void SettingsWidget::on_backup_create_button_clicked()
  232. {
  233. if (settings_changed_) {
  234. QMessageBox::warning(nullptr, "Невозможно выполнить действие!", "Некоторые настройки были изменены. Чтобы создать резервную копию, примените или отмените изменения!");
  235. return;
  236. }
  237. if (Settings::getValue("Backup/installed").toBool()) {
  238. int result = QMessageBox::question(nullptr, "Подтвердите действие", "Резервная копия уже существует. Вы хотите перезаписать существующую копию?", QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton);
  239. if (result != QMessageBox::Yes) {
  240. return;
  241. }
  242. }
  243. QMetaObject::invokeMethod(legacy_patches_, "createBackup", Qt::QueuedConnection);
  244. }
  245. void SettingsWidget::on_backup_restore_button_clicked()
  246. {
  247. if (!Settings::getValue("Backup/installed").toBool()) {
  248. QMessageBox::warning(nullptr, "Невозможно выполнить действие.", "Резервная копия не найдена. Создайте резервную копию, чтобы иметь возможность восстановления данных.");
  249. return;
  250. }
  251. if (settings_changed_) {
  252. QMessageBox::warning(nullptr, "Невозможно выполнить действие.", "Некоторые настройки были изменены. Чтобы восстановить данные из резервной копии, примените или отмените изменения!");
  253. return;
  254. }
  255. QMetaObject::invokeMethod(legacy_patches_, "restoreFromBackup", Qt::QueuedConnection);
  256. }
  257. void SettingsWidget::on_backup_remove_button_clicked()
  258. {
  259. if (Settings::getValue("Backup/installed").toBool()) {
  260. int result = QMessageBox::question(nullptr, "Подтвердите действие", "Вы уверены, что хотите удалить существующую резервную копию?", QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton);
  261. if (result != QMessageBox::Yes) {
  262. return;
  263. }
  264. } else {
  265. QMessageBox::information(nullptr, "Невозможно выполнить действие.", "Удаление невозможно: резервной копии не существует.");
  266. return;
  267. }
  268. QMetaObject::invokeMethod(legacy_patches_, "removeBackup", Qt::QueuedConnection);
  269. }
  270. void SettingsWidget::on_patch_texts_checkbox_clicked()
  271. {
  272. processParameterChange();
  273. if (ui->patch_texts_checkbox->isChecked()) {
  274. settings_backup_["Components/texts_main"] = true;
  275. } else {
  276. settings_backup_["Components/texts_main"] = false;
  277. }
  278. checkIfParametersWereReset();
  279. }
  280. void SettingsWidget::on_patch_items_checkbox_clicked()
  281. {
  282. processParameterChange();
  283. if (ui->patch_items_checkbox->isChecked()) {
  284. settings_backup_["Components/texts_items"] = true;
  285. } else {
  286. settings_backup_["Components/texts_items"] = false;
  287. }
  288. checkIfParametersWereReset();
  289. }
  290. void SettingsWidget::on_patch_emotes_checkbox_clicked()
  291. {
  292. processParameterChange();
  293. if (ui->patch_emotes_checkbox->isChecked()) {
  294. settings_backup_["Components/texts_emotes"] = true;
  295. } else {
  296. settings_backup_["Components/texts_emotes"] = false;
  297. }
  298. checkIfParametersWereReset();
  299. }
  300. void SettingsWidget::on_patch_maps_checkbox_clicked()
  301. {
  302. processParameterChange();
  303. if (ui->patch_maps_checkbox->isChecked()) {
  304. settings_backup_["Components/maps"] = true;
  305. } else {
  306. settings_backup_["Components/maps"] = false;
  307. }
  308. checkIfParametersWereReset();
  309. }
  310. void SettingsWidget::on_patch_textures_checkbox_clicked()
  311. {
  312. processParameterChange();
  313. if (ui->patch_textures_checkbox->isChecked()) {
  314. settings_backup_["Components/textures"] = true;
  315. } else {
  316. settings_backup_["Components/textures"] = false;
  317. }
  318. checkIfParametersWereReset();
  319. }
  320. void SettingsWidget::on_patch_loadscreens_checkbox_clicked()
  321. {
  322. processParameterChange();
  323. if (ui->patch_loadscreens_checkbox->isChecked()) {
  324. settings_backup_["Components/loadscreens"] = true;
  325. } else {
  326. settings_backup_["Components/loadscreens"] = false;
  327. }
  328. checkIfParametersWereReset();
  329. }
  330. void SettingsWidget::on_patch_sounds_checkbox_clicked()
  331. {
  332. processParameterChange();
  333. if (ui->patch_sounds_checkbox->isChecked()) {
  334. settings_backup_["Components/sounds"] = true;
  335. } else {
  336. settings_backup_["Components/sounds"] = false;
  337. }
  338. checkIfParametersWereReset();
  339. }
  340. void SettingsWidget::on_patch_video_checkbox_clicked()
  341. {
  342. processParameterChange();
  343. if (ui->patch_video_checkbox->isChecked()) {
  344. settings_backup_["Components/videos"] = true;
  345. } else {
  346. settings_backup_["Components/videos"] = false;
  347. }
  348. checkIfParametersWereReset();
  349. }
  350. void SettingsWidget::on_patch_force_apply_button_clicked()
  351. {
  352. // TODO(endevir): Implement
  353. }
  354. void SettingsWidget::on_micropatch_checkbox_clicked()
  355. {
  356. processParameterChange();
  357. if (ui->micropatch_checkbox->isChecked()) {
  358. settings_backup_["Components/micropatch"] = true;
  359. } else {
  360. settings_backup_["Components/micropatch"] = false;
  361. }
  362. checkIfParametersWereReset();
  363. }
  364. void SettingsWidget::on_interface_scale_combobox_currentIndexChanged(const QString &arg1)
  365. {
  366. MainWindow* window = qobject_cast<MainWindow*>(qApp->activeWindow());
  367. if (!window) {
  368. ui->interface_scale_combobox->setCurrentText(Settings::getValue("General/UI_scale").toString() + "%");
  369. qDebug() << "CANNOT FIND MAIN WINDOW!!!";
  370. return;
  371. }
  372. int value = arg1.left(arg1.length() - 1).toInt();
  373. window->resize(default_window_width * value / 100, default_window_height * value / 100);
  374. Settings::setValue("General/UI_scale", value);
  375. settings_backup_["General/UI_scale"] = value;
  376. }
  377. void SettingsWidget::onPatchTotalOperationsStarted()
  378. {
  379. patch_operations_running_ = true;
  380. ui->patch_installing_label->show();
  381. ui->change_folder_button->setEnabled(false);
  382. ui->lotro_base_language_combobox->setEnabled(false);
  383. ui->backup_create_button->setEnabled(false);
  384. ui->backup_restore_button->setEnabled(false);
  385. ui->backup_remove_button->setEnabled(false);
  386. ui->patch_texts_checkbox->setEnabled(false);
  387. ui->patch_items_checkbox->setEnabled(false);
  388. ui->patch_emotes_checkbox->setEnabled(false);
  389. ui->patch_maps_checkbox->setEnabled(false);
  390. ui->patch_textures_checkbox->setEnabled(false);
  391. ui->patch_loadscreens_checkbox->setEnabled(false);
  392. ui->patch_sounds_checkbox->setEnabled(false);
  393. ui->patch_video_checkbox->setEnabled(false);
  394. ui->patch_force_apply_button->setEnabled(false);
  395. ui->micropatch_checkbox->setEnabled(false);
  396. }
  397. void SettingsWidget::onPatchTotalOperationsFinished()
  398. {
  399. patch_operations_running_ = false;
  400. ui->patch_installing_label->hide();
  401. settings_backup_ = Settings::createSettingsBackup();
  402. ui->change_folder_button->setEnabled(true);
  403. ui->lotro_base_language_combobox->setEnabled(true);
  404. ui->backup_create_button->setEnabled(true);
  405. ui->backup_restore_button->setEnabled(true);
  406. ui->backup_remove_button->setEnabled(true);
  407. ui->patch_texts_checkbox->setEnabled(true);
  408. ui->patch_items_checkbox->setEnabled(true);
  409. ui->patch_emotes_checkbox->setEnabled(true);
  410. ui->patch_maps_checkbox->setEnabled(true);
  411. ui->patch_textures_checkbox->setEnabled(true);
  412. ui->patch_loadscreens_checkbox->setEnabled(true);
  413. ui->patch_sounds_checkbox->setEnabled(true);
  414. ui->patch_video_checkbox->setEnabled(true);
  415. ui->patch_force_apply_button->setEnabled(true);
  416. ui->micropatch_checkbox->setEnabled(true);
  417. }
  418. void SettingsWidget::on_apply_changes_button_clicked()
  419. {
  420. Settings::restoreFromSettingsBackup(settings_backup_);
  421. Settings::updatePatchComponentsDependencies();
  422. settings_changed_ = false;
  423. ui->apply_changes_label->hide();
  424. ui->apply_changes_button->hide();
  425. emit SettingsApplied();
  426. }