mirror of
https://github.com/edubart/otclient.git
synced 2025-04-29 17:19:20 +02:00

* i'm gradually restoring game functionality with the new modules design, though still a lot to do * you can reload all scripts and modules using Ctrl+R shortcut while playing (finally! this is the reason of all this rework) * a bunch of fixes, but new regression too :P * fix performance issue that could lead freezes in the client in older machines * completely new game module with new design * fix crashs in map render * remove uigame.cpp (now every game input is via lua) * enable DEBUG macro by default, with it you are able to view any possible lua leak while running
94 lines
2.3 KiB
Lua
94 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()
|
|
connect(g_game, { onGameStart = TopMenu.showGameButtons,
|
|
onGameEnd = TopMenu.hideGameButtons })
|
|
|
|
topMenu = displayUI('topmenu.otui')
|
|
|
|
leftButtonsPanel = topMenu:getChildById('leftButtonsPanel')
|
|
rightButtonsPanel = topMenu:getChildById('rightButtonsPanel')
|
|
gameButtonsPanel = topMenu:getChildById('gameButtonsPanel')
|
|
end
|
|
|
|
function TopMenu.terminate()
|
|
disconnect(g_game, { onGameStart = TopMenu.showGameButtons,
|
|
onGameEnd = TopMenu.hideGameButtons })
|
|
|
|
leftButtonsPanel = nil
|
|
rightButtonsPanel = nil
|
|
gameButtonsPanel = nil
|
|
|
|
topMenu:destroy()
|
|
topMenu = nil
|
|
|
|
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
|
|
|
|
|