improvment in connect

master
Eduardo Bart 12 years ago
parent 175f97b98f
commit 55fbb5f1a6

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

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

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

@ -36,7 +36,11 @@ function UIMap:onDrop(widget, mousePos)
spinbox:setCurrentIndex(count) spinbox:setCurrentIndex(count)
local okButton = moveWindow:getChildById('buttonOk') 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 moveWindow.onEnter = okButton.onClick
else else
g_game.move(widget.currentDragThing, tile:getPosition(), 1) g_game.move(widget.currentDragThing, tile:getPosition(), 1)

@ -473,19 +473,19 @@ void Creature::setOutfit(const Outfit& outfit)
void Creature::setSkull(uint8 skull) void Creature::setSkull(uint8 skull)
{ {
m_skull = skull; m_skull = skull;
g_lua.callGlobalField("Creature","onSkullChange", asCreature(), m_skull); callLuaField("onSkullChange", m_skull);
} }
void Creature::setShield(uint8 shield) void Creature::setShield(uint8 shield)
{ {
m_shield = shield; m_shield = shield;
g_lua.callGlobalField("Creature","onShieldChange", asCreature(), m_shield); callLuaField("onShieldChange", m_shield);
} }
void Creature::setEmblem(uint8 emblem) void Creature::setEmblem(uint8 emblem)
{ {
m_emblem = emblem; m_emblem = emblem;
g_lua.callGlobalField("Creature","onEmblemChange", asCreature(), m_emblem); callLuaField("onEmblemChange", m_emblem);
} }
void Creature::setSkullTexture(const std::string& filename) void Creature::setSkullTexture(const std::string& filename)

@ -26,6 +26,7 @@
#include <otclient/global.h> #include <otclient/global.h>
class Map; class Map;
class Game;
class MapView; class MapView;
class Tile; class Tile;
class Thing; class Thing;

@ -21,10 +21,7 @@
*/ */
#include "effect.h" #include "effect.h"
#include "thingstype.h"
#include "map.h" #include "map.h"
#include "tile.h"
#include <framework/core/clock.h>
#include <framework/core/eventdispatcher.h> #include <framework/core/eventdispatcher.h>
void Effect::draw(const Point& dest, float scaleFactor, bool animate) void Effect::draw(const Point& dest, float scaleFactor, bool animate)

@ -64,7 +64,7 @@ void Game::processConnectionError(const boost::system::error_code& error)
void Game::processDisconnect() void Game::processDisconnect()
{ {
if(isOnline()) { if(isOnline()) {
// only process logout event if a previous the player is known // only process logout event if the player is known
if(m_localPlayer->isKnown()) if(m_localPlayer->isKnown())
processLogout(); processLogout();
@ -86,7 +86,7 @@ void Game::processLoginError(const std::string& error)
void Game::processLoginAdvice(const std::string& message) void Game::processLoginAdvice(const std::string& message)
{ {
g_lua.callGlobalField("Game," "onLoginAdvice", message); g_lua.callGlobalField("g_game", "onLoginAdvice", message);
} }
void Game::processLoginWait(const std::string& message, int time) void Game::processLoginWait(const std::string& message, int time)
@ -113,7 +113,7 @@ void Game::processGameEnd()
{ {
g_lua.callGlobalField("g_game", "onGameEnd"); g_lua.callGlobalField("g_game", "onGameEnd");
// reset game states // reset game state
resetGameStates(); resetGameStates();
} }
@ -232,9 +232,7 @@ void Game::processOpenContainer(int containerId, int itemId, const std::string&
void Game::processContainerAddItem(int containerId, const ItemPtr& item) void Game::processContainerAddItem(int containerId, const ItemPtr& item)
{ {
if(item) item->setPosition(Position(65535, containerId + 0x40, 0));
item->setPosition(Position(65535, containerId + 0x40, 0));
g_lua.callGlobalField("g_game", "onContainerAddItem", containerId, item); g_lua.callGlobalField("g_game", "onContainerAddItem", containerId, item);
} }

@ -156,5 +156,3 @@ void LocalPlayer::terminateWalk()
Creature::terminateWalk(); Creature::terminateWalk();
m_preWalking = false; m_preWalking = false;
} }

Loading…
Cancel
Save