mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	search feature working
This commit is contained in:
		| @@ -43,6 +43,8 @@ AdventureMapShortcuts::AdventureMapShortcuts(AdventureMapInterface & owner) | ||||
| 	: owner(owner) | ||||
| 	, state(EAdventureState::NOT_INITIALIZED) | ||||
| 	, mapLevel(0) | ||||
| 	, searchLast(MapObjectID::NO_OBJ) | ||||
| 	, searchPos(0) | ||||
| {} | ||||
|  | ||||
| void AdventureMapShortcuts::setState(EAdventureState newState) | ||||
| @@ -462,6 +464,7 @@ void AdventureMapShortcuts::zoom( int distance) | ||||
|  | ||||
| void AdventureMapShortcuts::search() | ||||
| { | ||||
| 	// get all relevant objects | ||||
| 	std::vector<ObjectInstanceID> visitableObjInstances; | ||||
| 	int3 mapSizes = LOCPLINT->cb->getMapSize(); | ||||
| 	for(int x = 0; x < mapSizes.x; x++) | ||||
| @@ -486,26 +489,37 @@ void AdventureMapShortcuts::search() | ||||
| 		} | ||||
| 	); | ||||
|  | ||||
| 	// get pos of last selection | ||||
| 	int lastSel = 0; | ||||
| 	for(int i = 0; i < mapObjCountList.size(); i++) | ||||
| 		if(mapObjCountList[i].first == searchLast) | ||||
| 			lastSel = i; | ||||
|  | ||||
| 	// create texts | ||||
| 	std::vector<std::string> texts; | ||||
| 	for(auto & obj : mapObjCountList) | ||||
| 		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"), | ||||
| 	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; | ||||
|  | ||||
| 			// filter for matching objects | ||||
| 			std::vector<ObjectInstanceID> selVisitableObjInstances; | ||||
| 			for(auto & obj : visitableObjInstances) | ||||
| 										{ | ||||
| 											auto objInst = LOCPLINT->cb->getObjInstance(obj); | ||||
| 											if(selObj == objInst->getObjGroupIndex()) | ||||
| 				if(selObj == LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex()) | ||||
| 					selVisitableObjInstances.push_back(obj); | ||||
| 			 | ||||
| 			if(searchPos + 1 < selVisitableObjInstances.size() && searchLast == selObj) | ||||
| 				searchPos++; | ||||
| 			else | ||||
| 				searchPos = 0; | ||||
|  | ||||
| 			auto objInst = LOCPLINT->cb->getObjInstance(selVisitableObjInstances[searchPos]); | ||||
| 			owner.centerOnObject(objInst); | ||||
| 										} | ||||
| 											 | ||||
|  | ||||
| 									}, | ||||
| 									0); | ||||
| 			searchLast = objInst->getObjGroupIndex(); | ||||
| 		}, lastSel); | ||||
| } | ||||
|  | ||||
| void AdventureMapShortcuts::nextObject() | ||||
|   | ||||
| @@ -10,6 +10,8 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "../../lib/constants/EntityIdentifiers.h" | ||||
|  | ||||
| VCMI_LIB_NAMESPACE_BEGIN | ||||
| class Point; | ||||
| class Rect; | ||||
| @@ -33,6 +35,9 @@ class AdventureMapShortcuts | ||||
| 	EAdventureState state; | ||||
| 	int mapLevel; | ||||
|  | ||||
| 	MapObjectID searchLast; | ||||
| 	int searchPos; | ||||
| 	 | ||||
| 	void showOverview(); | ||||
| 	void worldViewBack(); | ||||
| 	void worldViewScale1x(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user