Added sorting by job type and by material for manager orders. Added shortcuts to the manager menu for new functions.

develop
Mikhail 2023-09-16 14:18:06 +03:00
parent 28b00d9f21
commit 69be3be359
3 changed files with 55 additions and 20 deletions

@ -17,10 +17,22 @@ Usage
manager orders. It will not clear the orders that already exist. manager orders. It will not clear the orders that already exist.
``orders clear`` ``orders clear``
Deletes all manager orders in the current embark. Deletes all manager orders in the current embark.
``orders reset``
Invalidates manager orders forcing material conditions recheck.
``orders sort`` ``orders sort``
Sorts current manager orders by repeat frequency so repeating orders don't Sorts current manager orders by repeat frequency so repeating orders don't
prevent one-time orders from ever being completed. The sorting order is: prevent one-time orders from ever being completed. The sorting order is:
one-time orders first, then yearly, seasonally, monthly, and finally, daily. 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 You can keep your orders automatically sorted by adding the following command to
your ``dfhack-config/init/onMapLoad.init`` file:: your ``dfhack-config/init/onMapLoad.init`` file::

@ -79,7 +79,7 @@ OrdersOverlay.ATTRS{
default_pos={x=53,y=-6}, default_pos={x=53,y=-6},
default_enabled=true, default_enabled=true,
viewscreens='dwarfmode/Info/WORK_ORDERS/Default', viewscreens='dwarfmode/Info/WORK_ORDERS/Default',
frame={w=75, h=4}, frame={w=73, h=4},
} }
function OrdersOverlay:init() function OrdersOverlay:init()
@ -107,39 +107,39 @@ function OrdersOverlay:init()
}, },
widgets.HotkeyLabel{ widgets.HotkeyLabel{
frame={t=0, l=15}, 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', label='sort by freq',
key='CUSTOM_CTRL_O', key='CUSTOM_CTRL_O',
auto_width=true, auto_width=true,
on_activate=do_sort, on_activate=do_sort,
}, },
widgets.HotkeyLabel{ widgets.HotkeyLabel{
frame={t=1, l=15}, frame={t=1, l=30},
label='sort by type', label='sort by type',
key='CUSTOM_CTRL_T', key='CUSTOM_CTRL_T',
auto_width=true, auto_width=true,
on_activate=do_sort_type, on_activate=do_sort_type,
}, },
widgets.HotkeyLabel{ widgets.HotkeyLabel{
frame={t=0, l=35}, frame={t=0, l=52},
label='sort by mat', label='sort by mat',
key='CUSTOM_CTRL_T', key='CUSTOM_CTRL_T',
auto_width=true, auto_width=true,
on_activate=do_sort_mat, 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,
},
}, },
} }

@ -1056,9 +1056,31 @@ static bool compare_type(df::manager_order *a, df::manager_order *b)
} }
// Compare job_type // 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); 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) static command_result orders_sort_type_command(color_ostream & out)
{ {
CoreSuspender suspend; CoreSuspender suspend;
@ -1118,9 +1140,10 @@ static bool compare_material(df::manager_order *a, df::manager_order *b)
} }
} }
// By default orders are equal // Fall back to material sort
return false; return compare_type(a, b);
} }
static command_result orders_sort_material_command(color_ostream & out) static command_result orders_sort_material_command(color_ostream & out)
{ {
CoreSuspender suspend; CoreSuspender suspend;