From 88860f21ec097e458f22d1548dfed7ab2e3351af Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 1 Feb 2023 08:46:32 -0800 Subject: [PATCH] add defocusable attribute to ZScreen --- docs/changelog.txt | 1 + docs/dev/Lua API.rst | 6 ++++++ library/lua/gui.lua | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index a78b14fc7..683db6359 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -68,6 +68,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `helpdb`: changed from auto-refreshing every 60 seconds to only refreshing on explicit call to ``helpdb.refresh()``. docs very rarely change during a play session, and the automatic database refreshes were slowing down the startup of `gui/launcher` - ``widgets.Label``: ``label.scroll()`` now understands ``home`` and ``end`` keywords for scrolling to the top or bottom - ``dfhack.units.getCitizens()``: gets a list of citizens +- ``gui.ZScreen``: new attribute: ``defocusable`` for controlling whether a window loses keyboard focus when the map is clicked ## Removed - `autohauler`: no plans to port to v50, as it just doesn't make sense with the new work detail system diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 658893ec1..dc33438d7 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -4187,6 +4187,12 @@ ZScreen provides the following functions: ZScreen subclasses can set the following attributes: +* ``defocusable`` (default: ``true``) + + Whether the ZScreen loses keyboard focus when the player clicks on an area + of the screen other than the tool window. If the player clicks on a different + ZScreen window, focus still transfers to that other ZScreen. + * ``initial_pause`` (default: ``DEFAULT_INITIAL_PAUSE``) Whether to pause the game when the ZScreen is shown. ``DEFAULT_INITIAL_PAUSE`` diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 061444f5d..b0aa35c81 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -699,6 +699,7 @@ local zscreen_inhibit_mouse_l = false ZScreen = defclass(ZScreen, Screen) ZScreen.ATTRS{ + defocusable=true, initial_pause=DEFAULT_NIL, force_pause=false, pass_pause=true, @@ -793,7 +794,7 @@ function ZScreen:onInput(keys) end if self.pass_mouse_clicks and keys._MOUSE_L_DOWN and not has_mouse then - self.defocused = true + self.defocused = self.defocusable self:sendInputToParent(keys) return elseif keys.LEAVESCREEN or keys._MOUSE_R_DOWN then