tibia-client/modules/client_topmenu/topmenu.lua

115 lines
3.1 KiB
Lua
Raw Normal View History

2011-11-01 17:41:15 +01:00
-- private variables
local topMenu
2012-01-07 18:36:58 +01:00
local leftButtonsPanel
local rightButtonsPanel
local leftGameButtonsPanel
local rightGameButtonsPanel
2011-11-01 17:41:15 +01:00
2012-01-07 21:00:07 +01:00
-- private functions
local function addButton(id, description, icon, callback, panel, toggle, front)
local class
if toggle then
class = 'TopToggleButton'
else
class = 'TopButton'
end
local button = g_ui.createWidget(class)
if front then
panel:insertChild(1, button)
else
panel:addChild(button)
end
button:setId(id)
button:setTooltip(description)
2013-01-19 01:24:40 +01:00
button:setIcon(resolvepath(icon, 3))
button.onMouseRelease = function(widget, mousePos, mouseButton)
if widget:containsPoint(mousePos) and mouseButton ~= MouseMiddleButton then
callback()
return true
end
end
return button
2012-01-07 21:00:07 +01:00
end
2011-11-01 17:41:15 +01:00
-- public functions
function init()
connect(g_game, { onGameStart = showGameButtons,
onGameEnd = hideGameButtons })
topMenu = g_ui.displayUI('topmenu')
2012-01-07 18:36:58 +01:00
leftButtonsPanel = topMenu:getChildById('leftButtonsPanel')
rightButtonsPanel = topMenu:getChildById('rightButtonsPanel')
leftGameButtonsPanel = topMenu:getChildById('leftGameButtonsPanel')
rightGameButtonsPanel = topMenu:getChildById('rightGameButtonsPanel')
if g_game.isOnline() then
leftGameButtonsPanel:show()
rightGameButtonsPanel:show()
end
2011-11-01 17:41:15 +01:00
end
function terminate()
disconnect(g_game, { onGameStart = showGameButtons,
onGameEnd = hideGameButtons })
2012-01-07 18:36:58 +01:00
leftButtonsPanel = nil
rightButtonsPanel = nil
leftGameButtonsPanel = nil
rightGameButtonsPanel = nil
2011-11-01 17:41:15 +01:00
topMenu:destroy()
topMenu = nil
2011-11-16 19:08:42 +01:00
end
function addLeftButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, leftButtonsPanel, false, front)
end
2012-01-07 18:36:58 +01:00
function addLeftToggleButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, leftButtonsPanel, true, front)
2012-01-07 18:36:58 +01:00
end
function addRightButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, rightButtonsPanel, false, front)
end
function addRightToggleButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, rightButtonsPanel, true, front)
2012-01-07 18:36:58 +01:00
end
function addLeftGameButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, leftGameButtonsPanel, false, front)
end
function addLeftGameToggleButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, leftGameButtonsPanel, true, front)
end
function addRightGameButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, rightGameButtonsPanel, false, front)
end
function addRightGameToggleButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, rightGameButtonsPanel, true, front)
2012-01-07 18:36:58 +01:00
end
function hideGameButtons()
leftGameButtonsPanel:hide()
rightGameButtonsPanel:hide()
2012-01-23 14:47:15 +01:00
end
function showGameButtons()
leftGameButtonsPanel:show()
rightGameButtonsPanel:show()
2012-01-23 14:47:15 +01:00
end
function getButton(id)
2012-01-07 18:36:58 +01:00
return topMenu:recursiveGetChildById(id)
end
function getTopMenu()
return topMenu
end