Eduardo Bart 28b5fc1d5a Refactor modules, closes #223
* All modules are sandboxed now
* All images,sounds,fonts,translations and styles were moved to "data" folder
* Reorganize image files folders
* Remove unmaintained modules: client_particles, client_shaders
* Implement new automatic way to load styles and fonts
* Add hide/show offline option in VipList
* Add invite/exclude to/from private channel in players menus
* Many other minor changes
2013-01-18 20:46:36 -02:00

115 lines
3.1 KiB
Lua

-- private variables
local topMenu
local leftButtonsPanel
local rightButtonsPanel
local leftGameButtonsPanel
local rightGameButtonsPanel
-- 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)
button:setIcon(icon, 3)
button.onMouseRelease = function(widget, mousePos, mouseButton)
if widget:containsPoint(mousePos) and mouseButton ~= MouseMiddleButton then
callback()
return true
end
end
return button
end
-- public functions
function init()
connect(g_game, { onGameStart = showGameButtons,
onGameEnd = hideGameButtons })
topMenu = g_ui.displayUI('topmenu')
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
end
function terminate()
disconnect(g_game, { onGameStart = showGameButtons,
onGameEnd = hideGameButtons })
leftButtonsPanel = nil
rightButtonsPanel = nil
leftGameButtonsPanel = nil
rightGameButtonsPanel = nil
topMenu:destroy()
topMenu = nil
end
function addLeftButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, leftButtonsPanel, false, front)
end
function addLeftToggleButton(id, description, icon, callback, front)
return addButton(id, description, icon, callback, leftButtonsPanel, true, front)
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)
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)
end
function hideGameButtons()
leftGameButtonsPanel:hide()
rightGameButtonsPanel:hide()
end
function showGameButtons()
leftGameButtonsPanel:show()
rightGameButtonsPanel:show()
end
function getButton(id)
return topMenu:recursiveGetChildById(id)
end
function getTopMenu()
return topMenu
end