|
|
@ -204,7 +204,8 @@ static bool ParseSpec(color_ostream &out, lua_State *L, const char *type, vector
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define PARSE_SPEC(type, params) \
|
|
|
|
#define PARSE_SPEC(type, params) \
|
|
|
|
if (!ParseSpec(*pout, L, type, params)) return false;
|
|
|
|
std::vector<unsigned> order; \
|
|
|
|
|
|
|
|
if (!ParseSpec(*pout, L, type, params)) return;
|
|
|
|
|
|
|
|
|
|
|
|
static bool prepare_sort(color_ostream *pout, lua_State *L)
|
|
|
|
static bool prepare_sort(color_ostream *pout, lua_State *L)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -230,24 +231,28 @@ static df::layer_object_listst *getLayerList(df::viewscreen_layerst *layer, int
|
|
|
|
return virtual_cast<df::layer_object_listst>(vector_get(layer->layer_objects,idx));
|
|
|
|
return virtual_cast<df::layer_object_listst>(vector_get(layer->layer_objects,idx));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
typedef void (*SortHandler)(color_ostream *pout, lua_State *L, int top,
|
|
|
|
df::viewscreen *screen, vector<string> ¶meters)
|
|
|
|
df::viewscreen *screen, vector<string> ¶meters);
|
|
|
|
{
|
|
|
|
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!prepare_sort(pout, L))
|
|
|
|
#define VIEWSCREEN(name) df::viewscreen_##name##st
|
|
|
|
return false;
|
|
|
|
#define DEFINE_SORT_HANDLER(map, screen_type, tail, screen) \
|
|
|
|
|
|
|
|
static void CONCAT_TOKENS(SortHandler_##screen_type,__LINE__)\
|
|
|
|
|
|
|
|
(color_ostream *pout, lua_State *L, int top, \
|
|
|
|
|
|
|
|
VIEWSCREEN(screen_type) *screen, vector<string> ¶meters); \
|
|
|
|
|
|
|
|
DFHACK_STATIC_ADD_TO_MAP(&map, #screen_type tail, \
|
|
|
|
|
|
|
|
(SortHandler)CONCAT_TOKENS(SortHandler_##screen_type,__LINE__) ); \
|
|
|
|
|
|
|
|
static void CONCAT_TOKENS(SortHandler_##screen_type,__LINE__)\
|
|
|
|
|
|
|
|
(color_ostream *pout, lua_State *L, int top, \
|
|
|
|
|
|
|
|
VIEWSCREEN(screen_type) *screen, vector<string> ¶meters)
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<unsigned> order;
|
|
|
|
static std::map<std::string, SortHandler> unit_sorters;
|
|
|
|
|
|
|
|
|
|
|
|
if (auto units = strict_virtual_cast<df::viewscreen_unitlistst>(screen))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Sort units in the 'u'nit list screen.
|
|
|
|
* Sort units in the 'u'nit list screen.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, unitlist, "", units)
|
|
|
|
|
|
|
|
{
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
|
|
int page = units->page;
|
|
|
|
int page = units->page;
|
|
|
@ -258,17 +263,14 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_vector(&units->units[page], order);
|
|
|
|
reorder_vector(&units->units[page], order);
|
|
|
|
reorder_vector(&units->jobs[page], order);
|
|
|
|
reorder_vector(&units->jobs[page], order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (auto jobs = strict_virtual_cast<df::viewscreen_joblistst>(screen))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Sort units in the 'j'ob list screen.
|
|
|
|
* Sort units in the 'j'ob list screen.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, joblist, "", jobs)
|
|
|
|
|
|
|
|
{
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
|
|
if (compute_order(*pout, L, top, &order, jobs->units))
|
|
|
|
if (compute_order(*pout, L, top, &order, jobs->units))
|
|
|
@ -277,25 +279,16 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_vector(&jobs->units, order);
|
|
|
|
reorder_vector(&jobs->units, order);
|
|
|
|
reorder_vector(&jobs->jobs, order);
|
|
|
|
reorder_vector(&jobs->jobs, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (auto military = strict_virtual_cast<df::viewscreen_layer_militaryst>(screen))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (military->page)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case df::viewscreen_layer_militaryst::Positions:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto &candidates = military->positions.candidates;
|
|
|
|
|
|
|
|
auto list3 = getLayerList(military, 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Sort candidate units in the 'p'osition page of the 'm'ilitary screen.
|
|
|
|
* Sort candidate units in the 'p'osition page of the 'm'ilitary screen.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
if (list3 && !candidates.empty() && list3->bright)
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, layer_military, "/Positions/Candidates", military)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!L) return true;
|
|
|
|
auto &candidates = military->positions.candidates;
|
|
|
|
|
|
|
|
auto list3 = getLayerList(military, 2);
|
|
|
|
|
|
|
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
|
@ -304,28 +297,17 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_cursor(&list3->cursor, order);
|
|
|
|
reorder_cursor(&list3->cursor, order);
|
|
|
|
reorder_vector(&candidates, order);
|
|
|
|
reorder_vector(&candidates, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (auto profile = strict_virtual_cast<df::viewscreen_layer_workshop_profilest>(screen))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto list1 = getLayerList(profile, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!list1) return false;
|
|
|
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Sort units in the workshop 'q'uery 'P'rofile modification screen.
|
|
|
|
* Sort units in the workshop 'q'uery 'P'rofile modification screen.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, layer_workshop_profile, "/Unit", profile)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto list1 = getLayerList(profile, 0);
|
|
|
|
|
|
|
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
|
|
if (compute_order(*pout, L, top, &order, profile->workers))
|
|
|
|
if (compute_order(*pout, L, top, &order, profile->workers))
|
|
|
@ -333,24 +315,11 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_cursor(&list1->cursor, order);
|
|
|
|
reorder_cursor(&list1->cursor, order);
|
|
|
|
reorder_vector(&profile->workers, order);
|
|
|
|
reorder_vector(&profile->workers, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (auto nobles = strict_virtual_cast<df::viewscreen_layer_noblelistst>(screen))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (nobles->mode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case df::viewscreen_layer_noblelistst::Appoint:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto list2 = getLayerList(nobles, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, layer_noblelist, "/Appoint", nobles)
|
|
|
|
* Sort units in the appointment candidate list of the 'n'obles screen.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (list2)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!L) return true;
|
|
|
|
auto list2 = getLayerList(nobles, 1);
|
|
|
|
|
|
|
|
|
|
|
|
sort_null_first(parameters);
|
|
|
|
sort_null_first(parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
@ -364,29 +333,14 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_cursor(&list2->cursor, order);
|
|
|
|
reorder_cursor(&list2->cursor, order);
|
|
|
|
reorder_vector(&nobles->candidates, order);
|
|
|
|
reorder_vector(&nobles->candidates, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (auto animals = strict_virtual_cast<df::viewscreen_petst>(screen))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (animals->mode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case df::viewscreen_petst::List:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Sort animal units in the Animal page of the 'z' status screen.
|
|
|
|
* Sort animal units in the Animal page of the 'z' status screen.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, pet, "/List", animals)
|
|
|
|
|
|
|
|
{
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<df::unit*> units;
|
|
|
|
std::vector<df::unit*> units;
|
|
|
@ -402,18 +356,14 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_vector(&animals->is_tame, order);
|
|
|
|
reorder_vector(&animals->is_tame, order);
|
|
|
|
reorder_vector(&animals->is_adopting, order);
|
|
|
|
reorder_vector(&animals->is_adopting, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case df::viewscreen_petst::SelectTrainer:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Sort candidate trainers in the Animal page of the 'z' status screen.
|
|
|
|
* Sort candidate trainers in the Animal page of the 'z' status screen.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, pet, "/SelectTrainer", animals)
|
|
|
|
|
|
|
|
{
|
|
|
|
sort_null_first(parameters);
|
|
|
|
sort_null_first(parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
|
@ -423,25 +373,16 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_vector(&animals->trainer_unit, order);
|
|
|
|
reorder_vector(&animals->trainer_unit, order);
|
|
|
|
reorder_vector(&animals->trainer_mode, order);
|
|
|
|
reorder_vector(&animals->trainer_mode, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (auto health = strict_virtual_cast<df::viewscreen_layer_overall_healthst>(screen))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto list1 = getLayerList(health, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!list1) return false;
|
|
|
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Sort units in the Health page of the 'z' status screen.
|
|
|
|
* Sort units in the Health page of the 'z' status screen.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, layer_overall_health, "/Units", health)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto list1 = getLayerList(health, 0);
|
|
|
|
|
|
|
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
|
|
if (compute_order(*pout, L, top, &order, health->unit))
|
|
|
|
if (compute_order(*pout, L, top, &order, health->unit))
|
|
|
@ -452,20 +393,14 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_vector(&health->bits2, order);
|
|
|
|
reorder_vector(&health->bits2, order);
|
|
|
|
reorder_vector(&health->bits3, order);
|
|
|
|
reorder_vector(&health->bits3, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strict_virtual_cast<df::viewscreen_dwarfmodest>(screen))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (ui->main.mode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case ui_sidebar_mode::Burrows:
|
|
|
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Sort burrow member candidate units in the 'w' sidebar mode.
|
|
|
|
* Sort burrow member candidate units in the 'w' sidebar mode.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, dwarfmode, "/Burrows/AddUnits", screen)
|
|
|
|
|
|
|
|
{
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
|
|
if (compute_order(*pout, L, top, &order, ui->burrows.list_units))
|
|
|
|
if (compute_order(*pout, L, top, &order, ui->burrows.list_units))
|
|
|
@ -474,36 +409,32 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_vector(&ui->burrows.list_units, order);
|
|
|
|
reorder_vector(&ui->burrows.list_units, order);
|
|
|
|
reorder_vector(&ui->burrows.sel_units, order);
|
|
|
|
reorder_vector(&ui->burrows.sel_units, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Sort building owner candidate units in the 'q' sidebar mode, or cage assignment.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
case ui_sidebar_mode::QueryBuilding:
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, dwarfmode, "/QueryBuilding/Some/Assign", screen)
|
|
|
|
if (!ui_building_in_assign || !*ui_building_in_assign)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
sort_null_first(parameters);
|
|
|
|
// fall through for building owner / chain assign animal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case ui_sidebar_mode::ZonesPenInfo:
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
if (ui_building_item_cursor &&
|
|
|
|
|
|
|
|
ui_building_assign_type &&
|
|
|
|
if (compute_order(*pout, L, top, &order, *ui_building_assign_units))
|
|
|
|
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;
|
|
|
|
reorder_cursor(ui_building_item_cursor, order);
|
|
|
|
|
|
|
|
reorder_vector(ui_building_assign_type, order);
|
|
|
|
|
|
|
|
reorder_vector(ui_building_assign_units, order);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Sort building owner candidate units in the 'q' sidebar mode,
|
|
|
|
* Sort pen assignment candidate units in 'z'->'N'.
|
|
|
|
* or pen assignment candidate units in 'z'->'N', or cage assignment.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: better way
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, dwarfmode, "/ZonesPenInfo/Assign", screen)
|
|
|
|
bool is_assign_owner = ((*ui_building_assign_type)[0] == -1);
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (is_assign_owner)
|
|
|
|
|
|
|
|
sort_null_first(parameters);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
|
|
if (compute_order(*pout, L, top, &order, *ui_building_assign_units))
|
|
|
|
if (compute_order(*pout, L, top, &order, *ui_building_assign_units))
|
|
|
@ -511,29 +442,15 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_cursor(ui_building_item_cursor, order);
|
|
|
|
reorder_cursor(ui_building_item_cursor, order);
|
|
|
|
reorder_vector(ui_building_assign_type, order);
|
|
|
|
reorder_vector(ui_building_assign_type, order);
|
|
|
|
reorder_vector(ui_building_assign_units, 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);
|
|
|
|
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);
|
|
|
|
reorder_vector(ui_building_assign_is_marked, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool unit_list_hotkey(df::viewscreen *screen)
|
|
|
|
static bool unit_list_hotkey(df::viewscreen *screen)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
vector<string> dummy;
|
|
|
|
auto focus = Gui::getFocusString(screen);
|
|
|
|
return maybe_sort_units(NULL, NULL, screen, dummy);
|
|
|
|
return findPrefixInMap(unit_sorters, focus) != NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static command_result sort_units(color_ostream &out, vector <string> ¶meters)
|
|
|
|
static command_result sort_units(color_ostream &out, vector <string> ¶meters)
|
|
|
@ -544,30 +461,28 @@ static command_result sort_units(color_ostream &out, vector <string> ¶meters
|
|
|
|
auto L = Lua::Core::State;
|
|
|
|
auto L = Lua::Core::State;
|
|
|
|
auto screen = Core::getInstance().getTopViewscreen();
|
|
|
|
auto screen = Core::getInstance().getTopViewscreen();
|
|
|
|
|
|
|
|
|
|
|
|
if (!maybe_sort_units(&out, L, screen, parameters))
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!prepare_sort(&out, L))
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
auto focus = Gui::getFocusString(screen);
|
|
|
|
}
|
|
|
|
auto handler = findPrefixInMap(unit_sorters, focus);
|
|
|
|
|
|
|
|
|
|
|
|
static bool maybe_sort_items(color_ostream *pout, lua_State *L,
|
|
|
|
if (!handler)
|
|
|
|
df::viewscreen *screen, vector<string> ¶meters)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
{
|
|
|
|
else
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
handler(&out, L, top, screen, parameters);
|
|
|
|
|
|
|
|
|
|
|
|
if (!prepare_sort(pout, L))
|
|
|
|
return CR_OK;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<unsigned> order;
|
|
|
|
static std::map<std::string, SortHandler> item_sorters;
|
|
|
|
|
|
|
|
|
|
|
|
if (auto trade = strict_virtual_cast<df::viewscreen_tradegoodsst>(screen))
|
|
|
|
DEFINE_SORT_HANDLER(item_sorters, tradegoods, "/Items/Broker", trade)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!L) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PARSE_SPEC("items", parameters);
|
|
|
|
PARSE_SPEC("items", parameters);
|
|
|
|
|
|
|
|
|
|
|
|
if (trade->in_right_pane)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (compute_order(*pout, L, top, &order, trade->broker_items))
|
|
|
|
if (compute_order(*pout, L, top, &order, trade->broker_items))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
reorder_cursor(&trade->broker_cursor, order);
|
|
|
|
reorder_cursor(&trade->broker_cursor, order);
|
|
|
@ -576,8 +491,11 @@ static bool maybe_sort_items(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_vector(&trade->broker_count, order);
|
|
|
|
reorder_vector(&trade->broker_count, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(item_sorters, tradegoods, "/Items/Trader", trade)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
PARSE_SPEC("items", parameters);
|
|
|
|
|
|
|
|
|
|
|
|
if (compute_order(*pout, L, top, &order, trade->trader_items))
|
|
|
|
if (compute_order(*pout, L, top, &order, trade->trader_items))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
reorder_cursor(&trade->trader_cursor, order);
|
|
|
|
reorder_cursor(&trade->trader_cursor, order);
|
|
|
@ -587,21 +505,11 @@ static bool maybe_sort_items(color_ostream *pout, lua_State *L,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
DEFINE_SORT_HANDLER(item_sorters, layer_assigntrade, "/Items", bring)
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (auto bring = strict_virtual_cast<df::viewscreen_layer_assigntradest>(screen))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto list1 = getLayerList(bring, 0);
|
|
|
|
auto list1 = getLayerList(bring, 0);
|
|
|
|
auto list2 = getLayerList(bring, 1);
|
|
|
|
auto list2 = getLayerList(bring, 1);
|
|
|
|
if (!list1 || !list2 || !list2->bright)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int list_idx = vector_get(bring->visible_lists, list1->cursor, (int16_t)-1);
|
|
|
|
int list_idx = vector_get(bring->visible_lists, list1->cursor, (int16_t)-1);
|
|
|
|
unsigned num_lists = sizeof(bring->lists)/sizeof(std::vector<int32_t>);
|
|
|
|
|
|
|
|
if (unsigned(list_idx) >= num_lists)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PARSE_SPEC("items", parameters);
|
|
|
|
PARSE_SPEC("items", parameters);
|
|
|
|
|
|
|
|
|
|
|
@ -616,17 +524,12 @@ static bool maybe_sort_items(color_ostream *pout, lua_State *L,
|
|
|
|
reorder_cursor(&list2->cursor, order);
|
|
|
|
reorder_cursor(&list2->cursor, order);
|
|
|
|
reorder_vector(&vec, order);
|
|
|
|
reorder_vector(&vec, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool item_list_hotkey(df::viewscreen *screen)
|
|
|
|
static bool item_list_hotkey(df::viewscreen *screen)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
vector<string> dummy;
|
|
|
|
auto focus = Gui::getFocusString(screen);
|
|
|
|
return maybe_sort_items(NULL, NULL, screen, dummy);
|
|
|
|
return findPrefixInMap(item_sorters, focus) != NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static command_result sort_items(color_ostream &out, vector <string> ¶meters)
|
|
|
|
static command_result sort_items(color_ostream &out, vector <string> ¶meters)
|
|
|
@ -637,8 +540,18 @@ static command_result sort_items(color_ostream &out, vector <string> ¶meters
|
|
|
|
auto L = Lua::Core::State;
|
|
|
|
auto L = Lua::Core::State;
|
|
|
|
auto screen = Core::getInstance().getTopViewscreen();
|
|
|
|
auto screen = Core::getInstance().getTopViewscreen();
|
|
|
|
|
|
|
|
|
|
|
|
if (!maybe_sort_items(&out, L, screen, parameters))
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!prepare_sort(&out, L))
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto focus = Gui::getFocusString(screen);
|
|
|
|
|
|
|
|
auto handler = findPrefixInMap(item_sorters, focus);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!handler)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
handler(&out, L, top, screen, parameters);
|
|
|
|
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|