From a1dd31aab32bdecfb360cf8bb40e5c7c836a6deb Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 25 Oct 2012 12:09:39 +0400 Subject: [PATCH] Tweak the mechanics for showing and rendering lua screens. - Place new screens below any dismissed ones on top. - When asked to render a dismissed lua screen, call render() on its parent to avoid producing a black screen frame when unlucky. --- library/lua/gui.lua | 9 +++++---- library/lua/gui/dwarfmode.lua | 6 ++---- library/modules/Screen.cpp | 7 ++++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 18b0d67d8..15d03742f 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -513,17 +513,18 @@ function Screen:sendInputToParent(...) end end -function Screen:show(below) +function Screen:show(parent) if self._native then error("This screen is already on display") end - self:onAboutToShow(below) - if not dscreen.show(self, below) then + parent = parent or dfhack.gui.getCurViewscreen(true) + self:onAboutToShow(parent) + if not dscreen.show(self, parent.child) then error('Could not show screen') end end -function Screen:onAboutToShow() +function Screen:onAboutToShow(parent) end function Screen:onShow() diff --git a/library/lua/gui/dwarfmode.lua b/library/lua/gui/dwarfmode.lua index cef52ae24..8c537639b 100644 --- a/library/lua/gui/dwarfmode.lua +++ b/library/lua/gui/dwarfmode.lua @@ -373,10 +373,8 @@ function DwarfOverlay:simulateCursorMovement(keys, anchor) end end -function DwarfOverlay:onAboutToShow(below) - local screen = dfhack.gui.getCurViewscreen() - if below then screen = below.parent end - if not df.viewscreen_dwarfmodest:is_instance(screen) then +function DwarfOverlay:onAboutToShow(parent) + if not df.viewscreen_dwarfmodest:is_instance(parent) then error("This screen requires the main dwarfmode view") end end diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index 29f718266..d89b3688d 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -639,7 +639,12 @@ dfhack_lua_viewscreen::~dfhack_lua_viewscreen() void dfhack_lua_viewscreen::render() { - if (Screen::isDismissed(this)) return; + if (Screen::isDismissed(this)) + { + if (parent) + parent->render(); + return; + } dfhack_viewscreen::render();