Merge pull request #2577 from myk002/myk_get_any

get rudimentary getAny(Unit|Item|Building) working
develop
Myk 2023-01-09 23:50:02 -08:00 committed by GitHub
commit c26ed36893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

@ -764,6 +764,23 @@ function ZScreen:isMouseOver()
end end
end end
local function zscreen_get_any(scr, thing)
if not scr._native or not scr._native.parent then return nil end
return dfhack.gui['getAny'..thing](scr._native.parent)
end
function ZScreen:onGetSelectedUnit()
return zscreen_get_any(self, 'Unit')
end
function ZScreen:onGetSelectedItem()
return zscreen_get_any(self, 'Item')
end
function ZScreen:onGetSelectedBuilding()
return zscreen_get_any(self, 'Building')
end
function ZScreen:onGetSelectedPlant()
return zscreen_get_any(self, 'Plant')
end
-------------------------- --------------------------
-- Framed screen object -- -- Framed screen object --
-------------------------- --------------------------

@ -832,6 +832,15 @@ df::job *Gui::getSelectedJob(color_ostream &out, bool quiet)
df::unit *Gui::getAnyUnit(df::viewscreen *top) df::unit *Gui::getAnyUnit(df::viewscreen *top)
{ {
using df::global::game;
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
return dfscreen->getSelectedUnit();
if (game->main_interface.view_sheets.open
&& game->main_interface.view_sheets.active_sheet == view_sheet_type::UNIT)
return df::unit::find(game->main_interface.view_sheets.active_id);
/* TODO: understand how this changes for v50 /* TODO: understand how this changes for v50
using namespace ui_sidebar_mode; using namespace ui_sidebar_mode;
using df::global::ui_look_cursor; using df::global::ui_look_cursor;
@ -1114,6 +1123,15 @@ df::unit *Gui::getSelectedUnit(color_ostream &out, bool quiet)
df::item *Gui::getAnyItem(df::viewscreen *top) df::item *Gui::getAnyItem(df::viewscreen *top)
{ {
using df::global::game;
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
return dfscreen->getSelectedItem();
if (game->main_interface.view_sheets.open
&& game->main_interface.view_sheets.active_sheet == view_sheet_type::ITEM)
return df::item::find(game->main_interface.view_sheets.active_id);
/* TODO: understand how this changes for v50 /* TODO: understand how this changes for v50
using namespace ui_sidebar_mode; using namespace ui_sidebar_mode;
using df::global::ui_look_cursor; using df::global::ui_look_cursor;
@ -1254,6 +1272,15 @@ df::item *Gui::getSelectedItem(color_ostream &out, bool quiet)
df::building *Gui::getAnyBuilding(df::viewscreen *top) df::building *Gui::getAnyBuilding(df::viewscreen *top)
{ {
using df::global::game;
if (auto dfscreen = dfhack_viewscreen::try_cast(top))
return dfscreen->getSelectedBuilding();
if (game->main_interface.view_sheets.open
&& game->main_interface.view_sheets.active_sheet == view_sheet_type::BUILDING)
return df::building::find(game->main_interface.view_sheets.active_id);
/* TODO: understand how this changes for v50 /* TODO: understand how this changes for v50
using namespace ui_sidebar_mode; using namespace ui_sidebar_mode;
using df::global::ui_look_list; using df::global::ui_look_list;