move tooltip and messagebox to modules

This commit is contained in:
Eduardo Bart 2011-11-03 20:28:10 -02:00
parent a9bf1cee36
commit 6aadf896da
8 changed files with 38 additions and 15 deletions

View File

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

View File

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

View File

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

View File

@ -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

View File

@ -16,11 +16,19 @@ local function moveToolTip(tooltip)
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('/core/tooltip/tooltip.otui', UI.root)
currentToolTip = UI.loadAndDisplay('/tooltip/tooltip.otui', UI.root)
currentToolTip.onMouseMove = moveToolTip
local label = currentToolTip:getChildById('toolTipText')
label:setText(text)
@ -39,3 +47,6 @@ function ToolTip.hide()
currentToolTip = nil
end
end
-- hooks
connect(UIButton, { onHoverChange = onButtonHoverChange})

View File

@ -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