Browse Source

Finished with translation components functionality

Ivan Arkhipov 3 years ago
parent
commit
e88fedf845

+ 36 - 4
src/Legacy/widgets/statuswidget.cpp

@@ -21,11 +21,11 @@ StatusWidget::StatusWidget(QWidget *parent)
     last_statusbar_update_time_.start();
     ui->galadriel_tooltip_example->hide();
 
-    connect(ui->weekly_code_widget, &WeeklyCodeWidget::showCompletedTooltip, this, [this](){setToolTipMessage("ЕЖЕНЕДЕЛЬНЫЙ КОД СКОПИРОВАН В БУФЕР ОБМЕНА", E_INFO);});
-    connect(ui->weekly_code_widget, &WeeklyCodeWidget::showHelpTooltip, this, [this](){setToolTipMessage("КЛИКНИТЕ ПО ЕЖЕНЕДЕЛЬНОМУ КОДУ, ЧТОБЫ СКОПИРОВАТЬ ЕГО", E_INFO);});
+    connect(ui->weekly_code_widget, &WeeklyCodeWidget::showCompletedTooltip, this, [this](){setToolTipMessage("Еженедельный код скопирован в буфер обмена.", E_INFO);});
+    connect(ui->weekly_code_widget, &WeeklyCodeWidget::showHelpTooltip, this, [this](){setToolTipMessage("Нажмите по еженедельному коду, чтобы скопировать его.", E_INFO);});
     connect(ui->weekly_code_widget, &WeeklyCodeWidget::showNoTooltip, this, [this](){unsetToolTipMessage(E_INFO);});
 
-    connect(ui->news_list, &NewsListWidget::showHelpToolTip, this, [this](){setToolTipMessage("НАЖМИТЕ НА ЗАГОЛОВОК НОВОСТИ, ЧТОБЫ ОТКРЫТЬ ЕЕ В БРАУЗЕРЕ", E_INFO);});
+    connect(ui->news_list, &NewsListWidget::showHelpToolTip, this, [this](){setToolTipMessage("Нажмите на заголовок новости, чтобы открыть её в браузере.", E_INFO);});
     connect(ui->news_list, &NewsListWidget::showNoToolTip, this, [this](){unsetToolTipMessage(E_INFO);});
 
     connect(ui->server_status_widget, &ServerStatusWidget::showServersTooltip, this, [this](QString message){setToolTipMessage(message, E_INFO);});
@@ -38,10 +38,15 @@ StatusWidget::StatusWidget(QWidget *parent)
     connect(&PatchInstaller::instance(), &PatchInstaller::started, this, &StatusWidget::onPatchInstallerStarted);
     connect(&PatchInstaller::instance(), &PatchInstaller::progressChanged, this, &StatusWidget::onPatchInstallerProgressChanged);
     connect(&PatchInstaller::instance(), &PatchInstaller::finished, this, &StatusWidget::onPatchInstallerFinished);
+
     connect(&PatchInstaller::instance(), &PatchInstaller::videosDownloadProgressChanged, this, &StatusWidget::onPatchInstallerVideoProgressChanged);
+
     connect(&PatchInstaller::instance(), &PatchInstaller::successfullyInitialized, this, &StatusWidget::showComponentsStatus);
     connect(&PatchInstaller::instance(), &PatchInstaller::deinitialized, this, &StatusWidget::hideComponentsStatus);
 
+    connect(ui->b_components_status, &TranslationComponents::needToPatch, this, &StatusWidget::onTranslationComponentsNeedToPatch);
+    connect(ui->b_components_status, &TranslationComponents::noNeedToPatch, this, &StatusWidget::onTranslationComponentsNoNeedToPatch);
+
     ui->b_components_status->hide();
 
     generateRandomTooltipMessage();
@@ -365,7 +370,6 @@ void StatusWidget::on_check_for_updates_button_clicked()
     QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::startPatchDownloaderChain, Qt::QueuedConnection);
 }
 
