Permalink
Browse files

STARTREK: Disabling menu buttons + text menu.

  • Loading branch information...
Drenn1 authored and sev- committed May 7, 2018
1 parent 69dac4d commit e1d70e6a04bd2457cd3f12e8cbc3e819533787e5
@@ -49,7 +49,7 @@ Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) {
_backgroundImage = new Bitmap(_vm->openFile("DEMON0.BMP").get());

_numSprites = 0;
_textboxVar1 = 2;
_textDisplayMode = TEXTDISPLAY_WAIT;

CursorMan.showMouse(true);
}
@@ -64,7 +64,7 @@ struct Menu {
};

class Graphics;
typedef String (Graphics::*TextGetterFunc)(int, void *, String *);
typedef String (Graphics::*TextGetterFunc)(int, uintptr, String *);


class Graphics {
@@ -115,10 +115,11 @@ class Graphics {

// text.cpp (TODO: separate class)
public:
int showText(TextGetterFunc textGetter, int 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, int arg10);

String readTextFromRdf(int choiceIndex, void *data, String *headerTextOutput);
String readTextFromBuffer(int choiceIndex, void *data, String *headerTextOutput);
String readTextFromRdf(int choiceIndex, uintptr data, String *headerTextOutput);
String readTextFromBuffer(int choiceIndex, uintptr data, String *headerTextOutput);
String readTextFromArray(int choiceIndex, uintptr data, String *headerTextOutput);

private:
int handleTextboxEvents(uint32 ticksUntilClickingEnabled, bool arg4);
@@ -129,7 +130,7 @@ class Graphics {
int getNumLines(const String &str);
void getTextboxHeader(String *headerTextOutput, String speakerText, int choiceIndex);

String readLineFormattedText(TextGetterFunc textGetter, int var, int choiceIndex, SharedPtr<TextBitmap> textBitmap, int numTextboxLines, int *numLines);
String readLineFormattedText(TextGetterFunc textGetter, uintptr var, int choiceIndex, SharedPtr<TextBitmap> textBitmap, int numTextboxLines, int *numLines);
String putTextIntoLines(const String &text);
const char *getNextTextLine(const char *text, char *line, int lineWidth);

@@ -139,11 +140,16 @@ class Graphics {
int getMenuButtonAt(const Menu &menu, int x, int y);
void drawMenuButtonOutline(SharedPtr<Bitmap> bitmap, byte color);
void loadMenuButtons(String mnuFilename, int xpos, int ypos);
void setMenuButtonVar2Bits(uint32 bits);
void clearMenuButtonVar2Bits(uint32 bits);
void disableMenuButton(uint32 bits);
void enableMenuButton(uint32 bits);

public:
void openTextConfigurationMenu(bool fromOptionMenu);
int loadTextDisplayMode();
void saveTextDisplayMode(int value);

uint16 _textboxVar1;
private:
int16 _textDisplayMode;
uint32 _textboxVar2;
uint32 _textboxVar3;
uint16 _textboxVar6;
@@ -154,7 +154,7 @@ void Sound::playSoundEffect(const char *baseSoundName) {
if (readStream == nullptr)
error("Couldn't open '%s'", soundName.c_str());

debugC(5, kDebugSound, "Playing sound effect '%s'", baseSoundName);
debugC(5, kDebugSound, "Playing sound effect '%s'", soundName.c_str());
Audio::AudioStream *audioStream = Audio::makeVOCStream(readStream, Audio::FLAG_UNSIGNED, DisposeAfterUse::YES);
_vm->_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandles[i], audioStream);
return;
@@ -75,16 +75,6 @@ Common::Error StarTrekEngine::run() {

initializeEventsAndMouse();

// Hexdump data
#if 0
Common::SeekableReadStream *stream = openFile("BRIDGE.PAL");
byte *data = (byte *)malloc(stream->size());
stream->read(data, stream->size());
Common::hexdump(data, stream->size());
free(data);
delete stream;
#endif

// Test graphics/music:

// Music Status:
@@ -149,6 +139,7 @@ Common::Error StarTrekEngine::run() {
*/


_gfx->openTextConfigurationMenu(false);
_gfx->showText(&Graphics::readTextFromRdf, 0x2220, 150, 160, 0xb3, 0, 10, 0);

while (!shouldQuit()) {
@@ -72,6 +72,12 @@ enum TrekEventType {
TREKEVENT_KEYDOWN = 6
};

enum TextDisplayMode {
TEXTDISPLAY_WAIT = 0, // Wait for input before closing text
TEXTDISPLAY_SUBTITLES, // Automatically continue when speech is done
TEXTDISPLAY_NONE // No text displayed
};

struct TrekEvent {
TrekEventType type;
Common::KeyState kbd;
@@ -46,8 +46,8 @@ enum TextEvent {

namespace StarTrek {

int Graphics::showText(TextGetterFunc textGetter, int var, int xoffset, int yoffset, int textColor, bool loopChoices, int maxTextLines, int arg10) {
uint16 tmpTextboxVar1 = _textboxVar1;
int Graphics::showText(TextGetterFunc textGetter, uintptr var, int xoffset, int yoffset, int textColor, bool loopChoices, int maxTextLines, int arg10) {
int16 tmpTextDisplayMode = _textDisplayMode;

uint32 var7c = 8;
if (_textboxVar3 > _textboxVar2+1) {
@@ -60,7 +60,7 @@ int Graphics::showText(TextGetterFunc textGetter, int var, int xoffset, int yoff
String speakerText;

while(true) {
String choiceText = (this->*textGetter)(numChoices, &var, &speakerText);
String choiceText = (this->*textGetter)(numChoices, var, &speakerText);
if (choiceText.empty())
break;

@@ -87,13 +87,14 @@ int Graphics::showText(TextGetterFunc textGetter, int var, int xoffset, int yoff

int choiceIndex = 0;
int scrollOffset = 0;
if (tmpTextboxVar1 != 0 && tmpTextboxVar1 != 1 && numChoices == 1
&& _vm->_sfxEnabled && !_vm->_audioEnabled)
if (tmpTextDisplayMode != TEXTDISPLAY_WAIT && tmpTextDisplayMode != TEXTDISPLAY_SUBTITLES
&& numChoices == 1 && _vm->_sfxEnabled && !_vm->_audioEnabled)
_textboxHasMultipleChoices = false;
else
_textboxHasMultipleChoices = true;

if (tmpTextboxVar1 >= 0 && tmpTextboxVar1 <= 2 && _vm->_sfxEnabled && !_vm->_audioEnabled)
if (tmpTextDisplayMode >= TEXTDISPLAY_WAIT && tmpTextDisplayMode <= TEXTDISPLAY_NONE
&& _vm->_sfxEnabled && !_vm->_audioEnabled)
_textboxVar6 = true;
else
_textboxVar6 = false;
@@ -119,13 +120,13 @@ int Graphics::showText(TextGetterFunc textGetter, int var, int xoffset, int yoff
int var80 = (numChoices > 1 ? 0x18 : 0);

// TODO: sub_288FB function call
// TODO: sub_28ACA(0x0002);
disableMenuButton(0x0002); // Disable scroll up

if (var7c == 0) {
// sub_28ACA(0x0001);
if (var7c == 0) { // Disable done button
disableMenuButton(0x0001);
}
if (loopChoices == 0) {
// sub_28ACA(0x0008);
if (!loopChoices) { // Disable prev button
disableMenuButton(0x0008);
}

bool doneShowingText = false;
@@ -135,7 +136,7 @@ int Graphics::showText(TextGetterFunc textGetter, int var, int xoffset, int yoff
int textboxReturnCode = handleTextboxEvents(var7c, true);

if (var7c == 0) {
clearMenuButtonVar2Bits(0x0001);
enableMenuButton(0x0001);
}

switch(textboxReturnCode) {
@@ -178,21 +179,21 @@ int Graphics::showText(TextGetterFunc textGetter, int var, int xoffset, int yoff
goto readjustScrollDown;

readjustScrollUp:
clearMenuButtonVar2Bits(0x0004);
enableMenuButton(0x0004);
if (scrollOffset < 0)
scrollOffset = 0;
if (scrollOffset == 0)
setMenuButtonVar2Bits(0x0002);
disableMenuButton(0x0002);
goto readjustScroll;

readjustScrollDown:
clearMenuButtonVar2Bits(0x0002);
enableMenuButton(0x0002);
if (scrollOffset >= numTextLines)
scrollOffset -= numTextboxLines;
if (scrollOffset > numTextLines-1)
scrollOffset = numTextLines-1;
if (scrollOffset+numTextboxLines >= numTextLines)
setMenuButtonVar2Bits(0x0004);
disableMenuButton(0x0004);
goto readjustScroll;

readjustScroll:
@@ -208,20 +209,20 @@ int Graphics::showText(TextGetterFunc textGetter, int var, int xoffset, int yoff
case TEXTEVENT_PREVCHOICE:
choiceIndex--;
if (!loopChoices && choiceIndex == 0) {
setMenuButtonVar2Bits(0x0008);
disableMenuButton(0x0008);
}
else {
if (choiceIndex < 0)
choiceIndex = numChoices-1;
}
clearMenuButtonVar2Bits(0x0010);
enableMenuButton(0x0010);
goto reloadText;

case TEXTEVENT_NEXTCHOICE:
clearMenuButtonVar2Bits(0x0008);
enableMenuButton(0x0008);
choiceIndex++;
if (!loopChoices && choiceIndex == numChoices-1) {
setMenuButtonVar2Bits(0x0010);
disableMenuButton(0x0010);
}
else {
choiceIndex %= numChoices;
@@ -237,8 +238,8 @@ int Graphics::showText(TextGetterFunc textGetter, int var, int xoffset, int yoff
else {
// sub_288FB(0x001F);
}
clearMenuButtonVar2Bits(0x0004);
setMenuButtonVar2Bits(0x0002);
enableMenuButton(0x0004);
disableMenuButton(0x0002);
textboxSprite.bitmapChanged = true;
break;

@@ -314,7 +315,7 @@ int Graphics::handleTextboxEvents(uint32 ticksUntilClickingEnabled, bool arg4) {

if (_vm->_finishedPlayingSpeech != 0) {
_vm->_finishedPlayingSpeech = 0;
if (_textboxVar1 != 0) {
if (_textDisplayMode != TEXTDISPLAY_WAIT) {
return TEXTEVENT_SPEECH_DONE;
}
}
@@ -358,10 +359,10 @@ int Graphics::handleTextboxEvents(uint32 ticksUntilClickingEnabled, bool arg4) {
/**
* Text getter for showText which reads from an rdf file.
*/
String Graphics::readTextFromRdf(int choiceIndex, void *data, String *headerTextOutput) {
String Graphics::readTextFromRdf(int choiceIndex, uintptr data, String *headerTextOutput) {
Room *room = _vm->getRoom();

int rdfVar = *(int*)data;
int rdfVar = (size_t)data;

uint16 textOffset = room->readRdfWord(rdfVar + (choiceIndex+1)*2);

@@ -387,9 +388,9 @@ String Graphics::readTextFromRdf(int choiceIndex, void *data, String *headerText
/**
* Text getter for showText which reads from a given buffer.
*/
String Graphics::readTextFromBuffer(int choiceIndex, void *data, String *headerTextOutput) {
String Graphics::readTextFromBuffer(int choiceIndex, uintptr data, String *headerTextOutput) {
char buf[TEXTBOX_WIDTH];
memcpy(buf, data, TEXTBOX_WIDTH-2);
memcpy(buf, (byte*)data, TEXTBOX_WIDTH-2);
buf[TEXTBOX_WIDTH-2] = '\0';

*headerTextOutput = String(buf);
@@ -398,6 +399,25 @@ String Graphics::readTextFromBuffer(int choiceIndex, void *data, String *headerT
return String(text);
}

/**
* Text getter for showText which reads choices from an array of pointers.
* Last element in the array must be an empty string.
*/
String Graphics::readTextFromArray(int choiceIndex, uintptr data, String *headerTextOutput) {
const char **textArray = (const char**)data;

const char *headerText = textArray[0];
const char *mainText = textArray[choiceIndex+1];

if (*mainText == '\0')
return Common::String(); // Technically should be nullptr...

*headerTextOutput = headerText;
while (headerTextOutput->size() < TEXTBOX_WIDTH-2)
*headerTextOutput += ' ';
return String(mainText);
}

/**
* Creates a blank textbox in a TextBitmap, and initializes a sprite to use it.
*/
@@ -535,17 +555,18 @@ void Graphics::getTextboxHeader(String *headerTextOutput, String speakerText, in
*headerTextOutput = header;
}

String Graphics::readLineFormattedText(TextGetterFunc textGetter, int var, int choiceIndex, SharedPtr<TextBitmap> textBitmap, int numTextboxLines, int *numTextLines) {
String Graphics::readLineFormattedText(TextGetterFunc textGetter, uintptr var, int choiceIndex, SharedPtr<TextBitmap> textBitmap, int numTextboxLines, int *numTextLines) {
String headerText;
String text = (this->*textGetter)(choiceIndex, &var, &headerText);
String text = (this->*textGetter)(choiceIndex, var, &headerText);

if (_textboxVar1 == 2 && _vm->_sfxEnabled && _vm->_audioEnabled) {
if (_textDisplayMode == TEXTDISPLAY_NONE && _vm->_sfxEnabled && _vm->_audioEnabled) {
uint32 oldSize = text.size();
text = playTextAudio(text);
if (oldSize != text.size())
_textboxHasMultipleChoices = true;
}
else if ((_textboxVar1 == 0 || _textboxVar1 == 1) && _vm->_sfxEnabled && _vm->_audioEnabled) {
else if ((_textDisplayMode == TEXTDISPLAY_WAIT || _textDisplayMode == TEXTDISPLAY_SUBTITLES)
&& _vm->_sfxEnabled && _vm->_audioEnabled) {
text = playTextAudio(text);
}
else {
@@ -802,16 +823,66 @@ void Graphics::loadMenuButtons(String mnuFilename, int xpos, int ypos) {
_textboxButtonVar4 = 0;
}

// 0x0002: Disable scroll up
// 0x0004: Disable scroll down
// 0x0008: Disable prev choice
// 0x0010: Disable next choice
void Graphics::setMenuButtonVar2Bits(uint32 bits) {
// TODO
// Values for standard text displays:
// 0x0001: Disable done button
// 0x0002: Disable scroll up
// 0x0004: Disable scroll down
// 0x0008: Disable prev choice
// 0x0010: Disable next choice
void Graphics::disableMenuButton(uint32 bits) {
_activeMenu->disabledButtons |= bits;
if (_activeMenu->selectedButton != -1
&& (_activeMenu->disabledButtons & (1<<_activeMenu->selectedButton))) {
Sprite *sprite = &_activeMenu->sprites[_activeMenu->selectedButton];
drawMenuButtonOutline(sprite->bitmap, 0x00);

sprite->bitmapChanged = true;
_activeMenu->selectedButton = -1;
}
}

void Graphics::enableMenuButton(uint32 bits) {
_activeMenu->disabledButtons &= ~bits;
}

/**
* This can be called from startup or from the options menu.
* On startup, this tries to load the setting without user input.
*/
void Graphics::openTextConfigurationMenu(bool fromOptionMenu) {
const char *options[] = { // TODO: languages...
"Text display",
"Text subtitles.",
"Display text until you press enter.",
"No text displayed.",
""
};

int val;
if (fromOptionMenu || (val = loadTextDisplayMode()) == -1) {
// TODO: fix X coordinate (should be 0x14, not 130)
val = showText(&Graphics::readTextFromArray, (uintptr)options, 130, 0x1e, 0xb0, true, 0, 1);
saveTextDisplayMode(val);
}

switch(val) {
case 0:
_textDisplayMode = TEXTDISPLAY_SUBTITLES;
break;
case 1:
_textDisplayMode = TEXTDISPLAY_WAIT;
break;
case 2:
_textDisplayMode = TEXTDISPLAY_NONE;
break;
}
}

void Graphics::clearMenuButtonVar2Bits(uint32 bits) {
// TODO
int Graphics::loadTextDisplayMode() {
return -1; // TODO
}
void Graphics::saveTextDisplayMode(int value) {
// TODO;
}

}

0 comments on commit e1d70e6

Please sign in to comment.