Eduardo Bart e03bf33f58 BEAWARE all game functionality is disabled with this commit for a while
* rework client modules
* hide main window when loading
* remake top menu functions
* rework modules autoload
* improve path resolving for otml and lua
* move core_widgets to core_lib
* fix tooltip issues
* split some styles
* add bit32 lua library
* fix assert issues
* fix compilation on linux 32 systems
* rework gcc compile options
* renable and fix some warnings
* remove unused constants
* speedup sprite cache
* move UIGame to lua (not funcional yet)
* fix a lot of issues in x11 window
* fix crash handler
* add some warnings do uiwidget
and much more...
2012-02-20 00:28:13 -02:00

92 lines
2.3 KiB
Lua

TopMenu = {}
-- private variables
local topMenu
local leftButtonsPanel
local rightButtonsPanel
local gameButtonsPanel
-- private functions
local function addButton(id, description, icon, callback, panel, toggle)
local class
if toggle then
class = 'TopToggleButton'
else
class = 'TopButton'
end
local button = createWidget(class, panel)
button:setId(id)
button:setTooltip(description)
button:setIcon(resolvepath(icon, 3))
if toggle then
button.onCheckChange = callback
else
button.onClick = callback
end
return button
end
-- public functions
function TopMenu.init()
topMenu = displayUI('topmenu.otui')
leftButtonsPanel = topMenu:getChildById('leftButtonsPanel')
rightButtonsPanel = topMenu:getChildById('rightButtonsPanel')
gameButtonsPanel = topMenu:getChildById('gameButtonsPanel')
connect(g_game, { onGameStart = TopMenu.showGameButtons,
onGameEnd = TopMenu.hideGameButtons })
end
function TopMenu.terminate()
leftButtonsPanel = nil
rightButtonsPanel = nil
gameButtonsPanel = nil
topMenu:destroy()
topMenu = nil
disconnect(g_game, { onGameStart = TopMenu.showGameButtons,
onGameEnd = TopMenu.hideGameButtons })
TopMenu = nil
end
function TopMenu.addLeftButton(id, description, icon, callback)
return addButton(id, description, icon, callback, leftButtonsPanel, false)
end
function TopMenu.addLeftToggleButton(id, description, icon, callback, right)
return addButton(id, description, icon, callback, leftButtonsPanel, true)
end
function TopMenu.addRightButton(id, description, icon, callback)
return addButton(id, description, icon, callback, rightButtonsPanel, false)
end
function TopMenu.addRightToggleButton(id, description, icon, callback, right)
return addButton(id, description, icon, callback, rightButtonsPanel, true)
end
function TopMenu.addGameButton(id, description, icon, callback)
return addButton(id, description, icon, callback, gameButtonsPanel, false)
end
function TopMenu.addGameToggleButton(id, description, icon, callback, right)
return addButton(id, description, icon, callback, gameButtonsPanel, true)
end
function TopMenu.hideGameButtons()
gameButtonsPanel:hide()
end
function TopMenu.showGameButtons()
gameButtonsPanel:show()
end
function TopMenu.getButton(id)
return topMenu:recursiveGetChildById(id)
end