From cba143c4478c2a0ee2b89c83a04f1c58ad65ab11 Mon Sep 17 00:00:00 2001 From: Anuradha Dissanayake Date: Sun, 4 May 2014 22:04:03 +1200 Subject: [PATCH] Add workshop profile search. --- NEWS | 1 + plugins/search.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 8be141a4f..961708dc3 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,7 @@ DFHack future - autotrade: adds "(Un)mark All" options to both panes of trade screen. - mousequery: several usability improvements. - mousequery: show live overlay (in menu area) of what's on the tile under the mouse cursor. + - search: workshop profile search added. Siege engine plugin: - engine quality and distance to target now affect accuracy diff --git a/plugins/search.cpp b/plugins/search.cpp index 0f519414b..e0213bf06 100644 --- a/plugins/search.cpp +++ b/plugins/search.cpp @@ -11,6 +11,7 @@ #include "df/viewscreen_layer_stockpilest.h" #include "df/viewscreen_layer_militaryst.h" #include "df/viewscreen_layer_noblelistst.h" +#include "df/viewscreen_layer_workshop_profilest.h" #include "df/viewscreen_tradegoodsst.h" #include "df/viewscreen_unitlistst.h" #include "df/viewscreen_buildinglistst.h" @@ -423,7 +424,7 @@ protected: virtual bool can_init(S *screen) { auto list = getLayerList(screen); - if (!is_list_valid(screen) || !list->active) + if (!is_list_valid(screen) || !list || !list->active) return false; return true; @@ -699,8 +700,8 @@ template V generic_search_hook ::module; #define IMPLEMENT_HOOKS_PRIO(screen, module, prio) \ typedef generic_search_hook module##_hook; \ - template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, feed, 100); \ - template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, render, 100) + template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, feed, prio); \ + template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, render, prio) // // END: Generic Search functionality @@ -920,7 +921,7 @@ private: }; -IMPLEMENT_HOOKS(df::viewscreen_storesst, stocks_search); +IMPLEMENT_HOOKS_PRIO(df::viewscreen_storesst, stocks_search, 100); // // END: Stocks screen search @@ -1048,7 +1049,9 @@ private: { // Block the keys if were searching if (!search_string.empty()) + { input->clear(); + } return false; } @@ -1081,6 +1084,9 @@ public: { make_text_dim(2, 37, 22); make_text_dim(42, gps->dimx-2, 22); + int32_t x = 2; + int32_t y = gps->dimy - 3; + OutputString(COLOR_YELLOW, x, y, "Note: Clear search to trade"); } } @@ -1120,6 +1126,9 @@ public: { make_text_dim(2, 37, 22); make_text_dim(42, gps->dimx-2, 22); + int32_t x = 42; + int32_t y = gps->dimy - 3; + OutputString(COLOR_YELLOW, x, y, "Note: Clear search to trade"); } } @@ -1432,6 +1441,36 @@ IMPLEMENT_HOOKS(df::viewscreen_layer_noblelistst, nobles_search); // END: Nobles search list // +// +// START: Workshop profiles search list +// +typedef layered_search profiles_search_base; +class profiles_search : public profiles_search_base +{ +public: + + string get_element_description(df::unit *element) const + { + return get_unit_description(element); + } + + void render() const + { + print_search_option(2, 23); + } + + vector *get_primary_list() + { + return &viewscreen->workers; + } +}; + +IMPLEMENT_HOOKS(df::viewscreen_layer_workshop_profilest, profiles_search); + +// +// END: Workshop profiles search list +// + // // START: Job list search @@ -1621,6 +1660,7 @@ DFHACK_PLUGIN_IS_ENABLED(is_enabled); HOOK_ACTION(pets_search_hook) \ HOOK_ACTION(military_search_hook) \ HOOK_ACTION(nobles_search_hook) \ + HOOK_ACTION(profiles_search_hook) \ HOOK_ACTION(annoucnement_search_hook) \ HOOK_ACTION(joblist_search_hook) \ HOOK_ACTION(burrow_search_hook) \