|
| 1 | +local textures = require('gui.textures') |
| 2 | +local Panel = require('gui.widgets.containers.panel') |
| 3 | +local Label = require('gui.widgets.labels.label') |
| 4 | + |
| 5 | +local to_pen = dfhack.pen.parse |
| 6 | + |
| 7 | +---------------- |
| 8 | +-- HelpButton -- |
| 9 | +---------------- |
| 10 | + |
| 11 | +---@class widgets.HelpButton.attrs: widgets.Panel.attrs |
| 12 | +---@field command? string |
| 13 | + |
| 14 | +---@class widgets.HelpButton.attrs.partial: widgets.HelpButton.attrs |
| 15 | + |
| 16 | +---@class widgets.HelpButton: widgets.Panel, widgets.HelpButton.attrs |
| 17 | +---@field super widgets.Panel |
| 18 | +---@field ATTRS widgets.HelpButton.attrs|fun(attributes: widgets.HelpButton.attrs.partial) |
| 19 | +---@overload fun(init_table: widgets.HelpButton.attrs.partial): self |
| 20 | +HelpButton = defclass(HelpButton, Panel) |
| 21 | + |
| 22 | +HelpButton.ATTRS{ |
| 23 | + frame={t=0, r=1, w=3, h=1}, |
| 24 | + command=DEFAULT_NIL, |
| 25 | +} |
| 26 | + |
| 27 | +local button_pen_left = to_pen{fg=COLOR_CYAN, |
| 28 | + tile=curry(textures.tp_control_panel, 7) or nil, ch=string.byte('[')} |
| 29 | +local button_pen_right = to_pen{fg=COLOR_CYAN, |
| 30 | + tile=curry(textures.tp_control_panel, 8) or nil, ch=string.byte(']')} |
| 31 | +local help_pen_center = to_pen{ |
| 32 | + tile=curry(textures.tp_control_panel, 9) or nil, ch=string.byte('?')} |
| 33 | + |
| 34 | +function HelpButton:init() |
| 35 | + self.frame.w = self.frame.w or 3 |
| 36 | + self.frame.h = self.frame.h or 1 |
| 37 | + |
| 38 | + local command = self.command .. ' ' |
| 39 | + |
| 40 | + self:addviews{ |
| 41 | + Label{ |
| 42 | + frame={t=0, l=0, w=3, h=1}, |
| 43 | + text={ |
| 44 | + {tile=button_pen_left}, |
| 45 | + {tile=help_pen_center}, |
| 46 | + {tile=button_pen_right}, |
| 47 | + }, |
| 48 | + on_click=function() dfhack.run_command('gui/launcher', command) end, |
| 49 | + }, |
| 50 | + } |
| 51 | +end |
| 52 | + |
| 53 | +return HelpButton |
0 commit comments