Permalink
Browse files

STARTREK: Begin implementing menus

  • Loading branch information...
Drenn1 authored and sev- committed Feb 25, 2018
1 parent 2dd96e0 commit 7c62092367d00418d930411ff4a080f6ad2d0417
@@ -36,6 +36,7 @@ class FileStream : public Common::SeekableReadStreamEndian {
Common::SeekableReadStream *_stream;
bool _bigEndian;

public:
// ReadStream functions
virtual bool eos() const;
virtual uint32 read(void* dataPtr, uint32 dataSize);
@@ -289,6 +289,8 @@ void Graphics::drawAllSprites() {
// TODO: implement properly
for (int i=0; i<_numSprites; i++) {
Sprite *spr = _sprites[i];
spr->drawX = spr->pos.x;
spr->drawY = spr->pos.y;
drawSprite(*spr);
}
}
@@ -47,10 +47,24 @@ const int SCREEN_WIDTH = 320;
const int SCREEN_HEIGHT = 200;

const int MAX_SPRITES = 32;
const int MAX_MENUBUTTONS = 16; // This is arbitrary, the original game has no such limit

const int TEXTBOX_WIDTH = 26;


// Keeps track of data for a list of buttons making up a menu
struct Menu {
Sprite sprites[MAX_MENUBUTTONS];
uint16 retvals[MAX_MENUBUTTONS];
uint16 buttonVar2;
SharedPtr<FileStream> menuFile;
uint16 numButtons;
uint16 buttonVar1;
SharedPtr<Menu> nextMenu;

Menu() : nextMenu(SharedPtr<Menu>()) {}
};

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

@@ -110,7 +124,7 @@ class Graphics {
Common::String skipOverAudioPrompt(const Common::String &str);
int getNumLines(const Common::String &str);
Common::String readLineFormattedText(TextGetterFunc textGetter, int var, int choiceIndex, SharedPtr<TextBitmap> textBitmap, int numTextboxLines, int *numLines);
void loadTextButtons(Common::String mnuFilename, int xpos, int ypos);
void loadMenuButtons(Common::String mnuFilename, int xpos, int ypos);
void warpMousePosition(int x, int y);

uint16 _textboxVar1;
@@ -121,6 +135,8 @@ class Graphics {
uint16 _textboxVar6;
uint16 _textboxVar7;
bool _textboxHasMultipleChoices;

SharedPtr<Menu> _activeMenu;
};

}
@@ -58,6 +58,18 @@ struct Sprite {
void setBitmap(SharedPtr<Bitmap> b);
};


class SpriteList {
public:
SpriteList(int n) { sprites = new Sprite[n]; }
~SpriteList() { delete[] sprites; }

Sprite &operator[](int i) const { return sprites[i]; }

private:
Sprite *sprites;
};

}

