From 55fbb5f1a61c84f5e7acec33c2f385f89e9202b0 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 8 Feb 2012 20:58:27 -0200 Subject: [PATCH] improvment in connect --- modules/core_lib/util.lua | 11 ++++++++++- modules/core_widgets/tooltip.lua | 2 +- modules/core_widgets/uipopupmenu.lua | 4 ++-- modules/game/map.lua | 6 +++++- src/otclient/core/creature.cpp | 6 +++--- src/otclient/core/declarations.h | 1 + src/otclient/core/effect.cpp | 3 --- src/otclient/core/game.cpp | 10 ++++------ src/otclient/core/localplayer.cpp | 2 -- 9 files changed, 26 insertions(+), 19 deletions(-) diff --git a/modules/core_lib/util.lua b/modules/core_lib/util.lua index 5a83a349..31610e84 100644 --- a/modules/core_lib/util.lua +++ b/modules/core_lib/util.lua @@ -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 diff --git a/modules/core_widgets/tooltip.lua b/modules/core_widgets/tooltip.lua index 6f8177c0..dec3a1e2 100644 --- a/modules/core_widgets/tooltip.lua +++ b/modules/core_widgets/tooltip.lua @@ -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}) diff --git a/modules/core_widgets/uipopupmenu.lua b/modules/core_widgets/uipopupmenu.lua index cf049507..6318728e 100644 --- a/modules/core_widgets/uipopupmenu.lua +++ b/modules/core_widgets/uipopupmenu.lua @@ -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 diff --git a/modules/game/map.lua b/modules/game/map.lua index 268bd040..bdbcd0f8 100644 --- a/modules/game/map.lua +++ b/modules/game/map.lua @@ -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) diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 64992331..9c2d5454 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -473,19 +473,19 @@ void Creature::setOutfit(const Outfit& outfit) void Creature::setSkull(uint8 skull) { m_skull = skull; - g_lua.callGlobalField("Creature","onSkullChange", asCreature(), m_skull); + callLuaField("onSkullChange", m_skull); } void Creature::setShield(uint8 shield) { m_shield = shield; - g_lua.callGlobalField("Creature","onShieldChange", asCreature(), m_shield); + callLuaField("onShieldChange", m_shield); } void Creature::setEmblem(uint8 emblem) { m_emblem = emblem; - g_lua.callGlobalField("Creature","onEmblemChange", asCreature(), m_emblem); + callLuaField("onEmblemChange", m_emblem); } void Creature::setSkullTexture(const std::string& filename) diff --git a/src/otclient/core/declarations.h b/src/otclient/core/declarations.h index a3e29eeb..78c46fd5 100644 --- a/src/otclient/core/declarations.h +++ b/src/otclient/core/declarations.h @@ -26,6 +26,7 @@ #include class Map; +class Game; class MapView; class Tile; class Thing; diff --git a/src/otclient/core/effect.cpp b/src/otclient/core/effect.cpp index 54b12596..19c6f829 100644 --- a/src/otclient/core/effect.cpp +++ b/src/otclient/core/effect.cpp @@ -21,10 +21,7 @@ */ #include "effect.h" -#include "thingstype.h" #include "map.h" -#include "tile.h" -#include #include void Effect::draw(const Point& dest, float scaleFactor, bool animate) diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 46305f7d..a6e4a9c6 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -64,7 +64,7 @@ void Game::processConnectionError(const boost::system::error_code& error) void Game::processDisconnect() { 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()) processLogout(); @@ -86,7 +86,7 @@ void Game::processLoginError(const std::string& error) 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) @@ -113,7 +113,7 @@ void Game::processGameEnd() { g_lua.callGlobalField("g_game", "onGameEnd"); - // reset game states + // reset game state resetGameStates(); } @@ -232,9 +232,7 @@ void Game::processOpenContainer(int containerId, int itemId, const std::string& 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); } diff --git a/src/otclient/core/localplayer.cpp b/src/otclient/core/localplayer.cpp index 4e5b604c..fbce3c9e 100644 --- a/src/otclient/core/localplayer.cpp +++ b/src/otclient/core/localplayer.cpp @@ -156,5 +156,3 @@ void LocalPlayer::terminateWalk() Creature::terminateWalk(); m_preWalking = false; } - -