statuswidget.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. #include "statuswidget.h"
  2. #include "ui_statuswidget.h"
  3. #include "models/patchlist.h"
  4. #include "widgets/mainwindow.h"
  5. #include "constants.h"
  6. #include <QDesktopServices>
  7. #include <QUrl>
  8. #include <QDebug>
  9. #include <QMessageBox>
  10. StatusWidget::StatusWidget(PatchList *legacy_patches, QWidget *parent)
  11. : QWidget(parent)
  12. , ui(new Ui::StatusWidget)
  13. , legacy_patches_(legacy_patches)
  14. {
  15. ui->setupUi(this);
  16. last_statusbar_update_time_.start();
  17. connect(ui->weekly_code_widget, &WeeklyCodeWidget::showCompletedTooltip, this, &StatusWidget::setToolTipToWeeklyCodeComplete);
  18. connect(ui->weekly_code_widget, &WeeklyCodeWidget::showHelpTooltip, this, &StatusWidget::setToolTipToWeeklyCodeHelp);
  19. connect(ui->weekly_code_widget, &WeeklyCodeWidget::showNoTooltip, this, &StatusWidget::resetToolTip);
  20. connect(ui->news_list, &NewsListWidget::showHelpToolTip, this, &StatusWidget::setToolTipToNewsHelp);
  21. connect(ui->news_list, &NewsListWidget::showNoToolTip, this, &StatusWidget::resetToolTip);
  22. connect(ui->server_status_widget, &ServerStatusWidget::updateServersTooltip, ui->server_status_tooltip, &QLabel::setText);
  23. connect(ui->server_status_widget, &ServerStatusWidget::showServersTooltip, this, &StatusWidget::setToolTipToServersStatus);
  24. connect(ui->server_status_widget, &ServerStatusWidget::showNoTooltip, this, &StatusWidget::resetToolTip);
  25. tooltip_effects[ui->news_tooltip->objectName()] = new QGraphicsOpacityEffect(ui->news_tooltip);
  26. tooltip_effects[ui->weekly_code_tooltip_1->objectName()] = new QGraphicsOpacityEffect(ui->weekly_code_tooltip_1);
  27. tooltip_effects[ui->weekly_code_tooltip_2->objectName()] = new QGraphicsOpacityEffect(ui->weekly_code_tooltip_2);
  28. tooltip_effects[ui->patches_status->objectName()] = new QGraphicsOpacityEffect(ui->patches_status);
  29. tooltip_effects[ui->server_status_tooltip->objectName()] = new QGraphicsOpacityEffect(ui->server_status_tooltip);
  30. tooltip_animations[ui->news_tooltip->objectName()] = new QPropertyAnimation(tooltip_effects[ui->news_tooltip->objectName()], "opacity");
  31. tooltip_animations[ui->weekly_code_tooltip_1->objectName()] = new QPropertyAnimation(tooltip_effects[ui->weekly_code_tooltip_1->objectName()], "opacity");
  32. tooltip_animations[ui->weekly_code_tooltip_2->objectName()] = new QPropertyAnimation(tooltip_effects[ui->weekly_code_tooltip_2->objectName()], "opacity");
  33. tooltip_animations[ui->patches_status->objectName()] = new QPropertyAnimation(tooltip_effects[ui->patches_status->objectName()], "opacity");
  34. tooltip_animations[ui->server_status_tooltip->objectName()] = new QPropertyAnimation(tooltip_effects[ui->server_status_tooltip->objectName()], "opacity");
  35. ui->news_tooltip->setGraphicsEffect(tooltip_effects[ui->news_tooltip->objectName()]);
  36. ui->weekly_code_tooltip_1->setGraphicsEffect(tooltip_effects[ui->weekly_code_tooltip_1->objectName()]);
  37. ui->weekly_code_tooltip_2->setGraphicsEffect(tooltip_effects[ui->weekly_code_tooltip_2->objectName()]);
  38. ui->patches_status->setGraphicsEffect(tooltip_effects[ui->patches_status->objectName()]);
  39. ui->server_status_tooltip->setGraphicsEffect(tooltip_effects[ui->server_status_tooltip->objectName()]);
  40. foreach (QPropertyAnimation* animation, tooltip_animations) {
  41. animation->setDuration(350);
  42. animation->setStartValue(0);
  43. animation->setEndValue(1);
  44. animation->setDirection(QAbstractAnimation::Forward);
  45. }
  46. foreach (QGraphicsOpacityEffect* effect, tooltip_effects) {
  47. effect->setOpacity(0);
  48. }
  49. active_tooltip = nullptr;
  50. resetToolTip();
  51. connect(legacy_patches_, &PatchList::patchOperationsStarted, this, &StatusWidget::onPatchTotalOperationsStarted);
  52. connect(legacy_patches_, &PatchList::patchOperationsFinished, this, &StatusWidget::onPatchTotalOperationsFinished);
  53. connect(legacy_patches_, &PatchList::progressChanged, this, &StatusWidget::onPatchTotalProgressChanged);
  54. foreach (Patch* patch, legacy_patches_->getPatchList()) {
  55. connect(patch, &Patch::progressChanged, this, &StatusWidget::onPatchProgressChanged);
  56. connect(patch, &Patch::operationStarted, this, &StatusWidget::onPatchOperationStarted);
  57. connect(patch, &Patch::operationFinished, this, &StatusWidget::onPatchOperationFinished);
  58. }
  59. }
  60. StatusWidget::~StatusWidget()
  61. {
  62. delete ui;
  63. }
  64. void StatusWidget::updateFontsSizes()
  65. {
  66. ui->progress_label->setFont(crimson_10pt);
  67. ui->game_button->setFont(trajan_11pt);
  68. ui->news_label->setFont(trajan_10pt);
  69. ui->graphicspatch_label->setFont(crimson_11pt);
  70. ui->graphicspatch_status->setFont(crimson_11pt);
  71. ui->soundspatch_label->setFont(crimson_11pt);
  72. ui->soundspatch_status->setFont(crimson_11pt);
  73. ui->textspatch_label->setFont(crimson_11pt);
  74. ui->textspatch_status->setFont(crimson_11pt);
  75. ui->videospatch_label->setFont(crimson_11pt);
  76. ui->videospatch_status->setFont(crimson_11pt);
  77. ui->news_tooltip->setFont(garamond_11pt);
  78. ui->weekly_code_tooltip_1->setFont(garamond_11pt);
  79. ui->weekly_code_tooltip_2->setFont(garamond_11pt);
  80. ui->server_status_tooltip->setFont(garamond_11pt);
  81. }
  82. void StatusWidget::resizeEvent(QResizeEvent *)
  83. {
  84. double coefficient = window_width / default_window_width;
  85. // ui->game_button->move(QPoint(820, 460) * coefficient);
  86. // ui->game_button->resize(QSize(150, 60) * coefficient);
  87. // ui->progressBar->move(QPoint(320, 480) * coefficient);
  88. // ui->progressBar->resize(QSize(470, 40) * coefficient);
  89. // ui->progress_label->move(QPoint(330, 390) * coefficient);
  90. // ui->progress_label->resize(QSize(380, 90) * coefficient);
  91. // ui->news_label->move(QPoint(45, 33)* coefficient);
  92. // ui->news_label->resize(QSize(180, 21) * coefficient);
  93. // ui->news_scroll_area->move(QPoint(40, 75) * coefficient);
  94. // ui->news_scroll_area->resize(QSize(240, 440) * coefficient);
  95. // ui->server_status_widget->move(QPoint(820, 90) * coefficient);
  96. // ui->server_status_widget->resize(QSize(155, 320) * coefficient);
  97. // ui->weekly_code_widget->move(QPoint(810, 13) * coefficient);
  98. // ui->weekly_code_widget->resize(QSize(173, 57) * coefficient);
  99. // ui->galadriel_widget->move(QPoint(320, 20) * coefficient);
  100. // ui->galadriel_widget->resize(QSize(531, 461) * coefficient);
  101. // ui->news_tooltip->move(QPoint(38, 13) * coefficient);
  102. // ui->news_tooltip->resize(QSize(365, 114) * coefficient);
  103. // ui->weekly_code_tooltip_1->move(QPoint(38, 13) * coefficient);
  104. // ui->weekly_code_tooltip_1->resize(QSize(365, 114) * coefficient);
  105. // ui->weekly_code_tooltip_2->move(QPoint(38, 13) * coefficient);
  106. // ui->weekly_code_tooltip_2->resize(QSize(365, 114) * coefficient);
  107. // ui->server_status_tooltip->move(QPoint(38, 13) * coefficient);
  108. // ui->server_status_tooltip->resize(QSize(365, 114) * coefficient);
  109. // ui->patches_status->move(QPoint(38, 13) * coefficient);
  110. // ui->patches_status->resize(QSize(385, 114) * coefficient);
  111. updateFontsSizes();
  112. }
  113. void StatusWidget::setToolTipToWeeklyCodeHelp()
  114. {
  115. fadeBetweenToolTips(ui->weekly_code_tooltip_1);
  116. }
  117. void StatusWidget::setToolTipToWeeklyCodeComplete()
  118. {
  119. fadeBetweenToolTips(ui->weekly_code_tooltip_2);
  120. }
  121. void StatusWidget::setToolTipToNewsHelp()
  122. {
  123. fadeBetweenToolTips(ui->news_tooltip);
  124. }
  125. void StatusWidget::setToolTipToServersStatus()
  126. {
  127. fadeBetweenToolTips(ui->server_status_tooltip);
  128. }
  129. void StatusWidget::resetToolTip()
  130. {
  131. fadeBetweenToolTips(ui->patches_status);
  132. }
  133. void StatusWidget::fadeBetweenToolTips(QWidget* next_tooltip)
  134. {
  135. if (active_tooltip) {
  136. QPropertyAnimation* active_tooltip_anim = tooltip_animations[active_tooltip->objectName()];
  137. active_tooltip_anim->setDirection(QAbstractAnimation::Backward);
  138. if (active_tooltip_anim->state() == QAbstractAnimation::Stopped)
  139. active_tooltip_anim->start();
  140. }
  141. QPropertyAnimation* next_active_tooltip_anim = tooltip_animations[next_tooltip->objectName()];
  142. next_active_tooltip_anim->setDirection(QAbstractAnimation::Forward);
  143. if (next_active_tooltip_anim->state() == QAbstractAnimation::Stopped)
  144. next_active_tooltip_anim->start();
  145. active_tooltip = next_tooltip;
  146. }
  147. void StatusWidget::onPatchTotalOperationsStarted()
  148. {
  149. all_patch_operations_finished_ = false;
  150. ui->game_button->setEnabled(false);
  151. }
  152. void StatusWidget::onPatchTotalOperationsFinished()
  153. {
  154. all_patch_operations_finished_ = true;
  155. ui->game_button->setEnabled(true);
  156. for (Patch* patch : legacy_patches_->getPatchList()) {
  157. QString label_name = patch->getPatchName().toLower() + "_status";
  158. QLabel *label = findChild<QLabel*>(label_name);
  159. if (!label) {
  160. return;
  161. }
  162. QString install_date;
  163. if (!(install_date = Settings::getValue("UpdateDates/" + patch->getPatchName()).toString()).isEmpty()) {
  164. label->setText("Патч версии от " + install_date);
  165. } else {
  166. label->setText("Все операции с патчем завершены.");
  167. }
  168. }
  169. ui->progress_label->setText("");
  170. }
  171. void StatusWidget::onPatchOperationStarted(Patch::Operation operation, Patch *patch)
  172. {
  173. QString label_name = patch->getPatchName().toLower() + "_status";
  174. QLabel *label = findChild<QLabel*>(label_name);
  175. patch_operations[patch] = operation;
  176. if (!label) {
  177. return;
  178. }
  179. switch (operation) {
  180. case Patch::E_CHECKFORUPDATES:
  181. label->setText("Проверка наличия обновлений...");
  182. break;
  183. case Patch::E_DOWNLOAD:
  184. label->setText("Подготовка к загрузке данных...");
  185. break;
  186. case Patch::E_INSTALL:
  187. label->setText("Ожидание начала установки...");
  188. break;
  189. case Patch::E_ACTIVATE:
  190. label->setText("Ожидание начала активации...");
  191. default:
  192. break;
  193. }
  194. }
  195. void StatusWidget::onPatchOperationFinished(Patch::Operation operation, Patch *patch)
  196. {
  197. if (all_patch_operations_finished_) {
  198. return;
  199. }
  200. QString label_name = patch->getPatchName().toLower() + "_status";
  201. QLabel *label = findChild<QLabel*>(label_name);
  202. if (!label) {
  203. return;
  204. }
  205. switch (operation) {
  206. case Patch::E_CHECKFORUPDATES:
  207. label->setText("Проверка обновлений завершена");
  208. break;
  209. case Patch::E_DOWNLOAD:
  210. label->setText("Загрузка данных завершена");
  211. break;
  212. case Patch::E_INSTALL:
  213. label->setText("Установка патча завершена");
  214. break;
  215. case Patch::E_ACTIVATE:
  216. label->setText("Активация патча завершена");
  217. default:
  218. break;
  219. }
  220. }
  221. void StatusWidget::onPatchTotalProgressChanged(Patch::OperationProgress operation_progress)
  222. {
  223. updateStatusBar(operation_progress);
  224. }
  225. void StatusWidget::onPatchProgressChanged(Patch::OperationProgress progress, Patch *patch)
  226. {
  227. QString label_name = patch->getPatchName().toLower() + "_status";
  228. QLabel *label = findChild<QLabel*>(label_name);
  229. if (!label) {
  230. return;
  231. }
  232. switch (patch_operations[patch]) {
  233. case Patch::E_CHECKFORUPDATES:
  234. label->setText("Проверка наличия обновлений...");
  235. break;
  236. case Patch::E_DOWNLOAD:
  237. label->setText("Загрузка... " + QString::number(progress.getDownloadPercent(), 'f', 1)
  238. + "% (" + Downloader::getSizeFormatted(progress.download_finished_bytes)
  239. + "/" + Downloader::getSizeFormatted(progress.download_total_bytes) + ")");
  240. break;
  241. case Patch::E_INSTALL:
  242. label->setText("Установка... " + QString::number(progress.getInstallPercent(), 'f', 2)
  243. + "% (" + QString::number(progress.install_finished_parts) + "/" + QString::number(progress.install_total_parts) + ")");
  244. break;
  245. case Patch::E_ACTIVATE:
  246. label->setText("Активация... " + QString::number(progress.getInstallPercent(), 'f', 2)
  247. + "% (" + QString::number(progress.install_finished_parts) + "/" + QString::number(progress.install_total_parts) + ")");
  248. default:
  249. break;
  250. }
  251. }
  252. void StatusWidget::updateStatusBar(Patch::OperationProgress progress)
  253. {
  254. if (last_statusbar_update_time_.elapsed() > 500) {
  255. QString text = "Выполнение операций...";
  256. if (progress.download_total_bytes != 0) {
  257. text += "\nЗагрузка данных: " + QString::number(progress.getDownloadPercent(), 'f', 1) + "% ("
  258. + Downloader::getSizeFormatted(progress.download_finished_bytes) + "/"
  259. + Downloader::getSizeFormatted(progress.download_total_bytes) + ", "
  260. + Downloader::getSpeedFormatted(progress.download_speed) + ")\n"
  261. + "До конца загрузки: " + Downloader::getElapsedTimeFormatted(progress.download_elapsed_time);
  262. }
  263. if (progress.install_total_parts != 0) {
  264. text += "\nПрименение патчей: " + QString::number(progress.getInstallPercent()) + "% "
  265. + "(часть " + QString::number(progress.install_finished_parts + 1) + " из " + QString::number(progress.install_total_parts);
  266. }
  267. ui->progress_label->setText(text);
  268. last_statusbar_update_time_.restart();
  269. }
  270. }