#endif
@@ -109,17 +109,17 @@ Common::Error StarTrekEngine::run() {
_gfx->addSprite(spr);
spr->bitmap = _gfx->loadBitmap("MWALKE00");
spr->drawPriority = 1;
spr->drawX = 150;
spr->drawY = 30;
spr->pos.x = 150;
spr->pos.y = 30;
spr->drawMode = 0;

// Draw mode 2 (translucent background)
spr = new Sprite;
_gfx->addSprite(spr);
spr->bitmap = _gfx->loadBitmap("KWALKS00");
spr->drawPriority = 1;
spr->drawX = 200;
spr->drawY = 40;
spr->pos.x = 200;
spr->pos.y = 40;
spr->drawMode = 2;

// Draw mode 3 (text)
@@ -128,19 +128,21 @@ Common::Error StarTrekEngine::run() {
spr->bitmap = SharedPtr<Bitmap>(new TextBitmap(8*8,8*8));
for (int i=0;i<8*8;i++)
spr->bitmap->pixels[i] = 0x40+i;
spr->drawX = 8*10;
spr->drawY = 50;
spr->pos.x = 8*10;
spr->pos.y = 50;
spr->textColor = 0xb3;
spr->drawMode = 3;

// initTextSprite function
/*
spr = new Sprite;
int x=0,y=0;
_gfx->initTextSprite(&x, &y, 0xb3, 3, false, spr);
spr->drawY = 150;
spr->pos.y = 150;
_gfx->showText(&Graphics::tmpFunction, 0, 0, 0, 0xb3, 0, 10, 0);
_gfx->showText(&Graphics::tmpFunction, 0, 50, 50, 0xb3, 0, 10, 0);
*/

while (!shouldQuit()) {
pollEvents();
@@ -64,6 +64,8 @@ int Graphics::showText(TextGetterFunc textGetter, int var, int xoffset, int yoff
Sprite textboxSprite;
SharedPtr<TextBitmap> textBitmap = initTextSprite(&xoffset, &yoffset, textColor, numTextboxLines, numChoicesWithNames, &textboxSprite);

debug("X: %d, Y: %d\n", xoffset, yoffset);

int choiceIndex = 0;
int var28 = 0;
if (tmpTextboxVar1 != 0 && tmpTextboxVar1 != 1 && numChoices == 1
@@ -84,7 +86,7 @@ int Graphics::showText(TextGetterFunc textGetter, int var, int xoffset, int yoff
// TODO
}
else {
loadTextButtons("textbtns", xoffset+0x96, yoffset-0x11);
loadMenuButtons("textbtns", xoffset+0x96, yoffset-0x11);

Common::Point oldMousePos = _mousePos;
SharedPtr<Bitmap> oldMouseBitmap = _mouseSprite.bitmap;
@@ -140,15 +142,13 @@ int Graphics::showText(TextGetterFunc textGetter, int var, int xoffset, int yoff
return choiceIndex;
}

const char* text = "Text test";

Common::String Graphics::tmpFunction(int choiceIndex, int var, Common::String *speakerTextOutput) {
if (speakerTextOutput != nullptr)
*speakerTextOutput = "Speaker";

if (choiceIndex >= 1)
return NULL;
return text;
return "Text test";
}

/**
@@ -178,17 +178,25 @@ SharedPtr<TextBitmap> Graphics::initTextSprite(int *xoffsetPtr, int *yoffsetPtr,
if (varC < 0)
xoffset += varC;

debug("xoffset A: %d", xoffset);

varC = xoffset - (bitmap->width+0x1d)/2;
if (varC < 1)
xoffset += varC-1;

debug("xoffset B: %d", xoffset);

varC = yoffset - (bitmap->height+0x11) - 20;
if (varC < 0)
yoffset -= varC;

debug("Mid xoffset: %d", xoffset);

xoffset -= (bitmap->width+0x1d)/2;
yoffset -= bitmap->height;

debug("Final xoffset: %d", xoffset);

bitmap->pixels[0] = 0x10;
memset(&bitmap->pixels[1], 0x11, TEXTBOX_WIDTH-2);
bitmap->pixels[TEXTBOX_WIDTH-1] = 0x12;
@@ -242,7 +250,7 @@ Common::String Graphics::readLineFormattedText(TextGetterFunc textGetter, int va
// TODO
*numPrintedLines = 1;

int numChars = textBitmap->width*textBitmap->height;
uint numChars = textBitmap->width*textBitmap->height;

Common::String text = (this->*textGetter)(choiceIndex, var, nullptr);
while (text.size() < numChars) text += ' ';
@@ -257,11 +265,37 @@ Common::String Graphics::readLineFormattedText(TextGetterFunc textGetter, int va
return text;
}

void Graphics::loadTextButtons(Common::String mnuFilename, int xpos, int ypos) {
// TODO: start of function
void Graphics::loadMenuButtons(Common::String mnuFilename, int xpos, int ypos) {
SharedPtr<Menu> oldMenu = _activeMenu;
_activeMenu = SharedPtr<Menu>(new Menu());
_activeMenu->nextMenu = oldMenu;

SharedPtr<Common::SeekableReadStream> mnuFile = _vm->openFile(mnuFilename + ".MNU");
int numEntries = mnuFile->size()/16;
SharedPtr<FileStream> stream = _vm->openFile(mnuFilename + ".MNU");

_activeMenu->menuFile = stream;
_activeMenu->numButtons = _activeMenu->menuFile->size()/16;

for (int i=0; i<_activeMenu->numButtons; i++) {
memset(&_activeMenu->sprites[i], 0, sizeof(Sprite));
addSprite(&_activeMenu->sprites[i]);
_activeMenu->sprites[i].drawMode = 2;

char bitmapBasename[11];
stream->seek(i*16, SEEK_SET);
stream->read(bitmapBasename, 10);
for (int j=0; j<10; j++) {
if (bitmapBasename[j] == ' ')
bitmapBasename[j] = '\0';
}
bitmapBasename[10] = '\0';

_activeMenu->sprites[i].bitmap = loadBitmap(bitmapBasename);
_activeMenu->sprites[i].pos.x = stream->readUint16() + xpos;
_activeMenu->sprites[i].pos.y = stream->readUint16() + ypos;
_activeMenu->retvals[i] = stream->readUint16();

_activeMenu->sprites[i].field6 = 8;
}
}

void Graphics::warpMousePosition(int x, int y) {

0 comments on commit 7c62092

Please sign in to comment.