From 51173fb9fea6002c8777ea3ceb30f5a4b674080e Mon Sep 17 00:00:00 2001 From: Mikhail Panov Date: Fri, 29 Sep 2023 17:34:48 +0300 Subject: [PATCH] Removed material and job type sortings. --- docs/plugins/orders.rst | 10 --- plugins/lua/orders.lua | 26 ++----- plugins/orders.cpp | 150 ---------------------------------------- 3 files changed, 6 insertions(+), 180 deletions(-) diff --git a/docs/plugins/orders.rst b/docs/plugins/orders.rst index 9bf220a06..d8d3fe585 100644 --- a/docs/plugins/orders.rst +++ b/docs/plugins/orders.rst @@ -28,16 +28,6 @@ Usage 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 c84dfa5f7..1a3208336 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=73, h=4}, + frame={w=46, h=4}, } function OrdersOverlay:init() @@ -114,31 +114,17 @@ function OrdersOverlay:init() }, 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', + label='sort', key='CUSTOM_CTRL_O', auto_width=true, on_activate=do_sort, }, widgets.HotkeyLabel{ - frame={t=1, l=30}, - label='sort by type', - key='CUSTOM_CTRL_J', - auto_width=true, - on_activate=do_sort_type, - }, - widgets.HotkeyLabel{ - frame={t=0, l=52}, - label='sort by mat', - key='CUSTOM_CTRL_T', + frame={t=0, l=31}, + label='clear', + key='CUSTOM_CTRL_C', auto_width=true, - on_activate=do_sort_mat, + on_activate=do_clear, }, }, } diff --git a/plugins/orders.cpp b/plugins/orders.cpp index 77e8d5fa8..a84f14172 100644 --- a/plugins/orders.cpp +++ b/plugins/orders.cpp @@ -67,8 +67,6 @@ static command_result orders_export_command(color_ostream & out, const std::stri static command_result orders_import_command(color_ostream & out, const std::string & name); static command_result orders_clear_command(color_ostream & out); static command_result orders_sort_command(color_ostream & out); -static command_result orders_sort_type_command(color_ostream & out); -static command_result orders_sort_material_command(color_ostream & out); static command_result orders_recheck_command(color_ostream & out); static command_result orders_recheck_current_command(color_ostream & out); @@ -118,16 +116,6 @@ static command_result orders_command(color_ostream & out, std::vectorfrequency != b->frequency) - { - return compare_freq(a, b); - } - - // Determine if only one order has reaction_name - bool a_has_reaction_name = !a->reaction_name.empty(); - bool b_has_reaction_name = !b->reaction_name.empty(); - - if (a_has_reaction_name != b_has_reaction_name) - { - return a_has_reaction_name; - } - else if (a_has_reaction_name && b_has_reaction_name) - { - if (a->reaction_name != b->reaction_name) - { - return a->reaction_name < b->reaction_name; - } - } - - // Compare 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; - } - } - - // By default orders are the same - return false; -} - -static command_result orders_sort_type_command(color_ostream & out) -{ - CoreSuspender suspend; - if (!std::is_sorted(world->manager_orders.begin(), - world->manager_orders.end(), - compare_type)) - { - std::stable_sort(world->manager_orders.begin(), - world->manager_orders.end(), - compare_type); - out << "Manager orders are sorted by job type." << std::endl; - } - - return CR_OK; -} - -static bool compare_material(df::manager_order *a, df::manager_order *b) -{ - // Goal: Sort orders to easily find them in the list and to see dupclicated orders. - // Sorting by materials - - // Divide orders by frequency first - if (a->frequency != b->frequency) - { - return compare_freq(a, b); - } - - // Determine if only one of the orders has mat_type - bool a_has_material = (a->mat_type != -1 || a->mat_index != -1); - bool b_has_material = (b->mat_type != -1 || b->mat_index != -1); - - if (a_has_material != b_has_material) - { - return a_has_material; - } - else if (a_has_material && b_has_material) - { - // Compare mat_type using MaterialInfo - if (MaterialInfo(a).getToken() != MaterialInfo(b).getToken()) - { - return MaterialInfo(a).getToken() < MaterialInfo(b).getToken(); - } - } - - // Determine if only one order has material_category - bool a_has_material_category = (a->material_category.whole != 0); - bool b_has_material_category = (b->material_category.whole != 0); - - if (a_has_material_category != b_has_material_category) - { - return a_has_material_category; - } - else if (a_has_material_category && b_has_material_category) - { - std::vector a_mats, b_mats; - bitfield_to_string(&a_mats, a->material_category); - bitfield_to_string(&b_mats, b->material_category); - - // Checking that mats are not empty just in case - if (!a_mats.empty() && !b_mats.empty() && a_mats[0] != b_mats[0]) - { - return a_mats[0] < b_mats[0]; - } - } - - // Fall back to material sort - return compare_type(a, b); -} - -static command_result orders_sort_material_command(color_ostream & out) -{ - CoreSuspender suspend; - if (!std::is_sorted(world->manager_orders.begin(), - world->manager_orders.end(), - compare_material)) - { - std::stable_sort(world->manager_orders.begin(), - world->manager_orders.end(), - compare_material); - out << "Manager orders are sorted by material." << std::endl; - } - - return CR_OK; -} - static command_result orders_recheck_command(color_ostream & out) { for (auto it : world->manager_orders)