[Scummvm-git-logs] scummvm master -> da3c3d097c4a6e71a6385c8ad1c6736d6825c205

sev- noreply at scummvm.org
Thu Mar 28 12:47:05 UTC 2024


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

Summary:
da3c3d097c GUI: Fix selector position after removing a game.


Commit: da3c3d097c4a6e71a6385c8ad1c6736d6825c205
    https://github.com/scummvm/scummvm/commit/da3c3d097c4a6e71a6385c8ad1c6736d6825c205
Author: kunxl-gg (tiwari.25 at iitj.ac.in)
Date: 2024-03-28T13:47:02+01:00

Commit Message:
GUI: Fix selector position after removing a game.
Signed-off-by: kunxl-gg <tiwari.25 at iitj.ac.in>

Added algorithm for feature

Signed-off-by: kunxl-gg <tiwari.25 at iitj.ac.in>

Fix merge conflicts

Signed-off-by: kunxl-gg <tiwari.25 at iitj.ac.in>

Added conditional statement

Signed-off-by: kunxl-gg <tiwari.25 at iitj.ac.in>

Removed equality sign in getNextPos

Signed-off-by: kunxl-gg <tiwari.25 at iitj.ac.in>

Fix lint issues

Signed-off-by: kunxl-gg <tiwari.25 at iitj.ac.in>

Fix redundant variables

Signed-off-by: kunxl-gg <tiwari.25 at iitj.ac.in>

Removed redundant include

Signed-off-by: kunxl-gg <tiwari.25 at iitj.ac.in>

Fix lint issues

Signed-off-by: kunxl-gg <tiwari.25 at iitj.ac.in>

Fix lint issues

Signed-off-by: kunxl-gg <tiwari.25 at iitj.ac.in>

Changed paths:
    gui/launcher.cpp
    gui/launcher.h
    gui/widgets/grid.cpp
    gui/widgets/grid.h
    gui/widgets/groupedlist.cpp
    gui/widgets/groupedlist.h


