From c03ac773cb427ab0afd944b75333822d3590a310 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 17 Jan 2024 10:16:05 -0800 Subject: [PATCH] auto-dismiss screen after confirm and clean up mask checking code --- gui/embark-anywhere.lua | 44 +++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/gui/embark-anywhere.lua b/gui/embark-anywhere.lua index 8ddfd4a157..44262bae31 100644 --- a/gui/embark-anywhere.lua +++ b/gui/embark-anywhere.lua @@ -40,8 +40,6 @@ end function EmbarkAnywhereScreen:init() self:addviews{ EmbarkAnywhere{view_id='main'}, - -- this panel will get checked for masking too, but it's wholely - -- inside the size selection panel, so it's ok widgets.Panel{ frame={l=20, t=1, w=22, h=6}, frame_style=gui.FRAME_MEDIUM, @@ -58,17 +56,23 @@ function EmbarkAnywhereScreen:init() }, visible=is_confirm_panel_visible, }, - widgets.Panel{ -- size selection panel - frame={l=0, t=0, w=61, h=11}, - }, - widgets.Panel{ -- abort button - frame={r=41, b=1, w=10, h=3}, - }, - widgets.Panel{ -- show elevation button - frame={r=22, b=1, w=18, h=3}, - }, - widgets.Panel{ -- show cliffs button - frame={r=0, b=1, w=21, h=3}, + widgets.Panel{ + view_id='masks', + frame={t=0, b=0, l=0, r=0}, + subviews={ + widgets.Panel{ -- size selection panel + frame={l=0, t=0, w=61, h=11}, + }, + widgets.Panel{ -- abort button + frame={r=41, b=1, w=10, h=3}, + }, + widgets.Panel{ -- show elevation button + frame={r=22, b=1, w=18, h=3}, + }, + widgets.Panel{ -- show cliffs button + frame={r=0, b=1, w=21, h=3}, + }, + }, }, } end @@ -91,10 +95,8 @@ local function force_embark(scr) end function EmbarkAnywhereScreen:clicked_on_panel_mask() - for _, sv in ipairs(self.subviews) do - if sv.view_id ~= 'main' then - if sv:getMousePos() then return true end - end + for _, sv in ipairs(self.subviews.masks.subviews) do + if sv:getMousePos() then return true end end end @@ -116,6 +118,14 @@ function EmbarkAnywhereScreen:onDismiss() view = nil end +function EmbarkAnywhereScreen:onRenderFrame(dc, rect) + local scr = dfhack.gui.getDFViewscreen(true) + if not dfhack.gui.matchFocusString('choose_start_site', scr) then + self:dismiss() + end + EmbarkAnywhereScreen.super.onRenderFrame(self, dc, rect) +end + if not dfhack.gui.matchFocusString('choose_start_site') then qerror('This script can only be run when choosing an embark site') end