mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
search for texts
This commit is contained in:
@ -43,7 +43,7 @@ AdventureMapShortcuts::AdventureMapShortcuts(AdventureMapInterface & owner)
|
|||||||
: owner(owner)
|
: owner(owner)
|
||||||
, state(EAdventureState::NOT_INITIALIZED)
|
, state(EAdventureState::NOT_INITIALIZED)
|
||||||
, mapLevel(0)
|
, mapLevel(0)
|
||||||
, searchLast({MapObjectID::NO_OBJ, 0})
|
, searchLast("")
|
||||||
, searchPos(0)
|
, searchPos(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -475,41 +475,41 @@ void AdventureMapShortcuts::search()
|
|||||||
visitableObjInstances.push_back(obj->id);
|
visitableObjInstances.push_back(obj->id);
|
||||||
|
|
||||||
// count of elements for each group
|
// count of elements for each group
|
||||||
std::map<std::pair<MapObjectID, MapObjectSubID>, int> mapObjCount;
|
std::map<std::string, int> mapObjCount;
|
||||||
for(auto & obj : visitableObjInstances)
|
for(auto & obj : visitableObjInstances)
|
||||||
mapObjCount[{ LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex(), LOCPLINT->cb->getObjInstance(obj)->getObjTypeIndex() }]++;
|
mapObjCount[{ VLC->objtypeh->getObjectName(LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex(), LOCPLINT->cb->getObjInstance(obj)->getObjTypeIndex()) }]++;
|
||||||
|
|
||||||
// sort by name
|
// sort by name
|
||||||
std::vector<std::pair<std::pair<MapObjectID, MapObjectSubID>, int>> mapObjCountList;
|
std::vector<std::pair<std::string, int>> textCountList;
|
||||||
for (auto itr = mapObjCount.begin(); itr != mapObjCount.end(); ++itr)
|
for (auto itr = mapObjCount.begin(); itr != mapObjCount.end(); ++itr)
|
||||||
mapObjCountList.push_back(*itr);
|
textCountList.push_back(*itr);
|
||||||
std::sort(mapObjCountList.begin(), mapObjCountList.end(),
|
std::sort(textCountList.begin(), textCountList.end(),
|
||||||
[=](std::pair<std::pair<MapObjectID, MapObjectSubID>, int>& a, std::pair<std::pair<MapObjectID, MapObjectSubID>, int>& b)
|
[=](std::pair<std::string, int>& a, std::pair<std::string, int>& b)
|
||||||
{
|
{
|
||||||
return VLC->objtypeh->getObjectName(a.first.first, a.first.second) < VLC->objtypeh->getObjectName(b.first.first, b.first.second);
|
return a.first < b.first;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// get pos of last selection
|
// get pos of last selection
|
||||||
int lastSel = 0;
|
int lastSel = 0;
|
||||||
for(int i = 0; i < mapObjCountList.size(); i++)
|
for(int i = 0; i < textCountList.size(); i++)
|
||||||
if(mapObjCountList[i].first == searchLast)
|
if(textCountList[i].first == searchLast)
|
||||||
lastSel = i;
|
lastSel = i;
|
||||||
|
|
||||||
// create texts
|
// create texts
|
||||||
std::vector<std::string> texts;
|
std::vector<std::string> texts;
|
||||||
for(auto & obj : mapObjCountList)
|
for(auto & obj : textCountList)
|
||||||
texts.push_back(VLC->objtypeh->getObjectName(obj.first.first, obj.first.second) + " (" + std::to_string(obj.second) + ")");
|
texts.push_back(obj.first + " (" + 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)
|
[this, textCountList, visitableObjInstances](int index)
|
||||||
{
|
{
|
||||||
auto selObj = mapObjCountList[index].first;
|
auto selObj = textCountList[index].first;
|
||||||
|
|
||||||
// filter for matching objects
|
// filter for matching objects
|
||||||
std::vector<ObjectInstanceID> selVisitableObjInstances;
|
std::vector<ObjectInstanceID> selVisitableObjInstances;
|
||||||
for(auto & obj : visitableObjInstances)
|
for(auto & obj : visitableObjInstances)
|
||||||
if(selObj == std::pair<MapObjectID, MapObjectSubID>{ LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex(), LOCPLINT->cb->getObjInstance(obj)->getObjTypeIndex() })
|
if(selObj == VLC->objtypeh->getObjectName(LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex(), LOCPLINT->cb->getObjInstance(obj)->getObjTypeIndex()))
|
||||||
selVisitableObjInstances.push_back(obj);
|
selVisitableObjInstances.push_back(obj);
|
||||||
|
|
||||||
if(searchPos + 1 < selVisitableObjInstances.size() && searchLast == selObj)
|
if(searchPos + 1 < selVisitableObjInstances.size() && searchLast == selObj)
|
||||||
@ -519,7 +519,7 @@ void AdventureMapShortcuts::search()
|
|||||||
|
|
||||||
auto objInst = LOCPLINT->cb->getObjInstance(selVisitableObjInstances[searchPos]);
|
auto objInst = LOCPLINT->cb->getObjInstance(selVisitableObjInstances[searchPos]);
|
||||||
owner.centerOnObject(objInst);
|
owner.centerOnObject(objInst);
|
||||||
searchLast = { objInst->getObjGroupIndex(), objInst->getObjTypeIndex() };
|
searchLast = VLC->objtypeh->getObjectName(objInst->getObjGroupIndex(), objInst->getObjTypeIndex());
|
||||||
}, lastSel);
|
}, lastSel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class AdventureMapShortcuts
|
|||||||
EAdventureState state;
|
EAdventureState state;
|
||||||
int mapLevel;
|
int mapLevel;
|
||||||
|
|
||||||
std::pair<MapObjectID, MapObjectSubID> searchLast;
|
std::string searchLast;
|
||||||
int searchPos;
|
int searchPos;
|
||||||
|
|
||||||
void showOverview();
|
void showOverview();
|
||||||
|
@ -185,6 +185,9 @@ void CListBox::scrollTo(size_t which)
|
|||||||
//scroll down
|
//scroll down
|
||||||
else if (first + items.size() <= which && which < totalSize)
|
else if (first + items.size() <= which && which < totalSize)
|
||||||
moveToPos(which - items.size() + 1);
|
moveToPos(which - items.size() + 1);
|
||||||
|
|
||||||
|
if(slider)
|
||||||
|
slider->scrollTo(which);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CListBox::moveToPos(size_t which)
|
void CListBox::moveToPos(size_t which)
|
||||||
|
@ -1494,6 +1494,7 @@ CObjectListWindow::CObjectListWindow(const std::vector<int> & _items, std::share
|
|||||||
}
|
}
|
||||||
|
|
||||||
init(titleWidget_, _title, _descr);
|
init(titleWidget_, _title, _descr);
|
||||||
|
list->scrollTo(initialSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
CObjectListWindow::CObjectListWindow(const std::vector<std::string> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection, std::vector<std::shared_ptr<IImage>> images)
|
CObjectListWindow::CObjectListWindow(const std::vector<std::string> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection, std::vector<std::shared_ptr<IImage>> images)
|
||||||
@ -1509,6 +1510,7 @@ CObjectListWindow::CObjectListWindow(const std::vector<std::string> & _items, st
|
|||||||
items.push_back(std::make_pair(int(i), _items[i]));
|
items.push_back(std::make_pair(int(i), _items[i]));
|
||||||
|
|
||||||
init(titleWidget_, _title, _descr);
|
init(titleWidget_, _title, _descr);
|
||||||
|
list->scrollTo(initialSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CObjectListWindow::init(std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr)
|
void CObjectListWindow::init(std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr)
|
||||||
|
Reference in New Issue
Block a user