|
|
@ -17,8 +17,8 @@ end
|
|
|
|
function should_hide_armok(cmdline)
|
|
|
|
function should_hide_armok(cmdline)
|
|
|
|
local command = get_command(cmdline)
|
|
|
|
local command = get_command(cmdline)
|
|
|
|
return dfhack.getHideArmokTools() and
|
|
|
|
return dfhack.getHideArmokTools() and
|
|
|
|
helpdb.is_entry(command) and
|
|
|
|
helpdb.is_entry(command) and
|
|
|
|
helpdb.get_entry_tags(command).armok
|
|
|
|
helpdb.get_entry_tags(command).armok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- ----------------- --
|
|
|
|
-- ----------------- --
|
|
|
@ -26,11 +26,11 @@ end
|
|
|
|
-- ----------------- --
|
|
|
|
-- ----------------- --
|
|
|
|
|
|
|
|
|
|
|
|
HotspotMenuWidget = defclass(HotspotMenuWidget, overlay.OverlayWidget)
|
|
|
|
HotspotMenuWidget = defclass(HotspotMenuWidget, overlay.OverlayWidget)
|
|
|
|
HotspotMenuWidget.ATTRS {
|
|
|
|
HotspotMenuWidget.ATTRS{
|
|
|
|
default_pos = { x = 5, y = 1 },
|
|
|
|
default_pos={x=5,y=1},
|
|
|
|
default_enabled = true,
|
|
|
|
default_enabled=true,
|
|
|
|
version = 2,
|
|
|
|
version=2,
|
|
|
|
viewscreens = {
|
|
|
|
viewscreens={
|
|
|
|
'adopt_region',
|
|
|
|
'adopt_region',
|
|
|
|
'choose_game_type',
|
|
|
|
'choose_game_type',
|
|
|
|
-- 'choose_start_site', -- conflicts with vanilla panel layouts
|
|
|
|
-- 'choose_start_site', -- conflicts with vanilla panel layouts
|
|
|
@ -48,51 +48,51 @@ HotspotMenuWidget.ATTRS {
|
|
|
|
'update_region',
|
|
|
|
'update_region',
|
|
|
|
'world'
|
|
|
|
'world'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
frame = { w = 4, h = 3 }
|
|
|
|
frame={w=4, h=3}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function HotspotMenuWidget:init()
|
|
|
|
function HotspotMenuWidget:init()
|
|
|
|
local to_pen = dfhack.pen.parse
|
|
|
|
local to_pen = dfhack.pen.parse
|
|
|
|
local function tp(idx, ch)
|
|
|
|
local function tp(idx, ch)
|
|
|
|
return to_pen {
|
|
|
|
return to_pen{
|
|
|
|
tile = function() return dfhack.textures.getTexposByHandle(logo_textures[idx]) end,
|
|
|
|
tile=function() return dfhack.textures.getTexposByHandle(logo_textures[idx]) end,
|
|
|
|
ch = ch,
|
|
|
|
ch=ch,
|
|
|
|
fg = COLOR_GREY,
|
|
|
|
fg=COLOR_GREY,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local function tph(idx, ch)
|
|
|
|
local function tph(idx, ch)
|
|
|
|
return to_pen {
|
|
|
|
return to_pen{
|
|
|
|
tile = function() return dfhack.textures.getTexposByHandle(logo_hovered_textures[idx]) end,
|
|
|
|
tile=function() return dfhack.textures.getTexposByHandle(logo_hovered_textures[idx]) end,
|
|
|
|
ch = ch,
|
|
|
|
ch=ch,
|
|
|
|
fg = COLOR_WHITE,
|
|
|
|
fg=COLOR_WHITE,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local function get_tile_token(idx, ch)
|
|
|
|
local function get_tile_token(idx, ch)
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
tile = tp(idx, ch),
|
|
|
|
tile=tp(idx, ch),
|
|
|
|
htile = tph(idx, ch),
|
|
|
|
htile=tph(idx, ch),
|
|
|
|
width = 1,
|
|
|
|
width=1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
self:addviews {
|
|
|
|
self:addviews{
|
|
|
|
widgets.Label {
|
|
|
|
widgets.Label{
|
|
|
|
text = {
|
|
|
|
text={
|
|
|
|
get_tile_token(1, '!'), get_tile_token(2, 'D'), get_tile_token(3, 'F'), get_tile_token(4, '!'), NEWLINE,
|
|
|
|
get_tile_token(1, '!'), get_tile_token(2, 'D'), get_tile_token(3, 'F'), get_tile_token(4, '!'), NEWLINE,
|
|
|
|
get_tile_token(5, '!'), get_tile_token(6, 'H'), get_tile_token(7, 'a'), get_tile_token(8, '!'), NEWLINE,
|
|
|
|
get_tile_token(5, '!'), get_tile_token(6, 'H'), get_tile_token(7, 'a'), get_tile_token(8, '!'), NEWLINE,
|
|
|
|
get_tile_token(9, '!'), get_tile_token(10, 'c'), get_tile_token(11, 'k'), get_tile_token(12, '!'),
|
|
|
|
get_tile_token(9, '!'), get_tile_token(10, 'c'), get_tile_token(11, 'k'), get_tile_token(12, '!'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
on_click = function() dfhack.run_command('hotkeys') end,
|
|
|
|
on_click=function() dfhack.run_command('hotkeys') end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function HotspotMenuWidget:overlay_trigger()
|
|
|
|
function HotspotMenuWidget:overlay_trigger()
|
|
|
|
return MenuScreen { hotspot = self }:show()
|
|
|
|
return MenuScreen{hotspot=self}:show()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- register the menu hotspot with the overlay
|
|
|
|
-- register the menu hotspot with the overlay
|
|
|
|
OVERLAY_WIDGETS = { menu = HotspotMenuWidget }
|
|
|
|
OVERLAY_WIDGETS = {menu=HotspotMenuWidget}
|
|
|
|
|
|
|
|
|
|
|
|
-- ---- --
|
|
|
|
-- ---- --
|
|
|
|
-- Menu --
|
|
|
|
-- Menu --
|
|
|
@ -103,15 +103,15 @@ local MAX_LIST_WIDTH = 45
|
|
|
|
local MAX_LIST_HEIGHT = 15
|
|
|
|
local MAX_LIST_HEIGHT = 15
|
|
|
|
|
|
|
|
|
|
|
|
Menu = defclass(Menu, widgets.Panel)
|
|
|
|
Menu = defclass(Menu, widgets.Panel)
|
|
|
|
Menu.ATTRS {
|
|
|
|
Menu.ATTRS{
|
|
|
|
hotspot = DEFAULT_NIL,
|
|
|
|
hotspot=DEFAULT_NIL,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-- get a map from the binding string to a list of hotkey strings that all
|
|
|
|
-- get a map from the binding string to a list of hotkey strings that all
|
|
|
|
-- point to that binding
|
|
|
|
-- point to that binding
|
|
|
|
local function get_bindings_to_hotkeys(hotkeys, bindings)
|
|
|
|
local function get_bindings_to_hotkeys(hotkeys, bindings)
|
|
|
|
local bindings_to_hotkeys = {}
|
|
|
|
local bindings_to_hotkeys = {}
|
|
|
|
for _, hotkey in ipairs(hotkeys) do
|
|
|
|
for _,hotkey in ipairs(hotkeys) do
|
|
|
|
local binding = bindings[hotkey]
|
|
|
|
local binding = bindings[hotkey]
|
|
|
|
table.insert(ensure_key(bindings_to_hotkeys, binding), hotkey)
|
|
|
|
table.insert(ensure_key(bindings_to_hotkeys, binding), hotkey)
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -126,17 +126,17 @@ local function get_choices(hotkeys, bindings, is_inverted)
|
|
|
|
local bindings_to_hotkeys = get_bindings_to_hotkeys(hotkeys, bindings)
|
|
|
|
local bindings_to_hotkeys = get_bindings_to_hotkeys(hotkeys, bindings)
|
|
|
|
|
|
|
|
|
|
|
|
-- build list choices
|
|
|
|
-- build list choices
|
|
|
|
for _, hotkey in ipairs(hotkeys) do
|
|
|
|
for _,hotkey in ipairs(hotkeys) do
|
|
|
|
local command = bindings[hotkey]
|
|
|
|
local command = bindings[hotkey]
|
|
|
|
if seen[command] then goto continue end
|
|
|
|
if seen[command] then goto continue end
|
|
|
|
seen[command] = true
|
|
|
|
seen[command] = true
|
|
|
|
local hk_width, tokens = 0, {}
|
|
|
|
local hk_width, tokens = 0, {}
|
|
|
|
for _, hk in ipairs(bindings_to_hotkeys[command]) do
|
|
|
|
for _,hk in ipairs(bindings_to_hotkeys[command]) do
|
|
|
|
if hk_width ~= 0 then
|
|
|
|
if hk_width ~= 0 then
|
|
|
|
table.insert(tokens, ', ')
|
|
|
|
table.insert(tokens, ', ')
|
|
|
|
hk_width = hk_width + 2
|
|
|
|
hk_width = hk_width + 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.insert(tokens, { text = hk, pen = COLOR_LIGHTGREEN })
|
|
|
|
table.insert(tokens, {text=hk, pen=COLOR_LIGHTGREEN})
|
|
|
|
hk_width = hk_width + #hk
|
|
|
|
hk_width = hk_width + #hk
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local command_str = command
|
|
|
|
local command_str = command
|
|
|
@ -144,20 +144,16 @@ local function get_choices(hotkeys, bindings, is_inverted)
|
|
|
|
local max_command_len = MAX_LIST_WIDTH - hk_width - LIST_BUFFER
|
|
|
|
local max_command_len = MAX_LIST_WIDTH - hk_width - LIST_BUFFER
|
|
|
|
command_str = command:sub(1, max_command_len - 3) .. '...'
|
|
|
|
command_str = command:sub(1, max_command_len - 3) .. '...'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.insert(tokens, 1, { text = command_str })
|
|
|
|
table.insert(tokens, 1, {text=command_str})
|
|
|
|
local choice = {
|
|
|
|
local choice = {icon=ARROW, command=command, text=tokens,
|
|
|
|
icon = ARROW,
|
|
|
|
hk_width=hk_width}
|
|
|
|
command = command,
|
|
|
|
|
|
|
|
text = tokens,
|
|
|
|
|
|
|
|
hk_width = hk_width
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
max_width = math.max(max_width, hk_width + #command_str + LIST_BUFFER)
|
|
|
|
max_width = math.max(max_width, hk_width + #command_str + LIST_BUFFER)
|
|
|
|
table.insert(choices, is_inverted and 1 or #choices + 1, choice)
|
|
|
|
table.insert(choices, is_inverted and 1 or #choices + 1, choice)
|
|
|
|
::continue::
|
|
|
|
::continue::
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- adjust width of command fields so the hotkey tokens are right justified
|
|
|
|
-- adjust width of command fields so the hotkey tokens are right justified
|
|
|
|
for _, choice in ipairs(choices) do
|
|
|
|
for _,choice in ipairs(choices) do
|
|
|
|
local command_token = choice.text[1]
|
|
|
|
local command_token = choice.text[1]
|
|
|
|
command_token.width = max_width - choice.hk_width - (LIST_BUFFER - 1)
|
|
|
|
command_token.width = max_width - choice.hk_width - (LIST_BUFFER - 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -168,19 +164,17 @@ end
|
|
|
|
function Menu:init()
|
|
|
|
function Menu:init()
|
|
|
|
local hotkeys, bindings = getHotkeys()
|
|
|
|
local hotkeys, bindings = getHotkeys()
|
|
|
|
if #hotkeys == 0 then
|
|
|
|
if #hotkeys == 0 then
|
|
|
|
hotkeys = { '' }
|
|
|
|
hotkeys = {''}
|
|
|
|
bindings = { [''] = 'gui/launcher' }
|
|
|
|
bindings = {['']='gui/launcher'}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local is_inverted = not not self.hotspot.frame.b
|
|
|
|
local is_inverted = not not self.hotspot.frame.b
|
|
|
|
local choices, list_width = get_choices(hotkeys, bindings, is_inverted)
|
|
|
|
local choices,list_width = get_choices(hotkeys, bindings, is_inverted)
|
|
|
|
|
|
|
|
|
|
|
|
list_width = math.max(35, list_width)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list_width = math.max(35, list_width)
|
|
|
|
list_width = math.max(35, list_width)
|
|
|
|
|
|
|
|
|
|
|
|
local list_frame = copyall(self.hotspot.frame)
|
|
|
|
local list_frame = copyall(self.hotspot.frame)
|
|
|
|
local list_widget_frame = { h = math.min(#choices, MAX_LIST_HEIGHT) }
|
|
|
|
local list_widget_frame = {h=math.min(#choices, MAX_LIST_HEIGHT)}
|
|
|
|
local quickstart_frame = {}
|
|
|
|
local quickstart_frame = {}
|
|
|
|
list_frame.w = list_width + 2
|
|
|
|
list_frame.w = list_width + 2
|
|
|
|
list_frame.h = list_widget_frame.h + 4
|
|
|
|
list_frame.h = list_widget_frame.h + 4
|
|
|
@ -199,51 +193,51 @@ function Menu:init()
|
|
|
|
list_frame.r = math.max(0, list_frame.r + 5)
|
|
|
|
list_frame.r = math.max(0, list_frame.r + 5)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local help_frame = { w = list_frame.w, l = list_frame.l, r = list_frame.r }
|
|
|
|
local help_frame = {w=list_frame.w, l=list_frame.l, r=list_frame.r}
|
|
|
|
if list_frame.t then
|
|
|
|
if list_frame.t then
|
|
|
|
help_frame.t = list_frame.t + list_frame.h
|
|
|
|
help_frame.t = list_frame.t + list_frame.h
|
|
|
|
else
|
|
|
|
else
|
|
|
|
help_frame.b = list_frame.b + list_frame.h
|
|
|
|
help_frame.b = list_frame.b + list_frame.h
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
self:addviews {
|
|
|
|
self:addviews{
|
|
|
|
widgets.Panel {
|
|
|
|
widgets.Panel{
|
|
|
|
view_id = 'list_panel',
|
|
|
|
view_id='list_panel',
|
|
|
|
frame = list_frame,
|
|
|
|
frame=list_frame,
|
|
|
|
frame_style = gui.PANEL_FRAME,
|
|
|
|
frame_style=gui.PANEL_FRAME,
|
|
|
|
frame_background = gui.CLEAR_PEN,
|
|
|
|
frame_background=gui.CLEAR_PEN,
|
|
|
|
subviews = {
|
|
|
|
subviews={
|
|
|
|
widgets.List {
|
|
|
|
widgets.List{
|
|
|
|
view_id = 'list',
|
|
|
|
view_id='list',
|
|
|
|
frame = list_widget_frame,
|
|
|
|
frame=list_widget_frame,
|
|
|
|
choices = choices,
|
|
|
|
choices=choices,
|
|
|
|
icon_width = 2,
|
|
|
|
icon_width=2,
|
|
|
|
on_select = self:callback('onSelect'),
|
|
|
|
on_select=self:callback('onSelect'),
|
|
|
|
on_submit = self:callback('onSubmit'),
|
|
|
|
on_submit=self:callback('onSubmit'),
|
|
|
|
on_submit2 = self:callback('onSubmit2'),
|
|
|
|
on_submit2=self:callback('onSubmit2'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
widgets.Panel { frame = { h = 1 } },
|
|
|
|
widgets.Panel{frame={h=1}},
|
|
|
|
widgets.HotkeyLabel {
|
|
|
|
widgets.HotkeyLabel{
|
|
|
|
frame = quickstart_frame,
|
|
|
|
frame=quickstart_frame,
|
|
|
|
label = 'Quickstart guide',
|
|
|
|
label='Quickstart guide',
|
|
|
|
key = 'STRING_A063',
|
|
|
|
key='STRING_A063',
|
|
|
|
on_activate = function()
|
|
|
|
on_activate=function()
|
|
|
|
self:onSubmit(nil, { command = 'quickstart-guide' })
|
|
|
|
self:onSubmit(nil, {command='quickstart-guide'})
|
|
|
|
end,
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
widgets.ResizingPanel {
|
|
|
|
widgets.ResizingPanel{
|
|
|
|
view_id = 'help_panel',
|
|
|
|
view_id='help_panel',
|
|
|
|
autoarrange_subviews = true,
|
|
|
|
autoarrange_subviews=true,
|
|
|
|
frame = help_frame,
|
|
|
|
frame=help_frame,
|
|
|
|
frame_style = gui.PANEL_FRAME,
|
|
|
|
frame_style=gui.PANEL_FRAME,
|
|
|
|
frame_background = gui.CLEAR_PEN,
|
|
|
|
frame_background=gui.CLEAR_PEN,
|
|
|
|
subviews = {
|
|
|
|
subviews={
|
|
|
|
widgets.WrappedLabel {
|
|
|
|
widgets.WrappedLabel{
|
|
|
|
view_id = 'help',
|
|
|
|
view_id='help',
|
|
|
|
text_to_wrap = '',
|
|
|
|
text_to_wrap='',
|
|
|
|
scroll_keys = {},
|
|
|
|
scroll_keys={},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -258,7 +252,7 @@ function Menu:onSelect(_, choice)
|
|
|
|
if not choice or #self.subviews == 0 then return end
|
|
|
|
if not choice or #self.subviews == 0 then return end
|
|
|
|
local command = get_command(choice.command)
|
|
|
|
local command = get_command(choice.command)
|
|
|
|
self.subviews.help.text_to_wrap = helpdb.is_entry(command) and
|
|
|
|
self.subviews.help.text_to_wrap = helpdb.is_entry(command) and
|
|
|
|
helpdb.get_entry_short_help(command) or 'Command not found'
|
|
|
|
helpdb.get_entry_short_help(command) or 'Command not found'
|
|
|
|
self.subviews.help_panel:updateLayout()
|
|
|
|
self.subviews.help_panel:updateLayout()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -308,7 +302,7 @@ end
|
|
|
|
|
|
|
|
|
|
|
|
function Menu:getMouseFramePos()
|
|
|
|
function Menu:getMouseFramePos()
|
|
|
|
return self.subviews.list_panel:getMouseFramePos() or
|
|
|
|
return self.subviews.list_panel:getMouseFramePos() or
|
|
|
|
self.subviews.help_panel:getMouseFramePos()
|
|
|
|
self.subviews.help_panel:getMouseFramePos()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Menu:onRenderBody(dc)
|
|
|
|
function Menu:onRenderBody(dc)
|
|
|
@ -330,14 +324,14 @@ end
|
|
|
|
|
|
|
|
|
|
|
|
MenuScreen = defclass(MenuScreen, gui.ZScreen)
|
|
|
|
MenuScreen = defclass(MenuScreen, gui.ZScreen)
|
|
|
|
MenuScreen.ATTRS {
|
|
|
|
MenuScreen.ATTRS {
|
|
|
|
focus_path = 'hotkeys/menu',
|
|
|
|
focus_path='hotkeys/menu',
|
|
|
|
initial_pause = false,
|
|
|
|
initial_pause=false,
|
|
|
|
hotspot = DEFAULT_NIL,
|
|
|
|
hotspot=DEFAULT_NIL,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function MenuScreen:init()
|
|
|
|
function MenuScreen:init()
|
|
|
|
self:addviews {
|
|
|
|
self:addviews{
|
|
|
|
Menu { hotspot = self.hotspot },
|
|
|
|
Menu{hotspot=self.hotspot},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -345,4 +339,4 @@ function MenuScreen:onDismiss()
|
|
|
|
cleanupHotkeys()
|
|
|
|
cleanupHotkeys()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return _ENV
|
|
|
|
return _ENV
|