MACVENTURE: Change GUI to accept ScummVM dialogs

This commit is contained in:
Borja Lorente 2016-08-02 13:01:35 +02:00
parent b7b4862e4c
commit 9ab6ce04a1
7 changed files with 60 additions and 14 deletions

View File

@ -32,9 +32,7 @@ namespace MacVenture {
const char *MacVentureEngine::getGameFileName() const {
return _gameDescription->filesDescriptions[0].fileName;
}
}
namespace MacVenture {
} // End of namespace MacVenture
#include "macventure/detection_tables.h"
@ -45,6 +43,8 @@ static const PlainGameDescriptor macventureGames[] = {
{ 0, 0 }
};
namespace MacVenture {
SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot);
class MacVentureMetaEngine : public AdvancedMetaEngine {
@ -73,6 +73,12 @@ bool MacVentureMetaEngine::hasFeature(MetaEngineFeature f) const {
(f == kSupportsLoadingDuringStartup);
}
bool MacVentureEngine::hasFeature(EngineFeature f) const {
return
(f == kSupportsLoadingDuringRuntime) ||
(f == kSupportsSavingDuringRuntime);
}
SaveStateList MacVentureMetaEngine::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames;
@ -116,14 +122,11 @@ int MacVentureMetaEngine::getMaximumSaveSlot() const { return 999; }
bool MacVentureMetaEngine::createInstance(OSystem * syst, Engine ** engine, const ADGameDescription *game) const {
if (game) {
*engine = new MacVentureEngine(syst, game);
*engine = new MacVenture::MacVentureEngine(syst, game);
}
return game != 0;
}
} // End of namespace MacVenture
#if PLUGIN_ENABLED_DYNAMIC(MACVENTURE)

View File

@ -39,7 +39,7 @@ extern PrebuiltDialog prebuiltDialogs[];
class Dialog {
public:
Dialog(Gui *gui, Common::Point pos, uint width, uint height);
Dialog(Gui *gui, PrebuiltDialogs prebuilt);
Dialog(Gui *gui, PrebuiltDialogs prebuilt);
~Dialog();

View File

@ -1081,15 +1081,15 @@ void Gui::handleMenuAction(MenuAction action) {
break;
case MacVenture::kMenuActionOpen:
debug("MacVenture Menu Action: Open");
loadGame(0);
_engine->scummVMSaveLoadDialog(false);
break;
case MacVenture::kMenuActionSave:
debug("MacVenture Menu Action: Save");
saveInto(0);
_engine->scummVMSaveLoadDialog(true);
break;
case MacVenture::kMenuActionSaveAs:
debug("MacVenture Menu Action: Save As");
showPrebuiltDialog(kSaveAsDialog);
_engine->scummVMSaveLoadDialog(true);
break;
case MacVenture::kMenuActionQuit:
debug("MacVenture Menu Action: Quit");

View File

@ -156,6 +156,8 @@ public:
void setTextInput(Common::String str);
void closeDialog();
// TODO: Currently unused, we are using ScummVM dialogs instead.
void loadGame(int slot);
void saveInto(int slot);

View File

@ -181,7 +181,11 @@ public:
MacVentureEngine(OSystem *syst, const ADGameDescription *gameDesc);
~MacVentureEngine();
virtual bool hasFeature(EngineFeature f) const;
virtual Common::Error run();
bool scummVMSaveLoadDialog(bool isSave);
virtual Common::Error loadGameState(int slot);
virtual Common::Error saveGameState(int slot, const Common::String &desc);

View File

@ -35,7 +35,7 @@ enum DialogAction {
};
enum PrebuiltDialogs {
kSaveAsDialog = 0,
kSaveAsDialog = 0, //TODO: Currently unused, we are using ScummVM dialogs instead.
kSpeakDialog = 1,
kPrebuiltDialogCount
};

View File

@ -25,6 +25,7 @@
#include "common/error.h"
#include "common/savefile.h"
#include "engines/savestate.h"
#include "gui/saveload.h"
namespace MacVenture {
@ -71,19 +72,55 @@ void writeMetaData(Common::OutSaveFile *file, Common::String desc) {
}
Common::Error MacVentureEngine::loadGameState(int slot) {
Common::InSaveFile *file = getSaveFileManager()->openForLoading("shadowgate.001");
Common::String saveFileName = Common::String::format("%s.%03d", _targetName.c_str(), slot);
Common::InSaveFile *file;
if(!(file = getSaveFileManager()->openForLoading(saveFileName))) {
error("missing savegame file %s", saveFileName.c_str());
}
_world->loadGameFrom(file);
reset();
return Common::kNoError;
}
Common::Error MacVentureEngine::saveGameState(int slot, const Common::String &desc) {
Common::String saveFileName = Common::String::format("%s.%03d", _targetName.c_str(), slot);
Common::SaveFileManager *manager = getSaveFileManager();
// HACK Get a real name!
Common::OutSaveFile *file = manager->openForSaving(desc);
Common::OutSaveFile *file = manager->openForSaving(saveFileName);
_world->saveGameInto(file);
writeMetaData(file, desc);
delete file;
}
bool MacVentureEngine::scummVMSaveLoadDialog(bool isSave) {
if (!isSave) {
// do loading
GUI::SaveLoadChooser dialog = GUI::SaveLoadChooser(Common::String("Load game:"), Common::String("Load"), false);
int slot = dialog.runModalWithCurrentTarget();
if (slot < 0)
return true;
return loadGameState(slot).getCode() == Common::kNoError;
}
// do saving
GUI::SaveLoadChooser dialog = GUI::SaveLoadChooser(Common::String("Save game:"), Common::String("Save"), true);
int slot = dialog.runModalWithCurrentTarget();
Common::String 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() > (1 << MACVENTURE_DESC_LENGTH * 4) - 1)
desc = Common::String(desc.c_str(), (1 << MACVENTURE_DESC_LENGTH * 4) - 1);
if (slot < 0)
return true;
return saveGameState(slot, desc).getCode() == Common::kNoError;
}
} // End of namespace MacVenture