diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index 6071fe2088..0b933917af 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -145,7 +145,7 @@ void ClippingNode::onEnter() #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { - if (sendNodeEventToJS(this, kNodeOnEnter)) + if (sendNodeEventToJSExtended(this, kNodeOnEnter)) return; } #endif @@ -160,13 +160,6 @@ void ClippingNode::onEnter() { CCLOG("ClippingNode warning: _stencil is nil."); } - -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeLua) - { - sendNodeEventToLua(this, kNodeOnEnter); - } -#endif } void ClippingNode::onEnterTransitionDidFinish() diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 06959b10cb..763f93b641 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -82,6 +82,7 @@ static bool sendNodeEventToJS(Node* node, int action) if (scriptEngine->isCalledFromScript()) { + // Should only be invoked at root class Node scriptEngine->setCalledFromScript(false); } else @@ -94,6 +95,20 @@ static bool sendNodeEventToJS(Node* node, int action) return false; } +static bool sendNodeEventToJSExtended(Node* node, int action) +{ + auto scriptEngine = ScriptEngineManager::getInstance()->getScriptEngine(); + + if (!scriptEngine->isCalledFromScript()) + { + BasicScriptData data(node,(void*)&action); + ScriptEvent scriptEvent(kNodeEvent,(void*)&data); + if (scriptEngine->sendEvent(&scriptEvent)) + return true; + } + + return false; +} static void sendNodeEventToLua(Node* node, int action) { diff --git a/cocos/2d/CCParticleSystem.cpp b/cocos/2d/CCParticleSystem.cpp index 9ddc692c3d..7d538fb70b 100644 --- a/cocos/2d/CCParticleSystem.cpp +++ b/cocos/2d/CCParticleSystem.cpp @@ -619,7 +619,7 @@ void ParticleSystem::onEnter() #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { - if (sendNodeEventToJS(this, kNodeOnEnter)) + if (sendNodeEventToJSExtended(this, kNodeOnEnter)) return; } #endif @@ -628,13 +628,6 @@ void ParticleSystem::onEnter() // update after action in run! this->scheduleUpdateWithPriority(1); - -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeLua) - { - sendNodeEventToLua(this, kNodeOnEnter); - } -#endif } void ParticleSystem::onExit() diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index 3cdd04fe25..1b71db9347 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -437,20 +437,13 @@ void Armature::onEnter() #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { - if (sendNodeEventToJS(this, kNodeOnEnter)) + if (sendNodeEventToJSExtended(this, kNodeOnEnter)) return; } #endif Node::onEnter(); scheduleUpdate(); - -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeLua) - { - sendNodeEventToLua(this, kNodeOnEnter); - } -#endif } void Armature::onExit() diff --git a/cocos/editor-support/spine/CCSkeleton.cpp b/cocos/editor-support/spine/CCSkeleton.cpp index 346b19b083..e2f52b945f 100644 --- a/cocos/editor-support/spine/CCSkeleton.cpp +++ b/cocos/editor-support/spine/CCSkeleton.cpp @@ -279,20 +279,13 @@ void Skeleton::onEnter() { #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { - if (sendNodeEventToJS(this, kNodeOnEnter)) + if (sendNodeEventToJSExtended(this, kNodeOnEnter)) return; } #endif Node::onEnter(); scheduleUpdate(); - -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeLua) - { - sendNodeEventToLua(this, kNodeOnEnter); - } -#endif } void Skeleton::onExit() { diff --git a/cocos/ui/CCProtectedNode.cpp b/cocos/ui/CCProtectedNode.cpp index 91b300f1f8..ebbde2023e 100644 --- a/cocos/ui/CCProtectedNode.cpp +++ b/cocos/ui/CCProtectedNode.cpp @@ -340,7 +340,7 @@ void ProtectedNode::onEnter() #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { - if (sendNodeEventToJS(this, kNodeOnEnter)) + if (sendNodeEventToJSExtended(this, kNodeOnEnter)) return; } #endif @@ -348,13 +348,6 @@ void ProtectedNode::onEnter() Node::onEnter(); for( const auto &child: _protectedChildren) child->onEnter(); - -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeLua) - { - sendNodeEventToLua(this, kNodeOnEnter); - } -#endif } void ProtectedNode::onEnterTransitionDidFinish() diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index ba22857014..b4f1227b17 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -105,7 +105,7 @@ void Layout::onEnter() #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { - if (sendNodeEventToJS(this, kNodeOnEnter)) + if (sendNodeEventToJSExtended(this, kNodeOnEnter)) return; } #endif @@ -117,13 +117,6 @@ void Layout::onEnter() } _doLayoutDirty = true; _clippingRectDirty = true; - -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeLua) - { - sendNodeEventToLua(this, kNodeOnEnter); - } -#endif } void Layout::onExit() diff --git a/cocos/ui/UIPageView.cpp b/cocos/ui/UIPageView.cpp index ee992a488e..dd465c73c5 100644 --- a/cocos/ui/UIPageView.cpp +++ b/cocos/ui/UIPageView.cpp @@ -71,20 +71,13 @@ void PageView::onEnter() #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { - if (sendNodeEventToJS(this, kNodeOnEnter)) + if (sendNodeEventToJSExtended(this, kNodeOnEnter)) return; } #endif Layout::onEnter(); scheduleUpdate(); - -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeLua) - { - sendNodeEventToLua(this, kNodeOnEnter); - } -#endif } bool PageView::init() diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index aa21fde150..183df6d1b1 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -98,20 +98,13 @@ void ScrollView::onEnter() #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { - if (sendNodeEventToJS(this, kNodeOnEnter)) + if (sendNodeEventToJSExtended(this, kNodeOnEnter)) return; } #endif Layout::onEnter(); scheduleUpdate(); - -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeLua) - { - sendNodeEventToLua(this, kNodeOnEnter); - } -#endif } bool ScrollView::init() diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index 9062dd5c43..c625aeb097 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -418,20 +418,13 @@ void TextField::onEnter() #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { - if (sendNodeEventToJS(this, kNodeOnEnter)) + if (sendNodeEventToJSExtended(this, kNodeOnEnter)) return; } #endif Widget::onEnter(); scheduleUpdate(); - -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeLua) - { - sendNodeEventToLua(this, kNodeOnEnter); - } -#endif } void TextField::initRenderer() diff --git a/extensions/GUI/CCEditBox/CCEditBox.cpp b/extensions/GUI/CCEditBox/CCEditBox.cpp index 1964c6a4f6..880a63be75 100644 --- a/extensions/GUI/CCEditBox/CCEditBox.cpp +++ b/extensions/GUI/CCEditBox/CCEditBox.cpp @@ -332,7 +332,7 @@ void EditBox::onEnter(void) #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { - if (sendNodeEventToJS(this, kNodeOnEnter)) + if (sendNodeEventToJSExtended(this, kNodeOnEnter)) return; } #endif @@ -345,13 +345,6 @@ void EditBox::onEnter(void) #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) this->schedule(schedule_selector(EditBox::updatePosition), CHECK_EDITBOX_POSITION_INTERVAL); #endif - -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeLua) - { - sendNodeEventToLua(this, kNodeOnEnter); - } -#endif } void EditBox::updatePosition(float dt)