Copy fixes from r3 to fix search issues in Nobles screen.

develop
Anuradha Dissanayake 2013-03-13 22:21:30 +13:00
parent 215a2e78af
commit b5806f7278
1 changed files with 53 additions and 33 deletions

@ -91,7 +91,15 @@ public:
return false; return false;
if (!can_init(screen)) if (!can_init(screen))
{
if (is_valid())
{
clear_search();
reset_all();
}
return false; return false;
}
if (!is_valid()) if (!is_valid())
{ {
@ -296,6 +304,11 @@ protected:
return true; return true;
} }
virtual bool force_in_search(size_t index)
{
return false;
}
// The actual sort // The actual sort
virtual void do_search() virtual void do_search()
{ {
@ -316,6 +329,12 @@ protected:
string search_string_l = toLower(search_string); string search_string_l = toLower(search_string);
for (size_t i = 0; i < saved_list1.size(); i++ ) 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)) if (!is_valid_for_search(i))
continue; continue;
@ -383,15 +402,7 @@ protected:
{ {
auto list = getLayerList(screen); auto list = getLayerList(screen);
if (!list->active) if (!list->active)
{
if (this->is_valid())
{
this->clear_search();
this->reset_all();
}
return false; return false;
}
return true; return true;
} }
@ -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, feed); \
template<> IMPLEMENT_VMETHOD_INTERPOSE(module##_hook, render) 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 // END: Generic Search functionality
@ -799,7 +814,8 @@ IMPLEMENT_HOOKS(df::viewscreen_petst, pets_search);
// //
// START: Stocks screen search // START: Stocks screen search
// //
class stocks_search : public search_generic<df::viewscreen_storesst, df::item*> typedef search_generic<df::viewscreen_storesst, df::item*> stocks_search_base;
class stocks_search : public stocks_search_base
{ {
public: public:
@ -833,7 +849,7 @@ public:
return false; return false;
} }
return search_generic::process_input(input); return stocks_search_base::process_input(input);
} }
virtual void do_post_input_feed() virtual void do_post_input_feed()
@ -883,7 +899,8 @@ IMPLEMENT_HOOKS(df::viewscreen_storesst, stocks_search);
// //
// START: Unit screen search // START: Unit screen search
// //
class unitlist_search : public search_twocolumn_modifiable<df::viewscreen_unitlistst, df::unit*, df::job*> typedef search_twocolumn_modifiable<df::viewscreen_unitlistst, df::unit*, df::job*> unitlist_search_base;
class unitlist_search : public unitlist_search_base
{ {
public: public:
void render() const void render() const
@ -894,7 +911,7 @@ public:
private: private:
void do_post_init() void do_post_init()
{ {
search_twocolumn_modifiable::do_post_init(); unitlist_search_base::do_post_init();
read_only = true; read_only = true;
} }
@ -969,8 +986,8 @@ private:
} }
}; };
typedef generic_search_hook<df::viewscreen_unitlistst, unitlist_search> unitlist_search_hook; typedef generic_search_hook<df::viewscreen_unitlistst, unitlist_search> unitlist_search_hook;
template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(unitlist_search_hook, feed, 100); template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(unitlist_search_hook, feed, 100);
template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(unitlist_search_hook, render, 100); template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(unitlist_search_hook, render, 100);
// //
// END: Unit screen search // END: Unit screen search
@ -1143,7 +1160,8 @@ IMPLEMENT_HOOKS(df::viewscreen_layer_stockpilest, stockpile_search);
// //
// START: Military screen search // START: Military screen search
// //
class military_search : public layered_search<df::viewscreen_layer_militaryst, df::unit *, 2> typedef layered_search<df::viewscreen_layer_militaryst, df::unit *, 2> military_search_base;
class military_search : public military_search_base
{ {
public: public:
@ -1167,7 +1185,7 @@ public:
if (screen->page != df::viewscreen_layer_militaryst::Positions) if (screen->page != df::viewscreen_layer_militaryst::Positions)
return false; return false;
return layered_search::can_init(screen); return military_search_base::can_init(screen);
} }
vector<df::unit *> *get_primary_list() vector<df::unit *> *get_primary_list()
@ -1197,7 +1215,7 @@ public:
} }
}; };
IMPLEMENT_HOOKS(df::viewscreen_layer_militaryst, military_search); IMPLEMENT_HOOKS_PRIO(df::viewscreen_layer_militaryst, military_search, 100);
// //
// END: Military screen search // END: Military screen search
@ -1209,8 +1227,8 @@ IMPLEMENT_HOOKS(df::viewscreen_layer_militaryst, military_search);
// //
static map< df::building_type, vector<string> > room_quality_names; static map< df::building_type, vector<string> > room_quality_names;
static int32_t room_value_bounds[] = {1, 100, 250, 500, 1000, 1500, 2500, 10000}; static int32_t room_value_bounds[] = {1, 100, 250, 500, 1000, 1500, 2500, 10000};
typedef search_twocolumn_modifiable<df::viewscreen_buildinglistst, df::building*, int32_t> roomlist_search_base;
class roomlist_search : public search_twocolumn_modifiable<df::viewscreen_buildinglistst, df::building*, int32_t> class roomlist_search : public roomlist_search_base
{ {
public: public:
void render() const void render() const
@ -1221,7 +1239,7 @@ public:
private: private:
void do_post_init() void do_post_init()
{ {
search_twocolumn_modifiable::do_post_init(); roomlist_search_base::do_post_init();
read_only = true; read_only = true;
} }
@ -1292,7 +1310,7 @@ IMPLEMENT_HOOKS(df::viewscreen_buildinglistst, roomlist_search);
// //
// START: Announcement list search // START: Announcement list search
// //
class annoucnement_search : public search_generic<df::viewscreen_announcelistst, void*> class annoucnement_search : public search_generic<df::viewscreen_announcelistst, void *>
{ {
public: public:
void render() const void render() const
@ -1331,8 +1349,8 @@ IMPLEMENT_HOOKS(df::viewscreen_announcelistst, annoucnement_search);
// START: Nobles search list // START: Nobles search list
// //
typedef df::viewscreen_layer_noblelistst::T_candidates T_candidates; typedef df::viewscreen_layer_noblelistst::T_candidates T_candidates;
typedef layered_search<df::viewscreen_layer_noblelistst, T_candidates *, 1> nobles_search_base;
class nobles_search : public layered_search<df::viewscreen_layer_noblelistst, T_candidates *, 1> class nobles_search : public nobles_search_base
{ {
public: public:
@ -1349,12 +1367,17 @@ public:
print_search_option(2, 23); 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) bool can_init(df::viewscreen_layer_noblelistst *screen)
{ {
if (screen->mode != df::viewscreen_layer_noblelistst::Appoint) if (screen->mode != df::viewscreen_layer_noblelistst::Appoint)
return false; return false;
return layered_search::can_init(screen); return nobles_search_base::can_init(screen);
} }
vector<T_candidates *> *get_primary_list() vector<T_candidates *> *get_primary_list()
@ -1419,7 +1442,8 @@ void get_job_details(string &desc, df::job *job)
desc += "suspended."; desc += "suspended.";
} }
class joblist_search : public search_twocolumn_modifiable<df::viewscreen_joblistst, df::job*, df::unit*> typedef search_twocolumn_modifiable<df::viewscreen_joblistst, df::job*, df::unit*> joblist_search_base;
class joblist_search : public joblist_search_base
{ {
public: public:
void render() const void render() const
@ -1430,7 +1454,7 @@ public:
private: private:
void do_post_init() void do_post_init()
{ {
search_twocolumn_modifiable::do_post_init(); joblist_search_base::do_post_init();
read_only = true; read_only = true;
} }
@ -1479,19 +1503,15 @@ IMPLEMENT_HOOKS(df::viewscreen_joblistst, joblist_search);
// //
using df::global::ui; using df::global::ui;
class burrow_search : public search_twocolumn_modifiable<df::viewscreen_dwarfmodest, df::unit*, bool> typedef search_twocolumn_modifiable<df::viewscreen_dwarfmodest, df::unit*, bool> burrow_search_base;
class burrow_search : public burrow_search_base
{ {
public: public:
bool can_init(df::viewscreen_dwarfmodest *screen) bool can_init(df::viewscreen_dwarfmodest *screen)
{ {
if (ui->main.mode == df::ui_sidebar_mode::Burrows && ui->burrows.in_add_units_mode) if (ui->main.mode == df::ui_sidebar_mode::Burrows && ui->burrows.in_add_units_mode)
{ {
return search_twocolumn_modifiable::can_init(screen); return burrow_search_base::can_init(screen);
}
else if (is_valid())
{
clear_search();
reset_all();
} }
return false; return false;