Skip to content
Open
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 @@ -59,6 +59,7 @@ Template for new versions:
## New Features

## Fixes
- `suspendmanager`: Fix the overlay appearing where it should not when following a unit

## Misc Improvements

Expand Down
32 changes: 27 additions & 5 deletions plugins/lua/suspendmanager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ function isBuildingPlanJob(job)
return suspendmanager_isBuildingPlanJob(job)
end

--- Return the selected construction job
local function getSelectedBuildingJob()
-- This is not relying on dfhack.gui.getSelectedJob() because we don't want
-- the job of a selected or followed unit, only of a selected building
local building = dfhack.gui.getSelectedBuilding(true)
if not building then
return nil
end

-- Find if the building is being constructed
for _, job in ipairs(building.jobs) do
if job.job_type == df.job_type.ConstructBuilding then
return job
end
end

return nil
end

function runOnce(prevent_blocking, quiet, unsuspend_everything)
suspendmanager_runOnce(prevent_blocking, unsuspend_everything)
if (not quiet) then
Expand Down Expand Up @@ -69,16 +88,19 @@ function StatusOverlay:init()
end

function StatusOverlay:get_status_string()
local job = dfhack.gui.getSelectedJob(true)
local job = getSelectedBuildingJob()
if job and job.flags.suspend then
return "Suspended because: " .. suspendmanager_suspensionDescription(job) .. "."
end
return "Not suspended."
end

function StatusOverlay:render(dc)
local job = dfhack.gui.getSelectedJob(true)
if not job or job.job_type ~= df.job_type.ConstructBuilding or not isEnabled() or isBuildingPlanJob(job) then
if not isEnabled() then
return
end
local job = getSelectedBuildingJob()
if not job or isBuildingPlanJob(job) then
return
end
StatusOverlay.super.render(self, dc)
Expand Down Expand Up @@ -110,8 +132,8 @@ function ToggleOverlay:init()
end

function ToggleOverlay:shouldRender()
local job = dfhack.gui.getSelectedJob(true)
return job and job.job_type == df.job_type.ConstructBuilding and not isBuildingPlanJob(job)
local job = getSelectedBuildingJob()
return job and not isBuildingPlanJob(job)
end

function ToggleOverlay:render(dc)
Expand Down