GUI: Clean up save load chooser selection code.
This commit is contained in:
parent
236db5ed87
commit
bd3d5fb8ff
3 changed files with 37 additions and 45 deletions
|
@ -31,6 +31,22 @@
|
||||||
|
|
||||||
namespace GUI {
|
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 {
|
enum {
|
||||||
kListSwitchCmd = 'LIST',
|
kListSwitchCmd = 'LIST',
|
||||||
kGridSwitchCmd = 'GRID'
|
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) {
|
void SaveLoadChooserDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case kListSwitchCmd:
|
case kListSwitchCmd:
|
||||||
setResult(kSwitchToList);
|
setResult(kSwitchSaveLoadDialog);
|
||||||
// We save the requested dialog type here to avoid the setting to be
|
// We save the requested dialog type here to avoid the setting to be
|
||||||
// overwritten when our reflowLayout logic selects a different dialog
|
// overwritten when our reflowLayout logic selects a different dialog
|
||||||
// type.
|
// type.
|
||||||
|
@ -82,7 +98,7 @@ void SaveLoadChooserDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kGridSwitchCmd:
|
case kGridSwitchCmd:
|
||||||
setResult(kSwitchToGrid);
|
setResult(kSwitchSaveLoadDialog);
|
||||||
// See above.
|
// See above.
|
||||||
ConfMan.set("gui_saveload_chooser", "grid", Common::ConfigManager::kApplicationDomain);
|
ConfMan.set("gui_saveload_chooser", "grid", Common::ConfigManager::kApplicationDomain);
|
||||||
close();
|
close();
|
||||||
|
@ -116,34 +132,11 @@ void SaveLoadChooserDialog::reflowLayout() {
|
||||||
addChooserButtons();
|
addChooserButtons();
|
||||||
|
|
||||||
const SaveLoadChooserType currentType = getType();
|
const SaveLoadChooserType currentType = getType();
|
||||||
SaveLoadChooserType requestedType;
|
const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(_saveMode, *_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.
|
|
||||||
requestedType = kSaveLoadDialogGrid;
|
|
||||||
} else {
|
|
||||||
// In all other cases we want to use the list dialog.
|
|
||||||
requestedType = kSaveLoadDialogList;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change the dialog type if there is any need for it.
|
// Change the dialog type if there is any need for it.
|
||||||
if (requestedType != currentType) {
|
if (requestedType != currentType) {
|
||||||
switch (requestedType) {
|
setResult(kSwitchSaveLoadDialog);
|
||||||
case kSaveLoadDialogGrid:
|
|
||||||
setResult(kSwitchToGrid);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kSaveLoadDialogList:
|
|
||||||
setResult(kSwitchToList);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,15 @@
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
#define kSwitchToList -2
|
#define kSwitchSaveLoadDialog -2
|
||||||
#define kSwitchToGrid -3
|
|
||||||
|
|
||||||
enum SaveLoadChooserType {
|
enum SaveLoadChooserType {
|
||||||
kSaveLoadDialogList = 0,
|
kSaveLoadDialogList = 0,
|
||||||
kSaveLoadDialogGrid = 1
|
kSaveLoadDialogGrid = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SaveLoadChooserType getRequestedSaveLoadDialog(const bool saveMode, const MetaEngine &metaEngine);
|
||||||
|
|
||||||
class SaveLoadChooserDialog : protected Dialog {
|
class SaveLoadChooserDialog : protected Dialog {
|
||||||
public:
|
public:
|
||||||
SaveLoadChooserDialog(const Common::String &dialogName, const bool saveMode);
|
SaveLoadChooserDialog(const Common::String &dialogName, const bool saveMode);
|
||||||
|
|
|
@ -40,18 +40,20 @@ SaveLoadChooser::~SaveLoadChooser() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveLoadChooser::selectChooser(const MetaEngine &engine) {
|
void SaveLoadChooser::selectChooser(const MetaEngine &engine) {
|
||||||
|
const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(_saveMode, engine);
|
||||||
|
if (!_impl || _impl->getType() != requestedType) {
|
||||||
delete _impl;
|
delete _impl;
|
||||||
_impl = 0;
|
_impl = 0;
|
||||||
|
|
||||||
Common::String userConfig = ConfMan.get("gui_saveload_chooser", Common::ConfigManager::kApplicationDomain);
|
switch (requestedType) {
|
||||||
|
case kSaveLoadDialogGrid:
|
||||||
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);
|
_impl = new LoadChooserThumbnailed(_title);
|
||||||
} else {
|
break;
|
||||||
|
|
||||||
|
case kSaveLoadDialogList:
|
||||||
_impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode);
|
_impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,12 +92,8 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con
|
||||||
do {
|
do {
|
||||||
ret = _impl->run(target, &(**plugin));
|
ret = _impl->run(target, &(**plugin));
|
||||||
|
|
||||||
if (ret == kSwitchToList) {
|
if (ret == kSwitchSaveLoadDialog) {
|
||||||
delete _impl;
|
selectChooser(**plugin);
|
||||||
_impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode);
|
|
||||||
} else if (ret == kSwitchToGrid) {
|
|
||||||
delete _impl;
|
|
||||||
_impl = new LoadChooserThumbnailed(_title);
|
|
||||||
}
|
}
|
||||||
} while (ret < -1);
|
} while (ret < -1);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue