From 85ca13db4b192b5993f1b291d90cce85ad94fb98 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Tue, 27 Mar 2012 00:21:16 +0300 Subject: AGI: Use the ScummVM dialogs for saving/loading An option has been added to use the original ones, if needed --- engines/agi/saveload.cpp | 134 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 97 insertions(+), 37 deletions(-) (limited to 'engines/agi/saveload.cpp') diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index 0ef6230374..04054daacd 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" @@ -784,7 +788,87 @@ int AgiEngine::selectSlot() { return rc; } +int AgiEngine::scummVMSaveLoadDialog(bool isSave) { + const EnginePlugin *plugin = NULL; + EngineMan.findGame(ConfMan.get("gameid"), &plugin); + GUI::SaveLoadChooser *dialog; + Common::String desc; + int slot; + + if (isSave) { + dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save")); + dialog->setSaveMode(true); + + slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + desc = dialog->getResultString(); + + if (desc.empty()) { + // create our own description for the saved game, the user didnt enter it +#if defined(USE_SAVEGAME_TIMESTAMP) + TimeDate curTime; + g_system->getTimeAndDate(curTime); + curTime.tm_year += 1900; // fixup year + curTime.tm_mon++; // fixup month + desc = Common::String::format("%04d.%02d.%02d / %02d:%02d:%02d", curTime.tm_year, curTime.tm_mon, curTime.tm_mday, curTime.tm_hour, curTime.tm_min, curTime.tm_sec); +#else + desc = Common::String::format("Save %d", slot + 1); +#endif + } + + if (desc.size() > 28) + desc = Common::String(desc.c_str(), 28); + } else { + dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore")); + dialog->setSaveMode(false); + slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + } + + delete dialog; + + 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 +938,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 +949,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 +961,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 +990,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, -- cgit v1.2.3 From 5e10737015faa15d225f70b364096982923eb415 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Tue, 27 Mar 2012 00:50:29 +0300 Subject: AGI: Add played time information to saved games --- engines/agi/saveload.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'engines/agi/saveload.cpp') diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index 04054daacd..8e524c8d9a 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -42,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 @@ -51,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 { @@ -86,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); @@ -298,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(); -- cgit v1.2.3 From d6bedc8a36d5a0785f27912cd99a3137a2a7062d Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 2 May 2012 23:51:02 +0300 Subject: AGI: Proper handling of the cancel button when saving/loading --- engines/agi/saveload.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/agi/saveload.cpp') diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index 8e524c8d9a..d58e55a6b9 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -831,6 +831,9 @@ int AgiEngine::scummVMSaveLoadDialog(bool isSave) { delete dialog; + if (slot < 0) + return true; + if (isSave) return doSave(slot, desc); else -- cgit v1.2.3 From 15046a7529e3c755de1f00b4a2666786eb2bd4f8 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 10 Jun 2012 04:14:17 +0200 Subject: GUI: Get rid of SaveLoadChooser::setSaveMode. We already pass the title and process button name to the constructor of SaveLoadChooser and then do not offer any way of changing it, thus changing the edit mode of the chooser is kind of pointless and was never actually used. Instead we pass the mode on SaveLoadChooser construction now. --- engines/agi/saveload.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'engines/agi/saveload.cpp') diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index d58e55a6b9..cb7792af8e 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -802,8 +802,7 @@ int AgiEngine::scummVMSaveLoadDialog(bool isSave) { int slot; if (isSave) { - dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save")); - dialog->setSaveMode(true); + dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true); slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); desc = dialog->getResultString(); @@ -824,8 +823,7 @@ int AgiEngine::scummVMSaveLoadDialog(bool isSave) { if (desc.size() > 28) desc = Common::String(desc.c_str(), 28); } else { - dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore")); - dialog->setSaveMode(false); + dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false); slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); } -- cgit v1.2.3 From 7c5cf1b400808865a5f601f70d624ad6704a0c8c Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 10 Jun 2012 04:49:42 +0200 Subject: GUI: Add helper to SaveLoadChooser, which uses the currently active target. This reduces the code duplication in all client code, which formerly duplicated the querying of the plugin, game id etc. and now simply calls the newly added method runModalWithCurrentTarget() on a SaveLoadChooser object. --- engines/agi/saveload.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'engines/agi/saveload.cpp') diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index cb7792af8e..25fa7829ef 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -795,8 +795,6 @@ int AgiEngine::selectSlot() { } int AgiEngine::scummVMSaveLoadDialog(bool isSave) { - const EnginePlugin *plugin = NULL; - EngineMan.findGame(ConfMan.get("gameid"), &plugin); GUI::SaveLoadChooser *dialog; Common::String desc; int slot; @@ -804,7 +802,7 @@ int AgiEngine::scummVMSaveLoadDialog(bool isSave) { if (isSave) { dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true); - slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + slot = dialog->runModalWithCurrentTarget(); desc = dialog->getResultString(); if (desc.empty()) { @@ -824,7 +822,7 @@ int AgiEngine::scummVMSaveLoadDialog(bool isSave) { desc = Common::String(desc.c_str(), 28); } else { dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false); - slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + slot = dialog->runModalWithCurrentTarget(); } delete dialog; -- cgit v1.2.3 From 49fafb48a7f089c97ed3baa9aefe65ec56dce682 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 10 Jun 2012 05:04:59 +0200 Subject: GUI: Refactor default savegame description creation. Formerly the GMM, AGI and SCI duplicated the logic for USE_SAVEGAME_TIMESTAMP. Now I added a method to SaveLoadChooser instead, which takes care of this. This might not be the best placement of such a functionality, thus I added a TODO which talks about moving it to a better place. --- engines/agi/saveload.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'engines/agi/saveload.cpp') diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index 25fa7829ef..3e63da756d 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -807,15 +807,7 @@ int AgiEngine::scummVMSaveLoadDialog(bool isSave) { if (desc.empty()) { // create our own description for the saved game, the user didnt enter it -#if defined(USE_SAVEGAME_TIMESTAMP) - TimeDate curTime; - g_system->getTimeAndDate(curTime); - curTime.tm_year += 1900; // fixup year - curTime.tm_mon++; // fixup month - desc = Common::String::format("%04d.%02d.%02d / %02d:%02d:%02d", curTime.tm_year, curTime.tm_mon, curTime.tm_mday, curTime.tm_hour, curTime.tm_min, curTime.tm_sec); -#else - desc = Common::String::format("Save %d", slot + 1); -#endif + desc = dialog->createDefaultSaveDescription(slot); } if (desc.size() > 28) -- cgit v1.2.3 From 89abab97e3124fa25eb4c7d3e8b38501747a8d17 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 26 Sep 2012 04:17:31 +0200 Subject: JANITORIAL: Remove trailing whitespaces. Powered by: git ls-files "*.cpp" "*.h" "*.m" "*.mm" | xargs sed -i -e 's/[ \t]*$//' --- engines/agi/saveload.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/agi/saveload.cpp') diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index 3e63da756d..d451a799a0 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -821,7 +821,7 @@ int AgiEngine::scummVMSaveLoadDialog(bool isSave) { if (slot < 0) return true; - + if (isSave) return doSave(slot, desc); else -- cgit v1.2.3