[Scummvm-cvs-logs] scummvm master -> 40fb004509620323a466ee1f49addc773094e21f

lordhoto lordhoto at gmail.com
Wed Sep 26 03:01:39 CEST 2012


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
66fb399227 GUI: Save/restore the last used page in the grid save/load dialog.
bc1743b225 GUI: Save/restore last scroll position in the list save/load dialog.
40fb004509 GUI: Fix maximum page number calculation in grid chooser.


Commit: 66fb399227acd92db3dc8d9ee193a41609cf3d39
    https://github.com/scummvm/scummvm/commit/66fb399227acd92db3dc8d9ee193a41609cf3d39
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2012-09-25T17:59:31-07:00

Commit Message:
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.

Changed paths:
    base/commandLine.cpp
    gui/saveload-dialog.cpp



diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index 5ad2331..44007c4 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -238,7 +238,7 @@ void registerDefaults() {
 	ConfMan.registerDefault("record_time_file_name", "record.time");
 
 	ConfMan.registerDefault("gui_saveload_chooser", "grid");
-
+	ConfMan.registerDefault("gui_saveload_last_pos", "0");
 }
 
 //
diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp
index 850dfcc..63d8d25 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;
 }
 


Commit: bc1743b225597715164e3d2701b2c4b5731415a4
    https://github.com/scummvm/scummvm/commit/bc1743b225597715164e3d2701b2c4b5731415a4
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2012-09-25T17:59:32-07:00

Commit Message:
GUI: Save/restore last scroll position in the list save/load dialog.

This should give a better user experience, since the user will not have to
scroll back to where he was when he used the dialog last.

Thanks to wjp for suggesting this.

Changed paths:
    gui/saveload-dialog.cpp
    gui/saveload-dialog.h
    gui/widgets/list.h



diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp
index 63d8d25..c8f7556 100644
--- a/gui/saveload-dialog.cpp
+++ b/gui/saveload-dialog.cpp
@@ -422,7 +422,28 @@ void SaveLoadChooserSimple::updateSelection(bool redraw) {
 	}
 }
 
+void SaveLoadChooserSimple::open() {
+	SaveLoadChooserDialog::open();
+
+	// Scroll the list to the last used entry.
+	_list->scrollTo(ConfMan.getInt("gui_saveload_last_pos"));
+}
+
 void SaveLoadChooserSimple::close() {
+	// Save the current scroll position/used entry.
+	const int result = getResult();
+	if (result >= 0) {
+		ConfMan.setInt("gui_saveload_last_pos", result);
+	} else {
+		// Use the current scroll position here.
+		// TODO: This means we canceled the dialog (or switch to the grid). Do
+		// we want to save this position here? Does the user want that?
+		// TODO: Do we want to save the current scroll position or the
+		// currently selected item here? The scroll position is what the user
+		// currently sees and seems to make more sense.
+		ConfMan.setInt("gui_saveload_last_pos", _list->getCurrentScrollPos());
+	}
+
 	_metaEngine = 0;
 	_target.clear();
 	_saveList.clear();
diff --git a/gui/saveload-dialog.h b/gui/saveload-dialog.h
index 9d0350d..6f7d95f 100644
--- a/gui/saveload-dialog.h
+++ b/gui/saveload-dialog.h
@@ -103,6 +103,7 @@ public:
 	virtual SaveLoadChooserType getType() const { return kSaveLoadDialogList; }
 #endif // !DISABLE_SAVELOADCHOOSER_GRID
 
+	virtual void open();
 	virtual void close();
 private:
 	virtual int runIntern();
diff --git a/gui/widgets/list.h b/gui/widgets/list.h
index 41fae37..47613b7 100644
--- a/gui/widgets/list.h
+++ b/gui/widgets/list.h
@@ -105,6 +105,7 @@ public:
 
 	void scrollTo(int item);
 	void scrollToEnd();
+	int getCurrentScrollPos() const { return _currentPos; }
 
 	void enableQuickSelect(bool enable) 		{ _quickSelect = enable; }
 	String getQuickSelectString() const 		{ return _quickSelectStr; }


Commit: 40fb004509620323a466ee1f49addc773094e21f
    https://github.com/scummvm/scummvm/commit/40fb004509620323a466ee1f49addc773094e21f
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2012-09-25T17:59:32-07:00

Commit Message:
GUI: Fix maximum page number calculation in grid chooser.

This avoids a off by one error in some cases.

Changed paths:
    gui/saveload-dialog.cpp



diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp
index c8f7556..cd0f96d 100644
--- a/gui/saveload-dialog.cpp
+++ b/gui/saveload-dialog.cpp
@@ -882,7 +882,7 @@ void SaveLoadChooserGrid::updateSaves() {
 		}
 	}
 
-	const uint numPages = (_entriesPerPage != 0) ? (_saveList.size() / _entriesPerPage + 1) : 1;
+	const uint numPages = (_entriesPerPage != 0 && !_saveList.empty()) ? ((_saveList.size() + _entriesPerPage - 1) / _entriesPerPage) : 1;
 	_pageDisplay->setLabel(Common::String::format("%u/%u", _curPage + 1, numPages));
 
 	if (_curPage > 0)






More information about the Scummvm-git-logs mailing list