-
 void StatusWidget::showComponentsStatus() {
     QPropertyAnimation *animation = new QPropertyAnimation(_components_status_opacity_effect, "opacity");
     animation->setDuration(1000);
@@ -385,3 +389,31 @@ void StatusWidget::hideComponentsStatus() {
     connect(animation, &QPropertyAnimation::finished, ui->b_components_status, &QWidget::hide);
 }
 
+void StatusWidget::onTranslationComponentsNeedToPatch() {
+    _need_to_install_patches = true;
+    updateButtonStatus();
+
+}
+
+void StatusWidget::onTranslationComponentsNoNeedToPatch() {
+    _need_to_install_patches = false;
+    updateButtonStatus();
+}
+
+void StatusWidget::updateButtonStatus() {
+    if (_need_to_update) {
+        setToolTipMessage("Доступна новая версия русификации. Нажмите \"Обновить\", чтобы начать загрузку.", ToolTipState::E_INFO);
+        ui->game_button->setText("ОБНОВИТЬ");
+    } else {
+        unsetToolTipMessage(ToolTipState::E_INFO);
+        ui->game_button->setText("ИГРАТЬ");
+    }
+
+    if (_need_to_install_patches) {
+        setToolTipMessage("Нажмите \"Установить\", чтобы начать процесс русификации.", ToolTipState::E_INFO);
+        ui->game_button->setText("установить");
+    } else {
+        unsetToolTipMessage(ToolTipState::E_INFO);
+        ui->game_button->setText("ИГРАТЬ");
+    }
+}

+ 8 - 0
src/Legacy/widgets/statuswidget.h

@@ -76,8 +76,13 @@ private slots:
 
     void hideComponentsStatus();
 
+    void onTranslationComponentsNeedToPatch();
+
+    void onTranslationComponentsNoNeedToPatch();
+
 private:
     void createTooltipMessageWidget(QString tooltip_id);
+    void updateButtonStatus();
 
 private:
     Ui::StatusWidget *ui;
@@ -101,6 +106,9 @@ private:
     QString error_timeout_message_ = "";
 
     QGraphicsOpacityEffect* _components_status_opacity_effect;
+
+    bool _need_to_install_patches = false;
+    bool _need_to_update = false;
 };
 
 #endif // STATUSWIDGET_H

+ 4 - 4
src/Legacy/widgets/statuswidget.ui

@@ -225,9 +225,9 @@ QPushButton#game_button:disabled {
    </property>
    <property name="geometry">
     <rect>
-     <x>310</x>
-     <y>420</y>
-     <width>491</width>
+     <x>290</x>
+     <y>425</y>
+     <width>521</width>
      <height>51</height>
     </rect>
    </property>
@@ -245,7 +245,7 @@ QPushButton#game_button:disabled {
     <string>TEST TOOLTIP USED FOR STYLE DESC</string>
    </property>
    <property name="alignment">
-    <set>Qt::AlignCenter</set>
+    <set>Qt::AlignBottom|Qt::AlignHCenter</set>
    </property>
    <property name="wordWrap">
     <bool>true</bool>

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

@@ -2,6 +2,8 @@
 #include "ui_translationcomponents.h"
 
 #include "models/patchinstaller.h"
+#include "models/patchdownloader.h"
+#include "models/settings.h"
 
 TranslationComponents::TranslationComponents(QWidget *parent) :
     QWidget(parent),
@@ -13,24 +15,34 @@ TranslationComponents::TranslationComponents(QWidget *parent) :
     ui->texts_block_label->setTooltipParentWidget(parentWidget());
     ui->texts_block_label->raise();
     ui->texts_block_label->setTooltipText("Перевод всех текстовых элементов в игре: названий, квестов, меню и т.д.");
+    connect(ui->texts_block_switch, &SwitchButton::valueChanged, this, &TranslationComponents::onTextsChange);
 
     ui->graphics_block_label->setTooltipParentWidget(parentWidget());
     ui->graphics_block_label->raise();
     ui->graphics_block_label->setTooltipText("Переведенные карты локаций и элементы графического интерфейса.");
