translationcomponents.cpp 7.0 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("Components/texts_main", info.texts_version != 0);
  45. Settings::setValue("Components/texts_emotes", info.texts_version != 0);
  46. Settings::setValue("Components/texts_items", info.texts_version != 0);
  47. Settings::setValue("Components/texts_videos", info.videos_version != 0);
  48. Settings::setValue("Components/maps", info.graphics_version != 0);
  49. Settings::setValue("Components/textures", info.graphics_version != 0);
  50. Settings::setValue("Components/sounds", info.audio_version != 0);
  51. Settings::setValue("Components/videos", info.videos_version != 0);
  52. Settings::setValue("Components/loadscreens", info.loadscreens_version != 0);
  53. ui->texts_block_switch->setValue(info.texts_version != 0);
  54. ui->graphics_block_switch->setValue(info.graphics_version != 0);
  55. ui->video_block_switch->setValue(info.videos_version != 0);
  56. ui->audio_block_switch->setValue(info.audio_version != 0);
  57. ui->loadscreens_block_switch->setValue(info.loadscreens_version != 0);
  58. }
  59. void TranslationComponents::disableControls() {
  60. ui->texts_block_switch->setEnabled(false);
  61. ui->graphics_block_switch->setEnabled(false);
  62. ui->video_block_switch->setEnabled(false);
  63. ui->audio_block_switch->setEnabled(false);
  64. ui->loadscreens_block_switch->setEnabled(false);
  65. }
  66. void TranslationComponents::enableControls() {
  67. ui->texts_block_switch->setEnabled(true);
  68. ui->graphics_block_switch->setEnabled(true);
  69. ui->video_block_switch->setEnabled(true);
  70. ui->audio_block_switch->setEnabled(true);
  71. ui->loadscreens_block_switch->setEnabled(true);
  72. }
  73. void TranslationComponents::onTextsChange(bool new_value) {
  74. Settings::setValue("Components/texts_main", new_value);
  75. Settings::setValue("Components/texts_emotes", new_value);
  76. Settings::setValue("Components/texts_items", new_value);
  77. checkIfSettingsDoNotMatchCurrentDatState();
  78. }
  79. void TranslationComponents::onImagesChange(bool new_value) {
  80. Settings::setValue("Components/maps", new_value);
  81. Settings::setValue("Components/textures", new_value);
  82. checkIfSettingsDoNotMatchCurrentDatState();
  83. }
  84. void TranslationComponents::onVideosChange(bool new_value) {
  85. Settings::setValue("Components/videos", new_value);
  86. Settings::setValue("Components/texts_videos", new_value);
  87. checkIfSettingsDoNotMatchCurrentDatState();
  88. }
  89. void TranslationComponents::onSoundsChange(bool new_value) {
  90. Settings::setValue("Components/sounds", new_value);
  91. checkIfSettingsDoNotMatchCurrentDatState();
  92. }
  93. void TranslationComponents::onLoadscreensChange(bool new_value) {
  94. Settings::setValue("Components/loadscreens", new_value);
  95. checkIfSettingsDoNotMatchCurrentDatState();
  96. }
  97. void TranslationComponents::checkIfSettingsDoNotMatchCurrentDatState() {
  98. PatchInstaller::AppliedPatchesInfo info = PatchInstaller::instance().getPatchesInfo();
  99. bool texts_enabled = info.texts_version != 0;
  100. bool images_enabled = info.graphics_version != 0;
  101. bool videos_enabled = info.videos_version != 0;
  102. bool sounds_enabled = info.audio_version != 0;
  103. bool loadscreens_enabled = info.loadscreens_version != 0;
  104. bool match = Settings::getValue("Components/texts_main").toBool() == texts_enabled &&
  105. Settings::getValue("Components/texts_emotes").toBool() == texts_enabled &&
  106. Settings::getValue("Components/texts_items").toBool() == texts_enabled &&
  107. Settings::getValue("Components/maps").toBool() == images_enabled &&
  108. Settings::getValue("Components/textures").toBool() == images_enabled &&
  109. Settings::getValue("Components/videos").toBool() == videos_enabled &&
  110. Settings::getValue("Components/texts_videos").toBool() == videos_enabled &&
  111. Settings::getValue("Components/sounds").toBool() == sounds_enabled &&
  112. Settings::getValue("Components/loadscreens").toBool() == loadscreens_enabled;
  113. if (!match) {
  114. emit needToPatch();
  115. } else {
  116. emit noNeedToPatch();
  117. }
  118. }