Explorar o código

Added server status messages

Ivan Arkhipov %!s(int64=5) %!d(string=hai) anos
pai
achega
74c36a2773

+ 1 - 1
src/Legacy/models/internallogicmanager.cpp

@@ -1,6 +1,6 @@
 #include "internallogicmanager.h"
 
-InternalLogicManager::InternalLogicManager(QObject *parent) : QObject(parent)
+InternalLogicManager::InternalLogicManager(PatchDownloader *patch_downloader, LotroDatManager *lotro_mgr, QObject *parent)
 {
 
 }

+ 2 - 0
src/Legacy/object_script.Legacy.Debug

@@ -20,6 +20,7 @@ INPUT(
 ./..\..\build\debug\Legacy\obj\weeklycodewidget.o
 ./..\..\build\debug\Legacy\obj\dialogwindow.o
 ./..\..\build\debug\Legacy\obj\fonts.o
+./..\..\build\debug\Legacy\obj\internallogicmanager.o
 ./..\..\build\debug\Legacy\obj\legacy_plugin_import.o
 ./..\..\build\debug\Legacy\obj\moc_downloader.o
 ./..\..\build\debug\Legacy\obj\moc_filesystem.o
@@ -38,4 +39,5 @@ INPUT(
 ./..\..\build\debug\Legacy\obj\moc_chooseversiondialog.o
 ./..\..\build\debug\Legacy\obj\moc_weeklycodewidget.o
 ./..\..\build\debug\Legacy\obj\moc_dialogwindow.o
+./..\..\build\debug\Legacy\obj\moc_internallogicmanager.o
 );

+ 2 - 0
src/Legacy/object_script.Legacy.Release

@@ -18,6 +18,7 @@ INPUT(
 ./..\..\build\release\Legacy\obj\weeklycodewidget.o
 ./..\..\build\release\Legacy\obj\dialogwindow.o
 ./..\..\build\release\Legacy\obj\fonts.o
+./..\..\build\release\Legacy\obj\internallogicmanager.o
 ./..\..\build\release\Legacy\obj\legacy_plugin_import.o
 ./..\..\build\release\Legacy\obj\moc_downloader.o
 ./..\..\build\release\Legacy\obj\moc_filesystem.o
@@ -36,4 +37,5 @@ INPUT(
 ./..\..\build\release\Legacy\obj\moc_chooseversiondialog.o
 ./..\..\build\release\Legacy\obj\moc_weeklycodewidget.o
 ./..\..\build\release\Legacy\obj\moc_dialogwindow.o
+./..\..\build\release\Legacy\obj\moc_internallogicmanager.o
 );

+ 95 - 27
src/Legacy/widgets/serverstatuswidget.cpp

@@ -8,16 +8,15 @@ ServerStatusWidget::ServerStatusWidget(QWidget *parent) :
     QWidget(parent),
     ui(new Ui::ServerStatusWidget)
 {
-    ui->setupUi(this);
+    servers_disabled = false;
+    setMouseTracking(true);
 
-    downloader.targetBytearray = &downloaded_data;
-    downloader.setUrl(QUrl("http://translate.lotros.ru/servers.txt"));
+    ui->setupUi(this);
+    connect(&update_timer, &QTimer::timeout, &status_downloader, &Downloader::start);
 
-    connect(&update_timer, &QTimer::timeout, &downloader, &Downloader::start);
-    connect(&downloader, &Downloader::downloadFinished, this, &ServerStatusWidget::updateStatus, Qt::QueuedConnection);
-    downloader.start();
-    update_timer.setInterval(1000 * 60); // 1 minute;
-    update_timer.start();
+    connect(&status_downloader, &Downloader::downloadFinished, this, &ServerStatusWidget::updateStatus);
+    // updateStatus will start tech_work_message_downloader
+    connect(&tech_work_message_downloader, &Downloader::downloadFinished, this, &ServerStatusWidget::updateTechWorksMessage);
 }
 
 ServerStatusWidget::~ServerStatusWidget()
@@ -25,27 +24,30 @@ ServerStatusWidget::~ServerStatusWidget()
     delete ui;
 }
 
-void ServerStatusWidget::updateFontsSizes()
+void ServerStatusWidget::setupUpdater(QUrl status_url, QUrl tech_works_message_url)
 {
-    QFont font9pt = QFont(ui->anor->font());
-    font9pt.setPixelSize(pixels_in_9_pt);
-    QStringList servers_list = {"Anor",
-                                "Arkenstone",
-                                "Belegaer",
-                                "Brandywine",
-                                "Bullroarer",
-                                "Crickhollow",
-                                "Evernight",
-                                "Gladden",
-                                "Gwaihir",
-                                "Ithil",
-                                "Landroval",
-                                "Laurelin",
-                                "Sirannon"};
+    status_downloader.targetBytearray = &status_data;
+    status_downloader.setUrl(status_url);
+
+    tech_work_message_downloader.targetBytearray = &tech_work_message_data;
+    tech_work_message_downloader.setUrl(tech_works_message_url);
+
+    update_timer.setInterval(1000 * 60); // 1 minute;
+    update_timer.start();
+
+    // Perform update on startup
+    status_downloader.start();
+}
 
+void ServerStatusWidget::updateFontsSizes()
+{
     foreach (QString server_name, servers_list) {
         QLabel* label = ui->servers_list->findChild<QLabel*>(server_name.toLower());
-        label->setFont(font9pt);
+        if (!label) {
+            qDebug() << "Error! Cannot find server widget " << server_name;
+            continue;
+        }
+        label->setFont(trajan_9pt);
     }
 }
 
@@ -54,9 +56,38 @@ void ServerStatusWidget::resizeEvent(QResizeEvent *event)
     updateFontsSizes();
 }
 
