Add getSelectedCivZone to dfhack.gui

Mostly helpful for my own automation in my custom lua scripts.

Tested it with barracks, meeting areas, and pastures.
develop
Kelvie Wong 2023-02-13 15:21:43 -08:00
parent 6202b29c56
commit f8d94afb7d
5 changed files with 37 additions and 3 deletions

@ -49,6 +49,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Documentation ## Documentation
## API ## API
- ``Gui::any_civzone_hotkey``, ``Gui::getAnyCivZone``, ``Gui::getSelectedCivZone``: new functions to operate on the new zone system
- Units module: added new predicates for: - Units module: added new predicates for:
- ``isGeldable()`` - ``isGeldable()``
@ -56,6 +57,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- ``isPet()`` - ``isPet()``
## Lua ## Lua
- ``dfhack.gui.getSelectedCivZone``: returns the Zone that the user has selected currently
- ``widgets.FilteredList``: Added ``edit_on_change`` optional parameter to allow a custom callback on filter edit change. - ``widgets.FilteredList``: Added ``edit_on_change`` optional parameter to allow a custom callback on filter edit change.

@ -1009,6 +1009,10 @@ General-purpose selections
Returns the building selected via :kbd:`q`, :kbd:`t`, :kbd:`k` or :kbd:`i`. Returns the building selected via :kbd:`q`, :kbd:`t`, :kbd:`k` or :kbd:`i`.
* ``dfhack.gui.getSelectedCivZone([silent])``
Returns the zone currently selected via :kbd:`z`
* ``dfhack.gui.getSelectedPlant([silent])`` * ``dfhack.gui.getSelectedPlant([silent])``
Returns the plant selected via :kbd:`k`. Returns the plant selected via :kbd:`k`.

@ -1476,6 +1476,7 @@ static const LuaWrapper::FunctionReg dfhack_gui_module[] = {
WRAPM(Gui, getSelectedUnit), WRAPM(Gui, getSelectedUnit),
WRAPM(Gui, getSelectedItem), WRAPM(Gui, getSelectedItem),
WRAPM(Gui, getSelectedBuilding), WRAPM(Gui, getSelectedBuilding),
WRAPM(Gui, getSelectedCivZone),
WRAPM(Gui, getSelectedStockpile), WRAPM(Gui, getSelectedStockpile),
WRAPM(Gui, getSelectedPlant), WRAPM(Gui, getSelectedPlant),
WRAPM(Gui, getAnyUnit), WRAPM(Gui, getAnyUnit),

@ -105,11 +105,17 @@ namespace DFHack
DFHACK_EXPORT df::item *getAnyItem(df::viewscreen *top); DFHACK_EXPORT df::item *getAnyItem(df::viewscreen *top);
DFHACK_EXPORT df::item *getSelectedItem(color_ostream &out, bool quiet = false); DFHACK_EXPORT df::item *getSelectedItem(color_ostream &out, bool quiet = false);
// A building is selected via 'q', 't' or 'i' (civzone) // A building is selected via 'q', 't' or 'i' (?)
DFHACK_EXPORT bool any_building_hotkey(df::viewscreen *top); DFHACK_EXPORT bool any_building_hotkey(df::viewscreen *top);
DFHACK_EXPORT df::building *getAnyBuilding(df::viewscreen *top); DFHACK_EXPORT df::building *getAnyBuilding(df::viewscreen *top);
DFHACK_EXPORT df::building *getSelectedBuilding(color_ostream &out, bool quiet = false); DFHACK_EXPORT df::building *getSelectedBuilding(color_ostream &out, bool quiet = false);
// A (civ)zone is selected via 'z'
DFHACK_EXPORT bool any_civzone_hotkey(df::viewscreen* top);
DFHACK_EXPORT df::building_civzonest *getAnyCivZone(df::viewscreen* top);
DFHACK_EXPORT df::building_civzonest *getSelectedCivZone(color_ostream& out, bool quiet = false);
// A stockpile is selected via 'p'
DFHACK_EXPORT bool any_stockpile_hotkey(df::viewscreen* top); DFHACK_EXPORT bool any_stockpile_hotkey(df::viewscreen* top);
DFHACK_EXPORT df::building_stockpilest *getAnyStockpile(df::viewscreen* top); DFHACK_EXPORT df::building_stockpilest *getAnyStockpile(df::viewscreen* top);
DFHACK_EXPORT df::building_stockpilest *getSelectedStockpile(color_ostream& out, bool quiet = false); DFHACK_EXPORT df::building_stockpilest *getSelectedStockpile(color_ostream& out, bool quiet = false);

@ -98,14 +98,15 @@ namespace DFHack
using namespace df::enums; using namespace df::enums;
using df::building_civzonest;
using df::global::game;
using df::global::gamemode; using df::global::gamemode;
using df::global::gps; using df::global::gps;
using df::global::gview; using df::global::gview;
using df::global::init; using df::global::init;
using df::global::selection_rect;
using df::global::plotinfo; using df::global::plotinfo;
using df::global::selection_rect;
using df::global::ui_menu_width; using df::global::ui_menu_width;
using df::global::game;
using df::global::world; using df::global::world;
/* TODO: understand how this changes for v50 /* TODO: understand how this changes for v50
@ -1111,6 +1112,26 @@ df::building_stockpilest* Gui::getSelectedStockpile(color_ostream& out, bool qui
return stockpile; return stockpile;
} }
bool Gui::any_civzone_hotkey(df::viewscreen* top) {
return getAnyCivZone(top) != NULL;
}
df::building_civzonest *Gui::getAnyCivZone(df::viewscreen* top) {
if (matchFocusString("dwarfmode/Zone")) {
return game->main_interface.civzone.cur_bld;
}
return NULL;
}
df::building_civzonest *Gui::getSelectedCivZone(color_ostream &out, bool quiet) {
df::building_civzonest *civzone = getAnyCivZone(Core::getTopViewscreen());
if (!civzone && !quiet)
out.printerr("No zone is selected in the UI");
return civzone;
}
df::building *Gui::getAnyBuilding(df::viewscreen *top) df::building *Gui::getAnyBuilding(df::viewscreen *top)
{ {
using df::global::game; using df::global::game;