Skip to content

Commit

Permalink
Search unique id, action id, containers or writable items on selected…
Browse files Browse the repository at this point in the history
… area.
  • Loading branch information
Mignari committed Oct 23, 2016
1 parent 335e750 commit 61b58ae
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 126 deletions.
22 changes: 15 additions & 7 deletions data/menubar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@
<separator/>
<item name="Find $Item..." hotkey="Ctrl+F" action="FIND_ITEM" help="Find all instances of an item type the map."/>
<item name="R$eplace Item..." hotkey="Ctrl+Shift+F" action="REPLACE_ITEM" help="Replaces all occurances of one item with another."/>
<menu name="$Find">
<item name="Find $Everything" action="SEARCH_EVERYTHING" help="Find all unique/action/text/container items."/>
<menu name="$Find on Map">
<item name="Find $Everything" action="SEARCH_ON_MAP_EVERYTHING" help="Find all unique/action/text/container items."/>
<separator/>
<item name="Find $Unique" action="SEARCH_UNIQUE" help="Find all items with an unique ID."/>
<item name="Find $Action" action="SEARCH_ACTION" help="Find all items with an action ID."/>
<item name="Find $Container" action="SEARCH_CONTAINER" help="Find all containers."/>
<item name="Find $Writeable" action="SEARCH_WRITEABLE" help="Find all writeable items."/>
<item name="Find $Unique" action="SEARCH_ON_MAP_UNIQUE" help="Find all items with an unique ID on map."/>
<item name="Find $Action" action="SEARCH_ON_MAP_ACTION" help="Find all items with an action ID on map."/>
<item name="Find $Container" action="SEARCH_ON_MAP_CONTAINER" help="Find all containers on map."/>
<item name="Find $Writeable" action="SEARCH_ON_MAP_WRITEABLE" help="Find all writeable items on map."/>
</menu>
<menu name="Find on Se$lected Area">
<item name="Find $Everything" action="SEARCH_ON_SELECTION_EVERYTHING" help="Find all unique/action/text/container items."/>
<separator/>
<item name="Find $Unique" action="SEARCH_ON_SELECTION_UNIQUE" help="Find all items with an unique ID on selected area."/>
<item name="Find $Action" action="SEARCH_ON_SELECTION_ACTION" help="Find all items with an action ID on selected area."/>
<item name="Find $Container" action="SEARCH_ON_SELECTION_CONTAINER" help="Find all containers on selected area."/>
<item name="Find $Writeable" action="SEARCH_ON_SELECTION_WRITEABLE" help="Find all writeable items on selected area."/>
</menu>
<separator/>
<menu name="$Selection">
Expand All @@ -62,7 +70,7 @@
<item name="Clear $Modified State" action="CLEAR_MODIFIED_STATE" help="Clears the modified state from all tiles."/>
</menu>
<separator/>
<item name="$Go To Previous Position" hotkey="P" action="GOTO_PREVIOUS_POSITION" help="Go to the previous screen center position."/>
<item name="Go To P$revious Position" hotkey="P" action="GOTO_PREVIOUS_POSITION" help="Go to the previous screen center position."/>
<item name="$Go To Position..." hotkey="Ctrl+G" action="GOTO_POSITION" help="Go to a specific XYZ position."/>
<item name="$Jump to Brush..." hotkey="J" action="JUMP_TO_BRUSH" help="Jump to a brush."/>
<item name="Jump to $Item..." hotkey="Ctrl+J" action="JUMP_TO_ITEM_BRUSH" help="Jump to an item brush (RAW palette)."/>
Expand Down
191 changes: 87 additions & 104 deletions source/main_menubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,16 @@ MainMenuBar::MainMenuBar(MainFrame *frame) : frame(frame)

