Skip to content

Commit

Permalink
GUI: Automatically switch to list based save/load chooser when changi…
Browse files Browse the repository at this point in the history
…ng resolution below 640x400.
  • Loading branch information
Johannes Schickel committed Jul 1, 2012
1 parent 1c389e5 commit 236db5e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
41 changes: 40 additions & 1 deletion gui/saveload-dialog.cpp
Expand Up @@ -21,6 +21,7 @@

#include "gui/saveload-dialog.h"
#include "common/translation.h"
#include "common/config-manager.h"

#include "gui/message.h"
#include "gui/gui-manager.h"
Expand Down Expand Up @@ -73,11 +74,17 @@ void SaveLoadChooserDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd
switch (cmd) {
case kListSwitchCmd:
setResult(kSwitchToList);
// We save the requested dialog type here to avoid the setting to be
// overwritten when our reflowLayout logic selects a different dialog
// type.
ConfMan.set("gui_saveload_chooser", "list", Common::ConfigManager::kApplicationDomain);
close();
break;

case kGridSwitchCmd:
setResult(kSwitchToGrid);
// See above.
ConfMan.set("gui_saveload_chooser", "grid", Common::ConfigManager::kApplicationDomain);
close();
break;

Expand All @@ -101,13 +108,45 @@ void SaveLoadChooserDialog::addChooserButtons() {

_listButton = createSwitchButton("SaveLoadChooser.ListSwitch", "L", _("List view"), ThemeEngine::kImageList, kListSwitchCmd);
_gridButton = createSwitchButton("SaveLoadChooser.GridSwitch", "G", _("Grid view"), ThemeEngine::kImageGrid, kGridSwitchCmd);
if (!_metaInfoSupport || !_thumbnailSupport || _saveMode)
if (!_metaInfoSupport || !_thumbnailSupport || _saveMode || !(g_gui.getWidth() >= 640 && g_gui.getHeight() >= 400))
_gridButton->setEnabled(false);
}

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;
}

// 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;
}

close();
}

Dialog::reflowLayout();
}

Expand Down
11 changes: 11 additions & 0 deletions gui/saveload-dialog.h
Expand Up @@ -32,6 +32,11 @@ namespace GUI {
#define kSwitchToList -2
#define kSwitchToGrid -3

enum SaveLoadChooserType {
kSaveLoadDialogList = 0,
kSaveLoadDialogGrid = 1
};

class SaveLoadChooserDialog : protected Dialog {
public:
SaveLoadChooserDialog(const Common::String &dialogName, const bool saveMode);
Expand All @@ -43,6 +48,8 @@ class SaveLoadChooserDialog : protected Dialog {

virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);

virtual SaveLoadChooserType getType() const = 0;

int run(const Common::String &target, const MetaEngine *metaEngine);
virtual const Common::String &getResultString() const = 0;

Expand Down Expand Up @@ -77,6 +84,8 @@ class SaveLoadChooserSimple : public SaveLoadChooserDialog {

virtual void reflowLayout();

virtual SaveLoadChooserType getType() const { return kSaveLoadDialogList; }

virtual void close();
private:
virtual int runIntern();
Expand Down Expand Up @@ -109,6 +118,8 @@ class LoadChooserThumbnailed : public SaveLoadChooserDialog {

virtual void reflowLayout();

virtual SaveLoadChooserType getType() const { return kSaveLoadDialogGrid; }

virtual void close();
protected:
virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
Expand Down
2 changes: 0 additions & 2 deletions gui/saveload.cpp
Expand Up @@ -93,11 +93,9 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con
if (ret == kSwitchToList) {
delete _impl;
_impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode);
ConfMan.set("gui_saveload_chooser", "list", Common::ConfigManager::kApplicationDomain);
} else if (ret == kSwitchToGrid) {
delete _impl;
_impl = new LoadChooserThumbnailed(_title);
ConfMan.set("gui_saveload_chooser", "grid", Common::ConfigManager::kApplicationDomain);
}
} while (ret < -1);

Expand Down

0 comments on commit 236db5e

Please sign in to comment.