aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjohndoe1232013-01-29 15:40:41 +0000
committerWillem Jan Palenstijn2013-05-08 20:47:43 +0200
commit8749efdea821433cf355ae4fa543ef412f33c2fe (patch)
treeaabfe5ebe3c0d88c775a0cd752e23ecced76cce8
parenta03879963f2e8adebd1f4bb90975ff0c43f286dc (diff)
downloadscummvm-rg350-8749efdea821433cf355ae4fa543ef412f33c2fe.tar.gz
scummvm-rg350-8749efdea821433cf355ae4fa543ef412f33c2fe.tar.bz2
scummvm-rg350-8749efdea821433cf355ae4fa543ef412f33c2fe.zip
NEVERHOOD: Add game-internal savegame delete menu
- Rename Widget::addSprite to Widget::initialize
-rw-r--r--engines/neverhood/menumodule.cpp167
-rw-r--r--engines/neverhood/menumodule.h26
-rw-r--r--engines/neverhood/neverhood.h1
-rw-r--r--engines/neverhood/saveload.cpp7
4 files changed, 179 insertions, 22 deletions
diff --git a/engines/neverhood/menumodule.cpp b/engines/neverhood/menumodule.cpp
index 0ba9bc03fa..8b0353287c 100644
--- a/engines/neverhood/menumodule.cpp
+++ b/engines/neverhood/menumodule.cpp
@@ -28,12 +28,13 @@
namespace Neverhood {
enum {
- MAIN_MENU = 0,
- CREDITS_SCENE = 1,
- MAKING_OF = 2,
- LOAD_GAME_MENU = 3,
- SAVE_GAME_MENU = 4,
- QUERY_OVR_MENU = 5
+ MAIN_MENU = 0,
+ CREDITS_SCENE = 1,
+ MAKING_OF = 2,
+ LOAD_GAME_MENU = 3,
+ SAVE_GAME_MENU = 4,
+ DELETE_GAME_MENU = 5,
+ QUERY_OVR_MENU = 6
};
enum {
@@ -90,6 +91,10 @@ void MenuModule::setSavegameInfo(const Common::String &description, uint index,
_savegameSlot = newSavegame ? -1 : (*_savegameList)[index].slotNum;
}
+void MenuModule::setDeletegameInfo(uint index) {
+ _savegameSlot = (*_savegameList)[index].slotNum;
+}
+
void MenuModule::createScene(int sceneNum, int which) {
_sceneNum = sceneNum;
switch (_sceneNum) {
@@ -108,6 +113,9 @@ void MenuModule::createScene(int sceneNum, int which) {
case SAVE_GAME_MENU:
createSaveGameMenu();
break;
+ case DELETE_GAME_MENU:
+ createDeleteGameMenu();
+ break;
case QUERY_OVR_MENU:
_childObject = new QueryOverwriteMenu(_vm, this, _savegameDescription);
break;
@@ -149,7 +157,7 @@ void MenuModule::updateScene() {
createScene(MAIN_MENU, -1);
break;
case kMainMenuDeleteGame:
- // TODO createDeleteGameMenu();
+ createScene(DELETE_GAME_MENU, -1);
break;
default:
createScene(MAIN_MENU, -1);
@@ -166,6 +174,9 @@ void MenuModule::updateScene() {
case SAVE_GAME_MENU:
handleSaveGameMenuAction(_moduleResult != 1, true);
break;
+ case DELETE_GAME_MENU:
+ handleDeleteGameMenuAction(_moduleResult != 1);
+ break;
case QUERY_OVR_MENU:
handleSaveGameMenuAction(_moduleResult != 1, false);
break;
@@ -193,6 +204,13 @@ void MenuModule::createSaveGameMenu() {
_childObject = new SaveGameMenu(_vm, this, _savegameList);
}
+void MenuModule::createDeleteGameMenu() {
+ _savegameSlot = -1;
+ _savegameList = new SavegameList();
+ loadSavegameList();
+ _childObject = new DeleteGameMenu(_vm, this, _savegameList);
+}
+
void MenuModule::handleLoadGameMenuAction(bool doLoad) {
createScene(MAIN_MENU, -1);
if (doLoad && _savegameSlot >= 0) {
@@ -224,6 +242,15 @@ void MenuModule::handleSaveGameMenuAction(bool doSave, bool doQuery) {
_savegameList = NULL;
}
+void MenuModule::handleDeleteGameMenuAction(bool doDelete) {
+ if (doDelete && _savegameSlot >= 0) {
+ _vm->removeGameState(_savegameSlot);
+ createScene(MAIN_MENU, -1);
+ }
+ delete _savegameList;
+ _savegameList = NULL;
+}
+
void MenuModule::loadSavegameList() {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
@@ -479,7 +506,7 @@ void Widget::refreshPosition() {
updateBounds();
}
-void Widget::addSprite() {
+void Widget::initialize() {
// Empty
}
@@ -523,7 +550,7 @@ TextLabelWidget::TextLabelWidget(NeverhoodEngine *vm, int16 x, int16 y, int16 it
}
-void TextLabelWidget::addSprite() {
+void TextLabelWidget::initialize() {
_parentScene->addSprite(this);
_parentScene->addCollisionSprite(this);
}
@@ -590,7 +617,7 @@ void TextEditWidget::onClick() {
Widget::onClick();
}
-void TextEditWidget::addSprite() {
+void TextEditWidget::initialize() {
SpriteResource cursorSpriteResource(_vm);
_spriteResource.load(_fileHash, true);
@@ -602,7 +629,7 @@ void TextEditWidget::addSprite() {
_textLabelWidget = new TextLabelWidget(_vm, _rect.x1, _rect.y1 + (_rect.y2 - _rect.y1 + 1 - _fontSurface->getCharHeight()) / 2,
0, _parentScene, _baseObjectPriority + 1, _baseSurfacePriority + 1,
(const byte*)_entryString.c_str(), _entryString.size(), _surface, _x, _y, _fontSurface);
- _textLabelWidget->addSprite();
+ _textLabelWidget->initialize();
cursorSpriteResource.load(_cursorFileHash, true);
_cursorSurface = new BaseSurface(_vm, 0, cursorSpriteResource.getDimensions().width, cursorSpriteResource.getDimensions().height);
_cursorSurface->drawSpriteResourceEx(cursorSpriteResource, false, false, cursorSpriteResource.getDimensions().width, cursorSpriteResource.getDimensions().height);
@@ -757,7 +784,7 @@ void SavegameListBox::onClick() {
}
}
-void SavegameListBox::addSprite() {
+void SavegameListBox::initialize() {
_spriteResource.load(_bgFileHash, true);
createSurface(_baseSurfacePriority, _spriteResource.getDimensions().width, _spriteResource.getDimensions().height);
refreshPosition();
@@ -778,7 +805,7 @@ void SavegameListBox::buildItems() {
int stringLen = (int)savegameList[i].description.size();
TextLabelWidget *label = new TextLabelWidget(_vm, itemX, itemY, i, _parentScene, _baseObjectPriority + 1,
_baseSurfacePriority + 1, string, MIN(stringLen, _maxStringLength), _surface, _x, _y, _fontSurface);
- label->addSprite();
+ label->initialize();
_textLabelItems.push_back(label);
}
}
@@ -869,12 +896,12 @@ SaveGameMenu::SaveGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameLi
_listBox = new SavegameListBox(_vm, 60, 142, 69/*ItemID*/, this,
_savegameList, _fontSurface, 0x1115A223, kListBoxRect);
- _listBox->addSprite();
+ _listBox->initialize();
_textEditWidget = new TextEditWidget(_vm, 50, 47, 70/*ItemID*/, this, 29,
_fontSurface, 0x3510A868, kTextEditRect);
_textEditWidget->setCursor(0x8290AC20, 2, 13);
- _textEditWidget->addSprite();
+ _textEditWidget->initialize();
setCurrWidget(_textEditWidget);
for (uint buttonIndex = 0; buttonIndex < 6; ++buttonIndex) {
@@ -984,13 +1011,12 @@ LoadGameMenu::LoadGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameLi
_listBox = new SavegameListBox(_vm, 263, 142, 69/*ItemID*/, this,
_savegameList, _fontSurface, 0x04040409, kListBoxRect);
- _listBox->addSprite();
+ _listBox->initialize();
_textEditWidget = new TextEditWidget(_vm, 263, 48, 70/*ItemID*/, this, 29,
_fontSurface, 0x10924C03, kTextEditRect);
- _textEditWidget->setCursor(0x18032303, 2, 13);
_textEditWidget->setReadOnly(true);
- _textEditWidget->addSprite();
+ _textEditWidget->initialize();
setCurrWidget(_textEditWidget);
for (uint buttonIndex = 0; buttonIndex < 6; ++buttonIndex) {
@@ -1056,6 +1082,111 @@ void LoadGameMenu::performLoadGame() {
leaveScene(0);
}
+DeleteGameMenu::DeleteGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList)
+ : WidgetScene(vm, parentModule), _savegameList(savegameList) {
+
+ static const uint32 kDeleteGameMenuButtonFileHashes[] = {
+ 0x8198E268,
+ 0xDD0C4620,
+ 0x81296520,
+ 0x8D284211,
+ 0x8C004621,
+ 0x07294020
+ };
+
+ static const NRect kDeleteGameMenuButtonCollisionBounds[] = {
+ NRect(518, 46, 595, 91),
+ NRect(524, 322, 599, 369),
+ NRect(395, 40, 462, 127),
+ NRect(405, 126, 460, 185),
+ NRect(397, 205, 456, 273),
+ NRect(395, 278, 452, 372)
+ };
+
+ static const NRect kListBoxRect(0, 0, 320, 271);
+ static const NRect kTextEditRect(0, 0, 320, 17);
+
+ _fontSurface = new FontSurface(_vm, calcHash("bgDeleteTinyAlphabet"), 32, 7, 32, 11, 17);
+
+ setBackground(0x4080E01C);
+ setPalette(0x4080E01C);
+ insertScreenMouse(0x0E018400);
+ insertStaticSprite(0x80083C01, 200);
+ insertStaticSprite(0x84181E81, 200);
+
+ _listBox = new SavegameListBox(_vm, 61, 64, 69/*ItemID*/, this,
+ _savegameList, _fontSurface, calcHash("mxDeleteListBox"), kListBoxRect);
+ _listBox->initialize();
+
+ _textEditWidget = new TextEditWidget(_vm, 49, 414, 70/*ItemID*/, this, 29,
+ _fontSurface, 0x250A3060, kTextEditRect);
+ _textEditWidget->setReadOnly(true);
+ _textEditWidget->initialize();
+ setCurrWidget(_textEditWidget);
+
+ for (uint buttonIndex = 0; buttonIndex < 6; ++buttonIndex) {
+ Sprite *menuButton = insertSprite<MenuButton>(this, buttonIndex,
+ kDeleteGameMenuButtonFileHashes[buttonIndex], kDeleteGameMenuButtonCollisionBounds[buttonIndex]);
+ addCollisionSprite(menuButton);
+ }
+
+ SetUpdateHandler(&Scene::update);
+ SetMessageHandler(&DeleteGameMenu::handleMessage);
+}
+
+DeleteGameMenu::~DeleteGameMenu() {
+ delete _fontSurface;
+}
+
+void DeleteGameMenu::handleEvent(int16 itemID, int eventType) {
+ if (itemID == 69 && eventType == 5) {
+ uint currIndex = _listBox->getCurrIndex();
+ _textEditWidget->setString((*_savegameList)[currIndex].description);
+ setCurrWidget(_textEditWidget);
+ }
+}
+
+uint32 DeleteGameMenu::handleMessage(int messageNum, const MessageParam &param, Entity *sender) {
+ Scene::handleMessage(messageNum, param, sender);
+ switch (messageNum) {
+ case 0x000B:
+ if (param.asInteger() == Common::KEYCODE_RETURN)
+ performDeleteGame();
+ else if (param.asInteger() == Common::KEYCODE_ESCAPE)
+ leaveScene(1);
+ break;
+ case 0x2000:
+ // Handle menu button click
+ switch (param.asInteger()) {
+ case 0:
+ performDeleteGame();
+ break;
+ case 1:
+ leaveScene(1);
+ break;
+ case 2:
+ _listBox->pageUp();
+ break;
+ case 3:
+ _listBox->scrollUp();
+ break;
+ case 4:
+ _listBox->scrollDown();
+ break;
+ case 5:
+ _listBox->pageDown();
+ break;
+ }
+ break;
+ }
+ return 0;
+}
+
+void DeleteGameMenu::performDeleteGame() {
+ ((MenuModule*)_parentModule)->setDeletegameInfo(_listBox->getCurrIndex());
+ leaveScene(0);
+}
+
QueryOverwriteMenu::QueryOverwriteMenu(NeverhoodEngine *vm, Module *parentModule, const Common::String &description)
: Scene(vm, parentModule) {
diff --git a/engines/neverhood/menumodule.h b/engines/neverhood/menumodule.h
index 2f91bdb40e..39cd36a7a2 100644
--- a/engines/neverhood/menumodule.h
+++ b/engines/neverhood/menumodule.h
@@ -44,6 +44,7 @@ public:
virtual ~MenuModule();
void setLoadgameInfo(uint index);
void setSavegameInfo(const Common::String &description, uint index, bool newSavegame);
+ void setDeletegameInfo(uint index);
protected:
int _sceneNum;
byte *_savedPaletteData;
@@ -55,8 +56,10 @@ protected:
uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
void createLoadGameMenu();
void createSaveGameMenu();
+ void createDeleteGameMenu();
void handleLoadGameMenuAction(bool doLoad);
void handleSaveGameMenuAction(bool doSave, bool doQuery);
+ void handleDeleteGameMenuAction(bool doDelete);
void loadSavegameList();
};
@@ -114,7 +117,7 @@ public:
virtual void onClick();
virtual void setPosition(int16 x, int16 y);
virtual void refreshPosition();
- virtual void addSprite();
+ virtual void initialize();
virtual int16 getWidth();
virtual int16 getHeight();
virtual void enterWidget();
@@ -133,7 +136,7 @@ public:
TextLabelWidget(NeverhoodEngine *vm, int16 x, int16 y, int16 itemID, WidgetScene *parentScene,
int baseObjectPriority, int baseSurfacePriority,
const byte *string, int stringLen, BaseSurface *drawSurface, int16 tx, int16 ty, FontSurface *fontSurface);
- virtual void addSprite();
+ virtual void initialize();
virtual int16 getWidth();
virtual int16 getHeight();
void drawString(int maxStringLength);
@@ -154,7 +157,7 @@ public:
int maxStringLength, FontSurface *fontSurface, uint32 fileHash, const NRect &rect);
~TextEditWidget();
virtual void onClick();
- virtual void addSprite();
+ virtual void initialize();
virtual void enterWidget();
virtual void exitWidget();
void setCursor(uint32 cursorFileHash, int16 cursorWidth, int16 cursorHeight);
@@ -191,7 +194,7 @@ public:
SavegameListBox(NeverhoodEngine *vm, int16 x, int16 y, int16 itemID, WidgetScene *parentScene,
SavegameList *savegameList, FontSurface *fontSurface, uint32 bgFileHash, const NRect &rect);
virtual void onClick();
- virtual void addSprite();
+ virtual void initialize();
void buildItems();
void drawItems();
void refresh();
@@ -244,6 +247,21 @@ protected:
void performLoadGame();
};
+class DeleteGameMenu : public WidgetScene {
+public:
+ DeleteGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList);
+ ~DeleteGameMenu();
+ virtual void handleEvent(int16 itemID, int eventType);
+protected:
+ SavegameList *_savegameList;
+ FontSurface *_fontSurface;
+ SavegameListBox *_listBox;
+ TextEditWidget *_textEditWidget;
+ Common::String _savegameDescription;
+ uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
+ void performDeleteGame();
+};
+
class QueryOverwriteMenu : public Scene {
public:
QueryOverwriteMenu(NeverhoodEngine *vm, Module *parentModule, const Common::String &description);
diff --git a/engines/neverhood/neverhood.h b/engines/neverhood/neverhood.h
index 14c283bc12..577fbd7a66 100644
--- a/engines/neverhood/neverhood.h
+++ b/engines/neverhood/neverhood.h
@@ -119,6 +119,7 @@ public:
Common::Error loadGameState(int slot);
Common::Error saveGameState(int slot, const Common::String &description);
+ Common::Error removeGameState(int slot);
void savegame(const char *filename, const char *description);
void loadgame(const char *filename);
const char *getSavegameFilename(int num);
diff --git a/engines/neverhood/saveload.cpp b/engines/neverhood/saveload.cpp
index 2f97adeeee..578d9858ff 100644
--- a/engines/neverhood/saveload.cpp
+++ b/engines/neverhood/saveload.cpp
@@ -143,6 +143,13 @@ Common::Error NeverhoodEngine::saveGameState(int slot, const Common::String &des
return Common::kNoError;
}
+Common::Error NeverhoodEngine::removeGameState(int slot) {
+ Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
+ Common::String filename = Neverhood::NeverhoodEngine::getSavegameFilename(_targetName, slot);
+ saveFileMan->removeSavefile(filename.c_str());
+ return Common::kNoError;
+}
+
const char *NeverhoodEngine::getSavegameFilename(int num) {
static Common::String filename;
filename = getSavegameFilename(_targetName, num);