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-07-12 18:45:22 +02:00
|
|
|
local leftGameButtonsPanel
|
|
|
|
local rightGameButtonsPanel
|
2011-11-01 17:41:15 +01:00
|
|
|
|
2012-01-07 21:00:07 +01:00
|
|
|
-- private functions
|
2012-02-20 03:27:08 +01:00
|
|
|
local function addButton(id, description, icon, callback, panel, toggle)
|
|
|
|
local class
|
|
|
|
if toggle then
|
|
|
|
class = 'TopToggleButton'
|
|
|
|
else
|
|
|
|
class = 'TopButton'
|
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
local button = g_ui.createWidget(class, panel)
|
2012-02-20 03:27:08 +01:00
|
|
|
button:setId(id)
|
|
|
|
button:setTooltip(description)
|
|
|
|
button:setIcon(resolvepath(icon, 3))
|
2012-03-23 14:48:05 +01:00
|
|
|
button.onClick = callback
|
2012-02-20 03:27:08 +01:00
|
|
|
return button
|
2012-01-07 21:00:07 +01:00
|
|
|
end
|
|
|
|
|
2011-11-01 17:41:15 +01:00
|
|
|
-- public functions
|
2012-01-07 18:36:58 +01:00
|
|
|
function TopMenu.init()
|
2012-03-18 14:34:39 +01:00
|
|
|
connect(g_game, { onGameStart = TopMenu.showGameButtons,
|
|
|
|
onGameEnd = TopMenu.hideGameButtons })
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
topMenu = g_ui.displayUI('topmenu.otui')
|
2012-03-18 14:34:39 +01:00
|
|
|
|
2012-01-07 18:36:58 +01:00
|
|
|
leftButtonsPanel = topMenu:getChildById('leftButtonsPanel')
|
|
|
|
rightButtonsPanel = topMenu:getChildById('rightButtonsPanel')
|
2012-07-12 18:45:22 +02:00
|
|
|
leftGameButtonsPanel = topMenu:getChildById('leftGameButtonsPanel')
|
|
|
|
rightGameButtonsPanel = topMenu:getChildById('rightGameButtonsPanel')
|
2012-03-23 14:48:05 +01:00
|
|
|
|
|
|
|
if g_game.isOnline() then
|
2012-07-12 18:45:22 +02:00
|
|
|
leftGameButtonsPanel:show()
|
|
|
|
rightGameButtonsPanel:show()
|
2012-03-23 14:48:05 +01:00
|
|
|
end
|
2011-11-01 17:41:15 +01:00
|
|
|
end
|
|
|
|
|
2012-01-07 18:36:58 +01:00
|
|
|
function TopMenu.terminate()
|
2012-03-18 14:34:39 +01:00
|
|
|
disconnect(g_game, { onGameStart = TopMenu.showGameButtons,
|
|
|
|
onGameEnd = TopMenu.hideGameButtons })
|
|
|
|
|
2012-01-07 18:36:58 +01:00
|
|
|
leftButtonsPanel = nil
|
|
|
|
rightButtonsPanel = nil
|
2012-07-12 18:45:22 +02:00
|
|
|
leftGameButtonsPanel = nil
|
|
|
|
rightGameButtonsPanel = nil
|
2012-03-18 14:34:39 +01:00
|
|
|
|
2011-11-01 17:41:15 +01:00
|
|
|
topMenu:destroy()
|
|
|
|
topMenu = nil
|
2012-02-06 20:19:47 +01:00
|
|
|
|
2012-02-07 01:41:53 +01:00
|
|
|
TopMenu = nil
|
2011-11-16 19:08:42 +01:00
|
|
|
end
|
|
|
|
|
2012-02-20 03:27:08 +01:00
|
|
|
function TopMenu.addLeftButton(id, description, icon, callback)
|
|
|
|
return addButton(id, description, icon, callback, leftButtonsPanel, false)
|
|
|
|
end
|
2012-01-07 18:36:58 +01:00
|
|
|
|
2012-02-20 03:27:08 +01:00
|
|
|
function TopMenu.addLeftToggleButton(id, description, icon, callback, right)
|
|
|
|
return addButton(id, description, icon, callback, leftButtonsPanel, true)
|
2012-01-07 18:36:58 +01:00
|
|
|
end
|
|
|
|
|
2012-02-20 03:27:08 +01:00
|
|
|
function TopMenu.addRightButton(id, description, icon, callback)
|
|
|
|
return addButton(id, description, icon, callback, rightButtonsPanel, false)
|
2012-01-15 16:13:22 +01:00
|
|
|
end
|
|
|
|
|
2012-02-20 03:27:08 +01:00
|
|
|
function TopMenu.addRightToggleButton(id, description, icon, callback, right)
|
|
|
|
return addButton(id, description, icon, callback, rightButtonsPanel, true)
|
2012-01-07 18:36:58 +01:00
|
|
|
end
|
|
|
|
|
2012-07-12 18:45:22 +02:00
|
|
|
function TopMenu.addLeftGameButton(id, description, icon, callback)
|
|
|
|
return addButton(id, description, icon, callback, leftGameButtonsPanel, false)
|
2012-02-20 03:27:08 +01:00
|
|
|
end
|
|
|
|
|
2012-07-12 18:45:22 +02:00
|
|
|
function TopMenu.addLeftGameToggleButton(id, description, icon, callback, right)
|
|
|
|
return addButton(id, description, icon, callback, leftGameButtonsPanel, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
function TopMenu.addRightGameButton(id, description, icon, callback)
|
|
|
|
return addButton(id, description, icon, callback, rightGameButtonsPanel, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
function TopMenu.addRightGameToggleButton(id, description, icon, callback, right)
|
|
|
|
return addButton(id, description, icon, callback, rightGameButtonsPanel, true)
|
2012-01-07 18:36:58 +01:00
|
|
|
end
|
|
|
|
|
2012-01-23 14:47:15 +01:00
|
|
|
function TopMenu.hideGameButtons()
|
2012-07-12 18:45:22 +02:00
|
|
|
leftGameButtonsPanel:hide()
|
|
|
|
rightGameButtonsPanel:hide()
|
2012-01-23 14:47:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function TopMenu.showGameButtons()
|
2012-07-12 18:45:22 +02:00
|
|
|
leftGameButtonsPanel:show()
|
|
|
|
rightGameButtonsPanel:show()
|
2012-01-23 14:47:15 +01:00
|
|
|
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
|
2012-02-20 03:27:08 +01:00
|
|
|
|
|
|
|
|