Patch #2122869: ALL: Common load dialog

svn-id: r34883
This commit is contained in:
Max Horn 2008-11-03 18:32:16 +00:00
parent 6466661252
commit 55c10e0ec6
24 changed files with 251 additions and 55 deletions

View file

@ -33,6 +33,7 @@
#include "gui/about.h"
#include "gui/newgui.h"
#include "gui/launcher.h"
#include "gui/ListWidget.h"
#include "gui/theme.h"
@ -96,8 +97,15 @@ MainMenuDialog::MainMenuDialog(Engine *engine)
new GUI::ButtonWidget(this, "GlobalMenu.Resume", "Resume", kPlayCmd, 'P');
// new GUI::ButtonWidget(this, "globalmain_load", "Load", kLoadCmd, 'L');
// new GUI::ButtonWidget(this, "globalmain_save", "Save", kSaveCmd, 'S');
_loadButton = new GUI::ButtonWidget(this, "GlobalMenu.Load", "Load", kLoadCmd, 'L');
// TODO: setEnabled -> setVisible
_loadButton->setEnabled(_engine->hasFeature(Engine::kSupportsListSaves) &&
_engine->hasFeature(Engine::kSupportsLoadingDuringRuntime));
_saveButton = new GUI::ButtonWidget(this, "GlobalMenu.Save", "Save", kSaveCmd, 'S');
// TODO: setEnabled -> setVisible
_saveButton->setEnabled(_engine->hasFeature(Engine::kSupportsListSaves) &&
_engine->hasFeature(Engine::kSupportsSavingDuringRuntime));
new GUI::ButtonWidget(this, "GlobalMenu.Options", "Options", kOptionsCmd, 'O');
@ -111,11 +119,14 @@ MainMenuDialog::MainMenuDialog(Engine *engine)
_aboutDialog = new GUI::AboutDialog();
_optionsDialog = new ConfigDialog();
_loadDialog = new GUI::SaveLoadChooser("Load game:", "Load");
}
MainMenuDialog::~MainMenuDialog() {
delete _aboutDialog;
delete _optionsDialog;
delete _loadDialog;
//delete _saveDialog;
}
void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
@ -123,6 +134,39 @@ void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
case kPlayCmd:
close();
break;
case kLoadCmd:
{
String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0;
EngineMan.findGame(gameId, &plugin);
int slot = _loadDialog->runModal(plugin, ConfMan.getActiveDomainName());
if (slot >= 0) {
_engine->loadGameState(slot);
close();
}
}
break;
case kSaveCmd:
/*
String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0;
EngineMan.findGame(gameId, &plugin);
int slot = _saveDialog->runModal(plugin, ConfMan.getActiveDomainName());
if (slot >= 0) {
_engine->saveGameState(slot);
close();
}
}
*/
break;
case kOptionsCmd:
_optionsDialog->runModal();
break;
@ -149,6 +193,9 @@ void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
}
void MainMenuDialog::reflowLayout() {
_loadButton->setEnabled(_engine->canLoadGameStateCurrently());
_saveButton->setEnabled(_engine->canSaveGameStateCurrently());
#ifndef DISABLE_FANCY_THEMES
if (g_gui.xmlEval()->getVar("Globals.ShowGlobalMenuLogo", 0) == 1 && g_gui.theme()->supportsImages()) {
if (!_logo)

View file

@ -27,6 +27,7 @@
#include "common/str.h"
#include "gui/dialog.h"
#include "gui/launcher.h"
#include "gui/options.h"
#include "gui/widget.h"
@ -56,8 +57,11 @@ protected:
GUI::GraphicsWidget *_logo;
GUI::ButtonWidget *_rtlButton;
GUI::ButtonWidget *_loadButton;
GUI::ButtonWidget *_saveButton;
GUI::Dialog *_aboutDialog;
GUI::Dialog *_optionsDialog;
GUI::SaveLoadChooser *_loadDialog;
};

View file

@ -255,6 +255,26 @@ void Engine::syncSoundSettings() {
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, soundVolumeSpeech);
}
int Engine::loadGameState(int slot) {
// Do nothing by default
return 0;
}
bool Engine::canLoadGameStateCurrently() {
// Do not allow loading by default
return false;
}
int Engine::saveGameState(int slot) {
// Do nothing by default
return 0;
}
bool Engine::canSaveGameStateCurrently() {
// Do not allow saving by default
return false;
}
void Engine::quitGame() {
Common::Event event;

View file

@ -125,6 +125,26 @@ public:
*/
virtual void syncSoundSettings();
/**
* Load a game state
*/
virtual int loadGameState(int slot);
/**
* Indicates whether a game state can be loaded
*/
virtual bool canLoadGameStateCurrently();
/**
* Save a game state
*/
virtual int saveGameState(int slot);
/**
* Indicates whether a game state can be saved
*/
virtual bool canSaveGameStateCurrently();
protected:
/**
@ -182,7 +202,24 @@ public:
/**
* 'Return to launcher' feature is supported, i.e., EVENT_RTL is handled.
*/
kSupportsRTL
kSupportsRTL = 0,
/**
* Listing all Save States for a given target is supported, i.e.,
* the listSaves() method is implemented.
* Used for --list-saves support, as well as the GMM load dialog.
*/
kSupportsListSaves = 1,
/**
* Loading from the in-game common ScummVM options dialog is supported
*/
kSupportsLoadingDuringRuntime = 8,
/**
* Saving from the in-game common ScummVM options dialog is supported
*/
kSupportsSavingDuringRuntime = 9
};
/**

View file

@ -427,8 +427,8 @@ protected:
void dialogueReplyToQuestion(int x, int y, int r, int g, int b, int reply = 0);
void saveOrLoadGameState(TypeSerializer &typeSerializer);
void loadGameState(int slot);
void saveGameState(int slot);
int loadGameState(int slot);
int saveGameState(int slot);
void generateGameStateFileName(int num, char *dst, int len) const;
MidiPlayer *_midiPlayer;

View file

@ -156,7 +156,7 @@ void IgorEngine::saveOrLoadGameState(TypeSerializer &typeSerializer) {
}
}
void IgorEngine::loadGameState(int slot) {
int IgorEngine::loadGameState(int slot) {
char name[64];
generateGameStateFileName(slot, name, 63);
Common::InSaveFile *isf = _saveFileMan->openForLoading(name);
@ -175,9 +175,11 @@ void IgorEngine::loadGameState(int slot) {
}
debug(0, "Loaded state, current part %d", _currentPart);
}
return 0; // TODO: return success/failure
}
void IgorEngine::saveGameState(int slot) {
int IgorEngine::saveGameState(int slot) {
char name[64];
generateGameStateFileName(slot, name, 63);
Common::OutSaveFile *osf = _saveFileMan->openForSaving(name);
@ -187,6 +189,8 @@ void IgorEngine::saveGameState(int slot) {
saveOrLoadGameState(ts);
delete osf;
}
return 0; // TODO: return success/failure
}
void IgorEngine::generateGameStateFileName(int num, char *dst, int len) const {

View file

@ -183,7 +183,17 @@ public:
* the game till the save.
* This flag may only be set when 'kSavesSupportMetaInfo' is set.
*/
kSavesSupportPlayTime
kSavesSupportPlayTime,
/**
*Features loading from the Common ScummVM options dialog in-game
*/
kSupportsLoadingDuringRuntime,
/**
*Features saving from the Common ScummVM options dialog in-game
*/
kSupportsSavingDuringRuntime
};
/**

View file

@ -351,7 +351,7 @@ void QueenEngine::saveGameState(int slot, const char *desc) {
}
}
void QueenEngine::loadGameState(int slot) {
int QueenEngine::loadGameState(int slot) {
debug(3, "Loading game from slot %d", slot);
GameStateHeader header;
Common::InSaveFile *file = readGameStateHeader(slot, &header);
@ -374,6 +374,8 @@ void QueenEngine::loadGameState(int slot) {
delete[] saveData;
delete file;
}
return 0; // TODO: return success/failure
}
Common::InSaveFile *QueenEngine::readGameStateHeader(int slot, GameStateHeader *gsh) {

View file

@ -108,7 +108,7 @@ public:
bool canLoadOrSave() const;
void saveGameState(int slot, const char *desc);
void loadGameState(int slot);
int loadGameState(int slot);
void makeGameStateName(int slot, char *buf) const;
int getGameStateSlot(const char *filename) const;
void findGameStateDescriptions(char descriptions[100][32]);

View file

@ -33,7 +33,9 @@
#include "common/advancedDetector.h"
#include "common/system.h"
#include "saga/animation.h"
#include "saga/displayinfo.h"
#include "saga/events.h"
#include "saga/rscfile.h"
#include "saga/interface.h"
#include "saga/scene.h"
@ -157,7 +159,9 @@ bool SagaMetaEngine::hasFeature(MetaEngineFeature f) const {
(f == kSupportsRTL) ||
(f == kSupportsListSaves) ||
(f == kSupportsLoadingDuringStartup) ||
(f == kSupportsDeleteSave);
(f == kSupportsDeleteSave) ||
(f == kSupportsLoadingDuringRuntime) ||
(f == kSupportsSavingDuringRuntime);
}
bool SagaMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common::ADGameDescription *desc) const {
@ -237,4 +241,24 @@ int SagaEngine::getDisplayHeight() const {
return di.logicalHeight;
}
int SagaEngine::loadGameState(int slot) {
// Init the current chapter to 8 (character selection) for IHNM
if (getGameType() == GType_IHNM)
_scene->changeScene(-2, 0, kTransitionFade, 8);
// First scene sets up palette
_scene->changeScene(getStartSceneNumber(), 0, kTransitionNoFade);
_events->handleEvents(0); // Process immediate events
if (getGameType() != GType_IHNM)
_interface->setMode(kPanelMain);
else
_interface->setMode(kPanelChapterSelection);
load(calcSaveFileName((uint)slot));
syncSoundSettings();
return 0; // TODO: return success/failure
}
} // End of namespace Saga

View file

@ -532,4 +532,12 @@ void SagaEngine::syncSoundSettings() {
_sound->setVolume();
}
bool SagaEngine::canLoadGameStateCurrently() {
return !this->_scene->isInIntro();
}
bool SagaEngine::canSaveGameStateCurrently() {
return !this->_scene->isInIntro();
}
} // End of namespace Saga

View file

@ -650,6 +650,9 @@ public:
const Common::Rect &getDisplayClip() const { return _displayClip;}
int getDisplayWidth() const;
int getDisplayHeight() const;
int loadGameState(int slot);
bool canLoadGameStateCurrently();
bool canSaveGameStateCurrently();
const GameDisplayInfo &getDisplayInfo();
const char *getTextString(int textStringId);

View file

@ -331,7 +331,7 @@ void ToucheEngine::handleMenuAction(void *menu, int actionId) {
break;
case kActionPerformSaveLoad:
if (menuData->mode == kMenuLoadStateMode) {
if (loadGameState(_saveLoadCurrentSlot)) {
if (loadGameState(_saveLoadCurrentSlot) == 0) {
menuData->quit = true;
}
} else if (menuData->mode == kMenuSaveStateMode) {

View file

@ -340,7 +340,7 @@ bool ToucheEngine::saveGameState(int num, const char *description) {
return saveOk;
}
bool ToucheEngine::loadGameState(int num) {
int ToucheEngine::loadGameState(int num) {
bool loadOk = false;
char gameStateFileName[64];
generateGameStateFileName(num, gameStateFileName, 63);
@ -360,7 +360,7 @@ bool ToucheEngine::loadGameState(int num) {
}
delete f;
}
return loadOk;
return loadOk ? 0 : 1;
}
void ToucheEngine::readGameStateDescription(int num, char *description, int len) {

View file

@ -496,7 +496,7 @@ protected:
void saveGameStateData(Common::WriteStream *stream);
void loadGameStateData(Common::ReadStream *stream);
bool saveGameState(int num, const char *description);
bool loadGameState(int num);
int loadGameState(int num);
void readGameStateDescription(int num, char *description, int len);
void generateGameStateFileName(int num, char *dst, int len, bool prefixOnly = false) const;
int getGameStateFileSlot(const char *filename) const;

View file

@ -473,45 +473,6 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
}
}
class SaveLoadChooser : public GUI::Dialog {
typedef Common::String String;
typedef Common::StringList StringList;
protected:
GUI::ListWidget *_list;
GUI::ButtonWidget *_chooseButton;
GUI::ButtonWidget *_deleteButton;
GUI::GraphicsWidget *_gfxWidget;
GUI::ContainerWidget *_container;
GUI::StaticTextWidget *_date;
GUI::StaticTextWidget *_time;
GUI::StaticTextWidget *_playtime;
const EnginePlugin *_plugin;
bool _delSupport;
bool _metaInfoSupport;
bool _thumbnailSupport;
bool _saveDateSupport;
bool _playTimeSupport;
String _target;
SaveStateList _saveList;
uint8 _fillR, _fillG, _fillB;
void updateSaveList();
void updateSelection(bool redraw);
public:
SaveLoadChooser(const String &title, const String &buttonLabel);
~SaveLoadChooser();
virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
void setList(const StringList& list);
int runModal(const EnginePlugin *plugin, const String &target);
virtual void reflowLayout();
virtual void close();
};
SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel)
: Dialog("ScummSaveLoad"), _delSupport(0), _list(0), _chooseButton(0), _deleteButton(0), _gfxWidget(0) {
_delSupport = _metaInfoSupport = _thumbnailSupport = _saveDateSupport = _playTimeSupport = false;

View file

@ -27,6 +27,7 @@
#include "gui/dialog.h"
#include "engines/game.h"
#include "engines/metaengine.h"
#include "common/str.h"
namespace GUI {
@ -79,6 +80,45 @@ protected:
void selectGame(const String &name);
};
class SaveLoadChooser : public GUI::Dialog {
typedef Common::String String;
typedef Common::StringList StringList;
protected:
GUI::ListWidget *_list;
GUI::ButtonWidget *_chooseButton;
GUI::ButtonWidget *_deleteButton;
GUI::GraphicsWidget *_gfxWidget;
GUI::ContainerWidget *_container;
GUI::StaticTextWidget *_date;
GUI::StaticTextWidget *_time;
GUI::StaticTextWidget *_playtime;
const EnginePlugin *_plugin;
bool _delSupport;
bool _metaInfoSupport;
bool _thumbnailSupport;
bool _saveDateSupport;
bool _playTimeSupport;
String _target;
SaveStateList _saveList;
uint8 _fillR, _fillG, _fillB;
void updateSaveList();
void updateSelection(bool redraw);
public:
SaveLoadChooser(const String &title, const String &buttonLabel);
~SaveLoadChooser();
virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
void setList(const StringList& list);
int runModal(const EnginePlugin *plugin, const String &target);
virtual void reflowLayout();
virtual void close();
};
} // End of namespace GUI
#endif

View file

@ -67,7 +67,7 @@ protected:
Widget *_firstWidget;
public:
GuiObject(int x, int y, int w, int h) : _x(x), _y(y), _w(w), _h(h), _name(""), _firstWidget(0) { }
GuiObject(int x, int y, int w, int h) : _x(x), _y(y), _w(w), _h(h), _firstWidget(0) { }
GuiObject(const Common::String &name);
~GuiObject();

Binary file not shown.

View file

@ -464,6 +464,15 @@
height = 'Globals.Button.Height'
/>
<space size = '10'/>
<widget name = 'Load'
width = '150'
height = 'Globals.Button.Height'
/>
<widget name = 'Save'
width = '150'
height = 'Globals.Button.Height'
/>
<space size = '10'/>
<widget name = 'Options'
width = '150'
height = 'Globals.Button.Height'

View file

@ -465,6 +465,15 @@
height = 'Globals.Button.Height'
/>
<space size = '4'/>
<widget name = 'Load'
width = '70'
height = 'Globals.Button.Height'
/>
<widget name = 'Save'
width = '70'
height = 'Globals.Button.Height'
/>
<space size = '4'/>
<widget name = 'Options'
width = '70'
height = 'Globals.Button.Height'

Binary file not shown.

View file

@ -476,6 +476,15 @@
height = 'Globals.Button.Height'
/>
<space size = '10'/>
<widget name = 'Load'
width = '150'
height = 'Globals.Button.Height'
/>
<widget name = 'Save'
width = '150'
height = 'Globals.Button.Height'
/>
<space size = '10'/>
<widget name = 'Options'
width = '150'
height = 'Globals.Button.Height'

View file

@ -462,6 +462,15 @@
height = 'Globals.Button.Height'
/>
<space size = '4'/>
<widget name = 'Load'
width = '70'
height = 'Globals.Button.Height'
/>
<widget name = 'Save'
width = '70'
height = 'Globals.Button.Height'
/>
<space size = '4'/>
<widget name = 'Options'
width = '70'
height = 'Globals.Button.Height'