issue #2377:Del register/unregister function in .cpp and .h files

This commit is contained in:
samuele3hu 2013-07-16 09:55:06 +08:00
parent 80a6811f9f
commit c955a559bf
21 changed files with 364 additions and 512 deletions

View File

@ -88,7 +88,6 @@ Node::Node(void)
, _ignoreAnchorPointForPosition(false)
, _reorderChildDirty(false)
, _isTransitionFinished(false)
, _scriptHandler(0)
, _updateScriptHandler(0)
, _componentContainer(NULL)
{
@ -108,7 +107,6 @@ Node::~Node(void)
{
CCLOGINFO( "cocos2d: deallocing: %p", this );
unregisterScriptHandler();
if (_updateScriptHandler)
{
ScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(_updateScriptHandler);
@ -988,23 +986,6 @@ void Node::onExit()
arrayMakeObjectsPerformSelector(_children, onExit, Node*);
}
void Node::registerScriptHandler(int nHandler)
{
unregisterScriptHandler();
_scriptHandler = nHandler;
LUALOG("[LUA] Add Node event handler: %d", _scriptHandler);
}
void Node::unregisterScriptHandler(void)
{
if (_scriptHandler)
{
ScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(_scriptHandler);
LUALOG("[LUA] Remove Node event handler: %d", _scriptHandler);
_scriptHandler = 0;
}
}
void Node::setActionManager(ActionManager* actionManager)
{
if( actionManager != _actionManager ) {

View File

@ -857,47 +857,6 @@ public:
*/
virtual bool isRunning() const;
/// @{
/// @name Script Bindings for lua
/**
* Registers a script function that will be called in onEnter() & onExit() seires functions.
*
* This handler will be removed automatically after onExit() called.
* @code
* -- lua sample
* local function sceneEventHandler(eventType)
* if eventType == kNodeOnEnter then
* -- do something
* elseif evetType == kNodeOnExit then
* -- do something
* end
* end
* scene::registerScriptHandler(sceneEventHandler)
* @endcode
*
* @warning This method is for internal usage, don't call it manually.
* @todo Perhaps we should rename it to get/set/removeScriptHandler acoording to the function name style.
*
* @param handler A number that indicates a lua function.
*/
virtual void registerScriptHandler(int handler);
/**
* Unregisters a script function that will be called in onEnter() & onExit() series functions.
*
* @see registerScriptHandler(int)
*/
virtual void unregisterScriptHandler(void);
/**
* Gets script handler for onEnter/onExit event.
* This is an internal method. g
* @see registerScriptHandler(int)
*
* @return A number that indicates a lua function.
*/
inline int getScriptHandler() const { return _scriptHandler; };
/**
* Schedules for lua script.
*/

View File

@ -48,9 +48,6 @@ Layer::Layer()
, _accelerometerEnabled(false)
, _keyboardEnabled(false)
, _keypadEnabled(false)
, _scriptTouchHandlerEntry(NULL)
, _scriptKeypadHandlerEntry(NULL)
, _scriptAccelerateHandlerEntry(NULL)
, _touchPriority(0)
, _touchMode(kTouchesAllAtOnce)
{
@ -60,9 +57,7 @@ Layer::Layer()
Layer::~Layer()
{
unregisterScriptTouchHandler();
unregisterScriptKeypadHandler();
unregisterScriptAccelerateHandler();
}
bool Layer::init()
@ -102,51 +97,20 @@ void Layer::registerWithTouchDispatcher()
{
TouchDispatcher* pDispatcher = Director::getInstance()->getTouchDispatcher();
// Using LuaBindings
if (_scriptTouchHandlerEntry)
{
if (_scriptTouchHandlerEntry->isMultiTouches())
{
pDispatcher->addStandardDelegate(this, 0);
LUALOG("[LUA] Add multi-touches event handler: %d", _scriptTouchHandlerEntry->getHandler());
}
else
{
pDispatcher->addTargetedDelegate(this,
_scriptTouchHandlerEntry->getPriority(),
_scriptTouchHandlerEntry->getSwallowsTouches());
LUALOG("[LUA] Add touch event handler: %d", _scriptTouchHandlerEntry->getHandler());
}
}
else
{
if( _touchMode == kTouchesAllAtOnce ) {
pDispatcher->addStandardDelegate(this, 0);
} else {
pDispatcher->addTargetedDelegate(this, _touchPriority, true);
}
if( _touchMode == kTouchesAllAtOnce ) {
pDispatcher->addStandardDelegate(this, 0);
} else {
pDispatcher->addTargetedDelegate(this, _touchPriority, true);
}
}
void Layer::registerScriptTouchHandler(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches)
{
unregisterScriptTouchHandler();
_scriptTouchHandlerEntry = TouchScriptHandlerEntry::create(nHandler, bIsMultiTouches, nPriority, bSwallowsTouches);
_scriptTouchHandlerEntry->retain();
}
void Layer::unregisterScriptTouchHandler(void)
{
CC_SAFE_RELEASE_NULL(_scriptTouchHandlerEntry);
}
int Layer::excuteScriptTouchHandler(int nEventType, Touch *pTouch)
{
if (kScriptTypeLua == _scriptType)
{
Set touches;
touches.addObject((Object*)pTouch);
TouchesScriptData data(nEventType,kLayerTouches,(void*)this,&touches);
TouchesScriptData data(nEventType,(void*)this,&touches);
ScriptEvent event(kTouchesEvent,&data);
return ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event);
}
@ -162,7 +126,7 @@ int Layer::excuteScriptTouchHandler(int nEventType, Set *pTouches)
{
if (kScriptTypeLua == _scriptType)
{
TouchesScriptData data(nEventType,kLayerTouches,(void*)this,pTouches);
TouchesScriptData data(nEventType,(void*)this,pTouches);
ScriptEvent event(kTouchesEvent,&data);
return ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event);
}
@ -292,18 +256,6 @@ void Layer::didAccelerate(Acceleration* pAccelerationValue)
}
}
void Layer::registerScriptAccelerateHandler(int nHandler)
{
unregisterScriptAccelerateHandler();
_scriptAccelerateHandlerEntry = ScriptHandlerEntry::create(nHandler);
_scriptAccelerateHandlerEntry->retain();
}
void Layer::unregisterScriptAccelerateHandler(void)
{
CC_SAFE_RELEASE_NULL(_scriptAccelerateHandlerEntry);
}
/// isKeyboardEnabled getter
bool Layer::isKeyboardEnabled() const
{
@ -357,23 +309,11 @@ void Layer::setKeypadEnabled(bool enabled)
}
}
void Layer::registerScriptKeypadHandler(int nHandler)
{
unregisterScriptKeypadHandler();
_scriptKeypadHandlerEntry = ScriptHandlerEntry::create(nHandler);
_scriptKeypadHandlerEntry->retain();
}
void Layer::unregisterScriptKeypadHandler(void)
{
CC_SAFE_RELEASE_NULL(_scriptKeypadHandlerEntry);
}
void Layer::keyBackClicked(void)
{
if (kScriptTypeLua == _scriptType)
{
KeypadScriptData data(kTypeBackClicked,kLayerKeypad,(void*)this);
KeypadScriptData data(kTypeBackClicked,(void*)this);
ScriptEvent event(kKeypadEvent,(void*)&data);
ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event);
}
@ -387,7 +327,7 @@ void Layer::keyMenuClicked(void)
{
if (kScriptTypeLua == _scriptType)
{
KeypadScriptData data(kTypeMenuClicked,kLayerKeypad,(void*)this);
KeypadScriptData data(kTypeMenuClicked,(void*)this);
ScriptEvent event(kKeypadEvent,(void*)&data);
ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event);
}
@ -426,8 +366,6 @@ void Layer::onExit()
if( _touchEnabled )
{
pDirector->getTouchDispatcher()->removeDelegate(this);
// [lua]:don't unregister script touch handler, or the handler will be destroyed
// unregisterScriptTouchHandler();
}
// remove this layer from the delegates who concern Accelerometer Sensor

View File

@ -87,8 +87,6 @@ public:
virtual void ccTouchesCancelled(Set *pTouches, Event *pEvent);
virtual void didAccelerate(Acceleration* pAccelerationValue);
void registerScriptAccelerateHandler(int nHandler);
void unregisterScriptAccelerateHandler(void);
/** If isTouchEnabled, this method is called onEnter. Override it to change the
way Layer receives touch events.
@ -102,11 +100,6 @@ public:
*/
virtual void registerWithTouchDispatcher(void);
/** Register script touch events handler */
virtual void registerScriptTouchHandler(int nHandler, bool bIsMultiTouches = false, int nPriority = INT_MIN, bool bSwallowsTouches = false);
/** Unregister script touch events handler */
virtual void unregisterScriptTouchHandler(void);
/** whether or not it will receive Touch events.
You can enable / disable touch events with this property.
Only the touches of this node will be affected. This "method" is not propagated to it's children.
@ -143,17 +136,8 @@ public:
virtual bool isKeypadEnabled() const;
virtual void setKeypadEnabled(bool value);
/** Register keypad events handler */
void registerScriptKeypadHandler(int nHandler);
/** Unregister keypad events handler */
void unregisterScriptKeypadHandler(void);
virtual void keyBackClicked(void);
virtual void keyMenuClicked(void);
inline TouchScriptHandlerEntry* getScriptTouchHandlerEntry() const { return _scriptTouchHandlerEntry; };
inline ScriptHandlerEntry* getScriptKeypadHandlerEntry() const { return _scriptKeypadHandlerEntry; };
inline ScriptHandlerEntry* getScriptAccelerateHandlerEntry() const { return _scriptAccelerateHandlerEntry; };
protected:
bool _touchEnabled;
bool _accelerometerEnabled;
@ -161,11 +145,6 @@ protected:
bool _keypadEnabled;
private:
// Script touch events handler
TouchScriptHandlerEntry* _scriptTouchHandlerEntry;
ScriptHandlerEntry* _scriptKeypadHandlerEntry;
ScriptHandlerEntry* _scriptAccelerateHandlerEntry;
int _touchPriority;
ccTouchesMode _touchMode;

View File

@ -92,8 +92,6 @@ bool MenuItem::initWithCallback(const ccMenuCallback& callback)
MenuItem::~MenuItem()
{
CC_SAFE_RELEASE(_target);
unregisterScriptTapHandler();
}
void MenuItem::selected()
@ -106,23 +104,6 @@ void MenuItem::unselected()
_selected = false;
}
void MenuItem::registerScriptTapHandler(int nHandler)
{
unregisterScriptTapHandler();
_scriptTapHandler = nHandler;
LUALOG("[LUA] Add MenuItem script handler: %d", _scriptTapHandler);
}
void MenuItem::unregisterScriptTapHandler(void)
{
if (_scriptTapHandler)
{
ScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(_scriptTapHandler);
LUALOG("[LUA] Remove MenuItem script handler: %d", _scriptTapHandler);
_scriptTapHandler = 0;
}
}
void MenuItem::activate()
{
if (_enabled)

View File

@ -62,7 +62,6 @@ public:
MenuItem()
: _selected(false)
, _enabled(false)
, _scriptTapHandler(0)
, _callback(nullptr)
, _target(NULL)
{}
@ -87,11 +86,6 @@ public:
/** The item was unselected */
virtual void unselected();
/** Register menu handler script function */
virtual void registerScriptTapHandler(int nHandler);
virtual void unregisterScriptTapHandler(void);
int getScriptTapHandler() const { return _scriptTapHandler; };
virtual bool isEnabled() const;
//@note: It's 'setIsEnable' in cocos2d-iphone.
virtual void setEnabled(bool value);
@ -108,7 +102,6 @@ public:
protected:
bool _selected;
bool _enabled;
int _scriptTapHandler;
// callback
ccMenuCallback _callback;
// If using the old API, the _target needs to be retained / released

View File

@ -166,19 +166,10 @@ enum ScriptEventType
kTouchesEvent,
kKeypadEvent,
kAccelerometerEvent,
kControlEvent,
kCommonEvent,
};
enum TouchesObjectType
{
kLayerTouches = 0,
};
enum KeypadObjectType
{
kLayerKeypad = 0,
};
struct BasicScriptData
{
//nativeobject:to get handler for lua or to get jsobject for js
@ -209,12 +200,10 @@ struct SchedulerScriptData
struct TouchesScriptData
{
int actionType;
int objectType;
void* nativeObject;
Set* touches;
TouchesScriptData(int inActionType,int inObjectType,void* inNativeObject,Set* inTouches)
TouchesScriptData(int inActionType,void* inNativeObject,Set* inTouches)
:actionType(inActionType),
objectType(inObjectType),
nativeObject(inNativeObject),
touches(inTouches)
{
@ -224,10 +213,9 @@ struct TouchesScriptData
struct KeypadScriptData
{
int actionType;
int objectType;
void* nativeObject;
KeypadScriptData(int inActionType,int inObjectType,void* inNativeObject)
:actionType(inActionType),objectType(inObjectType),nativeObject(inNativeObject)
KeypadScriptData(int inActionType,void* inNativeObject)
:actionType(inActionType),nativeObject(inNativeObject)
{
}
};

View File

@ -78,8 +78,6 @@ bool Control::init()
this->setTouchPriority(1);
// Initialise the tables
_dispatchTable = new Dictionary();
// Initialise the mapHandleOfControlEvents
_mapHandleOfControlEvent.clear();
return true;
}
@ -128,15 +126,11 @@ void Control::sendActionsForControlEvents(ControlEvent controlEvents)
invocation->invoke(this);
}
//Call ScriptFunc
if (kScriptTypeNone != _scriptType)
if (kScriptTypeLua == _scriptType)
{
int nHandler = this->getHandleOfControlEvent(controlEvents);
if (0 != nHandler)
{
cocos2d::CommonScriptData data(nHandler, "",(Object*)this);
cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data);
cocos2d::ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event);
}
cocos2d::BasicScriptData data((void*)this,(void*)&controlEvents);
cocos2d::ScriptEvent event(cocos2d::kControlEvent,(void*)&data);
cocos2d::ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event);
}
}
}
@ -338,30 +332,4 @@ bool Control::hasVisibleParents()
}
return true;
}
void Control::addHandleOfControlEvent(int nFunID,ControlEvent controlEvent)
{
_mapHandleOfControlEvent[controlEvent] = nFunID;
}
void Control::removeHandleOfControlEvent(ControlEvent controlEvent)
{
std::map<int,int>::iterator Iter = _mapHandleOfControlEvent.find(controlEvent);
if (_mapHandleOfControlEvent.end() != Iter)
{
_mapHandleOfControlEvent.erase(Iter);
}
}
int Control::getHandleOfControlEvent(ControlEvent controlEvent)
{
std::map<int,int>::iterator Iter = _mapHandleOfControlEvent.find(controlEvent);
if (_mapHandleOfControlEvent.end() != Iter)
return Iter->second;
return 0;
}
NS_CC_EXT_END

