diff options
author | Johannes Schickel | 2012-09-26 02:11:39 +0200 |
---|---|---|
committer | Johannes Schickel | 2012-09-26 02:59:31 +0200 |
commit | 66fb399227acd92db3dc8d9ee193a41609cf3d39 (patch) | |
tree | ecf3e3a902fed90f222f2f76812780da58df2614 /gui | |
parent | be9c9e59b75a5a341eec0bdb6812ae3e3c4c338b (diff) | |
download | scummvm-rg350-66fb399227acd92db3dc8d9ee193a41609cf3d39.tar.gz scummvm-rg350-66fb399227acd92db3dc8d9ee193a41609cf3d39.tar.bz2 scummvm-rg350-66fb399227acd92db3dc8d9ee193a41609cf3d39.zip |
GUI: Save/restore the last used page in the grid save/load dialog.
This allows opening the dialog on (nearly) the same page again as when it was
closed. Sadly due to the different number of entries in the save and load
version this is not always exactly the same page as before. Same goes for
resolution changes.
Thanks to wjp for suggesting this.
Diffstat (limited to 'gui')
-rw-r--r-- | gui/saveload-dialog.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp index 850dfcc78f..63d8d25fe0 100644 --- a/gui/saveload-dialog.cpp +++ b/gui/saveload-dialog.cpp @@ -590,10 +590,21 @@ void SaveLoadChooserGrid::handleMouseWheel(int x, int y, int direction) { void SaveLoadChooserGrid::open() { SaveLoadChooserDialog::open(); - _curPage = 0; _saveList = _metaEngine->listSaves(_target.c_str()); _resultString.clear(); + // Load information to restore the last page the user had open. + assert(_entriesPerPage != 0); + const uint lastPos = ConfMan.getInt("gui_saveload_last_pos"); + const uint listSize = _saveList.size(); + if (lastPos < listSize) { + _curPage = lastPos / _entriesPerPage; + } else if (listSize) { + _curPage = (_saveList.size() - 1) / _entriesPerPage; + } else { + _curPage = 0; + } + // Determine the next free save slot for save mode if (_saveMode) { int lastSlot = -1; @@ -718,6 +729,24 @@ void SaveLoadChooserGrid::reflowLayout() { } void SaveLoadChooserGrid::close() { + // Save the current page. + const int result = getResult(); + if (result >= 0 && result != _nextFreeSaveSlot) { + // If the user selected a slot we use that one. We ignore new slots + // here, since otherwise the dialog would reset to page 0 when the + // user cancels the savename dialog. + ConfMan.setInt("gui_saveload_last_pos", result); + } else { + // Otherwise save the first entry on the current page. + // This is less precise than the solution above, since the number of + // entries shown differs between save and load version of the dialog, + // thus it might wrap to a different page than expected. + // Similar things happen on resolution changes. + // TODO: Should we ignore this here? Is the user likely to be + // interested in having this page restored when he canceled? + ConfMan.setInt("gui_saveload_last_pos", _curPage * _entriesPerPage); + } + SaveLoadChooserDialog::close(); hideButtons(); } @@ -737,6 +766,12 @@ int SaveLoadChooserGrid::runIntern() { slot = runModal(); } while (_saveMode && slot >= 0 && !selectDescription()); + // Special case for new save games. We need to handle this here, since + // we cannot handle it in close() without problems. + if (slot == _nextFreeSaveSlot) { + ConfMan.setInt("gui_saveload_last_pos", slot); + } + return slot; } |