|
|
|
@ -204,7 +204,8 @@ static bool ParseSpec(color_ostream &out, lua_State *L, const char *type, vector
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#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)
|
|
|
|
|
{
|
|
|
|
@ -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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
|
df::viewscreen *screen, vector<string> ¶meters)
|
|
|
|
|
{
|
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
|
|
|
|
|
|
if (!prepare_sort(pout, L))
|
|
|
|
|
return false;
|
|
|
|
|
typedef void (*SortHandler)(color_ostream *pout, lua_State *L, int top,
|
|
|
|
|
df::viewscreen *screen, vector<string> ¶meters);
|
|
|
|
|
|
|
|
|
|
std::vector<unsigned> order;
|
|
|
|
|
#define VIEWSCREEN(name) df::viewscreen_##name##st
|
|
|
|
|
#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)
|
|
|
|
|
|
|
|
|
|
if (auto units = strict_virtual_cast<df::viewscreen_unitlistst>(screen))
|
|
|
|
|
{
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
static std::map<std::string, SortHandler> unit_sorters;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
/*
|
|
|
|
|
* Sort units in the 'u'nit list screen.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, unitlist, "", units)
|
|
|
|
|
{
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
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->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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, joblist, "", jobs)
|
|
|
|
|
{
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
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->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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (list3 && !candidates.empty() && list3->bright)
|
|
|
|
|
{
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, layer_military, "/Positions/Candidates", military)
|
|
|
|
|
{
|
|
|
|
|
auto &candidates = military->positions.candidates;
|
|
|
|
|
auto list3 = getLayerList(military, 2);
|
|
|
|
|
|
|
|
|
|
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_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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, layer_workshop_profile, "/Unit", profile)
|
|
|
|
|
{
|
|
|
|
|
auto list1 = getLayerList(profile, 0);
|
|
|
|
|
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
if (compute_order(*pout, L, top, &order, profile->workers))
|
|
|
|
@ -333,25 +315,12 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
|
reorder_cursor(&list1->cursor, 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:
|
|
|
|
|
{
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, layer_noblelist, "/Appoint", nobles)
|
|
|
|
|
{
|
|
|
|
|
auto list2 = getLayerList(nobles, 1);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Sort units in the appointment candidate list of the 'n'obles screen.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (list2)
|
|
|
|
|
{
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
|
|
|
|
|
sort_null_first(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_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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, pet, "/List", animals)
|
|
|
|
|
{
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
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_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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, pet, "/SelectTrainer", animals)
|
|
|
|
|
{
|
|
|
|
|
sort_null_first(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_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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, layer_overall_health, "/Units", health)
|
|
|
|
|
{
|
|
|
|
|
auto list1 = getLayerList(health, 0);
|
|
|
|
|
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
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->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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, dwarfmode, "/Burrows/AddUnits", screen)
|
|
|
|
|
{
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
if (compute_order(*pout, L, top, &order, ui->burrows.list_units))
|
|
|
|
@ -474,34 +409,14 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
|
reorder_vector(&ui->burrows.list_units, order);
|
|
|
|
|
reorder_vector(&ui->burrows.sel_units, order);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case ui_sidebar_mode::QueryBuilding:
|
|
|
|
|
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,
|
|
|
|
|
* or pen assignment candidate units in 'z'->'N', or cage assignment.
|
|
|
|
|
/*
|
|
|
|
|
* Sort building owner candidate units in the 'q' sidebar mode, or cage assignment.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// TODO: better way
|
|
|
|
|
bool is_assign_owner = ((*ui_building_assign_type)[0] == -1);
|
|
|
|
|
|
|
|
|
|
if (is_assign_owner)
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, dwarfmode, "/QueryBuilding/Some/Assign", screen)
|
|
|
|
|
{
|
|
|
|
|
sort_null_first(parameters);
|
|
|
|
|
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
@ -511,29 +426,31 @@ static bool maybe_sort_units(color_ostream *pout, lua_State *L,
|
|
|
|
|
reorder_cursor(ui_building_item_cursor, 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;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
/*
|
|
|
|
|
* Sort pen assignment candidate units in 'z'->'N'.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
DEFINE_SORT_HANDLER(unit_sorters, dwarfmode, "/ZonesPenInfo/Assign", screen)
|
|
|
|
|
{
|
|
|
|
|
PARSE_SPEC("units", parameters);
|
|
|
|
|
|
|
|
|
|
if (compute_order(*pout, L, top, &order, *ui_building_assign_units))
|
|
|
|
|
{
|
|
|
|
|
reorder_cursor(ui_building_item_cursor, order);
|
|
|
|
|
reorder_vector(ui_building_assign_type, order);
|
|
|
|
|
reorder_vector(ui_building_assign_units, order);
|
|
|
|
|
reorder_vector(ui_building_assign_items, order);
|
|
|
|
|
reorder_vector(ui_building_assign_is_marked, order);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool unit_list_hotkey(df::viewscreen *screen)
|
|
|
|
|
{
|
|
|
|
|
vector<string> dummy;
|
|
|
|
|
return maybe_sort_units(NULL, NULL, screen, dummy);
|
|
|
|
|
auto focus = Gui::getFocusString(screen);
|
|
|
|
|
return findPrefixInMap(unit_sorters, focus) != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 screen = Core::getInstance().getTopViewscreen();
|
|
|
|
|
|
|
|
|
|
if (!maybe_sort_units(&out, L, screen, parameters))
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
if (!prepare_sort(&out, L))
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
static bool maybe_sort_items(color_ostream *pout, lua_State *L,
|
|
|
|
|
df::viewscreen *screen, vector<string> ¶meters)
|
|
|
|
|
{
|
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
|
auto focus = Gui::getFocusString(screen);
|
|
|
|
|
auto handler = findPrefixInMap(unit_sorters, focus);
|
|
|
|
|
|
|
|
|
|
if (!prepare_sort(pout, L))
|
|
|
|
|
return false;
|
|
|
|
|
if (!handler)
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
else
|
|
|
|
|
handler(&out, L, top, screen, parameters);
|
|
|
|
|
|
|
|
|
|
std::vector<unsigned> order;
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (auto trade = strict_virtual_cast<df::viewscreen_tradegoodsst>(screen))
|
|
|
|
|
{
|
|
|
|
|
if (!L) return true;
|
|
|
|
|
static std::map<std::string, SortHandler> item_sorters;
|
|
|
|
|
|
|
|
|
|
DEFINE_SORT_HANDLER(item_sorters, tradegoods, "/Items/Broker", trade)
|
|
|
|
|
{
|
|
|
|
|
PARSE_SPEC("items", parameters);
|
|
|
|
|
|
|
|
|
|
if (trade->in_right_pane)
|
|
|
|
|
{
|
|
|
|
|
if (compute_order(*pout, L, top, &order, trade->broker_items))
|
|
|
|
|
{
|
|
|
|
|
reorder_cursor(&trade->broker_cursor, order);
|
|
|
|
@ -575,9 +490,12 @@ static bool maybe_sort_items(color_ostream *pout, lua_State *L,
|
|
|
|
|
reorder_vector(&trade->broker_selected, 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))
|
|
|
|
|
{
|
|
|
|
|
reorder_cursor(&trade->trader_cursor, order);
|
|
|
|
@ -585,23 +503,13 @@ static bool maybe_sort_items(color_ostream *pout, lua_State *L,
|
|
|
|
|
reorder_vector(&trade->trader_selected, order);
|
|
|
|
|
reorder_vector(&trade->trader_count, order);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (auto bring = strict_virtual_cast<df::viewscreen_layer_assigntradest>(screen))
|
|
|
|
|
{
|
|
|
|
|
DEFINE_SORT_HANDLER(item_sorters, layer_assigntrade, "/Items", bring)
|
|
|
|
|
{
|
|
|
|
|
auto list1 = getLayerList(bring, 0);
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
@ -616,17 +524,12 @@ static bool maybe_sort_items(color_ostream *pout, lua_State *L,
|
|
|
|
|
reorder_cursor(&list2->cursor, order);
|
|
|
|
|
reorder_vector(&vec, order);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool item_list_hotkey(df::viewscreen *screen)
|
|
|
|
|
{
|
|
|
|
|
vector<string> dummy;
|
|
|
|
|
return maybe_sort_items(NULL, NULL, screen, dummy);
|
|
|
|
|
auto focus = Gui::getFocusString(screen);
|
|
|
|
|
return findPrefixInMap(item_sorters, focus) != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 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;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|