SUPERNOVA: Add Text To Speech support

This commit is contained in:
taylorzhancher 2021-09-05 02:24:12 +08:00 committed by GitHub
parent 7db6a06e01
commit fa8845e367
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 9 deletions

View File

@ -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"},
@ -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
};
@ -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",
@ -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",
@ -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
{
@ -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",
@ -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
};

View File

@ -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"
@ -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)
@ -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:
@ -555,13 +565,23 @@ bool GameManager::isNullObject(Object *obj) {
void GameManager::sentence(int number, bool brightness) {
if (number < 0)
return;
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) {

View File

@ -101,6 +101,7 @@ private:
class GameManager {
public:
GameManager(SupernovaEngine *vm, Sound *sound);
virtual ~GameManager();

View File

@ -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"
@ -286,6 +287,7 @@ void Screen::renderMessage(int stringId, MessagePosition position,
text = Common::String::format(text.c_str(), var1.c_str());
}
renderMessage(text, position);
}
@ -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);
while (*p != '\0') {
row[numRows] = p;
++numRows;

View File

@ -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"
@ -99,6 +101,7 @@ SupernovaEngine::SupernovaEngine(OSystem *syst)
_MSPart = 0;
_improved = ConfMan.getBool("improved");
}
SupernovaEngine::~SupernovaEngine() {
@ -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()) {
@ -830,5 +837,4 @@ void SupernovaEngine::stopSound() {
_sound->stop();
}
}