gamesettings.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "gamesettings.h"
  2. #include "ui_gamesettings.h"
  3. #include "models/settings.h"
  4. #include "models/filesystem.h"
  5. #include "models/patchinstaller.h"
  6. #include "models/patchdownloader.h"
  7. #include "legacyapplication.h"
  8. #include <QFileDialog>
  9. GameSettings::GameSettings(QWidget *parent) :
  10. QWidget(parent),
  11. ui(new Ui::GameSettings)
  12. {
  13. ui->setupUi(this);
  14. setAttribute(Qt::WA_StyledBackground, true);
  15. setActualParametersValues();
  16. connect(&PatchInstaller::instance(), &PatchInstaller::started, this, &GameSettings::onPatchTotalOperationsStarted);
  17. connect(&PatchInstaller::instance(), &PatchInstaller::finished, this, &GameSettings::onPatchTotalOperationsFinished);
  18. connect(&PatchDownloader::instance(), &PatchDownloader::started, this, &GameSettings::onPatchTotalOperationsStarted);
  19. connect(&PatchDownloader::instance(), &PatchDownloader::finished, this, &GameSettings::onPatchTotalOperationsFinished);
  20. }
  21. GameSettings::~GameSettings()
  22. {
  23. delete ui;
  24. }
  25. void GameSettings::setActualParametersValues()
  26. {
  27. QString game_path = Settings::getValue("Lotro/game_path").toString();
  28. if (game_path == "none") {
  29. game_path = "(не выбрана)";
  30. }
  31. ui->game_folder_path->setText(game_path);
  32. QString original_locale = Settings::getValue("Lotro/original_locale").toString();
  33. int index = 0;
  34. if (original_locale == "English")
  35. index = 0;
  36. if (original_locale == "DE")
  37. index = 1;
  38. if (original_locale == "FR")
  39. index = 2;
  40. ui->lotro_base_language_combobox->setCurrentIndex(index);
  41. }
  42. void GameSettings::on_change_folder_button_clicked()
  43. {
  44. QStringList known_paths = FileSystem::recognizeRegistryLotroPath();
  45. QString template_path = known_paths.empty() ? "" : known_paths[0];
  46. QString str = QFileDialog::getOpenFileName(0, "Расположение игры", template_path, "LotroLauncher.exe");
  47. if (str.isEmpty()) {
  48. return;
  49. }
  50. QString game_folder= str.replace("/LotroLauncher.exe", "").replace("\\", "/").replace("//", "/") + "/";
  51. ui->game_folder_path->setText(game_folder);
  52. Settings::setValue("Lotro/game_path", game_folder);
  53. QMetaObject::invokeMethod(&PatchInstaller::instance(), &PatchInstaller::deinit, Qt::QueuedConnection);
  54. QMetaObject::invokeMethod(&LegacyApplication::instance(), &LegacyApplication::InitModules, Qt::DirectConnection);
  55. }
  56. void GameSettings::on_lotro_base_language_combobox_currentIndexChanged(int index)
  57. {
  58. QString value = "English";
  59. if (index == 0)
  60. value = "English";
  61. if (index == 1)
  62. value = "DE";
  63. if (index == 2)
  64. value = "FR";
  65. Settings::setValue("Lotro/original_locale", value);
  66. QMetaObject::invokeMethod(&PatchInstaller::instance(), &PatchInstaller::deinit, Qt::QueuedConnection);
  67. QMetaObject::invokeMethod(&LegacyApplication::instance(), &LegacyApplication::InitModules, Qt::DirectConnection);
  68. }
  69. void GameSettings::onPatchTotalOperationsStarted() {
  70. ui->change_folder_button->setEnabled(false);
  71. ui->lotro_base_language_combobox->setEnabled(false);
  72. }
  73. void GameSettings::onPatchTotalOperationsFinished() {
  74. ui->change_folder_button->setEnabled(true);
  75. ui->lotro_base_language_combobox->setEnabled(true);
  76. }