View File

@ -254,13 +254,6 @@ protected:
void removeTargetWithActionForControlEvent(Object* target, SEL_CCControlHandler action, ControlEvent controlEvent);
static Control* create();
public:
void addHandleOfControlEvent(int nFunID,ControlEvent controlEvent);
void removeHandleOfControlEvent(ControlEvent controlEvent);
private:
int getHandleOfControlEvent(ControlEvent controlEvent);
private:
std::map<int,int> _mapHandleOfControlEvent;
};
// end of GUI group

View File

@ -76,7 +76,7 @@ bool AppDelegate::applicationDidFinishLaunching()
#endif
FileUtils::getInstance()->setSearchPaths(searchPaths);
pEngine->expandLuaObjecFunc();
pEngine->extendLuaObjec();
pEngine->executeScriptFile("luaScript/controller.lua");
return true;

View File

@ -70,6 +70,7 @@ end
local function PauseTest()
local ret = createTestLayer("Pause Test")
local schedulerEntry = nil
local function unpause(dt)
scheduler:unscheduleScriptEntry(schedulerEntry)
schedulerEntry = nil
@ -96,7 +97,7 @@ local function PauseTest()
schedulerEntry = scheduler:scheduleScriptFunc(unpause, 3.0, false)
elseif event == "exit" then
if scheduleEventHandler ~= nil then
if schedulerEntry ~= nil then
scheduler:unscheduleScriptEntry(schedulerEntry)
end
end

