diff options
Diffstat (limited to 'gui')
-rw-r--r-- | gui/launcher.cpp | 221 | ||||
-rw-r--r-- | gui/launcher.h | 7 | ||||
-rw-r--r-- | gui/newgui.cpp | 6 | ||||
-rw-r--r-- | gui/theme-config.cpp | 33 | ||||
-rw-r--r-- | gui/themes/classic080.ini | 5 | ||||
-rw-r--r-- | gui/themes/modern.ini | 2 |
6 files changed, 267 insertions, 7 deletions
diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 7cfe3943a7..40e0c3685e 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -29,6 +29,7 @@ #include "common/events.h" #include "common/fs.h" #include "common/util.h" +#include "common/savefile.h" #include "common/system.h" #include "gui/about.h" @@ -61,7 +62,10 @@ enum { kAddGameCmd = 'ADDG', kEditGameCmd = 'EDTG', kRemoveGameCmd = 'REMG', + kLoadGameCmd = 'LOAD', kQuitCmd = 'QUIT', + kChooseCmd = 'CHOS', + kDelCmd = 'DEL', kCmdGlobalGraphicsOverride = 'OGFX', @@ -468,6 +472,140 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat } } +class SaveLoadChooser : public GUI::Dialog { + typedef Common::String String; + typedef Common::StringList StringList; +protected: + bool _delSave; + bool _delSupport; + GUI::ListWidget *_list; + GUI::ButtonWidget *_chooseButton; + GUI::ButtonWidget *_deleteButton; + GUI::GraphicsWidget *_gfxWidget; + GUI::ContainerWidget *_container; + + uint8 _fillR, _fillG, _fillB; + + void updateInfos(bool redraw); +public: + SaveLoadChooser(const String &title, const String &buttonLabel); + ~SaveLoadChooser(); + + virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); + const String &getResultString() const; + void setList(const StringList& list); + int runModal(bool delSupport); + + virtual void reflowLayout(); + + bool delSave() { return _delSave; }; +}; + +SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel) + : Dialog("scummsaveload"), _delSave(0), _delSupport(0), _list(0), _chooseButton(0), _deleteButton(0), _gfxWidget(0) { + + _drawingHints |= GUI::THEME_HINT_SPECIAL_COLOR; + + new StaticTextWidget(this, "scummsaveload_title", title); + + // Add choice list + _list = new GUI::ListWidget(this, "scummsaveload_list"); + _list->setNumberingMode(GUI::kListNumberingZero); + + _container = new GUI::ContainerWidget(this, 0, 0, 10, 10); + _container->setHints(GUI::THEME_HINT_USE_SHADOW); + + _gfxWidget = new GUI::GraphicsWidget(this, 0, 0, 10, 10); + + // Buttons + new GUI::ButtonWidget(this, "scummsaveload_cancel", "Cancel", kCloseCmd, 0); + _chooseButton = new GUI::ButtonWidget(this, "scummsaveload_choose", buttonLabel, kChooseCmd, 0); + _chooseButton->setEnabled(false); + + _deleteButton = new GUI::ButtonWidget(this, "scummsaveload_delete", "Delete", kDelCmd, 0); + _deleteButton->setEnabled(false); +} + +SaveLoadChooser::~SaveLoadChooser() { +} + +const Common::String &SaveLoadChooser::getResultString() const { + return _list->getSelectedString(); +} + +void SaveLoadChooser::setList(const StringList& list) { + _list->setList(list); +} + +int SaveLoadChooser::runModal(bool delSupport) { + if (_gfxWidget) + _gfxWidget->setGfx(0); + _delSave = false; + _delSupport = delSupport; + int ret = Dialog::runModal(); + return ret; +} + +void SaveLoadChooser::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { + int selItem = _list->getSelected(); + switch (cmd) { + case GUI::kListItemActivatedCmd: + case GUI::kListItemDoubleClickedCmd: + if (selItem >= 0) { + if (!getResultString().empty()) { + _list->endEditMode(); + setResult(selItem); + close(); + } + } + break; + case kChooseCmd: + _list->endEditMode(); + setResult(selItem); + close(); + break; + case GUI::kListSelectionChangedCmd: { + if (_gfxWidget) { + updateInfos(true); + } + + // Disable these buttons if nothing is selected, or if an empty + // list item is selected. + _chooseButton->setEnabled(selItem >= 0 && (!getResultString().empty())); + _chooseButton->draw(); + // Delete will always be disabled if the engine doesn't support it. + _deleteButton->setEnabled(_delSupport && (selItem >= 0) && (!getResultString().empty())); + _deleteButton->draw(); + } break; + case kDelCmd: + setResult(selItem); + _delSave = true; + + // Disable these buttons again after deleteing a selection + _chooseButton->setEnabled(false); + _deleteButton->setEnabled(false); + + close(); + break; + case kCloseCmd: + setResult(-1); + default: + Dialog::handleCommand(sender, cmd, data); + } +} + +void SaveLoadChooser::reflowLayout() { + _container->setFlags(GUI::WIDGET_INVISIBLE); + _gfxWidget->setFlags(GUI::WIDGET_INVISIBLE); + Dialog::reflowLayout(); +} + +void SaveLoadChooser::updateInfos(bool redraw) { + _gfxWidget->setGfx(-1, -1, _fillR, _fillG, _fillB); + if (redraw) + _gfxWidget->draw(); +} + #pragma mark - @@ -501,6 +639,8 @@ LauncherDialog::LauncherDialog() new ButtonWidget(this, "launcher_options_button", "Options", kOptionsCmd, 'O'); _startButton = new ButtonWidget(this, "launcher_start_button", "Start", kStartCmd, 'S'); + + new ButtonWidget(this, "launcher_loadGame_button", "Load", kLoadGameCmd, 'L'); // Above the lowest button rows: two more buttons (directly below the list box) _addButton = @@ -529,6 +669,9 @@ LauncherDialog::LauncherDialog() // Create file browser dialog _browser = new BrowserDialog("Select directory with game data", true); + + // Create Load dialog + _loadDialog = new SaveLoadChooser("Load game:", "Load"); } void LauncherDialog::selectGame(const String &name) { @@ -546,6 +689,7 @@ void LauncherDialog::selectGame(const String &name) { LauncherDialog::~LauncherDialog() { delete _browser; + delete _loadDialog; } void LauncherDialog::open() { @@ -795,6 +939,80 @@ void LauncherDialog::editGame(int item) { } } +void LauncherDialog::loadGame(int item) { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + String gameId = ConfMan.get("gameid", _domains[item]); + if (gameId.empty()) + gameId = _domains[item]; + + const EnginePlugin *plugin = 0; + GameDescriptor game = EngineMan.findGame(gameId, &plugin); + + String description = _domains[item]; + description.toLowercase(); + + int idx; + if (plugin) { + bool delSupport = (*plugin)->hasFeature(MetaEngine::kSupportsDeleteSave); + + if ((*plugin)->hasFeature(MetaEngine::kSupportsListSaves) && + (*plugin)->hasFeature(MetaEngine::kSupportsDirectLoad)) + { + do { + Common::StringList saveNames = generateSavegameList(item, plugin); + _loadDialog->setList(saveNames); + SaveStateList saveList = (*plugin)->listSaves(description.c_str()); + idx = _loadDialog->runModal(delSupport); + if (idx >= 0) { + // Delete the savegame + if (_loadDialog->delSave()) { + String filename = saveList[idx].filename(); + //printf("Deleting file: %s\n", filename.c_str()); + MessageDialog alert("Do you really want to delete this savegame?", + "Yes", "No"); + if (alert.runModal() == GUI::kMessageOK) { + saveFileMan->removeSavefile(filename.c_str()); + if ((saveList.size() - 1) == 0) + ConfMan.setInt("save_slot", -1); + } + } + // Load the savegame + else { + int slot = atoi(saveList[idx].save_slot().c_str()); + //const char *file = saveList[idx].filename().c_str(); + //printf("Loading slot: %d\n", slot); + //printf("Loading file: %s\n", file); + ConfMan.setActiveDomain(_domains[item]); + ConfMan.setInt("save_slot", slot); + close(); + } + } + } + while (_loadDialog->delSave()); + } else { + MessageDialog dialog + ("Sorry, this game does not yet support loading games from the launcher.", "OK"); + dialog.runModal(); + } + } else { + MessageDialog dialog("ScummVM could not find any engine capable of running the selected game!", "OK"); + dialog.runModal(); + } +} + +Common::StringList LauncherDialog::generateSavegameList(int item, const EnginePlugin *plugin) { + String description = _domains[item]; + description.toLowercase(); + + StringList saveNames; + SaveStateList saveList = (*plugin)->listSaves(description.c_str()); + + for (SaveStateList::const_iterator x = saveList.begin(); x != saveList.end(); ++x) + saveNames.push_back(x->description().c_str()); + + return saveNames; +} + void LauncherDialog::handleKeyDown(Common::KeyState state) { Dialog::handleKeyDown(state); updateButtons(); @@ -818,6 +1036,9 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat case kEditGameCmd: editGame(item); break; + case kLoadGameCmd: + loadGame(item); + break; case kOptionsCmd: { GlobalOptionsDialog options; options.runModal(); diff --git a/gui/launcher.h b/gui/launcher.h index a9d09bf109..a26651eef5 100644 --- a/gui/launcher.h +++ b/gui/launcher.h @@ -34,11 +34,10 @@ namespace GUI { class BrowserDialog; class ListWidget; class GraphicsWidget; - +class SaveLoadChooser; Common::String addGameToConf(const GameDescriptor &result); - class LauncherDialog : public Dialog { typedef Common::String String; typedef Common::StringList StringList; @@ -62,6 +61,7 @@ protected: #endif StringList _domains; BrowserDialog *_browser; + SaveLoadChooser *_loadDialog; virtual void reflowLayout(); @@ -73,6 +73,9 @@ protected: virtual void addGame(); void removeGame(int item); void editGame(int item); + void loadGame(int item); + + StringList generateSavegameList(int item, const EnginePlugin *plugin); void selectGame(const String &name); }; diff --git a/gui/newgui.cpp b/gui/newgui.cpp index 618c7bc873..b892fe076a 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -25,6 +25,7 @@ #include "common/events.h" #include "common/system.h" #include "common/util.h" +#include "engines/engine.h" #include "graphics/cursorman.h" #include "gui/newgui.h" #include "gui/dialog.h" @@ -255,7 +256,7 @@ void NewGui::runLoop() { Common::Event event; while (eventMan->pollEvent(event)) { - if (activeDialog != getTopDialog() && event.type != Common::EVENT_QUIT && event.type != Common::EVENT_SCREEN_CHANGED) + if (activeDialog != getTopDialog() && event.type != Common::EVENT_SCREEN_CHANGED) continue; Common::Point mouse(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y); @@ -313,7 +314,8 @@ void NewGui::runLoop() { activeDialog->handleMouseWheel(mouse.x, mouse.y, 1); break; case Common::EVENT_QUIT: - _system->quit(); + if (!g_engine) + _system->quit(); return; case Common::EVENT_SCREEN_CHANGED: screenChange(); diff --git a/gui/theme-config.cpp b/gui/theme-config.cpp index 47f60d3d7b..9fc23c5e7d 100644 --- a/gui/theme-config.cpp +++ b/gui/theme-config.cpp @@ -95,6 +95,7 @@ const char *Theme::_defaultConfigINI = "scummsaveload_thumbnail=(parent.w - (kThumbnailWidth + 22)) 18\n" "scummsaveload_cancel=(parent.w - 2 * (buttonWidth + 10)) (parent.h - buttonHeight - 8) buttonWidth buttonHeight\n" "scummsaveload_choose=(prev.x2 + 10) prev.y prev.w prev.h\n" +"scummsaveload_delete=prev.x2 prev.y prev.w prev.h\n" "scummsaveload_extinfo.visible=false\n" "\n" "# MM NES resolution\n" @@ -118,6 +119,7 @@ const char *Theme::_defaultConfigINI = "def_aboutXOff=8\n" "def_aboutYOff=5\n" "def_aboutOuterBorder=80\n" +"def_globalmainHOffset=52\n" "def_scummmainHOffset=12\n" "def_scummmainVSpace=7\n" "def_scummmainVAddOff=3\n" @@ -171,10 +173,11 @@ const char *Theme::_defaultConfigINI = "launcher_options_button=(prev.x2 + space) prev.y prev.w prev.h\n" "launcher_start_button=(prev.x2 + space) prev.y prev.w prev.h\n" "top=(top - buttonHeight * 2)\n" -"numButtons=3\n" +"numButtons=4\n" "space=10\n" "butWidth=((w - 2 * hBorder - space * (numButtons - 1)) / numButtons)\n" -"launcher_addGame_button=hBorder top butWidth buttonHeight\n" +"launcher_loadGame_button=hBorder top butWidth buttonHeight\n" +"launcher_addGame_button=(prev.x2 + space) prev.y prev.w prev.h\n" "launcher_editGame_button=(prev.x2 + space) prev.y prev.w prev.h\n" "launcher_removeGame_button=(prev.x2 + space) prev.y prev.w prev.h\n" "launcher_list=hBorder (kLineHeight + 16) (w - 2 * hBorder) (top - kLineHeight - 20)\n" @@ -371,6 +374,7 @@ const char *Theme::_defaultConfigINI = "scummsaveload_thumbnail.fillB=0\n" "scummsaveload_cancel=(parent.w - 2 * (buttonWidth + 10)) (parent.h - buttonHeight - 8) buttonWidth buttonHeight\n" "scummsaveload_choose=(prev.x2 + 10) prev.y prev.w prev.h\n" +"scummsaveload_delete=prev.x (prev.y - 30) prev.w prev.h\n" "scummsaveload_extinfo.visible=true\n" "\n" "############################################\n" @@ -482,6 +486,31 @@ const char *Theme::_defaultConfigINI = "smH=(smY + scummmainVSpace)\n" "scummmain=((w - smW) / 2) ((h - smH) / 2) smW smH\n" "\n" +"#### Global Main Menu Dialog" +"[globalmain]\n" +"# note that globalmain size depends on overall height\n" +"hBorder=10\n" +"gmW=(scummmainButtonWidth + (2 * scummmainHOffset) + 80)\n" +"global_title=hBorder 8 (gmW - 2 * hBorder) kLineHeight\n" +"global_title.align=kTextAlignCenter\n" +"global_version=hBorder 25 (gmW - 2 * hBorder) kLineHeight\n" +"global_version.align=kTextAlignCenter\n" +"gmY=((scummmainVSpace * 7)+ scummmainVAddOff)\n" +"globalmain_resume=globalmainHOffset gmY scummmainButtonWidth scummmainButtonHeight\n" +"gmY=(gmY + scummmainButtonHeight + scummmainVAddOff)\n" +"gmY=(gmY + scummmainVSpace)\n" +"globalmain_options=prev.x gmY prev.w prev.h\n" +"gmY=(gmY + scummmainButtonHeight + scummmainVAddOff)\n" +"globalmain_about=prev.x gmY prev.w prev.h\n" +"gmY=(gmY + scummmainButtonHeight + scummmainVAddOff)\n" +"gmY=(gmY + scummmainVSpace)\n" +"globalmain_rtl=prev.x gmY prev.w prev.h\n" +"gmY=(gmY + scummmainButtonHeight + scummmainVAddOff)\n" +"globalmain_quit=prev.x gmY prev.w prev.h\n" +"gmY=(gmY + scummmainButtonHeight + scummmainVAddOff)\n" +"gmH=(gmY + scummmainVSpace)\n" +"globalmain=((w - gmW) / 2) ((h - gmH) / 2) gmW gmH\n" +"\n" "# PSP GUI\n" "[480x272]\n" "def_buttonWidth=100\n" diff --git a/gui/themes/classic080.ini b/gui/themes/classic080.ini index b5c911bada..766059ecb5 100644 --- a/gui/themes/classic080.ini +++ b/gui/themes/classic080.ini @@ -82,13 +82,14 @@ hBorder=10 launcher_version=hBorder 8 (w - 2 * hBorder) kLineHeight launcher_version.align=kTextAlignCenter top=(h - 8 - buttonHeight) -numButtons=4 +numButtons=3 space=8 butWidth=((w - 2 * hBorder - space * (numButtons - 1)) / numButtons) launcher_quit_button=hBorder top butWidth buttonHeight launcher_about_button=(prev.x2 + space) prev.y prev.w prev.h launcher_options_button=(prev.x2 + space) prev.y prev.w prev.h launcher_start_button=(prev.x2 + space) prev.y prev.w prev.h +launcher_loadGame_button=(prev.x2 + space) prev.y prev.w prev.h top=(top - buttonHeight * 2) numButtons=3 space=10 @@ -289,6 +290,7 @@ scummsaveload_thumbnail.fillG=0 scummsaveload_thumbnail.fillB=0 scummsaveload_cancel=(parent.w - 2 * (buttonWidth + 10)) (parent.h - buttonHeight - 8) buttonWidth buttonHeight scummsaveload_choose=(prev.x2 + 10) prev.y prev.w prev.h +scummsaveload_delete=prev.x (prev.y - 30) prev.w prev.h scummsaveload_extinfo.visible=true ############################################ @@ -441,6 +443,7 @@ scummsaveload_list=10 18 prev.w (parent.h - 17 - buttonHeight - 8 - self.y) scummsaveload_thumbnail=(parent.w - (kThumbnailWidth + 22)) 18 scummsaveload_cancel=(parent.w - 2 * (buttonWidth + 10)) (parent.h - buttonHeight - 8) buttonWidth buttonHeight scummsaveload_choose=(prev.x2 + 10) prev.y prev.w prev.h +scummsaveload_delete=prev.x (prev.y - 30) prev.w prev.h scummsaveload_extinfo.visible=false # MM NES resolution diff --git a/gui/themes/modern.ini b/gui/themes/modern.ini index 87ef0bcbb9..8dbe7331f8 100644 --- a/gui/themes/modern.ini +++ b/gui/themes/modern.ini @@ -250,6 +250,7 @@ space1=20 space2=5 launcher_list=insetX insetY insetW insetH launcher_start_button=(prev.x2 + 17) prev.y buttonWidth buttonHeight +launcher_loadGame_button=prev.x (prev.y2 + space2) prev.w prev.h launcher_addGame_button=prev.x (prev.y2 + space1) prev.w prev.h launcher_editGame_button=prev.x (prev.y2 + space2) prev.w prev.h launcher_removeGame_button=prev.x (prev.y2 + space2) prev.w prev.h @@ -456,6 +457,7 @@ scummsaveload_thumbnail.fillG=0 scummsaveload_thumbnail.fillB=0 scummsaveload_cancel=(parent.w - 2 * (buttonWidth + 10)) (parent.h - buttonHeight - 8) buttonWidth buttonHeight scummsaveload_choose=(prev.x2 + 10) prev.y prev.w prev.h +scummsaveload_delete=prev.x (prev.y - 30) prev.w prev.h scummsaveload_extinfo.visible=true ############################################ |