From 69be3be35963569f9edf56f0e75b2a6ef8407276 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sat, 16 Sep 2023 14:18:06 +0300 Subject: [PATCH] Added sorting by job type and by material for manager orders. Added shortcuts to the manager menu for new functions. --- docs/plugins/orders.rst | 12 ++++++++++++ plugins/lua/orders.lua | 34 +++++++++++++++++----------------- plugins/orders.cpp | 29 ++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/docs/plugins/orders.rst b/docs/plugins/orders.rst index 46a004081..4affa01b3 100644 --- a/docs/plugins/orders.rst +++ b/docs/plugins/orders.rst @@ -17,10 +17,22 @@ Usage manager orders. It will not clear the orders that already exist. ``orders clear`` Deletes all manager orders in the current embark. +``orders reset`` + Invalidates manager orders forcing material conditions recheck. ``orders sort`` Sorts current manager orders by repeat frequency so repeating orders don't prevent one-time orders from ever being completed. The sorting order is: one-time orders first, then yearly, seasonally, monthly, and finally, daily. +``orders sort_type`` + Sorts current manager orders by job type, making it easier to locate orders + that produce similar items. The sorting is done by reaction name, job type + and item subtype. If orders are equal by these fields the sorting falls back + to sort by frequency. +``orders sort_material`` + Sorts current manager orders by material, making it easier to locate orders + that produce items of the same material. The sorting is done by material type + and material category. If orders are equal by these fields the sorting falls back + to sort by job type. You can keep your orders automatically sorted by adding the following command to your ``dfhack-config/init/onMapLoad.init`` file:: diff --git a/plugins/lua/orders.lua b/plugins/lua/orders.lua index 91fd3bef6..510e88b8c 100644 --- a/plugins/lua/orders.lua +++ b/plugins/lua/orders.lua @@ -79,7 +79,7 @@ OrdersOverlay.ATTRS{ default_pos={x=53,y=-6}, default_enabled=true, viewscreens='dwarfmode/Info/WORK_ORDERS/Default', - frame={w=75, h=4}, + frame={w=73, h=4}, } function OrdersOverlay:init() @@ -107,39 +107,39 @@ function OrdersOverlay:init() }, widgets.HotkeyLabel{ frame={t=0, l=15}, + label='reset', + key='CUSTOM_CTRL_R', + auto_width=true, + on_activate=do_reset, + }, + widgets.HotkeyLabel{ + frame={t=1, l=15}, + label='clear', + key='CUSTOM_CTRL_C', + auto_width=true, + on_activate=do_clear, + }, + widgets.HotkeyLabel{ + frame={t=0, l=30}, label='sort by freq', key='CUSTOM_CTRL_O', auto_width=true, on_activate=do_sort, }, widgets.HotkeyLabel{ - frame={t=1, l=15}, + frame={t=1, l=30}, label='sort by type', key='CUSTOM_CTRL_T', auto_width=true, on_activate=do_sort_type, }, widgets.HotkeyLabel{ - frame={t=0, l=35}, + frame={t=0, l=52}, label='sort by mat', key='CUSTOM_CTRL_T', auto_width=true, on_activate=do_sort_mat, }, - widgets.HotkeyLabel{ - frame={t=1, l=35}, - label='reset', - key='CUSTOM_CTRL_R', - auto_width=true, - on_activate=do_reset, - }, - widgets.HotkeyLabel{ - frame={t=1, l=55}, - label='clear', - key='CUSTOM_CTRL_C', - auto_width=true, - on_activate=do_clear, - }, }, } diff --git a/plugins/orders.cpp b/plugins/orders.cpp index ceaf84196..7fcefa745 100644 --- a/plugins/orders.cpp +++ b/plugins/orders.cpp @@ -1056,7 +1056,29 @@ static bool compare_type(df::manager_order *a, df::manager_order *b) } // Compare job_type - return enum_item_key(a->job_type) < enum_item_key(b->job_type); + if (enum_item_key(a->job_type) != enum_item_key(b->job_type)) + { + return enum_item_key(a->job_type) < enum_item_key(b->job_type); + } + + // Compare item subtype + bool a_has_item_subtype = (a->item_subtype != -1); + bool b_has_item_subtype = (b->item_subtype != -1); + + if (a_has_item_subtype != b_has_item_subtype) + { + return a_has_item_subtype; + } + else if (a_has_item_subtype && b_has_item_subtype) + { + if (a->item_subtype != b->item_subtype) + { + return a->item_subtype < b->item_subtype; + } + } + + // Fall back to freq sort + return compare_freq(a, b); } static command_result orders_sort_type_command(color_ostream & out) @@ -1118,9 +1140,10 @@ static bool compare_material(df::manager_order *a, df::manager_order *b) } } - // By default orders are equal - return false; + // Fall back to material sort + return compare_type(a, b); } + static command_result orders_sort_material_command(color_ostream & out) { CoreSuspender suspend;