GUI: Refactor engine plugin access out of SaveLoadChooserImpl into SaveLoadChooser.

This commit is contained in:
Johannes Schickel 2012-06-14 03:13:49 +02:00
parent b7c3ffd37c
commit e866dfd406

View file

@ -47,8 +47,7 @@ class SaveLoadChooserImpl : GUI::Dialog {
public: public:
SaveLoadChooserImpl(const String &title, const String &buttonLabel, bool saveMode); SaveLoadChooserImpl(const String &title, const String &buttonLabel, bool saveMode);
int runModalWithCurrentTarget(); int run(const String &target, const MetaEngine *metaEngine);
int runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target);
virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
@ -69,7 +68,7 @@ private:
GUI::StaticTextWidget *_time; GUI::StaticTextWidget *_time;
GUI::StaticTextWidget *_playtime; GUI::StaticTextWidget *_playtime;
const EnginePlugin *_plugin; const MetaEngine *_metaEngine;
bool _delSupport; bool _delSupport;
bool _metaInfoSupport; bool _metaInfoSupport;
bool _thumbnailSupport; bool _thumbnailSupport;
@ -118,41 +117,22 @@ SaveLoadChooserImpl::SaveLoadChooserImpl(const String &title, const String &butt
// _container->setHints(GUI::THEME_HINT_USE_SHADOW); // _container->setHints(GUI::THEME_HINT_USE_SHADOW);
} }
int SaveLoadChooserImpl::runModalWithCurrentTarget() { int SaveLoadChooserImpl::run(const String &target, const MetaEngine *metaEngine) {
const Common::String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0;
EngineMan.findGame(gameId, &plugin);
return runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
}
int SaveLoadChooserImpl::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) {
if (_gfxWidget) if (_gfxWidget)
_gfxWidget->setGfx(0); _gfxWidget->setGfx(0);
// Set up the game domain as newly active domain, so _metaEngine = metaEngine;
// target specific savepath will be checked
String oldDomain = ConfMan.getActiveDomainName();
ConfMan.setActiveDomain(target);
_plugin = plugin;
_target = target; _target = target;
_delSupport = (*_plugin)->hasFeature(MetaEngine::kSupportsDeleteSave); _delSupport = _metaEngine->hasFeature(MetaEngine::kSupportsDeleteSave);
_metaInfoSupport = (*_plugin)->hasFeature(MetaEngine::kSavesSupportMetaInfo); _metaInfoSupport = _metaEngine->hasFeature(MetaEngine::kSavesSupportMetaInfo);
_thumbnailSupport = _metaInfoSupport && (*_plugin)->hasFeature(MetaEngine::kSavesSupportThumbnail); _thumbnailSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportThumbnail);
_saveDateSupport = _metaInfoSupport && (*_plugin)->hasFeature(MetaEngine::kSavesSupportCreationDate); _saveDateSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportCreationDate);
_playTimeSupport = _metaInfoSupport && (*_plugin)->hasFeature(MetaEngine::kSavesSupportPlayTime); _playTimeSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportPlayTime);
_resultString.clear(); _resultString.clear();
reflowLayout(); reflowLayout();
updateSaveList(); updateSaveList();
int ret = Dialog::runModal(); return Dialog::runModal();
// Revert to the old active domain
ConfMan.setActiveDomain(oldDomain);
return ret;
} }
void SaveLoadChooserImpl::open() { void SaveLoadChooserImpl::open() {
@ -201,7 +181,7 @@ void SaveLoadChooserImpl::handleCommand(CommandSender *sender, uint32 cmd, uint3
MessageDialog alert(_("Do you really want to delete this savegame?"), MessageDialog alert(_("Do you really want to delete this savegame?"),
_("Delete"), _("Cancel")); _("Delete"), _("Cancel"));
if (alert.runModal() == GUI::kMessageOK) { if (alert.runModal() == GUI::kMessageOK) {
(*_plugin)->removeSaveState(_target.c_str(), _saveList[selItem].getSaveSlot()); _metaEngine->removeSaveState(_target.c_str(), _saveList[selItem].getSaveSlot());
setResult(-1); setResult(-1);
_list->setSelected(-1); _list->setSelected(-1);
@ -288,7 +268,7 @@ void SaveLoadChooserImpl::updateSelection(bool redraw) {
_playtime->setLabel(_("No playtime saved")); _playtime->setLabel(_("No playtime saved"));
if (selItem >= 0 && _metaInfoSupport) { if (selItem >= 0 && _metaInfoSupport) {
SaveStateDescriptor desc = (*_plugin)->querySaveMetaInfos(_target.c_str(), _saveList[selItem].getSaveSlot()); SaveStateDescriptor desc = _metaEngine->querySaveMetaInfos(_target.c_str(), _saveList[selItem].getSaveSlot());
isDeletable = desc.getDeletableFlag() && _delSupport; isDeletable = desc.getDeletableFlag() && _delSupport;
isWriteProtected = desc.getWriteProtectedFlag(); isWriteProtected = desc.getWriteProtectedFlag();
@ -359,7 +339,7 @@ void SaveLoadChooserImpl::updateSelection(bool redraw) {
} }
void SaveLoadChooserImpl::close() { void SaveLoadChooserImpl::close() {
_plugin = 0; _metaEngine = 0;
_target.clear(); _target.clear();
_saveList.clear(); _saveList.clear();
_list->setList(StringArray()); _list->setList(StringArray());
@ -368,7 +348,7 @@ void SaveLoadChooserImpl::close() {
} }
void SaveLoadChooserImpl::updateSaveList() { void SaveLoadChooserImpl::updateSaveList() {
_saveList = (*_plugin)->listSaves(_target.c_str()); _saveList = _metaEngine->listSaves(_target.c_str());
int curSlot = 0; int curSlot = 0;
int saveSlot = 0; int saveSlot = 0;
@ -410,7 +390,7 @@ void SaveLoadChooserImpl::updateSaveList() {
// Fill the rest of the save slots with empty saves // Fill the rest of the save slots with empty saves
int maximumSaveSlots = (*_plugin)->getMaximumSaveSlot(); int maximumSaveSlots = _metaEngine->getMaximumSaveSlot();
#ifdef __DS__ #ifdef __DS__
// Low memory on the DS means too many save slots are impractical, so limit // Low memory on the DS means too many save slots are impractical, so limit
@ -455,17 +435,32 @@ Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) con
} }
int SaveLoadChooser::runModalWithCurrentTarget() { int SaveLoadChooser::runModalWithCurrentTarget() {
if (_impl) if (!_impl)
return _impl->runModalWithCurrentTarget();
else
return -1; return -1;
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) { int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) {
if (_impl) if (!_impl)
return _impl->runModalWithPluginAndTarget(plugin, target);
else
return -1; return -1;
// Set up the game domain as newly active domain, so
// target specific savepath will be checked
String oldDomain = ConfMan.getActiveDomainName();
ConfMan.setActiveDomain(target);
int ret = _impl->run(target, &(**plugin));
// Revert to the old active domain
ConfMan.setActiveDomain(oldDomain);
return ret;
} }
Common::String SaveLoadChooser::getResultString() const { Common::String SaveLoadChooser::getResultString() const {