improvment in connect

This commit is contained in:
Eduardo Bart
2012-02-08 20:58:27 -02:00
parent 175f97b98f
commit 55fbb5f1a6
9 changed files with 26 additions and 19 deletions

View File

@@ -20,6 +20,15 @@ end
function connect(object, signalsAndSlots, pushFront)
for signal,slot in pairs(signalsAndSlots) do
if not object[signal] then
local mt = getmetatable(object)
if mt then
object[signal] = function(...)
return signalcall(mt[signal], ...)
end
end
end
if not object[signal] then
object[signal] = slot
elseif type(object[signal]) == 'function' then
@@ -140,7 +149,7 @@ function signalcall(param, ...)
return param(...)
elseif type(param) == 'table' then
for k,v in pairs(param) do
if param(...) then
if v(...) then
return true
end
end

View File

@@ -44,7 +44,7 @@ function ToolTip.init()
toolTipLabel = createWidget('Label', rootWidget)
toolTipLabel:setId('toolTip')
toolTipLabel:setBackgroundColor('#111111bb')
connect(toolTipLabel, { onMouseMove = moveToolTip })
toolTipLabel.onMouseMove = moveToolTip
connect(UIWidget, { onStyleApply = onWidgetStyleApply,
onHoverChange = onWidgetHoverChange})

View File

@@ -30,9 +30,9 @@ end
function UIPopupMenu:addOption(optionName, optionCallback)
local optionWidget = createWidget(self:getStyleName() .. 'Button', self)
local lastOptionWidget = self:getLastChild()
optionWidget.onClick = function()
optionWidget.onClick = function(self)
optionCallback()
self:destroy()
self:getParent():destroy()
end
optionWidget:setText(optionName)
local width = optionWidget:getTextSize().width + optionWidget:getMarginLeft() + optionWidget:getMarginRight() + 6

View File

@@ -36,7 +36,11 @@ function UIMap:onDrop(widget, mousePos)
spinbox:setCurrentIndex(count)
local okButton = moveWindow:getChildById('buttonOk')
okButton.onClick = function() g_game.move(widget.currentDragThing, tile:getPosition(), spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end
okButton.onClick = function()
g_game.move(widget.currentDragThing, tile:getPosition(), spinbox:getCurrentIndex())
okButton:getParent():destroy()
widget.currentDragThing = nil
end
moveWindow.onEnter = okButton.onClick
else
g_game.move(widget.currentDragThing, tile:getPosition(), 1)