From 55e58e5f06dd5cec0a83aa2f8dc02411fb918f98 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 14 May 2016 11:43:37 -0400 Subject: [PATCH] Update handling of viewscreen_workshop_profilest in Gui module, search/sort plugins --- library/modules/Gui.cpp | 38 ++++++++++++++++++++++---------------- library/xml | 2 +- plugins/search.cpp | 16 +++++++++++++--- plugins/sort.cpp | 34 ++++++++++++++++------------------ 4 files changed, 52 insertions(+), 38 deletions(-) diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index df89b1932..3fc353abf 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -429,16 +429,22 @@ DEFINE_GET_FOCUS_STRING_HANDLER(layer_military) } } -// DEFINE_GET_FOCUS_STRING_HANDLER(layer_workshop_profile) -// { -// auto list1 = getLayerList(screen, 0); -// if (!list1) return; - -// if (vector_get(screen->workers, list1->cursor)) -// focus += "/Unit"; -// else -// focus += "/None"; -// } +DEFINE_GET_FOCUS_STRING_HANDLER(workshop_profile) +{ + typedef df::viewscreen_workshop_profilest::T_tab T_tab; + switch(screen->tab) + { + case T_tab::Workers: + focus += "/Unit"; + break; + case T_tab::Orders: + focus += "/Orders"; + break; + case T_tab::Restrictions: + focus += "/Restrictions"; + break; + } +} DEFINE_GET_FOCUS_STRING_HANDLER(layer_noblelist) { @@ -810,12 +816,12 @@ df::unit *Gui::getAnyUnit(df::viewscreen *top) return ref ? ref->getUnit() : NULL; } - // if (VIRTUAL_CAST_VAR(screen, df::viewscreen_layer_workshop_profilest, top)) - // { - // if (auto list1 = getLayerList(screen, 0)) - // return vector_get(screen->workers, list1->cursor); - // return NULL; - // } + if (VIRTUAL_CAST_VAR(screen, df::viewscreen_workshop_profilest, top)) + { + if (screen->tab == df::viewscreen_workshop_profilest::Workers) + return vector_get(screen->workers, screen->worker_idx); + return NULL; + } if (VIRTUAL_CAST_VAR(screen, df::viewscreen_layer_noblelistst, top)) { diff --git a/library/xml b/library/xml index 83aa92b37..eae49d13a 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 83aa92b3717e876afbd26d300175c17a075c0678 +Subproject commit eae49d13af541710f6f6f5a42368e915f74bd749 diff --git a/plugins/search.cpp b/plugins/search.cpp index 83d498367..0b7556552 100644 --- a/plugins/search.cpp +++ b/plugins/search.cpp @@ -15,7 +15,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_workshop_profilest.h" #include "df/viewscreen_topicmeeting_fill_land_holder_positionsst.h" #include "df/viewscreen_tradegoodsst.h" #include "df/viewscreen_unitlistst.h" @@ -1654,11 +1654,16 @@ IMPLEMENT_HOOKS(df::viewscreen_layer_noblelistst, nobles_search); // // START: Workshop profiles search list // -typedef layered_search profiles_search_base; +typedef search_generic profiles_search_base; class profiles_search : public profiles_search_base { public: + bool can_init (df::viewscreen_workshop_profilest *screen) + { + return screen->tab == df::viewscreen_workshop_profilest::T_tab::Workers; + } + string get_element_description(df::unit *element) const { return get_unit_description(element); @@ -1673,9 +1678,14 @@ public: { return &viewscreen->workers; } + + int32_t *get_viewscreen_cursor() + { + return &viewscreen->worker_idx; + } }; -IMPLEMENT_HOOKS(df::viewscreen_layer_workshop_profilest, profiles_search); +IMPLEMENT_HOOKS(df::viewscreen_workshop_profilest, profiles_search); // // END: Workshop profiles search list diff --git a/plugins/sort.cpp b/plugins/sort.cpp index 7d80b4aa1..264da21db 100644 --- a/plugins/sort.cpp +++ b/plugins/sort.cpp @@ -16,7 +16,6 @@ #include "df/viewscreen_joblistst.h" #include "df/viewscreen_unitlistst.h" #include "df/viewscreen_layer_militaryst.h" -#include "df/viewscreen_layer_workshop_profilest.h" #include "df/viewscreen_layer_noblelistst.h" #include "df/viewscreen_layer_overall_healthst.h" #include "df/viewscreen_layer_assigntradest.h" @@ -24,6 +23,7 @@ #include "df/viewscreen_dwarfmodest.h" #include "df/viewscreen_petst.h" #include "df/viewscreen_storesst.h" +#include "df/viewscreen_workshop_profilest.h" #include "df/layer_object_listst.h" #include "df/assign_trade_status.h" @@ -310,23 +310,6 @@ DEFINE_SORT_HANDLER(unit_sorters, layer_military, "/Positions/Candidates", milit } -/* - * Sort units in the workshop 'q'uery 'P'rofile modification screen. - */ - -DEFINE_SORT_HANDLER(unit_sorters, layer_workshop_profile, "/Unit", profile) -{ - auto list1 = getLayerList(profile, 0); - - PARSE_SPEC("units", parameters); - - if (compute_order(*pout, L, top, &order, profile->workers)) - { - reorder_cursor(&list1->cursor, order); - reorder_vector(&profile->workers, order); - } -} - DEFINE_SORT_HANDLER(unit_sorters, layer_noblelist, "/Appoint", nobles) { auto list2 = getLayerList(nobles, 1); @@ -443,6 +426,21 @@ DEFINE_SORT_HANDLER(unit_sorters, dwarfmode, "/QueryBuilding/Some/Assign", scree } } +/* + * Sort units in the workshop 'q'uery 'P'rofile modification screen. + */ + +DEFINE_SORT_HANDLER(unit_sorters, workshop_profile, "/Unit", profile) +{ + PARSE_SPEC("units", parameters); + + if (compute_order(*pout, L, top, &order, profile->workers)) + { + reorder_cursor(&profile->worker_idx, order); + reorder_vector(&profile->workers, order); + } +} + /* * Sort pen assignment candidate units in 'z'->'N'. */