Ticket #8925: common-load_v2.patch

File common-load_v2.patch, 15.6 KB (added by bluegr, 16 years ago)

Common load/save game dialog, version 2 (WIP)

  • engines/dialogs.cpp

     
    3434#include "gui/about.h"
    3535#include "gui/eval.h"
    3636#include "gui/newgui.h"
     37#include "gui/launcher.h"
    3738#include "gui/ListWidget.h"
    3839#include "gui/theme.h"
    3940
     
    9596               
    9697        new GUI::ButtonWidget(this, "globalmain_resume", "Resume", kPlayCmd, 'P');
    9798
    98 //      new GUI::ButtonWidget(this, "globalmain_load", "Load", kLoadCmd, 'L');
    99 //      new GUI::ButtonWidget(this, "globalmain_save", "Save", kSaveCmd, 'S');
     99        _loadButton = new GUI::ButtonWidget(this, "globalmain_load", "Load", kLoadCmd, 'L');
    100100
     101        _saveButton = new GUI::ButtonWidget(this, "globalmain_save", "Save", kSaveCmd, 'S');
     102
    101103        new GUI::ButtonWidget(this, "globalmain_options", "Options", kOptionsCmd, 'O');
    102104
    103105        new GUI::ButtonWidget(this, "globalmain_about", "About", kAboutCmd, 'A');
     
    111113
    112114        _aboutDialog = new GUI::AboutDialog();
    113115        _optionsDialog = new ConfigDialog();
     116        _loadDialog = new GUI::SaveLoadChooser("Load game:", "Load");
    114117}
    115118
    116119MainMenuDialog::~MainMenuDialog() {
    117120        delete _aboutDialog;
    118121        delete _optionsDialog;
     122        delete _loadDialog;
     123        //delete _saveDialog;
    119124}
    120125
    121126void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
     
    123128        case kPlayCmd:
    124129                close();
    125130                break;
     131        case kLoadCmd:
     132                {
     133                String gameId = ConfMan.get("gameid");
     134
     135                const EnginePlugin *plugin = 0;
     136                EngineMan.findGame(gameId, &plugin);
     137
     138                int slot = _loadDialog->runModal(plugin, ConfMan.getActiveDomainName());
     139
     140                if (slot >= 0) {
     141                        _engine->loadGameState(slot);
     142                        close();
     143                }
     144
     145                }
     146                break;
     147        case kSaveCmd:
     148                /*
     149                String gameId = ConfMan.get("gameid");
     150
     151                const EnginePlugin *plugin = 0;
     152                EngineMan.findGame(gameId, &plugin);
     153
     154                int slot = _saveDialog->runModal(plugin, ConfMan.getActiveDomainName());
     155
     156                if (slot >= 0) {
     157                        _engine->saveGameState(slot);
     158                        close();
     159                }
     160
     161                }
     162                */
     163                break;
    126164        case kOptionsCmd:
    127165                _optionsDialog->runModal();
    128166                break;
     
    149187}
    150188
    151189void MainMenuDialog::reflowLayout() {
     190        // '1' - kSupportsListSaves, '8' - kSupportsLoading
     191        _loadButton->setEnabled(_engine->hasFeature(1) &&
     192                                                        _engine->hasFeature(8) &&
     193                                                        _engine->canLoadGameState());
     194        // '1' - kSupportsListSaves, '9' - kSupportsSaving
     195        _saveButton->setEnabled(_engine->hasFeature(1) &&
     196                                                        _engine->hasFeature(9) &&
     197                                                        _engine->canSaveGameState());
     198
    152199#ifndef DISABLE_FANCY_THEMES
    153200        if (g_gui.evaluator()->getVar("global_logo.visible") == 1 && g_gui.theme()->supportsImages()) {
    154201                if (!_logo)
  • engines/dialogs.h

     
    2727
    2828#include "common/str.h"
    2929#include "gui/dialog.h"
     30#include "gui/launcher.h"
    3031#include "gui/options.h"
    3132#include "gui/widget.h"
    3233
     
    5657
    5758        GUI::GraphicsWidget *_logo;
    5859        GUI::ButtonWidget       *_rtlButton;
     60        GUI::ButtonWidget       *_loadButton;
     61        GUI::ButtonWidget       *_saveButton;
    5962        GUI::Dialog             *_aboutDialog;
    6063        GUI::Dialog             *_optionsDialog;
     64        GUI::SaveLoadChooser    *_loadDialog;
    6165
    6266};
    6367
  • engines/engine.cpp

     
    216216        _mixer->pauseAll(pause);
    217217}
    218218
     219int Engine::loadGameState(int slot) {
     220        // Do nothing by default
     221        return 0;
     222}
     223
     224bool Engine::canLoadGameState() {
     225        // Allow loading by default
     226        return true;
     227}
     228
     229int Engine::saveGameState(int slot) {
     230        // Do nothing by default
     231        return 0;
     232}
     233
     234bool Engine::canSaveGameState() {
     235        // Allow saving by default
     236        return true;
     237}
     238
     239void Engine::audioSettingsChanged() {
     240        // Do nothing by default
     241}
     242
    219243void Engine::mainMenuDialog() {
    220244        if (!_mainMenuDialog)
    221245                _mainMenuDialog = new MainMenuDialog(this);
  • engines/engine.h

     
    164164         * for details.
    165165         */
    166166        virtual void pauseEngineIntern(bool pause);
     167
     168        /** Load a game state */
     169        virtual int loadGameState(int slot);
     170
     171        /** Indicates whether a game state can be loaded */
     172        virtual bool canLoadGameState();
     173
     174        /** Save a game state */
     175        virtual int saveGameState(int slot);
     176
     177        /** Indicates whether a game state can be saved */
     178        virtual bool canSaveGameState();
     179
     180        /** Called when the user changes volume settings from the GMM */
     181        virtual void audioSettingsChanged();
    167182};
    168183
    169184extern Engine *g_engine;
  • engines/igor/igor.h

     
    427427        void dialogueReplyToQuestion(int x, int y, int r, int g, int b, int reply = 0);
    428428
    429429        void saveOrLoadGameState(TypeSerializer &typeSerializer);
    430         void loadGameState(int slot);
    431         void saveGameState(int slot);
     430        int loadGameState(int slot);
     431        int saveGameState(int slot);
    432432        void generateGameStateFileName(int num, char *dst, int len) const;
    433433
    434434        MidiPlayer *_midiPlayer;
  • engines/igor/saveload.cpp

     
    156156        }
    157157}
    158158
    159 void IgorEngine::loadGameState(int slot) {
     159int IgorEngine::loadGameState(int slot) {
    160160        char name[64];
    161161        generateGameStateFileName(slot, name, 63);
    162162        Common::InSaveFile *isf = _saveFileMan->openForLoading(name);
     
    175175                }
    176176                debug(0, "Loaded state, current part %d", _currentPart);
    177177        }
     178
     179        return 0;       // TODO: return success/failure
    178180}
    179181
    180 void IgorEngine::saveGameState(int slot) {
     182int IgorEngine::saveGameState(int slot) {
    181183        char name[64];
    182184        generateGameStateFileName(slot, name, 63);
    183185        Common::OutSaveFile *osf = _saveFileMan->openForSaving(name);
     
    187189                saveOrLoadGameState(ts);
    188190                delete osf;
    189191        }
     192
     193        return 0;       // TODO: return success/failure
    190194}
    191195
    192196void IgorEngine::generateGameStateFileName(int num, char *dst, int len) const {
  • engines/metaengine.h

     
    170170                 * the game till the save.
    171171                 * This flag may only be set when 'kSupportsMetaInfos' is set.
    172172                 */
    173                 kSupportsSavePlayTime   = 7
     173                kSupportsSavePlayTime   = 7,
     174
     175                /** Loading from the Common ScummVM options dialog in-game */
     176                kSupportsLoading                = 8,
     177
     178                /** Saving from the Common ScummVM options dialog in-game */
     179                kSupportsSaving                 = 9
    174180        };     
    175181
    176182        /**
  • engines/queen/queen.cpp

     
    351351        }
    352352}
    353353
    354 void QueenEngine::loadGameState(int slot) {
     354int QueenEngine::loadGameState(int slot) {
    355355        debug(3, "Loading game from slot %d", slot);
    356356        GameStateHeader header;
    357357        Common::InSaveFile *file = readGameStateHeader(slot, &header);
     
    374374                delete[] saveData;
    375375                delete file;
    376376        }
     377
     378        return 0;       // TODO: return success/failure
    377379}
    378380
    379381Common::InSaveFile *QueenEngine::readGameStateHeader(int slot, GameStateHeader *gsh) {
  • engines/queen/queen.h

     
    108108
    109109        bool canLoadOrSave() const;
    110110        void saveGameState(int slot, const char *desc);
    111         void loadGameState(int slot);
     111        int loadGameState(int slot);
    112112        void makeGameStateName(int slot, char *buf) const;
    113113        int getGameStateSlot(const char *filename) const;
    114114        void findGameStateDescriptions(char descriptions[100][32]);
  • engines/saga/detection.cpp

     
    3232#include "common/config-manager.h"
    3333#include "common/advancedDetector.h"
    3434
     35#include "saga/animation.h"
    3536#include "saga/displayinfo.h"
     37#include "saga/events.h"
    3638#include "saga/rscfile.h"
    3739#include "saga/interface.h"
    3840#include "saga/scene.h"
     
    158160                (f == kSupportsRTL) ||
    159161                (f == kSupportsListSaves) ||
    160162                (f == kSupportsDirectLoad) ||
    161                 (f == kSupportsDeleteSave);
     163                (f == kSupportsDeleteSave) ||
     164                (f == kSupportsLoading) ||
     165                (f == kSupportsSaving);
    162166}
    163167
    164168bool SagaMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common::ADGameDescription *desc) const {
     
    238242        return di.logicalHeight;
    239243}
    240244
     245int SagaEngine::loadGameState(int slot) {
     246        // Init the current chapter to 8 (character selection) for IHNM
     247        if (getGameType() == GType_IHNM)
     248                _scene->changeScene(-2, 0, kTransitionFade, 8);
     249
     250        // First scene sets up palette
     251        _scene->changeScene(getStartSceneNumber(), 0, kTransitionNoFade);
     252        _events->handleEvents(0); // Process immediate events
     253
     254        if (getGameType() != GType_IHNM)
     255                _interface->setMode(kPanelMain);
     256        else
     257                _interface->setMode(kPanelChapterSelection);
     258
     259        load(calcSaveFileName((uint)slot));
     260        syncSoundSettings();
     261
     262        return 0;       // TODO: return success/failure
     263}
     264
    241265} // End of namespace Saga
  • engines/saga/saga.cpp

     
    532532        _sound->setVolume();
    533533}
    534534
     535bool SagaEngine::canLoadGameState() {
     536        return !this->_scene->isInIntro();
     537}
     538
     539bool SagaEngine::canSaveGameState() {
     540        return !this->_scene->isInIntro();
     541}
     542
    535543} // End of namespace Saga
  • engines/saga/saga.h

     
    651651        const Common::Rect &getDisplayClip() const { return _displayClip;}
    652652        int getDisplayWidth() const;
    653653        int getDisplayHeight() const;
     654        int loadGameState(int slot);
     655        bool canLoadGameState();
     656        bool canSaveGameState();
    654657        const GameDisplayInfo &getDisplayInfo();
    655658
    656659        const char *getTextString(int textStringId);
  • engines/touche/menu.cpp

     
    331331                break;
    332332        case kActionPerformSaveLoad:
    333333                if (menuData->mode == kMenuLoadStateMode) {
    334                         if (loadGameState(_saveLoadCurrentSlot)) {
     334                        if (loadGameState(_saveLoadCurrentSlot) == 0) {
    335335                                menuData->quit = true;
    336336                        }
    337337                } else if (menuData->mode == kMenuSaveStateMode) {
  • engines/touche/saveload.cpp

     
    340340        return saveOk;
    341341}
    342342
    343 bool ToucheEngine::loadGameState(int num) {
     343int ToucheEngine::loadGameState(int num) {
    344344        bool loadOk = false;
    345345        char gameStateFileName[64];
    346346        generateGameStateFileName(num, gameStateFileName, 63);
     
    360360                }
    361361                delete f;
    362362        }
    363         return loadOk;
     363        return loadOk ? 0 : 1;
    364364}
    365365
    366366void ToucheEngine::readGameStateDescription(int num, char *description, int len) {
  • engines/touche/touche.h

     
    496496        void saveGameStateData(Common::WriteStream *stream);
    497497        void loadGameStateData(Common::ReadStream *stream);
    498498        bool saveGameState(int num, const char *description);
    499         bool loadGameState(int num);
     499        int loadGameState(int num);
    500500        void readGameStateDescription(int num, char *description, int len);
    501501        void generateGameStateFileName(int num, char *dst, int len, bool prefixOnly = false) const;
    502502        int getGameStateFileSlot(const char *filename) const;
  • gui/launcher.cpp

     
    473473        }
    474474}
    475475
    476 class SaveLoadChooser : public GUI::Dialog {
    477         typedef Common::String String;
    478         typedef Common::StringList StringList;
    479 protected:
    480         GUI::ListWidget         *_list;
    481         GUI::ButtonWidget       *_chooseButton;
    482         GUI::ButtonWidget       *_deleteButton;
    483         GUI::GraphicsWidget     *_gfxWidget;
    484         GUI::ContainerWidget    *_container;
    485         GUI::StaticTextWidget   *_date;
    486         GUI::StaticTextWidget   *_time;
    487         GUI::StaticTextWidget   *_playtime;
    488 
    489         const EnginePlugin              *_plugin;
    490         bool                                    _delSupport;
    491         bool                                    _metaInfoSupport;
    492         bool                                    _thumbnailSupport;
    493         bool                                    _saveDateSupport;
    494         bool                                    _playTimeSupport;
    495         String                                  _target;
    496         SaveStateList                   _saveList;
    497 
    498         uint8 _fillR, _fillG, _fillB;
    499 
    500         void updateSaveList();
    501         void updateSelection(bool redraw);
    502 public:
    503         SaveLoadChooser(const String &title, const String &buttonLabel);
    504         ~SaveLoadChooser();
    505 
    506         virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
    507         void setList(const StringList& list);
    508         int runModal(const EnginePlugin *plugin, const String &target);
    509 
    510         virtual void reflowLayout();
    511 
    512         virtual void close();
    513 };
    514 
    515476SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel)
    516477        : Dialog("scummsaveload"), _delSupport(0), _list(0), _chooseButton(0), _deleteButton(0), _gfxWidget(0)  {
    517478        _delSupport = _metaInfoSupport = _thumbnailSupport = _saveDateSupport = _playTimeSupport = false;
  • gui/launcher.h

     
    2727
    2828#include "gui/dialog.h"
    2929#include "engines/game.h"
     30#include "engines/metaengine.h"
    3031#include "common/str.h"
    3132
    3233namespace GUI {
     
    7980        void selectGame(const String &name);
    8081};
    8182
     83class SaveLoadChooser : public GUI::Dialog {
     84        typedef Common::String String;
     85        typedef Common::StringList StringList;
     86protected:
     87        GUI::ListWidget         *_list;
     88        GUI::ButtonWidget       *_chooseButton;
     89        GUI::ButtonWidget       *_deleteButton;
     90        GUI::GraphicsWidget     *_gfxWidget;
     91        GUI::ContainerWidget    *_container;
     92        GUI::StaticTextWidget   *_date;
     93        GUI::StaticTextWidget   *_time;
     94        GUI::StaticTextWidget   *_playtime;
     95
     96        const EnginePlugin              *_plugin;
     97        bool                                    _delSupport;
     98        bool                                    _metaInfoSupport;
     99        bool                                    _thumbnailSupport;
     100        bool                                    _saveDateSupport;
     101        bool                                    _playTimeSupport;
     102        String                                  _target;
     103        SaveStateList                   _saveList;
     104
     105        uint8 _fillR, _fillG, _fillB;
     106
     107        void updateSaveList();
     108        void updateSelection(bool redraw);
     109public:
     110        SaveLoadChooser(const String &title, const String &buttonLabel);
     111        ~SaveLoadChooser();
     112
     113        virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
     114        void setList(const StringList& list);
     115        int runModal(const EnginePlugin *plugin, const String &target);
     116
     117        virtual void reflowLayout();
     118
     119        virtual void close();
     120};
     121
    82122} // End of namespace GUI
    83123
    84124#endif
  • gui/themes/modern.ini

     
    273273globalmain_resume=globalmainHOffset gmY scummmainButtonWidth scummmainButtonHeight
    274274gmY=(gmY + scummmainButtonHeight + scummmainVAddOff)
    275275gmY=(gmY + scummmainVSpace)
     276globalmain_load=prev.x gmY prev.w prev.h
     277gmY=(gmY + scummmainButtonHeight + scummmainVAddOff)
     278globalmain_save=prev.x gmY prev.w prev.h
     279gmY=(gmY + scummmainButtonHeight + scummmainVAddOff)
    276280globalmain_options=prev.x gmY prev.w prev.h
    277281gmY=(gmY + scummmainButtonHeight + scummmainVAddOff)
    278282globalmain_about=prev.x gmY prev.w prev.h