Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUPERNOVA: Text To Speech (TTS) for the game #3267

Merged
merged 5 commits into from Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions engines/supernova/detection.cpp
Expand Up @@ -28,6 +28,7 @@
#include "supernova/supernova.h"

#define GAMEOPTION_IMPROVED GUIO_GAMEOPTIONS1
#define GAMEOPTION_TTS GUIO_GAMEOPTIONS2

static const DebugChannelDef debugFlagList[] = {
{Supernova::kDebugGeneral, "general", "Supernova general debug channel"},
Expand All @@ -45,6 +46,16 @@ static const ADExtraGuiOptionsMap optionsList[] = {
}
},

{
GAMEOPTION_TTS,
{
_s("Enable Text to Speech"),
_s("Use TTS to read the descriptions (if TTS is available)"),
"tts_enabled",
false
}
},

AD_EXTRA_GUI_OPTIONS_TERMINATOR
};

Expand All @@ -64,7 +75,7 @@ static const ADGameDescription gameDescriptions[] = {
Common::DE_DEU,
Common::kPlatformDOS,
ADGF_NO_FLAGS,
GUIO2(GAMEOPTION_IMPROVED, GUIO_NOMIDI)
GUIO3(GAMEOPTION_TTS, GAMEOPTION_IMPROVED, GUIO_NOMIDI)
},
{
"msn1",
Expand All @@ -73,7 +84,7 @@ static const ADGameDescription gameDescriptions[] = {
Common::EN_ANY,
Common::kPlatformDOS,
ADGF_NO_FLAGS,
GUIO2(GAMEOPTION_IMPROVED, GUIO_NOMIDI)
GUIO3(GAMEOPTION_TTS, GAMEOPTION_IMPROVED, GUIO_NOMIDI)
},
{
"msn1",
Expand All @@ -82,7 +93,7 @@ static const ADGameDescription gameDescriptions[] = {
Common::IT_ITA,
Common::kPlatformDOS,
ADGF_NO_FLAGS,
GUIO2(GAMEOPTION_IMPROVED, GUIO_NOMIDI)
GUIO3(GAMEOPTION_TTS, GAMEOPTION_IMPROVED, GUIO_NOMIDI)
},
// Mission Supernova 2
criezy marked this conversation as resolved.
Show resolved Hide resolved
{
Expand All @@ -92,7 +103,7 @@ static const ADGameDescription gameDescriptions[] = {
Common::DE_DEU,
Common::kPlatformDOS,
ADGF_NO_FLAGS,
GUIO2(GAMEOPTION_IMPROVED, GUIO_NOMIDI)
GUIO3(GAMEOPTION_TTS, GAMEOPTION_IMPROVED, GUIO_NOMIDI)
},
{
"msn2",
Expand All @@ -101,7 +112,7 @@ static const ADGameDescription gameDescriptions[] = {
Common::EN_ANY,
Common::kPlatformDOS,
ADGF_NO_FLAGS,
GUIO2(GAMEOPTION_IMPROVED, GUIO_NOMIDI)
GUIO3(GAMEOPTION_TTS, GAMEOPTION_IMPROVED, GUIO_NOMIDI)
},
AD_TABLE_END_MARKER
};
Expand Down
26 changes: 23 additions & 3 deletions engines/supernova/game-manager.cpp
Expand Up @@ -21,6 +21,8 @@
*/

#include "common/system.h"
#include "common/config-manager.h"
#include "common/text-to-speech.h"
#include "graphics/cursorman.h"
#include "graphics/palette.h"
#include "gui/message.h"
Expand Down Expand Up @@ -360,6 +362,8 @@ void GameManager::processInput() {
onInventoryArrowDown
} mouseLocation;

Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();

if (_mouseField >= 0 && _mouseField < 256)
mouseLocation = onObject;
else if (_mouseField >= 256 && _mouseField < 512)
Expand Down Expand Up @@ -529,12 +533,18 @@ void GameManager::processInput() {
case onInventory:
_guiInventory[_mouseField - 512].setHighlight(true);
_currentInputObject = _inventory.get(_mouseField - 512 + _inventoryScroll);
if (ttsMan != nullptr && ConfMan.getBool("tts_enabled") && !isNullObject(_currentInputObject))
ttsMan->say(_vm->getGameString(_currentInputObject->_name), Common::kDos850);
break;
case onCmdButton:
_guiCommandButton[_mouseField - 256].setHighlight(true);
if (ttsMan != nullptr && ConfMan.getBool("tts_enabled"))
ttsMan->say(_guiCommandButton[_mouseField - 256].getText(), Common::kDos850);
break;
case onObject:
_currentInputObject = _currentRoom->getObject(_mouseField);
if (ttsMan != nullptr && ConfMan.getBool("tts_enabled") && !isNullObject(_currentInputObject))
ttsMan->say(_vm->getGameString(_currentInputObject->_name), Common::kDos850);
break;
case onNone:
default:
Expand All @@ -555,13 +565,23 @@ bool GameManager::isNullObject(Object *obj) {
void GameManager::sentence(int number, bool brightness) {
if (number < 0)
return;
criezy marked this conversation as resolved.
Show resolved Hide resolved
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
Common::String string;

_vm->renderBox(0, 141 + _rowsStart[number] * 10, 320, _rows[number] * 10 - 1, brightness ? kColorWhite44 : kColorWhite25);
if (_texts[_rowsStart[number]] == kStringDialogSeparator)
if (_texts[_rowsStart[number]] == kStringDialogSeparator) {
_vm->renderText(kStringConversationEnd, 1, 142 + _rowsStart[number] * 10, brightness ? kColorRed : kColorDarkRed);
else {
for (int r = _rowsStart[number]; r < _rowsStart[number] + _rows[number]; ++r)
string = _vm->getGameString(kStringConversationEnd);
} else {
for (int r = _rowsStart[number]; r < _rowsStart[number] + _rows[number]; ++r) {
_vm->renderText(_texts[r], 1, 142 + r * 10, brightness ? kColorGreen : kColorDarkGreen);
if (!string.empty())
string += " ";
string += _vm->getGameString(_texts[r]);
}
}
if (ttsMan != nullptr && ConfMan.getBool("tts_enabled") && brightness)
ttsMan->say(string, Common::TextToSpeechManager::QUEUE_NO_REPEAT, Common::kDos850);
}

void GameManager::say(int textId) {
Expand Down
1 change: 1 addition & 0 deletions engines/supernova/game-manager.h
Expand Up @@ -101,6 +101,7 @@ class GuiElement : public Common::Rect {

class GameManager {
public:

GameManager(SupernovaEngine *vm, Sound *sound);
virtual ~GameManager();

Expand Down
6 changes: 6 additions & 0 deletions engines/supernova/screen.cpp
Expand Up @@ -27,6 +27,7 @@
#include "graphics/palette.h"
#include "graphics/surface.h"
#include "common/config-manager.h"
#include "common/text-to-speech.h"

#include "supernova/imageid.h"
#include "supernova/resman.h"
Expand Down Expand Up @@ -286,6 +287,7 @@ void Screen::renderMessage(int stringId, MessagePosition position,
text = Common::String::format(text.c_str(), var1.c_str());
}


renderMessage(text, position);
}

Expand Down Expand Up @@ -530,6 +532,10 @@ void Screen::renderMessage(const char *text, MessagePosition position, int posit
int y = 0;
byte textColor = 0;

Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
if (ttsMan != nullptr && ConfMan.getBool("tts_enabled"))
ttsMan->say(text, Common::TextToSpeechManager::QUEUE_NO_REPEAT, Common::kDos850);

criezy marked this conversation as resolved.
Show resolved Hide resolved
while (*p != '\0') {
row[numRows] = p;
++numRows;
Expand Down
8 changes: 7 additions & 1 deletion engines/supernova/supernova.cpp
Expand Up @@ -33,7 +33,9 @@
#include "common/str.h"
#include "common/system.h"
#include "common/translation.h"
#include "common/text-to-speech.h"
#include "engines/util.h"
#include "engines/advancedDetector.h"
#include "graphics/cursorman.h"
#include "graphics/surface.h"
#include "graphics/screen.h"
Expand Down Expand Up @@ -99,6 +101,7 @@ SupernovaEngine::SupernovaEngine(OSystem *syst)
_MSPart = 0;

_improved = ConfMan.getBool("improved");

}

SupernovaEngine::~SupernovaEngine() {
Expand All @@ -110,6 +113,10 @@ SupernovaEngine::~SupernovaEngine() {
}

Common::Error SupernovaEngine::run() {
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
if (ttsMan != nullptr)
ttsMan->setLanguage(ConfMan.get("language"));

init();

while (!shouldQuit()) {
Expand Down Expand Up @@ -830,5 +837,4 @@ void SupernovaEngine::stopSound() {
_sound->stop();
}


}