+    connect(ui->graphics_block_switch, &SwitchButton::valueChanged, this, &TranslationComponents::onImagesChange);
 
     ui->video_block_label->setTooltipParentWidget(parentWidget());
     ui->video_block_label->raise();
     ui->video_block_label->setTooltipText("Переведенные и озвученные видеоролики и кат-сцены.");
+    connect(ui->video_block_switch, &SwitchButton::valueChanged, this, &TranslationComponents::onVideosChange);
 
     ui->audio_block_label->setTooltipParentWidget(parentWidget());
     ui->audio_block_label->raise();
     ui->audio_block_label->setTooltipText("Переведенные и озвученные реплики персонажей.");
+    connect(ui->audio_block_switch, &SwitchButton::valueChanged, this, &TranslationComponents::onSoundsChange);
 
     ui->loadscreens_block_label->setTooltipParentWidget(parentWidget());
     ui->loadscreens_block_label->raise();
     ui->loadscreens_block_label->setTooltipText("Загрузочные экраны от команды Наследия");
+    connect(ui->loadscreens_block_switch, &SwitchButton::valueChanged, this, &TranslationComponents::onLoadscreensChange);
 
     connect(&PatchInstaller::instance(), &PatchInstaller::successfullyInitialized, this, &TranslationComponents::resetSwitchesToDefault);
+    connect(&PatchInstaller::instance(), &PatchInstaller::started, this, &TranslationComponents::disableControls);
+    connect(&PatchInstaller::instance(), &PatchInstaller::finished, this, &TranslationComponents::enableControls);
+    connect(&PatchDownloader::instance(), &PatchDownloader::started, this, &TranslationComponents::disableControls);
+    connect(&PatchDownloader::instance(), &PatchDownloader::finished, this, &TranslationComponents::enableControls);
+
 }
 
 TranslationComponents::~TranslationComponents()
@@ -41,9 +53,89 @@ TranslationComponents::~TranslationComponents()
 void TranslationComponents::resetSwitchesToDefault() {
     PatchInstaller::AppliedPatchesInfo info = PatchInstaller::instance().getPatchesInfo();
 
+    Settings::setValue("Components/texts_main", info.texts_version != 0);
+    Settings::setValue("Components/texts_emotes", info.texts_version != 0);
+    Settings::setValue("Components/texts_items", info.texts_version != 0);
+    Settings::setValue("Components/texts_videos", info.videos_version != 0);
+    Settings::setValue("Components/maps", info.graphics_version != 0);
+    Settings::setValue("Components/textures", info.graphics_version != 0);
+    Settings::setValue("Components/sounds", info.audio_version != 0);
+    Settings::setValue("Components/videos", info.videos_version != 0);
+    Settings::setValue("Components/loadscreens", info.loadscreens_version != 0);
+
     ui->texts_block_switch->setValue(info.texts_version != 0);
     ui->graphics_block_switch->setValue(info.graphics_version != 0);
     ui->video_block_switch->setValue(info.videos_version != 0);
     ui->audio_block_switch->setValue(info.audio_version != 0);
     ui->loadscreens_block_switch->setValue(info.loadscreens_version != 0);
 }
