diff options
-rw-r--r-- | engines/zvision/core/save_manager.cpp | 40 | ||||
-rw-r--r-- | engines/zvision/core/save_manager.h | 1 | ||||
-rw-r--r-- | engines/zvision/detection.cpp | 61 | ||||
-rw-r--r-- | engines/zvision/scripting/script_manager.cpp | 23 | ||||
-rw-r--r-- | engines/zvision/video/video.cpp | 2 | ||||
-rw-r--r-- | engines/zvision/zvision.cpp | 9 | ||||
-rw-r--r-- | engines/zvision/zvision.h | 8 |
7 files changed, 121 insertions, 23 deletions
diff --git a/engines/zvision/core/save_manager.cpp b/engines/zvision/core/save_manager.cpp index 11d3dd391a..20bd39fde5 100644 --- a/engines/zvision/core/save_manager.cpp +++ b/engines/zvision/core/save_manager.cpp @@ -23,22 +23,60 @@ #include "common/scummsys.h" #include "zvision/core/save_manager.h" - #include "zvision/zvision.h" #include "zvision/scripting/script_manager.h" #include "zvision/graphics/render_manager.h" #include "common/system.h" +#include "common/translation.h" #include "graphics/surface.h" #include "graphics/thumbnail.h" #include "gui/message.h" +#include "gui/saveload.h" namespace ZVision { const uint32 SaveManager::SAVEGAME_ID = MKTAG('Z', 'E', 'N', 'G'); +bool SaveManager::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 false; + + if (isSave) { + saveGame(slot, desc); + return true; + } else { + Common::ErrorCode result = loadGame(slot).getCode(); + return (result == Common::kNoError); + } +} + void SaveManager::saveGame(uint slot, const Common::String &saveName) { // The games only support 20 slots //assert(slot <= 1 && slot <= 20); diff --git a/engines/zvision/core/save_manager.h b/engines/zvision/core/save_manager.h index 5cd61c7aa9..75841331e7 100644 --- a/engines/zvision/core/save_manager.h +++ b/engines/zvision/core/save_manager.h @@ -96,6 +96,7 @@ public: void prepareSaveBuffer(); void flushSaveBuffer(); + bool scummVMSaveLoadDialog(bool isSave); private: void writeSaveGameHeader(Common::OutSaveFile *file, const Common::String &saveName); }; diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp index 4d210abe86..a60ef6040d 100644 --- a/engines/zvision/detection.cpp +++ b/engines/zvision/detection.cpp @@ -26,6 +26,8 @@ #include "zvision/zvision.h" #include "zvision/detection.h" +#include "zvision/core/save_manager.h" +#include "zvision/scripting/script_manager.h" #include "common/translation.h" #include "common/savefile.h" @@ -178,24 +180,40 @@ public: }; bool ZVisionMetaEngine::hasFeature(MetaEngineFeature f) const { - return false; - /* + return (f == kSupportsListSaves) || (f == kSupportsLoadingDuringStartup) || - (f == kSupportsDeleteSave) || - (f == kSavesSupportMetaInfo) || - (f == kSavesSupportThumbnail) || - (f == kSavesSupportCreationDate) || - (f == kSavesSupportPlayTime); - */ + (f == kSupportsDeleteSave); + //(f == kSavesSupportMetaInfo) || + //(f == kSavesSupportThumbnail) || + //(f == kSavesSupportCreationDate) || + //(f == kSavesSupportPlayTime); } -/*bool ZVision::ZVision::hasFeature(EngineFeature f) const { +bool ZVision::ZVision::hasFeature(EngineFeature f) const { return (f == kSupportsRTL) || (f == kSupportsLoadingDuringRuntime) || (f == kSupportsSavingDuringRuntime); -}*/ +} + +Common::Error ZVision::ZVision::loadGameState(int slot) { + return _saveManager->loadGame(slot); +} + +Common::Error ZVision::ZVision::saveGameState(int slot, const Common::String &desc) { + _saveManager->saveGame(slot, desc); + return Common::kNoError; +} + +bool ZVision::ZVision::canLoadGameStateCurrently() { + return !_videoIsPlaying; +} + +bool ZVision::ZVision::canSaveGameStateCurrently() { + Location currentLocation = _scriptManager->getCurrentLocation(); + return !_videoIsPlaying && currentLocation.world != 'g' && !(currentLocation.room == 'j' || currentLocation.room == 'a'); +} bool ZVisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { const ZVision::ZVisionGameDescription *gd = (const ZVision::ZVisionGameDescription *)desc; @@ -213,8 +231,8 @@ const ExtraGuiOptions ZVisionMetaEngine::getExtraGuiOptions(const Common::String } SaveStateList ZVisionMetaEngine::listSaves(const char *target) const { - //Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); - /*ZVision::ZVision::SaveHeader header; + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + ZVision::SaveGameHeader header; Common::String pattern = target; pattern += ".???"; @@ -223,20 +241,25 @@ SaveStateList ZVisionMetaEngine::listSaves(const char *target) const { Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)*/ SaveStateList saveList; - /* for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) { + // We only use readSaveGameHeader() here, which doesn't need an engine callback + ZVision::SaveManager *zvisionSaveMan = new ZVision::SaveManager(NULL); + + 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) { - if (ZVision::ZVision::readSaveHeader(in, false, header) == ZVision::ZVision::kRSHENoError) { - saveList.push_back(SaveStateDescriptor(slotNum, header.description)); + if (zvisionSaveMan->readSaveGameHeader(in, header)) { + saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); } delete in; } } - }*/ + } + + delete zvisionSaveMan; return saveList; } @@ -246,9 +269,8 @@ int ZVisionMetaEngine::getMaximumSaveSlot() const { } void ZVisionMetaEngine::removeSaveState(const char *target, int slot) const { - /* Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); - Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); + Common::String filename = Common::String::format("%s.%03u", target, slot); saveFileMan->removeSavefile(filename.c_str()); @@ -265,10 +287,9 @@ void ZVisionMetaEngine::removeSaveState(const char *target, int slot) const { // Rename every slot greater than the deleted slot, if (slotNum > slot) { saveFileMan->renameSavefile(file->c_str(), filename.c_str()); - filename = ZVision::ZVision::getSavegameFilename(target, ++slot); + filename = Common::String::format("%s.%03u", target, ++slot); } } - */ } SaveStateDescriptor ZVisionMetaEngine::querySaveMetaInfos(const char *target, int slot) const { diff --git a/engines/zvision/scripting/script_manager.cpp b/engines/zvision/scripting/script_manager.cpp index 7904817156..c532a2b15d 100644 --- a/engines/zvision/scripting/script_manager.cpp +++ b/engines/zvision/scripting/script_manager.cpp @@ -36,6 +36,7 @@ #include "common/hashmap.h" #include "common/debug.h" #include "common/stream.h" +#include "common/config-manager.h" namespace ZVision { @@ -521,6 +522,28 @@ void ScriptManager::ChangeLocationReal() { assert(_nextLocation.world != 0); debug(1, "Changing location to: %c %c %c %c %u", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view, _nextLocation.offset); + if (_nextLocation.world == 'g' && _nextLocation.room == 'j' && !ConfMan.getBool("originalsaveload")) { + if ((_nextLocation.node == 's' || _nextLocation.node == 'r') && _nextLocation.view == 'e') { + // Hook up the ScummVM save/restore dialog + bool isSave = (_nextLocation.node == 's'); + bool gameSavedOrLoaded = _engine->getSaveManager()->scummVMSaveLoadDialog(isSave); + if (!gameSavedOrLoaded || isSave) { + // Reload the current room + _nextLocation.world = _currentLocation.world; + _nextLocation.room = _currentLocation.room; + _nextLocation.node = _currentLocation.node; + _nextLocation.view = _currentLocation.view; + _nextLocation.offset = _currentLocation.offset; + _currentLocation.world = '0'; + _currentLocation.room = '0'; + _currentLocation.node = '0'; + _currentLocation.view = '0'; + _currentLocation.offset = 0; + } else + return; + } + } + _engine->setRenderDelay(2); if (getStateValue(StateKey_World) != 'g' || getStateValue(StateKey_Room) != 'j') { diff --git a/engines/zvision/video/video.cpp b/engines/zvision/video/video.cpp index 36b5f9b921..db6161bf0c 100644 --- a/engines/zvision/video/video.cpp +++ b/engines/zvision/video/video.cpp @@ -53,6 +53,7 @@ void ZVision::playVideo(Video::VideoDecoder &vid, const Common::Rect &destRect, _clock.stop(); vid.start(); + _videoIsPlaying = true; // Only continue while the video is still playing while (!shouldQuit() && !vid.endOfVideo() && vid.isPlaying()) { @@ -99,6 +100,7 @@ void ZVision::playVideo(Video::VideoDecoder &vid, const Common::Rect &destRect, _system->delayMillis(vid.getTimeToNextFrame() / 2); } + _videoIsPlaying = false; _clock.start(); if (scaled) { diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index af9d26a350..8a44ccebea 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -96,7 +96,8 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) _audioId(0), _rendDelay(2), _kbdVelocity(0), - _mouseVelocity(0) { + _mouseVelocity(0), + _videoIsPlaying(false) { debug(1, "ZVision::ZVision"); @@ -205,6 +206,10 @@ void ZVision::initialize() { Common::Error ZVision::run() { initialize(); + // Check if a saved game is to be loaded from the launcher + if (ConfMan.hasKey("save_slot")) + _saveManager->loadGame(ConfMan.getInt("save_slot")); + // Main loop while (!shouldQuit()) { _clock.update(); @@ -327,7 +332,7 @@ void ZVision::pauseEngineIntern(bool pause) { } Common::String ZVision::generateSaveFileName(uint slot) { - return Common::String::format("%s.%02u", _targetName.c_str(), slot); + return Common::String::format("%s.%03u", _targetName.c_str(), slot); } Common::String ZVision::generateAutoSaveFileName() { diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index ca6c8e10e4..5850bf66cd 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -124,6 +124,7 @@ private: int16 _mouseVelocity; int16 _kbdVelocity; bool _halveDelay; + bool _videoIsPlaying; uint8 _cheatBuff[KEYBUF_SIZE]; public: @@ -198,6 +199,13 @@ public: void checkBorders(); void showDebugMsg(const Common::String &msg, int16 delay = 3000); + + // Engine features + bool hasFeature(EngineFeature f) const; + bool canLoadGameStateCurrently(); + bool canSaveGameStateCurrently(); + Common::Error loadGameState(int slot); + Common::Error saveGameState(int slot, const Common::String &desc); private: void initialize(); void initFonts(); |