closed #3290: The order of onEnter works correctly on JSB and LuaBindings.

This commit is contained in:
James Chen 2014-03-08 11:51:10 +08:00
parent 9b0c0ab44e
commit 7aec578b35
2 changed files with 88 additions and 29 deletions

View File

@ -982,64 +982,120 @@ kmMat4 Node::transform(const kmMat4& parentTransform)
return ret; return ret;
} }
void Node::onEnter()
{
_isTransitionFinished = false;
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (_scriptType != kScriptTypeNone)
static bool sendNodeEventToJS(Node* node, int action)
{
auto scriptEngine = ScriptEngineManager::getInstance()->getScriptEngine();
if (scriptEngine->isCalledFromScript())
{ {
int action = kNodeOnEnter; scriptEngine->setCalledFromScript(false);
BasicScriptData data(this,(void*)&action); }
else
{
BasicScriptData data(node,(void*)&action);
ScriptEvent scriptEvent(kNodeEvent,(void*)&data); ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent); if (scriptEngine->sendEvent(&scriptEvent))
return true;
}
return false;
}
static void sendNodeEventToLua(Node* node, int action)
{
auto scriptEngine = ScriptEngineManager::getInstance()->getScriptEngine();
BasicScriptData data(node,(void*)&action);
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
scriptEngine->sendEvent(&scriptEvent);
}
#endif
void Node::onEnter()
{
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (sendNodeEventToJS(this, kNodeOnEnter))
return;
} }
#endif #endif
_isTransitionFinished = false;
for( const auto &child: _children) for( const auto &child: _children)
child->onEnter(); child->onEnter();
this->resume(); this->resume();
_running = true; _running = true;
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeLua)
{
sendNodeEventToLua(this, kNodeOnEnter);
}
#endif
} }
void Node::onEnterTransitionDidFinish() void Node::onEnterTransitionDidFinish()
{ {
_isTransitionFinished = true;
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (_scriptType != kScriptTypeNone) if (_scriptType == kScriptTypeJavascript)
{ {
int action = kNodeOnEnterTransitionDidFinish; if (sendNodeEventToJS(this, kNodeOnEnterTransitionDidFinish))
BasicScriptData data(this,(void*)&action); return;
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
} }
#endif #endif
_isTransitionFinished = true;
for( const auto &child: _children) for( const auto &child: _children)
child->onEnterTransitionDidFinish(); child->onEnterTransitionDidFinish();
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeLua)
{
sendNodeEventToLua(this, kNodeOnEnterTransitionDidFinish);
}
#endif
} }
void Node::onExitTransitionDidStart() void Node::onExitTransitionDidStart()
{ {
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (sendNodeEventToJS(this, kNodeOnExitTransitionDidStart))
return;
}
#endif
for( const auto &child: _children) for( const auto &child: _children)
child->onExitTransitionDidStart(); child->onExitTransitionDidStart();
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (_scriptType != kScriptTypeNone) if (_scriptType == kScriptTypeLua)
{ {
int action = kNodeOnExitTransitionDidStart; sendNodeEventToLua(this, kNodeOnExitTransitionDidStart);
BasicScriptData data(this,(void*)&action);
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
} }
#endif #endif
} }
void Node::onExit() void Node::onExit()
{ {
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (sendNodeEventToJS(this, kNodeOnExit))
return;
}
#endif
this->pause(); this->pause();
_running = false; _running = false;
@ -1048,12 +1104,9 @@ void Node::onExit()
child->onExit(); child->onExit();
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (_scriptType != kScriptTypeNone) if (_scriptType == kScriptTypeLua)
{ {
int action = kNodeOnExit; sendNodeEventToLua(this, kNodeOnExit);
BasicScriptData data(this,(void*)&action);
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
} }
#endif #endif
} }

View File

@ -364,6 +364,9 @@ struct ScriptEvent
class CC_DLL ScriptEngineProtocol class CC_DLL ScriptEngineProtocol
{ {
public: public:
ScriptEngineProtocol()
{};
/** /**
* @js NA * @js NA
* @lua NA * @lua NA
@ -435,6 +438,9 @@ public:
*/ */
virtual bool handleAssert(const char *msg) = 0; virtual bool handleAssert(const char *msg) = 0;
virtual void setCalledFromScript(bool callFromScript) { CC_UNUSED_PARAM(callFromScript); };
virtual bool isCalledFromScript() { return false; };
enum class ConfigType enum class ConfigType
{ {
NONE, NONE,