From 06629b08264274dca426be5d824e9ebe31219cb2 Mon Sep 17 00:00:00 2001 From: Peter Kohaut Date: Sat, 9 Mar 2019 23:03:24 +0100 Subject: BLADERUNNER: Clean-up for subtitles initialization code --- engines/bladerunner/archive.cpp | 4 ++ engines/bladerunner/archive.h | 1 + engines/bladerunner/bladerunner.cpp | 14 ++++--- engines/bladerunner/subtitles.cpp | 24 ++++------- engines/bladerunner/subtitles.h | 35 ++++++++-------- engines/bladerunner/ui/kia_section_settings.cpp | 56 ++++++++++++++----------- 6 files changed, 72 insertions(+), 62 deletions(-) (limited to 'engines') diff --git a/engines/bladerunner/archive.cpp b/engines/bladerunner/archive.cpp index e29ed0a9a9..7ac2e3e983 100644 --- a/engines/bladerunner/archive.cpp +++ b/engines/bladerunner/archive.cpp @@ -38,6 +38,10 @@ MIXArchive::~MIXArchive() { } } +bool MIXArchive::exists(const Common::String &filename) { + return Common::File::exists(filename); +} + bool MIXArchive::open(const Common::String &filename) { if (!_fd.open(filename)) { warning("MIXArchive::open(): Can not open %s", filename.c_str()); diff --git a/engines/bladerunner/archive.h b/engines/bladerunner/archive.h index 9f7c67920d..28ddf86c1c 100644 --- a/engines/bladerunner/archive.h +++ b/engines/bladerunner/archive.h @@ -35,6 +35,7 @@ public: ~MIXArchive(); static int32 getHash(const Common::String &name); + static bool exists(const Common::String &filename); bool open(const Common::String &filename); void close(); diff --git a/engines/bladerunner/bladerunner.cpp b/engines/bladerunner/bladerunner.cpp index 793939df9a..d93bb3dad0 100644 --- a/engines/bladerunner/bladerunner.cpp +++ b/engines/bladerunner/bladerunner.cpp @@ -371,13 +371,17 @@ bool BladeRunnerEngine::startup(bool hasSavegames) { // Try to load the SUBTITLES.MIX first, before Startup.MIX // allows overriding any identically named resources (such as the original font files and as a bonus also the TRE files for the UI and dialogue menu) _subtitles = new Subtitles(this); - bool r = openArchive("SUBTITLES.MIX"); - if (!r) { - _subtitles->setSubtitlesSystemInactive(true); // no subtitles support + if (MIXArchive::exists("SUBTITLES.MIX")) { + bool r = openArchive("SUBTITLES.MIX"); + if (!r) + return false; + + _subtitles->init(); + } else { + debug("Download SUBTITLES.MIX from ScummVM's website to enable subtitles"); } - _subtitles->init(); - r = openArchive("STARTUP.MIX"); + bool r = openArchive("STARTUP.MIX"); if (!r) return false; diff --git a/engines/bladerunner/subtitles.cpp b/engines/bladerunner/subtitles.cpp index 4157d754ef..612091d84f 100644 --- a/engines/bladerunner/subtitles.cpp +++ b/engines/bladerunner/subtitles.cpp @@ -95,7 +95,7 @@ const char *Subtitles::SUBTITLES_FILENAME_PREFIXES[kMaxTextResourceEntries] = { */ Subtitles::Subtitles(BladeRunnerEngine *vm) { _vm = vm; - _subtitlesSystemInactive = false; + _subtitlesSystemActive = false; // Initializing and reseting Subtitles for (int i = 0; i < kMaxTextResourceEntries; i++) { _vqaSubsTextResourceEntries[i] = nullptr; @@ -128,9 +128,7 @@ Subtitles::~Subtitles() { // Init is kept separated from constructor to allow not loading up resources if subtitles system is disabled // void Subtitles::init(void) { - if (_subtitlesSystemInactive) { - return; - } + _subtitlesSystemActive = true; // // Loading text resources for (int i = 0; i < kMaxTextResourceEntries; i++) { @@ -172,10 +170,6 @@ void Subtitles::init(void) { } } -void Subtitles::setSubtitlesSystemInactive(bool flag) { - _subtitlesSystemInactive = flag; -} - /** * * Returns the index of the specified Text Resource filename in the SUBTITLES_FILENAME_PREFIXES table @@ -203,7 +197,7 @@ int Subtitles::getIdxForSubsTreName(const Common::String &treName) const { * Returns the dialogue quote, but also sets the private _currentSubtitleTextFull member */ const char *Subtitles::getInGameSubsText(int actorId, int speech_id) { - if (_subtitlesSystemInactive) { + if (!_subtitlesSystemActive) { return ""; } @@ -227,7 +221,7 @@ const char *Subtitles::getInGameSubsText(int actorId, int speech_id) { * Returns the dialogue quote, but also sets the private _currentSubtitleTextFull member */ const char *Subtitles::getOuttakeSubsText(const Common::String &outtakesName, int frame) { - if (_subtitlesSystemInactive) { + if (!_subtitlesSystemActive) { return ""; } @@ -269,7 +263,7 @@ void Subtitles::setGameSubsText(Common::String dbgQuote, bool forceShowWhenNoSpe * @return true if the member was set now, false if the member was already set */ bool Subtitles::show() { - if (_subtitlesSystemInactive) { + if (!_subtitlesSystemActive) { return false; } @@ -285,7 +279,7 @@ bool Subtitles::show() { * @return true if the member was cleared, false if it was already clear. */ bool Subtitles::hide() { - if (_subtitlesSystemInactive) { + if (!_subtitlesSystemActive) { return false; } @@ -302,14 +296,14 @@ bool Subtitles::hide() { * @return the value of the _isVisible member boolean var */ bool Subtitles::isVisible() const { - return _subtitlesSystemInactive || _isVisible; + return !_subtitlesSystemActive || _isVisible; } /** * Tick method specific for outtakes (VQA videos) */ void Subtitles::tickOuttakes(Graphics::Surface &s) { - if (_subtitlesSystemInactive || !_vm->isSubtitlesEnabled()) { + if (!_subtitlesSystemActive || !_vm->isSubtitlesEnabled()) { return; } @@ -329,7 +323,7 @@ void Subtitles::tickOuttakes(Graphics::Surface &s) { * Tick method for in-game subtitles -- Not for outtake cutscenes (VQA videos) */ void Subtitles::tick(Graphics::Surface &s) { - if (_subtitlesSystemInactive || !_vm->isSubtitlesEnabled()) { + if (!_subtitlesSystemActive || !_vm->isSubtitlesEnabled()) { return; } diff --git a/engines/bladerunner/subtitles.h b/engines/bladerunner/subtitles.h index 2947ab5645..0a3ec820c8 100644 --- a/engines/bladerunner/subtitles.h +++ b/engines/bladerunner/subtitles.h @@ -57,33 +57,34 @@ class Subtitles { BladeRunnerEngine *_vm; - TextResource *_vqaSubsTextResourceEntries[kMaxTextResourceEntries]; - Font *_subsFont; - - bool _isVisible; - bool _forceShowWhenNoSpeech; - Common::String _currentSubtitleTextFull; - Common::String _subtitleLineQuote[kMaxNumOfSubtitlesLines]; - int _subtitleLineScreenY[kMaxNumOfSubtitlesLines]; - int _subtitleLineScreenX[kMaxNumOfSubtitlesLines]; - int _subtitleLineSplitAtCharIndex[kMaxNumOfSubtitlesLines]; - int _currentSubtitleLines; - bool _subtitlesQuoteChanged; + TextResource *_vqaSubsTextResourceEntries[kMaxTextResourceEntries]; + Font *_subsFont; + + bool _isVisible; + bool _forceShowWhenNoSpeech; + Common::String _currentSubtitleTextFull; + Common::String _subtitleLineQuote[kMaxNumOfSubtitlesLines]; + int _subtitleLineScreenY[kMaxNumOfSubtitlesLines]; + int _subtitleLineScreenX[kMaxNumOfSubtitlesLines]; + int _subtitleLineSplitAtCharIndex[kMaxNumOfSubtitlesLines]; + int _currentSubtitleLines; + bool _subtitlesQuoteChanged; bool _gameSubsResourceEntriesFound[kMaxTextResourceEntries]; // false if a TRE file did not open successfully bool _subsFontsLoaded; // false if external fonts did not load - bool _subtitlesSystemInactive; // true if the whole subtitles subsystem should be disabled (due to missing required resources) + bool _subtitlesSystemActive; // true if the whole subtitles subsystem should be disabled (due to missing required resources) public: Subtitles(BladeRunnerEngine *vm); ~Subtitles(); + bool isSystemActive() const { return _subtitlesSystemActive; } + void init(); - void setSubtitlesSystemInactive(bool flag); // disable subtitles system (possibly due to missing important resources like SUBTITLES.MIX file) - const char *getInGameSubsText(int actorId, int speech_id) ; // get the text for actorId, quoteId (in-game subs) - const char *getOuttakeSubsText(const Common::String &outtakesName, int frame); // get the text for this frame if any + const char *getInGameSubsText(int actorId, int speech_id); // get the text for actorId, quoteId (in-game subs) + const char *getOuttakeSubsText(const Common::String &outtakesName, int frame); // get the text for this frame if any - void setGameSubsText(Common::String dbgQuote, bool force); // for debugging - explicit set subs text + void setGameSubsText(Common::String dbgQuote, bool force); // for debugging - explicit set subs text bool show(); bool hide(); bool isVisible() const; diff --git a/engines/bladerunner/ui/kia_section_settings.cpp b/engines/bladerunner/ui/kia_section_settings.cpp index ce2832c1f0..2d0ab1db85 100644 --- a/engines/bladerunner/ui/kia_section_settings.cpp +++ b/engines/bladerunner/ui/kia_section_settings.cpp @@ -32,6 +32,7 @@ #include "bladerunner/game_info.h" #include "bladerunner/music.h" #include "bladerunner/settings.h" +#include "bladerunner/subtitles.h" #include "bladerunner/text_resource.h" #include "bladerunner/ui/kia.h" #include "bladerunner/ui/kia_shapes.h" @@ -76,7 +77,9 @@ KIASectionSettings::KIASectionSettings(BladeRunnerEngine *vm) _uiContainer->add(_gammaCorrection); #endif _uiContainer->add(_directorsCut); - _uiContainer->add(_subtitlesEnable); + if (_vm->_subtitles->isSystemActive()) { + _uiContainer->add(_subtitlesEnable); + } _learyPos = 0; } @@ -145,29 +148,6 @@ void KIASectionSettings::draw(Graphics::Surface &surface) { const char *textLight = _vm->_textOptions->getText(15); #endif - // Allow this to be loading as an extra text item in the resource for text options - const char *subtitlesTranslation = "Subtitles"; - if (_vm->_languageCode == "E") { - subtitlesTranslation = "Subtitles"; // EN_ANY - } - else if (_vm->_languageCode == "G") { - subtitlesTranslation = "Untertitel"; // DE_DEU - } - else if (_vm->_languageCode == "F") { - subtitlesTranslation = "Sous-titres"; // FR_FRA - } - else if (_vm->_languageCode == "I") { - subtitlesTranslation = "Sottotitoli"; // IT_ITA - } - else if (_vm->_languageCode == "R") { - subtitlesTranslation = "Subtitry"; // RU_RUS - } - else if (_vm->_languageCode == "S") { - subtitlesTranslation = "Subtitulos"; // ES_ESP - } - - const char *textSubtitles = strcmp(_vm->_textOptions->getText(42), "") == 0? subtitlesTranslation : _vm->_textOptions->getText(42); // +1 to the max of original index of textOptions which is 41 - int posConversationChoices = 320 - _vm->_mainFont->getTextWidth(textConversationChoices) / 2; int posMusic = 320 - _vm->_mainFont->getTextWidth(textMusic) / 2; int posSoundEffects = 320 - _vm->_mainFont->getTextWidth(textSoundEffects) / 2; @@ -211,7 +191,33 @@ void KIASectionSettings::draw(Graphics::Surface &surface) { #endif _vm->_mainFont->drawColor(textDesignersCut, surface, 192, 365, 0x7751); - _vm->_mainFont->drawColor(textSubtitles, surface, 323, 365, 0x7751); // moved further to the right to avoid overlap with 'Designer's Cut' in some language versions (ESP) + + if (_vm->_subtitles->isSystemActive()) { + // Allow this to be loading as an extra text item in the resource for text options + const char *subtitlesTranslation = "Subtitles"; + if (_vm->_languageCode == "E") { + subtitlesTranslation = "Subtitles"; // EN_ANY + } + else if (_vm->_languageCode == "G") { + subtitlesTranslation = "Untertitel"; // DE_DEU + } + else if (_vm->_languageCode == "F") { + subtitlesTranslation = "Sous-titres"; // FR_FRA + } + else if (_vm->_languageCode == "I") { + subtitlesTranslation = "Sottotitoli"; // IT_ITA + } + else if (_vm->_languageCode == "R") { + subtitlesTranslation = "Subtitry"; // RU_RUS + } + else if (_vm->_languageCode == "S") { + subtitlesTranslation = "Subtitulos"; // ES_ESP + } + + const char *textSubtitles = strcmp(_vm->_textOptions->getText(42), "") == 0? subtitlesTranslation : _vm->_textOptions->getText(42); // +1 to the max of original index of textOptions which is 41 + + _vm->_mainFont->drawColor(textSubtitles, surface, 323, 365, 0x7751); // moved further to the right to avoid overlap with 'Designer's Cut' in some language versions (ESP) + } _playerAgendaSelector->drawTooltip(surface, _mouseX, _mouseY); } -- cgit v1.2.3