-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathquickstart-guide.lua
124 lines (114 loc) · 3.32 KB
/
quickstart-guide.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
-- quickstart visual help manual
local gui = require('gui')
local widgets = require('gui.widgets')
local GUIDE_FILE = 'hack/docs/docs/Quickstart.txt'
local function add_section_widget(sections, section)
if #section == 0 then return end
local section_text = table.concat(section, NEWLINE)
local widget = widgets.WrappedLabel{
frame={t=0},
text_to_wrap=section_text,
}
table.insert(sections, widget)
end
local function get_sections()
local sections, section = {}, {}
local ok, lines = pcall(io.lines, GUIDE_FILE)
if not ok then
table.insert(section, 'Guide text not found!')
add_section_widget(sections, section)
return sections
end
local prev_line = nil
for line in lines do
line = dfhack.utf2df(line)
if line:match('^[=-]+$') then
add_section_widget(sections, section)
section = {}
end
table.insert(section, prev_line)
prev_line = line
end
table.insert(section, prev_line)
add_section_widget(sections, section)
return sections
end
Quickstart = defclass(Quickstart, widgets.Window)
Quickstart.ATTRS {
frame_title='DFHack Quickstart Guide',
frame={w=50, h=45},
resizable=true,
resize_min={w=43, h=20},
}
function Quickstart:init()
local is_not_first_page_fn = function()
return self.subviews.pages:getSelected() > 1
end
local is_not_last_page_fn = function()
return self.subviews.pages:getSelected() < #self.subviews.pages.subviews
end
local prev_page_fn = function()
local pages = self.subviews.pages
pages:setSelected(pages:getSelected() - 1)
end
local next_page_fn = function()
local pages = self.subviews.pages
pages:setSelected(pages:getSelected() + 1)
end
self:addviews{
widgets.Pages{
view_id='pages',
frame={t=0, l=0, r=0, b=2},
subviews=get_sections(),
},
widgets.HotkeyLabel{
frame={l=0, b=0},
label='Back',
auto_width=true,
key='KEYBOARD_CURSOR_LEFT',
on_activate=prev_page_fn,
active=is_not_first_page_fn,
enabled=is_not_first_page_fn,
},
widgets.Label{
frame={l=0, b=0, w=1},
text_pen=COLOR_LIGHTGREEN,
text=string.char(27),
},
widgets.Label{
frame={b=0},
auto_width=true,
text={
'Page ',
{text=function() return (self.subviews.pages:getSelected()) end},
' of ',
{text=function() return #self.subviews.pages.subviews end}
},
},
widgets.HotkeyLabel{
frame={r=0, b=0},
label='Next',
auto_width=true,
key='KEYBOARD_CURSOR_RIGHT',
on_activate=next_page_fn,
active=is_not_last_page_fn,
enabled=is_not_last_page_fn,
},
widgets.Label{
frame={r=6, b=0, w=1},
text_pen=COLOR_LIGHTGREEN,
text=string.char(26),
},
}
end
QuickstartScreen = defclass(QuickstartScreen, gui.ZScreen)
QuickstartScreen.ATTRS {
focus_path='quickstart',
}
function QuickstartScreen:init()
self:addviews{Quickstart{}}
end
function QuickstartScreen:onDismiss()
view = nil
end
view = view and view:raise() or QuickstartScreen{}:show()