View File

@ -371,7 +371,7 @@ local function runCCControlTest()
pDisplayValueLabel:setPosition(ccp(screenSize.width / 1.7, screenSize.height / 2.0))
pLayer:addChild(pDisplayValueLabel)
local function valueChanged(strEventName,pSender)
local function valueChanged(pSender)
if nil == pSender or nil == pDisplayValueLabel then
return
end
@ -396,7 +396,7 @@ local function runCCControlTest()
pSlider:setTag(1)
--When the value of the slider will change, the given selector will be call
pSlider:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged)
pSlider:registerControlEventHandler(valueChanged, CCControlEventValueChanged)
local pRestrictSlider = CCControlSlider:create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png")
pRestrictSlider:setAnchorPoint(ccp(0.5, 1.0))
@ -408,7 +408,7 @@ local function runCCControlTest()
pRestrictSlider:setPosition(ccp(screenSize.width / 2.0, screenSize.height / 2.0 - 24))
pRestrictSlider:setTag(2)
--same with restricted
pRestrictSlider:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged)
pRestrictSlider:registerControlEventHandler(valueChanged, CCControlEventValueChanged)
pLayer:addChild(pSlider)
pLayer:addChild(pRestrictSlider)
end
@ -428,7 +428,7 @@ local function runCCControlTest()
local dLayer_width = 0
--Create the colour picker,pStrEventName not use
local function colourValueChanged(pStrEventName,pSender)
local function colourValueChanged(pSender)
if nil == pSender or nil == pColorLabel then
return
end
@ -440,7 +440,7 @@ local function runCCControlTest()
local pColourPicker = CCControlColourPicker:create()
pColourPicker:setColor(Color3B(37, 46, 252))
pColourPicker:setPosition(ccp (pColourPicker:getContentSize().width / 2, 0))
pColourPicker:addHandleOfControlEvent(colourValueChanged, CCControlEventValueChanged)
pColourPicker:registerControlEventHandler(colourValueChanged, CCControlEventValueChanged)
pNode:addChild(pColourPicker)
dLayer_width = dLayer_width + pColourPicker:getContentSize().width
@ -462,7 +462,7 @@ local function runCCControlTest()
pNode:setAnchorPoint(ccp (0.5, 0.5))
--Update the color text
colourValueChanged("", pColourPicker)
colourValueChanged(pColourPicker)
end
--SwitchTest
@ -493,7 +493,7 @@ local function runCCControlTest()
pNode:addChild(pDisplayValueLabel)
--Create the switch
local function valueChanged(strEventName,pSender)
local function valueChanged(pSender)
if nil == pDisplayValueLabel or nil == pSender then
return
end
@ -515,14 +515,14 @@ local function runCCControlTest()
)
pSwitchControl:setPosition(ccp (dLayer_width + 10 + pSwitchControl:getContentSize().width / 2, 0))
pNode:addChild(pSwitchControl)
pSwitchControl:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged)
pSwitchControl:registerControlEventHandler(valueChanged, CCControlEventValueChanged)
--Set the layer size
pNode:setContentSize(CCSizeMake(dLayer_width, 0))
pNode:setAnchorPoint(ccp (0.5, 0.5))
--Update the value label
valueChanged("", pSwitchControl)
valueChanged(pSwitchControl)
end
--Hvs:HelloVariableSize
@ -730,14 +730,14 @@ local function runCCControlTest()
pControlButton:setTitleColorForState(Color3B(255, 255, 255), CCControlStateHighlighted)
pControlButton:setAnchorPoint(ccp(0.5, 1))
pControlButton:setPosition(ccp(screenSize.width / 2.0, screenSize.height / 2.0))
pControlButton:addHandleOfControlEvent(touchDownAction,CCControlEventTouchDown)
pControlButton:addHandleOfControlEvent(touchDragInsideAction,CCControlEventTouchDragInside)
pControlButton:addHandleOfControlEvent(touchDragOutsideAction,CCControlEventTouchDragOutside)
pControlButton:addHandleOfControlEvent(touchDragEnterAction,CCControlEventTouchDragEnter)
pControlButton:addHandleOfControlEvent(touchDragExitAction,CCControlEventTouchDragExit)
pControlButton:addHandleOfControlEvent(touchUpInsideAction,CCControlEventTouchUpInside)
pControlButton:addHandleOfControlEvent(touchUpOutsideAction,CCControlEventTouchUpOutside)
pControlButton:addHandleOfControlEvent(touchCancelAction,CCControlEventTouchCancel)
pControlButton:registerControlEventHandler(touchDownAction,CCControlEventTouchDown)
pControlButton:registerControlEventHandler(touchDragInsideAction,CCControlEventTouchDragInside)
pControlButton:registerControlEventHandler(touchDragOutsideAction,CCControlEventTouchDragOutside)
pControlButton:registerControlEventHandler(touchDragEnterAction,CCControlEventTouchDragEnter)
pControlButton:registerControlEventHandler(touchDragExitAction,CCControlEventTouchDragExit)
pControlButton:registerControlEventHandler(touchUpInsideAction,CCControlEventTouchUpInside)
pControlButton:registerControlEventHandler(touchUpOutsideAction,CCControlEventTouchUpOutside)
pControlButton:registerControlEventHandler(touchCancelAction,CCControlEventTouchCancel)
pLayer:addChild(pControlButton, 1)
--Add the black background
@ -773,7 +773,7 @@ local function runCCControlTest()
pNode:addChild(pDisplayValueLabel)
-- Add the slider
local function valueChanged(strEventName,pSender)
local function valueChanged(pSender)
if nil == pSender then
return
end
@ -787,7 +787,7 @@ local function runCCControlTest()
pPotentiometer:setPosition(ccp (dLayer_width + 10 + pPotentiometer:getContentSize().width / 2, 0))
-- When the value of the slider will change, the given selector will be call
pPotentiometer:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged)
pPotentiometer:registerControlEventHandler(valueChanged, CCControlEventValueChanged)
pNode:addChild(pPotentiometer)
@ -798,7 +798,7 @@ local function runCCControlTest()
pNode:setAnchorPoint(ccp (0.5, 0.5))
-- Update the value label
valueChanged("", pPotentiometer)
valueChanged(pPotentiometer)
end
local function InitStepperTest(pLayer)
@ -830,7 +830,7 @@ local function runCCControlTest()
local minusSprite = CCSprite:create("extensions/stepper-minus.png")
local plusSprite = CCSprite:create("extensions/stepper-plus.png")
local function valueChanged(strEventName,pSender)
local function valueChanged(pSender)
if nil == pDisplayValueLabel or nil == pSender then
return
end
@ -841,7 +841,7 @@ local function runCCControlTest()
end
local stepper = CCControlStepper:create(minusSprite, plusSprite)
stepper:setPosition(ccp (layer_width + 10 + stepper:getContentSize().width / 2, 0))
stepper:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged)
stepper:registerControlEventHandler(valueChanged, CCControlEventValueChanged)
pNode:addChild(stepper)
layer_width = layer_width + stepper:getContentSize().width
@ -851,7 +851,7 @@ local function runCCControlTest()
pNode:setAnchorPoint(ccp (0.5, 0.5))
-- Update the value label
valueChanged("", stepper)
valueChanged(stepper)
end
local function InitSpecialSceneLayer(pLayer)

