Browse Source

Implemented base game settings

Ivan Arkhipov 3 years ago
parent
commit
dd4d411706

+ 7 - 9
src/Legacy/models/patchinstaller.cpp

@@ -25,15 +25,18 @@ QString getComponentNameFromId(int id) {
 PatchInstaller::PatchInstaller(QObject *parent)
     : QObject(parent)
     , orig_files_db(QSqlDatabase::addDatabase("QSQLITE")) {
+        client_local_file_ = new LOTRO_DAT::DatFile(100);
+        client_general_file_ = new LOTRO_DAT::DatFile(101);
 }
 
 bool PatchInstaller::initialised() {
-    return client_general_file_ && client_local_file_
-            && client_general_file_->Initialized() && client_local_file_->Initialized();
+    return client_general_file_->Initialized() && client_local_file_->Initialized();
 }
 
 PatchInstaller::~PatchInstaller() {
     deinit();
+    delete client_local_file_;
+    delete client_general_file_;
 }
 
 // ############## PRIVATE ############## //
@@ -54,10 +57,8 @@ bool PatchInstaller::datPathIsRelevant() {
 
 void PatchInstaller::deinit() {
     orig_files_db.close();
-    if (client_local_file_)
-        client_local_file_->Deinit();
-    if (client_general_file_)
-        client_general_file_->Deinit();
+    client_local_file_->Deinit();
+    client_general_file_->Deinit();
     emit deinitialized();
 }
 
@@ -257,9 +258,6 @@ void PatchInstaller::init()
 
     // Initialising client_local_*.dat file and client_general.dat
 
-    client_local_file_ = new LOTRO_DAT::DatFile(1);
-    client_general_file_ = new LOTRO_DAT::DatFile(2);
-
     auto client_local_init_res = client_local_file_->Init(client_local_filepath.toStdString());
     auto client_general_init_res = client_general_file_->Init(client_general_filepath.toStdString());
 

+ 1 - 2
src/Legacy/models/patchinstaller.h

@@ -42,8 +42,6 @@ private:
 
     bool datPathIsRelevant();
 
-    void deinit();
-
     void installPatch(QString patch_name, LOTRO_DAT::Database* database);
 
     void installLoadscreens(LOTRO_DAT::Database* database);
@@ -51,6 +49,7 @@ private:
     void installVideos(LOTRO_DAT::Database* database);
 
 public slots:
+    void deinit();
     void init();
     void startGame(bool freeze_updates);
     void startPatchInstallationChain();

+ 76 - 0
src/Legacy/widgets/gamesettings.cpp

@@ -1,15 +1,91 @@
 #include "gamesettings.h"
 #include "ui_gamesettings.h"
 
+#include "models/settings.h"
+#include "models/filesystem.h"
+#include "models/patchinstaller.h"
+
+#include <QFileDialog>
+
 GameSettings::GameSettings(QWidget *parent) :
     QWidget(parent),
     ui(new Ui::GameSettings)
 {
     ui->setupUi(this);
     setAttribute(Qt::WA_StyledBackground, true);
+    setActualParametersValues();
 }
 
 GameSettings::~GameSettings()
 {
     delete ui;
 }
+
+void GameSettings::setActualParametersValues()
+{
+    QString game_path = Settings::getValue("Lotro/game_path").toString();
+    if (game_path == "none") {
+        game_path = "Путь к файлам игры не выбран";
+    }
+    ui->game_folder_path->setText(game_path);
+
+    QString original_locale = Settings::getValue("Lotro/original_locale").toString();
+    int index = 0;
+
+    if (original_locale == "English")
+        index = 0;
+    if (original_locale == "DE")
+        index = 1;
+    if (original_locale == "FR")
+        index = 2;
+    ui->lotro_base_language_combobox->setCurrentIndex(index);
+}
+
+void GameSettings::on_change_folder_button_clicked()
+{
+    QStringList known_paths = FileSystem::recognizeRegistryLotroPath();
+    QString template_path = known_paths.empty() ? "" : known_paths[0];
+    QString str = QFileDialog::getOpenFileName(0, "Расположение игры", template_path, "LotroLauncher.exe");
+
+    if (str.isEmpty()) {
+        return;
+    }
+
+    QString game_folder= str.replace("/LotroLauncher.exe", "").replace("\\", "/").replace("//", "/") + "/";
+    ui->game_folder_path->setText(game_folder);
+
+    Settings::setValue("Lotro/game_path", game_folder);
+
+    QMetaObject::invokeMethod(&PatchInstaller::instance(), &PatchInstaller::deinit, Qt::QueuedConnection);
+    QMetaObject::invokeMethod(&PatchInstaller::instance(), &PatchInstaller::init, Qt::QueuedConnection);
+}
+
+void GameSettings::on_lotro_base_language_combobox_currentIndexChanged(int index)
+{
+    QString value = "English";
+
+    if (index == 0)
+        value = "English";
+    if (index == 1)
+        value = "DE";
+    if (index == 2)
+        value = "FR";
+
+    Settings::setValue("Lotro/original_locale", value);
+
+    QMetaObject::invokeMethod(&PatchInstaller::instance(), &PatchInstaller::deinit, Qt::QueuedConnection);
+    QMetaObject::invokeMethod(&PatchInstaller::instance(), &PatchInstaller::init, Qt::QueuedConnection);
+}
+
+
+void GameSettings::onPatchTotalOperationsStarted() {
+    ui->change_folder_button->setDisabled(true);
+    ui->lotro_base_language_combobox->setDisabled(true);
+}
+
+void GameSettings::onPatchTotalOperationsFinished() {
+    ui->change_folder_button->setEnabled(true);
+    ui->lotro_base_language_combobox->setEnabled(true);
+}
+
+

+ 12 - 0
src/Legacy/widgets/gamesettings.h

@@ -15,6 +15,18 @@ public:
     explicit GameSettings(QWidget *parent = nullptr);
     ~GameSettings();
 
+public slots:
+    void setActualParametersValues();
+
+private slots:
+    void on_change_folder_button_clicked();
+
+    void on_lotro_base_language_combobox_currentIndexChanged(int index);
+
+    void onPatchTotalOperationsStarted();
+
+    void onPatchTotalOperationsFinished();
+
 private:
     Ui::GameSettings *ui;
 };

+ 1 - 1
src/Legacy/widgets/statuswidget.cpp

@@ -377,7 +377,7 @@ void StatusWidget::showComponentsStatus() {
 
 void StatusWidget::hideComponentsStatus() {
     QPropertyAnimation *animation = new QPropertyAnimation(_components_status_opacity_effect, "opacity");
-    animation->setDuration(300);
+    animation->setDuration(1000);
     animation->setStartValue(1);
     animation->setEndValue(0);
     animation->setEasingCurve(QEasingCurve::InBack);

+ 0 - 1
src/Legacy/widgets/translationcomponents.cpp

@@ -27,7 +27,6 @@ TranslationComponents::TranslationComponents(QWidget *parent) :
     ui->loadscreens_block_label->setTooltipParentWidget(parentWidget());
     ui->loadscreens_block_label->raise();
     ui->loadscreens_block_label->setTooltipText("Загрузочные экраны от команды Наследия");
-
 }
 
 TranslationComponents::~TranslationComponents()