From 154e9e8565c185047e78ea5a2e18c27e96f13f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sun, 6 Jul 2025 20:59:30 +0200 Subject: [PATCH] Remove favourite status as a sorting criterion in element searches It was added as one in c73dfe8ca0db, as the highest priority criterion too. Nobody remembers why and it doesn't make much sense, so out it goes. --- .../elementsearch/ElementSearchActivity.cpp | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/gui/elementsearch/ElementSearchActivity.cpp b/src/gui/elementsearch/ElementSearchActivity.cpp index 09be65d6d..a8060bc0a 100644 --- a/src/gui/elementsearch/ElementSearchActivity.cpp +++ b/src/gui/elementsearch/ElementSearchActivity.cpp @@ -14,7 +14,6 @@ #include "gui/game/Favorite.h" #include "gui/game/GameController.h" #include "gui/game/ToolButton.h" -#include "gui/game/Favorite.h" #include "graphics/Graphics.h" @@ -74,23 +73,16 @@ void ElementSearchActivity::searchTools(String query) struct Match { - int favouritePriority; // relevant by whether the tool is favourited int toolIndex; // relevance by position of tool in tools vector int haystackOrigin; // relevance by origin of haystack int needlePosition; // relevance by position of needle in haystack bool operator <(Match const &other) const { - return std::tie(favouritePriority, haystackOrigin, needlePosition, toolIndex) < std::tie(other.favouritePriority, other.haystackOrigin, other.needlePosition, other.toolIndex); + return std::tie(haystackOrigin, needlePosition, toolIndex) < std::tie(other.haystackOrigin, other.needlePosition, other.toolIndex); } }; - std::set favs; - for (auto fav : Favorite::Ref().GetFavoritesList()) - { - favs.insert(fav); - } - std::map indexToMatch; auto push = [ &indexToMatch ](Match match) { auto it = indexToMatch.find(match.toolIndex); @@ -104,18 +96,18 @@ void ElementSearchActivity::searchTools(String query) } }; - auto pushIfMatches = [ &queryLower, &push ](String infoLower, int toolIndex, int favouritePriority, int haystackRelevance) { + auto pushIfMatches = [ &queryLower, &push ](String infoLower, int toolIndex, int haystackRelevance) { if (infoLower == queryLower) { - push(Match{ favouritePriority, toolIndex, haystackRelevance, 0 }); + push(Match{ toolIndex, haystackRelevance, 0 }); } if (infoLower.BeginsWith(queryLower)) { - push(Match{ favouritePriority, toolIndex, haystackRelevance, 1 }); + push(Match{ toolIndex, haystackRelevance, 1 }); } if (infoLower.Contains(queryLower)) { - push(Match{ favouritePriority, toolIndex, haystackRelevance, 2 }); + push(Match{ toolIndex, haystackRelevance, 2 }); } }; @@ -130,13 +122,12 @@ void ElementSearchActivity::searchTools(String query) for (int toolIndex = 0; toolIndex < (int)tools.size(); ++toolIndex) { - int favouritePriority = favs.find(tools[toolIndex]->Identifier) != favs.end() ? 0 : 1; - pushIfMatches(tools[toolIndex]->Name.ToLower(), toolIndex, favouritePriority, 0); - pushIfMatches(tools[toolIndex]->Description.ToLower(), toolIndex, favouritePriority, 1); + pushIfMatches(tools[toolIndex]->Name.ToLower(), toolIndex, 0); + pushIfMatches(tools[toolIndex]->Description.ToLower(), toolIndex, 1); auto it = menudescriptionLower.find(tools[toolIndex]); if (it != menudescriptionLower.end()) { - pushIfMatches(it->second, toolIndex, favouritePriority, 2); + pushIfMatches(it->second, toolIndex, 2); } }