MAKE_ACTION(FIND_ITEM, wxITEM_NORMAL, OnSearchForItem);
MAKE_ACTION(REPLACE_ITEM, wxITEM_NORMAL, OnReplaceItem);
MAKE_ACTION(SEARCH_EVERYTHING, wxITEM_NORMAL, OnSearchForStuff);
MAKE_ACTION(SEARCH_UNIQUE, wxITEM_NORMAL, OnSearchForUnique);
MAKE_ACTION(SEARCH_ACTION, wxITEM_NORMAL, OnSearchForAction);
MAKE_ACTION(SEARCH_CONTAINER, wxITEM_NORMAL, OnSearchForContainer);
MAKE_ACTION(SEARCH_WRITEABLE, wxITEM_NORMAL, OnSearchForWriteable);
MAKE_ACTION(SEARCH_ON_MAP_EVERYTHING, wxITEM_NORMAL, OnSearchForStuffOnMap);
MAKE_ACTION(SEARCH_ON_MAP_UNIQUE, wxITEM_NORMAL, OnSearchForUniqueOnMap);
MAKE_ACTION(SEARCH_ON_MAP_ACTION, wxITEM_NORMAL, OnSearchForActionOnMap);
MAKE_ACTION(SEARCH_ON_MAP_CONTAINER, wxITEM_NORMAL, OnSearchForContainerOnMap);
MAKE_ACTION(SEARCH_ON_MAP_WRITEABLE, wxITEM_NORMAL, OnSearchForWriteableOnMap);
MAKE_ACTION(SEARCH_ON_SELECTION_EVERYTHING, wxITEM_NORMAL, OnSearchForStuffOnSelection);
MAKE_ACTION(SEARCH_ON_SELECTION_UNIQUE, wxITEM_NORMAL, OnSearchForUniqueOnSelection);
MAKE_ACTION(SEARCH_ON_SELECTION_ACTION, wxITEM_NORMAL, OnSearchForActionOnSelection);
MAKE_ACTION(SEARCH_ON_SELECTION_CONTAINER, wxITEM_NORMAL, OnSearchForContainerOnSelection);
MAKE_ACTION(SEARCH_ON_SELECTION_WRITEABLE, wxITEM_NORMAL, OnSearchForWriteableOnSelection);
MAKE_ACTION(SELECT_MODE_COMPENSATE, wxITEM_RADIO, OnSelectionTypeChange);
MAKE_ACTION(SELECT_MODE_LOWER, wxITEM_RADIO, OnSelectionTypeChange);
MAKE_ACTION(SELECT_MODE_CURRENT, wxITEM_RADIO, OnSelectionTypeChange);
Expand Down Expand Up @@ -273,6 +278,7 @@ void MainMenuBar::Update()

bool loaded = g_gui.IsVersionLoaded();
bool has_map = editor != nullptr;
bool has_selection = editor && editor->hasSelection();
bool is_live = editor && editor->IsLive();
bool is_host = has_map && !editor->IsLiveClient();
bool is_local = has_map && !is_live;
Expand All @@ -289,11 +295,16 @@ void MainMenuBar::Update()

EnableItem(FIND_ITEM, is_host);
EnableItem(REPLACE_ITEM, is_local);
EnableItem(SEARCH_EVERYTHING, is_host);
EnableItem(SEARCH_UNIQUE, is_host);
EnableItem(SEARCH_ACTION, is_host);
EnableItem(SEARCH_CONTAINER, is_host);
EnableItem(SEARCH_WRITEABLE, is_host);
EnableItem(SEARCH_ON_MAP_EVERYTHING, is_host);
EnableItem(SEARCH_ON_MAP_UNIQUE, is_host);
EnableItem(SEARCH_ON_MAP_ACTION, is_host);
EnableItem(SEARCH_ON_MAP_CONTAINER, is_host);
EnableItem(SEARCH_ON_MAP_WRITEABLE, is_host);
EnableItem(SEARCH_ON_SELECTION_EVERYTHING, has_selection && is_host);
EnableItem(SEARCH_ON_SELECTION_UNIQUE, has_selection && is_host);
EnableItem(SEARCH_ON_SELECTION_ACTION, has_selection && is_host);
EnableItem(SEARCH_ON_SELECTION_CONTAINER, has_selection && is_host);
EnableItem(SEARCH_ON_SELECTION_WRITEABLE, has_selection && is_host);

