Add an API function that returns the selected building.

develop
Alexander Gavrilov 2012-09-20 10:41:03 +04:00
parent 1fd0654d63
commit 7ce772ae0e
5 changed files with 70 additions and 0 deletions

@ -777,6 +777,10 @@ Gui module
last case, the highlighted *contained item* is returned, not
the container itself.
* ``dfhack.gui.getSelectedBuilding([silent])``
Returns the building selected via *'q'*, *'t'*, *'k'* or *'i'*.
* ``dfhack.gui.showAnnouncement(text,color[,is_bright])``
Adds a regular announcement with given text, color, and brightness.

@ -1032,6 +1032,9 @@ a full-screen item view of a container. Note that in the
last case, the highlighted <em>contained item</em> is returned, not
the container itself.</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">dfhack.gui.getSelectedBuilding([silent])</span></tt></p>
<p>Returns the building selected via <em>'q'</em>, <em>'t'</em>, <em>'k'</em> or <em>'i'</em>.</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">dfhack.gui.showAnnouncement(text,color[,is_bright])</span></tt></p>
<p>Adds a regular announcement with given text, color, and brightness.
The is_bright boolean actually seems to invert the brightness.</p>

@ -760,6 +760,7 @@ static const LuaWrapper::FunctionReg dfhack_gui_module[] = {
WRAPM(Gui, getSelectedJob),
WRAPM(Gui, getSelectedUnit),
WRAPM(Gui, getSelectedItem),
WRAPM(Gui, getSelectedBuilding),
WRAPM(Gui, showAnnouncement),
WRAPM(Gui, showZoomAnnouncement),
WRAPM(Gui, showPopupAnnouncement),

@ -91,6 +91,10 @@ namespace DFHack
DFHACK_EXPORT bool any_item_hotkey(df::viewscreen *top);
DFHACK_EXPORT df::item *getSelectedItem(color_ostream &out, bool quiet = false);
// A building is selected via 'q', 't' or 'i' (civzone)
DFHACK_EXPORT bool any_building_hotkey(df::viewscreen *top);
DFHACK_EXPORT df::building *getSelectedBuilding(color_ostream &out, bool quiet = false);
// Show a plain announcement, or a titan-style popup message
DFHACK_EXPORT void showAnnouncement(std::string message, int color = 7, bool bright = true);
DFHACK_EXPORT void showZoomAnnouncement(df::announcement_type type, df::coord pos, std::string message, int color = 7, bool bright = true);

@ -933,6 +933,64 @@ df::item *Gui::getSelectedItem(color_ostream &out, bool quiet)
return item;
}
static df::building *getAnyBuilding(df::viewscreen *top)
{
using namespace ui_sidebar_mode;
using df::global::ui;
using df::global::ui_look_list;
using df::global::ui_look_cursor;
using df::global::world;
using df::global::ui_sidebar_menus;
if (!Gui::dwarfmode_hotkey(top))
return NULL;
switch (ui->main.mode) {
case LookAround:
{
if (!ui_look_list || !ui_look_cursor)
return NULL;
auto item = vector_get(ui_look_list->items, *ui_look_cursor);
if (item && item->type == df::ui_look_list::T_items::Building)
return item->building;
else
return NULL;
}
case QueryBuilding:
case BuildingItems:
{
return world->selected_building;
}
case Zones:
case ZonesPenInfo:
case ZonesPitInfo:
case ZonesHospitalInfo:
{
if (ui_sidebar_menus)
return ui_sidebar_menus->zone.selected;
return NULL;
}
default:
return NULL;
}
}
bool Gui::any_building_hotkey(df::viewscreen *top)
{
return getAnyBuilding(top) != NULL;
}
df::building *Gui::getSelectedBuilding(color_ostream &out, bool quiet)
{
df::building *building = getAnyBuilding(Core::getTopViewscreen());
if (!building && !quiet)
out.printerr("No building is selected in the UI.\n");
return building;
}
//
static void doShowAnnouncement(