1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00

search feature working

This commit is contained in:
Laserlicht 2024-10-01 20:20:19 +02:00
parent 5ea9063a3b
commit bd58caac13
2 changed files with 34 additions and 15 deletions

View File

@ -43,6 +43,8 @@ AdventureMapShortcuts::AdventureMapShortcuts(AdventureMapInterface & owner)
: owner(owner) : owner(owner)
, state(EAdventureState::NOT_INITIALIZED) , state(EAdventureState::NOT_INITIALIZED)
, mapLevel(0) , mapLevel(0)
, searchLast(MapObjectID::NO_OBJ)
, searchPos(0)
{} {}
void AdventureMapShortcuts::setState(EAdventureState newState) void AdventureMapShortcuts::setState(EAdventureState newState)
@ -462,6 +464,7 @@ void AdventureMapShortcuts::zoom( int distance)
void AdventureMapShortcuts::search() void AdventureMapShortcuts::search()
{ {
// get all relevant objects
std::vector<ObjectInstanceID> visitableObjInstances; std::vector<ObjectInstanceID> visitableObjInstances;
int3 mapSizes = LOCPLINT->cb->getMapSize(); int3 mapSizes = LOCPLINT->cb->getMapSize();
for(int x = 0; x < mapSizes.x; x++) 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; std::vector<std::string> texts;
for(auto & obj : mapObjCountList) for(auto & obj : mapObjCountList)
texts.push_back(VLC->objtypeh->getObjectName(obj.first, 0) + " (" + std::to_string(obj.second) + ")"); texts.push_back(VLC->objtypeh->getObjectName(obj.first, 0) + " (" + std::to_string(obj.second) + ")");
GH.windows().createAndPushWindow<CObjectListWindow>(texts, nullptr, GH.windows().createAndPushWindow<CObjectListWindow>(texts, nullptr, CGI->generaltexth->translate("vcmi.adventureMap.search.hover"), CGI->generaltexth->translate("vcmi.adventureMap.search.help"),
CGI->generaltexth->translate("vcmi.adventureMap.search.hover"), [this, mapObjCountList, visitableObjInstances](int index)
CGI->generaltexth->translate("vcmi.adventureMap.search.help"), {
[this, mapObjCountList, visitableObjInstances](int index) auto selObj = mapObjCountList[index].first;
{
auto selObj = mapObjCountList[index].first;
for(auto & obj : visitableObjInstances)
{
auto objInst = LOCPLINT->cb->getObjInstance(obj);
if(selObj == objInst->getObjGroupIndex())
owner.centerOnObject(objInst);
}
}, // filter for matching objects
0); std::vector<ObjectInstanceID> selVisitableObjInstances;
for(auto & obj : visitableObjInstances)
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);
searchLast = objInst->getObjGroupIndex();
}, lastSel);
} }
void AdventureMapShortcuts::nextObject() void AdventureMapShortcuts::nextObject()

View File

@ -10,6 +10,8 @@
#pragma once #pragma once
#include "../../lib/constants/EntityIdentifiers.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class Point; class Point;
class Rect; class Rect;
@ -33,6 +35,9 @@ class AdventureMapShortcuts
EAdventureState state; EAdventureState state;
int mapLevel; int mapLevel;
MapObjectID searchLast;
int searchPos;
void showOverview(); void showOverview();
void worldViewBack(); void worldViewBack();
void worldViewScale1x(); void worldViewScale1x();