Skip to content

Commit

Permalink
Merge pull request #869 from myk002/myk_overlay
Browse files Browse the repository at this point in the history
[gui/overlay] filter overlays by context, not just by screen
  • Loading branch information
myk002 authored Oct 16, 2023
2 parents 93920c8 + 493d50e commit 2932e8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Template for new versions:

## Misc Improvements
- `prioritize`: refuse to automatically prioritize dig and smooth/carve job types since it can break the DF job scheduler; instead, print a suggestion that the player use specialized units and vanilla designation priorities
- `gui/overlay`: filter overlays by current context so there are fewer on the screen at once and you can more easily click on the one you want to reposition
- `quickfort`: now allows constructions to be built on top of constructed floors and ramps, just like vanilla. however, to allow blueprints to be safely reapplied to the same area, for example to fill in buildings whose constructions were canceled due to lost items, floors will not be rebuilt on top of floors and ramps will not be rebuilt on top of ramps

## Removed
Expand Down
28 changes: 16 additions & 12 deletions gui/overlay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ function OverlayConfig:init()
-- prevent hotspot widgets from reacting
overlay.register_trigger_lock_screen(self)

self.scr_name = overlay.simplify_viewscreen_name(
getmetatable(dfhack.gui.getDFViewscreen(true)))
local contexts = dfhack.gui.getFocusStrings(dfhack.gui.getDFViewscreen(true))

local main_panel = widgets.Window{
frame={w=DIALOG_WIDTH, h=LIST_HEIGHT+15},
Expand All @@ -123,13 +122,16 @@ function OverlayConfig:init()
main_panel:addviews{
widgets.Label{
frame={t=0, l=0},
text={'Current screen: ', {text=self.scr_name, pen=COLOR_CYAN}}},
text={
'Current contexts: ',
{text=table.concat(contexts, ', '), pen=COLOR_CYAN}
}},
widgets.CycleHotkeyLabel{
view_id='filter',
frame={t=2, l=0},
key='CUSTOM_CTRL_O',
label='Showing:',
options={{label='overlays for the current screen', value='cur'},
options={{label='overlays for the current contexts', value='cur'},
{label='all overlays', value='all'}},
on_change=self:callback('refresh_list')},
widgets.FilteredList{
Expand Down Expand Up @@ -173,6 +175,7 @@ end

function OverlayConfig:refresh_list(filter)
local choices = {}
local scr = dfhack.gui.getDFViewscreen(true)
local state = overlay.get_state()
local list = self.subviews.list
local make_on_click_fn = function(idx)
Expand All @@ -182,16 +185,15 @@ function OverlayConfig:refresh_list(filter)
local db_entry = state.db[name]
local widget = db_entry.widget
if widget.overlay_only then goto continue end
if not widget.hotspot and filter ~= 'all' then
local matched = false
for _,scr in ipairs(overlay.normalize_list(widget.viewscreens)) do
if overlay.simplify_viewscreen_name(scr):startswith(self.scr_name) then
matched = true
break
if (not widget.hotspot or #widget.viewscreens > 0) and filter ~= 'all' then
for _,vs in ipairs(overlay.normalize_list(widget.viewscreens)) do
if dfhack.gui.matchFocusString(overlay.simplify_viewscreen_name(vs), scr) then
goto matched
end
end
if not matched then goto continue end
goto continue
end
::matched::
local panel = nil
panel = DraggablePanel{
frame=make_highlight_frame(widget.frame),
Expand Down Expand Up @@ -290,12 +292,14 @@ function OverlayConfig:onInput(keys)
return true
end
end
if self:inputToSubviews(keys) then
return true
end
for _,choice in ipairs(self.subviews.list:getVisibleChoices()) do
if choice.panel and choice.panel:onInput(keys) then
return true
end
end
return self:inputToSubviews(keys)
end

function OverlayConfig:onRenderFrame(dc, rect)
Expand Down

0 comments on commit 2932e8e

Please sign in to comment.