Skip to content

Commit

Permalink
Add option to find item on a selected area.
Browse files Browse the repository at this point in the history
Menu Edit > Find on Selected Area > Find Item
  • Loading branch information
Mignari committed May 24, 2019
1 parent a6f8922 commit 202a907
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions data/menubar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<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."/>
<separator/>
<item name="Find $Item" action="SEARCH_ON_SELECTION_ITEM" help="Find items on selected area."/>
</menu>
<separator/>
<menu name="$Selection">
Expand Down
38 changes: 38 additions & 0 deletions source/main_menubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ MainMenuBar::MainMenuBar(MainFrame *frame) : frame(frame)
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(SEARCH_ON_SELECTION_ITEM, wxITEM_NORMAL, OnSearchForItemOnSelection);
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 @@ -311,6 +312,7 @@ void MainMenuBar::Update()
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(SEARCH_ON_SELECTION_ITEM, has_selection && is_host);

EnableItem(CUT, has_map);
EnableItem(COPY, has_map);
Expand Down Expand Up @@ -1034,6 +1036,42 @@ void MainMenuBar::OnSearchForWriteableOnSelection(wxCommandEvent& WXUNUSED(event
SearchItems(false, false, false, true, true);
}

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

FindItemDialog dialog(frame, "Search on Selection");
dialog.setSearchMode((FindItemDialog::SearchMode)g_settings.getInteger(Config::FIND_ITEM_MODE));
if(dialog.ShowModal() == wxID_OK) {
OnSearchForItem::Finder finder(dialog.getResultID());
g_gui.CreateLoadBar("Searching on selected area...");

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

g_gui.DestroyLoadBar();

if(finder.more_than_value) {
wxString msg;
msg << "Only the first " << size_t(g_settings.getInteger(Config::REPLACE_SIZE)) << " results will be displayed.";
g_gui.PopupDialog("Notice", msg, wxOK);
}

SearchResultWindow* result = g_gui.ShowSearchWindow();
result->Clear();
for(std::vector<std::pair<Tile*, Item*> >::const_iterator iter = found.begin(); iter != found.end(); ++iter) {
Tile* tile = iter->first;
Item* item = iter->second;
result->AddPosition(wxstr(item->getName()), tile->getPosition());
}

g_settings.setInteger(Config::FIND_ITEM_MODE, (int)dialog.getSearchMode());
}

dialog.Destroy();
}

void MainMenuBar::OnSelectionTypeChange(wxCommandEvent& WXUNUSED(event))
{
g_settings.setInteger(Config::COMPENSATED_SELECT, IsItemChecked(MenuBar::SELECT_MODE_COMPENSATE));
Expand Down
2 changes: 2 additions & 0 deletions source/main_menubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace MenuBar
SEARCH_ON_SELECTION_ACTION,
SEARCH_ON_SELECTION_CONTAINER,
SEARCH_ON_SELECTION_WRITEABLE,
SEARCH_ON_SELECTION_ITEM,
SELECT_MODE_COMPENSATE,
SELECT_MODE_CURRENT,
SELECT_MODE_LOWER,
Expand Down Expand Up @@ -221,6 +222,7 @@ class MainMenuBar : wxEvtHandler
void OnSearchForActionOnSelection(wxCommandEvent& event);
void OnSearchForContainerOnSelection(wxCommandEvent& event);
void OnSearchForWriteableOnSelection(wxCommandEvent& event);
void OnSearchForItemOnSelection(wxCommandEvent& event);

// Map menu
void OnMapEditTowns(wxCommandEvent& event);
Expand Down

0 comments on commit 202a907

Please sign in to comment.