move tooltip and messagebox to modules

master
Eduardo Bart 13 years ago
parent a9bf1cee36
commit 6aadf896da

@ -17,7 +17,5 @@ Module
require 'widget' require 'widget'
require 'ui' require 'ui'
require 'gfx' require 'gfx'
require 'messagebox/messagebox'
require 'tooltip/tooltip'
return true return true

@ -23,17 +23,7 @@ Button < UIButton
color: #999999 color: #999999
background-color: #ffffff88 background-color: #ffffff88
ToolTipButton < UIButton TopButton < UIButton
onHoverChange: |
function(self, hovered)
if hovered then
ToolTip.display(self:getStyle().tooltip)
else
ToolTip:hide()
end
end
TopButton < ToolTipButton
background-color: white background-color: white
size: 26 25 size: 26 25
text-translate: 0 0 text-translate: 0 0

@ -10,7 +10,7 @@ function MessageBox.create(title, text, flags)
setmetatable(box, MessageBox) setmetatable(box, MessageBox)
-- create messagebox window -- create messagebox window
local window = UI.loadAndDisplayLocked('/core/messagebox/messagebox.otui') local window = UI.loadAndDisplayLocked('/messagebox/messagebox.otui')
window:setTitle(title) window:setTitle(title)
local label = window:getChildById('messageBoxLabel') local label = window:getChildById('messageBoxLabel')

@ -0,0 +1,12 @@
Module
name: messagebox
description: Manages message boxes
author: OTClient team
website: https://github.com/edubart/otclient
autoLoad: true
dependencies:
- core
onLoad: |
require 'messagebox'
return true

@ -16,11 +16,19 @@ local function moveToolTip(tooltip)
tooltip:moveTo(pos) tooltip:moveTo(pos)
end end
local function onButtonHoverChange(button, hovered)
if hovered then
ToolTip.display(button:getStyle().tooltip)
else
ToolTip:hide()
end
end
-- public functions -- public functions
function ToolTip.display(text) function ToolTip.display(text)
ToolTip.hide() ToolTip.hide()
if text then if text then
currentToolTip = UI.loadAndDisplay('/core/tooltip/tooltip.otui', UI.root) currentToolTip = UI.loadAndDisplay('/tooltip/tooltip.otui', UI.root)
currentToolTip.onMouseMove = moveToolTip currentToolTip.onMouseMove = moveToolTip
local label = currentToolTip:getChildById('toolTipText') local label = currentToolTip:getChildById('toolTipText')
label:setText(text) label:setText(text)
@ -39,3 +47,6 @@ function ToolTip.hide()
currentToolTip = nil currentToolTip = nil
end end
end end
-- hooks
connect(UIButton, { onHoverChange = onButtonHoverChange})

@ -0,0 +1,12 @@
Module
name: tooltip
description: Enable tooltips on any button
author: OTClient team
website: https://github.com/edubart/otclient
autoLoad: true
dependencies:
- core
onLoad: |
require 'tooltip'
return true
Loading…
Cancel
Save