Skip to content

Commit

Permalink
Fix #126
Browse files Browse the repository at this point in the history
  • Loading branch information
Mignari committed Oct 22, 2016
1 parent 1431e33 commit 335e750
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions source/main_menubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,25 @@ namespace OnSearchForStuff

return label;
}

void sort()
{
if(search_unique || search_action)
std::sort(found.begin(), found.end(), Searcher::compare);
}

static bool compare(const std::pair<Tile*, Item*>& pair1, const std::pair<Tile*, Item*>& pair2)
{
const Item* item1 = pair1.second;
const Item* item2 = pair2.second;

if(item1->getActionID() != 0 || item2->getActionID() != 0)
return item1->getActionID() < item2->getActionID();
else if(item1->getUniqueID() != 0 || item2->getUniqueID() != 0)
return item1->getUniqueID() < item2->getUniqueID();

return false;
}
};
}

Expand All @@ -944,6 +963,7 @@ void MainMenuBar::OnSearchForStuff(wxCommandEvent& WXUNUSED(event))
searcher.search_writeable = true;

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

g_gui.DestroyLoadBar();
Expand All @@ -965,6 +985,7 @@ void MainMenuBar::OnSearchForUnique(wxCommandEvent& WXUNUSED(event))
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();
Expand All @@ -985,6 +1006,7 @@ void MainMenuBar::OnSearchForAction(wxCommandEvent& WXUNUSED(event)) {
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();
Expand Down

0 comments on commit 335e750

Please sign in to comment.