-
Notifications
You must be signed in to change notification settings - Fork 191
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 workorder-recheck
work again
#797
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8a4daf3
Update workorder-recheck.lua
TymurGubayev 9fd31b1
Update workorder-recheck.rst
TymurGubayev fcb7a53
remove doc-string from workorder-recheck.lua
TymurGubayev b2e0ac1
adjust widget position depending on tab rows
TymurGubayev 0015251
Update workorder-recheck.lua
TymurGubayev 8f053f7
Update workorder-recheck.lua
TymurGubayev 36a81f2
add is_current_active
TymurGubayev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,103 @@ | ||
-- Resets the selected work order to the `Checking` state | ||
--[====[ | ||
|
||
workorder-recheck | ||
================= | ||
Sets the status to ``Checking`` (from ``Active``) of the selected work order (in the ``j-m`` or ``u-m`` screens). | ||
This makes the manager reevaluate its conditions. | ||
]====] | ||
local scr = dfhack.gui.getCurViewscreen() | ||
if df.viewscreen_jobmanagementst:is_instance(scr) then | ||
local orders = df.global.world.manager_orders | ||
local idx = scr.sel_idx | ||
if idx < #orders then | ||
orders[idx].status.active = false | ||
|
||
--@ module = true | ||
|
||
local widgets = require('gui.widgets') | ||
local overlay = require('plugins.overlay') | ||
|
||
local function set_current_inactive() | ||
local scrConditions = df.global.game.main_interface.info.work_orders.conditions | ||
if scrConditions.open then | ||
local order = scrConditions.wq | ||
order.status.active = false | ||
else | ||
qerror("Invalid order selected") | ||
qerror("Order conditions is not open") | ||
end | ||
else | ||
qerror('Must be called on the manager screen (j-m or u-m)') | ||
end | ||
|
||
local function is_current_active() | ||
local scrConditions = df.global.game.main_interface.info.work_orders.conditions | ||
local order = scrConditions.wq | ||
return order.status.active | ||
end | ||
|
||
-- ------------------- | ||
-- RecheckOverlay | ||
-- | ||
|
||
local focusString = 'dwarfmode/Info/WORK_ORDERS/Conditions' | ||
|
||
RecheckOverlay = defclass(RecheckOverlay, overlay.OverlayWidget) | ||
RecheckOverlay.ATTRS{ | ||
default_pos={x=6,y=8}, | ||
default_enabled=true, | ||
viewscreens=focusString, | ||
-- width is the sum of lengths of `[` + `Ctrl+A` + `: ` + button.label + `]` | ||
frame={w=1 + 6 + 2 + 16 + 1, h=3}, | ||
} | ||
|
||
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 ~= 0 and pen.ch ~= 32) | ||
end | ||
|
||
function RecheckOverlay: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 RecheckOverlay:init() | ||
self:addviews{ | ||
widgets.TextButton{ | ||
view_id = 'button', | ||
-- frame={t=0, l=0, r=0, h=1}, -- is set in `updateTextButtonFrame()` | ||
label='request re-check', | ||
key='CUSTOM_CTRL_A', | ||
on_activate=set_current_inactive, | ||
TymurGubayev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
enabled=is_current_active, | ||
}, | ||
} | ||
|
||
self:updateTextButtonFrame() | ||
end | ||
|
||
function RecheckOverlay: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 | ||
|
||
RecheckOverlay.super.onRenderBody(self, dc) | ||
end | ||
|
||
-- ------------------- | ||
|
||
OVERLAY_WIDGETS = { | ||
recheck=RecheckOverlay, | ||
} | ||
|
||
if dfhack_flags.module then | ||
return | ||
end | ||
|
||
-- Check if on the correct screen and perform the action if so | ||
if not dfhack.gui.matchFocusString(focusString) then | ||
qerror('workorder-recheck must be run from the manager order conditions view') | ||
end | ||
|
||
set_current_inactive() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the condition that would allow the overlay to be shown or the focus string to match below. I suppose it doesn't hurt terribly to check it again, but I don't think it's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it in case something went terribly wrong. I guess the only possible scenario is if the overlay would somehow be active when it shouldn't...