View File

@ -23,6 +23,7 @@
****************************************************************************/
#include "CCBProxy.h"
#include "LuaScriptHandlerMgr.h"
CCBReader* CCBProxy::createCCBReader()
{
@ -144,7 +145,7 @@ void CCBProxy::setCallback(Node* pNode,int nHandle)
{
MenuItem *pMenuItem = dynamic_cast<MenuItem*>(pNode);
if (NULL != pMenuItem) {
pMenuItem->registerScriptTapHandler(nHandle);
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)pMenuItem, nHandle, ScriptHandlerMgr::kMenuClickHandler);
}
}
else if (NULL != dynamic_cast<ControlButton*>(pNode))
@ -152,10 +153,8 @@ void CCBProxy::setCallback(Node* pNode,int nHandle)
ControlButton *pBtnItem = dynamic_cast<ControlButton*>(pNode);
if (NULL != pBtnItem) {
//UNOD,need Btn Pros to addHanldeOfControlEvent
pBtnItem->addHandleOfControlEvent(nHandle,ControlEventTouchUpInside);
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)pBtnItem, nHandle, ScriptHandlerMgr::kControlTouchUpInsideHandler);
}
}
}

View File

@ -27,6 +27,7 @@
#include "cocoa/CCArray.h"
#include "CCScheduler.h"
#include "LuaScriptHandlerMgr.h"
#include "CCControl.h"
NS_CC_BEGIN
@ -99,49 +100,12 @@ int LuaEngine::executeGlobalFunction(const char* functionName)
int LuaEngine::executeNodeEvent(Node* pNode, int nAction)
{
int nHandler = pNode->getScriptHandler();
if (!nHandler) return 0;
switch (nAction)
{
case kNodeOnEnter:
_stack->pushString("enter");
break;
case kNodeOnExit:
_stack->pushString("exit");
break;
case kNodeOnEnterTransitionDidFinish:
_stack->pushString("enterTransitionFinish");
break;
case kNodeOnExitTransitionDidStart:
_stack->pushString("exitTransitionStart");
break;
case kNodeOnCleanup:
_stack->pushString("cleanup");
break;
default:
return 0;
}
int ret = _stack->executeFunctionByHandler(nHandler, 1);
_stack->clean();
return ret;
return 0;
}
int LuaEngine::executeMenuItemEvent(MenuItem* pMenuItem)
{
int nHandler = pMenuItem->getScriptTapHandler();
if (!nHandler) return 0;
_stack->pushInt(pMenuItem->getTag());
_stack->pushObject(pMenuItem, "CCMenuItem");
int ret = _stack->executeFunctionByHandler(nHandler, 2);
_stack->clean();
return ret;
return 0;
}
int LuaEngine::executeNotificationEvent(NotificationCenter* pNotificationCenter, const char* pszName)
@ -157,16 +121,7 @@ int LuaEngine::executeNotificationEvent(NotificationCenter* pNotificationCenter,
int LuaEngine::executeCallFuncActionEvent(CallFunc* pAction, Object* pTarget/* = NULL*/)
{
int nHandler = pAction->getScriptHandler();
if (!nHandler) return 0;
if (pTarget)
{
_stack->pushObject(pTarget, "CCNode");
}
int ret = _stack->executeFunctionByHandler(nHandler, pTarget ? 1 : 0);
_stack->clean();
return ret;
return 0;
}
int LuaEngine::executeSchedule(int nHandler, float dt, Node* pNode/* = NULL*/)
@ -180,131 +135,22 @@ int LuaEngine::executeSchedule(int nHandler, float dt, Node* pNode/* = NULL*/)
int LuaEngine::executeLayerTouchEvent(Layer* pLayer, int eventType, Touch *pTouch)
{
TouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptTouchHandlerEntry();
if (!pScriptHandlerEntry) return 0;
int nHandler = pScriptHandlerEntry->getHandler();
if (!nHandler) return 0;
switch (eventType)
{
case CCTOUCHBEGAN:
_stack->pushString("began");
break;
case CCTOUCHMOVED:
_stack->pushString("moved");
break;
case CCTOUCHENDED:
_stack->pushString("ended");
break;
case CCTOUCHCANCELLED:
_stack->pushString("cancelled");
break;
default:
return 0;
}
const Point pt = Director::getInstance()->convertToGL(pTouch->getLocationInView());
_stack->pushFloat(pt.x);
_stack->pushFloat(pt.y);
int ret = _stack->executeFunctionByHandler(nHandler, 3);
_stack->clean();
return ret;
return 0;
}
int LuaEngine::executeLayerTouchesEvent(Layer* pLayer, int eventType, Set *pTouches)
{
TouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptTouchHandlerEntry();
if (!pScriptHandlerEntry) return 0;
int nHandler = pScriptHandlerEntry->getHandler();
if (!nHandler) return 0;
switch (eventType)
{
case CCTOUCHBEGAN:
_stack->pushString("began");
break;
case CCTOUCHMOVED:
_stack->pushString("moved");
break;
case CCTOUCHENDED:
_stack->pushString("ended");
break;
case CCTOUCHCANCELLED:
_stack->pushString("cancelled");
break;
default:
return 0;
}
Director* pDirector = Director::getInstance();
lua_State *L = _stack->getLuaState();
lua_newtable(L);
int i = 1;
for (SetIterator it = pTouches->begin(); it != pTouches->end(); ++it)
{
Touch* pTouch = (Touch*)*it;
Point pt = pDirector->convertToGL(pTouch->getLocationInView());
lua_pushnumber(L, pt.x);
lua_rawseti(L, -2, i++);
lua_pushnumber(L, pt.y);
lua_rawseti(L, -2, i++);
lua_pushinteger(L, pTouch->getID());
lua_rawseti(L, -2, i++);
}
int ret = _stack->executeFunctionByHandler(nHandler, 2);
_stack->clean();
return ret;
return 0;
}
int LuaEngine::executeLayerKeypadEvent(Layer* pLayer, int eventType)
{
ScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptKeypadHandlerEntry();
if (!pScriptHandlerEntry)
return 0;
int nHandler = pScriptHandlerEntry->getHandler();
if (!nHandler) return 0;
switch (eventType)
{
case kTypeBackClicked:
_stack->pushString("backClicked");
break;
case kTypeMenuClicked:
_stack->pushString("menuClicked");
break;
default:
return 0;
}
int ret = _stack->executeFunctionByHandler(nHandler, 1);
_stack->clean();
return ret;
return 0;
}
int LuaEngine::executeAccelerometerEvent(Layer* pLayer, Acceleration* pAccelerationValue)
{
ScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptAccelerateHandlerEntry();
if (!pScriptHandlerEntry)
return 0;
int nHandler = pScriptHandlerEntry->getHandler();
if (!nHandler) return 0;
_stack->pushFloat(pAccelerationValue->x);
_stack->pushFloat(pAccelerationValue->y);
_stack->pushFloat(pAccelerationValue->z);
_stack->pushFloat(pAccelerationValue->timestamp);
int ret = _stack->executeFunctionByHandler(nHandler, 4);
_stack->clean();
return ret;
return 0;
}
int LuaEngine::executeEvent(int nHandler, const char* pEventName, Object* pEventSource /* = NULL*/, const char* pEventSourceClassName /* = NULL*/)
@ -384,6 +230,11 @@ int LuaEngine::sendEvent(ScriptEvent* message)
return handleCommonEvent(message->data);
}
break;
case kControlEvent:
{
return handlerControlEvent(message->data);
}
break;
default:
break;
}
@ -527,20 +378,29 @@ int LuaEngine::handleKeypadEvent(void* data)
if (NULL == keypadScriptData->nativeObject)
return 0;
switch (keypadScriptData->objectType)
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)keypadScriptData->nativeObject, ScriptHandlerMgr::kKeypadHandler);
if (0 == handler)
return 0;
int action = keypadScriptData->actionType;
switch (action)
{
case kLayerKeypad:
{
Layer* layer = (Layer*)(keypadScriptData->nativeObject);
return handleLayerKeypadEvent(layer, keypadScriptData->actionType);
}
break;
case kTypeBackClicked:
_stack->pushString("backClicked");
break;
case kTypeMenuClicked:
_stack->pushString("menuClicked");
break;
default:
break;
return 0;
}
return 0;
int ret = _stack->executeFunctionByHandler(handler, 1);
_stack->clean();
return ret;
}
int LuaEngine::handleAccelerometerEvent(void* data)
@ -601,32 +461,12 @@ int LuaEngine::handleTouchesEvent(void* data)
if (NULL == touchesScriptData->nativeObject || NULL == touchesScriptData->touches)
return 0;
switch (touchesScriptData->objectType)
{
case kLayerTouches:
{
Layer* layer = (Layer*)(touchesScriptData->nativeObject);
return handleLayerTouchesEvent(layer, touchesScriptData->actionType, touchesScriptData->touches);
}
break;
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)touchesScriptData->nativeObject, ScriptHandlerMgr::kTouchesHandler);
default:
break;
}
return 0;
}
int LuaEngine::handleLayerTouchesEvent(Layer* layer,int actionType,Set* touches)
{
if (NULL == layer || NULL == touches)
return 0;
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)layer, ScriptHandlerMgr::kTouchesHandler);
if (0 == handler)
return 0;
switch (actionType)
switch (touchesScriptData->actionType)
{
case CCTOUCHBEGAN:
_stack->pushString("began");
@ -650,11 +490,11 @@ int LuaEngine::handleLayerTouchesEvent(Layer* layer,int actionType,Set* touches)
Director* pDirector = Director::getInstance();
lua_State *L = _stack->getLuaState();
int count = touches->count();
int count = touchesScriptData->touches->count();
int ret = 0;
if (count == 1)
{
Touch* touch = (Touch*)*(touches->begin());
Touch* touch = (Touch*)*(touchesScriptData->touches->begin());
if (NULL != touch) {
const Point pt = Director::getInstance()->convertToGL(touch->getLocationInView());
_stack->pushFloat(pt.x);
@ -666,7 +506,7 @@ int LuaEngine::handleLayerTouchesEvent(Layer* layer,int actionType,Set* touches)
{
lua_newtable(L);
int i = 1;
for (SetIterator it = touches->begin(); it != touches->end(); ++it)
for (SetIterator it = touchesScriptData->touches->begin(); it != touchesScriptData->touches->end(); ++it)
{
Touch* pTouch = (Touch*)*it;
Point pt = pDirector->convertToGL(pTouch->getLocationInView());
@ -683,97 +523,133 @@ int LuaEngine::handleLayerTouchesEvent(Layer* layer,int actionType,Set* touches)
return ret;
}
int LuaEngine::handleLayerKeypadEvent(Layer* layer,int actionType)
int LuaEngine::handlerControlEvent(void* data)
{
if (NULL == layer)
if ( NULL == data )
return 0;
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)layer, ScriptHandlerMgr::kKeypadHandler);
if (0 == handler)
BasicScriptData* basicScriptData = (BasicScriptData*)data;
if (NULL == basicScriptData->nativeObject)
return 0;
int action = actionType;
int controlEvents = *((int*)(basicScriptData->value));
switch (action)
int handler = 0;
int ret = 0;
for (int i = 0; i < kControlEventTotalNumber; i++)
{
case kTypeBackClicked:
_stack->pushString("backClicked");
break;
if ((controlEvents & (1 << i)))
{
handler = ScriptHandlerMgr::getInstance()->getObjectHandler(basicScriptData->nativeObject, ScriptHandlerMgr::kControlTouchDownHandler + i);
case kTypeMenuClicked:
_stack->pushString("menuClicked");
break;
default:
return 0;
if (0 != handler)
{
_stack->pushObject((Object*)basicScriptData->nativeObject, "CCObject");
ret = _stack->executeFunctionByHandler(handler, 1);
_stack->clean();
}
}
}
int ret = _stack->executeFunctionByHandler(handler, 1);
_stack->clean();
return ret;
}
void LuaEngine::expandLuaObjecFunc()
void LuaEngine::extendLuaObjec()
{
if ( NULL == _stack || NULL == _stack->getLuaState())
return;
lua_State* lua_S = _stack->getLuaState();
expandNodeFunc(lua_S);
expandMenuItemFunc(lua_S);
expandLayerFunc(lua_S);
extendNode(lua_S);
extendMenuItem(lua_S);
extendLayer(lua_S);
extendControl(lua_S);
_stack->clean();
}
void LuaEngine::expandNodeFunc(lua_State* lua_S)
void LuaEngine::extendNode(lua_State* lua_S)
{
if(NULL == lua_S)
return;
lua_pushstring(lua_S,"CCNode");
lua_gettable(lua_S,LUA_REGISTRYINDEX); /* get super */
lua_rawget(lua_S,LUA_REGISTRYINDEX);
if (lua_istable(lua_S,-1))
{
lua_pushstring(lua_S,"registerScriptHandler");
lua_pushcfunction(lua_S,tolua_Cocos2d_registerScriptHandler00);
lua_rawset(lua_S,-3);
lua_pushstring(lua_S,"unregisterScriptHandler");
lua_pushcfunction(lua_S,tolua_Cocos2d_unregisterScriptHandler00);
lua_rawset(lua_S, -3);
}
}
void LuaEngine::expandMenuItemFunc(lua_State* lua_S)
void LuaEngine::extendMenuItem(lua_State* lua_S)
{
if (NULL == lua_S)
return;
lua_pushstring(lua_S,"CCMenuItem");
lua_gettable(lua_S,LUA_REGISTRYINDEX); /* get super */
lua_rawget(lua_S,LUA_REGISTRYINDEX);
if (lua_istable(lua_S,-1))
{
lua_pushstring(lua_S,"registerScriptTapHandler");
lua_pushcfunction(lua_S,tolua_Cocos2d_registerScriptTapHandler00);
lua_rawset(lua_S,-3);
lua_pushstring(lua_S, "unregisterScriptTapHandler");
lua_pushcfunction(lua_S,tolua_Cocos2d_unregisterScriptTapHandler00);
lua_rawset(lua_S, -3);
}
}
void LuaEngine::expandLayerFunc(lua_State* lua_S)
void LuaEngine::extendLayer(lua_State* lua_S)
{
if (NULL == lua_S)
return;
lua_pushstring(lua_S,"CCLayer");
lua_gettable(lua_S,LUA_REGISTRYINDEX); /* get super */
lua_rawget(lua_S,LUA_REGISTRYINDEX);
if (lua_istable(lua_S,-1))
{
lua_pushstring(lua_S,"registerScriptTouchHandler");
lua_pushcfunction(lua_S,tolua_Cocos2d_registerScriptTouchHandler00);
lua_rawset(lua_S,-3);
lua_pushstring(lua_S, "unregisterScriptTouchHandler");
lua_pushcfunction(lua_S,tolua_Cocos2d_unregisterScriptTouchHandler00);
lua_rawset(lua_S, -3);
lua_pushstring(lua_S, "registerScriptKeypadHandler");
lua_pushcfunction(lua_S, tolua_Cocos2d_registerScriptKeypadHandler00);
lua_rawset(lua_S, -3);
lua_pushstring(lua_S, "unregisterScriptKeypadHandler");
lua_pushcfunction(lua_S, tolua_Cocos2d_unregisterScriptKeypadHandler00);
lua_rawset(lua_S, -3);
lua_pushstring(lua_S, "registerScriptAccelerateHandler");
lua_pushcfunction(lua_S, tolua_Cocos2d_registerScriptAccelerateHandler00);
lua_rawset(lua_S, -3);
lua_pushstring(lua_S, "unregisterScriptAccelerateHandler");
lua_pushcfunction(lua_S, tolua_Cocos2d_unregisterScriptAccelerateHandler00);
lua_rawset(lua_S, -3);
}
}
void LuaEngine::extendControl(lua_State* lua_S)
{
if (NULL == lua_S)
return;
lua_pushstring(lua_S,"CCControl");
lua_rawget(lua_S,LUA_REGISTRYINDEX);
if (lua_istable(lua_S,-1))
{
lua_pushstring(lua_S,"registerControlEventHandler");
lua_pushcfunction(lua_S,tolua_Cocos2d_registerControlEventHandler00);
lua_rawset(lua_S,-3);
lua_pushstring(lua_S,"unregisterControlEventHandler");
lua_pushcfunction(lua_S,tolua_Cocos2d_unregisterControlEventHandler00);
lua_rawset(lua_S,-3);
}
}
NS_CC_END

View File

@ -119,7 +119,7 @@ public:
virtual bool handleAssert(const char *msg);
virtual int sendEvent(ScriptEvent* message);
void expandLuaObjecFunc();
void extendLuaObjec();
private:
int handleNodeEvent(void* data);
int handleMenuClickedEvent(void* data);
@ -130,11 +130,11 @@ private:
int handleAccelerometerEvent(void* data);
int handleCommonEvent(void* data);
int handleTouchesEvent(void* data);
int handleLayerTouchesEvent(Layer* layer,int actionType,Set* touches);
int handleLayerKeypadEvent(Layer* layer,int actionType);
void expandNodeFunc(lua_State* lua_S);
void expandMenuItemFunc(lua_State* lua_S);
void expandLayerFunc(lua_State* lua_S);
int handlerControlEvent(void* data);
void extendNode(lua_State* lua_S);
void extendMenuItem(lua_State* lua_S);
void extendLayer(lua_State* lua_S);
void extendControl(lua_State* lua_S);
private:
LuaEngine(void)
: _stack(NULL)

View File

@ -1 +1 @@
bd510fcf9510da9b94a1cde547a41103429b2f5b
66f7f4866297ccfebd77aa7752fd3c58e5fb9505

View File

@ -1 +1 @@
d0b231fcad3b4e35d4f2a998dce1b7437ae689ab
9fac9e19f8a57d40eb90b02c0be6e9f8e20e0d22

View File

@ -227,6 +227,29 @@ tolua_lerror:
#endif
}
int tolua_Cocos2d_unregisterScriptHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"CCNode",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Node* node = (Node*)tolua_tousertype(tolua_S,1,0);
ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)node, ScriptHandlerMgr::kNodeHandler);
return 0;
}
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err);
return 0;
#endif
}
int tolua_Cocos2d_registerScriptTapHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
@ -252,6 +275,29 @@ tolua_lerror:
#endif
}
int tolua_Cocos2d_unregisterScriptTapHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"CCMenuItem",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
MenuItem* menuItem = (MenuItem*)tolua_tousertype(tolua_S,1,0);
ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)menuItem, ScriptHandlerMgr::kMenuClickHandler);
return 0;
}
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err);
return 0;
#endif
}
int tolua_Cocos2d_registerScriptTouchHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
@ -287,6 +333,28 @@ tolua_lerror:
#endif
}
int tolua_Cocos2d_unregisterScriptTouchHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"CCLayer",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Layer* layer = (Layer*) tolua_tousertype(tolua_S,1,0);
ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)layer, ScriptHandlerMgr::kTouchesHandler);
return 0;
}
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'registerScriptTouchHandler'.",&tolua_err);
return 0;
#endif
}
int tolua_Cocos2d_registerScriptKeypadHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
@ -312,6 +380,29 @@ tolua_lerror:
#endif
}
int tolua_Cocos2d_unregisterScriptKeypadHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"CCLayer",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Layer* layer = (Layer*) tolua_tousertype(tolua_S,1,0);
ScriptHandlerMgr::getInstance()->removeObjectHandler(layer, ScriptHandlerMgr::kKeypadHandler);
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'unregisterScriptKeypadHandler'.",&tolua_err);
return 0;
#endif
}
int tolua_Cocos2d_registerScriptAccelerateHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
@ -337,6 +428,88 @@ tolua_lerror:
#endif
}
int tolua_Cocos2d_unregisterScriptAccelerateHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"CCLayer",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Layer* layer = (Layer*) tolua_tousertype(tolua_S,1,0);
ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)layer, ScriptHandlerMgr::kAccelerometerHandler);
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'unregisterScriptAccelerateHandler'.",&tolua_err);
return 0;
#endif
}
int tolua_Cocos2d_registerControlEventHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"CCControl",0,&tolua_err) ||
(tolua_isvaluenil(tolua_S,2,&tolua_err) || !toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err)) ||
!tolua_isnumber(tolua_S, 3, 0, &tolua_err)||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Control* control = (Control*) tolua_tousertype(tolua_S,1,0);
LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0));
int controlevent = ((ControlEvent) (int) tolua_tonumber(tolua_S,3,0));
for (int i = 0; i < kControlEventTotalNumber; i++)
{
if ((controlevent & (1 << i)))
{
int handlerevent = ScriptHandlerMgr::kControlTouchDownHandler + i;
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)control, handler, handlerevent);
break;
}
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'registerControlEventHandler'.",&tolua_err);
return 0;
#endif
}
int tolua_Cocos2d_unregisterControlEventHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"CCControl",0,&tolua_err) ||
!tolua_isnumber(tolua_S, 2, 0, &tolua_err)||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Control* control = (Control*) tolua_tousertype(tolua_S,1,0);
int handlerEvent = (int)tolua_tonumber(tolua_S,2,0);
ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)control,handlerEvent);
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'registerControlEventHandler'.",&tolua_err);
return 0;
#endif
}
static void tolua_reg_script_handler_mgr_type(lua_State* tolua_S)
{
tolua_usertype(tolua_S, "CCCallFunc");
@ -407,8 +580,6 @@ TOLUA_API int tolua_script_handler_mgr_open(lua_State* tolua_S)
tolua_reg_script_handler_mgr_type(tolua_S);
tolua_module(tolua_S, NULL,0);
tolua_beginmodule(tolua_S, NULL);
tolua_constant(tolua_S, "kLayerTouches", kLayerTouches);
tolua_constant(tolua_S, "kLayerKeypad", kLayerKeypad);
tolua_cclass(tolua_S, "CCCallFunc", "CCCallFunc","CCActionInstant",NULL);
tolua_beginmodule(tolua_S, "CCCallFunc");
tolua_function(tolua_S, "create", tolua_Cocos2d_LuaCallFunc_create00);
@ -417,11 +588,21 @@ TOLUA_API int tolua_script_handler_mgr_open(lua_State* tolua_S)
tolua_beginmodule(tolua_S, "ScriptHandlerMgr");
tolua_constant(tolua_S,"kNormalHandler",ScriptHandlerMgr::kNodeHandler);
tolua_constant(tolua_S,"kMenuClickHandler",ScriptHandlerMgr::kMenuClickHandler);
tolua_constant(tolua_S,"kScheduleHandler",ScriptHandlerMgr::kScheduleHandler);
tolua_constant(tolua_S,"kNotificationHandler",ScriptHandlerMgr::kNotificationHandler);
tolua_constant(tolua_S,"kCallFuncHandler",ScriptHandlerMgr::kCallFuncHandler);
tolua_constant(tolua_S,"kScheduleHandler",ScriptHandlerMgr::kScheduleHandler);
tolua_constant(tolua_S,"kTouchesHandler",ScriptHandlerMgr::kTouchesHandler);
tolua_constant(tolua_S,"kKeypadHandler",ScriptHandlerMgr::kKeypadHandler);
tolua_constant(tolua_S,"kAccelerometerHandler",ScriptHandlerMgr::kAccelerometerHandler);
tolua_constant(tolua_S,"kControlTouchDownHandler",ScriptHandlerMgr::kControlTouchDownHandler);
tolua_constant(tolua_S,"kControlTouchDragInsideHandler",ScriptHandlerMgr::kControlTouchDragInsideHandler);
tolua_constant(tolua_S,"kControlTouchDragOutsideHandler",ScriptHandlerMgr::kControlTouchDragOutsideHandler);
tolua_constant(tolua_S,"kControlTouchDragEnterHandler",ScriptHandlerMgr::kControlTouchDragEnterHandler);
tolua_constant(tolua_S,"kControlTouchDragExitHandler",ScriptHandlerMgr::kControlTouchDragExitHandler);
tolua_constant(tolua_S,"kControlTouchUpInsideHandler",ScriptHandlerMgr::kControlTouchUpInsideHandler);
tolua_constant(tolua_S,"kControlTouchUpOutsideHandler",ScriptHandlerMgr::kControlTouchUpOutsideHandler);
tolua_constant(tolua_S,"kControlTouchCancelHandler",ScriptHandlerMgr::kControlTouchCancelHandler);
tolua_constant(tolua_S,"kControlValueChangedHandler",ScriptHandlerMgr::kControlValueChangedHandler);
tolua_function(tolua_S, "getInstance", tolua_Cocos2d_ScriptHandlerMgr_getInstance00);
tolua_endmodule(tolua_S);
tolua_endmodule(tolua_S);

View File

@ -80,6 +80,16 @@ public:
kTouchesHandler,
kKeypadHandler,
kAccelerometerHandler,
kControlTouchDownHandler,
kControlTouchDragInsideHandler,
kControlTouchDragOutsideHandler,
kControlTouchDragEnterHandler,
kControlTouchDragExitHandler,
kControlTouchUpInsideHandler,
kControlTouchUpOutsideHandler,
kControlTouchCancelHandler,
kControlValueChangedHandler,
};
@ -92,14 +102,22 @@ private:
NS_CC_END
TOLUA_API int tolua_Cocos2d_registerScriptHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_unregisterScriptHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_registerScriptTapHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_unregisterScriptTapHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_registerScriptTouchHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_unregisterScriptTouchHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_registerScriptKeypadHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_unregisterScriptKeypadHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_registerScriptAccelerateHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_unregisterScriptAccelerateHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_registerControlEventHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_unregisterControlEventHandler00(lua_State* tolua_S);
TOLUA_API int tolua_script_handler_mgr_open(lua_State* tolua_S);

