Selaa lähdekoodia

search basic implementation

Laserlicht 1 vuosi sitten
vanhempi
sitoutus
d04f369d85

+ 36 - 1
client/adventureMap/AdventureMapShortcuts.cpp

@@ -36,6 +36,7 @@
 #include "../../lib/mapObjects/CGTownInstance.h"
 #include "../../lib/mapping/CMap.h"
 #include "../../lib/pathfinder/CGPathNode.h"
+#include "../../lib/mapObjectConstructors/CObjectClassesHandler.h"
 
 AdventureMapShortcuts::AdventureMapShortcuts(AdventureMapInterface & owner)
 	: owner(owner)
@@ -109,7 +110,8 @@ std::vector<AdventureMapShortcutState> AdventureMapShortcuts::getShortcuts()
 		{ EShortcut::ADVENTURE_MOVE_HERO_EE,     optionHeroSelected(),   [this]() { this->moveHeroDirectional({+1,  0}); } },
 		{ EShortcut::ADVENTURE_MOVE_HERO_NW,     optionHeroSelected(),   [this]() { this->moveHeroDirectional({-1, -1}); } },
 		{ EShortcut::ADVENTURE_MOVE_HERO_NN,     optionHeroSelected(),   [this]() { this->moveHeroDirectional({ 0, -1}); } },
-		{ EShortcut::ADVENTURE_MOVE_HERO_NE,     optionHeroSelected(),   [this]() { this->moveHeroDirectional({+1, -1}); } }
+		{ EShortcut::ADVENTURE_MOVE_HERO_NE,     optionHeroSelected(),   [this]() { this->moveHeroDirectional({+1, -1}); } },
+		{ EShortcut::ADVENTURE_SEARCH,           optionSidePanelActive(),[this]() { this->search(); } }
 	};
 	return result;
 }
@@ -457,6 +459,39 @@ void AdventureMapShortcuts::zoom( int distance)
 	owner.hotkeyZoom(distance, false);
 }
 
+void AdventureMapShortcuts::search()
+{
+	LOCPLINT->showInfoDialog("search");
+
+	std::vector<ObjectInstanceID> visitableObjInstances;
+	int3 mapSizes = LOCPLINT->cb->getMapSize();
+	for(int x = 0; x < mapSizes.x; x++)
+		for(int y = 0; y < mapSizes.y; y++)
+			for(int z = 0; z < mapSizes.z; z++)
+				for(auto & obj : LOCPLINT->cb->getVisitableObjs(int3(x, y, z), false))
+					visitableObjInstances.push_back(obj->id);
+
+	// count of elements for each group
+	std::map<MapObjectID, int> mapObjCount;
+	for(auto & obj : visitableObjInstances)
+		mapObjCount[LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex()]++;
+
+	// sort by name
+	std::vector<std::pair<int, 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)
+		{
+			return VLC->objtypeh->getObjectName(a.first, 0) < VLC->objtypeh->getObjectName(b.first, 0);
+		}
+	);
+
+	//TODO show table as popup
+	for(auto & obj : mapObjCountList)
+		std::cout << VLC->objtypeh->getObjectName(obj.first, 0) << "   " << obj.second << "\n";
+}
+
 void AdventureMapShortcuts::nextObject()
 {
 	const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();

+ 1 - 0
client/adventureMap/AdventureMapShortcuts.h

@@ -71,6 +71,7 @@ class AdventureMapShortcuts
 	void nextTown();
 	void nextObject();
 	void zoom( int distance);
+	void search();
 	void moveHeroDirectional(const Point & direction);
 
 public:

+ 1 - 0
client/gui/Shortcut.h

@@ -161,6 +161,7 @@ enum class EShortcut
 	ADVENTURE_RESTART_GAME,
 	ADVENTURE_TO_MAIN_MENU,
 	ADVENTURE_QUIT_GAME,
+	ADVENTURE_SEARCH,
 
 	// Move hero one tile in specified direction. Bound to cursors & numpad buttons
 	ADVENTURE_MOVE_HERO_SW,

+ 1 - 0
client/gui/ShortcutHandler.cpp

@@ -209,6 +209,7 @@ EShortcut ShortcutHandler::findShortcut(const std::string & identifier ) const
 		{"adventureZoomIn",          EShortcut::ADVENTURE_ZOOM_IN         },
 		{"adventureZoomOut",         EShortcut::ADVENTURE_ZOOM_OUT        },
 		{"adventureZoomReset",       EShortcut::ADVENTURE_ZOOM_RESET      },
+		{"adventureSearch",          EShortcut::ADVENTURE_SEARCH          },
 		{"battleToggleHeroesStats",  EShortcut::BATTLE_TOGGLE_HEROES_STATS},
 		{"battleToggleQueue",        EShortcut::BATTLE_TOGGLE_QUEUE       },
 		{"battleUseCreatureSpell",   EShortcut::BATTLE_USE_CREATURE_SPELL },

+ 1 - 0
config/shortcutsConfig.json

@@ -56,6 +56,7 @@
 		"adventureZoomIn":          "Keypad +",
 		"adventureZoomOut":         "Keypad -",
 		"adventureZoomReset":       "Backspace",
+		"adventureSearch":          "Ctrl+F",
 		"battleAutocombat":         "A",
 		"battleAutocombatEnd":      "Q",
 		"battleCastSpell":          "C",