From 16248953b0d07e72225f7bea9b2a3919ddaaaa54 Mon Sep 17 00:00:00 2001 From: unboundlopez Date: Sun, 1 Jun 2025 12:39:49 -0500 Subject: [PATCH 01/11] Add zSelectLockLabors script and documentation --- docs/zSelectLockLabors.rst | 48 +++++++++++++++++++ zSelectLockLabors.lua | 94 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 docs/zSelectLockLabors.rst create mode 100644 zSelectLockLabors.lua diff --git a/docs/zSelectLockLabors.rst b/docs/zSelectLockLabors.rst new file mode 100644 index 000000000..a06cb9adb --- /dev/null +++ b/docs/zSelectLockLabors.rst @@ -0,0 +1,48 @@ +Select Lock Overlay +=================== + +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. + +Features +-------- + +- **Overlay Interface**: Integrated directly into the `LABOR/WORK_DETAILS` viewscreen. +- **Action Modes**: Choose between `Select only`, `Lock only`, or `Select + Lock`. +- **Batch Processing**: Specify how many entries to affect and apply actions with one click. +- **Non-Intrusive**: Uses DFHack GUI input simulation to trigger existing functionality. + +Usage +----- + +Once the plugin is loaded and you're in the `Work Details` screen (e.g., `u` -> `Work Details`), the overlay will automatically appear. + +1. Use the **Mode** dropdown to select what action(s) to simulate: + - `Select only`: Just toggles unit selection. + - `Lock only`: Just toggles the lock status. + - `Select + Lock`: Toggles both selection and lock. + +2. Adjust the number of entries to apply actions to (default is 100). + +3. Press the **RUN** button (or the hotkey defined for it) to execute the actions. + +Install +------- + +1. Place this script in your DFHack `hack/scripts` directory. +2. Ensure the plugin is listed in your `dfhack.init` or loaded manually via `:lua require('select_lock_overlay')`. + +Contributing +------------ + +Pull requests and issues are welcome! Please make sure your changes follow the existing code style. + +License +------- + +This plugin is distributed under the MIT License. See ``LICENSE`` for more information. + +Author +------ + +This plugin was written for DFHack by [Your Name Here]. + diff --git a/zSelectLockLabors.lua b/zSelectLockLabors.lua new file mode 100644 index 000000000..339e23caf --- /dev/null +++ b/zSelectLockLabors.lua @@ -0,0 +1,94 @@ +--@module=true +local gui = require('gui') +local widgets = require('gui.widgets') +local overlay = require('plugins.overlay') + +local SelectLockOverlay = defclass(nil, overlay.OverlayWidget) +SelectLockOverlay.ATTRS { + desc = 'Simulate selection and locking of multiple units.', + viewscreens = {'dwarfmode/Info/LABOR/WORK_DETAILS/Default'}, + default_enabled = true, + default_pos = {x = -70, y = 10}, + frame = {w = 25, h = 6, r = 1, t = 1, transparent = false}, +} + +local function simulate_actions(self, count) + local function step(i) + if i > count then + for _ = 1, count do + gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_UP') + gui.simulateInput(dfhack.gui.getCurViewscreen(), 'CONTEXT_SCROLL_UP') + end + self.is_running = false + return + end + + if self.action_mode ~= 'lock' then + gui.simulateInput(dfhack.gui.getCurViewscreen(), 'SELECT') + end + if self.action_mode ~= 'select' then + gui.simulateInput(dfhack.gui.getCurViewscreen(), 'UNITLIST_SPECIALIZE') + end + gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_DOWN') + gui.simulateInput(dfhack.gui.getCurViewscreen(), 'CONTEXT_SCROLL_DOWN') + + dfhack.timeout(2, 'frames', function() step(i + 1) end) + end + + step(1) +end + +function SelectLockOverlay:init() + self.action_mode = 'both' + self.entry_count = 100 + self.is_running = false + self:addviews{ + widgets.Panel{ + frame_style = gui.MEDIUM_FRAME, + frame_background = gui.CLEAR_PEN, + subviews = { + widgets.CycleHotkeyLabel{ + view_id = 'action_mode', + frame = {l = 1, t = 1}, + label = 'Mode', + option_gap = 2, + options = { + {label = 'Select only', value = 'select'}, + {label = 'Lock only', value = 'lock'}, + {label = 'Select + Lock', value = 'both'}, + }, + initial_option = 'both', + on_change = function(val) self.action_mode = val end, + }, + widgets.EditField{ + numeric = true, + frame = {l = 1, t = 2}, + key = 'CUSTOM_CTRL_N', + auto_focus = false, + text = '100', + on_change = function(val) + local num = tonumber(val) + self.entry_count = (num and num > 0 and math.floor(num)) or 100 + end, + }, + widgets.HotkeyLabel{ + view_id = 'run_button', + frame = {l = 1, t = 3}, + label = 'RUN', + on_activate = function() + if self.is_running then return end + self.is_running = true + simulate_actions(self, self.entry_count) + end, + enabled = function() return not self.is_running end, + }, + }, + }, + } +end + +OVERLAY_WIDGETS = { + select_lock_overlay = SelectLockOverlay, +} + +return {} From 72bc102fbf24dfbc299645f75a0a9f6d94829140 Mon Sep 17 00:00:00 2001 From: unboundlopez <47876628+unboundlopez@users.noreply.github.com> Date: Sun, 1 Jun 2025 12:43:06 -0500 Subject: [PATCH 02/11] Update zSelectLockLabors.rst --- docs/zSelectLockLabors.rst | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/docs/zSelectLockLabors.rst b/docs/zSelectLockLabors.rst index a06cb9adb..74e82dbaf 100644 --- a/docs/zSelectLockLabors.rst +++ b/docs/zSelectLockLabors.rst @@ -24,25 +24,3 @@ Once the plugin is loaded and you're in the `Work Details` screen (e.g., `u` -> 2. Adjust the number of entries to apply actions to (default is 100). 3. Press the **RUN** button (or the hotkey defined for it) to execute the actions. - -Install -------- - -1. Place this script in your DFHack `hack/scripts` directory. -2. Ensure the plugin is listed in your `dfhack.init` or loaded manually via `:lua require('select_lock_overlay')`. - -Contributing ------------- - -Pull requests and issues are welcome! Please make sure your changes follow the existing code style. - -License -------- - -This plugin is distributed under the MIT License. See ``LICENSE`` for more information. - -Author ------- - -This plugin was written for DFHack by [Your Name Here]. - From f37b9d759f0f4f43470a257a0f5c1c5feb766aad Mon Sep 17 00:00:00 2001 From: unboundlopez <47876628+unboundlopez@users.noreply.github.com> Date: Sun, 1 Jun 2025 12:51:54 -0500 Subject: [PATCH 03/11] Update zSelectLockLabors.rst --- docs/zSelectLockLabors.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zSelectLockLabors.rst b/docs/zSelectLockLabors.rst index 74e82dbaf..4cfa2ff9b 100644 --- a/docs/zSelectLockLabors.rst +++ b/docs/zSelectLockLabors.rst @@ -14,7 +14,7 @@ Features Usage ----- -Once the plugin is loaded and you're in the `Work Details` screen (e.g., `u` -> `Work Details`), the overlay will automatically appear. +Once the plugin is loaded and you're in the `Work Details` screen (e.g., `y` -> `Work Details`), the overlay will automatically appear. 1. Use the **Mode** dropdown to select what action(s) to simulate: - `Select only`: Just toggles unit selection. From 5b3abf685612ae098c1aff8b4c4ff551a4d60bdd Mon Sep 17 00:00:00 2001 From: unboundlopez <47876628+unboundlopez@users.noreply.github.com> Date: Sun, 1 Jun 2025 16:27:46 -0500 Subject: [PATCH 04/11] Removed gui.simulateInput(dfhack.gui.getCurViewscreen(), 'CONTEXT_SCROLL_DOWN') --- zSelectLockLabors.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/zSelectLockLabors.lua b/zSelectLockLabors.lua index 339e23caf..9b06b7488 100644 --- a/zSelectLockLabors.lua +++ b/zSelectLockLabors.lua @@ -30,7 +30,6 @@ local function simulate_actions(self, count) gui.simulateInput(dfhack.gui.getCurViewscreen(), 'UNITLIST_SPECIALIZE') end gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_DOWN') - gui.simulateInput(dfhack.gui.getCurViewscreen(), 'CONTEXT_SCROLL_DOWN') dfhack.timeout(2, 'frames', function() step(i + 1) end) end From 52defde3ef358be0f1b25b673d28bd875ef7954d Mon Sep 17 00:00:00 2001 From: unboundlopez <47876628+unboundlopez@users.noreply.github.com> Date: Sun, 1 Jun 2025 17:06:48 -0500 Subject: [PATCH 05/11] Update zSelectLockLabors.lua --- zSelectLockLabors.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zSelectLockLabors.lua b/zSelectLockLabors.lua index 9b06b7488..d6aa9aa42 100644 --- a/zSelectLockLabors.lua +++ b/zSelectLockLabors.lua @@ -29,7 +29,10 @@ local function simulate_actions(self, count) if self.action_mode ~= 'select' then gui.simulateInput(dfhack.gui.getCurViewscreen(), 'UNITLIST_SPECIALIZE') end + --This line is keyboard arrow down gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_DOWN') + --CONTEXT_SCROLL_DOWN helps with consistency. Otherwise the program will miss some units. Line below is scroll wheel down + gui.simulateInput(dfhack.gui.getCurViewscreen(), 'CONTEXT_SCROLL_DOWN') dfhack.timeout(2, 'frames', function() step(i + 1) end) end From 58e7ea52f03530eda3f0390b0b88b31203c57274 Mon Sep 17 00:00:00 2001 From: unboundlopez <47876628+unboundlopez@users.noreply.github.com> Date: Sun, 1 Jun 2025 19:41:27 -0500 Subject: [PATCH 06/11] added gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_RIGHT') added gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_RIGHT') reason: in the event that the user does not select a unit and the selection is only the labor choices(by default). This line will select the first unit on the list. --- zSelectLockLabors.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zSelectLockLabors.lua b/zSelectLockLabors.lua index d6aa9aa42..03a2ef446 100644 --- a/zSelectLockLabors.lua +++ b/zSelectLockLabors.lua @@ -13,6 +13,8 @@ SelectLockOverlay.ATTRS { } local function simulate_actions(self, count) + gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_RIGHT') + local function step(i) if i > count then for _ = 1, count do From b48dd5dfcb0880c3d561b42a1a5c449415a50eb5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Jun 2025 21:39:15 +0000 Subject: [PATCH 07/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- zSelectLockLabors.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zSelectLockLabors.lua b/zSelectLockLabors.lua index 03a2ef446..0e37d2e08 100644 --- a/zSelectLockLabors.lua +++ b/zSelectLockLabors.lua @@ -14,7 +14,7 @@ SelectLockOverlay.ATTRS { local function simulate_actions(self, count) gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_RIGHT') - + local function step(i) if i > count then for _ = 1, count do From 20ee74b3b9022ca54fd91f554925896ce6b22e96 Mon Sep 17 00:00:00 2001 From: unboundlopez <47876628+unboundlopez@users.noreply.github.com> Date: Wed, 4 Jun 2025 12:36:48 -0500 Subject: [PATCH 08/11] Update zSelectLockLabors.lua I think 7 as a default is reasonable compared to 100 --- zSelectLockLabors.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zSelectLockLabors.lua b/zSelectLockLabors.lua index 0e37d2e08..912a9091b 100644 --- a/zSelectLockLabors.lua +++ b/zSelectLockLabors.lua @@ -69,7 +69,7 @@ function SelectLockOverlay:init() frame = {l = 1, t = 2}, key = 'CUSTOM_CTRL_N', auto_focus = false, - text = '100', + text = '7', on_change = function(val) local num = tonumber(val) self.entry_count = (num and num > 0 and math.floor(num)) or 100 From 3908ae693675ad5614e01fe37f6b0dbb59b9be6c Mon Sep 17 00:00:00 2001 From: unboundlopez <47876628+unboundlopez@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:41:13 -0500 Subject: [PATCH 09/11] Update zSelectLockLabors.rst --- docs/zSelectLockLabors.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zSelectLockLabors.rst b/docs/zSelectLockLabors.rst index 4cfa2ff9b..9ddb76714 100644 --- a/docs/zSelectLockLabors.rst +++ b/docs/zSelectLockLabors.rst @@ -21,6 +21,6 @@ Once the plugin is loaded and you're in the `Work Details` screen (e.g., `y` -> - `Lock only`: Just toggles the lock status. - `Select + Lock`: Toggles both selection and lock. -2. Adjust the number of entries to apply actions to (default is 100). +2. Adjust the number of entries to apply actions to (default is 7). 3. Press the **RUN** button (or the hotkey defined for it) to execute the actions. From 3718568ae78f81939362ba67235adeea5d56afc2 Mon Sep 17 00:00:00 2001 From: unboundlopez <47876628+unboundlopez@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:42:42 -0500 Subject: [PATCH 10/11] Update zSelectLockLabors.lua --- zSelectLockLabors.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zSelectLockLabors.lua b/zSelectLockLabors.lua index 912a9091b..4cef24158 100644 --- a/zSelectLockLabors.lua +++ b/zSelectLockLabors.lua @@ -14,7 +14,7 @@ SelectLockOverlay.ATTRS { local function simulate_actions(self, count) gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_RIGHT') - + local function step(i) if i > count then for _ = 1, count do @@ -36,7 +36,7 @@ local function simulate_actions(self, count) --CONTEXT_SCROLL_DOWN helps with consistency. Otherwise the program will miss some units. Line below is scroll wheel down gui.simulateInput(dfhack.gui.getCurViewscreen(), 'CONTEXT_SCROLL_DOWN') - dfhack.timeout(2, 'frames', function() step(i + 1) end) + dfhack.timeout(3, 'frames', function() step(i + 1) end) end step(1) @@ -44,7 +44,7 @@ end function SelectLockOverlay:init() self.action_mode = 'both' - self.entry_count = 100 + self.entry_count = 7 self.is_running = false self:addviews{ widgets.Panel{ @@ -72,7 +72,7 @@ function SelectLockOverlay:init() text = '7', on_change = function(val) local num = tonumber(val) - self.entry_count = (num and num > 0 and math.floor(num)) or 100 + self.entry_count = (num and num > 0 and math.floor(num)) or 7 end, }, widgets.HotkeyLabel{ From acc7de36c567e727635676a99d6b558189e87d24 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 27 Jun 2025 12:43:06 +0000 Subject: [PATCH 11/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- zSelectLockLabors.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zSelectLockLabors.lua b/zSelectLockLabors.lua index 4cef24158..0187c95d4 100644 --- a/zSelectLockLabors.lua +++ b/zSelectLockLabors.lua @@ -14,7 +14,7 @@ SelectLockOverlay.ATTRS { local function simulate_actions(self, count) gui.simulateInput(dfhack.gui.getCurViewscreen(), 'STANDARDSCROLL_RIGHT') - + local function step(i) if i > count then for _ = 1, count do