Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make gui/workorder-details and gui/workshop-job work again #799

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
84fc36d
Update workorder-details.lua
TymurGubayev Aug 13, 2023
1f9c249
Update workorder-details.rst
TymurGubayev Aug 13, 2023
9eca80b
remove trailing whitespaces
TymurGubayev Aug 13, 2023
8b559fd
merge workorder-details into workshop-job, update to not use `gui.dia…
TymurGubayev Sep 3, 2023
c94a5be
Update job-details.lua: fix whitespaces
TymurGubayev Sep 3, 2023
1f2c9f5
`require 'gui.dialogs'` for the `showMessage()`
TymurGubayev Sep 3, 2023
3846f1f
add instructions how to open the tool
TymurGubayev Sep 3, 2023
d80af4f
explain magic numbers
TymurGubayev Oct 2, 2023
d06b5a8
make use of more specific focus strings
TymurGubayev Oct 2, 2023
937e6d2
avoid redefining a variable
TymurGubayev Oct 2, 2023
e2bd30f
use more descriptive label text
TymurGubayev Oct 8, 2023
07a9ccd
separate ZScreenModal and Window
TymurGubayev Oct 10, 2023
bfa2892
separate ZScreenModal and Window, part 2
TymurGubayev Oct 10, 2023
590dd4a
add the widget to workorder conditions as well
TymurGubayev Nov 5, 2023
7603249
use HotkeyLabel to make actions clickable
TymurGubayev Nov 5, 2023
9ada99a
place the overlay text over task name in BuildingTask view regardless…
TymurGubayev Nov 5, 2023
ef0ebcc
do not show unnamed flags even if set
TymurGubayev Nov 5, 2023
bf055ab
job-details.rst: mention where can we find the tool
TymurGubayev Nov 5, 2023
85b92c0
enable in the workshops' work order details screen
TymurGubayev Nov 5, 2023
36985ed
improve positioning logic for building overlay
TymurGubayev Nov 6, 2023
069fd09
set auto_width=true on hotkey labels
TymurGubayev Nov 6, 2023
bd88a1a
remove the 'LEAVESCREEN' label
TymurGubayev Nov 7, 2023
77ab5b9
only hide numeric flag names if `dfhack.getHideArmokTools() == true`
TymurGubayev Nov 7, 2023
597c48a
Use user-friendly quantity instead of internal counter
TymurGubayev Nov 7, 2023
cd7ca2f
use window size do determine if tabs are in two rows
TymurGubayev Nov 7, 2023
bb95a28
disable the key if job has no items
TymurGubayev Nov 7, 2023
17ca139
add an ability to reset changes
TymurGubayev Nov 7, 2023
e861565
disable "change type" if Armok mode is off
TymurGubayev Nov 7, 2023
5ac5b9c
use special setItemType and setMaterial methods when resetting changes
TymurGubayev Nov 7, 2023
11393bc
fix a bug introduced in recent commit
TymurGubayev Nov 7, 2023
492417b
fix another bug
TymurGubayev Nov 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/gui/job-details.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ gui/job-details
:tags: fort inspection jobs workorders interface

This tool allows you to inspect or change the input reagents for the selected job:
open the job's "Details" screen by clicking the magnifying glass, then press :kbd:`Ctrl-D`.
open the job's "Details" screen by clicking the magnifying glass, then press :kbd:`Ctrl-D`
or click the "Configure job inputs" label. This is possible in a workshop
job list and manager work order list (in case the magnifying glass is present),
as well as from the work order conditions screen.

Pressing :kbd:`i` shows a dialog where you can select an item type from a list.

Expand Down
195 changes: 164 additions & 31 deletions gui/job-details.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ JobDetails.ATTRS {

function JobDetails:isManagerOrder()
return self.context == df.job_details_context_type.MANAGER_WORK_ORDER
or self.context == df.job_details_context_type.BUILDING_WORK_ORDER
end

function JobDetails:init(args)
Expand All @@ -62,19 +63,29 @@ function JobDetails:init(args)
' ', status
}
},
widgets.Label{
frame = { l = 0, t = 4 },
text = {
{ key = 'CUSTOM_I', text = ': Input item, ',
enabled = self:callback('canChangeIType'),
on_activate = self:callback('onChangeIType') },
{ key = 'CUSTOM_M', text = ': Material, ',
enabled = self:callback('canChangeMat'),
on_activate = self:callback('onChangeMat') },
{ key = 'CUSTOM_T', text = ': Traits',
enabled = self:callback('canChangeTrait'),
on_activate = self:callback('onChangeTrait') }
}
widgets.HotkeyLabel{
frame = { l = 0, t = 4},
key = 'CUSTOM_I',
label = "Input item",
auto_width=true,
enabled = self:callback('canChangeIType'),
on_activate = self:callback('onChangeIType'),
},
widgets.HotkeyLabel{
frame = { l = string.len("i: Input item") + 1, t = 4},
key = 'CUSTOM_M',
label = "Material",
auto_width=true,
enabled = self:callback('canChangeMat'),
on_activate = self:callback('onChangeMat'),
},
widgets.HotkeyLabel{
frame = { l = string.len("i: Input item m: Material") + 1, t = 4},
key = 'CUSTOM_T',
label = "Traits",
auto_width=true,
enabled = self:callback('canChangeTrait'),
on_activate = self:callback('onChangeTrait'),
},
widgets.List{
view_id = 'list',
Expand Down Expand Up @@ -138,10 +149,20 @@ local function describe_material(iobj)
return matline
end

local function isString(o)
return type(o) == "string"
end

local function list_flags(list, bitfield)
for name,val in pairs(bitfield) do
if val then
table.insert(list, name)
-- as of DFHack version 50.11-r2 (git: 94d70e0) on x86_64,
-- a job_item_flags3[20] might be set on a job item (f.e. Cut Gems)
-- even though the flag is unnamed (i.e. `df.job_item_flags3[20] == nil`)
-- we'll ignore those for clarity.
if isString(name) then
table.insert(list, name)
end
end
end
end
Expand Down Expand Up @@ -346,24 +367,44 @@ local function ScrJobDetails()
return df.global.game.main_interface.job_details
end

local function ScrWorkorderConditions()
return df.global.game.main_interface.info.work_orders.conditions
TymurGubayev marked this conversation as resolved.
Show resolved Hide resolved
end

local function show_job_details()
local job
local context
local scr = ScrJobDetails()
if not scr.open -- dfhack.gui.matchFocusString('dwarfmode/JobDetails')

if scr.open
then
qerror("This script needs to be run from a job details screen")
context = scr.context
if context == df.job_details_context_type.BUILDING_TASK_LIST
or context == df.job_details_context_type.TASK_LIST_TASK
then
job = scr.jb
elseif context == df.job_details_context_type.MANAGER_WORK_ORDER
or context == df.job_details_context_type.BUILDING_WORK_ORDER
then
job = scr.wq
end
if job == nil then
qerror("Unhandled screen context: ".. df.job_details_context_type[context])
end
else
scr = ScrWorkorderConditions()
if scr.open
then
context = df.job_details_context_type.MANAGER_WORK_ORDER
job = scr.wq
end
end

local job
if scr.context == df.job_details_context_type.BUILDING_TASK_LIST then
job = scr.jb
elseif scr.context == df.job_details_context_type.MANAGER_WORK_ORDER then
job = scr.wq
end
if job == nil then
qerror("Unhandled screen context: ".. df.job_details_context_type[scr.context])
if (job == nil) then
qerror("This script needs to be run from a job details or order conditions screen")
end

JobDetailsScreen{ job = job, context = scr.context }:show()
JobDetailsScreen{ job = job, context = context }:show()
end

-- --------------------
Expand Down Expand Up @@ -391,31 +432,123 @@ function DetailsHotkeyOverlay:init()
self:addviews{
widgets.TextButton{
view_id = 'button',
frame={t=0, l=0, r=0, h=1},
frame={t=0, l=0, w=DetailsHotkeyOverlay.ATTRS.frame.w, h=1},
label=LABEL_TEXT,
key='CUSTOM_CTRL_D',
on_activate=show_job_details,
},
}
end

DetailsHotkeyOverlay_BuildingTask = defclass(DetailsHotkeyOverlay_BuildingTask, DetailsHotkeyOverlay)
DetailsHotkeyOverlay_BuildingTask.ATTRS{
-- 7 is the x position of the text on the narrowest screen
-- we make the frame wider by 7 so we can move the label a bit if necessary
default_pos={x=-110 + 7, y=6},
frame={w=DetailsHotkeyOverlay.ATTRS.frame.w + 7, h= 1},
viewscreens={
'dwarfmode/JobDetails/BUILDING_TASK_LIST',
'dwarfmode/JobDetails/BUILDING_WORK_ORDER',
}
}

function DetailsHotkeyOverlay_BuildingTask:updateTextButtonFrame()
local mainWidth, _ = dfhack.screen.getWindowSize()
if (self._mainWidth == mainWidth) then return false end

self._mainWidth = mainWidth

-- calculated position of the left edge - not necessarily the real one if the screen is too narrow
local x1 = mainWidth + DetailsHotkeyOverlay_BuildingTask.ATTRS.default_pos.x - DetailsHotkeyOverlay_BuildingTask.ATTRS.frame.w

local offset = 0
if x1 < 0 then
x1 = 0
end
if x1 < 6 then
offset = 6 - x1
end

self.subviews.button.frame.l = offset

-- this restores original position for the case the screen was narrowed to the minimum
-- and then expanded again.
self.frame.r = - DetailsHotkeyOverlay_BuildingTask.ATTRS.default_pos.x - 1

return true
end

function DetailsHotkeyOverlay_BuildingTask:onRenderBody(dc)
if self:updateTextButtonFrame() then
self:updateLayout()
end

DetailsHotkeyOverlay_BuildingTask.super.onRenderBody(self, dc)
end

DetailsHotkeyOverlay_ManagerWorkOrder = defclass(DetailsHotkeyOverlay_ManagerWorkOrder, DetailsHotkeyOverlay)
DetailsHotkeyOverlay_ManagerWorkOrder.ATTRS{
default_pos={x=5, y=5}, -- {x=5, y=5} is right above the job title
viewscreens='dwarfmode/JobDetails/MANAGER_WORK_ORDER',
viewscreens={
'dwarfmode/JobDetails/MANAGER_WORK_ORDER',
-- as of DF50.11, once input materials in the task list are changed,
-- there is no going back (the magnifying glass button disappears),
-- which is why this option is disabled.
-- 'dwarfmode/JobDetails/TASK_LIST_TASK',
},
}

DetailsHotkeyOverlay_BuildingTask = defclass(DetailsHotkeyOverlay_BuildingTask, DetailsHotkeyOverlay)
DetailsHotkeyOverlay_BuildingTask.ATTRS{
default_pos={x=-120, y=6}, -- {x=-120, y=6} is right above the job title on all but smallest widths
viewscreens='dwarfmode/JobDetails/BUILDING_TASK_LIST',
DetailsHotkeyOverlay_ManagerWorkOrderConditions = defclass(DetailsHotkeyOverlay_ManagerWorkOrderConditions, DetailsHotkeyOverlay)
DetailsHotkeyOverlay_ManagerWorkOrderConditions.ATTRS{
default_pos={x=37, y=7},
frame={w=DetailsHotkeyOverlay.ATTRS.frame.w, h=3}, -- we need h=3 here to move the button around depending on tabs in one or two rows
viewscreens='dwarfmode/Info/WORK_ORDERS/Conditions',
}

--
-- change label position if window is resized
-- same logic as in workorder-recheck.lua
--
local function areTabsInTwoRows()
-- get the tile above the order status icon
local pen = dfhack.screen.readTile(7, 7, false)
-- in graphics mode, `0` when one row, something else when two (`67` aka 'C' from "Creatures")
-- in ASCII mode, `32` aka ' ' when one row, something else when two (`196` aka '-' from tab frame's top)
return pen.ch == 67 or pen.ch == 196
end

function DetailsHotkeyOverlay_ManagerWorkOrderConditions:updateTextButtonFrame()
local twoRows = areTabsInTwoRows()
if (self._twoRows == twoRows) then return false end

self._twoRows = twoRows
local frame = twoRows
and {b=0, l=0, r=0, h=1}
or {t=0, l=0, r=0, h=1}
self.subviews.button.frame = frame

return true
end

function DetailsHotkeyOverlay_ManagerWorkOrderConditions:onRenderBody(dc)
if (self.frame_rect.y1 == 7) then
-- only apply this logic if the overlay is on the same row as
-- originally thought: just above the order status icon

if self:updateTextButtonFrame() then
self:updateLayout()
end
end

DetailsHotkeyOverlay_ManagerWorkOrderConditions.super.onRenderBody(self, dc)
end

-- -------------------

OVERLAY_WIDGETS = {
job_details=DetailsHotkeyOverlay_BuildingTask,
workorder_details=DetailsHotkeyOverlay_ManagerWorkOrder,
workorder_conditions=DetailsHotkeyOverlay_ManagerWorkOrderConditions,
}

if dfhack_flags.module then
Expand Down
Loading