Implement unit sorting for the pen zone assignment interface.

develop
Alexander Gavrilov 2012-04-25 18:28:00 +04:00
parent 763a301b4f
commit 1cd802d426
2 changed files with 34 additions and 9 deletions

@ -1 +1 @@
Subproject commit 0ec109ce5643be2c3ebcd4d652aeafaf78f33da7
Subproject commit f649d31001e6023a9df5fe83c7971c17afe0d87d

@ -34,9 +34,12 @@ using namespace df::enums;
using df::global::ui;
using df::global::world;
using df::global::ui_building_in_owner;
using df::global::ui_building_in_assign;
using df::global::ui_building_item_cursor;
using df::global::ui_owner_candidates;
using df::global::ui_building_assign_type;
using df::global::ui_building_assign_is_marked;
using df::global::ui_building_assign_units;
using df::global::ui_building_assign_items;
static bool unit_list_hotkey(df::viewscreen *top);
@ -452,22 +455,44 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
return true;
case ui_sidebar_mode::QueryBuilding:
if (ui_building_in_owner && *ui_building_in_owner &&
ui_owner_candidates && ui_building_item_cursor)
if (!ui_building_in_assign || !*ui_building_in_assign)
return false;
// fall through for building owner / chain assign animal
case ui_sidebar_mode::ZonesPenInfo:
if (ui_building_item_cursor &&
ui_building_assign_type &&
ui_building_assign_is_marked &&
ui_building_assign_units &&
ui_building_assign_items &&
ui_building_assign_type->size() == ui_building_assign_units->size() &&
!ui_building_assign_type->empty())
{
if (!L) return true;
/*
* Sort building owner candidate units in the 'q' sidebar mode.
* Sort building owner candidate units in the 'q' sidebar mode,
* or pen assignment candidate units in 'z'->'N', or cage assignment.
*/
sort_null_first(parameters);
// TODO: better way
bool is_assign_owner = ((*ui_building_assign_type)[0] == -1);
if (is_assign_owner)
sort_null_first(parameters);
PARSE_SPEC("units", parameters);
if (compute_order(*pout, L, top, &order, *ui_owner_candidates))
if (compute_order(*pout, L, top, &order, *ui_building_assign_units))
{
reorder_cursor(ui_building_item_cursor, order);
reorder_vector(ui_owner_candidates, order);
reorder_vector(ui_building_assign_type, order);
reorder_vector(ui_building_assign_units, order);
if (ui_building_assign_units->size() == ui_building_assign_items->size())
reorder_vector(ui_building_assign_items, order);
if (ui_building_assign_units->size() == ui_building_assign_is_marked->size())
reorder_vector(ui_building_assign_is_marked, order);
}
return true;