handle case where jobs are manually removed from the tasks screen

develop
Myk Taylor 2023-11-27 10:09:23 -08:00
parent 21822b3aa3
commit b63e99e165
No known key found for this signature in database
2 changed files with 35 additions and 6 deletions

@ -57,6 +57,7 @@ Template for new versions:
- `sort`: search and sort for the "choose unit to elevate to the barony" screen. units are sorted by the number of item preferences they have and the units are annotated with the items that they have preferences for - `sort`: search and sort for the "choose unit to elevate to the barony" screen. units are sorted by the number of item preferences they have and the units are annotated with the items that they have preferences for
## Fixes ## Fixes
- `sort`: fix potential crash when removing jobs directly from the Tasks info screen
## Misc Improvements ## Misc Improvements
- wherever units are listed in DFHack tools, properties like "agitated" or (-trained-) are now shown - wherever units are listed in DFHack tools, properties like "agitated" or (-trained-) are now shown

@ -436,21 +436,49 @@ function InfoOverlay:updateFrames()
return true return true
end end
function InfoOverlay:do_refresh()
self.refresh_search = nil
if self:get_key() == 'JOBS' then
local data = self.state.JOBS
-- if any jobs have been canceled, fix up our data vectors
if data and data.saved_visible and data.saved_original then
local to_remove = {}
for _,elem in ipairs(data.saved_visible) do
if not utils.linear_index(tasks.cri_job, elem) then
table.insert(to_remove, elem)
end
end
for _,elem in ipairs(to_remove) do
table.remove(data.saved_visible, utils.linear_index(data.saved_visible, elem))
data.saved_visible_size = data.saved_visible_size - 1
table.remove(data.saved_original, utils.linear_index(data.saved_original, elem))
data.saved_original_size = data.saved_original_size - 1
end
end
end
self:do_search(self.subviews.search.text, true)
end
function InfoOverlay:onRenderBody(dc) function InfoOverlay:onRenderBody(dc)
if self.refresh_search then
self:do_refresh()
end
InfoOverlay.super.onRenderBody(self, dc) InfoOverlay.super.onRenderBody(self, dc)
if self:updateFrames() then if self:updateFrames() then
self:updateLayout() self:updateLayout()
end end
if self.refresh_search then
self.refresh_search = nil
self:do_search(self.subviews.search.text)
end
end end
function InfoOverlay:onInput(keys) function InfoOverlay:onInput(keys)
if keys._MOUSE_L and self:get_key() == 'WORK_DETAILS' then if self.refresh_search then
self:do_refresh()
end
if keys._MOUSE_L then
local key = self:get_key()
if key == 'WORK_DETAILS' or key == 'JOBS' then
self.refresh_search = true self.refresh_search = true
end end
end
return InfoOverlay.super.onInput(self, keys) return InfoOverlay.super.onInput(self, keys)
end end