зеркало из https://github.com/microsoft/cocos2d-x.git
Merge pull request #5636 from dumganhar/iss3290-onenter-order
closed #3290: The order of onEnter / onExit work correctly on JSB and LuaBindings.
This commit is contained in:
Коммит
2784955845
|
@ -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,
|
||||
|
|
Загрузка…
Ссылка в новой задаче