mirror of
https://github.com/OTCv8/otclientv8.git
synced 2025-10-19 06:03:27 +02:00
Version 0.95 BETA
This commit is contained in:
192
modules/client_topmenu/topmenu.lua
Normal file
192
modules/client_topmenu/topmenu.lua
Normal file
@@ -0,0 +1,192 @@
|
||||
-- private variables
|
||||
local topMenu
|
||||
local fpsUpdateEvent = nil
|
||||
|
||||
local HIDE_TOPMENU = false
|
||||
|
||||
-- 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 = panel:getChildById(id)
|
||||
if not button then
|
||||
button = g_ui.createWidget(class)
|
||||
if front then
|
||||
panel:insertChild(1, button)
|
||||
else
|
||||
panel:addChild(button)
|
||||
end
|
||||
end
|
||||
button:setId(id)
|
||||
button:setTooltip(description)
|
||||
button:setIcon(resolvepath(icon, 3))
|
||||
button.onMouseRelease = function(widget, mousePos, mouseButton)
|
||||
if widget:containsPoint(mousePos) and mouseButton ~= MouseMidButton then
|
||||
callback()
|
||||
return true
|
||||
end
|
||||
end
|
||||
return button
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function init()
|
||||
connect(g_game, { onGameStart = online,
|
||||
onGameEnd = offline,
|
||||
onPingBack = updatePing })
|
||||
|
||||
topMenu = g_ui.displayUI('topmenu')
|
||||
g_keyboard.bindKeyDown('Ctrl+Shift+T', toggle)
|
||||
|
||||
if g_game.isOnline() then
|
||||
online()
|
||||
end
|
||||
|
||||
updateFps()
|
||||
|
||||
if HIDE_TOPMENU then
|
||||
topMenu:setHeight(0)
|
||||
topMenu:hide()
|
||||
end
|
||||
end
|
||||
|
||||
function terminate()
|
||||
disconnect(g_game, { onGameStart = online,
|
||||
onGameEnd = offline,
|
||||
onPingBack = updatePing })
|
||||
removeEvent(fpsUpdateEvent)
|
||||
|
||||
topMenu:destroy()
|
||||
end
|
||||
|
||||
function online()
|
||||
showGameButtons()
|
||||
|
||||
addEvent(function()
|
||||
if modules.client_options.getOption('showPing') and (g_game.getFeature(GameClientPing) or g_game.getFeature(GameExtendedClientPing)) then
|
||||
topMenu.pingLabel:show()
|
||||
else
|
||||
topMenu.pingLabel:hide()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function offline()
|
||||
hideGameButtons()
|
||||
topMenu.pingLabel:hide()
|
||||
end
|
||||
|
||||
function updateFps()
|
||||
fpsUpdateEvent = scheduleEvent(updateFps, 500)
|
||||
text = 'FPS: ' .. g_app.getFps()
|
||||
topMenu.fpsLabel:setText(text)
|
||||
end
|
||||
|
||||
function updatePing(ping)
|
||||
if g_proxy and g_proxy.getPing() > 0 then
|
||||
ping = g_proxy.getPing()
|
||||
end
|
||||
|
||||
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
|
||||
topMenu.pingLabel:setColor(color)
|
||||
topMenu.pingLabel:setText(text)
|
||||
end
|
||||
|
||||
function setPingVisible(enable)
|
||||
topMenu.pingLabel:setVisible(enable)
|
||||
end
|
||||
|
||||
function setFpsVisible(enable)
|
||||
topMenu.fpsLabel:setVisible(enable)
|
||||
end
|
||||
|
||||
function addLeftButton(id, description, icon, callback, front)
|
||||
return addButton(id, description, icon, callback, topMenu.leftButtonsPanel, false, front)
|
||||
end
|
||||
|
||||
function addLeftToggleButton(id, description, icon, callback, front)
|
||||
return addButton(id, description, icon, callback, topMenu.leftButtonsPanel, true, front)
|
||||
end
|
||||
|
||||
function addRightButton(id, description, icon, callback, front)
|
||||
return addButton(id, description, icon, callback, topMenu.rightButtonsPanel, false, front)
|
||||
end
|
||||
|
||||
function addRightToggleButton(id, description, icon, callback, front)
|
||||
return addButton(id, description, icon, callback, topMenu.rightButtonsPanel, true, front)
|
||||
end
|
||||
|
||||
function addLeftGameButton(id, description, icon, callback, front)
|
||||
return addButton(id, description, icon, callback, topMenu.leftGameButtonsPanel, false, front)
|
||||
end
|
||||
|
||||
function addLeftGameToggleButton(id, description, icon, callback, front)
|
||||
return addButton(id, description, icon, callback, topMenu.leftGameButtonsPanel, true, front)
|
||||
end
|
||||
|
||||
function addRightGameButton(id, description, icon, callback, front)
|
||||
return addButton(id, description, icon, callback, topMenu.rightGameButtonsPanel, false, front)
|
||||
end
|
||||
|
||||
function addRightGameToggleButton(id, description, icon, callback, front)
|
||||
return addButton(id, description, icon, callback, topMenu.rightGameButtonsPanel, true, front)
|
||||
end
|
||||
|
||||
function showGameButtons()
|
||||
topMenu.leftGameButtonsPanel:show()
|
||||
topMenu.rightGameButtonsPanel:show()
|
||||
end
|
||||
|
||||
function hideGameButtons()
|
||||
topMenu.leftGameButtonsPanel:hide()
|
||||
topMenu.rightGameButtonsPanel:hide()
|
||||
end
|
||||
|
||||
function getButton(id)
|
||||
return topMenu:recursiveGetChildById(id)
|
||||
end
|
||||
|
||||
function getTopMenu()
|
||||
return topMenu
|
||||
end
|
||||
|
||||
function toggle()
|
||||
local menu = getTopMenu()
|
||||
if not menu then
|
||||
return
|
||||
end
|
||||
|
||||
if HIDE_TOPMENU then
|
||||
return
|
||||
end
|
||||
|
||||
if menu:isVisible() then
|
||||
menu:hide()
|
||||
modules.client_background.getBackground():addAnchor(AnchorTop, 'parent', AnchorTop)
|
||||
modules.game_interface.getRootPanel():addAnchor(AnchorTop, 'parent', AnchorTop)
|
||||
else
|
||||
menu:show()
|
||||
topMenu:setHeight(36)
|
||||
modules.client_background.getBackground():addAnchor(AnchorTop, 'topMenu', AnchorBottom)
|
||||
modules.game_interface.getRootPanel():addAnchor(AnchorTop, 'topMenu', AnchorBottom)
|
||||
end
|
||||
end
|
10
modules/client_topmenu/topmenu.otmod
Normal file
10
modules/client_topmenu/topmenu.otmod
Normal file
@@ -0,0 +1,10 @@
|
||||
Module
|
||||
name: client_topmenu
|
||||
description: Create the top menu
|
||||
author: edubart
|
||||
website: https://github.com/edubart/otclient
|
||||
scripts: [ topmenu ]
|
||||
sandboxed: true
|
||||
@onLoad: init()
|
||||
@onUnload: terminate()
|
||||
|
46
modules/client_topmenu/topmenu.otui
Normal file
46
modules/client_topmenu/topmenu.otui
Normal file
@@ -0,0 +1,46 @@
|
||||
TopMenuPanel
|
||||
id: topMenu
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
|
||||
TopMenuButtonsPanel
|
||||
id: leftButtonsPanel
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
|
||||
TopMenuButtonsPanel
|
||||
id: leftGameButtonsPanel
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: prev.right
|
||||
visible: false
|
||||
|
||||
TopMenuFrameCounterLabel
|
||||
id: fpsLabel
|
||||
text-auto-resize: true
|
||||
anchors.top: parent.top
|
||||
anchors.left: leftGameButtonsPanel.right
|
||||
anchors.right: rightGameButtonsPanel.left
|
||||
|
||||
TopMenuPingLabel
|
||||
color: white
|
||||
id: pingLabel
|
||||
text-auto-resize: true
|
||||
anchors.top: fpsLabel.bottom
|
||||
anchors.left: fpsLabel.left
|
||||
anchors.right: fpsLabel.right
|
||||
|
||||
TopMenuButtonsPanel
|
||||
id: rightButtonsPanel
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.right: parent.right
|
||||
|
||||
TopMenuButtonsPanel
|
||||
id: rightGameButtonsPanel
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.right: prev.left
|
||||
visible: false
|
Reference in New Issue
Block a user