NEVERHOOD: Changed the save/load menu to allow gaps in saved games to simplify game deletion

This commit is contained in:
johndoe123 2013-01-29 14:59:09 +00:00 committed by Willem Jan Palenstijn
parent 2a571d71b0
commit a03879963f
4 changed files with 52 additions and 67 deletions

View File

@ -174,7 +174,6 @@ SaveStateList NeverhoodMetaEngine::listSaves(const char *target) const {
for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) {
// Obtain the last 3 digits of the filename, since they correspond to the save slot
int slotNum = atoi(file->c_str() + file->size() - 3);
if (slotNum >= 0 && slotNum <= 999) {
Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str());
if (in) {
@ -194,31 +193,9 @@ int NeverhoodMetaEngine::getMaximumSaveSlot() const {
}
void NeverhoodMetaEngine::removeSaveState(const char *target, int slot) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::String filename = Neverhood::NeverhoodEngine::getSavegameFilename(target, slot);
saveFileMan->removeSavefile(filename.c_str());
Common::StringArray filenames;
Common::String pattern = target;
pattern += ".???";
filenames = saveFileMan->listSavefiles(pattern.c_str());
Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)
for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
// Obtain the last 3 digits of the filename, since they correspond to the save slot
int slotNum = atoi(file->c_str() + file->size() - 3);
// Rename every slot greater than the deleted slot,
// Also do not rename quicksaves.
if (slotNum > slot && slotNum < 990) {
saveFileMan->renameSavefile(file->c_str(), filename.c_str());
filename = Neverhood::NeverhoodEngine::getSavegameFilename(target, ++slot);
}
}
}
SaveStateDescriptor NeverhoodMetaEngine::querySaveMetaInfos(const char *target, int slot) const {

View File

@ -345,7 +345,7 @@ uint32 GameModule::handleMessage(int messageNum, const MessageParam &param, Enti
}
void GameModule::startup() {
#if 1
#if 0
createModule(1500, 0); // Logos and intro video // Real game start
#else
// DEBUG>>>
@ -394,8 +394,8 @@ void GameModule::startup() {
#if 1
_vm->gameState().which = 0;
_vm->gameState().sceneNum = 8;
createModule(1800, -1);
_vm->gameState().sceneNum = 0;
createModule(1000, -1);
#endif
#if 0
_vm->gameState().sceneNum = 5;

View File

@ -81,15 +81,13 @@ MenuModule::~MenuModule() {
_vm->_screen->setPaletteData(_savedPaletteData);
}
void MenuModule::setLoadgameInfo(uint slot) {
_savegameSlot = slot;
debug("LOADGAME: slot = %d", slot);
void MenuModule::setLoadgameInfo(uint index) {
_savegameSlot = (*_savegameList)[index].slotNum;
}
void MenuModule::setSavegameInfo(const Common::String &description, uint slot, bool newSavegame) {
void MenuModule::setSavegameInfo(const Common::String &description, uint index, bool newSavegame) {
_savegameDescription = description;
_savegameSlot = newSavegame ? _savegameList->size() : slot;
debug("SAVEGAME: description = [%s]; slot = %d; new = %d", description.c_str(), slot, newSavegame);
_savegameSlot = newSavegame ? -1 : (*_savegameList)[index].slotNum;
}
void MenuModule::createScene(int sceneNum, int which) {
@ -183,14 +181,14 @@ uint32 MenuModule::handleMessage(int messageNum, const MessageParam &param, Enti
void MenuModule::createLoadGameMenu() {
_savegameSlot = -1;
_savegameList = new Common::StringArray();
_savegameList = new SavegameList();
loadSavegameList();
_childObject = new LoadGameMenu(_vm, this, _savegameList);
}
void MenuModule::createSaveGameMenu() {
_savegameSlot = -1;
_savegameList = new Common::StringArray();
_savegameList = new SavegameList();
loadSavegameList();
_childObject = new SaveGameMenu(_vm, this, _savegameList);
}
@ -206,9 +204,12 @@ void MenuModule::handleLoadGameMenuAction(bool doLoad) {
}
void MenuModule::handleSaveGameMenuAction(bool doSave, bool doQuery) {
if (doSave && doQuery && _savegameSlot >= 0 && _savegameSlot < (int)_savegameList->size()) {
if (doSave && doQuery && _savegameSlot >= 0) {
createScene(QUERY_OVR_MENU, -1);
} else if (doSave && _savegameSlot >= 0) {
} else if (doSave) {
// Get a new slot number if it's a new savegame
if (_savegameSlot < 0)
_savegameSlot = _savegameList->size() > 0 ? _savegameList->back().slotNum + 1 : 0;
// Restore the scene palette and background so that the correct thumbnail is saved
byte *menuPaletteData = _vm->_screen->getPaletteData();
_vm->_screen->setPaletteData(_savedPaletteData);
@ -240,8 +241,12 @@ void MenuModule::loadSavegameList() {
if (slotNum >= 0 && slotNum <= 999) {
Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str());
if (in) {
if (Neverhood::NeverhoodEngine::readSaveHeader(in, false, header) == Neverhood::NeverhoodEngine::kRSHENoError)
_savegameList->push_back(header.description);
if (Neverhood::NeverhoodEngine::readSaveHeader(in, false, header) == Neverhood::NeverhoodEngine::kRSHENoError) {
SavegameItem savegameItem;
savegameItem.slotNum = slotNum;
savegameItem.description = header.description;
_savegameList->push_back(savegameItem);
}
delete in;
}
}
@ -548,9 +553,8 @@ void TextLabelWidget::setString(const byte *string, int stringLen) {
}
TextEditWidget::TextEditWidget(NeverhoodEngine *vm, int16 x, int16 y, int16 itemID, WidgetScene *parentScene,
int baseObjectPriority, int baseSurfacePriority, int maxStringLength, FontSurface *fontSurface,
uint32 fileHash, const NRect &rect)
: Widget(vm, x, y, itemID, parentScene, baseObjectPriority, baseSurfacePriority),
int maxStringLength, FontSurface *fontSurface, uint32 fileHash, const NRect &rect)
: Widget(vm, x, y, itemID, parentScene, 1000, 1000),
_maxStringLength(maxStringLength), _fontSurface(fontSurface), _fileHash(fileHash), _rect(rect),
_cursorSurface(NULL), _cursorTicks(0), _cursorPos(0), _cursorFileHash(0), _cursorWidth(0), _cursorHeight(0),
_modified(false), _readOnly(false) {
@ -728,9 +732,8 @@ uint32 TextEditWidget::handleMessage(int messageNum, const MessageParam &param,
}
SavegameListBox::SavegameListBox(NeverhoodEngine *vm, int16 x, int16 y, int16 itemID, WidgetScene *parentScene,
int baseObjectPriority, int baseSurfacePriority,
Common::StringArray *savegameList, FontSurface *fontSurface, uint32 bgFileHash, const NRect &rect)
: Widget(vm, x, y, itemID, parentScene, baseObjectPriority, baseSurfacePriority),
SavegameList *savegameList, FontSurface *fontSurface, uint32 bgFileHash, const NRect &rect)
: Widget(vm, x, y, itemID, parentScene, 1000, 1000),
_savegameList(savegameList), _fontSurface(fontSurface), _bgFileHash(bgFileHash), _rect(rect),
_maxStringLength(0), _firstVisibleItem(0), _lastVisibleItem(0), _currIndex(0) {
@ -768,11 +771,11 @@ void SavegameListBox::addSprite() {
}
void SavegameListBox::buildItems() {
Common::StringArray &savegameList = *_savegameList;
SavegameList &savegameList = *_savegameList;
int16 itemX = _rect.x1, itemY = 0;
for (uint i = 0; i < savegameList.size(); ++i) {
const byte *string = (const byte*)savegameList[i].c_str();
int stringLen = (int)savegameList[i].size();
const byte *string = (const byte*)savegameList[i].description.c_str();
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();
@ -831,7 +834,7 @@ void SavegameListBox::pageDown() {
}
}
SaveGameMenu::SaveGameMenu(NeverhoodEngine *vm, Module *parentModule, Common::StringArray *savegameList)
SaveGameMenu::SaveGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList)
: WidgetScene(vm, parentModule), _savegameList(savegameList) {
static const uint32 kSaveGameMenuButtonFileHashes[] = {
@ -864,11 +867,11 @@ SaveGameMenu::SaveGameMenu(NeverhoodEngine *vm, Module *parentModule, Common::St
insertStaticSprite(0x1340A5C2, 200);
insertStaticSprite(0x1301A7EA, 200);
_listBox = new SavegameListBox(_vm, 60, 142, 69/*ItemID*/, this, 1000, 1000,
_listBox = new SavegameListBox(_vm, 60, 142, 69/*ItemID*/, this,
_savegameList, _fontSurface, 0x1115A223, kListBoxRect);
_listBox->addSprite();
_textEditWidget = new TextEditWidget(_vm, 50, 47, 70/*ItemID*/, this, 1000, 1000, 29,
_textEditWidget = new TextEditWidget(_vm, 50, 47, 70/*ItemID*/, this, 29,
_fontSurface, 0x3510A868, kTextEditRect);
_textEditWidget->setCursor(0x8290AC20, 2, 13);
_textEditWidget->addSprite();
@ -891,7 +894,7 @@ SaveGameMenu::~SaveGameMenu() {
void SaveGameMenu::handleEvent(int16 itemID, int eventType) {
if (itemID == 69 && eventType == 5) {
uint currIndex = _listBox->getCurrIndex();
_textEditWidget->setString((*_savegameList)[currIndex]);
_textEditWidget->setString((*_savegameList)[currIndex].description);
setCurrWidget(_textEditWidget);
}
}
@ -946,7 +949,7 @@ void SaveGameMenu::performSaveGame() {
leaveScene(0);
}
LoadGameMenu::LoadGameMenu(NeverhoodEngine *vm, Module *parentModule, Common::StringArray *savegameList)
LoadGameMenu::LoadGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList)
: WidgetScene(vm, parentModule), _savegameList(savegameList) {
static const uint32 kLoadGameMenuButtonFileHashes[] = {
@ -979,11 +982,11 @@ LoadGameMenu::LoadGameMenu(NeverhoodEngine *vm, Module *parentModule, Common::St
insertStaticSprite(0x0BC600A3, 200);
insertStaticSprite(0x0F960021, 200);
_listBox = new SavegameListBox(_vm, 263, 142, 69/*ItemID*/, this, 1000, 1000,
_listBox = new SavegameListBox(_vm, 263, 142, 69/*ItemID*/, this,
_savegameList, _fontSurface, 0x04040409, kListBoxRect);
_listBox->addSprite();
_textEditWidget = new TextEditWidget(_vm, 263, 48, 70/*ItemID*/, this, 1000, 1000, 29,
_textEditWidget = new TextEditWidget(_vm, 263, 48, 70/*ItemID*/, this, 29,
_fontSurface, 0x10924C03, kTextEditRect);
_textEditWidget->setCursor(0x18032303, 2, 13);
_textEditWidget->setReadOnly(true);
@ -1007,7 +1010,7 @@ LoadGameMenu::~LoadGameMenu() {
void LoadGameMenu::handleEvent(int16 itemID, int eventType) {
if (itemID == 69 && eventType == 5) {
uint currIndex = _listBox->getCurrIndex();
_textEditWidget->setString((*_savegameList)[currIndex]);
_textEditWidget->setString((*_savegameList)[currIndex].description);
setCurrWidget(_textEditWidget);
}
}

View File

@ -31,16 +31,23 @@
namespace Neverhood {
struct SavegameItem {
int slotNum;
Common::String description;
};
typedef Common::Array<SavegameItem> SavegameList;
class MenuModule : public Module {
public:
MenuModule(NeverhoodEngine *vm, Module *parentModule, int which);
virtual ~MenuModule();
void setLoadgameInfo(uint slot);
void setSavegameInfo(const Common::String &description, uint slot, bool newSavegame);
void setLoadgameInfo(uint index);
void setSavegameInfo(const Common::String &description, uint index, bool newSavegame);
protected:
int _sceneNum;
byte *_savedPaletteData;
Common::StringArray *_savegameList;
SavegameList *_savegameList;
Common::String _savegameDescription;
int _savegameSlot;
void createScene(int sceneNum, int which);
@ -144,8 +151,7 @@ protected:
class TextEditWidget : public Widget {
public:
TextEditWidget(NeverhoodEngine *vm, int16 x, int16 y, int16 itemID, WidgetScene *parentScene,
int baseObjectPriority, int baseSurfacePriority, int maxStringLength, FontSurface *fontSurface,
uint32 fileHash, const NRect &rect);
int maxStringLength, FontSurface *fontSurface, uint32 fileHash, const NRect &rect);
~TextEditWidget();
virtual void onClick();
virtual void addSprite();
@ -183,8 +189,7 @@ protected:
class SavegameListBox : public Widget {
public:
SavegameListBox(NeverhoodEngine *vm, int16 x, int16 y, int16 itemID, WidgetScene *parentScene,
int baseObjectPriority, int baseSurfacePriority,
Common::StringArray *savegameList, FontSurface *fontSurface, uint32 bgFileHash, const NRect &rect);
SavegameList *savegameList, FontSurface *fontSurface, uint32 bgFileHash, const NRect &rect);
virtual void onClick();
virtual void addSprite();
void buildItems();
@ -202,7 +207,7 @@ protected:
Common::Array<TextLabelWidget*> _textLabelItems;
int _firstVisibleItem;
int _lastVisibleItem;
Common::StringArray *_savegameList;
SavegameList *_savegameList;
FontSurface *_fontSurface;
uint _currIndex;
int _maxVisibleItemsCount;
@ -210,11 +215,11 @@ protected:
class SaveGameMenu : public WidgetScene {
public:
SaveGameMenu(NeverhoodEngine *vm, Module *parentModule, Common::StringArray *savegameList);
SaveGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList);
~SaveGameMenu();
virtual void handleEvent(int16 itemID, int eventType);
protected:
Common::StringArray *_savegameList;
SavegameList *_savegameList;
FontSurface *_fontSurface;
SavegameListBox *_listBox;
TextEditWidget *_textEditWidget;
@ -226,11 +231,11 @@ protected:
class LoadGameMenu : public WidgetScene {
public:
LoadGameMenu(NeverhoodEngine *vm, Module *parentModule, Common::StringArray *savegameList);
LoadGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList);
~LoadGameMenu();
virtual void handleEvent(int16 itemID, int eventType);
protected:
Common::StringArray *_savegameList;
SavegameList *_savegameList;
FontSurface *_fontSurface;
SavegameListBox *_listBox;
TextEditWidget *_textEditWidget;