GUI: Clean up save load chooser selection code.

This commit is contained in:
Johannes Schickel 2012-07-01 16:07:48 +02:00
parent 236db5ed87
commit bd3d5fb8ff
3 changed files with 37 additions and 45 deletions

View file

@ -31,6 +31,22 @@
namespace GUI {
SaveLoadChooserType getRequestedSaveLoadDialog(const bool saveMode, const MetaEngine &metaEngine) {
const Common::String &userConfig = ConfMan.get("gui_saveload_chooser", Common::ConfigManager::kApplicationDomain);
if (!saveMode && g_gui.getWidth() >= 640 && g_gui.getHeight() >= 400
&& metaEngine.hasFeature(MetaEngine::kSavesSupportMetaInfo)
&& metaEngine.hasFeature(MetaEngine::kSavesSupportThumbnail)
&& userConfig.equalsIgnoreCase("grid")) {
// In case we are 640x400 or higher, this dialog is not in save mode,
// the user requested the grid dialog and the engines supports it we
// try to set it up.
return kSaveLoadDialogGrid;
} else {
// In all other cases we want to use the list dialog.
return kSaveLoadDialogList;
}
}
enum {
kListSwitchCmd = 'LIST',
kGridSwitchCmd = 'GRID'
@ -73,7 +89,7 @@ int SaveLoadChooserDialog::run(const Common::String &target, const MetaEngine *m
void SaveLoadChooserDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kListSwitchCmd:
setResult(kSwitchToList);
setResult(kSwitchSaveLoadDialog);
// We save the requested dialog type here to avoid the setting to be
// overwritten when our reflowLayout logic selects a different dialog
// type.
@ -82,7 +98,7 @@ void SaveLoadChooserDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd
break;
case kGridSwitchCmd:
setResult(kSwitchToGrid);
setResult(kSwitchSaveLoadDialog);
// See above.
ConfMan.set("gui_saveload_chooser", "grid", Common::ConfigManager::kApplicationDomain);
close();
@ -116,34 +132,11 @@ void SaveLoadChooserDialog::reflowLayout() {
addChooserButtons();
const SaveLoadChooserType currentType = getType();
SaveLoadChooserType requestedType;
const Common::String &userConfig = ConfMan.get("gui_saveload_chooser", Common::ConfigManager::kApplicationDomain);
if (!_saveMode && g_gui.getWidth() >= 640 && g_gui.getHeight() >= 400
&& _metaEngine->hasFeature(MetaEngine::kSavesSupportMetaInfo)
&& _metaEngine->hasFeature(MetaEngine::kSavesSupportThumbnail)
&& userConfig.equalsIgnoreCase("grid")) {
// In case we are 640x400 or higher, this dialog is not in save mode,
// the user requested the grid dialog and the engines supports it we
// try to set it up.
requestedType = kSaveLoadDialogGrid;
} else {
// In all other cases we want to use the list dialog.
requestedType = kSaveLoadDialogList;
}
const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(_saveMode, *_metaEngine);
// Change the dialog type if there is any need for it.
if (requestedType != currentType) {
switch (requestedType) {
case kSaveLoadDialogGrid:
setResult(kSwitchToGrid);
break;
case kSaveLoadDialogList:
setResult(kSwitchToList);
break;
}
setResult(kSwitchSaveLoadDialog);
close();
}

View file

@ -29,14 +29,15 @@
namespace GUI {
#define kSwitchToList -2
#define kSwitchToGrid -3
#define kSwitchSaveLoadDialog -2
enum SaveLoadChooserType {
kSaveLoadDialogList = 0,
kSaveLoadDialogGrid = 1
};
SaveLoadChooserType getRequestedSaveLoadDialog(const bool saveMode, const MetaEngine &metaEngine);
class SaveLoadChooserDialog : protected Dialog {
public:
SaveLoadChooserDialog(const Common::String &dialogName, const bool saveMode);

View file

@ -40,18 +40,20 @@ SaveLoadChooser::~SaveLoadChooser() {
}
void SaveLoadChooser::selectChooser(const MetaEngine &engine) {
delete _impl;
_impl = 0;
const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(_saveMode, engine);
if (!_impl || _impl->getType() != requestedType) {
delete _impl;
_impl = 0;
Common::String userConfig = ConfMan.get("gui_saveload_chooser", Common::ConfigManager::kApplicationDomain);
switch (requestedType) {
case kSaveLoadDialogGrid:
_impl = new LoadChooserThumbnailed(_title);
break;
if (!_saveMode && g_gui.getWidth() >= 640 && g_gui.getHeight() >= 400
&& engine.hasFeature(MetaEngine::kSavesSupportMetaInfo)
&& engine.hasFeature(MetaEngine::kSavesSupportThumbnail)
&& userConfig.equalsIgnoreCase("grid")) {
_impl = new LoadChooserThumbnailed(_title);
} else {
_impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode);
case kSaveLoadDialogList:
_impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode);
break;
}
}
}
@ -90,12 +92,8 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con
do {
ret = _impl->run(target, &(**plugin));
if (ret == kSwitchToList) {
delete _impl;
_impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode);
} else if (ret == kSwitchToGrid) {
delete _impl;
_impl = new LoadChooserThumbnailed(_title);
if (ret == kSwitchSaveLoadDialog) {
selectChooser(**plugin);
}
} while (ret < -1);