mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-04 16:26:53 +00:00
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.
This commit is contained in:
parent
9b05f4e103
commit
7c5cf1b400
@ -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;
|
||||
|
@ -70,11 +70,8 @@ bool Keyboard::getKey(Common::Event &event) {
|
||||
return false;
|
||||
case Common::KEYCODE_F5:
|
||||
if (_vm->canSaveGameStateCurrently()) {
|
||||
const EnginePlugin *plugin = NULL;
|
||||
EngineMan.findGame(_vm->_gameDescription->gameid, &plugin);
|
||||
|
||||
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save", true);
|
||||
int16 savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
int16 savegameId = dialog->runModalWithCurrentTarget();
|
||||
Common::String savegameDescription = dialog->getResultString();
|
||||
delete dialog;
|
||||
|
||||
@ -84,11 +81,8 @@ bool Keyboard::getKey(Common::Event &event) {
|
||||
return false;
|
||||
case Common::KEYCODE_F7:
|
||||
if (_vm->canLoadGameStateCurrently()) {
|
||||
const EnginePlugin *plugin = NULL;
|
||||
EngineMan.findGame(_vm->_gameDescription->gameid, &plugin);
|
||||
|
||||
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore", false);
|
||||
int16 savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
int16 savegameId = dialog->runModalWithCurrentTarget();
|
||||
delete dialog;
|
||||
|
||||
if (savegameId != -1)
|
||||
|
@ -207,15 +207,13 @@ int processMenu(menuStruct *pMenu) {
|
||||
}
|
||||
|
||||
static void handleSaveLoad(bool saveFlag) {
|
||||
const EnginePlugin *plugin = 0;
|
||||
EngineMan.findGame(_vm->getGameId(), &plugin);
|
||||
GUI::SaveLoadChooser *dialog;
|
||||
if (saveFlag)
|
||||
dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
|
||||
else
|
||||
dialog = new GUI::SaveLoadChooser(_("Load game:"), _("Load"), false);
|
||||
|
||||
int slot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
int slot = dialog->runModalWithCurrentTarget();
|
||||
|
||||
if (slot >= 0) {
|
||||
if (!saveFlag)
|
||||
|
@ -214,12 +214,7 @@ void MainMenuDialog::reflowLayout() {
|
||||
}
|
||||
|
||||
void MainMenuDialog::save() {
|
||||
const Common::String gameId = ConfMan.get("gameid");
|
||||
|
||||
const EnginePlugin *plugin = 0;
|
||||
EngineMan.findGame(gameId, &plugin);
|
||||
|
||||
int slot = _saveDialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
int slot = _saveDialog->runModalWithCurrentTarget();
|
||||
|
||||
if (slot >= 0) {
|
||||
Common::String result(_saveDialog->getResultString());
|
||||
@ -250,12 +245,7 @@ void MainMenuDialog::save() {
|
||||
}
|
||||
|
||||
void MainMenuDialog::load() {
|
||||
const Common::String gameId = ConfMan.get("gameid");
|
||||
|
||||
const EnginePlugin *plugin = 0;
|
||||
EngineMan.findGame(gameId, &plugin);
|
||||
|
||||
int slot = _loadDialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
int slot = _loadDialog->runModalWithCurrentTarget();
|
||||
|
||||
_engine->setGameToLoadSlot(slot);
|
||||
|
||||
|
@ -158,11 +158,8 @@ void DreamWebEngine::doLoad(int savegameId) {
|
||||
if (savegameId == -1) {
|
||||
// Open dialog to get savegameId
|
||||
|
||||
const EnginePlugin *plugin = NULL;
|
||||
Common::String gameId = ConfMan.get("gameid");
|
||||
EngineMan.findGame(gameId, &plugin);
|
||||
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
|
||||
savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
savegameId = dialog->runModalWithCurrentTarget();
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
@ -244,11 +241,8 @@ void DreamWebEngine::saveGame() {
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
const EnginePlugin *plugin = NULL;
|
||||
Common::String gameId = ConfMan.get("gameid");
|
||||
EngineMan.findGame(gameId, &plugin);
|
||||
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
|
||||
int savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
int savegameId = dialog->runModalWithCurrentTarget();
|
||||
Common::String game_description = dialog->getResultString();
|
||||
if (game_description.empty())
|
||||
game_description = "Untitled";
|
||||
|
@ -330,14 +330,12 @@ sound_pt FileManager::getSound(const int16 sound, uint16 *size) {
|
||||
bool FileManager::saveGame(const int16 slot, const Common::String &descrip) {
|
||||
debugC(1, kDebugFile, "saveGame(%d, %s)", slot, descrip.c_str());
|
||||
|
||||
const EnginePlugin *plugin = NULL;
|
||||
int16 savegameId;
|
||||
Common::String savegameDescription;
|
||||
EngineMan.findGame(_vm->getGameId(), &plugin);
|
||||
|
||||
if (slot == -1) {
|
||||
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save", true);
|
||||
savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
savegameId = dialog->runModalWithCurrentTarget();
|
||||
savegameDescription = dialog->getResultString();
|
||||
delete dialog;
|
||||
} else {
|
||||
@ -435,13 +433,11 @@ bool FileManager::saveGame(const int16 slot, const Common::String &descrip) {
|
||||
bool FileManager::restoreGame(const int16 slot) {
|
||||
debugC(1, kDebugFile, "restoreGame(%d)", slot);
|
||||
|
||||
const EnginePlugin *plugin = NULL;
|
||||
int16 savegameId;
|
||||
EngineMan.findGame(_vm->getGameId(), &plugin);
|
||||
|
||||
if (slot == -1) {
|
||||
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore", false);
|
||||
savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
savegameId = dialog->runModalWithCurrentTarget();
|
||||
delete dialog;
|
||||
} else {
|
||||
savegameId = slot;
|
||||
|
@ -715,12 +715,7 @@ void MohawkEngine_Riven::delayAndUpdate(uint32 ms) {
|
||||
void MohawkEngine_Riven::runLoadDialog() {
|
||||
GUI::SaveLoadChooser slc(_("Load game:"), _("Load"), false);
|
||||
|
||||
Common::String gameId = ConfMan.get("gameid");
|
||||
|
||||
const EnginePlugin *plugin = 0;
|
||||
EngineMan.findGame(gameId, &plugin);
|
||||
|
||||
int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
int slot = slc.runModalWithCurrentTarget();
|
||||
if (slot >= 0)
|
||||
loadGameState(slot);
|
||||
}
|
||||
|
@ -184,12 +184,7 @@ int SaveLoad::selectSaveFile(Common::String &selectedName, bool saveMode, const
|
||||
|
||||
selectedName.clear();
|
||||
|
||||
Common::String gameId = ConfMan.get("gameid");
|
||||
|
||||
const EnginePlugin *plugin = 0;
|
||||
EngineMan.findGame(gameId, &plugin);
|
||||
|
||||
int idx = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
int idx = slc.runModalWithCurrentTarget();
|
||||
if (idx >= 0) {
|
||||
selectedName = slc.getResultString();
|
||||
}
|
||||
|
@ -562,10 +562,8 @@ reg_t kSaveGame(EngineState *s, int argc, reg_t *argv) {
|
||||
|
||||
// we are supposed to show a dialog for the user and let him choose where to save
|
||||
g_sci->_soundCmd->pauseAll(true); // pause music
|
||||
const EnginePlugin *plugin = NULL;
|
||||
EngineMan.findGame(g_sci->getGameIdStr(), &plugin);
|
||||
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
|
||||
savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
savegameId = dialog->runModalWithCurrentTarget();
|
||||
game_description = dialog->getResultString();
|
||||
if (game_description.empty()) {
|
||||
// create our own description for the saved game, the user didnt enter it
|
||||
@ -668,10 +666,8 @@ reg_t kRestoreGame(EngineState *s, int argc, reg_t *argv) {
|
||||
if (savegameId == -1) {
|
||||
// we are supposed to show a dialog for the user and let him choose a saved game
|
||||
g_sci->_soundCmd->pauseAll(true); // pause music
|
||||
const EnginePlugin *plugin = NULL;
|
||||
EngineMan.findGame(g_sci->getGameIdStr(), &plugin);
|
||||
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
|
||||
savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
savegameId = dialog->runModalWithCurrentTarget();
|
||||
delete dialog;
|
||||
if (savegameId < 0) {
|
||||
g_sci->_soundCmd->pauseAll(false); // unpause music
|
||||
|
@ -2955,14 +2955,12 @@ Common::String ToonEngine::getSavegameName(int nr) {
|
||||
}
|
||||
|
||||
bool ToonEngine::saveGame(int32 slot, const Common::String &saveGameDesc) {
|
||||
const EnginePlugin *plugin = NULL;
|
||||
int16 savegameId;
|
||||
Common::String savegameDescription;
|
||||
EngineMan.findGame(_gameDescription->gameid, &plugin);
|
||||
|
||||
if (slot == -1) {
|
||||
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save", true);
|
||||
savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
savegameId = dialog->runModalWithCurrentTarget();
|
||||
savegameDescription = dialog->getResultString();
|
||||
delete dialog;
|
||||
} else {
|
||||
@ -3051,13 +3049,11 @@ bool ToonEngine::saveGame(int32 slot, const Common::String &saveGameDesc) {
|
||||
}
|
||||
|
||||
bool ToonEngine::loadGame(int32 slot) {
|
||||
const EnginePlugin *plugin = NULL;
|
||||
int16 savegameId;
|
||||
EngineMan.findGame(_gameDescription->gameid, &plugin);
|
||||
|
||||
if (slot == -1) {
|
||||
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore", false);
|
||||
savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
savegameId = dialog->runModalWithCurrentTarget();
|
||||
delete dialog;
|
||||
} else {
|
||||
savegameId = slot;
|
||||
|
@ -569,15 +569,13 @@ void Game::quitGame() {
|
||||
}
|
||||
|
||||
void Game::handleSaveLoad(bool saveFlag, int &saveSlot, Common::String &saveName) {
|
||||
const EnginePlugin *plugin = 0;
|
||||
EngineMan.findGame(g_vm->getGameId(), &plugin);
|
||||
GUI::SaveLoadChooser *dialog;
|
||||
if (saveFlag)
|
||||
dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), saveFlag);
|
||||
else
|
||||
dialog = new GUI::SaveLoadChooser(_("Load game:"), _("Load"), saveFlag);
|
||||
|
||||
saveSlot = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
saveSlot = dialog->runModalWithCurrentTarget();
|
||||
saveName = dialog->getResultString();
|
||||
|
||||
delete dialog;
|
||||
|
@ -76,6 +76,15 @@ SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel,
|
||||
SaveLoadChooser::~SaveLoadChooser() {
|
||||
}
|
||||
|
||||
int SaveLoadChooser::runModalWithCurrentTarget() {
|
||||
const Common::String gameId = ConfMan.get("gameid");
|
||||
|
||||
const EnginePlugin *plugin = 0;
|
||||
EngineMan.findGame(gameId, &plugin);
|
||||
|
||||
return runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
||||
}
|
||||
|
||||
int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) {
|
||||
if (_gfxWidget)
|
||||
_gfxWidget->setGfx(0);
|
||||
|
@ -67,6 +67,13 @@ public:
|
||||
|
||||
virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
|
||||
void setList(const StringArray& list);
|
||||
/**
|
||||
* Runs the save/load chooser with the currently active config manager
|
||||
* domain as target.
|
||||
*
|
||||
* @return The selcted save slot. -1 in case none is selected.
|
||||
*/
|
||||
int runModalWithCurrentTarget();
|
||||
int runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target);
|
||||
void open();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user