Permalink
Browse files

STARTREK: Cleanup some text code

  • Loading branch information...
Drenn1 authored and sev- committed May 20, 2018
1 parent a6bee58 commit 66b4ec36bdfb19a5242325e58c3180bc79574c89
Showing with 36 additions and 28 deletions.
  1. +6 −1 engines/startrek/awaymission.cpp
  2. +2 −2 engines/startrek/menu.cpp
  3. +3 −3 engines/startrek/startrek.h
  4. +25 −22 engines/startrek/text.cpp
@@ -31,7 +31,7 @@ void StarTrekEngine::initAwayMission() {
// memset(bitmapBuffer->pixels, 0, 0xfa00);

_txtFilename = "ground";
_itemDescription = "";
_loadedText = "";

// sub_23a60(); // TODO
_sound->loadMusicFile("ground");
@@ -425,6 +425,11 @@ void StarTrekEngine::handleAwayMissionCommand() {
else {
if (command.action.activeObject == OBJECT_REDSHIRT)
showTextbox("", getItemDescription(0x4c), 20, 20, TEXTCOLOR_YELLOW, 0);

// Show generic "nothing of note" text.
// BUG? This text is also shown after looking at the redshirt. However, his
// text is normally overridden on a per-mission basis, so perhaps this bug
// never manifests itself?
showTextbox("", getItemDescription(0x4d), 20, 20, TEXTCOLOR_YELLOW, 0);
}
break;
@@ -839,7 +839,7 @@ void StarTrekEngine::showQuitGamePrompt(int x, int y) {
return;

_inQuitGameMenu = true;
int val = showText(&StarTrekEngine::readTextFromArray, (uintptr)options, x, y, 0xb0, true, 0, 1);
int val = showText(&StarTrekEngine::readTextFromArray, (uintptr)options, x, y, TEXTCOLOR_YELLOW, true, 0, true);
_inQuitGameMenu = false;

if (val == 0) {
@@ -863,7 +863,7 @@ void StarTrekEngine::showTextConfigurationMenu(bool fromOptionMenu) {

int val;
if (fromOptionMenu || (val = loadTextDisplayMode()) == -1) {
val = showText(&StarTrekEngine::readTextFromArray, (uintptr)options, 20, 30, 0xb0, true, 0, 1);
val = showText(&StarTrekEngine::readTextFromArray, (uintptr)options, 20, 30, TEXTCOLOR_YELLOW, true, 0, true);
saveTextDisplayMode(val);
}

@@ -317,12 +317,12 @@ class StarTrekEngine : public ::Engine {
String readTextFromRdf(int choiceIndex, uintptr data, String *headerTextOutput);
String readTextFromBuffer(int choiceIndex, uintptr data, String *headerTextOutput);

int showTextbox(String headerText, const String &mainText, int xoffset, int yoffset, byte textColor, int maxTextLines); // TODO: better name. (return type?)
void showTextbox(String headerText, const String &mainText, int xoffset, int yoffset, byte textColor, int maxTextLines); // TODO: better name. (return type?)

String skipTextAudioPrompt(const String &str);
String playTextAudio(const String &str);

int showText(TextGetterFunc textGetter, uintptr var, int xoffset, int yoffset, int textColor, bool loopChoices, int maxTextLines, int arg10);
int showText(TextGetterFunc textGetter, uintptr var, int xoffset, int yoffset, int textColor, bool loopChoices, int maxTextLines, bool rclickCancelsChoice);

int getNumTextboxLines(const String &str);
String putTextIntoLines(const String &text);
@@ -403,7 +403,7 @@ class StarTrekEngine : public ::Engine {
int32 _playerActorScale;

Common::String _txtFilename;
Common::String _itemDescription;
Common::String _loadedText; // TODO: might be OK to delete this

// Queue of "commands" (ie. next frame, clicked on object) for away mission or bridge
Common::Queue<Command> _commandQueue;
@@ -40,7 +40,6 @@ const char *StarTrekEngine::getNextTextLine(const char *text, char *lineOutput,

const char *lastSpaceInput = nullptr;
char *lastSpaceOutput = nullptr;
int var4;
int charIndex = 0;

while (charIndex != lineWidth && *text != '\0') {
@@ -52,7 +51,6 @@ const char *StarTrekEngine::getNextTextLine(const char *text, char *lineOutput,
}

if (c == ' ') {
var4 = charIndex;
lastSpaceInput = text;
lastSpaceOutput = lineOutput;
}
@@ -132,13 +130,14 @@ String StarTrekEngine::readTextFromRdf(int choiceIndex, uintptr data, String *he
/**
* Shows text with the given header and main text.
*/
int StarTrekEngine::showTextbox(String headerText, const String &mainText, int xoffset, int yoffset, byte textColor, int maxTextLines) {
void StarTrekEngine::showTextbox(String headerText, const String &mainText, int xoffset, int yoffset, byte textColor, int maxTextLines) {
if (!headerText.empty()) {
while (headerText.size() < TEXTBOX_WIDTH - 2)
headerText += ' ';
}

int newMaxTextLines = (maxTextLines < 0 ? 0 : maxTextLines);
int commandParam = (maxTextLines < 0 ? 0 : maxTextLines);

if (maxTextLines < 0)
maxTextLines = -maxTextLines;

@@ -151,11 +150,9 @@ int StarTrekEngine::showTextbox(String headerText, const String &mainText, int x
strings[1] = mainText.c_str();
strings[2] = "";

showText(&StarTrekEngine::readTextFromArray, (uintptr)strings, xoffset, yoffset, textColor, false, maxTextLines, 0);
showText(&StarTrekEngine::readTextFromArray, (uintptr)strings, xoffset, yoffset, textColor, false, maxTextLines, false);

// TODO
// sub_15a77();
// sub_14669(newMaxTextLines);
addCommand(Command(COMMAND_TALK, commandParam, 0, 0));
}

String StarTrekEngine::skipTextAudioPrompt(const String &str) {
@@ -199,12 +196,16 @@ String StarTrekEngine::playTextAudio(const String &str) {
return String(text+1);
}

int StarTrekEngine::showText(TextGetterFunc textGetter, uintptr var, int xoffset, int yoffset, int textColor, bool loopChoices, int maxTextLines, int arg10) {
/**
* @param rclickCancelsChoice If true, right-clicks return "-1" as choice instead of
* whetever was selected.
*/
int StarTrekEngine::showText(TextGetterFunc textGetter, uintptr var, int xoffset, int yoffset, int textColor, bool loopChoices, int maxTextLines, bool rclickCancelsChoice) {
int16 tmpTextDisplayMode = _textDisplayMode;

uint32 var7c = 8;
if (_frameIndex > _textboxVar2+1) {
var7c = 0x10;
uint32 ticksUntilClickingEnabled = 8;
if (_frameIndex > _textboxVar2 + 1) {
ticksUntilClickingEnabled = 0x10;
}

int numChoicesWithNames = 0;
@@ -217,11 +218,11 @@ int StarTrekEngine::showText(TextGetterFunc textGetter, uintptr var, int xoffset
if (choiceText.empty())
break;

int lines = getNumTextboxLines(choiceText);
int lines = getNumTextboxLines(skipTextAudioPrompt(choiceText));
if (lines > numTextboxLines)
numTextboxLines = lines;

if (!speakerText.empty()) // Technically should check for nullptr
if (!speakerText.empty()) // FIXME: Technically should check for nullptr
numChoicesWithNames++;

numChoices++;
@@ -256,6 +257,8 @@ int StarTrekEngine::showText(TextGetterFunc textGetter, uintptr var, int xoffset
String lineFormattedText = readLineFormattedText(textGetter, var, choiceIndex, textBitmap, numTextboxLines, &numTextLines);

if (lineFormattedText.empty()) { // Technically should check for nullptr
_gfx->delSprite(&textboxSprite);

// TODO
}
else {
@@ -280,7 +283,7 @@ int StarTrekEngine::showText(TextGetterFunc textGetter, uintptr var, int xoffset

disableMenuButtons(1 << TEXTBUTTON_SCROLLUP); // Disable scroll up

if (var7c == 0) { // Disable done button
if (ticksUntilClickingEnabled == 0) { // Disable done button
disableMenuButtons(1 << TEXTBUTTON_CONFIRM);
}
if (!loopChoices) { // Disable prev button
@@ -291,19 +294,19 @@ int StarTrekEngine::showText(TextGetterFunc textGetter, uintptr var, int xoffset

// Loop until text is done being displayed
while (!doneShowingText) {
int textboxReturnCode = handleMenuEvents(var7c, true);
int textboxReturnCode = handleMenuEvents(ticksUntilClickingEnabled, true);

if (var7c == 0) {
if (ticksUntilClickingEnabled == 0) {
enableMenuButtons(1 << TEXTBUTTON_CONFIRM);
}

switch(textboxReturnCode) {

case MENUEVENT_RCLICK_OFFBUTTON:
case MENUEVENT_RCLICK_ONBUTTON:
if (var7c == 0) {
if (ticksUntilClickingEnabled == 0) {
doneShowingText = true;
if (arg10)
if (rclickCancelsChoice)
choiceIndex = -1;
}
break;
@@ -411,19 +414,19 @@ int StarTrekEngine::showText(TextGetterFunc textGetter, uintptr var, int xoffset
default:
break;
}

ticksUntilClickingEnabled = 0;
}

_gfx->setMouseBitmap(oldMouseBitmap);
_gfx->warpMouse(oldMousePos.x, oldMousePos.y);

_mouseControllingShip = tmpMouseControllingShip;
unloadMenuButtons();
textboxSprite.field16 = true;
textboxSprite.bitmapChanged = true;

textboxSprite.dontDrawNextFrame();
_gfx->drawAllSprites();
_gfx->delSprite(&textboxSprite);
// sub_272B4
}

_textboxVar2 = _frameIndex;

0 comments on commit 66b4ec3

Please sign in to comment.