mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 22:13:27 +02:00
BEAWARE all game functionality is disabled with this commit for a while
* rework client modules * hide main window when loading * remake top menu functions * rework modules autoload * improve path resolving for otml and lua * move core_widgets to core_lib * fix tooltip issues * split some styles * add bit32 lua library * fix assert issues * fix compilation on linux 32 systems * rework gcc compile options * renable and fix some warnings * remove unused constants * speedup sprite cache * move UIGame to lua (not funcional yet) * fix a lot of issues in x11 window * fix crash handler * add some warnings do uiwidget and much more...
This commit is contained in:
94
modules/core_lib/ui/tooltip.lua
Normal file
94
modules/core_lib/ui/tooltip.lua
Normal file
@@ -0,0 +1,94 @@
|
||||
ToolTip = {}
|
||||
|
||||
-- private variables
|
||||
local toolTipLabel
|
||||
local currentHoveredWidget
|
||||
|
||||
-- private functions
|
||||
local function moveToolTip(tooltip)
|
||||
if not tooltip:isVisible() then return end
|
||||
|
||||
local pos = g_window.getMousePosition()
|
||||
pos.y = pos.y + 1
|
||||
local xdif = g_window.getSize().width - (pos.x + tooltip:getWidth())
|
||||
if xdif < 2 then
|
||||
pos.x = pos.x - tooltip:getWidth() - 3
|
||||
else
|
||||
pos.x = pos.x + 10
|
||||
end
|
||||
tooltip:setPosition(pos)
|
||||
end
|
||||
|
||||
local function onWidgetHoverChange(widget, hovered)
|
||||
if hovered then
|
||||
if widget.tooltip then
|
||||
ToolTip.display(widget.tooltip)
|
||||
currentHoveredWidget = widget
|
||||
end
|
||||
else
|
||||
if widget == currentHoveredWidget then
|
||||
ToolTip:hide()
|
||||
currentHoveredWidget = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function onWidgetStyleApply(widget, styleName, styleNode)
|
||||
if styleNode.tooltip then
|
||||
widget.tooltip = styleNode.tooltip
|
||||
end
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function ToolTip.init()
|
||||
connect(UIWidget, { onStyleApply = onWidgetStyleApply,
|
||||
onHoverChange = onWidgetHoverChange})
|
||||
|
||||
addEvent(function()
|
||||
toolTipLabel = createWidget('Label', rootWidget)
|
||||
toolTipLabel:setId('toolTip')
|
||||
toolTipLabel:setBackgroundColor('#111111bb')
|
||||
toolTipLabel.onMouseMove = moveToolTip
|
||||
end)
|
||||
end
|
||||
|
||||
function ToolTip.terminate()
|
||||
disconnect(UIWidget, { onStyleApply = onWidgetStyleApply,
|
||||
onHoverChange = onWidgetHoverChange })
|
||||
|
||||
currentHoveredWidget = nil
|
||||
toolTipLabel:destroy()
|
||||
toolTipLabel = nil
|
||||
|
||||
ToolTip = nil
|
||||
end
|
||||
|
||||
function ToolTip.display(text)
|
||||
if text == nil then return end
|
||||
if not toolTipLabel then return end
|
||||
|
||||
toolTipLabel:setText(text)
|
||||
toolTipLabel:resizeToText()
|
||||
toolTipLabel:resize(toolTipLabel:getWidth() + 4, toolTipLabel:getHeight() + 4)
|
||||
toolTipLabel:show()
|
||||
toolTipLabel:raise()
|
||||
toolTipLabel:enable()
|
||||
moveToolTip(toolTipLabel)
|
||||
end
|
||||
|
||||
function ToolTip.hide()
|
||||
|
||||
toolTipLabel:hide()
|
||||
end
|
||||
|
||||
-- UIWidget extensions
|
||||
function UIWidget:setTooltip(text)
|
||||
self.tooltip = text
|
||||
end
|
||||
|
||||
function UIWidget:getTooltip()
|
||||
return self.tooltip
|
||||
end
|
||||
|
||||
ToolTip.init()
|
||||
connect(g_app, { onTerminate = ToolTip.terminate })
|
Reference in New Issue
Block a user