Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
STARTREK: Disabling menu buttons + text menu.
  • Loading branch information
Stewmath authored and sev- committed Aug 9, 2018
1 parent 69dac4d commit e1d70e6
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 59 deletions.
2 changes: 1 addition & 1 deletion engines/startrek/graphics.cpp
Expand Up @@ -49,7 +49,7 @@ Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) {
_backgroundImage = new Bitmap(_vm->openFile("DEMON0.BMP").get()); _backgroundImage = new Bitmap(_vm->openFile("DEMON0.BMP").get());


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


CursorMan.showMouse(true); CursorMan.showMouse(true);
} }
Expand Down
22 changes: 14 additions & 8 deletions engines/startrek/graphics.h
Expand Up @@ -64,7 +64,7 @@ struct Menu {
}; };


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




class Graphics { class Graphics {
Expand Down Expand Up @@ -115,10 +115,11 @@ class Graphics {


// text.cpp (TODO: separate class) // text.cpp (TODO: separate class)
public: 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 readTextFromRdf(int choiceIndex, uintptr data, String *headerTextOutput);
String readTextFromBuffer(int choiceIndex, void *data, String *headerTextOutput); String readTextFromBuffer(int choiceIndex, uintptr data, String *headerTextOutput);
String readTextFromArray(int choiceIndex, uintptr data, String *headerTextOutput);


private: private:
int handleTextboxEvents(uint32 ticksUntilClickingEnabled, bool arg4); int handleTextboxEvents(uint32 ticksUntilClickingEnabled, bool arg4);
Expand All @@ -129,7 +130,7 @@ class Graphics {
int getNumLines(const String &str); int getNumLines(const String &str);
void getTextboxHeader(String *headerTextOutput, String speakerText, int choiceIndex); 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); String putTextIntoLines(const String &text);
const char *getNextTextLine(const char *text, char *line, int lineWidth); const char *getNextTextLine(const char *text, char *line, int lineWidth);


Expand All @@ -139,11 +140,16 @@ class Graphics {
int getMenuButtonAt(const Menu &menu, int x, int y); int getMenuButtonAt(const Menu &menu, int x, int y);
void drawMenuButtonOutline(SharedPtr<Bitmap> bitmap, byte color); void drawMenuButtonOutline(SharedPtr<Bitmap> bitmap, byte color);
void loadMenuButtons(String mnuFilename, int xpos, int ypos); void loadMenuButtons(String mnuFilename, int xpos, int ypos);
void setMenuButtonVar2Bits(uint32 bits); void disableMenuButton(uint32 bits);
void clearMenuButtonVar2Bits(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 _textboxVar2;
uint32 _textboxVar3; uint32 _textboxVar3;
uint16 _textboxVar6; uint16 _textboxVar6;
Expand Down
2 changes: 1 addition & 1 deletion engines/startrek/sound.cpp
Expand Up @@ -154,7 +154,7 @@ void Sound::playSoundEffect(const char *baseSoundName) {
if (readStream == nullptr) if (readStream == nullptr)
error("Couldn't open '%s'", soundName.c_str()); 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); Audio::AudioStream *audioStream = Audio::makeVOCStream(readStream, Audio::FLAG_UNSIGNED, DisposeAfterUse::YES);
_vm->_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandles[i], audioStream); _vm->_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandles[i], audioStream);
return; return;
Expand Down
11 changes: 1 addition & 10 deletions engines/startrek/startrek.cpp
Expand Up @@ -75,16 +75,6 @@ Common::Error StarTrekEngine::run() {


initializeEventsAndMouse(); 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: // Test graphics/music:


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




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


while (!shouldQuit()) { while (!shouldQuit()) {
Expand Down
6 changes: 6 additions & 0 deletions engines/startrek/startrek.h
Expand Up @@ -72,6 +72,12 @@ enum TrekEventType {
TREKEVENT_KEYDOWN = 6 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 { struct TrekEvent {
TrekEventType type; TrekEventType type;
Common::KeyState kbd; Common::KeyState kbd;
Expand Down
149 changes: 110 additions & 39 deletions engines/startrek/text.cpp
Expand Up @@ -46,8 +46,8 @@ enum TextEvent {


namespace StarTrek { namespace StarTrek {


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


if (_vm->_finishedPlayingSpeech != 0) { if (_vm->_finishedPlayingSpeech != 0) {
_vm->_finishedPlayingSpeech = 0; _vm->_finishedPlayingSpeech = 0;
if (_textboxVar1 != 0) { if (_textDisplayMode != TEXTDISPLAY_WAIT) {
return TEXTEVENT_SPEECH_DONE; return TEXTEVENT_SPEECH_DONE;
} }
} }
Expand Down Expand Up @@ -358,10 +359,10 @@ int Graphics::handleTextboxEvents(uint32 ticksUntilClickingEnabled, bool arg4) {
/** /**
* Text getter for showText which reads from an rdf file. * 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(); Room *room = _vm->getRoom();


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


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


Expand All @@ -387,9 +388,9 @@ String Graphics::readTextFromRdf(int choiceIndex, void *data, String *headerText
/** /**
* Text getter for showText which reads from a given buffer. * 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]; char buf[TEXTBOX_WIDTH];
memcpy(buf, data, TEXTBOX_WIDTH-2); memcpy(buf, (byte*)data, TEXTBOX_WIDTH-2);
buf[TEXTBOX_WIDTH-2] = '\0'; buf[TEXTBOX_WIDTH-2] = '\0';


*headerTextOutput = String(buf); *headerTextOutput = String(buf);
Expand All @@ -398,6 +399,25 @@ String Graphics::readTextFromBuffer(int choiceIndex, void *data, String *headerT
return String(text); 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. * Creates a blank textbox in a TextBitmap, and initializes a sprite to use it.
*/ */
Expand Down Expand Up @@ -535,17 +555,18 @@ void Graphics::getTextboxHeader(String *headerTextOutput, String speakerText, in
*headerTextOutput = header; *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 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(); uint32 oldSize = text.size();
text = playTextAudio(text); text = playTextAudio(text);
if (oldSize != text.size()) if (oldSize != text.size())
_textboxHasMultipleChoices = true; _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); text = playTextAudio(text);
} }
else { else {
Expand Down Expand Up @@ -802,16 +823,66 @@ void Graphics::loadMenuButtons(String mnuFilename, int xpos, int ypos) {
_textboxButtonVar4 = 0; _textboxButtonVar4 = 0;
} }


// 0x0002: Disable scroll up // Values for standard text displays:
// 0x0004: Disable scroll down // 0x0001: Disable done button
// 0x0008: Disable prev choice // 0x0002: Disable scroll up
// 0x0010: Disable next choice // 0x0004: Disable scroll down
void Graphics::setMenuButtonVar2Bits(uint32 bits) { // 0x0008: Disable prev choice
// TODO // 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) { int Graphics::loadTextDisplayMode() {
// TODO return -1; // TODO
}
void Graphics::saveTextDisplayMode(int value) {
// TODO;
} }


} }

0 comments on commit e1d70e6

Please sign in to comment.