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
Родитель 9b0c0ab44e
Коммит 7aec578b35
2 изменённых файлов: 88 добавлений и 29 удалений

Просмотреть файл

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

Просмотреть файл

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