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 --- README | 5 ++ engines/agi/agi.cpp | 3 ++ engines/agi/agi.h | 3 ++ engines/agi/detection.cpp | 16 ++++++ engines/agi/saveload.cpp | 134 +++++++++++++++++++++++++++++++++------------- po/POTFILES | 2 + 6 files changed, 126 insertions(+), 37 deletions(-) diff --git a/README b/README index a12ba073a2..91dca99a3f 100644 --- a/README +++ b/README @@ -2066,6 +2066,11 @@ The following keywords are recognized: boot_param number Pass this number to the boot script +Sierra games using the AGI engine add the following non-standard keywords: + + originalsaveload bool If true, the original save/load screens are + used instead of the enhanced ScummVM ones + Sierra games using the SCI engine add the following non-standard keywords: disable_dithering bool Remove dithering artifacts from EGA games diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp index 137d6073d1..3adcf96e01 100644 --- a/engines/agi/agi.cpp +++ b/engines/agi/agi.cpp @@ -498,6 +498,9 @@ static const GameSettings agiSettings[] = { }; AgiBase::AgiBase(OSystem *syst, const AGIGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) { + // Assign default values to the config manager, in case settings are missing + ConfMan.registerDefault("originalsaveload", "false"); + _noSaveLoadAllowed = false; _rnd = new Common::RandomSource("agi"); diff --git a/engines/agi/agi.h b/engines/agi/agi.h index cebee421ef..520b0aae59 100644 --- a/engines/agi/agi.h +++ b/engines/agi/agi.h @@ -890,6 +890,9 @@ public: int saveGameSimple(); int loadGameDialog(); int loadGameSimple(); + int doSave(int slot, const Common::String &desc); + int doLoad(int slot, bool showMessages); + int scummVMSaveLoadDialog(bool isSave); uint8 *_intobj; InputMode _oldMode; diff --git a/engines/agi/detection.cpp b/engines/agi/detection.cpp index 982dce8405..7c7394e87e 100644 --- a/engines/agi/detection.cpp +++ b/engines/agi/detection.cpp @@ -31,6 +31,8 @@ #include "common/md5.h" #include "common/savefile.h" #include "common/textconsole.h" +#include "common/translation.h" + #include "graphics/thumbnail.h" #include "graphics/surface.h" @@ -139,6 +141,13 @@ static const PlainGameDescriptor agiGames[] = { {0, 0} }; +static const ExtraGuiOption agiExtraGuiOption = { + _s("Use original save/load screens"), + _s("Use the original save/load screens, instead of the ScummVM ones"), + "originalsaveload", + false +}; + #include "agi/detection_tables.h" using namespace Agi; @@ -162,6 +171,7 @@ public: virtual bool hasFeature(MetaEngineFeature f) const; virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; + virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const; virtual SaveStateList listSaves(const char *target) const; virtual int getMaximumSaveSlot() const; virtual void removeSaveState(const char *target, int slot) const; @@ -219,6 +229,12 @@ bool AgiMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameD return res; } +const ExtraGuiOptions AgiMetaEngine::getExtraGuiOptions(const Common::String &target) const { + ExtraGuiOptions options; + options.push_back(agiExtraGuiOption); + return options; +} + SaveStateList AgiMetaEngine::listSaves(const char *target) const { const uint32 AGIflag = MKTAG('A','G','I',':'); Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); 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, diff --git a/po/POTFILES b/po/POTFILES index 7241b2bb09..8b74115939 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -23,6 +23,8 @@ common/util.cpp engines/advancedDetector.cpp engines/dialogs.cpp engines/engine.cpp +engines/agi/detection.cpp +engines/agi/saveload.cpp engines/dreamweb/detection.cpp engines/sci/detection.cpp engines/scumm/dialogs.cpp -- cgit v1.2.3