From ceb5299811200705ceb553b2b3439e7bba77b1d3 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Sun, 21 Jun 2020 21:48:22 +0100 Subject: [PATCH] GLK: Add engine options to enable TTS --- engines/glk/POTFILES | 1 + engines/glk/conf.cpp | 3 ++- engines/glk/detection.cpp | 22 ++++++++++++++++++++++ engines/glk/detection.h | 5 +++++ engines/glk/window_text_buffer.cpp | 8 ++++++-- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/engines/glk/POTFILES b/engines/glk/POTFILES index f21c2c9bd58..ef29a25887c 100644 --- a/engines/glk/POTFILES +++ b/engines/glk/POTFILES @@ -1,3 +1,4 @@ +engines/glk/detection.cpp engines/glk/glk_api.cpp engines/glk/quetzal.cpp engines/glk/streams.cpp diff --git a/engines/glk/conf.cpp b/engines/glk/conf.cpp index 8c33a8a7dbd..fbe9019c91a 100644 --- a/engines/glk/conf.cpp +++ b/engines/glk/conf.cpp @@ -216,7 +216,8 @@ void Conf::get(const Common::String &key, int &field, int defaultVal) { } void Conf::get(const Common::String &key, bool &field, bool defaultVal) { - field = ConfMan.hasKey(key) ? strToInt(ConfMan.get(key).c_str()) != 0 : defaultVal; + if (!ConfMan.hasKey(key) || !Common::parseBool(ConfMan.get(key), field)) + field = defaultVal; } void Conf::get(const Common::String &key, FACES &field, FACES defaultFont) { diff --git a/engines/glk/detection.cpp b/engines/glk/detection.cpp index 4b9024afe95..7983a79bd62 100644 --- a/engines/glk/detection.cpp +++ b/engines/glk/detection.cpp @@ -66,6 +66,7 @@ #include "graphics/surface.h" #include "common/config-manager.h" #include "common/file.h" +#include "common/translation.h" namespace Glk { @@ -338,6 +339,27 @@ void GlkMetaEngine::detectClashes() const { Glk::ZCode::ZCodeMetaEngine::detectClashes(map); } +const ExtraGuiOptions GlkMetaEngine::getExtraGuiOptions(const Common::String &) const { + ExtraGuiOptions options; +#if defined(USE_TTS) + static const ExtraGuiOption ttsSpeakOptions = { + _s("Enable Text to Speech"), + _s("Use TTS to read the text"), + "speak", + false + }; + static const ExtraGuiOption ttsSpeakInputOptions = { + _s("Also read input text"), + _s("Use TTS to read the input text"), + "speak_input", + false + }; + options.push_back(ttsSpeakOptions); + options.push_back(ttsSpeakInputOptions); +#endif + return options; +} + SaveStateList GlkMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; diff --git a/engines/glk/detection.h b/engines/glk/detection.h index d61b1a6639c..b538245cf78 100644 --- a/engines/glk/detection.h +++ b/engines/glk/detection.h @@ -77,6 +77,11 @@ public: * Calls each sub-engine in turn to ensure no game Id accidentally shares the same Id */ void detectClashes() const; + + /** + * Return a list of extra GUI options for the specified target. + */ + const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const override; }; namespace Glk { diff --git a/engines/glk/window_text_buffer.cpp b/engines/glk/window_text_buffer.cpp index c1e4ec31b3f..d212d8f7839 100644 --- a/engines/glk/window_text_buffer.cpp +++ b/engines/glk/window_text_buffer.cpp @@ -50,11 +50,15 @@ TextBufferWindow::TextBufferWindow(Windows *windows, uint rock) : TextWindow(win _attrs = _lines[0]._attrs; Common::copy(&g_conf->_tStyles[0], &g_conf->_tStyles[style_NUMSTYLES], _styles); - gli_initialize_tts(); + + if (g_conf->_speak) + gli_initialize_tts(); } TextBufferWindow::~TextBufferWindow() { - gli_free_tts(); + if (g_conf->_speak) + gli_free_tts(); + if (_inBuf) { if (g_vm->gli_unregister_arr) (*g_vm->gli_unregister_arr)(_inBuf, _inMax, "&+#!Cn", _inArrayRock);