Skip to content

Commit

Permalink
Fix various issues with updated search.
Browse files Browse the repository at this point in the history
- Priority conflict with tweak military-stable-assign.
- The noble screen misbehaves if only one list item is left.
- Noble screen search string not reset after Enter/Esc.
  • Loading branch information
angavrilov committed Jan 16, 2013
1 parent 14d41b8 commit 5970744
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions plugins/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ class search_generic
return false;

if (!can_init(screen))
{
if (is_valid())
{
clear_search();
reset_all();
}

return false;
}

if (!is_valid())
{
Expand Down Expand Up @@ -296,6 +304,11 @@ class search_generic
return true;
}

virtual bool force_in_search(size_t index)
{
return false;
}

// The actual sort
virtual void do_search()
{
Expand All @@ -316,6 +329,12 @@ class search_generic
string search_string_l = toLower(search_string);
for (size_t i = 0; i < saved_list1.size(); i++ )
{
if (force_in_search(i))
{
add_to_filtered_list(i);
continue;
}

if (!is_valid_for_search(i))
continue;

Expand Down Expand Up @@ -383,15 +402,7 @@ class layered_search : public search_generic<S, T>
{
auto list = getLayerList(screen);
if (!list->active)
{
if (this->is_valid())
{
this->clear_search();
this->reset_all();
}

return false;
}

return true;
}
Expand Down Expand Up @@ -655,6 +666,10 @@ template <class T, class V, int D> V generic_search_hook<T, V, D> ::module;
template<> IMPLEMENT_VMETHOD_INTERPOSE(module##_hook, feed); \
template<> IMPLEMENT_VMETHOD_INTERPOSE(module##_hook, render)

#define IMPLEMENT_HOOKS_PRIO(screen, module, prio) \
typedef generic_search_hook<screen, module> module##_hook; \
template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, feed, 100); \
template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, render, 100)

//
// END: Generic Search functionality
Expand Down Expand Up @@ -1197,7 +1212,7 @@ class military_search : public layered_search<df::viewscreen_layer_militaryst, d
}
};

IMPLEMENT_HOOKS(df::viewscreen_layer_militaryst, military_search);
IMPLEMENT_HOOKS_PRIO(df::viewscreen_layer_militaryst, military_search, 100);

//
// END: Military screen search
Expand Down Expand Up @@ -1349,6 +1364,11 @@ class nobles_search : public layered_search<df::viewscreen_layer_noblelistst, T_
print_search_option(2, 23);
}

bool force_in_search(size_t index)
{
return index == 0; // Leave Vacant
}

bool can_init(df::viewscreen_layer_noblelistst *screen)
{
if (screen->mode != df::viewscreen_layer_noblelistst::Appoint)
Expand Down Expand Up @@ -1488,11 +1508,6 @@ class burrow_search : public search_twocolumn_modifiable<df::viewscreen_dwarfmod
{
return search_twocolumn_modifiable::can_init(screen);
}
else if (is_valid())
{
clear_search();
reset_all();
}

return false;
}
Expand Down

0 comments on commit 5970744

Please sign in to comment.