diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index f69e11778e..2290110a82 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -41,6 +41,8 @@ using namespace std; #include "MiscUtils.h" using namespace DFHack; +#include "modules/Job.h" + #include "DataDefs.h" #include "df/world.h" #include "df/global_objects.h" @@ -58,6 +60,7 @@ using namespace DFHack; #include "df/viewscreen_layer_militaryst.h" #include "df/viewscreen_petst.h" #include "df/viewscreen_tradegoodsst.h" +#include "df/viewscreen_storesst.h" #include "df/ui_unit_view_mode.h" #include "df/ui_sidebar_menus.h" #include "df/ui_look_list.h" @@ -353,6 +356,9 @@ DEFINE_GET_FOCUS_STRING_HANDLER(pet) if (vector_get(screen->trainer_unit, screen->trainer_cursor)) focus += "/Unit"; break; + + default: + break; } } @@ -391,6 +397,17 @@ DEFINE_GET_FOCUS_STRING_HANDLER(layer_assigntrade) focus += "/Items"; } +DEFINE_GET_FOCUS_STRING_HANDLER(stores) +{ + if (!screen->in_right_list) + focus += "/Categories"; + else if (screen->in_group_mode) + focus += "/Groups"; + else + focus += "/Items"; +} + + std::string Gui::getFocusString(df::viewscreen *top) { if (!top) @@ -625,7 +642,13 @@ static df::unit *getAnyUnit(df::viewscreen *top) using df::global::ui_selected_unit; if (VIRTUAL_CAST_VAR(screen, df::viewscreen_joblistst, top)) - return vector_get(screen->units, screen->cursor_pos); + { + if (auto unit = vector_get(screen->units, screen->cursor_pos)) + return unit; + if (auto job = vector_get(screen->jobs, screen->cursor_pos)) + return Job::getWorker(job); + return NULL; + } if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitlistst, top)) return vector_get(screen->units[screen->page], screen->cursor_pos[screen->page]); @@ -781,6 +804,14 @@ static df::item *getAnyItem(df::viewscreen *top) return vector_get(screen->trader_items, screen->trader_cursor); } + if (VIRTUAL_CAST_VAR(screen, df::viewscreen_storesst, top)) + { + if (screen->in_right_list && !screen->in_group_mode) + return vector_get(screen->items, screen->item_cursor); + + return NULL; + } + if (!Gui::dwarfmode_hotkey(top)) return NULL; diff --git a/plugins/sort.cpp b/plugins/sort.cpp index 9274a4cfbf..5748a065bb 100644 --- a/plugins/sort.cpp +++ b/plugins/sort.cpp @@ -6,6 +6,7 @@ #include "modules/Gui.h" #include "modules/Translation.h" #include "modules/Units.h" +#include "modules/Job.h" #include "LuaTools.h" @@ -22,6 +23,7 @@ #include "df/viewscreen_tradegoodsst.h" #include "df/viewscreen_dwarfmodest.h" #include "df/viewscreen_petst.h" +#include "df/viewscreen_storesst.h" #include "df/layer_object_listst.h" #include "df/assign_trade_status.h" @@ -273,7 +275,16 @@ DEFINE_SORT_HANDLER(unit_sorters, joblist, "", jobs) { PARSE_SPEC("units", parameters); - if (compute_order(*pout, L, top, &order, jobs->units)) + std::vector units; + for (size_t i = 0; i < jobs->units.size(); i++) + { + auto unit = jobs->units[i]; + if (!unit && jobs->jobs[i]) + unit = Job::getWorker(jobs->jobs[i]); + units.push_back(unit); + } + + if (compute_order(*pout, L, top, &order, units)) { reorder_cursor(&jobs->cursor_pos, order); reorder_vector(&jobs->units, order); @@ -526,6 +537,17 @@ DEFINE_SORT_HANDLER(item_sorters, layer_assigntrade, "/Items", bring) } } +DEFINE_SORT_HANDLER(item_sorters, stores, "/Items", stocks) +{ + PARSE_SPEC("items", parameters); + + if (compute_order(*pout, L, top, &order, stocks->items)) + { + reorder_cursor(&stocks->item_cursor, order); + reorder_vector(&stocks->items, order); + } +} + static bool item_list_hotkey(df::viewscreen *screen) { auto focus = Gui::getFocusString(screen);