|
1 | 1 | -- adjust work orders' input item, material, traits
|
2 |
| ---[====[ |
3 | 2 |
|
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 |
20 | 4 |
|
21 | 5 | --[[
|
22 | 6 | Credit goes to the author of `gui/workshop-job`, it showed
|
23 | 7 | me the way. Also, a huge chunk of code could be reused.
|
24 | 8 | ]]
|
25 | 9 |
|
| 10 | +local overlay = require('plugins.overlay') |
| 11 | + |
26 | 12 | local utils = require 'utils'
|
27 | 13 | local gui = require 'gui'
|
28 | 14 | local guimat = require 'gui.materials'
|
29 | 15 | local widgets = require 'gui.widgets'
|
30 |
| -local dlg = require 'gui.dialogs' |
31 | 16 |
|
32 | 17 | local wsj = reqscript 'gui/workshop-job'
|
33 | 18 |
|
@@ -180,11 +165,70 @@ function JobDetails:onChangeTrait()
|
180 | 165 | }:show()
|
181 | 166 | end
|
182 | 167 |
|
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 |
186 | 232 | end
|
187 | 233 |
|
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