diff --git a/gui/launcher.cpp b/gui/launcher.cpp
index fba7df8aba2..efe356b6343 100644
--- a/gui/launcher.cpp
+++ b/gui/launcher.cpp
@@ -449,6 +449,15 @@ void LauncherDialog::removeGame(int item) {
 	MessageDialog alert(_("Do you really want to remove this game configuration?"), _("Yes"), _("No"));
 
 	if (alert.runModal() == GUI::kMessageOK) {
+        int nextPos = -1;
+        if (_groupBy != kGroupByNone && getType() == kLauncherDisplayList) {
+            // Find the position of the next item in the sorted list.
+            nextPos = getNextPos(item);
+        } else if (_groupBy != kGroupByNone && getType() == kLauncherDisplayGrid) {
+            // Find the position of the next item in the sorted grid.
+            nextPos = getNextPos(item);
+		}
+
 		// Remove the currently selected game from the list
 		assert(item >= 0);
 		ConfMan.removeGameDomain(_domains[item]);
@@ -457,7 +466,7 @@ void LauncherDialog::removeGame(int item) {
 		ConfMan.flushToDisk();
 
 		// Update the ListWidget/GridWidget and force a redraw
-		updateListing();
+		updateListing(nextPos);
 		g_gui.scheduleTopDialogRedraw();
 	}
 }
@@ -981,7 +990,8 @@ public:
 	LauncherDisplayType getType() const override { return kLauncherDisplayList; }
 
 protected:
-	void updateListing() override;
+	void updateListing(int selPos = -1) override;
+	int getNextPos(int item) override;
 	void groupEntries(const Common::Array<LauncherEntry> &metadata);
 	void updateButtons() override;
 	void selectTarget(const Common::String &target) override;
@@ -1003,7 +1013,8 @@ public:
 	LauncherDisplayType getType() const override { return kLauncherDisplayGrid; }
 
 protected:
-	void updateListing() override;
+	void updateListing(int selPos = -1) override;
+	int getNextPos(int item) override;
 	void groupEntries(const Common::Array<LauncherEntry> &metadata);
 	void updateButtons() override;
 	void selectTarget(const Common::String &target) override;
@@ -1117,7 +1128,7 @@ void LauncherSimple::build() {
 	updateButtons();
 }
 
-void LauncherSimple::updateListing() {
+void LauncherSimple::updateListing(int selPos) {
 	Common::U32StringArray l;
 	ThemeEngine::FontColor color;
 	int numEntries = ConfMan.getInt("gui_list_max_scan_entries");
@@ -1156,7 +1167,9 @@ void LauncherSimple::updateListing() {
 
 	groupEntries(domainList);
 
-	if (oldSel < (int)l.size() && oldSel >= 0)
+	if (_groupBy != kGroupByNone && selPos != -1) {
+		_list->setSelected(_list->getNewSel(selPos));
+	} else if (oldSel < (int)l.size() && oldSel >= 0)
 		_list->setSelected(oldSel);	// Restore the old selection
 	else if (oldSel != -1)
 		// Select the last entry if the list has been reduced
@@ -1171,6 +1184,10 @@ void LauncherSimple::updateListing() {
 	_list->loadClosedGroups(Common::U32String(groupingModes[_groupBy].name));
 }
 
+int LauncherSimple::getNextPos(int item) {
+	return _list->getNextPos(item);
+}
+
 void LauncherSimple::groupEntries(const Common::Array<LauncherEntry> &metadata) {
 	Common::U32StringArray attrs;
 	Common::StringMap metadataNames;
@@ -1553,7 +1570,7 @@ void LauncherGrid::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
 	}
 }
 
-void LauncherGrid::updateListing() {
+void LauncherGrid::updateListing(int selPos) {
 	// Retrieve a list of all games defined in the config file
 	_domains.clear();
 	const Common::ConfigManager::DomainMap &domains = ConfMan.getGameDomains();
@@ -1586,7 +1603,9 @@ void LauncherGrid::updateListing() {
 	_grid->setEntryList(&gridList);
 	groupEntries(domainList);
 
-	if (oldSel < (int)gridList.size() && oldSel >= 0)
+	if (_groupBy != kGroupByNone && selPos != -1) {
+		_grid->setSelected(_grid->getNewSel(selPos));
+	} else if (oldSel < (int)gridList.size() && oldSel >= 0)
 		_grid->setSelected(oldSel);	// Restore the old selection
 	else if (oldSel != -1)
 		// Select the last entry if the list has been reduced
@@ -1596,6 +1615,10 @@ void LauncherGrid::updateListing() {
 	_grid->loadClosedGroups(Common::U32String(groupingModes[_groupBy].name));
 }
 
+int LauncherGrid::getNextPos(int oldSel) {
+    return _grid->getNextPos(oldSel);
+}
+
 void LauncherGrid::updateButtons() {
 	bool enable = (_grid->getSelected() >= 0);
 
diff --git a/gui/launcher.h b/gui/launcher.h
index 0b0c4442e96..c0431d7167d 100644
--- a/gui/launcher.h
+++ b/gui/launcher.h
@@ -164,7 +164,9 @@ protected:
 	 * Fill the list widget with all currently configured targets, and trigger
 	 * a redraw.
 	 */
-	virtual void updateListing() = 0;
+	virtual void updateListing(int selPos = -1) = 0;
+
+	virtual int getNextPos(int item) = 0;
 
 	virtual void updateButtons() = 0;
 
diff --git a/gui/widgets/grid.cpp b/gui/widgets/grid.cpp
index 156a6900a8b..e1f2a517d7c 100644
--- a/gui/widgets/grid.cpp
+++ b/gui/widgets/grid.cpp
@@ -860,6 +860,42 @@ void GridWidget::assignEntriesToItems() {
 	}
 }
 
+int GridWidget::getNextPos(int oldSel) {
+    int pos = 0;
+
+    // Find the next item in the grid
+    for (uint i = 0; i < _sortedEntryList.size(); i++) {
+        if (_sortedEntryList[i]->entryID == oldSel) {
+            return pos;
+        } else if (!_sortedEntryList[i]->isHeader) {
+            pos++;
+        }
+    }
+
+    return -1;
+}
+
+int GridWidget::getNewSel(int index) {
+    if (_sortedEntryList.size() == 0) {
+        return -1;
+    }
+
+    // Find the index-th item in the grid
+    for (int i = 0; i < _sortedEntryList.size(); i++) {
+        if (index == 0 && _sortedEntryList[i]->isHeader == 0) {
+            return _sortedEntryList[i]->entryID;
+        } else if (_sortedEntryList[i]->isHeader == 0) {
+            index--;
+        }
+    }
+
+    if (index == 0) {
+        return _sortedEntryList[_sortedEntryList.size() - 1]->entryID;
+    } else {
+        return -1;
+    }
+}
+
 void GridWidget::handleMouseWheel(int x, int y, int direction) {
 	_scrollBar->handleMouseWheel(x, y, direction);
 	_scrollPos = _scrollBar->_currentPos;
diff --git a/gui/widgets/grid.h b/gui/widgets/grid.h
index 79ee987b2df..121555db748 100644
--- a/gui/widgets/grid.h
+++ b/gui/widgets/grid.h
@@ -206,6 +206,8 @@ public:
 	void scrollToEntry(int id, bool forceToTop);
 	void assignEntriesToItems();
 
+	int getNextPos(int oldSel);
+    int getNewSel(int index);
 	int getScrollPos() const { return _scrollPos; }
 	int getSelected() const { return ((_selectedEntry == nullptr) ? -1 : _selectedEntry->entryID); }
 	int getThumbnailHeight() const { return _thumbnailHeight; }
diff --git a/gui/widgets/groupedlist.cpp b/gui/widgets/groupedlist.cpp
index 4248ec8f5b4..fdb3c837131 100644
--- a/gui/widgets/groupedlist.cpp
+++ b/gui/widgets/groupedlist.cpp
@@ -294,6 +294,44 @@ void GroupedListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32
 	}
 }
 
+int GroupedListWidget::getNextPos(int oldSel) {
+    int pos = 0;
+
+    // Find the position of the new selection in the list. 
+    for (int i = 0; i < _listIndex.size(); i++) {
+        if (_listIndex[i] == oldSel) {
+            return pos;
+        } else if (_listIndex[i] > 0) {
+            pos++;
+        }
+    }
+    
+    return -1;
+}
+
+int GroupedListWidget::getNewSel(int index) {   
+    // If the list is empty, return -1
+    if (_listIndex.size() == 1){
+        return -1;
+    }
+
+    // Find the index-th item in the list
+    for (int i = 0; i < _listIndex.size(); i++) {
+        if (index == 0 && _listIndex[i] >= 0) {
+            return _listIndex[i];
+        } else if (_listIndex[i] >= 0) {
+            index--;
+        }
+    }
+
+    // If we are at the end of the list, return the last item.
+    if (index == 0) {
+        return _listIndex[_listIndex.size() - 1];
+    } else {
+        return -1;
+    }
+}
+
 void GroupedListWidget::toggleGroup(int groupID) {
 	_groupExpanded[groupID] = !_groupExpanded[groupID];
 	sortGroups();
diff --git a/gui/widgets/groupedlist.h b/gui/widgets/groupedlist.h
index c4377561c76..4cc97368c48 100644
--- a/gui/widgets/groupedlist.h
+++ b/gui/widgets/groupedlist.h
@@ -67,6 +67,9 @@ public:
 
 	void setGroupsVisibility(bool val) { _groupsVisible = val; }
 
+	int getNextPos(int oldSel);
+	int getNewSel(int index);
+
 	void startEditMode() override { error("Edit mode is not supported for Grouped Lists"); }
 
 protected:




More information about the Scummvm-git-logs mailing list