translationcomponents.cpp 7.5 KB

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