+void ServerStatusWidget::leaveEvent(QEvent *event)
+{
+    event->ignore();
+    emit showNoTooltip();
+}
+
+void ServerStatusWidget::enterEvent(QEvent *event)
+{
+    event->ignore();
+    emit showServersTooltip();
+}
+
 void ServerStatusWidget::updateStatus()
 {
-    QStringList servers = QString(downloaded_data).split("|||");
+    if (QString(status_data).contains("profilaktika")) {
+        servers_disabled = true;
+        qDebug() << "All servers are closed!";
+        foreach (QString server_name, servers_list) {
+            QLabel* label = ui->servers_list->findChild<QLabel*>(server_name.toLower());
+            if (!label) {
+                qDebug() << "Error! Cannot find server widget " << server_name;
+                continue;
+            }
+            label->setStyleSheet(closed_color);
+        }
+        status_data = "";
+        tech_work_message_downloader.start();
+        return;
+    }
+
+    servers_disabled = false;
+    QStringList servers = QString(status_data).split("|||");
     foreach (QString server, servers) {
         QStringList data = server.split(":::");
         QWidget* widget = findChild<QWidget*>(QString(data[0]).toLower());
@@ -67,5 +98,42 @@ void ServerStatusWidget::updateStatus()
         else
             widget->setStyleSheet(closed_color);
     }
-    downloaded_data = "";
+    status_data = "";
+    tech_work_message_downloader.start();
+}
+
+void ServerStatusWidget::updateTechWorksMessage()
+{
+    if (tech_work_message_data.isEmpty()) {
+        QString result;
+        if (!servers_disabled) {
+            result = "<p style=\"color:#00aa00\">Сервера игры работают в штатном режиме.</p>";
+        } else {
+            result = "<p style =\"color:#ff0000\">Сервера игры отключены.</p>";
+        }
+        emit updateServersTooltip(result);
+        tech_work_message_data = "";
+        return;
+    }
+
+    QStringList list = QString(tech_work_message_data).split(":::");
+    if (list.size() < 4) {
+        tech_work_message_data = "";
+        return;
+    }
+
+    QString time_beginning = list[0];
+    QString time_end = list[1];
+    QString day = list[2];
+    QString month = " " + list[3];
+
+    QString result;
+    if (!servers_disabled) {
+        result = "<p style=\"color:#ffff7f\">Запланирована профилактика игровых серверов " + day + month + " с " + time_beginning + " до " + time_end+ " (МСК).</p>";
+    } else {
+        result = "<p style=\"color:#ff0000\">Сервера игры отключены. Ориентировочное время проф. работ: " + day + month + " с " + time_beginning + " до " + time_end + " (МСК).</p>";
+    }
+
+    tech_work_message_data = "";
+    emit updateServersTooltip(result);
 }

+ 31 - 2
src/Legacy/widgets/serverstatuswidget.h

@@ -19,24 +19,53 @@ public:
     ~ServerStatusWidget();
 
 public slots:
