aboutsummaryrefslogtreecommitdiff
path: root/engines/toltecs
diff options
context:
space:
mode:
authorBenjamin Haisch2009-12-09 14:52:07 +0000
committerWillem Jan Palenstijn2011-11-20 22:43:08 +0100
commit28c74ff3b4c65be64636d0d679a88acc3fd23f84 (patch)
treec673d0920fd54c2d6025e0cf143779da469f11ab /engines/toltecs
parent3d0775bd8987c6d5a80da18a4d97eaf6d3adb77e (diff)
downloadscummvm-rg350-28c74ff3b4c65be64636d0d679a88acc3fd23f84.tar.gz
scummvm-rg350-28c74ff3b4c65be64636d0d679a88acc3fd23f84.tar.bz2
scummvm-rg350-28c74ff3b4c65be64636d0d679a88acc3fd23f84.zip
TOLTECS: More work on the menu; started with the saveload menu page and fixed some early bugs
Diffstat (limited to 'engines/toltecs')
-rw-r--r--engines/toltecs/menu.cpp140
-rw-r--r--engines/toltecs/menu.h27
-rw-r--r--engines/toltecs/toltecs.h1
3 files changed, 162 insertions, 6 deletions
diff --git a/engines/toltecs/menu.cpp b/engines/toltecs/menu.cpp
index a82477bc73..62ff65eaf8 100644
--- a/engines/toltecs/menu.cpp
+++ b/engines/toltecs/menu.cpp
@@ -34,6 +34,7 @@
#include "toltecs/toltecs.h"
#include "toltecs/menu.h"
+#include "toltecs/palette.h"
#include "toltecs/resource.h"
#include "toltecs/screen.h"
@@ -41,6 +42,7 @@ namespace Toltecs {
MenuSystem::MenuSystem(ToltecsEngine *vm) : _vm(vm) {
_currMenuID = kMenuIdNone;
+ //_newMenuID = kMenuIdLoad;
_newMenuID = kMenuIdMain;
_currItemID = kItemIdNone;
_cfgText = true;
@@ -60,7 +62,15 @@ int MenuSystem::run() {
_background = new Graphics::Surface();
_background->create(640, 400, 1);
+ _top = 30 - _vm->_guiHeight / 2;
+
+ memset(_vm->_screen->_frontScreen, 250, 640 * 400);
+
memcpy(_background->pixels, _vm->_screen->_frontScreen, 640 * 400);
+
+ _vm->_palette->buildColorTransTable(0, 16, 7);
+
+ shadeRect(60, 39, 520, 246, 30, 94);
while (1) {
update();
@@ -129,7 +139,7 @@ void MenuSystem::drawItem(ItemID itemID, bool active) {
Item *item = getItem(itemID);
if (item) {
byte color = active ? item->activeColor : item->defaultColor;
- drawString(item->rect.left, item->rect.top, 0, item->fontNum, color, (byte*)item->caption.c_str());
+ drawString(item->rect.left, item->y, 0, item->fontNum, color, (byte*)item->caption.c_str());
}
}
@@ -167,7 +177,7 @@ void MenuSystem::setItemCaption(Item *item, const byte *caption) {
Font font(_vm->_res->load(_vm->_screen->getFontResIndex(item->fontNum))->data);
int width = font.getTextWidth((byte*)caption);
int height = font.getHeight();
- item->rect = Common::Rect(item->x, item->y, item->x + width, item->y + height);
+ item->rect = Common::Rect(item->x, item->y - height, item->x + width, item->y);
if (item->w) {
item->rect.translate(item->w - width / 2, 0);
}
@@ -191,6 +201,21 @@ void MenuSystem::initMenu(MenuID menuID) {
addClickTextItem(kItemIdPlay, 0, 245, 320, 0, (const byte*)"PLAY", kFontColorMenuDefault, kFontColorMenuActive);
addClickTextItem(kItemIdQuit, 0, 275, 320, 0, (const byte*)"QUIT GAME", kFontColorMenuDefault, kFontColorMenuActive);
break;
+ case kMenuIdLoad:
+ drawString(0, 74, 320, 1, 229, (byte*)"Load game");
+ addClickTextItem(kItemIdSavegameUp, 0, 155, 545, 1, (const byte*)"^", 255, 253);
+ addClickTextItem(kItemIdSavegameDown, 0, 195, 545, 1, (const byte*)"\\", 255, 253);
+ addClickTextItem(kItemIdCancel, 0, 275, 320, 0, (const byte*)"CANCEL", 255, 253);
+ addClickTextItem(kItemIdSavegame1, 0, 115 + 20 * 0, 300, 0, (const byte*)"SAVEGAME 1", 231, 234);
+ addClickTextItem(kItemIdSavegame2, 0, 115 + 20 * 1, 300, 0, (const byte*)"SAVEGAME 2", 231, 234);
+ addClickTextItem(kItemIdSavegame3, 0, 115 + 20 * 2, 300, 0, (const byte*)"SAVEGAME 3", 231, 234);
+ addClickTextItem(kItemIdSavegame4, 0, 115 + 20 * 3, 300, 0, (const byte*)"SAVEGAME 4", 231, 234);
+ addClickTextItem(kItemIdSavegame5, 0, 115 + 20 * 4, 300, 0, (const byte*)"SAVEGAME 5", 231, 234);
+ addClickTextItem(kItemIdSavegame6, 0, 115 + 20 * 5, 300, 0, (const byte*)"SAVEGAME 6", 231, 234);
+ addClickTextItem(kItemIdSavegame7, 0, 115 + 20 * 6, 300, 0, (const byte*)"SAVEGAME 7", 231, 234);
+ initSavegames();
+ setSavegameCaptions();
+ break;
case kMenuIdVolumes:
drawString(0, 74, 320, 1, 229, (byte*)"Adjust volume");
drawString(0, 130, 200, 0, 244, (byte*)"Master");
@@ -243,12 +268,17 @@ void MenuSystem::clickItem(ItemID id) {
break;
case kItemIdLoad:
debug("kItemIdLoad");
+ _newMenuID = kMenuIdLoad;
break;
case kItemIdToggleText:
setCfgText(!_cfgText, true);
+ if (!_cfgVoices && !_cfgText)
+ setCfgVoices(true, false);
break;
case kItemIdToggleVoices:
setCfgVoices(!_cfgVoices, true);
+ if (!_cfgVoices && !_cfgText)
+ setCfgText(true, false);
break;
case kItemIdVolumesMenu:
debug("kItemIdVolumesMenu");
@@ -295,6 +325,14 @@ void MenuSystem::clickItem(ItemID id) {
_newMenuID = kMenuIdMain;
break;
// Save/Load menu
+ case kItemIdSavegame1:
+ case kItemIdSavegame2:
+ case kItemIdSavegame3:
+ case kItemIdSavegame4:
+ case kItemIdSavegame5:
+ case kItemIdSavegame6:
+ clickSavegameItem(id);
+ break;
default:
break;
}
@@ -316,19 +354,109 @@ void MenuSystem::restoreRect(int x, int y, int w, int h) {
}
}
+void MenuSystem::shadeRect(int x, int y, int w, int h, byte color1, byte color2) {
+ byte *src = (byte*)_background->getBasePtr(x, y);
+ for (int xc = 0; xc < w; xc++) {
+ src[xc] = color1;
+ //src[xc] = 46;
+ }
+ src += 640;
+ w -= 2;
+ h -= 2;
+ while (h--) {
+ src[0] = color2;
+ src[w + 1] = color2;
+ for (int xc = 1; xc < w; xc++) {
+ src[xc] = _vm->_palette->getColorTransPixel(src[xc]);
+ }
+ src += 640;
+ }
+}
+
void MenuSystem::drawString(int16 x, int16 y, int w, uint fontNum, byte color, byte *text) {
fontNum = _vm->_screen->getFontResIndex(fontNum);
+ Font font(_vm->_res->load(fontNum)->data);
if (w) {
- Font font(_vm->_res->load(fontNum)->data);
x = x + w - font.getTextWidth(text) / 2;
}
- _vm->_screen->drawString(x, y, color, fontNum, text, -1, NULL, true);
+ _vm->_screen->drawString(x, y - font.getHeight(), color, fontNum, text, -1, NULL, true);
+}
+
+void MenuSystem::initSavegames() {
+
+ _savegameListTopIndex = 0;
+ _savegames.clear();
+
+ Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
+ Toltecs::ToltecsEngine::SaveHeader header;
+ Common::String pattern = _vm->getTargetName();
+ pattern += ".???";
+
+ Common::StringList filenames;
+ filenames = saveFileMan->listSavefiles(pattern.c_str());
+ Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)
+
+ for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++) {
+ Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str());
+ if (in) {
+ if (_vm->readSaveHeader(in, false, header) == Toltecs::ToltecsEngine::kRSHENoError) {
+ _savegames.push_back(SavegameItem(*file, header.description));
+ debug("%s -> %s", file->c_str(), header.description.c_str());
+ }
+ delete in;
+ }
+ }
+
+}
+
+void MenuSystem::setSavegameCaptions() {
+ int index = _savegameListTopIndex;
+ setItemCaption(getItem(kItemIdSavegame1), index < _savegames.size() ? (const byte*)_savegames[index++]._description.c_str() : (const byte*)"");
+ setItemCaption(getItem(kItemIdSavegame2), index < _savegames.size() ? (const byte*)_savegames[index++]._description.c_str() : (const byte*)"");
+ setItemCaption(getItem(kItemIdSavegame3), index < _savegames.size() ? (const byte*)_savegames[index++]._description.c_str() : (const byte*)"");
+ setItemCaption(getItem(kItemIdSavegame4), index < _savegames.size() ? (const byte*)_savegames[index++]._description.c_str() : (const byte*)"");
+ setItemCaption(getItem(kItemIdSavegame5), index < _savegames.size() ? (const byte*)_savegames[index++]._description.c_str() : (const byte*)"");
+ setItemCaption(getItem(kItemIdSavegame6), index < _savegames.size() ? (const byte*)_savegames[index++]._description.c_str() : (const byte*)"");
+ setItemCaption(getItem(kItemIdSavegame7), index < _savegames.size() ? (const byte*)_savegames[index++]._description.c_str() : (const byte*)"");
+}
+
+void MenuSystem::clickSavegameItem(ItemID id) {
+ if (_currMenuID == kMenuIdLoad) {
+ SavegameItem *savegameItem;
+ switch (id) {
+ case kItemIdSavegame1:
+ savegameItem = &_savegames[_savegameListTopIndex + 0];
+ break;
+ case kItemIdSavegame2:
+ savegameItem = &_savegames[_savegameListTopIndex + 1];
+ break;
+ case kItemIdSavegame3:
+ savegameItem = &_savegames[_savegameListTopIndex + 2];
+ break;
+ case kItemIdSavegame4:
+ savegameItem = &_savegames[_savegameListTopIndex + 3];
+ break;
+ case kItemIdSavegame5:
+ savegameItem = &_savegames[_savegameListTopIndex + 4];
+ break;
+ case kItemIdSavegame6:
+ savegameItem = &_savegames[_savegameListTopIndex + 5];
+ break;
+ default:
+ return;
+ }
+
+ debug("filename = [%s]; description = [%s]", savegameItem->_filename.c_str(), savegameItem->_description.c_str());
+
+ } else {
+ }
}
void MenuSystem::setCfgText(bool value, bool active) {
if (_cfgText != value) {
Item *item = getItem(kItemIdToggleText);
_cfgText = value;
+ restoreRect(item->rect.left, item->rect.top, item->rect.width() + 1, item->rect.height() - 2);
if (_cfgText)
setItemCaption(item, (const byte*)"TEXT ON");
else
@@ -341,6 +469,7 @@ void MenuSystem::setCfgVoices(bool value, bool active) {
if (_cfgVoices != value) {
Item *item = getItem(kItemIdToggleVoices);
_cfgVoices = value;
+ restoreRect(item->rect.left, item->rect.top, item->rect.width() + 1, item->rect.height() - 2);
if (_cfgVoices)
setItemCaption(item, (const byte*)"VOICES ON");
else
@@ -378,7 +507,8 @@ void MenuSystem::drawVolumeBar(ItemID itemID) {
return;
}
- restoreRect(390, y, 100, 25);
+ Font font(_vm->_res->load(_vm->_screen->getFontResIndex(1))->data);
+ restoreRect(390, y - font.getHeight(), 100, 25);
for (int i = 0; i < volume; i++)
text[i] = '|';
diff --git a/engines/toltecs/menu.h b/engines/toltecs/menu.h
index 41541a88e9..2709acf4fc 100644
--- a/engines/toltecs/menu.h
+++ b/engines/toltecs/menu.h
@@ -86,6 +86,15 @@ enum ItemID {
kItemIdDone,
kItemIdCancel,
// Save/load menu
+ kItemIdSavegameUp,
+ kItemIdSavegameDown,
+ kItemIdSavegame1,
+ kItemIdSavegame2,
+ kItemIdSavegame3,
+ kItemIdSavegame4,
+ kItemIdSavegame5,
+ kItemIdSavegame6,
+ kItemIdSavegame7,
// TODO
kMenuIdDummy
};
@@ -111,14 +120,26 @@ protected:
int x, y, w;
uint fontNum;
};
+
+ struct SavegameItem {
+ Common::String _filename;
+ Common::String _description;
+ SavegameItem()
+ : _filename(""), _description("") {}
+ SavegameItem(Common::String filename, Common::String description)
+ : _filename(filename), _description(description) {}
+ };
ToltecsEngine *_vm;
Graphics::Surface *_background;
MenuID _currMenuID, _newMenuID;
ItemID _currItemID;
+ int _top;
+ int _savegameListTopIndex;
Common::Array<Item> _items;
+ Common::Array<SavegameItem> _savegames;
bool _cfgText, _cfgVoices;
int _cfgMasterVolume, _cfgVoicesVolume, _cfgMusicVolume, _cfgSoundFXVolume, _cfgBackgroundVolume;
@@ -142,8 +163,12 @@ protected:
void saveBackground();
void restoreBackground();
void restoreRect(int x, int y, int w, int h);
+ void shadeRect(int x, int y, int w, int h, byte color1, byte color2);
void drawString(int16 x, int16 y, int w, uint fontNum, byte color, byte *text);
-
+
+ void initSavegames();
+ void setSavegameCaptions();
+ void clickSavegameItem(ItemID id);
void setCfgText(bool value, bool active);
void setCfgVoices(bool value, bool active);
void drawVolumeBar(ItemID itemID);
diff --git a/engines/toltecs/toltecs.h b/engines/toltecs/toltecs.h
index b425af8274..e870137fae 100644
--- a/engines/toltecs/toltecs.h
+++ b/engines/toltecs/toltecs.h
@@ -75,6 +75,7 @@ public:
const ToltecsGameDescription *_gameDescription;
uint32 getFeatures() const;
Common::Language getLanguage() const;
+ const Common::String& getTargetName() const { return _targetName; }
void loadScene(uint resIndex);