From dc56d6c0a19197257f4683c1db51e7f94932ab86 Mon Sep 17 00:00:00 2001 From: Magistrum <136035179+MagistrumT-T@users.noreply.github.com> Date: Tue, 6 Feb 2024 23:33:31 -0300 Subject: [PATCH 1/9] Create gui\probe Creates a tool that will run probe on the position of the mouse and show it in a screen in the right corner of the screen. --- gui/probe.lua | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 gui/probe.lua diff --git a/gui/probe.lua b/gui/probe.lua new file mode 100644 index 0000000000..a5d6fc550f --- /dev/null +++ b/gui/probe.lua @@ -0,0 +1,71 @@ +-- Shows the info given by `probe` in a friendly display + +local gui = require('gui') +local guidm = require('gui.dwarfmode') +local widgets = require('gui.widgets') +local overlay = require('plugins.overlay') + +Probe = defclass(Probe, widgets.Window) +Probe.ATTRS{ + frame = { + w = 40, + h = 45, + r = 2, + t = 18, + }, + resizable=true, + frame_title='Probe', +} + +function Probe:init() + self:addviews{ + widgets.ToggleHotkeyLabel{ + view_id='lock', + frame={t=0, l=0}, + key='CUSTOM_CTRL_F', + label='Lock on tile:', + initial_option=false, + }, + widgets.Label{ + view_id='report', + frame={t=2, l=0}, + }, + } +end + +function Probe:onRenderBody() + if self.subviews.lock:getOptionValue() then return end + guidm.setCursorPos(dfhack.gui.getMousePos()) + local report = dfhack.run_command_silent('probe') + self.subviews.report:setText(report) + self:updateLayout() +end + +function Probe:onInput(keys) + if Probe.super.onInput(self, keys) then + return true + end + if keys._MOUSE_L and not self:getMouseFramePos() then + self.subviews.lock:cycle() + return true + end +end + +ProbeScreen = defclass(ProbeScreen, gui.ZScreenModal) +ProbeScreen.ATTRS{ + focus_string='probe-screen', +} + +function ProbeScreen:init() + self:addviews{Probe{}} +end + +function ProbeScreen:onDismiss() + view = nil +end + +if not dfhack.isMapLoaded() then + qerror("This script requires a fortress map to be loaded") +end + +view = view and view:raise() or ProbeScreen {}:show() From 5788e71d1ac0d39db0368e4e232a88574abee842 Mon Sep 17 00:00:00 2001 From: Magistrum <136035179+MagistrumT-T@users.noreply.github.com> Date: Wed, 7 Feb 2024 23:51:25 -0300 Subject: [PATCH 2/9] Remove sneaky tabs and stop checking the tiles under the window. --- gui/probe.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gui/probe.lua b/gui/probe.lua index a5d6fc550f..87d0205da9 100644 --- a/gui/probe.lua +++ b/gui/probe.lua @@ -19,7 +19,7 @@ Probe.ATTRS{ function Probe:init() self:addviews{ - widgets.ToggleHotkeyLabel{ + widgets.ToggleHotkeyLabel{ view_id='lock', frame={t=0, l=0}, key='CUSTOM_CTRL_F', @@ -34,8 +34,8 @@ function Probe:init() end function Probe:onRenderBody() - if self.subviews.lock:getOptionValue() then return end - guidm.setCursorPos(dfhack.gui.getMousePos()) + if self.subviews.lock:getOptionValue() or self:getMouseFramePos() then return end + guidm.setCursorPos(dfhack.gui.getMousePos()) local report = dfhack.run_command_silent('probe') self.subviews.report:setText(report) self:updateLayout() From 3f1f13f52f75eb334f93050bb7d522b8018b1847 Mon Sep 17 00:00:00 2001 From: Magistrum <136035179+MagistrumT-T@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:11:27 -0300 Subject: [PATCH 3/9] Give user ability to unpause and move map around. Switches from ZScreenModal to ZScreen to stop being greedy with the inputs. --- gui/probe.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gui/probe.lua b/gui/probe.lua index 87d0205da9..8fa756467a 100644 --- a/gui/probe.lua +++ b/gui/probe.lua @@ -51,9 +51,11 @@ function Probe:onInput(keys) end end -ProbeScreen = defclass(ProbeScreen, gui.ZScreenModal) +ProbeScreen = defclass(ProbeScreen, gui.ZScreen) ProbeScreen.ATTRS{ focus_string='probe-screen', + pass_pause = true, + pass_movement_keys = true, } function ProbeScreen:init() From 2266109e06bf1a08ed1a39f34ea289ef3db34185 Mon Sep 17 00:00:00 2001 From: Magistrum <136035179+MagistrumT-T@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:40:17 -0300 Subject: [PATCH 4/9] Bring in suggested changes. Doesn't keep updating the keyboard cursor position anymore. --- gui/probe.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gui/probe.lua b/gui/probe.lua index 8fa756467a..e09d45efd1 100644 --- a/gui/probe.lua +++ b/gui/probe.lua @@ -26,7 +26,7 @@ function Probe:init() label='Lock on tile:', initial_option=false, }, - widgets.Label{ + widgets.WrappedLabel{ view_id='report', frame={t=2, l=0}, }, @@ -35,9 +35,9 @@ end function Probe:onRenderBody() if self.subviews.lock:getOptionValue() or self:getMouseFramePos() then return end - guidm.setCursorPos(dfhack.gui.getMousePos()) - local report = dfhack.run_command_silent('probe') - self.subviews.report:setText(report) + pos = dfhack.gui.getMousePos() + local report = dfhack.run_command_silent('probe', '--cursor', string.format("%d,%d,%d", pos.x, pos.y, pos.z)) + self.subviews.report.text_to_wrap = report self:updateLayout() end @@ -53,7 +53,7 @@ end ProbeScreen = defclass(ProbeScreen, gui.ZScreen) ProbeScreen.ATTRS{ - focus_string='probe-screen', + focus_string = 'probe', pass_pause = true, pass_movement_keys = true, } From 38fa629b4b92619d6f02c175ebc015f6dcadcc50 Mon Sep 17 00:00:00 2001 From: Magistrum <136035179+MagistrumT-T@users.noreply.github.com> Date: Sun, 11 Feb 2024 23:31:39 -0300 Subject: [PATCH 5/9] Add changelog and docs entry. "Hovering" kind of makes it seem like holding the mouse over any tile without doing anything will trigger it, but I think one would quickly discover that isn't the case and try to run it anyway. --- changelog.txt | 1 + docs/gui/probe.rst | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 docs/gui/probe.rst diff --git a/changelog.txt b/changelog.txt index 3c21789bbc..3069364dc5 100644 --- a/changelog.txt +++ b/changelog.txt @@ -27,6 +27,7 @@ Template for new versions: # Future ## New Tools +- `gui/probe`: Now you can check the properties of a tile by hovering the mouse over it. ## New Features diff --git a/docs/gui/probe.rst b/docs/gui/probe.rst new file mode 100644 index 0000000000..4da1b4cfd6 --- /dev/null +++ b/docs/gui/probe.rst @@ -0,0 +1,17 @@ +gui/probe +=========== + +.. dfhack-tool:: + :summary: Check tile properties. + :tags: fort inspection map + +Shows the output of "probe"(tiletype, material, temperature, etc...) on the tile below mouse on a window on the right hand of the screen. + +Usage +----- + +:: + + gui/confirm + +Hover the mouse over the tile you wish to inspect, left click to lock on the current tile. From 4e6a0efe53c55f02e8a8ded69fc390ba69ef2615 Mon Sep 17 00:00:00 2001 From: Magistrum <136035179+MagistrumT-T@users.noreply.github.com> Date: Sun, 11 Feb 2024 23:58:50 -0300 Subject: [PATCH 6/9] Add mouse over tile marker. --- gui/probe.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gui/probe.lua b/gui/probe.lua index e09d45efd1..7647fa4701 100644 --- a/gui/probe.lua +++ b/gui/probe.lua @@ -17,6 +17,17 @@ Probe.ATTRS{ frame_title='Probe', } +local cursor_pen = dfhack.pen.parse { + ch = "+", + fg = COLOR_YELLOW, + keep_lower = true, + tile = dfhack.screen.findGraphicsTile( + "CURSORS", + 0, + 22 + ), +} + function Probe:init() self:addviews{ widgets.ToggleHotkeyLabel{ @@ -34,8 +45,9 @@ function Probe:init() end function Probe:onRenderBody() - if self.subviews.lock:getOptionValue() or self:getMouseFramePos() then return end pos = dfhack.gui.getMousePos() + guidm.renderMapOverlay(function() return cursor_pen end, {x1 = pos.x, x2= pos.x, y1 = pos.y, y2= pos.y, z1 = pos.z, z2= pos.z}) + if self.subviews.lock:getOptionValue() or self:getMouseFramePos() then return end local report = dfhack.run_command_silent('probe', '--cursor', string.format("%d,%d,%d", pos.x, pos.y, pos.z)) self.subviews.report.text_to_wrap = report self:updateLayout() From 8ca9bb2ca29d98b22225fdf141227081168e3463 Mon Sep 17 00:00:00 2001 From: Magistrum <136035179+MagistrumT-T@users.noreply.github.com> Date: Wed, 14 Feb 2024 23:33:06 -0300 Subject: [PATCH 7/9] Make the cursor blink when in ascii mode When in graphics mode it just renders over the current tile transparently, so I think it doesn't need to blink there. --- gui/probe.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gui/probe.lua b/gui/probe.lua index 7647fa4701..33eb6ed454 100644 --- a/gui/probe.lua +++ b/gui/probe.lua @@ -46,7 +46,11 @@ end function Probe:onRenderBody() pos = dfhack.gui.getMousePos() - guidm.renderMapOverlay(function() return cursor_pen end, {x1 = pos.x, x2= pos.x, y1 = pos.y, y2= pos.y, z1 = pos.z, z2= pos.z}) + if dfhack.screen.inGraphicsMode() then + guidm.renderMapOverlay(function() return cursor_pen end, {x1 = pos.x, x2= pos.x, y1 = pos.y, y2= pos.y, z1 = pos.z, z2= pos.z}) + elseif gui.blink_visible(500) then + guidm.renderMapOverlay(function() return cursor_pen end, {x1 = pos.x, x2= pos.x, y1 = pos.y, y2= pos.y, z1 = pos.z, z2= pos.z}) + end if self.subviews.lock:getOptionValue() or self:getMouseFramePos() then return end local report = dfhack.run_command_silent('probe', '--cursor', string.format("%d,%d,%d", pos.x, pos.y, pos.z)) self.subviews.report.text_to_wrap = report From 3518bf4fc503ec7b1612a7b5decb90237e2dcc5f Mon Sep 17 00:00:00 2001 From: Magistrum <136035179+MagistrumT-T@users.noreply.github.com> Date: Thu, 15 Feb 2024 00:06:46 -0300 Subject: [PATCH 8/9] Keep cursor at last probed position when locked or havering the panel. Forgot the lock and screen over behavior on the last commit. --- gui/probe.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/probe.lua b/gui/probe.lua index 33eb6ed454..226eb6c25a 100644 --- a/gui/probe.lua +++ b/gui/probe.lua @@ -45,13 +45,13 @@ function Probe:init() end function Probe:onRenderBody() - pos = dfhack.gui.getMousePos() if dfhack.screen.inGraphicsMode() then guidm.renderMapOverlay(function() return cursor_pen end, {x1 = pos.x, x2= pos.x, y1 = pos.y, y2= pos.y, z1 = pos.z, z2= pos.z}) elseif gui.blink_visible(500) then guidm.renderMapOverlay(function() return cursor_pen end, {x1 = pos.x, x2= pos.x, y1 = pos.y, y2= pos.y, z1 = pos.z, z2= pos.z}) end if self.subviews.lock:getOptionValue() or self:getMouseFramePos() then return end + pos = dfhack.gui.getMousePos() local report = dfhack.run_command_silent('probe', '--cursor', string.format("%d,%d,%d", pos.x, pos.y, pos.z)) self.subviews.report.text_to_wrap = report self:updateLayout() From bc9347f7a27112dab6d32c5ba242ab8f23012427 Mon Sep 17 00:00:00 2001 From: Magistrum <136035179+MagistrumT-T@users.noreply.github.com> Date: Wed, 21 Feb 2024 20:49:50 -0300 Subject: [PATCH 9/9] Add cprobe and bprobe functionality. Also noticed that I had set the lock key to 'f' instead of 'ctrl-f'. --- gui/probe.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/gui/probe.lua b/gui/probe.lua index 226eb6c25a..ec0a90bdaa 100644 --- a/gui/probe.lua +++ b/gui/probe.lua @@ -15,6 +15,7 @@ Probe.ATTRS{ }, resizable=true, frame_title='Probe', + cycle_lock=false, } local cursor_pen = dfhack.pen.parse { @@ -31,6 +32,7 @@ local cursor_pen = dfhack.pen.parse { function Probe:init() self:addviews{ widgets.ToggleHotkeyLabel{ + key='CUSTOM_CTRL_F', view_id='lock', frame={t=0, l=0}, key='CUSTOM_CTRL_F', @@ -45,13 +47,40 @@ function Probe:init() end function Probe:onRenderBody() + --Cycle the cursor lock if the user just clicked the map. + if self.cycle_lock then + if not (dfhack.gui.getSelectedUnit(true) or dfhack.gui.getSelectedBuilding(true)) then + self.subviews.lock:cycle() + end + self.cycle_lock = false + end + + --If a unit is selected, show unit details. + if dfhack.gui.getSelectedUnit(true) then + local report = dfhack.run_command_silent('cprobe') + self.subviews.report.text_to_wrap = report + self:updateLayout() + return true + end + + --If a building is selected, show building details. + if dfhack.gui.getSelectedBuilding(true) then + local report = dfhack.run_command_silent('bprobe') + self.subviews.report.text_to_wrap = report + self:updateLayout() + return true + end + + --If nor unit nor building is selected, show cursor and details on the tile under mouse. if dfhack.screen.inGraphicsMode() then guidm.renderMapOverlay(function() return cursor_pen end, {x1 = pos.x, x2= pos.x, y1 = pos.y, y2= pos.y, z1 = pos.z, z2= pos.z}) elseif gui.blink_visible(500) then guidm.renderMapOverlay(function() return cursor_pen end, {x1 = pos.x, x2= pos.x, y1 = pos.y, y2= pos.y, z1 = pos.z, z2= pos.z}) end - if self.subviews.lock:getOptionValue() or self:getMouseFramePos() then return end - pos = dfhack.gui.getMousePos() + + if not (self.subviews.lock:getOptionValue() or self:getMouseFramePos()) then + pos = dfhack.gui.getMousePos() or pos + end local report = dfhack.run_command_silent('probe', '--cursor', string.format("%d,%d,%d", pos.x, pos.y, pos.z)) self.subviews.report.text_to_wrap = report self:updateLayout() @@ -61,9 +90,21 @@ function Probe:onInput(keys) if Probe.super.onInput(self, keys) then return true end + + --Cycle the cursor lock if the user clicks the map. if keys._MOUSE_L and not self:getMouseFramePos() then - self.subviews.lock:cycle() - return true + self.cycle_lock = true + return false + end + + if (keys.LEAVESCREEN or keys._MOUSE_R) then + if dfhack.gui.getSelectedUnit(true) or dfhack.gui.getSelectedBuilding(true) then + self.parent_view:sendInputToParent(keys) + return true + else + self.parent_view:dismiss() + return true + end end end @@ -72,6 +113,8 @@ ProbeScreen.ATTRS{ focus_string = 'probe', pass_pause = true, pass_movement_keys = true, + pass_mouse_clicks = true, + defocusable=false, } function ProbeScreen:init()