aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2012-09-26 16:10:35 +0200
committerJohannes Schickel2012-09-26 16:14:18 +0200
commit9942b5ab600f6b71b5d10921d11bf761f5eef298 (patch)
tree5445e85b82990d026861c12c411adc9d94adcf54
parent89abab97e3124fa25eb4c7d3e8b38501747a8d17 (diff)
downloadscummvm-rg350-9942b5ab600f6b71b5d10921d11bf761f5eef298.tar.gz
scummvm-rg350-9942b5ab600f6b71b5d10921d11bf761f5eef298.tar.bz2
scummvm-rg350-9942b5ab600f6b71b5d10921d11bf761f5eef298.zip
GUI: Support for page restoring for non-continuous save lists in the grid chooser.
-rw-r--r--gui/saveload-dialog.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp
index be6cefda26..df8dda7470 100644
--- a/gui/saveload-dialog.cpp
+++ b/gui/saveload-dialog.cpp
@@ -618,14 +618,22 @@ void SaveLoadChooserGrid::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;
+ uint bestMatch = 0;
+ uint diff = 0xFFFFFFFF;
+
+ // We look for the nearest available slot, since a slot might be missing
+ // due to the user deleting it via the list based chooser, by deleting
+ // it by hand, etc.
+ for (uint i = 0; i < listSize; ++i) {
+ uint curDiff = ABS(_saveList[i].getSaveSlot() - (int)lastPos);
+ if (curDiff < diff) {
+ diff = curDiff;
+ bestMatch = i;
+ }
}
+ _curPage = bestMatch / _entriesPerPage;
+
// Determine the next free save slot for save mode
if (_saveMode) {
int lastSlot = -1;
@@ -765,7 +773,7 @@ void SaveLoadChooserGrid::close() {
// 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);
+ ConfMan.setInt("gui_saveload_last_pos", !_saveList.empty() ? _saveList[_curPage * _entriesPerPage].getSaveSlot() : 0);
}
SaveLoadChooserDialog::close();