2011-11-01 17:41:15 +01:00
|
|
|
-- 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
|
2013-01-18 06:53:41 +01:00
|
|
|
local function addButton(id, description, icon, callback, panel, toggle, front)
|
2012-02-20 03:27:08 +01:00
|
|
|
local class
|
|
|
|
if toggle then
|
|
|
|
class = 'TopToggleButton'
|
|
|
|
else
|
|
|
|
class = 'TopButton'
|
|
|
|
end
|
|
|
|
|
2013-02-01 02:47:15 +01:00
|
|
|
local button = panel:getChildById(id)
|
|
|
|
if not button then
|
|
|
|
button = g_ui.createWidget(class)
|
|
|
|
if front then
|
|
|
|
panel:insertChild(1, button)
|
|
|
|
else
|
|
|
|
panel:addChild(button)
|
|
|
|
end
|
2013-01-18 06:53:41 +01:00
|
|
|
end
|
2012-02-20 03:27:08 +01:00
|
|
|
button:setId(id)
|
|
|
|
button:setTooltip(description)
|
2013-01-19 01:24:40 +01:00
|
|
|
button:setIcon(resolvepath(icon, 3))
|
2013-01-18 23:39:11 +01:00
|
|
|
button.onMouseRelease = function(widget, mousePos, mouseButton)
|
|
|
|
if widget:containsPoint(mousePos) and mouseButton ~= MouseMiddleButton then
|
|
|
|
callback()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
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
|
2013-01-18 23:39:11 +01:00
|
|
|
function init()
|
2013-02-24 21:26:19 +01:00
|
|
|
connect(g_game, { onGameStart = online,
|
|
|
|
onGameEnd = offline,
|
|
|
|
onPingBack = updatePing })
|
|
|
|
connect(g_app, { onFps = updateFps })
|
2012-03-18 14:34:39 +01:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
topMenu = g_ui.displayUI('topmenu')
|
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')
|
2013-02-24 21:26:19 +01:00
|
|
|
pingLabel = topMenu:getChildById('pingLabel')
|
|
|
|
fpsLabel = topMenu:getChildById('fpsLabel')
|
2012-03-23 14:48:05 +01:00
|
|
|
|
|
|
|
if g_game.isOnline() then
|
2013-02-24 21:26:19 +01:00
|
|
|
online()
|
2012-03-23 14:48:05 +01:00
|
|
|
end
|
2011-11-01 17:41:15 +01:00
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function terminate()
|
2013-02-24 21:26:19 +01:00
|
|
|
disconnect(g_game, { onGameStart = online,
|
|
|
|
onGameEnd = offline,
|
|
|
|
onPingBack = updatePing })
|
|
|
|
disconnect(g_app, { onFps = updateFps })
|
2012-03-18 14:34:39 +01:00
|
|
|
|
2011-11-01 17:41:15 +01:00
|
|
|
topMenu:destroy()
|
2011-11-16 19:08:42 +01:00
|
|
|
end
|
|
|
|
|
2013-02-24 21:26:19 +01:00
|
|
|
function online()
|
|
|
|
showGameButtons()
|
|
|
|
|
2013-02-28 22:39:27 +01:00
|
|
|
addEvent(function()
|
|
|
|
if modules.client_options.getOption('showPing') and (g_game.getFeature(GameClientPing) or g_game.getFeature(GameExtendedClientPing)) then
|
|
|
|
pingLabel:show()
|
|
|
|
else
|
|
|
|
pingLabel:hide()
|
|
|
|
end
|
|
|
|
end)
|
2013-02-24 21:26:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function offline()
|
|
|
|
hideGameButtons()
|
|
|
|
pingLabel:hide()
|
|
|
|
end
|
|
|
|
|
|
|
|
function updateFps(fps)
|
|
|
|
text = 'FPS: ' .. fps
|
|
|
|
fpsLabel:setText(text)
|
|
|
|
end
|
|
|
|
|
|
|
|
function updatePing(ping)
|
|
|
|
local text = 'Ping: '
|
|
|
|
local color
|
|
|
|
if ping < 0 then
|
|
|
|
text = text .. "??"
|
|
|
|
color = 'yellow'
|
|
|
|
else
|
|
|
|
text = text .. ping .. ' ms'
|
|
|
|
if ping >= 500 then
|
|
|
|
color = 'red'
|
|
|
|
elseif ping >= 250 then
|
|
|
|
color = 'yellow'
|
|
|
|
else
|
|
|
|
color = 'green'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
pingLabel:setColor(color)
|
|
|
|
pingLabel:setText(text)
|
|
|
|
end
|
|
|
|
|
|
|
|
function setPingVisible(enable)
|
|
|
|
pingLabel:setVisible(enable)
|
|
|
|
end
|
|
|
|
|
|
|
|
function setFpsVisible(enable)
|
|
|
|
fpsLabel:setVisible(enable)
|
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function addLeftButton(id, description, icon, callback, front)
|
2013-01-18 06:53:41 +01:00
|
|
|
return addButton(id, description, icon, callback, leftButtonsPanel, false, front)
|
2012-02-20 03:27:08 +01:00
|
|
|
end
|
2012-01-07 18:36:58 +01:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function addLeftToggleButton(id, description, icon, callback, front)
|
2013-01-18 06:53:41 +01:00
|
|
|
return addButton(id, description, icon, callback, leftButtonsPanel, true, front)
|
2012-01-07 18:36:58 +01:00
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function addRightButton(id, description, icon, callback, front)
|
2013-01-18 06:53:41 +01:00
|
|
|
return addButton(id, description, icon, callback, rightButtonsPanel, false, front)
|
2012-01-15 16:13:22 +01:00
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function addRightToggleButton(id, description, icon, callback, front)
|
2013-01-18 06:53:41 +01:00
|
|
|
return addButton(id, description, icon, callback, rightButtonsPanel, true, front)
|
2012-01-07 18:36:58 +01:00
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function addLeftGameButton(id, description, icon, callback, front)
|
2013-01-18 06:53:41 +01:00
|
|
|
return addButton(id, description, icon, callback, leftGameButtonsPanel, false, front)
|
2012-02-20 03:27:08 +01:00
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function addLeftGameToggleButton(id, description, icon, callback, front)
|
2013-01-18 06:53:41 +01:00
|
|
|
return addButton(id, description, icon, callback, leftGameButtonsPanel, true, front)
|
2012-07-12 18:45:22 +02:00
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function addRightGameButton(id, description, icon, callback, front)
|
2013-01-18 06:53:41 +01:00
|
|
|
return addButton(id, description, icon, callback, rightGameButtonsPanel, false, front)
|
2012-07-12 18:45:22 +02:00
|
|
|
end
|
2012-07-28 05:54:47 +02:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function addRightGameToggleButton(id, description, icon, callback, front)
|
2013-01-18 06:53:41 +01:00
|
|
|
return addButton(id, description, icon, callback, rightGameButtonsPanel, true, front)
|
2012-01-07 18:36:58 +01:00
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function showGameButtons()
|
2012-07-12 18:45:22 +02:00
|
|
|
leftGameButtonsPanel:show()
|
|
|
|
rightGameButtonsPanel:show()
|
2012-01-23 14:47:15 +01:00
|
|
|
end
|
|
|
|
|
2013-02-24 21:26:19 +01:00
|
|
|
function hideGameButtons()
|
|
|
|
leftGameButtonsPanel:hide()
|
|
|
|
rightGameButtonsPanel:hide()
|
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function getButton(id)
|
2012-01-07 18:36:58 +01:00
|
|
|
return topMenu:recursiveGetChildById(id)
|
|
|
|
end
|
2012-02-20 03:27:08 +01:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function getTopMenu()
|
|
|
|
return topMenu
|
|
|
|
end
|