+    void setupUpdater(QUrl status_url, QUrl tech_works_message_url);
     void updateFontsSizes();
 
+signals:
+    void showServersTooltip();
+    void showNoTooltip();
+    void updateServersTooltip(QString tooltip);
+
 protected:
     void resizeEvent(QResizeEvent *event) override;
+    virtual void leaveEvent(QEvent * event) override;
+    virtual void enterEvent(QEvent * event) override;
 
 public slots:
     void updateStatus();
+    void updateTechWorksMessage();
 
 private:
-    QByteArray downloaded_data;
     QTimer update_timer;
-    Downloader downloader;
+
+    Downloader status_downloader;
+    QByteArray status_data;
+
+    Downloader tech_work_message_downloader;
+    QByteArray tech_work_message_data;
 
     const QString open_color = "color: rgb(0, 170, 0);";
     const QString closed_color = "color: rgb(255, 0, 0);";
 
 private:
+    const QStringList servers_list = {"Anor",
+                                      "Arkenstone",
+                                      "Belegaer",
+                                      "Brandywine",
+                                      "Bullroarer",
+                                      "Crickhollow",
+                                      "Evernight",
+                                      "Gladden",
+                                      "Gwaihir",
+                                      "Ithil",
+                                      "Landroval",
+                                      "Laurelin",
+                                      "Sirannon"};
+
     Ui::ServerStatusWidget *ui;
+    bool servers_disabled;
+
 };
 
 #endif // SERVERSTATUSWIDGET_H

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

