mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	search with CObjectListWindow
This commit is contained in:
		| @@ -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!", | ||||
|   | ||||
| @@ -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!", | ||||
|   | ||||
| @@ -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<ObjectInstanceID> 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<std::pair<int, int>> mapObjCountList; | ||||
| 	std::vector<std::pair<MapObjectID, int>> mapObjCountList; | ||||
| 	for (auto itr = mapObjCount.begin(); itr != mapObjCount.end(); ++itr) | ||||
| 		mapObjCountList.push_back(*itr); | ||||
| 	std::sort(mapObjCountList.begin(), mapObjCountList.end(), | ||||
| 		[=](std::pair<int, int>& a, std::pair<int, int>& b) | ||||
| 		[=](std::pair<MapObjectID, int>& a, std::pair<MapObjectID, int>& b) | ||||
| 		{ | ||||
| 			return VLC->objtypeh->getObjectName(a.first, 0) < VLC->objtypeh->getObjectName(b.first, 0); | ||||
| 		} | ||||
| 	); | ||||
|  | ||||
| 	//TODO show table as popup | ||||
| 	std::vector<std::string> 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<CObjectListWindow>(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() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user