Skip to content

Commit 84fc36d

Browse files
committed
Update workorder-details.lua
1 parent af4cef2 commit 84fc36d

File tree

1 file changed

+68
-24
lines changed

1 file changed

+68
-24
lines changed

gui/workorder-details.lua

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
-- adjust work orders' input item, material, traits
2-
--[====[
32

4-
gui/workorder-details
5-
=====================
6-
Adjust input items, material, or traits for work orders. Actual
7-
jobs created for it will inherit the details.
8-
9-
This is the equivalent of `gui/workshop-job` for work orders,
10-
with the additional possibility to set input items' traits.
11-
12-
It has to be run from a work order's detail screen
13-
(:kbd:`j-m`, select work order, :kbd:`d`).
14-
15-
For best experience add the following to your ``dfhack*.init``::
16-
17-
keybinding add D@workquota_details gui/workorder-details
18-
19-
]====]
3+
--@ module = true
204

215
--[[
226
Credit goes to the author of `gui/workshop-job`, it showed
237
me the way. Also, a huge chunk of code could be reused.
248
]]
259

10+
local overlay = require('plugins.overlay')
11+
2612
local utils = require 'utils'
2713
local gui = require 'gui'
2814
local guimat = require 'gui.materials'
2915
local widgets = require 'gui.widgets'
30-
local dlg = require 'gui.dialogs'
3116

3217
local wsj = reqscript 'gui/workshop-job'
3318

@@ -180,11 +165,70 @@ function JobDetails:onChangeTrait()
180165
}:show()
181166
end
182167

183-
local scr = dfhack.gui.getCurViewscreen()
184-
if not df.viewscreen_workquota_detailsst:is_instance(scr) then
185-
qerror("This script needs to be run from a work order details screen")
168+
local function ScrJobDetails()
169+
return df.global.game.main_interface.job_details
170+
end
171+
172+
local function show_job_details()
173+
local scr = ScrJobDetails()
174+
if not scr.open -- dfhack.gui.matchFocusString('dwarfmode/JobDetails')
175+
or scr.context ~= df.job_details_context_type.MANAGER_WORK_ORDER
176+
then
177+
qerror("This script needs to be run from a work order details screen")
178+
end
179+
180+
-- by opening the viewscreen_workquota_detailsst the
181+
-- work order's .items array is initialized
182+
JobDetails{ job = scr.wq }:show()
183+
end
184+
185+
-- -------------------
186+
-- RecheckOverlay
187+
--
188+
189+
local focusStrings = 'dwarfmode/JobDetails'
190+
191+
DetailsHotkeyOverlay = defclass(DetailsHotkeyOverlay, overlay.OverlayWidget)
192+
DetailsHotkeyOverlay.ATTRS{
193+
default_pos={x=5,y=7},
194+
default_enabled=true,
195+
viewscreens=focusStrings,
196+
frame={w=1+6+2+(7)+1, h=3},
197+
}
198+
199+
function DetailsHotkeyOverlay:init()
200+
self:addviews{
201+
widgets.TextButton{
202+
view_id = 'button',
203+
frame={t=0, l=0, r=0, h=1},
204+
label='details',
205+
key='CUSTOM_CTRL_D',
206+
on_activate=show_job_details,
207+
},
208+
}
209+
end
210+
211+
function DetailsHotkeyOverlay:onRenderBody(dc)
212+
local scr = ScrJobDetails()
213+
214+
if (scr.context ~= df.job_details_context_type.MANAGER_WORK_ORDER) then
215+
self.subviews.button.visible = false
216+
return
217+
else
218+
self.subviews.button.visible = true
219+
end
220+
221+
DetailsHotkeyOverlay.super.onRenderBody(self, dc)
222+
end
223+
224+
-- -------------------
225+
226+
OVERLAY_WIDGETS = {
227+
details=DetailsHotkeyOverlay,
228+
}
229+
230+
if dfhack_flags.module then
231+
return
186232
end
187233

188-
-- by opening the viewscreen_workquota_detailsst the
189-
-- work order's .items array is initialized
190-
JobDetails{ job = scr.order }:show()
234+
show_job_details()

0 commit comments

Comments
 (0)