mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 14:03:26 +02:00
move tooltip and messagebox to modules
This commit is contained in:
52
modules/tooltip/tooltip.lua
Normal file
52
modules/tooltip/tooltip.lua
Normal file
@@ -0,0 +1,52 @@
|
||||
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
|
||||
|
||||
local function onButtonHoverChange(button, hovered)
|
||||
if hovered then
|
||||
ToolTip.display(button:getStyle().tooltip)
|
||||
else
|
||||
ToolTip:hide()
|
||||
end
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function ToolTip.display(text)
|
||||
ToolTip.hide()
|
||||
if text then
|
||||
currentToolTip = UI.loadAndDisplay('/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)
|
||||
moveToolTip(currentToolTip)
|
||||
end
|
||||
end
|
||||
|
||||
function ToolTip.hide()
|
||||
if currentToolTip then
|
||||
currentToolTip:destroy()
|
||||
currentToolTip = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- hooks
|
||||
connect(UIButton, { onHoverChange = onButtonHoverChange})
|
Reference in New Issue
Block a user