diff options
author | Willem Jan Palenstijn | 2013-04-18 23:37:54 +0200 |
---|---|---|
committer | Willem Jan Palenstijn | 2013-05-08 20:46:44 +0200 |
commit | 02c5cc75a7cb8885d2a0fa141fbc0e763c5b31a0 (patch) | |
tree | 72b64a67ebeca41e9b83593da80850e848a99e2e /engines/agi/saveload.cpp | |
parent | 1539023834a2ad7cf8942711d60983891a10a82a (diff) | |
parent | 1e200620d673af4acdd2d128ed6e390df001aacf (diff) | |
download | scummvm-rg350-02c5cc75a7cb8885d2a0fa141fbc0e763c5b31a0.tar.gz scummvm-rg350-02c5cc75a7cb8885d2a0fa141fbc0e763c5b31a0.tar.bz2 scummvm-rg350-02c5cc75a7cb8885d2a0fa141fbc0e763c5b31a0.zip |
Merge branch 'master'
Conflicts:
configure
base/plugins.cpp
Diffstat (limited to 'engines/agi/saveload.cpp')
-rw-r--r-- | engines/agi/saveload.cpp | 137 |
1 files changed, 97 insertions, 40 deletions
diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index 0ef6230374..d451a799a0 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -29,6 +29,10 @@ #include "common/config-manager.h" #include "common/savefile.h" #include "common/textconsole.h" +#include "common/translation.h" + +#include "gui/saveload.h" + #include "graphics/thumbnail.h" #include "graphics/surface.h" @@ -38,7 +42,7 @@ #include "agi/keyboard.h" #include "agi/menu.h" -#define SAVEGAME_VERSION 5 +#define SAVEGAME_VERSION 6 // // Version 0 (Sarien): view table has 64 entries @@ -47,6 +51,7 @@ // Version 3 (ScummVM): added AGIPAL save/load support // Version 4 (ScummVM): added thumbnails and save creation date/time // Version 5 (ScummVM): Added game md5 +// Version 6 (ScummVM): Added game played time // namespace Agi { @@ -82,12 +87,14 @@ int AgiEngine::saveGame(const Common::String &fileName, const Common::String &de uint32 saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF); uint16 saveTime = ((curTime.tm_hour & 0xFF) << 8) | ((curTime.tm_min) & 0xFF); + uint32 playTime = g_engine->getTotalPlayTime() / 1000; out->writeUint32BE(saveDate); debugC(5, kDebugLevelMain | kDebugLevelSavegame, "Writing save date (%d)", saveDate); out->writeUint16BE(saveTime); debugC(5, kDebugLevelMain | kDebugLevelSavegame, "Writing save time (%d)", saveTime); - // TODO: played time + out->writeUint32BE(playTime); + debugC(5, kDebugLevelMain | kDebugLevelSavegame, "Writing play time (%d)", playTime); out->writeByte(_game.state); debugC(5, kDebugLevelMain | kDebugLevelSavegame, "Writing game state (%d)", _game.state); @@ -294,7 +301,10 @@ int AgiEngine::loadGame(const Common::String &fileName, bool checkId) { in->readUint32BE(); // save date in->readUint16BE(); // save time - // TODO: played time + if (saveVersion >= 6) { + uint32 playTime = in->readUint32BE(); + g_engine->setTotalPlayTime(playTime * 1000); + } } _game.state = (State)in->readByte(); @@ -784,7 +794,78 @@ int AgiEngine::selectSlot() { return rc; } +int AgiEngine::scummVMSaveLoadDialog(bool isSave) { + GUI::SaveLoadChooser *dialog; + Common::String desc; + int slot; + + if (isSave) { + dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true); + + slot = dialog->runModalWithCurrentTarget(); + desc = dialog->getResultString(); + + if (desc.empty()) { + // create our own description for the saved game, the user didnt enter it + desc = dialog->createDefaultSaveDescription(slot); + } + + if (desc.size() > 28) + desc = Common::String(desc.c_str(), 28); + } else { + dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false); + slot = dialog->runModalWithCurrentTarget(); + } + + delete dialog; + + if (slot < 0) + return true; + + if (isSave) + return doSave(slot, desc); + else + return doLoad(slot, false); +} + +int AgiEngine::doSave(int slot, const Common::String &desc) { + Common::String fileName = getSavegameFilename(slot); + debugC(8, kDebugLevelMain | kDebugLevelResources, "file is [%s]", fileName.c_str()); + + // Make sure all graphics was blitted to screen. This fixes bug + // #2960567: "AGI: Ego partly erased in Load/Save thumbnails" + _gfx->doUpdate(); + + return saveGame(fileName, desc); +} + +int AgiEngine::doLoad(int slot, bool showMessages) { + Common::String fileName = getSavegameFilename(slot); + debugC(8, kDebugLevelMain | kDebugLevelResources, "file is [%s]", fileName.c_str()); + + _sprites->eraseBoth(); + _sound->stopSound(); + closeWindow(); + + int result = loadGame(fileName); + + if (result == errOK) { + if (showMessages) + messageBox("Game restored."); + _game.exitAllLogics = 1; + _menu->enableAll(); + } else { + if (showMessages) + messageBox("Error restoring game."); + } + + return result; +} + int AgiEngine::saveGameDialog() { + if (!ConfMan.getBool("originalsaveload")) + return scummVMSaveLoadDialog(true); + char *desc; const char *buttons[] = { "Do as I say!", "I regret", NULL }; char dstr[200]; @@ -854,14 +935,7 @@ int AgiEngine::saveGameDialog() { return errOK; } - Common::String fileName = getSavegameFilename(_firstSlot + slot); - debugC(8, kDebugLevelMain | kDebugLevelResources, "file is [%s]", fileName.c_str()); - - // Make sure all graphics was blitted to screen. This fixes bug - // #2960567: "AGI: Ego partly erased in Load/Save thumbnails" - _gfx->doUpdate(); - - int result = saveGame(fileName, desc); + int result = doSave(_firstSlot + slot, desc); if (result == errOK) messageBox("Game saved."); @@ -872,6 +946,9 @@ int AgiEngine::saveGameDialog() { } int AgiEngine::saveGameSimple() { + if (!ConfMan.getBool("originalsaveload")) + return scummVMSaveLoadDialog(true); + Common::String fileName = getSavegameFilename(0); int result = saveGame(fileName, "Default savegame"); @@ -881,7 +958,10 @@ int AgiEngine::saveGameSimple() { } int AgiEngine::loadGameDialog() { - int rc, slot = 0; + if (!ConfMan.getBool("originalsaveload")) + return scummVMSaveLoadDialog(false); + + int slot = 0; int hm, vm, hp, vp; // box margins int w; @@ -907,37 +987,14 @@ int AgiEngine::loadGameDialog() { return errOK; } - Common::String fileName = getSavegameFilename(_firstSlot + slot); - - if ((rc = loadGame(fileName)) == errOK) { - messageBox("Game restored."); - _game.exitAllLogics = 1; - _menu->enableAll(); - } else { - messageBox("Error restoring game."); - } - - return rc; + return doLoad(_firstSlot + slot, true); } int AgiEngine::loadGameSimple() { - int rc = 0; - - Common::String fileName = getSavegameFilename(0); - - _sprites->eraseBoth(); - _sound->stopSound(); - closeWindow(); - - if ((rc = loadGame(fileName)) == errOK) { - messageBox("Game restored."); - _game.exitAllLogics = 1; - _menu->enableAll(); - } else { - messageBox("Error restoring game."); - } - - return rc; + if (!ConfMan.getBool("originalsaveload")) + return scummVMSaveLoadDialog(false); + else + return doLoad(0, true); } void AgiEngine::recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3, |