From 5ea9063a3b5d6948e8c37c0448298e9d43d4fa73 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Tue, 1 Oct 2024 19:47:10 +0200 Subject: [PATCH] search with CObjectListWindow --- Mods/vcmi/config/vcmi/english.json | 2 ++ Mods/vcmi/config/vcmi/german.json | 2 ++ client/adventureMap/AdventureMapShortcuts.cpp | 28 +++++++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index b62ee25d2..032f6ac2e 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -13,6 +13,8 @@ "vcmi.adventureMap.monsterThreat.levels.10" : "Deadly", "vcmi.adventureMap.monsterThreat.levels.11" : "Impossible", "vcmi.adventureMap.monsterLevel" : "\n\nLevel %LEVEL %TOWN unit", + "vcmi.adventureMap.search.hover" : "Search map object", + "vcmi.adventureMap.search.help" : "Select object to search on map.", "vcmi.adventureMap.confirmRestartGame" : "Are you sure you want to restart the game?", "vcmi.adventureMap.noTownWithMarket" : "There are no available marketplaces!", diff --git a/Mods/vcmi/config/vcmi/german.json b/Mods/vcmi/config/vcmi/german.json index efe786220..0ca8f9748 100644 --- a/Mods/vcmi/config/vcmi/german.json +++ b/Mods/vcmi/config/vcmi/german.json @@ -13,6 +13,8 @@ "vcmi.adventureMap.monsterThreat.levels.10" : "Tödlich", "vcmi.adventureMap.monsterThreat.levels.11" : "Unmöglich", "vcmi.adventureMap.monsterLevel" : "\n\nStufe %LEVEL %TOWN-Einheit", + "vcmi.adventureMap.search.hover" : "Suche Kartenobjekt", + "vcmi.adventureMap.search.help" : "Wähle Objekt das gesucht werden soll.", "vcmi.adventureMap.confirmRestartGame" : "Seid Ihr sicher, dass Ihr das Spiel neu starten wollt?", "vcmi.adventureMap.noTownWithMarket" : "Kein Marktplatz verfügbar!", diff --git a/client/adventureMap/AdventureMapShortcuts.cpp b/client/adventureMap/AdventureMapShortcuts.cpp index 9497bf1df..0980e6634 100644 --- a/client/adventureMap/AdventureMapShortcuts.cpp +++ b/client/adventureMap/AdventureMapShortcuts.cpp @@ -24,6 +24,7 @@ #include "../windows/CKingdomInterface.h" #include "../windows/CSpellWindow.h" #include "../windows/CMarketWindow.h" +#include "../windows/GUIClasses.h" #include "../windows/settings/SettingsMainWindow.h" #include "AdventureMapInterface.h" #include "AdventureOptions.h" @@ -461,8 +462,6 @@ void AdventureMapShortcuts::zoom( int distance) void AdventureMapShortcuts::search() { - LOCPLINT->showInfoDialog("search"); - std::vector visitableObjInstances; int3 mapSizes = LOCPLINT->cb->getMapSize(); for(int x = 0; x < mapSizes.x; x++) @@ -477,19 +476,36 @@ void AdventureMapShortcuts::search() mapObjCount[LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex()]++; // sort by name - std::vector> mapObjCountList; + std::vector> mapObjCountList; for (auto itr = mapObjCount.begin(); itr != mapObjCount.end(); ++itr) mapObjCountList.push_back(*itr); std::sort(mapObjCountList.begin(), mapObjCountList.end(), - [=](std::pair& a, std::pair& b) + [=](std::pair& a, std::pair& b) { return VLC->objtypeh->getObjectName(a.first, 0) < VLC->objtypeh->getObjectName(b.first, 0); } ); - //TODO show table as popup + std::vector texts; for(auto & obj : mapObjCountList) - std::cout << VLC->objtypeh->getObjectName(obj.first, 0) << " " << obj.second << "\n"; + texts.push_back(VLC->objtypeh->getObjectName(obj.first, 0) + " (" + std::to_string(obj.second) + ")"); + + GH.windows().createAndPushWindow(texts, nullptr, + CGI->generaltexth->translate("vcmi.adventureMap.search.hover"), + CGI->generaltexth->translate("vcmi.adventureMap.search.help"), + [this, mapObjCountList, visitableObjInstances](int index) + { + auto selObj = mapObjCountList[index].first; + for(auto & obj : visitableObjInstances) + { + auto objInst = LOCPLINT->cb->getObjInstance(obj); + if(selObj == objInst->getObjGroupIndex()) + owner.centerOnObject(objInst); + } + + + }, + 0); } void AdventureMapShortcuts::nextObject()