@@ -26,6 +26,25 @@ function isBuildingPlanJob(job)
2626 return suspendmanager_isBuildingPlanJob (job )
2727end
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+
2948function 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()
6988end
7089
7190function 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."
7796end
7897
7998function 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()
110132end
111133
112134function 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 )
115137end
116138
117139function ToggleOverlay :render (dc )
0 commit comments