From e075a064861fb3ea0cfee507105e8898c9130265 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 27 Dec 2015 15:49:10 -0500 Subject: [PATCH] Add search controls to all viewscreen_petst subpages --- NEWS.rst | 7 ++- library/xml | 2 +- plugins/search.cpp | 141 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 140 insertions(+), 10 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index 04e99c056..cab6c0c69 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -44,7 +44,12 @@ Internals New Features ------------ - `confirm`: Added a confirmation for retiring locations -- `search-plugin`: Support for the location occupation assignment menu +- `search-plugin`: Support for new screens: + + - location occupation assignment + - civilization animal training knowledge + - animal trainer assignment + - `tweak`: - ``tweak title-start-rename``: Adds a safe rename option to the title screen "Start Playing" menu diff --git a/library/xml b/library/xml index cc74796a9..c8f486bf7 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit cc74796a90b139e6f7ca7291d5161f84d7beb985 +Subproject commit c8f486bf79ee456ef7a9ed5ed938263fd3703466 diff --git a/plugins/search.cpp b/plugins/search.cpp index cd94b3320..83d498367 100644 --- a/plugins/search.cpp +++ b/plugins/search.cpp @@ -7,6 +7,7 @@ #include "uicommon.h" +#include "df/creature_raw.h" #include "df/ui_look_list.h" #include "df/viewscreen_announcelistst.h" #include "df/viewscreen_petst.h" @@ -621,7 +622,7 @@ protected: }; // This basic match function is separated out from the generic multi column class, because the -// pets screen, which uses a union in its primary list, will cause a compile failure is this +// pets screen, which uses a union in its primary list, will cause a compile failure if this // match function exists in the generic class template < class S, class T, class PARENT = search_generic > class search_multicolumn_modifiable : public search_multicolumn_modifiable_generic @@ -751,7 +752,7 @@ template V generic_search_hook ::module; typedef generic_search_hook module##_hook; \ template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, feed, prio); \ template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, render, prio); \ - template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, key_conflict, prio) + template<> IMPLEMENT_VMETHOD_INTERPOSE_PRIO(module##_hook, key_conflict, prio); // // END: Generic Search functionality @@ -761,19 +762,24 @@ template V generic_search_hook ::module; // // START: Animal screen search // -typedef df::viewscreen_petst::T_animal T_animal; -typedef df::viewscreen_petst::T_mode T_mode; -class pets_search : public search_multicolumn_modifiable_generic +typedef search_multicolumn_modifiable_generic pets_search_base; +class pets_search : public pets_search_base { + typedef df::viewscreen_petst::T_animal T_animal; + typedef df::viewscreen_petst::T_mode T_mode; public: void render() const { - if (viewscreen->mode == T_mode::List) - print_search_option(25, 4); + print_search_option(25, 4); } private: + bool can_init(df::viewscreen_petst *screen) + { + return pets_search_base::can_init(screen) && screen->mode == T_mode::List; + } + int32_t *get_viewscreen_cursor() { return &viewscreen->cursor; @@ -876,13 +882,130 @@ private: std::vector *is_adopting, is_adopting_s; }; -IMPLEMENT_HOOKS(df::viewscreen_petst, pets_search); +IMPLEMENT_HOOKS_WITH_ID(df::viewscreen_petst, pets_search, 1, 0); // // END: Animal screen search // +// +// START: Animal knowledge screen search +// + +typedef search_generic animal_knowledge_search_base; +class animal_knowledge_search : public animal_knowledge_search_base +{ + typedef df::viewscreen_petst::T_mode T_mode; + bool can_init(df::viewscreen_petst *screen) + { + return animal_knowledge_search_base::can_init(screen) && screen->mode == T_mode::TrainingKnowledge; + } + +public: + void render() const + { + print_search_option(2, 4); + } + +private: + int32_t *get_viewscreen_cursor() + { + return NULL; + } + + vector *get_primary_list() + { + return &viewscreen->known; + } + + string get_element_description(int32_t id) const + { + auto craw = df::creature_raw::find(id); + string out; + if (craw) + { + for (size_t i = 0; i < 3; ++i) + out += craw->name[i] + " "; + } + return out; + } +}; + +IMPLEMENT_HOOKS_WITH_ID(df::viewscreen_petst, animal_knowledge_search, 2, 0); + +// +// END: Animal knowledge screen search +// + + +// +// START: Animal trainer search +// + +typedef search_twocolumn_modifiable animal_trainer_search_base; +class animal_trainer_search : public animal_trainer_search_base +{ + typedef df::viewscreen_petst::T_mode T_mode; + typedef df::viewscreen_petst::T_trainer_mode T_trainer_mode; + + bool can_init(df::viewscreen_petst *screen) + { + return animal_trainer_search_base::can_init(screen) && screen->mode == T_mode::SelectTrainer; + } + +public: + void render() const + { + Screen::paintTile(Screen::Pen(186, 8, 0), 14, 2); + Screen::paintTile(Screen::Pen(186, 8, 0), gps->dimx - 14, 2); + Screen::paintTile(Screen::Pen(201, 8, 0), 14, 1); + Screen::paintTile(Screen::Pen(187, 8, 0), gps->dimx - 14, 1); + for (int x = 15; x <= gps->dimx - 15; ++x) + { + Screen::paintTile(Screen::Pen(205, 8, 0), x, 1); + Screen::paintTile(Screen::Pen(0, 0, 0), x, 2); + } + print_search_option(16, 2); + } + +private: + int32_t *get_viewscreen_cursor() + { + return &viewscreen->trainer_cursor; + } + + vector *get_primary_list() + { + return &viewscreen->trainer_unit; + } + + string get_element_description(df::unit *u) const + { + return get_unit_description(u); + } + + std::vector *get_secondary_list() + { + return &viewscreen->trainer_mode; + } + +public: + bool process_input(set *input) + { + if (input->count(interface_key::SELECT) && viewscreen->trainer_unit.empty() && !in_entry_mode()) + return true; + return animal_trainer_search_base::process_input(input); + } + +}; + +IMPLEMENT_HOOKS_WITH_ID(df::viewscreen_petst, animal_trainer_search, 3, 0); + +// +// END: Animal trainer search +// + // // START: Stocks screen search @@ -1997,6 +2120,8 @@ IMPLEMENT_HOOKS(df::viewscreen_locationsst, location_assign_occupation_search); HOOK_ACTION(trade_search_fort_hook) \ HOOK_ACTION(stocks_search_hook) \ HOOK_ACTION(pets_search_hook) \ + HOOK_ACTION(animal_knowledge_search_hook) \ + HOOK_ACTION(animal_trainer_search_hook) \ HOOK_ACTION(military_search_hook) \ HOOK_ACTION(nobles_search_hook) \ HOOK_ACTION(profiles_search_hook) \