EnableItem(CUT, has_map);
EnableItem(COPY, has_map);
Expand Down Expand Up @@ -822,7 +833,7 @@ void MainMenuBar::OnSearchForItem(wxCommandEvent& WXUNUSED(event))
OnSearchForItem::Finder func(finder.getResultID());
g_gui.CreateLoadBar(wxT("Searching map..."));

foreach_ItemOnMap(g_gui.GetCurrentMap(), func);
foreach_ItemOnMap(g_gui.GetCurrentMap(), func, false);
std::vector<std::pair<Tile*, Item*> >& found = func.found;

g_gui.DestroyLoadBar();
Expand Down Expand Up @@ -858,7 +869,7 @@ void MainMenuBar::OnReplaceItem(wxCommandEvent& WXUNUSED(event))
g_gui.CreateLoadBar(wxT("Searching & replacing map..."));

// Search the map
foreach_ItemOnMap(g_gui.GetCurrentMap(), finder);
foreach_ItemOnMap(g_gui.GetCurrentMap(), finder, false);

// Replace the items in a second step (can't replace while iterating)
for(std::vector<std::pair<Tile*, Item*> >::const_iterator replace_iter = finder.found.begin();
Expand Down Expand Up @@ -949,114 +960,54 @@ namespace OnSearchForStuff
};
}

void MainMenuBar::OnSearchForStuff(wxCommandEvent& WXUNUSED(event))
void MainMenuBar::OnSearchForStuffOnMap(wxCommandEvent& WXUNUSED(event))
{
if(!g_gui.IsEditorOpen())
return;

g_gui.CreateLoadBar(wxT("Searching map..."));

OnSearchForStuff::Searcher searcher;
searcher.search_unique = true;
searcher.search_action = true;
searcher.search_container = true;
searcher.search_writeable = true;

foreach_ItemOnMap(g_gui.GetCurrentMap(), searcher);
searcher.sort();
std::vector<std::pair<Tile*, Item*> >& found = searcher.found;

g_gui.DestroyLoadBar();

SearchResultWindow* result = g_gui.ShowSearchWindow();
result->Clear();
for(std::vector<std::pair<Tile*, Item*> >::iterator iter = found.begin(); iter != found.end(); ++iter) {
result->AddPosition(searcher.desc(iter->second), iter->first->getPosition());
}
SearchItems(true, true, true, true);
}

void MainMenuBar::OnSearchForUnique(wxCommandEvent& WXUNUSED(event))
void MainMenuBar::OnSearchForUniqueOnMap(wxCommandEvent& WXUNUSED(event))
{
if(!g_gui.IsEditorOpen())
return;

g_gui.CreateLoadBar(wxT("Searching map..."));

OnSearchForStuff::Searcher searcher;
searcher.search_unique = true;
foreach_ItemOnMap(g_gui.GetCurrentMap(), searcher);
searcher.sort();
std::vector<std::pair<Tile*, Item*> >& found = searcher.found;

g_gui.DestroyLoadBar();

SearchResultWindow* result = g_gui.ShowSearchWindow();
result->Clear();
for(std::vector<std::pair<Tile*, Item*> >::iterator iter = found.begin(); iter != found.end(); ++iter) {
result->AddPosition(searcher.desc(iter->second), iter->first->getPosition());
}
SearchItems(true, false, false, false);
}

