add Gui::getDFViewscreen and Lua binding

develop
Myk Taylor 2023-01-06 12:17:36 -08:00
parent 9de09ac779
commit 6f46ae672e
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
5 changed files with 28 additions and 4 deletions

@ -48,12 +48,14 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## API ## API
- ``Gui::getDwarfmodeDims``: now only returns map viewport dimensions; menu dimensions are obsolete - ``Gui::getDwarfmodeDims``: now only returns map viewport dimensions; menu dimensions are obsolete
- ``Gui::getDFViewscreen``: returns the topmost underlying DF viewscreen
## Lua ## Lua
- ``gui.View``: ``visible`` and ``active`` can now be functions that return a boolean - ``gui.View``: ``visible`` and ``active`` can now be functions that return a boolean
- ``widgets.Panel``: new attributes to control window dragging and resizing with mouse or keyboard - ``widgets.Panel``: new attributes to control window dragging and resizing with mouse or keyboard
- ``widgets.Window``: Panel subclass with attributes preset for top-level windows - ``widgets.Window``: Panel subclass with attributes preset for top-level windows
- `overlay`: ``OverlayWidget`` now inherits from ``Panel`` instead of ``Widget`` to get all the frame and mouse integration goodies - `overlay`: ``OverlayWidget`` now inherits from ``Panel`` instead of ``Widget`` to get all the frame and mouse integration goodies
- ``dfhack.gui.getDFViewscreen()``: returns the topmost underlying DF viewscreen
## Internals ## Internals

@ -965,6 +965,11 @@ Screens
the specified type (e.g. ``df.viewscreen_titlest``), or ``nil`` if none match. the specified type (e.g. ``df.viewscreen_titlest``), or ``nil`` if none match.
If ``depth`` is not specified or is less than 1, all viewscreens are checked. If ``depth`` is not specified or is less than 1, all viewscreens are checked.
* ``dfhack.gui.getDFViewscreen([skip_dismissed])``
Returns the topmost viewscreen not owned by DFHack. If ``skip_dismissed`` is
``true``, ignores screens already marked to be removed.
General-purpose selections General-purpose selections
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~

@ -1454,6 +1454,7 @@ static int gui_getMousePos(lua_State *L)
static const LuaWrapper::FunctionReg dfhack_gui_module[] = { static const LuaWrapper::FunctionReg dfhack_gui_module[] = {
WRAPM(Gui, getCurViewscreen), WRAPM(Gui, getCurViewscreen),
WRAPM(Gui, getDFViewscreen),
WRAPM(Gui, getFocusString), WRAPM(Gui, getFocusString),
WRAPM(Gui, getCurFocus), WRAPM(Gui, getCurFocus),
WRAPM(Gui, getSelectedWorkshopJob), WRAPM(Gui, getSelectedWorkshopJob),

@ -181,6 +181,9 @@ namespace DFHack
DFHACK_EXPORT df::viewscreen *getViewscreenByIdentity(virtual_identity &id, int n = 1); DFHACK_EXPORT df::viewscreen *getViewscreenByIdentity(virtual_identity &id, int n = 1);
/// Get the top-most underlying DF viewscreen (not owned by DFHack)
DFHACK_EXPORT df::viewscreen *getDFViewscreen(bool skip_dismissed = false);
/// Get the top-most viewscreen of the given type from the top `n` viewscreens (or all viewscreens if n < 1) /// Get the top-most viewscreen of the given type from the top `n` viewscreens (or all viewscreens if n < 1)
/// returns NULL if none match /// returns NULL if none match
template <typename T> template <typename T>

@ -1873,6 +1873,12 @@ bool Gui::autoDFAnnouncement(df::announcement_type type, df::coord pos, std::str
return autoDFAnnouncement(r, message); return autoDFAnnouncement(r, message);
} }
static df::viewscreen * do_skip_dismissed(df::viewscreen * ws) {
while (ws && Screen::isDismissed(ws) && ws->parent)
ws = ws->parent;
return ws;
}
df::viewscreen *Gui::getCurViewscreen(bool skip_dismissed) df::viewscreen *Gui::getCurViewscreen(bool skip_dismissed)
{ {
if (!gview) if (!gview)
@ -1883,10 +1889,7 @@ df::viewscreen *Gui::getCurViewscreen(bool skip_dismissed)
ws = ws->child; ws = ws->child;
if (skip_dismissed) if (skip_dismissed)
{ ws = do_skip_dismissed(ws);
while (ws && Screen::isDismissed(ws) && ws->parent)
ws = ws->parent;
}
return ws; return ws;
} }
@ -1906,6 +1909,16 @@ df::viewscreen *Gui::getViewscreenByIdentity (virtual_identity &id, int n)
return NULL; return NULL;
} }
df::viewscreen *Gui::getDFViewscreen(bool skip_dismissed) {
df::viewscreen *screen = Gui::getCurViewscreen(skip_dismissed);
while (screen && dfhack_viewscreen::is_instance(screen)) {
screen = screen->parent;
if (skip_dismissed)
screen = do_skip_dismissed(screen);
}
return screen;
}
df::coord Gui::getViewportPos() df::coord Gui::getViewportPos()
{ {
if (!df::global::window_x || !df::global::window_y || !df::global::window_z) if (!df::global::window_x || !df::global::window_y || !df::global::window_z)