2011-11-01 17:41:15 +01:00
|
|
|
TopMenu = {}
|
|
|
|
|
|
|
|
-- private variables
|
|
|
|
local topMenu
|
2012-01-07 18:36:58 +01:00
|
|
|
local leftButtonsPanel
|
|
|
|
local rightButtonsPanel
|
2012-01-15 16:13:22 +01:00
|
|
|
local gameButtonsPanel
|
2011-11-01 17:41:15 +01:00
|
|
|
|
2012-01-07 21:00:07 +01:00
|
|
|
-- private functions
|
|
|
|
local function onLogout()
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.isOnline() then
|
|
|
|
g_game.safeLogout()
|
2012-01-07 21:00:07 +01:00
|
|
|
else
|
|
|
|
exit()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-01 17:41:15 +01:00
|
|
|
-- public functions
|
2012-01-07 18:36:58 +01:00
|
|
|
function TopMenu.init()
|
2012-01-03 01:42:53 +01:00
|
|
|
topMenu = displayUI('topmenu.otui')
|
2012-01-07 18:36:58 +01:00
|
|
|
leftButtonsPanel = topMenu:getChildById('leftButtonsPanel')
|
|
|
|
rightButtonsPanel = topMenu:getChildById('rightButtonsPanel')
|
2012-01-15 16:13:22 +01:00
|
|
|
gameButtonsPanel = topMenu:getChildById('gameButtonsPanel')
|
2012-01-07 18:36:58 +01:00
|
|
|
|
2012-01-07 21:00:07 +01:00
|
|
|
TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout)
|
2012-02-06 05:39:52 +01:00
|
|
|
Keyboard.bindKeyDown('Ctrl+Q', onLogout)
|
2012-02-06 20:19:47 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
connect(g_game, { onGameStart = TopMenu.showGameButtons,
|
2012-02-08 00:54:33 +01:00
|
|
|
onGameEnd = TopMenu.hideGameButtons })
|
2011-11-01 17:41:15 +01:00
|
|
|
end
|
|
|
|
|
2012-01-07 18:36:58 +01:00
|
|
|
function TopMenu.terminate()
|
2012-02-06 05:39:52 +01:00
|
|
|
Keyboard.unbindKeyDown('Ctrl+Q')
|
2012-01-07 18:36:58 +01:00
|
|
|
leftButtonsPanel = nil
|
|
|
|
rightButtonsPanel = nil
|
2012-02-05 23:42:35 +01:00
|
|
|
gameButtonsPanel = nil
|
2011-11-01 17:41:15 +01:00
|
|
|
topMenu:destroy()
|
|
|
|
topMenu = nil
|
2012-02-06 20:19:47 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
disconnect(g_game, { onGameStart = TopMenu.showGameButtons,
|
2012-02-08 00:54:33 +01:00
|
|
|
onGameEnd = TopMenu.hideGameButtons })
|
2012-02-07 01:41:53 +01:00
|
|
|
|
|
|
|
TopMenu = nil
|
2011-11-16 19:08:42 +01:00
|
|
|
end
|
|
|
|
|
2012-01-07 18:36:58 +01:00
|
|
|
function TopMenu.addButton(id, description, icon, callback, right)
|
|
|
|
local panel
|
|
|
|
local class
|
|
|
|
if right then
|
|
|
|
panel = rightButtonsPanel
|
|
|
|
class = 'TopRightButton'
|
|
|
|
else
|
|
|
|
panel = leftButtonsPanel
|
|
|
|
class = 'TopLeftButton'
|
|
|
|
end
|
|
|
|
|
|
|
|
local button = createWidget(class, panel)
|
|
|
|
button:setId(id)
|
|
|
|
button:setTooltip(description)
|
|
|
|
button:setIcon(resolvepath(icon, 2))
|
|
|
|
button.onClick = callback
|
|
|
|
return button
|
|
|
|
end
|
|
|
|
|
2012-01-15 16:13:22 +01:00
|
|
|
function TopMenu.addGameButton(id, description, icon, callback)
|
|
|
|
local button = createWidget('GameTopButton', gameButtonsPanel)
|
|
|
|
button:setId(id)
|
|
|
|
button:setTooltip(description)
|
|
|
|
button:setIcon(resolvepath(icon, 2))
|
|
|
|
button.onClick = callback
|
|
|
|
return button
|
|
|
|
end
|
|
|
|
|
2012-01-07 18:36:58 +01:00
|
|
|
function TopMenu.addLeftButton(id, description, icon, callback)
|
2012-01-24 19:39:16 +01:00
|
|
|
return TopMenu.addButton(id, description, resolvepath(icon, 2), callback, false)
|
2012-01-07 18:36:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function TopMenu.addRightButton(id, description, icon, callback)
|
2012-01-24 19:39:16 +01:00
|
|
|
return TopMenu.addButton(id, description, resolvepath(icon, 2), callback, true)
|
2012-01-07 18:36:58 +01:00
|
|
|
end
|
|
|
|
|
2012-01-23 14:47:15 +01:00
|
|
|
function TopMenu.hideGameButtons()
|
|
|
|
gameButtonsPanel:hide()
|
|
|
|
end
|
|
|
|
|
|
|
|
function TopMenu.showGameButtons()
|
|
|
|
gameButtonsPanel:show()
|
|
|
|
end
|
|
|
|
|
2011-11-16 19:08:42 +01:00
|
|
|
function TopMenu.getButton(id)
|
2012-01-07 18:36:58 +01:00
|
|
|
return topMenu:recursiveGetChildById(id)
|
|
|
|
end
|