void MainMenuBar::OnSearchForAction(wxCommandEvent& WXUNUSED(event)) {
if(!g_gui.IsEditorOpen())
return;

g_gui.CreateLoadBar(wxT("Searching map..."));

OnSearchForStuff::Searcher searcher;
searcher.search_action = true;
foreach_ItemOnMap(g_gui.GetCurrentMap(), searcher);
searcher.sort();
std::vector<std::pair<Tile*, Item*> >& found = searcher.found;

g_gui.DestroyLoadBar();

SearchResultWindow* result = g_gui.ShowSearchWindow();
result->Clear();
for(std::vector<std::pair<Tile*, Item*> >::iterator iter = found.begin(); iter != found.end(); ++iter) {
result->AddPosition(searcher.desc(iter->second), iter->first->getPosition());
}
void MainMenuBar::OnSearchForActionOnMap(wxCommandEvent& WXUNUSED(event))
{
SearchItems(false, true, false, false);
}

void MainMenuBar::OnSearchForContainer(wxCommandEvent& WXUNUSED(event))
void MainMenuBar::OnSearchForContainerOnMap(wxCommandEvent& WXUNUSED(event))
{
if(!g_gui.IsEditorOpen())
return;

g_gui.CreateLoadBar(wxT("Searching map..."));

OnSearchForStuff::Searcher searcher;
searcher.search_container = true;
foreach_ItemOnMap(g_gui.GetCurrentMap(), searcher);
std::vector<std::pair<Tile*, Item*> >& found = searcher.found;

g_gui.DestroyLoadBar();
SearchItems(false, false, true, false);
}

SearchResultWindow* result = g_gui.ShowSearchWindow();
result->Clear();
for(std::vector<std::pair<Tile*, Item*> >::iterator iter = found.begin(); iter != found.end(); ++iter) {
result->AddPosition(searcher.desc(iter->second), iter->first->getPosition());
}
void MainMenuBar::OnSearchForWriteableOnMap(wxCommandEvent& WXUNUSED(event))
{
SearchItems(false, false, false, true);
}

void MainMenuBar::OnSearchForWriteable(wxCommandEvent& WXUNUSED(event)) {
if(!g_gui.IsEditorOpen())
return;
void MainMenuBar::OnSearchForStuffOnSelection(wxCommandEvent& WXUNUSED(event))
{
SearchItems(true, true, true, true, true);
}

g_gui.CreateLoadBar(wxT("Searching map..."));
void MainMenuBar::OnSearchForUniqueOnSelection(wxCommandEvent& WXUNUSED(event))
{
SearchItems(true, false, false, false, true);
}

OnSearchForStuff::Searcher searcher;
searcher.search_writeable = true;
foreach_ItemOnMap(g_gui.GetCurrentMap(), searcher);
std::vector<std::pair<Tile*, Item*> >& found = searcher.found;
void MainMenuBar::OnSearchForActionOnSelection(wxCommandEvent& WXUNUSED(event))
{
SearchItems(false, true, false, false, true);
}

g_gui.DestroyLoadBar();
void MainMenuBar::OnSearchForContainerOnSelection(wxCommandEvent& WXUNUSED(event))
{
SearchItems(false, false, true, false, true);
}

SearchResultWindow* result = g_gui.ShowSearchWindow();
result->Clear();
for(std::vector<std::pair<Tile*, Item*> >::iterator iter = found.begin(); iter != found.end(); ++iter) {
result->AddPosition(searcher.desc(iter->second), iter->first->getPosition());
}
void MainMenuBar::OnSearchForWriteableOnSelection(wxCommandEvent& WXUNUSED(event))
{
SearchItems(false, false, false, true, true);
}

void MainMenuBar::OnSelectionTypeChange(wxCommandEvent& WXUNUSED(event))
Expand Down Expand Up @@ -1984,3 +1935,35 @@ void MainMenuBar::OnCloseLive(wxCommandEvent& event)

Update();
}

void MainMenuBar::SearchItems(bool unique, bool action, bool container, bool writable, bool onSelection/* = false*/)
{
if (!unique && !action && !container && !writable)
return;

if(!g_gui.IsEditorOpen())
return;

if(onSelection)
g_gui.CreateLoadBar(wxT("Searching on selected area..."));
else
g_gui.CreateLoadBar(wxT("Searching on map..."));

OnSearchForStuff::Searcher searcher;
searcher.search_unique = unique;
searcher.search_action = action;
searcher.search_container = container;
searcher.search_writeable = writable;

foreach_ItemOnMap(g_gui.GetCurrentMap(), searcher, onSelection);
searcher.sort();
std::vector<std::pair<Tile*, Item*> >& found = searcher.found;

g_gui.DestroyLoadBar();

SearchResultWindow* result = g_gui.ShowSearchWindow();
result->Clear();
for(std::vector<std::pair<Tile*, Item*> >::iterator iter = found.begin(); iter != found.end(); ++iter) {
result->AddPosition(searcher.desc(iter->second), iter->first->getPosition());
}
}
31 changes: 21 additions & 10 deletions source/main_menubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ namespace MenuBar
REDO,
FIND_ITEM,
REPLACE_ITEM,
SEARCH_EVERYTHING,
SEARCH_UNIQUE,
SEARCH_ACTION,
SEARCH_CONTAINER,
SEARCH_WRITEABLE,
SEARCH_ON_MAP_EVERYTHING,
SEARCH_ON_MAP_UNIQUE,
SEARCH_ON_MAP_ACTION,
SEARCH_ON_MAP_CONTAINER,
SEARCH_ON_MAP_WRITEABLE,
SEARCH_ON_SELECTION_EVERYTHING,
SEARCH_ON_SELECTION_UNIQUE,
SEARCH_ON_SELECTION_ACTION,
SEARCH_ON_SELECTION_CONTAINER,
SEARCH_ON_SELECTION_WRITEABLE,
SELECT_MODE_COMPENSATE,
SELECT_MODE_CURRENT,
SELECT_MODE_LOWER,
Expand Down Expand Up @@ -202,11 +207,16 @@ class MainMenuBar : wxEvtHandler
void OnPaste(wxCommandEvent& event);
void OnSearchForItem(wxCommandEvent& event);
void OnReplaceItem(wxCommandEvent& event);
void OnSearchForStuff(wxCommandEvent& event);
void OnSearchForUnique(wxCommandEvent& event);
void OnSearchForAction(wxCommandEvent& event);
void OnSearchForContainer(wxCommandEvent& event);
void OnSearchForWriteable(wxCommandEvent& event);
void OnSearchForStuffOnMap(wxCommandEvent& event);
void OnSearchForUniqueOnMap(wxCommandEvent& event);
void OnSearchForActionOnMap(wxCommandEvent& event);
void OnSearchForContainerOnMap(wxCommandEvent& event);
void OnSearchForWriteableOnMap(wxCommandEvent& event);
void OnSearchForStuffOnSelection(wxCommandEvent& event);
void OnSearchForUniqueOnSelection(wxCommandEvent& event);
void OnSearchForActionOnSelection(wxCommandEvent& event);
void OnSearchForContainerOnSelection(wxCommandEvent& event);
void OnSearchForWriteableOnSelection(wxCommandEvent& event);

// Map menu
void OnMapEditTowns(wxCommandEvent& event);
Expand Down Expand Up @@ -256,6 +266,7 @@ class MainMenuBar : wxEvtHandler
wxObject* LoadItem(pugi::xml_node node, wxMenu* parent, wxArrayString& warnings, wxString& error);
// Checks the items in the menus according to the settings (in config)
void LoadValues();
void SearchItems(bool unique, bool action, bool container, bool writable, bool onSelection = false);
protected:

MainFrame* frame;
Expand Down
14 changes: 9 additions & 5 deletions source/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,26 @@ class Map : public BaseMap
};

template <typename ForeachType>
inline void foreach_ItemOnMap(Map& map, ForeachType& foreach) {
inline void foreach_ItemOnMap(Map& map, ForeachType& foreach, bool selectedTiles)
{
MapIterator tileiter = map.begin();
MapIterator end = map.end();
long long done = 0;

while(tileiter != end) {
++done;
Tile* tile = (*tileiter)->get();
if(selectedTiles && !tile->isSelected()) {
++tileiter;
continue;
}

if(tile->ground) {
foreach(map, tile, tile->ground, done);
}

std::queue<Container*> containers;
for(ItemVector::iterator itemiter = tile->items.begin();
itemiter != tile->items.end();
++itemiter)
{
for(ItemVector::iterator itemiter = tile->items.begin(); itemiter != tile->items.end(); ++itemiter) {
Item* item = *itemiter;
Container* container = dynamic_cast<Container*>(item);
foreach(map, tile, item, done);
Expand Down

0 comments on commit 61b58ae

Please sign in to comment.