Skip to content

Commit 0fde142

Browse files
authored
Merge pull request #5695 from plule/fix-follow-overlay
Fix the suspendmanager overlay appearing for followed units
2 parents 579c063 + 5fc36c4 commit 0fde142

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Template for new versions:
6060

6161
## Fixes
6262
- `autochop`: the report will no longer throw a C++ exception when burrows are defined.
63+
- `suspendmanager`: Fix the overlay appearing where it should not when following a unit
6364

6465
## Misc Improvements
6566

plugins/lua/suspendmanager.lua

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@ function isBuildingPlanJob(job)
2626
return suspendmanager_isBuildingPlanJob(job)
2727
end
2828

29+
--- Return the selected construction job
30+
local function getSelectedBuildingJob()
31+
-- This is not relying on dfhack.gui.getSelectedJob() because we don't want
32+
-- the job of a selected or followed unit, only of a selected building
33+
local building = dfhack.gui.getSelectedBuilding(true)
34+
if not building then
35+
return nil
36+
end
37+
38+
-- Find if the building is being constructed
39+
for _, job in ipairs(building.jobs) do
40+
if job.job_type == df.job_type.ConstructBuilding then
41+
return job
42+
end
43+
end
44+
45+
return nil
46+
end
47+
2948
function runOnce(prevent_blocking, quiet, unsuspend_everything)
3049
suspendmanager_runOnce(prevent_blocking, unsuspend_everything)
3150
if (not quiet) then
@@ -69,16 +88,19 @@ function StatusOverlay:init()
6988
end
7089

7190
function StatusOverlay:get_status_string()
72-
local job = dfhack.gui.getSelectedJob(true)
91+
local job = getSelectedBuildingJob()
7392
if job and job.flags.suspend then
7493
return "Suspended because: " .. suspendmanager_suspensionDescription(job) .. "."
7594
end
7695
return "Not suspended."
7796
end
7897

7998
function StatusOverlay:render(dc)
80-
local job = dfhack.gui.getSelectedJob(true)
81-
if not job or job.job_type ~= df.job_type.ConstructBuilding or not isEnabled() or isBuildingPlanJob(job) then
99+
if not isEnabled() then
100+
return
101+
end
102+
local job = getSelectedBuildingJob()
103+
if not job or isBuildingPlanJob(job) then
82104
return
83105
end
84106
StatusOverlay.super.render(self, dc)
@@ -110,8 +132,8 @@ function ToggleOverlay:init()
110132
end
111133

112134
function ToggleOverlay:shouldRender()
113-
local job = dfhack.gui.getSelectedJob(true)
114-
return job and job.job_type == df.job_type.ConstructBuilding and not isBuildingPlanJob(job)
135+
local job = getSelectedBuildingJob()
136+
return job and not isBuildingPlanJob(job)
115137
end
116138

117139
function ToggleOverlay:render(dc)

0 commit comments

Comments
 (0)