Skip to content

Commit

Permalink
auto-dismiss screen after confirm
Browse files Browse the repository at this point in the history
and clean up mask checking code
  • Loading branch information
myk002 committed Jan 17, 2024
1 parent 41a0abd commit c03ac77
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions gui/embark-anywhere.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit c03ac77

Please sign in to comment.