View File

@ -35,7 +35,7 @@ classes = Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.*
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = Node::[^setPosition$ getGrid setGLServerState description getUserObject .*UserData getGLServerState .*schedule],
skip = Node::[^setPosition$ getGrid setGLServerState description getUserObject .*UserData getGLServerState .*schedule registerScriptHandler unregisterScriptHandler getScriptHandler],
Sprite::[getQuad displayFrame getBlendFunc ^setPosition$ setBlendFunc setSpriteBatchNode getSpriteBatchNode],
SpriteBatchNode::[getBlendFunc setBlendFunc],
MotionStreak::[getBlendFunc setBlendFunc draw update],
@ -45,9 +45,9 @@ skip = Node::[^setPosition$ getGrid setGLServerState description getUserObject .
ParticleSystem::[getBlendFunc setBlendFunc],
DrawNode::[getBlendFunc setBlendFunc drawPolygon],
Director::[sharedDirector getAccelerometer (g|s)et.*Dispatcher getOpenGLView getProjection getClassTypeInfo],
Layer.*::[didAccelerate (g|s)etBlendFunc keyPressed keyReleased unregisterScriptKeypadHandler],
Layer.*::[didAccelerate (g|s)etBlendFunc keyPressed keyReleased unregisterScriptKeypadHandler getScriptTouchHandlerEntry getScriptKeypadHandlerEntry getScriptAccelerateHandlerEntry registerScriptTouchHandler unregisterScriptTouchHandler registerScriptKeypadHandler registerScriptAccelerateHandler unregisterScriptAccelerateHandler],
Menu.*::[.*Target getSubItems create initWithItems alignItemsInRows alignItemsInColumns],
MenuItem.*::[create setCallback initWithCallback],
MenuItem.*::[create setCallback initWithCallback registerScriptTapHandler unregisterScriptTapHandler getScriptTapHandler],
Copying::[*],
.*Protocol::[*],
.*Delegate::[*],

View File

@ -59,7 +59,4 @@ class CCControl:public CCLayerRGBA
virtual CCPoint getTouchLocation(CCTouch* touch);
virtual bool isTouchInside(CCTouch * touch);
void addHandleOfControlEvent(LUA_FUNCTION nFunID,CCControlEvent controlEvents);
void removeHandleOfControlEvent(CCControlEvent controlEvents);
};