Ticket #8925: common-load_v4.patch

File common-load_v4.patch, 18.1 KB (added by bluegr, 16 years ago)

Common save/load game dialog, version 4 (working with the current GUI code)

  • engines/dialogs.cpp

     
    3333
    3434#include "gui/about.h"
    3535#include "gui/newgui.h"
     36#include "gui/launcher.h"
    3637#include "gui/ListWidget.h"
    3738#include "gui/theme.h"
    3839
     
    9697               
    9798        new GUI::ButtonWidget(this, "GlobalMenu.Resume", "Resume", kPlayCmd, 'P');
    9899
    99 //      new GUI::ButtonWidget(this, "globalmain_load", "Load", kLoadCmd, 'L');
    100 //      new GUI::ButtonWidget(this, "globalmain_save", "Save", kSaveCmd, 'S');
     100        _loadButton = new GUI::ButtonWidget(this, "GlobalMenu.Load", "Load", kLoadCmd, 'L');
     101        // TODO: setEnabled -> setVisible
     102        _loadButton->setEnabled(_engine->hasFeature(Engine::kSupportsListSaves) &&
     103                                                        _engine->hasFeature(Engine::kSupportsLoadingDuringRuntime));
     104 
     105        _saveButton = new GUI::ButtonWidget(this, "GlobalMenu.Save", "Save", kSaveCmd, 'S');
     106        // TODO: setEnabled -> setVisible
     107        _saveButton->setEnabled(_engine->hasFeature(Engine::kSupportsListSaves) &&
     108                                                        _engine->hasFeature(Engine::kSupportsSavingDuringRuntime));
    101109
    102110        new GUI::ButtonWidget(this, "GlobalMenu.Options", "Options", kOptionsCmd, 'O');
    103111
     
    111119
    112120        _aboutDialog = new GUI::AboutDialog();
    113121        _optionsDialog = new ConfigDialog();
     122        _loadDialog = new GUI::SaveLoadChooser("Load game:", "Load");
    114123}
    115124
    116125MainMenuDialog::~MainMenuDialog() {
    117126        delete _aboutDialog;
    118127        delete _optionsDialog;
     128        delete _loadDialog;
     129        //delete _saveDialog;
    119130}
    120131
    121132void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
     
    123134        case kPlayCmd:
    124135                close();
    125136                break;
     137        case kLoadCmd:
     138                {
     139                String gameId = ConfMan.get("gameid");
     140
     141                const EnginePlugin *plugin = 0;
     142                EngineMan.findGame(gameId, &plugin);
     143
     144                int slot = _loadDialog->runModal(plugin, ConfMan.getActiveDomainName());
     145
     146                if (slot >= 0) {
     147                        _engine->loadGameState(slot);
     148                        close();
     149                }
     150
     151                }
     152                break;
     153        case kSaveCmd:
     154                /*
     155                String gameId = ConfMan.get("gameid");
     156
     157                const EnginePlugin *plugin = 0;
     158                EngineMan.findGame(gameId, &plugin);
     159
     160                int slot = _saveDialog->runModal(plugin, ConfMan.getActiveDomainName());
     161
     162                if (slot >= 0) {
     163                        _engine->saveGameState(slot);
     164                        close();
     165                }
     166
     167                }
     168                */
     169                break;
    126170        case kOptionsCmd:
    127171                _optionsDialog->runModal();
    128172                break;
     
    149193}
    150194
    151195void MainMenuDialog::reflowLayout() {
     196        _loadButton->setEnabled(_engine->canLoadGameStateCurrently());
     197        _saveButton->setEnabled(_engine->canSaveGameStateCurrently());
     198
    152199#ifndef DISABLE_FANCY_THEMES
    153200        if (g_gui.xmlEval()->getVar("Globals.ShowGlobalMenuLogo", 0) == 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

     
    244244        _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, soundVolumeSpeech);
    245245}
    246246
     247int Engine::loadGameState(int slot) {
     248        // Do nothing by default
     249        return 0;
     250}
     251
     252bool Engine::canLoadGameStateCurrently() {
     253        // Do not allow loading by default
     254        return false;
     255}
     256
     257int Engine::saveGameState(int slot) {
     258        // Do nothing by default
     259        return 0;
     260}
     261
     262bool Engine::canSaveGameStateCurrently() {
     263        // Do not allow saving by default
     264        return false;
     265}
     266
    247267void Engine::quitGame() {
    248268        Common::Event event;
    249269
  • engines/engine.h

     
    125125         */
    126126        virtual void syncSoundSettings();
    127127
     128        /**
     129         * Load a game state
     130         */
     131        virtual int loadGameState(int slot);
     132
     133        /**
     134         * Indicates whether a game state can be loaded
     135         */
     136        virtual bool canLoadGameStateCurrently();
     137
     138        /**
     139         * Save a game state
     140         */
     141        virtual int saveGameState(int slot);
     142
     143        /**
     144         * Indicates whether a game state can be saved
     145         */
     146        virtual bool canSaveGameStateCurrently();
     147
    128148protected:
    129149
    130150        /**
     
    182202                /**
    183203                 * 'Return to launcher' feature is supported, i.e., EVENT_RTL is handled.
    184204                 */
    185                 kSupportsRTL
     205                kSupportsRTL = 0,
     206               
     207                /**
     208                 * Listing all Save States for a given target is supported, i.e.,
     209                 * the listSaves() method is implemented.
     210                 * Used for --list-saves support, as well as the GMM load dialog.
     211                 */
     212                kSupportsListSaves = 1,
     213
     214                /**
     215                 * Loading from the in-game common ScummVM options dialog is supported
     216                 */
     217                kSupportsLoadingDuringRuntime = 8,
     218
     219                /**
     220                 * Saving from the in-game common ScummVM options dialog is supported
     221                 */
     222                kSupportsSavingDuringRuntime = 9
    186223        };
    187224
    188225        /**
  • 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

     
    183183                 * the game till the save.
    184184                 * This flag may only be set when 'kSavesSupportMetaInfo' is set.
    185185                 */
    186                 kSavesSupportPlayTime
     186                kSavesSupportPlayTime,
     187               
     188                /**
     189                 *Features loading from the Common ScummVM options dialog in-game
     190                 */
     191                kSupportsLoadingDuringRuntime,
     192
     193                /**
     194                 *Features saving from the Common ScummVM options dialog in-game
     195                 */
     196                kSupportsSavingDuringRuntime
    187197        };     
    188198
    189199        /**
  • 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

     
    3333#include "common/advancedDetector.h"
    3434#include "common/system.h"
    3535
     36#include "saga/animation.h"
    3637#include "saga/displayinfo.h"
     38#include "saga/events.h"
    3739#include "saga/rscfile.h"
    3840#include "saga/interface.h"
    3941#include "saga/scene.h"
     
    157159                (f == kSupportsRTL) ||
    158160                (f == kSupportsListSaves) ||
    159161                (f == kSupportsLoadingDuringStartup) ||
    160                 (f == kSupportsDeleteSave);
     162                (f == kSupportsDeleteSave) ||
     163                (f == kSupportsLoadingDuringRuntime) ||
     164                (f == kSupportsSavingDuringRuntime);
    161165}
    162166
    163167bool SagaMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common::ADGameDescription *desc) const {
     
    237241        return di.logicalHeight;
    238242}
    239243
     244int SagaEngine::loadGameState(int slot) {
     245        // Init the current chapter to 8 (character selection) for IHNM
     246        if (getGameType() == GType_IHNM)
     247                _scene->changeScene(-2, 0, kTransitionFade, 8);
     248
     249        // First scene sets up palette
     250        _scene->changeScene(getStartSceneNumber(), 0, kTransitionNoFade);
     251        _events->handleEvents(0); // Process immediate events
     252
     253        if (getGameType() != GType_IHNM)
     254                _interface->setMode(kPanelMain);
     255        else
     256                _interface->setMode(kPanelChapterSelection);
     257
     258        load(calcSaveFileName((uint)slot));
     259        syncSoundSettings();
     260
     261        return 0;       // TODO: return success/failure
     262}
     263
    240264} // End of namespace Saga
  • engines/saga/saga.cpp

     
    535535        _sound->setVolume();
    536536}
    537537
     538bool SagaEngine::canLoadGameStateCurrently() {
     539        return !this->_scene->isInIntro();
     540}
     541
     542bool SagaEngine::canSaveGameStateCurrently() {
     543        return !this->_scene->isInIntro();
     544}
     545
    538546} // End of namespace Saga
  • engines/saga/saga.h

     
    650650        const Common::Rect &getDisplayClip() const { return _displayClip;}
    651651        int getDisplayWidth() const;
    652652        int getDisplayHeight() const;
     653        int loadGameState(int slot);
     654        bool canLoadGameStateCurrently();
     655        bool canSaveGameStateCurrently();
    653656        const GameDisplayInfo &getDisplayInfo();
    654657
    655658        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/scummclassic/classic_layout.stx

     
    464464                                        height = 'Globals.Button.Height'
    465465                        />
    466466                        <space size = '10'/>
     467                        <widget name = 'Load'
     468                                        width = '150'
     469                                        height = 'Globals.Button.Height'
     470                        />
     471                        <widget name = 'Save'
     472                                        width = '150'
     473                                        height = 'Globals.Button.Height'
     474                        />                     
     475                        <space size = '10'/>
    467476                        <widget name = 'Options'
    468477                                        width = '150'
    469478                                        height = 'Globals.Button.Height'
  • gui/themes/scummclassic/classic_layout_320.stx

     
    465465                                        height = 'Globals.Button.Height'
    466466                        />
    467467                        <space size = '4'/>
     468                        <widget name = 'Load'
     469                                        width = '70'
     470                                        height = 'Globals.Button.Height'
     471                        />
     472                        <widget name = 'Save'
     473                                        width = '70'
     474                                        height = 'Globals.Button.Height'
     475                        />
     476                        <space size = '4'/>
    468477                        <widget name = 'Options'
    469478                                        width = '70'
    470479                                        height = 'Globals.Button.Height'
  • gui/themes/scummmodern/scummmodern_layout.stx

     
    476476                                        height = 'Globals.Button.Height'
    477477                        />
    478478                        <space size = '10'/>
     479                        <widget name = 'Load'
     480                                        width = '150'
     481                                        height = 'Globals.Button.Height'
     482                        />
     483                        <widget name = 'Save'
     484                                        width = '150'
     485                                        height = 'Globals.Button.Height'
     486                        />                     
     487                        <space size = '10'/>
    479488                        <widget name = 'Options'
    480489                                        width = '150'
    481490                                        height = 'Globals.Button.Height'
  • gui/themes/scummmodern/scummmodern_layout_320.stx

     
    462462                                        height = 'Globals.Button.Height'
    463463                        />
    464464                        <space size = '4'/>
     465                        <widget name = 'Load'
     466                                        width = '70'
     467                                        height = 'Globals.Button.Height'
     468                        />
     469                        <widget name = 'Save'
     470                                        width = '70'
     471                                        height = 'Globals.Button.Height'
     472                        />                                     
     473                        <space size = '4'/>
    465474                        <widget name = 'Options'
    466475                                        width = '70'
    467476                                        height = 'Globals.Button.Height'