Skip to content

Commit 01a8d46

Browse files
authored
Merge pull request #797 from TymurGubayev/TymurGubayev-patch-1
Make `workorder-recheck` work again
2 parents 5b59f60 + 36a81f2 commit 01a8d46

File tree

2 files changed

+105
-22
lines changed

2 files changed

+105
-22
lines changed

docs/workorder-recheck.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ workorder-recheck
33

44
.. dfhack-tool::
55
:summary: Recheck start conditions for a manager workorder.
6-
:tags: unavailable fort workorders
6+
:tags: fort workorders
77

8-
Sets the status to ``Checking`` (from ``Active``) of the selected work order (in
9-
the ``j-m`` or ``u-m`` screens). This makes the manager reevaluate its
10-
conditions. This is especially useful for an order that had its conditions met
11-
when it was started, but the requisite items have since disappeared and the
12-
workorder is now generating job cancellation spam.
8+
Sets the status to ``Checking`` (from ``Active``) of the selected work order.
9+
This makes the manager reevaluate its conditions. This is especially useful
10+
for an order that had its conditions met when it was started, but the requisite
11+
items have since disappeared and the workorder is now generating job cancellation
12+
spam.
1313

1414
Usage
1515
-----

workorder-recheck.lua

Lines changed: 99 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,103 @@
11
-- Resets the selected work order to the `Checking` state
2-
--[====[
3-
4-
workorder-recheck
5-
=================
6-
Sets the status to ``Checking`` (from ``Active``) of the selected work order (in the ``j-m`` or ``u-m`` screens).
7-
This makes the manager reevaluate its conditions.
8-
]====]
9-
local scr = dfhack.gui.getCurViewscreen()
10-
if df.viewscreen_jobmanagementst:is_instance(scr) then
11-
local orders = df.global.world.manager_orders
12-
local idx = scr.sel_idx
13-
if idx < #orders then
14-
orders[idx].status.active = false
2+
3+
--@ module = true
4+
5+
local widgets = require('gui.widgets')
6+
local overlay = require('plugins.overlay')
7+
8+
local function set_current_inactive()
9+
local scrConditions = df.global.game.main_interface.info.work_orders.conditions
10+
if scrConditions.open then
11+
local order = scrConditions.wq
12+
order.status.active = false
1513
else
16-
qerror("Invalid order selected")
14+
qerror("Order conditions is not open")
1715
end
18-
else
19-
qerror('Must be called on the manager screen (j-m or u-m)')
2016
end
17+
18+
local function is_current_active()
19+
local scrConditions = df.global.game.main_interface.info.work_orders.conditions
20+
local order = scrConditions.wq
21+
return order.status.active
22+
end
23+
24+
-- -------------------
25+
-- RecheckOverlay
26+
--
27+
28+
local focusString = 'dwarfmode/Info/WORK_ORDERS/Conditions'
29+
30+
RecheckOverlay = defclass(RecheckOverlay, overlay.OverlayWidget)
31+
RecheckOverlay.ATTRS{
32+
default_pos={x=6,y=8},
33+
default_enabled=true,
34+
viewscreens=focusString,
35+
-- width is the sum of lengths of `[` + `Ctrl+A` + `: ` + button.label + `]`
36+
frame={w=1 + 6 + 2 + 16 + 1, h=3},
37+
}
38+
39+
local function areTabsInTwoRows()
40+
-- get the tile above the order status icon
41+
local pen = dfhack.screen.readTile(7, 7, false)
42+
-- in graphics mode, `0` when one row, something else when two (`67` aka 'C' from "Creatures")
43+
-- in ASCII mode, `32` aka ' ' when one row, something else when two (`196` aka '-' from tab frame's top)
44+
return (pen.ch ~= 0 and pen.ch ~= 32)
45+
end
46+
47+
function RecheckOverlay:updateTextButtonFrame()
48+
local twoRows = areTabsInTwoRows()
49+
if (self._twoRows == twoRows) then return false end
50+
51+
self._twoRows = twoRows
52+
local frame = twoRows
53+
and {b=0, l=0, r=0, h=1}
54+
or {t=0, l=0, r=0, h=1}
55+
self.subviews.button.frame = frame
56+
57+
return true
58+
end
59+
60+
function RecheckOverlay:init()
61+
self:addviews{
62+
widgets.TextButton{
63+
view_id = 'button',
64+
-- frame={t=0, l=0, r=0, h=1}, -- is set in `updateTextButtonFrame()`
65+
label='request re-check',
66+
key='CUSTOM_CTRL_A',
67+
on_activate=set_current_inactive,
68+
enabled=is_current_active,
69+
},
70+
}
71+
72+
self:updateTextButtonFrame()
73+
end
74+
75+
function RecheckOverlay:onRenderBody(dc)
76+
if (self.frame_rect.y1 == 7) then
77+
-- only apply this logic if the overlay is on the same row as
78+
-- originally thought: just above the order status icon
79+
80+
if self:updateTextButtonFrame() then
81+
self:updateLayout()
82+
end
83+
end
84+
85+
RecheckOverlay.super.onRenderBody(self, dc)
86+
end
87+
88+
-- -------------------
89+
90+
OVERLAY_WIDGETS = {
91+
recheck=RecheckOverlay,
92+
}
93+
94+
if dfhack_flags.module then
95+
return
96+
end
97+
98+
-- Check if on the correct screen and perform the action if so
99+
if not dfhack.gui.matchFocusString(focusString) then
100+
qerror('workorder-recheck must be run from the manager order conditions view')
101+
end
102+
103+
set_current_inactive()

0 commit comments

Comments
 (0)