@@ -16,6 +16,8 @@ StatusWidget::StatusWidget(QSettings* settings, PatchDownloader* patch_downloade
 {
 
     ui->setupUi(this);
+    ui->server_status_widget->setupUpdater(settings->value("Network/game_servers_status", "http://translate.lotros.ru/servers.txt").toUrl(),
+                                           settings->value("Network/game_servers_message", "http://translate.lotros.ru/profmessage.txt").toUrl());
     last_progress_update_time.start();
 
     connect(patch_updater, &PatchDownloader::checkForUpdatesStarted, this, &StatusWidget::onPatchDownloaderStarted, Qt::QueuedConnection);
@@ -30,20 +32,27 @@ StatusWidget::StatusWidget(QSettings* settings, PatchDownloader* patch_downloade
     connect(ui->news_list, &NewsListWidget::showHelpToolTip, this, &StatusWidget::setToolTipToNewsHelp);
     connect(ui->news_list, &NewsListWidget::showNoToolTip, this, &StatusWidget::resetToolTip);
 
+    connect(ui->server_status_widget, &ServerStatusWidget::updateServersTooltip, ui->server_status_tooltip, &QLabel::setText);
+    connect(ui->server_status_widget, &ServerStatusWidget::showServersTooltip, this, &StatusWidget::setToolTipToServersStatus);
+    connect(ui->server_status_widget, &ServerStatusWidget::showNoTooltip, this, &StatusWidget::resetToolTip);
+
     tooltip_effects[ui->news_tooltip->objectName()] = new QGraphicsOpacityEffect(ui->news_tooltip);
     tooltip_effects[ui->weekly_code_tooltip_1->objectName()] = new QGraphicsOpacityEffect(ui->weekly_code_tooltip_1);
     tooltip_effects[ui->weekly_code_tooltip_2->objectName()] = new QGraphicsOpacityEffect(ui->weekly_code_tooltip_2);
     tooltip_effects[ui->patches_status->objectName()] = new QGraphicsOpacityEffect(ui->patches_status);
+    tooltip_effects[ui->server_status_tooltip->objectName()] = new QGraphicsOpacityEffect(ui->server_status_tooltip);
 
     tooltip_animations[ui->news_tooltip->objectName()] = new QPropertyAnimation(tooltip_effects[ui->news_tooltip->objectName()], "opacity");
     tooltip_animations[ui->weekly_code_tooltip_1->objectName()] = new QPropertyAnimation(tooltip_effects[ui->weekly_code_tooltip_1->objectName()], "opacity");
     tooltip_animations[ui->weekly_code_tooltip_2->objectName()] = new QPropertyAnimation(tooltip_effects[ui->weekly_code_tooltip_2->objectName()], "opacity");
     tooltip_animations[ui->patches_status->objectName()] = new QPropertyAnimation(tooltip_effects[ui->patches_status->objectName()], "opacity");
+    tooltip_animations[ui->server_status_tooltip->objectName()] = new QPropertyAnimation(tooltip_effects[ui->server_status_tooltip->objectName()], "opacity");
 
     ui->news_tooltip->setGraphicsEffect(tooltip_effects[ui->news_tooltip->objectName()]);
     ui->weekly_code_tooltip_1->setGraphicsEffect(tooltip_effects[ui->weekly_code_tooltip_1->objectName()]);
     ui->weekly_code_tooltip_2->setGraphicsEffect(tooltip_effects[ui->weekly_code_tooltip_2->objectName()]);
     ui->patches_status->setGraphicsEffect(tooltip_effects[ui->patches_status->objectName()]);
+    ui->server_status_tooltip->setGraphicsEffect(tooltip_effects[ui->server_status_tooltip->objectName()]);
 
     foreach (QPropertyAnimation* animation, tooltip_animations) {
         animation->setDuration(250);
@@ -79,7 +88,6 @@ void StatusWidget::updateFontsSizes()
     ui->progress_label->setFont(crimson_10pt);
     ui->game_button->setFont(trajan_11pt);
     ui->news_label->setFont(trajan_10pt);
-    ui->news_tooltip->setFont(garamond_10pt);
 
     ui->images_label->setFont(crimson_11pt);
     ui->images_status->setFont(crimson_11pt);
@@ -90,8 +98,10 @@ void StatusWidget::updateFontsSizes()
     ui->videos_label->setFont(crimson_11pt);
     ui->videos_status->setFont(crimson_11pt);
 
+    ui->news_tooltip->setFont(garamond_10pt);
     ui->weekly_code_tooltip_1->setFont(garamond_10pt);
     ui->weekly_code_tooltip_2->setFont(garamond_10pt);
+    ui->server_status_tooltip->setFont(crimson_14pt);
 }
 
 void StatusWidget::resizeEvent(QResizeEvent *event)
@@ -120,6 +130,8 @@ void StatusWidget::resizeEvent(QResizeEvent *event)
     ui->weekly_code_tooltip_1->resize(QSize(365, 114) * coefficient);
     ui->weekly_code_tooltip_2->move(QPoint(38, 13) * coefficient);
     ui->weekly_code_tooltip_2->resize(QSize(365, 114) * coefficient);
+    ui->server_status_tooltip->move(QPoint(38, 13) * coefficient);
+    ui->server_status_tooltip->resize(QSize(365, 114) * coefficient);
 
     ui->patches_status->move(QPoint(38, 13) * coefficient);
     ui->patches_status->resize(QSize(365, 114) * coefficient);
@@ -194,6 +206,11 @@ void StatusWidget::setToolTipToNewsHelp()
     fadeBetweenToolTips(ui->news_tooltip);
 }
 
+void StatusWidget::setToolTipToServersStatus()
+{
+    fadeBetweenToolTips(ui->server_status_tooltip);
+}
+
 void StatusWidget::resetToolTip()
 {
     fadeBetweenToolTips(ui->patches_status);

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

@@ -41,6 +41,7 @@ private slots:
     void setToolTipToWeeklyCodeHelp();
     void setToolTipToWeeklyCodeComplete();
     void setToolTipToNewsHelp();
+    void setToolTipToServersStatus();
     void resetToolTip();
 
     void fadeBetweenToolTips(QWidget* next_tooltip);

+ 29 - 0
src/Legacy/widgets/statuswidget.ui

@@ -452,6 +452,35 @@ border-image: url(:/characters/galadriel_with_text.png);
      </item>
     </layout>
    </widget>
+   <widget class="QLabel" name="server_status_tooltip">
+    <property name="geometry">
+     <rect>
+      <x>38</x>
+      <y>13</y>
+      <width>365</width>
+      <height>114</height>
+     </rect>
+    </property>
+    <property name="font">
+     <font>
+      <family>Crimson Text</family>
+      <pointsize>15</pointsize>
+      <italic>false</italic>
+     </font>
+    </property>
+    <property name="styleSheet">
+     <string notr="true"/>
+    </property>
+    <property name="text">
+     <string>Игровые сервера работают в штатном режиме</string>
+    </property>
+    <property name="alignment">
+     <set>Qt::AlignCenter</set>
+    </property>
+    <property name="wordWrap">
+     <bool>true</bool>
+    </property>
+   </widget>
   </widget>
   <widget class="QPushButton" name="game_button">
    <property name="geometry">