Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sort] reset state whenever we leave the local info context #4221

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Template for new versions:
## New Features

## Fixes
- `sort`: fix potential crash when switching between info tabs

## Misc Improvements
- `reveal`: automatically reset saved map state when a new save is loaded
Expand Down
16 changes: 15 additions & 1 deletion plugins/lua/sort/info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,21 @@ InfoOverlay = defclass(InfoOverlay, sortoverlay.SortOverlay)
InfoOverlay.ATTRS{
desc='Adds search and filter functionality to most info panels.',
default_pos={x=64, y=8},
viewscreens='dwarfmode/Info',
viewscreens={
'dwarfmode/Info/CREATURES/CITIZEN',
'dwarfmode/Info/CREATURES/PET',
'dwarfmode/Info/CREATURES/AddingTrainer',
'dwarfmode/Info/CREATURES/AssignWorkAnimal',
'dwarfmode/Info/CREATURES/OverallTraining',
'dwarfmode/Info/CREATURES/OTHER',
'dwarfmode/Info/CREATURES/DECEASED',
'dwarfmode/Info/JOBS',
'dwarfmode/Info/Labor/WORK_DETAILS',
'dwarfmode/Info/ARTIFACTS/ARTIFACTS',
'dwarfmode/Info/ARTIFACTS/SYMBOLS',
'dwarfmode/Info/ARTIFACTS/NAMED_OBJECTS',
'dwarfmode/Info/ARTIFACTS/WRITTEN_CONTENT',
},
frame={w=40, h=6},
}

Expand Down
15 changes: 12 additions & 3 deletions plugins/lua/sort/sortoverlay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,20 @@ local function do_cleanup(handlers, key, data)
data.saved_original = nil
end

local function get_in_scope(scopes)
if type(scopes) == 'string' then scopes = {scopes} end
local scr = dfhack.gui.getDFViewscreen(true)
for _,scope in ipairs(scopes) do
if dfhack.gui.matchFocusString(scope, scr) then
return true
end
end
end

-- handles reset and clean up when the player exits the handled scope
function SortOverlay:overlay_onupdate()
if self.overlay_onupdate_max_freq_seconds == 0 and
not dfhack.gui.matchFocusString(self.viewscreens, dfhack.gui.getDFViewscreen(true))
then
if self.overlay_onupdate_max_freq_seconds ~= 0 then return end
if not get_in_scope(self.viewscreens) then
for key,data in pairs(self.state) do
if type(data) == 'table' then
do_cleanup(self.handlers, key, data)
Expand Down
Loading