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

gui/probe candidate #967

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
71 changes: 71 additions & 0 deletions gui/probe.lua
Original file line number Diff line number Diff line change
@@ -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{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you're allowing the window to be resized, a widgets.WrappedLabel might be more appropriate here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I have done it I find it a bit harder to understand this way. The wrapping is perfect for the tiletypes section, but on the materials section it becomes difficult to parse and to someone who is not already used to probe it is impossible to discern what it is describing because there are a lot of colons on the material names/description.

Wondering if having text clearly going off screen wouldn't be better to hint to the player that he should extend the screen if he needs that bit of info, but I don't know if it is even common knowledge that you can move and resize DFHack screens, considering vanilla screens don't let you I don't think anyone even tries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the text needs better formatting, you have a few options:

  1. change the formatting of probe itself
  2. have probe return the raw data in a structure via a Lua API call and you can format it yourself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking a bit about it, I believe it would be very clear where and how wrapping is happening if we just color the words before the first colon on each line(if present). I don't suppose we have any markup or anything like that for the current label text pen situation? If not I think we are going with 2.

view_id='report',
frame={t=2, l=0},
},
}
end

function Probe:onRenderBody()
if self.subviews.lock:getOptionValue() or self:getMouseFramePos() then return end
guidm.setCursorPos(dfhack.gui.getMousePos())
MagistrumT-T marked this conversation as resolved.
Show resolved Hide resolved
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',
MagistrumT-T marked this conversation as resolved.
Show resolved Hide resolved
}

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()
Loading