diff --git a/docs/changelog.txt b/docs/changelog.txt index df78568b5..d6e9a2695 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -49,6 +49,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Documentation ## API +- ``Gui::any_civzone_hotkey``, ``Gui::getAnyCivZone``, ``Gui::getSelectedCivZone``: new functions to operate on the new zone system - Units module: added new predicates for: - ``isGeldable()`` @@ -56,6 +57,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - ``isPet()`` ## 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. diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 72c6a85ab..1a46cbff1 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -1009,6 +1009,10 @@ General-purpose selections 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])`` Returns the plant selected via :kbd:`k`. diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index ce1f66091..2dc2ddf8b 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1476,6 +1476,7 @@ static const LuaWrapper::FunctionReg dfhack_gui_module[] = { WRAPM(Gui, getSelectedUnit), WRAPM(Gui, getSelectedItem), WRAPM(Gui, getSelectedBuilding), + WRAPM(Gui, getSelectedCivZone), WRAPM(Gui, getSelectedStockpile), WRAPM(Gui, getSelectedPlant), WRAPM(Gui, getAnyUnit), diff --git a/library/include/modules/Gui.h b/library/include/modules/Gui.h index b579dcc97..bbdaa0d39 100644 --- a/library/include/modules/Gui.h +++ b/library/include/modules/Gui.h @@ -105,11 +105,17 @@ namespace DFHack DFHACK_EXPORT df::item *getAnyItem(df::viewscreen *top); 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 df::building *getAnyBuilding(df::viewscreen *top); 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 df::building_stockpilest *getAnyStockpile(df::viewscreen* top); DFHACK_EXPORT df::building_stockpilest *getSelectedStockpile(color_ostream& out, bool quiet = false); diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 56f8bc301..e3a7ba983 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -98,14 +98,15 @@ namespace DFHack using namespace df::enums; +using df::building_civzonest; +using df::global::game; using df::global::gamemode; using df::global::gps; using df::global::gview; using df::global::init; -using df::global::selection_rect; using df::global::plotinfo; +using df::global::selection_rect; using df::global::ui_menu_width; -using df::global::game; using df::global::world; /* TODO: understand how this changes for v50 @@ -1111,6 +1112,26 @@ df::building_stockpilest* Gui::getSelectedStockpile(color_ostream& out, bool qui 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) { using df::global::game;