+
+void TranslationComponents::disableControls() {
+    ui->texts_block_switch->setEnabled(false);
+    ui->graphics_block_switch->setEnabled(false);
+    ui->video_block_switch->setEnabled(false);
+    ui->audio_block_switch->setEnabled(false);
+    ui->loadscreens_block_switch->setEnabled(false);
+}
+
+void TranslationComponents::enableControls() {
+    ui->texts_block_switch->setEnabled(true);
+    ui->graphics_block_switch->setEnabled(true);
+    ui->video_block_switch->setEnabled(true);
+    ui->audio_block_switch->setEnabled(true);
+    ui->loadscreens_block_switch->setEnabled(true);
+}
+
+void TranslationComponents::onTextsChange(bool new_value) {
+    Settings::setValue("Components/texts_main", new_value);
+    Settings::setValue("Components/texts_emotes", new_value);
+    Settings::setValue("Components/texts_items", new_value);
+    checkIfSettingsDoNotMatchCurrentDatState();
+}
+
+void TranslationComponents::onImagesChange(bool new_value) {
+    Settings::setValue("Components/maps", new_value);
+    Settings::setValue("Components/textures", new_value);
+    checkIfSettingsDoNotMatchCurrentDatState();
+}
+
+void TranslationComponents::onVideosChange(bool new_value) {
+    Settings::setValue("Components/videos", new_value);
+    Settings::setValue("Components/texts_videos", new_value);
+    checkIfSettingsDoNotMatchCurrentDatState();
+}
+
+void TranslationComponents::onSoundsChange(bool new_value) {
+    Settings::setValue("Components/sounds", new_value);
+    checkIfSettingsDoNotMatchCurrentDatState();
+}
+
+void TranslationComponents::onLoadscreensChange(bool new_value) {
+    Settings::setValue("Components/loadscreens", new_value);
+    checkIfSettingsDoNotMatchCurrentDatState();
+}
+
+void TranslationComponents::checkIfSettingsDoNotMatchCurrentDatState() {
+    PatchInstaller::AppliedPatchesInfo info = PatchInstaller::instance().getPatchesInfo();
+    bool texts_enabled = info.texts_version != 0;
+    bool images_enabled = info.graphics_version != 0;
+    bool videos_enabled = info.videos_version != 0;
+    bool sounds_enabled = info.audio_version != 0;
+    bool loadscreens_enabled = info.loadscreens_version != 0;
+
+    bool match = Settings::getValue("Components/texts_main").toBool() == texts_enabled &&
+                 Settings::getValue("Components/texts_emotes").toBool() == texts_enabled &&
+                 Settings::getValue("Components/texts_items").toBool() == texts_enabled &&
+                 Settings::getValue("Components/maps").toBool() == images_enabled &&
+                 Settings::getValue("Components/textures").toBool() == images_enabled &&
+                 Settings::getValue("Components/videos").toBool() == videos_enabled &&
+                 Settings::getValue("Components/texts_videos").toBool() == videos_enabled &&
+                 Settings::getValue("Components/sounds").toBool() == sounds_enabled &&
+                 Settings::getValue("Components/loadscreens").toBool() == loadscreens_enabled;
+
+    if (!match) {
+        emit needToPatch();
+    } else {
+        emit noNeedToPatch();
+    }
+}

+ 15 - 0
src/Legacy/widgets/translationcomponents.h

@@ -16,9 +16,24 @@ public:
     explicit TranslationComponents(QWidget *parent = nullptr);
     ~TranslationComponents();
 
+signals:
+    void needToPatch();
+    void noNeedToPatch();
+
 public slots:
     void resetSwitchesToDefault();
 
+private slots:
+    void disableControls();
+    void enableControls();
+    void checkIfSettingsDoNotMatchCurrentDatState();
+
+    void onTextsChange(bool new_value);
+    void onImagesChange(bool new_value);
+    void onVideosChange(bool new_value);
+    void onSoundsChange(bool new_value);
+    void onLoadscreensChange(bool new_value);
+
 private:
     Ui::TranslationComponents *ui;
 };

+ 3 - 3
src/Legacy/widgets/translationcomponents.ui

@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>400</width>
-    <height>300</height>
+    <height>305</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -332,7 +332,7 @@
     </widget>
    </item>
    <item>
-    <widget class="QWidget" name="e_loadscreens_block" native="true">
+    <widget class="QWidget" name="d_loadscreens_block" native="true">
      <layout class="QHBoxLayout" name="horizontalLayout_7">
       <property name="spacing">
        <number>3</number>
@@ -373,7 +373,7 @@
        </widget>
       </item>
       <item>
-       <spacer name="horizontalSpacer_6">
+       <spacer name="horizontalSpacer_4">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>