aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Stewart2018-02-24 21:48:06 -0500
committerEugene Sandulenko2018-08-09 08:37:30 +0200
commit7c62092367d00418d930411ff4a080f6ad2d0417 (patch)
tree42f4daad22d481457e0c1ef4d768f9e5c3929ba4
parent2dd96e044f46aed90ed1b6dbc682bc01f43e438c (diff)
downloadscummvm-rg350-7c62092367d00418d930411ff4a080f6ad2d0417.tar.gz
scummvm-rg350-7c62092367d00418d930411ff4a080f6ad2d0417.tar.bz2
scummvm-rg350-7c62092367d00418d930411ff4a080f6ad2d0417.zip
STARTREK: Begin implementing menus
-rw-r--r--engines/startrek/filestream.h1
-rwxr-xr-xengines/startrek/graphics.cpp2
-rwxr-xr-xengines/startrek/graphics.h18
-rw-r--r--engines/startrek/sprite.h12
-rwxr-xr-xengines/startrek/startrek.cpp18
-rw-r--r--engines/startrek/text.cpp52
6 files changed, 85 insertions, 18 deletions
diff --git a/engines/startrek/filestream.h b/engines/startrek/filestream.h
index 899f639ad5..475bbcfeea 100644
--- a/engines/startrek/filestream.h
+++ b/engines/startrek/filestream.h
@@ -36,6 +36,7 @@ private:
Common::SeekableReadStream *_stream;
bool _bigEndian;
+public:
// ReadStream functions
virtual bool eos() const;
virtual uint32 read(void* dataPtr, uint32 dataSize);
diff --git a/engines/startrek/graphics.cpp b/engines/startrek/graphics.cpp
index 307efcb1b5..cf63faa889 100755
--- a/engines/startrek/graphics.cpp
+++ b/engines/startrek/graphics.cpp
@@ -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);
}
}
diff --git a/engines/startrek/graphics.h b/engines/startrek/graphics.h
index ef146a2d7a..88e68cbea7 100755
--- a/engines/startrek/graphics.h
+++ b/engines/startrek/graphics.h
@@ -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 @@ private:
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 @@ private:
uint16 _textboxVar6;
uint16 _textboxVar7;
bool _textboxHasMultipleChoices;
+
+ SharedPtr<Menu> _activeMenu;
};
}
diff --git a/engines/startrek/sprite.h b/engines/startrek/sprite.h
index 280a0d2755..93fd2dc53f 100644
--- a/engines/startrek/sprite.h
+++ b/engines/startrek/sprite.h
@@ -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
diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp
index 10ec35fcc1..8dd4f9010e 100755
--- a/engines/startrek/startrek.cpp
+++ b/engines/startrek/startrek.cpp
@@ -109,8 +109,8 @@ 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)
@@ -118,8 +118,8 @@ Common::Error StarTrekEngine::run() {
_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();
diff --git a/engines/startrek/text.cpp b/engines/startrek/text.cpp
index 5af9bc0c9e..dcc4b88d91 100644
--- a/engines/startrek/text.cpp
+++ b/engines/startrek/text.cpp
@@ -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) {