mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
implement button tooltips on top menu
This commit is contained in:
@@ -18,5 +18,6 @@ Module
|
||||
require 'ui'
|
||||
require 'gfx'
|
||||
require 'messagebox/messagebox'
|
||||
require 'tooltip/tooltip'
|
||||
return true
|
||||
|
||||
|
40
modules/core/tooltip/tooltip.lua
Normal file
40
modules/core/tooltip/tooltip.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
ToolTip = {}
|
||||
|
||||
-- private variables
|
||||
local currentToolTip
|
||||
|
||||
-- private functions
|
||||
local function moveToolTip(tooltip)
|
||||
local pos = getMouseCursorPos()
|
||||
pos.y = pos.y + 1
|
||||
local xdif = getScreenSize().width - (pos.x + tooltip:getWidth())
|
||||
if xdif < 2 then
|
||||
pos.x = pos.x - tooltip:getWidth() - 3
|
||||
else
|
||||
pos.x = pos.x + 10
|
||||
end
|
||||
tooltip:moveTo(pos)
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function ToolTip.display(text)
|
||||
ToolTip.hide()
|
||||
if text then
|
||||
currentToolTip = UI.loadAndDisplay('/core/tooltip/tooltip.otui', UI.root)
|
||||
currentToolTip.onMouseMove = moveToolTip
|
||||
local label = currentToolTip:getChildById('toolTipText')
|
||||
label:setText(text)
|
||||
label:resizeToText()
|
||||
local size = label:getSize()
|
||||
size.width = size.width + 4
|
||||
size.height = size.height + 4
|
||||
currentToolTip:setSize(size)
|
||||
end
|
||||
end
|
||||
|
||||
function ToolTip.hide()
|
||||
if currentToolTip then
|
||||
currentToolTip:destroy()
|
||||
currentToolTip = nil
|
||||
end
|
||||
end
|
9
modules/core/tooltip/tooltip.otui
Normal file
9
modules/core/tooltip/tooltip.otui
Normal file
@@ -0,0 +1,9 @@
|
||||
RectPanel
|
||||
background-color: #111111bb
|
||||
size: 200 200
|
||||
id: toolTip
|
||||
focusable: false
|
||||
|
||||
Label
|
||||
id: toolTipText
|
||||
anchors.centerIn: parent
|
@@ -23,7 +23,17 @@ Button < UIButton
|
||||
color: #999999
|
||||
background-color: #ffffff88
|
||||
|
||||
TopButton < UIButton
|
||||
ToolTipButton < UIButton
|
||||
onHoverChange: |
|
||||
function(self, hovered)
|
||||
if hovered then
|
||||
ToolTip.display(self:getStyle().tooltip)
|
||||
else
|
||||
ToolTip:hide()
|
||||
end
|
||||
end
|
||||
|
||||
TopButton < ToolTipButton
|
||||
background-color: white
|
||||
size: 26 25
|
||||
text-translate: 0 0
|
||||
|
@@ -11,6 +11,7 @@ TopPanel
|
||||
anchors.left: parent.left
|
||||
margin.top: 4
|
||||
margin.left: 6
|
||||
tooltip: Options
|
||||
onClick: Options.create()
|
||||
|
||||
UIWidget
|
||||
@@ -23,6 +24,7 @@ TopPanel
|
||||
anchors.top: prev.top
|
||||
anchors.left: prev.right
|
||||
margin.left: 6
|
||||
tooltip: Enter game with a character
|
||||
onClick: |
|
||||
if Game.isOnline() then
|
||||
CharacterList.show()
|
||||
@@ -41,6 +43,7 @@ TopPanel
|
||||
anchors.right: parent.right
|
||||
margin.top: 4
|
||||
margin.right: 6
|
||||
tooltip: Logout
|
||||
onClick: |
|
||||
if Game.isOnline() then
|
||||
Game.logout(false)
|
||||
@@ -59,6 +62,7 @@ TopPanel
|
||||
anchors.right: prev.left
|
||||
margin.top: 4
|
||||
margin.right: 6
|
||||
tooltip: About OTClient
|
||||
onClick: About.create()
|
||||
|
||||
UIWidget
|
||||
|
Reference in New Issue
Block a user