scummvm/engines/twine/text.cpp

803 lines
20 KiB
C++
Raw Normal View History

/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "twine/text.h"
2020-11-06 20:49:18 +01:00
#include "common/endian.h"
#include "common/memstream.h"
#include "common/scummsys.h"
#include "common/str.h"
#include "common/system.h"
#include "twine/hqr.h"
2020-10-23 13:44:38 +02:00
#include "twine/input.h"
2020-10-24 12:32:00 +02:00
#include "twine/interface.h"
#include "twine/menu.h"
#include "twine/renderer.h"
#include "twine/resources.h"
#include "twine/scene.h"
#include "twine/screens.h"
#include "twine/sound.h"
#include "twine/twine.h"
namespace TwinE {
2020-10-14 14:20:38 +02:00
/** FLA movie extension */
#define VOX_EXT ".vox"
#define INDEXOFFSET 0
#define DIALOGSOFFSET 1
2020-11-17 19:15:36 +01:00
Text::~Text() {
free(dialTextPtr);
free(dialOrderPtr);
}
void Text::initVoxBank(int32 bankIdx) {
static const char *LanguageSufixTypes[] = {
"sys",
"cre",
"gam", // global game voices (e.g. inventory descriptions)
"000", // Citadel Island voices
"001", // Principal Island voices
"002", // White Leaf Desert voices
"003", // Proxima Island voices
"004", // Rebellion Island voices
"005", // Hamalayi Mountains - sourthern range voices
"006", // Hamalayi Mountains - northern range voices
"007", // Tippett Island voices
"008", // Brundle Island voices
"009", // Fortress Island voices
"010", // Polar Island voices
"011" //
};
if (bankIdx < 0 || bankIdx >= ARRAYSIZE(LanguageSufixTypes)) {
error("bankIdx is out of bounds: %i", bankIdx);
}
2020-10-14 14:20:38 +02:00
// get the correct vox hqr file
currentVoxBankFile = Common::String::format("%s%s" VOX_EXT, LanguageTypes[_engine->cfgfile.LanguageId].id, LanguageSufixTypes[bankIdx]);
// TODO: loop through other languages and take the scummvm settings regarding voices into account...
2020-10-14 14:20:38 +02:00
// TODO check the rest to reverse
}
bool Text::initVoxToPlay(int32 index) { // setVoxFileAtDigit
currDialTextEntry = 0;
2020-10-14 14:20:38 +02:00
voxHiddenIndex = 0;
2020-10-24 12:32:00 +02:00
hasHiddenVox = false;
2020-10-14 14:20:38 +02:00
Common::MemoryReadStream stream((const byte *)dialOrderPtr, dialOrderSize);
2020-10-14 14:20:38 +02:00
// choose right text from order index
for (int32 i = 0; i < numDialTextEntries; i++) {
int32 orderIdx = stream.readSint16LE();
2020-10-14 14:20:38 +02:00
if (orderIdx == index) {
currDialTextEntry = i;
2020-10-14 14:20:38 +02:00
break;
}
}
_engine->_sound->playVoxSample(currDialTextEntry);
2020-10-14 14:20:38 +02:00
return true;
2020-10-14 14:20:38 +02:00
}
bool Text::playVox(int32 index) {
if (!_engine->cfgfile.Voice) {
return false;
}
if (hasHiddenVox && !_engine->_sound->isSamplePlaying(index)) {
_engine->_sound->playVoxSample(index);
return true;
2020-10-14 14:20:38 +02:00
}
return false;
2020-10-14 14:20:38 +02:00
}
bool Text::playVoxSimple(int32 index) {
if (_engine->_sound->isSamplePlaying(index)) {
return true;
2020-10-14 14:20:38 +02:00
}
return playVox(index);
2020-10-14 14:20:38 +02:00
}
bool Text::stopVox(int32 index) {
if (!_engine->_sound->isSamplePlaying(index)) {
return false;
}
2020-10-24 12:32:00 +02:00
hasHiddenVox = false;
_engine->_sound->stopSample(index);
return true;
2020-10-14 14:20:38 +02:00
}
void Text::initTextBank(int32 bankIdx) {
2020-10-14 14:20:38 +02:00
// don't load if we already have the dialogue text bank loaded
if (bankIdx == currentBankIdx) {
2020-10-14 14:20:38 +02:00
return;
}
2020-10-14 14:20:38 +02:00
currentBankIdx = bankIdx;
textVar2[0] = '\0';
2020-10-14 14:20:38 +02:00
// get index according with language
2020-10-27 17:33:09 +01:00
const int32 size = _engine->isLBA1() ? 28 : 30;
2020-11-01 22:25:16 +01:00
// the text banks indices are split into index and dialogs - each entry thus consists of two entries in the hqr
// every 28 entries starts a new language
const int32 languageIndex = _engine->cfgfile.LanguageId * size + (int)bankIdx * 2;
dialOrderSize = HQR::getAllocEntry((uint8 **)&dialOrderPtr, Resources::HQR_TEXT_FILE, languageIndex + INDEXOFFSET);
if (dialOrderSize == 0) {
2020-10-22 13:30:06 +02:00
warning("Failed to initialize text bank %i from file %s", languageIndex, Resources::HQR_TEXT_FILE);
return;
}
2020-10-14 14:20:38 +02:00
numDialTextEntries = dialOrderSize / 2;
2020-10-14 14:20:38 +02:00
if (HQR::getAllocEntry((uint8 **)&dialTextPtr, Resources::HQR_TEXT_FILE, languageIndex + DIALOGSOFFSET) == 0) {
2020-10-22 13:30:06 +02:00
warning("Failed to initialize additional text bank %i from file %s", languageIndex + 1, Resources::HQR_TEXT_FILE);
return;
}
initVoxBank(bankIdx);
2020-10-14 14:20:38 +02:00
}
void Text::drawCharacter(int32 x, int32 y, uint8 character) { // drawCharacter
const uint8 sizeX = getCharWidth(character);
uint8 sizeY = getCharHeight(character);
Common::MemoryReadStream stream(_engine->_resources->fontPtr, _engine->_resources->fontBufSize);
stream.seek(character * 4);
stream.seek(stream.readSint16LE());
stream.skip(2);
x += stream.readByte();
y += stream.readByte();
2020-10-14 14:20:38 +02:00
const uint8 usedColor = dialTextColor;
2020-10-14 14:20:38 +02:00
2020-11-16 18:01:16 +01:00
uint8 *screen2 = (uint8 *)_engine->frontVideoBuffer.getBasePtr(x, y);
2020-10-14 14:20:38 +02:00
int32 tempX = x;
int32 tempY = y;
2020-10-14 14:20:38 +02:00
const int32 toNextLine = SCREEN_WIDTH - sizeX;
2020-10-14 14:20:38 +02:00
do {
uint8 index = stream.readByte();
2020-10-14 14:20:38 +02:00
do {
const uint8 jump = stream.readByte();
screen2 += jump;
2020-10-14 14:20:38 +02:00
tempX += jump;
if (--index == 0) {
screen2 += toNextLine;
2020-10-14 14:20:38 +02:00
tempY++;
tempX = x;
sizeY--;
if (sizeY <= 0) {
return;
}
break;
}
uint8 number = stream.readByte();
for (uint8 i = 0; i < number; i++) {
if (tempX >= SCREEN_TEXTLIMIT_LEFT && tempX < SCREEN_TEXTLIMIT_RIGHT && tempY >= SCREEN_TEXTLIMIT_TOP && tempY < SCREEN_TEXTLIMIT_BOTTOM) {
*((uint8 *)_engine->frontVideoBuffer.getBasePtr(tempX, tempY)) = usedColor;
2020-10-14 14:20:38 +02:00
}
screen2++;
tempX++;
}
if (--index == 0) {
screen2 += toNextLine;
tempY++;
tempX = x;
2020-10-14 14:20:38 +02:00
sizeY--;
if (sizeY <= 0) {
return;
2020-10-14 14:20:38 +02:00
}
break;
2020-10-14 14:20:38 +02:00
}
} while (1);
} while (1);
}
void Text::drawCharacterShadow(int32 x, int32 y, uint8 character, int32 color) { // drawDoubleLetter
2020-10-14 14:20:38 +02:00
int32 left, top, right, bottom;
2020-10-22 13:30:06 +02:00
if (character != ' ') {
2020-10-14 14:20:38 +02:00
// shadow color
setFontColor(0);
drawCharacter(x + 2, y + 4, character);
// text color
setFontColor(color);
drawCharacter(x, y, character);
left = x;
top = y;
// FIXME: get right font size
right = x + 32;
bottom = y + 38;
_engine->copyBlockPhys(left, top, right, bottom);
2020-10-14 14:20:38 +02:00
}
}
void Text::drawText(int32 x, int32 y, const char *dialogue) { // Font
// if the font is not defined
if (_engine->_resources->fontPtr == nullptr) {
2020-10-14 14:20:38 +02:00
return;
}
2020-10-14 14:20:38 +02:00
do {
2020-10-24 12:32:00 +02:00
const uint8 currChar = (uint8) * (dialogue++); // read the next char from the string
2020-10-14 14:20:38 +02:00
if (currChar == '\0') {
2020-10-14 14:20:38 +02:00
break;
}
2020-10-14 14:20:38 +02:00
if (currChar == ' ') {
2020-10-14 14:20:38 +02:00
x += dialCharSpace;
} else {
dialTextSize = getCharWidth(currChar);
drawCharacter(x, y, currChar); // draw the character on screen
2020-10-14 14:20:38 +02:00
// add the length of the space between 2 characters
x += dialSpaceBetween;
// add the length of the current character
x += dialTextSize;
}
} while (1);
}
int32 Text::getTextSize(const char *dialogue) { // SizeFont
2020-10-14 14:20:38 +02:00
dialTextSize = 0;
do {
uint8 currChar = (uint8) * (dialogue++);
2020-10-14 14:20:38 +02:00
if (currChar == 0)
break;
if (currChar == ' ') {
2020-10-14 14:20:38 +02:00
dialTextSize += dialCharSpace;
} else {
dialTextSize += dialSpaceBetween;
dialTextSize += getCharWidth(currChar);
2020-10-14 14:20:38 +02:00
}
} while (1);
return (dialTextSize);
}
void Text::initDialogueBox() { // InitDialWindow
2020-11-16 18:01:16 +01:00
_engine->_interface->blitBox(dialTextBoxLeft, dialTextBoxTop, dialTextBoxRight, dialTextBoxBottom, _engine->workVideoBuffer, dialTextBoxLeft, dialTextBoxTop, _engine->frontVideoBuffer);
2020-10-14 14:20:38 +02:00
if (drawTextBoxBackground) {
_engine->_menu->drawBox(dialTextBoxLeft, dialTextBoxTop, dialTextBoxRight, dialTextBoxBottom);
_engine->_interface->drawTransparentBox(dialTextBoxLeft + 1, dialTextBoxTop + 1, dialTextBoxRight - 1, dialTextBoxBottom - 1, 3);
2020-10-14 14:20:38 +02:00
}
_engine->copyBlockPhys(dialTextBoxLeft, dialTextBoxTop, dialTextBoxRight, dialTextBoxBottom);
_blendInCharactersPos = 0;
2020-11-16 18:01:16 +01:00
_engine->_interface->blitBox(dialTextBoxLeft, dialTextBoxTop, dialTextBoxRight, dialTextBoxBottom, _engine->frontVideoBuffer, dialTextBoxLeft, dialTextBoxTop, _engine->workVideoBuffer);
2020-10-14 14:20:38 +02:00
}
void Text::initInventoryDialogueBox() { // SecondInitDialWindow
2020-11-16 18:01:16 +01:00
_engine->_interface->blitBox(dialTextBoxLeft, dialTextBoxTop, dialTextBoxRight, dialTextBoxBottom, _engine->workVideoBuffer, dialTextBoxLeft, dialTextBoxTop, _engine->frontVideoBuffer);
_engine->copyBlockPhys(dialTextBoxLeft, dialTextBoxTop, dialTextBoxRight, dialTextBoxBottom);
_blendInCharactersPos = 0;
2020-10-14 14:20:38 +02:00
}
// TODO: refactor this code
void Text::initText(int32 index) {
2020-10-14 14:20:38 +02:00
if (!getText(index)) {
printTextVar13 = false;
2020-10-14 14:20:38 +02:00
return;
}
printText8Ptr1 = buf1;
progressiveTextBuffer = buf2;
2020-10-14 14:20:38 +02:00
printTextVar13 = true;
2020-10-14 14:20:38 +02:00
printText8Var1 = 0;
buf1[0] = '\0';
buf2[0] = '\0';
_blendInCharactersPos = 0;
2020-10-14 14:20:38 +02:00
TEXT_CurrentLetterX = dialTextBoxLeft + 8;
printText8Var5 = false;
printText8Var6 = false;
2020-10-14 14:20:38 +02:00
TEXT_CurrentLetterY = dialTextBoxTop + 8;
printText8Var8 = currDialTextPtr;
// lba font is get while engine start
setFontParameters(2, 7);
}
void Text::initProgressiveTextBuffer() {
2020-10-14 14:20:38 +02:00
int32 i = 0;
buf2[0] = '\0';
2020-10-14 14:20:38 +02:00
while (i < dialTextBufferSize) {
strncat(buf2, " ", sizeof(buf2));
2020-10-14 14:20:38 +02:00
i++;
};
progressiveTextBuffer = buf2;
2020-10-14 14:20:38 +02:00
addLineBreakX = 16;
printText8Var1 = 0;
}
void Text::fillFadeInBuffer(int16 x, int16 y, int16 chr) {
if (_blendInCharactersPos < 32) {
_blendInCharacters[_blendInCharactersPos].chr = chr;
_blendInCharacters[_blendInCharactersPos].x = x;
_blendInCharacters[_blendInCharactersPos].y = y;
_blendInCharactersPos++;
return;
}
2020-10-14 14:20:38 +02:00
int32 counter2 = 0;
while (counter2 < 31) {
const int32 var1 = (counter2 + 1);
const int32 var2 = counter2;
_blendInCharacters[var2] = _blendInCharacters[var1];
counter2++;
2020-10-14 14:20:38 +02:00
}
_blendInCharacters[31].chr = chr;
_blendInCharacters[31].x = x;
_blendInCharacters[31].y = y;
2020-10-14 14:20:38 +02:00
}
Text::WordSize Text::getWordSize(const char *arg1, char *arg2) {
2020-10-14 14:20:38 +02:00
int32 temp = 0;
const char *arg2Save = arg2;
2020-10-14 14:20:38 +02:00
while (*arg1 != '\0' && *arg1 != '\1' && *arg1 != ' ') {
2020-10-14 14:20:38 +02:00
temp++;
*arg2++ = *arg1++;
}
WordSize size;
size.inChar = temp;
*arg2 = '\0';
size.inPixel = getTextSize(arg2Save);
return size;
2020-10-14 14:20:38 +02:00
}
void Text::processTextLine() {
2020-10-20 23:52:15 +02:00
char *buffer = printText8Var8;
2020-10-14 14:20:38 +02:00
dialCharSpace = 7;
2020-10-20 23:52:15 +02:00
int16 var4 = 1;
2020-10-14 14:20:38 +02:00
addLineBreakX = 0;
printText8PrepareBufferVar2 = 0;
buf2[0] = 0;
for (;;) {
2020-10-20 23:52:15 +02:00
if (*buffer == ' ') {
2020-10-14 14:20:38 +02:00
buffer++;
continue;
}
2020-11-20 19:03:53 +01:00
if (*buffer == '\0') {
break;
}
2020-10-14 14:20:38 +02:00
2020-11-20 19:03:53 +01:00
printText8Var8 = buffer;
WordSize wordSize = getWordSize(buffer, buf1);
if (addLineBreakX + dialCharSpace + wordSize.inPixel < dialTextBoxParam2) {
char *temp = buffer + 1;
if (*buffer == 1) {
var4 = 0;
buffer = temp;
} else {
if (*buf1 == '@') {
2020-10-14 14:20:38 +02:00
var4 = 0;
buffer = temp;
2020-11-20 19:03:53 +01:00
if (addLineBreakX == 0) {
addLineBreakX = 7;
*((int16 *)buf2) = spaceChar;
}
if (buf1[1] == 'P') {
printText8Var1 = dialTextBoxParam1;
buffer++;
}
2020-10-14 14:20:38 +02:00
} else {
2020-11-20 19:03:53 +01:00
buffer += wordSize.inChar;
printText8Var8 = buffer;
strncat(buf2, buf1, sizeof(buf2));
strncat(buf2, " ", sizeof(buf2)); // not 100% accurate
printText8PrepareBufferVar2++;
addLineBreakX += wordSize.inPixel + dialCharSpace;
if (*printText8Var8 != '\0') {
printText8Var8++;
continue;
2020-10-14 14:20:38 +02:00
}
}
}
}
break;
}
if (printText8PrepareBufferVar2 != 0) {
2020-10-14 14:20:38 +02:00
printText8PrepareBufferVar2--;
}
2020-10-14 14:20:38 +02:00
2020-10-20 23:52:15 +02:00
if (*printText8Var8 != '\0' && var4 == 1) {
if (printText8PrepareBufferVar2 == 0) {
printText8PrepareBufferVar2 = 1;
}
2020-10-14 14:20:38 +02:00
dialCharSpace += (dialTextBoxParam2 - addLineBreakX) / printText8PrepareBufferVar2;
printText10Var1 = dialTextBoxParam2 - addLineBreakX - dialTextBoxParam2 - addLineBreakX; // stupid... recheck
2020-10-14 14:20:38 +02:00
}
printText8Var8 = buffer;
progressiveTextBuffer = buf2;
2020-10-14 14:20:38 +02:00
}
void Text::renderContinueReadingTriangle() {
2020-11-08 13:31:57 +01:00
const int32 right = dialTextBoxRight - 3;
const int32 left = dialTextBoxRight - 24;
const int32 top = dialTextBoxBottom - 24;
const int32 bottom = dialTextBoxBottom - 3;
_engine->_renderer->vertexCoordinates[0] = dialTextStopColor;
2020-11-08 13:31:57 +01:00
_engine->_renderer->vertexCoordinates[1] = right;
_engine->_renderer->vertexCoordinates[2] = top;
_engine->_renderer->vertexCoordinates[3] = dialTextStopColor;
2020-11-08 13:31:57 +01:00
_engine->_renderer->vertexCoordinates[4] = left;
_engine->_renderer->vertexCoordinates[5] = bottom;
_engine->_renderer->vertexCoordinates[6] = dialTextStartColor;
_engine->_renderer->vertexCoordinates[7] = _engine->_renderer->vertexCoordinates[1];
_engine->_renderer->vertexCoordinates[8] = _engine->_renderer->vertexCoordinates[5];
2020-10-14 14:20:38 +02:00
_engine->_renderer->numOfVertex = 3;
2020-10-14 14:20:38 +02:00
_engine->_renderer->renderPolygons(POLYGONTYPE_FLAT, dialTextStopColor);
2020-10-14 14:20:38 +02:00
2020-11-08 13:31:57 +01:00
_engine->copyBlockPhys(left, top, right, bottom);
2020-10-14 14:20:38 +02:00
}
void Text::fadeInCharacters(int32 counter, int32 fontColor) {
_engine->_system->delayMillis(1);
2020-10-14 14:20:38 +02:00
while (--counter >= 0) {
const BlendInCharacter *ptr = &_blendInCharacters[counter];
2020-10-20 23:52:15 +02:00
setFontColor(fontColor);
drawCharacterShadow(ptr->x, ptr->y, ptr->chr, fontColor);
2020-10-20 23:52:15 +02:00
fontColor -= dialTextStepSize;
if (fontColor > dialTextStopColor) {
fontColor = dialTextStopColor;
}
2020-11-20 19:03:53 +01:00
}
2020-10-14 14:20:38 +02:00
}
int32 Text::getCharWidth(uint8 chr) const {
Common::MemoryReadStream stream(_engine->_resources->fontPtr, _engine->_resources->fontBufSize);
stream.seek(chr * 4);
stream.seek(stream.readSint16LE());
return stream.readByte();
2020-10-14 14:20:38 +02:00
}
int32 Text::getCharHeight(uint8 chr) const {
Common::MemoryReadStream stream(_engine->_resources->fontPtr, _engine->_resources->fontBufSize);
stream.seek(chr * 4);
stream.seek(stream.readSint16LE() + 1);
return stream.readByte();
}
2020-10-14 14:20:38 +02:00
// TODO: refactor this code
int Text::printText10() {
if (!printTextVar13) {
2020-10-14 14:20:38 +02:00
return 0;
}
if (*progressiveTextBuffer == '\0') {
if (printText8Var5) {
if (renderTextTriangle) {
renderContinueReadingTriangle();
2020-10-14 14:20:38 +02:00
}
printTextVar13 = false;
2020-10-14 14:20:38 +02:00
return 0;
}
if (printText8Var6) {
2020-11-16 18:01:16 +01:00
_engine->_interface->blitBox(dialTextBoxLeft, dialTextBoxTop, dialTextBoxRight, dialTextBoxBottom, _engine->workVideoBuffer, dialTextBoxLeft, dialTextBoxTop, _engine->frontVideoBuffer);
_engine->copyBlockPhys(dialTextBoxLeft, dialTextBoxTop, dialTextBoxRight, dialTextBoxBottom);
_blendInCharactersPos = 0;
printText8Var6 = false;
2020-10-14 14:20:38 +02:00
TEXT_CurrentLetterX = dialTextBoxLeft + 8;
TEXT_CurrentLetterY = dialTextBoxTop + 8;
}
2020-10-20 23:52:15 +02:00
if (*printText8Var8 == '\0') {
2020-10-14 14:20:38 +02:00
initProgressiveTextBuffer();
printText8Var5 = true;
2020-10-14 14:20:38 +02:00
return 1;
}
processTextLine();
}
// RECHECK this later
if (*progressiveTextBuffer == '\0') {
2020-10-14 14:20:38 +02:00
return 1;
}
fillFadeInBuffer(TEXT_CurrentLetterX, TEXT_CurrentLetterY, *progressiveTextBuffer);
fadeInCharacters(_blendInCharactersPos, dialTextStartColor);
int8 charWidth = getCharWidth(*progressiveTextBuffer);
2020-10-14 14:20:38 +02:00
if (*progressiveTextBuffer != ' ') {
2020-10-14 14:20:38 +02:00
TEXT_CurrentLetterX += charWidth + 2;
} else {
if (printText10Var1 != 0) {
TEXT_CurrentLetterX++;
printText10Var1--;
}
TEXT_CurrentLetterX += dialCharSpace;
}
// next character
progressiveTextBuffer++;
2020-10-14 14:20:38 +02:00
if (*progressiveTextBuffer != '\0') {
2020-10-14 14:20:38 +02:00
return 1;
}
2020-10-14 14:20:38 +02:00
TEXT_CurrentLetterY += 38;
TEXT_CurrentLetterX = dialTextBoxLeft + 8;
if (printText8Var6 && !printText8Var5) {
renderContinueReadingTriangle();
return 2;
2020-10-14 14:20:38 +02:00
}
printText8Var1++;
if (printText8Var1 < dialTextBoxParam1) {
return 1;
}
initProgressiveTextBuffer();
printText8Var6 = true;
2020-10-14 14:20:38 +02:00
2020-10-20 23:52:15 +02:00
if (*printText8Var8 == '\0') {
printText8Var5 = true;
2020-10-14 14:20:38 +02:00
}
return 1;
}
// TODO: refactor this code
bool Text::drawTextFullscreen(int32 index) {
ScopedKeyMap scoped(_engine, cutsceneKeyMapId);
_engine->_interface->saveClip();
_engine->_interface->resetClip();
_engine->_screens->copyScreen(_engine->frontVideoBuffer, _engine->workVideoBuffer);
2020-10-14 14:20:38 +02:00
// get right VOX entry index
initVoxToPlay(index);
2020-10-14 14:20:38 +02:00
bool aborted = false;
2020-10-14 14:20:38 +02:00
// if we don't display text, than still plays vox file
if (_engine->cfgfile.FlagDisplayText) {
2020-10-14 14:20:38 +02:00
initText(index);
initDialogueBox();
int32 printedText;
for (;;) {
_engine->readKeys();
2020-10-14 14:20:38 +02:00
printedText = printText10();
playVox(currDialTextEntry);
2020-10-23 23:38:29 +02:00
if (!printedText && !_engine->_sound->isSamplePlaying(currDialTextEntry)) {
2020-10-14 14:20:38 +02:00
break;
}
if (_engine->shouldQuit() || _engine->_input->toggleAbortAction()) {
aborted = true;
break;
}
_engine->_system->delayMillis(1);
}
2020-10-24 12:32:00 +02:00
hasHiddenVox = false;
2020-10-14 14:20:38 +02:00
printTextVar13 = false;
2020-10-14 14:20:38 +02:00
if (printedText == 0) {
stopVox(currDialTextEntry);
// wait displaying text
for (;;) {
_engine->readKeys();
if (_engine->shouldQuit() || _engine->_input->toggleAbortAction()) {
aborted = true;
break;
}
_engine->_system->delayMillis(1);
}
}
2020-10-14 14:20:38 +02:00
} else { // RECHECK THIS
2020-10-24 12:32:00 +02:00
while (playVox(currDialTextEntry)) {
_engine->readKeys();
if (_engine->shouldQuit() || _engine->_input->toggleAbortAction()) {
aborted = true;
break;
}
2020-10-24 12:32:00 +02:00
_engine->_system->delayMillis(1);
}
2020-10-24 12:32:00 +02:00
hasHiddenVox = false;
2020-10-14 14:20:38 +02:00
voxHiddenIndex = 0;
}
stopVox(currDialTextEntry);
2020-10-14 14:20:38 +02:00
_engine->_interface->loadClip();
return aborted;
2020-10-14 14:20:38 +02:00
}
void Text::setFontParameters(int32 spaceBetween, int32 charSpace) {
2020-10-14 14:20:38 +02:00
dialSpaceBetween = spaceBetween;
dialCharSpace = charSpace;
}
void Text::setFontCrossColor(int32 color) {
2020-10-14 14:20:38 +02:00
dialTextStepSize = -1;
dialTextBufferSize = 14;
dialTextStartColor = color << 4;
dialTextStopColor = (color << 4) + 12;
}
void Text::setFontColor(int32 color) {
2020-10-14 14:20:38 +02:00
dialTextColor = color;
}
void Text::setTextCrossColor(int32 stopColor, int32 startColor, int32 stepSize) {
2020-10-14 14:20:38 +02:00
dialTextStartColor = startColor;
dialTextStopColor = stopColor;
dialTextStepSize = stepSize;
dialTextBufferSize = ((startColor - stopColor) + 1) / stepSize;
}
bool Text::getText(int32 index) {
2020-10-14 14:20:38 +02:00
int32 currIdx = 0;
int32 orderIdx = 0;
const int16 *localTextBuf = (const int16 *)dialTextPtr;
const int16 *localOrderBuf = (const int16 *)dialOrderPtr;
2020-10-14 14:20:38 +02:00
int32 numEntries = numDialTextEntries;
2020-10-14 14:20:38 +02:00
// choose right text from order index
do {
orderIdx = *(localOrderBuf++);
2020-10-20 23:52:15 +02:00
if (orderIdx == index) {
2020-10-14 14:20:38 +02:00
break;
2020-10-20 23:52:15 +02:00
}
2020-10-14 14:20:38 +02:00
currIdx++;
} while (currIdx < numDialTextEntries);
if (currIdx >= numEntries) {
return false;
}
2020-10-14 14:20:38 +02:00
2020-11-06 20:49:18 +01:00
int32 ptrCurrentEntry = READ_LE_INT16(&localTextBuf[currIdx]);
int32 ptrNextEntry = READ_LE_INT16(&localTextBuf[currIdx + 1]);
2020-10-14 14:20:38 +02:00
currDialTextPtr = (dialTextPtr + ptrCurrentEntry);
currDialTextSize = ptrNextEntry - ptrCurrentEntry;
numDialTextEntries = numEntries;
// RECHECK: this was added for vox playback
currDialTextEntry = currIdx;
return true;
2020-10-14 14:20:38 +02:00
}
void Text::copyText(const char *src, char *dst, int32 size) {
for (int32 i = 0; i < size; i++) {
2020-10-14 14:20:38 +02:00
*(dst++) = *(src++);
2020-10-20 23:52:15 +02:00
}
2020-10-14 14:20:38 +02:00
}
bool Text::getMenuText(int32 index, char *text, uint32 textSize) {
if (index == _engine->_menu->currMenuTextIndex) {
if (_engine->_menu->currMenuTextBank == _engine->_scene->sceneTextBank) {
Common::strlcpy(text, _engine->_menu->currMenuTextBuffer, textSize);
return true;
2020-10-14 14:20:38 +02:00
}
}
if (!getText(index)) {
// if doesn't have text
text[0] = '\0';
return false;
2020-10-14 14:20:38 +02:00
}
if ((currDialTextSize - 1) > 0xFF) {
2020-10-14 14:20:38 +02:00
currDialTextSize = 0xFF;
}
2020-10-14 14:20:38 +02:00
copyText(currDialTextPtr, text, currDialTextSize);
2020-10-14 14:20:38 +02:00
currDialTextSize++;
copyText(text, _engine->_menu->currMenuTextBuffer, currDialTextSize);
2020-10-14 14:20:38 +02:00
_engine->_menu->currMenuTextIndex = index;
_engine->_menu->currMenuTextBank = _engine->_scene->sceneTextBank;
return true;
2020-10-14 14:20:38 +02:00
}
void Text::textClipFull() { // newGame2
2020-10-14 14:20:38 +02:00
dialTextBoxLeft = 8;
dialTextBoxTop = 8;
dialTextBoxRight = 631;
dialTextBoxBottom = 471;
dialTextBoxParam1 = 11;
dialTextBoxParam2 = 607;
}
void Text::textClipSmall() { // newGame4
2020-10-14 14:20:38 +02:00
dialTextBoxLeft = 16;
dialTextBoxTop = 334;
dialTextBoxRight = 623;
dialTextBoxBottom = 463;
dialTextBoxParam1 = 3;
dialTextBoxParam2 = 591;
}
2020-10-24 12:32:00 +02:00
void Text::drawAskQuestion(int32 index) {
2020-10-14 14:20:38 +02:00
// get right VOX entry index
initVoxToPlay(index);
2020-10-14 14:20:38 +02:00
initText(index);
initDialogueBox();
2020-11-17 23:01:23 +01:00
int32 textStatus = 1;
2020-10-14 14:20:38 +02:00
do {
_engine->readKeys();
2020-10-14 14:20:38 +02:00
textStatus = printText10();
if (textStatus == 2) {
do {
_engine->readKeys();
if (_engine->shouldQuit()) {
break;
}
2020-10-24 12:32:00 +02:00
if (!playVoxSimple(currDialTextEntry)) {
break;
}
_engine->_system->delayMillis(1);
2020-10-24 12:32:00 +02:00
} while (!_engine->_input->toggleAbortAction());
2020-10-14 14:20:38 +02:00
}
_engine->_system->delayMillis(1);
} while (textStatus);
2020-10-14 14:20:38 +02:00
while (playVoxSimple(currDialTextEntry)) {
2020-10-24 12:32:00 +02:00
if (_engine->shouldQuit() || _engine->_input->toggleAbortAction()) {
stopVox(currDialTextEntry);
break;
}
2020-10-24 12:32:00 +02:00
_engine->_system->delayMillis(1);
}
2020-10-14 14:20:38 +02:00
2020-10-24 12:32:00 +02:00
hasHiddenVox = false;
voxHiddenIndex = 0;
printTextVar13 = false;
2020-10-14 14:20:38 +02:00
}
} // namespace TwinE