translationcomponents.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include "translationcomponents.h"
  2. #include "ui_translationcomponents.h"
  3. #include "models/patchinstaller.h"
  4. #include "models/patchdownloader.h"
  5. #include "models/settings.h"
  6. #include "fonts.h"
  7. TranslationComponents::TranslationComponents(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::TranslationComponents)
  10. {
  11. ui->setupUi(this);
  12. setAttribute(Qt::WA_StyledBackground, true);
  13. ui->texts_block_label->setTooltipParentWidget(parentWidget());
  14. ui->texts_block_label->raise();
  15. ui->texts_block_label->setTooltipText("Перевод всех текстовых элементов в игре: названий, квестов, меню и т.д.");
  16. connect(ui->texts_block_switch, &SwitchButton::valueChanged, this, &TranslationComponents::onTextsChange);
  17. ui->graphics_block_label->setTooltipParentWidget(parentWidget());
  18. ui->graphics_block_label->raise();
  19. ui->graphics_block_label->setTooltipText("Переведенные карты локаций и элементы графического интерфейса.");
  20. connect(ui->graphics_block_switch, &SwitchButton::valueChanged, this, &TranslationComponents::onImagesChange);
  21. ui->video_block_label->setTooltipParentWidget(parentWidget());
  22. ui->video_block_label->raise();
  23. ui->video_block_label->setTooltipText("Переведенные и озвученные видеоролики и кат-сцены.");
  24. connect(ui->video_block_switch, &SwitchButton::valueChanged, this, &TranslationComponents::onVideosChange);
  25. ui->audio_block_label->setTooltipParentWidget(parentWidget());
  26. ui->audio_block_label->raise();
  27. ui->audio_block_label->setTooltipText("Переведенные и озвученные реплики персонажей.");
  28. connect(ui->audio_block_switch, &SwitchButton::valueChanged, this, &TranslationComponents::onSoundsChange);
  29. ui->loadscreens_block_label->setTooltipParentWidget(parentWidget());
  30. ui->loadscreens_block_label->raise();
  31. ui->loadscreens_block_label->setTooltipText("Загрузочные экраны от команды Наследия");
  32. connect(ui->loadscreens_block_switch, &SwitchButton::valueChanged, this, &TranslationComponents::onLoadscreensChange);
  33. connect(&PatchInstaller::instance(), &PatchInstaller::successfullyInitialized, this, &TranslationComponents::resetSwitchesToDefault);
  34. connect(&PatchInstaller::instance(), &PatchInstaller::started, this, &TranslationComponents::disableControls);
  35. connect(&PatchInstaller::instance(), &PatchInstaller::finished, this, &TranslationComponents::enableControls);
  36. connect(&PatchDownloader::instance(), &PatchDownloader::started, this, &TranslationComponents::disableControls);
  37. connect(&PatchDownloader::instance(), &PatchDownloader::finished, this, &TranslationComponents::enableControls);
  38. }
  39. TranslationComponents::~TranslationComponents()
  40. {
  41. delete ui;
  42. }
  43. void TranslationComponents::updateFontsSizes()
  44. {
  45. ui->sub_entry_3_title->setFont(crimson_12pt);
  46. ui->audio_block_label->setFont(crimson_12pt);
  47. ui->texts_block_label->setFont(crimson_12pt);
  48. ui->video_block_label->setFont(crimson_12pt);
  49. ui->graphics_block_label->setFont(crimson_12pt);
  50. ui->loadscreens_block_label->setFont(crimson_12pt);
  51. }
  52. void TranslationComponents::resizeEvent(QResizeEvent *)
  53. {
  54. updateFontsSizes();
  55. }
  56. void TranslationComponents::resetSwitchesToDefault() {
  57. PatchInstaller::AppliedPatchesInfo info = PatchInstaller::instance().getPatchesInfo();
  58. Settings::setValue("DatabaseDownload/text", info.texts_patch_hashsum != "");
  59. Settings::setValue("DatabaseDownload/font", info.texts_patch_hashsum != "");
  60. Settings::setValue("DatabaseDownload/image", info.images_patch_hashsum != "");
  61. Settings::setValue("DatabaseDownload/loadscreen", info.loadscreens_patch_hashsum != "");
  62. Settings::setValue("DatabaseDownload/texture", info.textures_patch_hashsum != "");
  63. Settings::setValue("DatabaseDownload/sound", info.sounds_patch_hashsum != "");
  64. Settings::setValue("DatabaseDownload/video", info.videos_patch_hashsum != "");
  65. ui->texts_block_switch->setValue(info.texts_patch_hashsum != 0 && info.fonts_patch_hashsum != 0);
  66. ui->graphics_block_switch->setValue(info.images_patch_hashsum != 0 && info.textures_patch_hashsum != 0);
  67. ui->video_block_switch->setValue(info.videos_patch_hashsum != 0);
  68. ui->audio_block_switch->setValue(info.sounds_patch_hashsum != 0);
  69. ui->loadscreens_block_switch->setValue(info.loadscreens_patch_hashsum != 0);
  70. }
  71. void TranslationComponents::disableControls() {
  72. ui->texts_block_switch->setEnabled(false);
  73. ui->graphics_block_switch->setEnabled(false);
  74. ui->video_block_switch->setEnabled(false);
  75. ui->audio_block_switch->setEnabled(false);
  76. ui->loadscreens_block_switch->setEnabled(false);
  77. }
  78. void TranslationComponents::enableControls() {
  79. ui->texts_block_switch->setEnabled(true);
  80. ui->graphics_block_switch->setEnabled(true);
  81. ui->video_block_switch->setEnabled(true);
  82. ui->audio_block_switch->setEnabled(true);
  83. ui->loadscreens_block_switch->setEnabled(true);
  84. }
  85. void TranslationComponents::onTextsChange(bool new_value) {
  86. Settings::setValue("DatabaseDownload/text", new_value);
  87. Settings::setValue("DatabaseDownload/font", new_value);
  88. checkIfSettingsDoNotMatchCurrentDatState();
  89. QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::checkForUpdates, Qt::QueuedConnection);
  90. }
  91. void TranslationComponents::onImagesChange(bool new_value) {
  92. Settings::setValue("DatabaseDownload/image", new_value);
  93. Settings::setValue("DatabaseDownload/texture", new_value);
  94. checkIfSettingsDoNotMatchCurrentDatState();
  95. QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::checkForUpdates, Qt::QueuedConnection);
  96. }
  97. void TranslationComponents::onVideosChange(bool new_value) {
  98. Settings::setValue("DatabaseDownload/video", new_value);
  99. checkIfSettingsDoNotMatchCurrentDatState();
  100. QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::checkForUpdates, Qt::QueuedConnection);
  101. }
  102. void TranslationComponents::onSoundsChange(bool new_value) {
  103. Settings::setValue("DatabaseDownload/sound", new_value);
  104. checkIfSettingsDoNotMatchCurrentDatState();
  105. QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::checkForUpdates, Qt::QueuedConnection);
  106. }
  107. void TranslationComponents::onLoadscreensChange(bool new_value) {
  108. Settings::setValue("DatabaseDownload/loadscreen", new_value);
  109. checkIfSettingsDoNotMatchCurrentDatState();
  110. QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::checkForUpdates, Qt::QueuedConnection);
  111. }
  112. void TranslationComponents::checkIfSettingsDoNotMatchCurrentDatState() {
  113. PatchInstaller::AppliedPatchesInfo info = PatchInstaller::instance().getPatchesInfo();
  114. bool texts_enabled = info.texts_patch_hashsum != "";
  115. bool images_enabled = info.images_patch_hashsum != "";
  116. bool sounds_enabled = info.sounds_patch_hashsum != "";
  117. bool loadscreens_enabled = info.loadscreens_patch_hashsum != "";
  118. bool textures_enabled = info.textures_patch_hashsum != "";
  119. bool fonts_enabled = info.fonts_patch_hashsum != "";
  120. bool videos_enabled = info.videos_patch_hashsum != "";
  121. bool match = Settings::getValue("DatabaseDownload/text").toBool() == texts_enabled &&
  122. Settings::getValue("DatabaseDownload/font").toBool() == fonts_enabled &&
  123. Settings::getValue("DatabaseDownload/image").toBool() == images_enabled &&
  124. Settings::getValue("DatabaseDownload/loadscreen").toBool() == loadscreens_enabled &&
  125. Settings::getValue("DatabaseDownload/texture").toBool() == textures_enabled &&
  126. Settings::getValue("DatabaseDownload/sound").toBool() == sounds_enabled &&
  127. Settings::getValue("DatabaseDownload/video").toBool() == videos_enabled;
  128. if (!match) {
  129. emit needToPatch();
  130. } else {
  131. emit noNeedToPatch();
  132. }
  133. }