Skip to content

Commit c218558

Browse files
authored
Merge pull request #8 from unboundlopez/codex/rename-zselectlocklabors-to-selectlocklabors
Tighten SelectLockLabors input handling and refresh viewscreen; rename docs
2 parents c595134 + 830edb5 commit c218558

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,40 @@ SelectLockOverlay.ATTRS {
1212
frame = {w = 25, h = 6, r = 1, t = 1, transparent = false},
1313
}
1414

15+
local function sanitize_entry_count(count, fallback)
16+
local num = tonumber(count)
17+
if num then
18+
return math.max(1, math.floor(num))
19+
end
20+
return fallback
21+
end
22+
1523
local function simulate_actions(self, count)
16-
gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_RIGHT')
24+
count = sanitize_entry_count(count, 1)
25+
gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_RIGHT')
1726

1827
local function step(i)
1928
if i > count then
2029
for _ = 1, count do
21-
gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_UP')
22-
gui.simulateInput(dfhack.gui.getCurViewscreen(), 'CONTEXT_SCROLL_UP')
30+
local viewscreen = dfhack.gui.getCurViewscreen()
31+
gui.simulateInput(viewscreen, 'STANDARDSCROLL_UP')
32+
gui.simulateInput(viewscreen, 'CONTEXT_SCROLL_UP')
2333
end
2434
self.is_running = false
2535
return
2636
end
2737

38+
local viewscreen = dfhack.gui.getCurViewscreen()
2839
if self.action_mode ~= 'lock' then
29-
gui.simulateInput(dfhack.gui.getCurViewscreen(), 'SELECT')
40+
gui.simulateInput(viewscreen, 'SELECT')
3041
end
3142
if self.action_mode ~= 'select' then
32-
gui.simulateInput(dfhack.gui.getCurViewscreen(), 'UNITLIST_SPECIALIZE')
43+
gui.simulateInput(viewscreen, 'UNITLIST_SPECIALIZE')
3344
end
3445
--This line is keyboard arrow down
35-
gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_DOWN')
46+
gui.simulateInput(viewscreen, 'STANDARDSCROLL_DOWN')
3647
--CONTEXT_SCROLL_DOWN helps with consistency. Otherwise the program will miss some units. Line below is scroll wheel down
37-
gui.simulateInput(dfhack.gui.getCurViewscreen(), 'CONTEXT_SCROLL_DOWN')
48+
gui.simulateInput(viewscreen, 'CONTEXT_SCROLL_DOWN')
3849

3950
dfhack.timeout(3, 'frames', function() step(i + 1) end)
4051
end
@@ -69,10 +80,9 @@ function SelectLockOverlay:init()
6980
frame = {l = 1, t = 2},
7081
key = 'CUSTOM_CTRL_N',
7182
auto_focus = false,
72-
text = '7',
83+
text = tostring(self.entry_count),
7384
on_change = function(val)
74-
local num = tonumber(val)
75-
self.entry_count = (num and num > 0 and math.floor(num)) or 7
85+
self.entry_count = sanitize_entry_count(val, self.entry_count)
7686
end,
7787
},
7888
widgets.HotkeyLabel{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Select Lock Overlay
22
===================
33

4-
This is a DFHack overlay plugin for Dwarf Fortress that simulates the selection and locking of multiple units within the **Work Details** screen. It provides a simple UI interface to batch-toggle units' labor assignments, either by selecting, locking, or both.
4+
This is a DFHack overlay plugin for Dwarf Fortress (`SelectLockLabors`) that simulates the selection and locking of multiple units within the **Work Details** screen. It provides a simple UI interface to batch-toggle units' labor assignments, either by selecting, locking, or both.
55

66
Features
77
--------

0 commit comments

Comments
 (0)