2017-10-26 17:17:30 +08:00
|
|
|
|
#include "..\emanagers.h"
|
2017-10-19 12:48:58 +08:00
|
|
|
|
#include "..\eactions.h"
|
2017-10-19 00:50:04 +08:00
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
static std::vector<e2d::Action*> s_vActions;
|
2017-10-19 00:50:04 +08:00
|
|
|
|
|
2017-10-19 12:48:58 +08:00
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ActionManager::_add(Action * pAction, Node * pTargetNode)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
WARN_IF(pAction == nullptr, "Action NULL pointer exception!");
|
2017-10-19 12:48:58 +08:00
|
|
|
|
|
2018-02-06 15:34:47 +08:00
|
|
|
|
if (pAction)
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-06 15:34:47 +08:00
|
|
|
|
pAction->startWith(pTargetNode);
|
|
|
|
|
|
pAction->retain();
|
|
|
|
|
|
s_vActions.push_back(pAction);
|
2017-10-19 12:48:58 +08:00
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ActionManager::resumeAllActionsBindedWith(Node * pTargetNode)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2017-10-21 19:09:31 +08:00
|
|
|
|
if (pTargetNode)
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
for (auto action : s_vActions)
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
if (action->getTarget() == pTargetNode)
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-02-06 15:34:47 +08:00
|
|
|
|
action->resume();
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
2017-10-19 12:48:58 +08:00
|
|
|
|
}
|
2018-02-03 22:04:43 +08:00
|
|
|
|
for (auto child : pTargetNode->getChildren())
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
ActionManager::resumeAllActionsBindedWith(child);
|
2017-10-19 12:48:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ActionManager::pauseAllActionsBindedWith(Node * pTargetNode)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pTargetNode)
|
|
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
for (auto action : s_vActions)
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
if (action->getTarget() == pTargetNode)
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
action->pause();
|
2017-10-19 12:48:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-02-03 22:04:43 +08:00
|
|
|
|
for (auto child : pTargetNode->getChildren())
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
ActionManager::pauseAllActionsBindedWith(child);
|
2017-10-19 12:48:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ActionManager::stopAllActionsBindedWith(Node * pTargetNode)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pTargetNode)
|
|
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
for (auto action : s_vActions)
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
if (action->getTarget() == pTargetNode)
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
action->stop();
|
2017-10-19 12:48:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-02-03 22:04:43 +08:00
|
|
|
|
for (auto child : pTargetNode->getChildren())
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
ActionManager::stopAllActionsBindedWith(child);
|
2017-10-19 12:48:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ActionManager::__clearAllActionsBindedWith(Node * pTargetNode)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pTargetNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (size_t i = 0; i < s_vActions.size();)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto a = s_vActions[i];
|
|
|
|
|
|
if (a->getTarget() == pTargetNode)
|
|
|
|
|
|
{
|
2017-10-31 17:19:13 +08:00
|
|
|
|
SafeRelease(&a);
|
2017-10-19 12:48:58 +08:00
|
|
|
|
s_vActions.erase(s_vActions.begin() + i);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ActionManager::resumeAllActions()
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
for (auto child : SceneManager::getCurrentScene()->getRoot()->getChildren())
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
ActionManager::resumeAllActionsBindedWith(child);
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ActionManager::pauseAllActions()
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
for (auto child : SceneManager::getCurrentScene()->getRoot()->getChildren())
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
ActionManager::pauseAllActionsBindedWith(child);
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ActionManager::stopAllActions()
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
for (auto child : SceneManager::getCurrentScene()->getRoot()->getChildren())
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
ActionManager::stopAllActionsBindedWith(child);
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ActionManager::__resetAllActions()
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
for (auto action : s_vActions)
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
action->_resetTime();
|
2017-10-19 12:48:58 +08:00
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ActionManager::__update()
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
if (s_vActions.empty() || Game::isPaused())
|
2017-10-19 12:48:58 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĶ<D0B5><C4B6><EFBFBD>
|
2018-02-06 21:11:54 +08:00
|
|
|
|
for (size_t i = 0; i < s_vActions.size(); i++)
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-06 21:11:54 +08:00
|
|
|
|
auto &action = s_vActions[i];
|
2017-10-19 12:48:58 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
2018-02-06 15:34:47 +08:00
|
|
|
|
if (action->isRunning() &&
|
|
|
|
|
|
action->getTarget() &&
|
2018-02-07 16:37:12 +08:00
|
|
|
|
action->getTarget()->getParentScene() == SceneManager::getCurrentScene())
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-06 21:11:54 +08:00
|
|
|
|
if (!action->_isEnding())
|
2017-10-19 12:48:58 +08:00
|
|
|
|
{
|
2018-02-06 21:11:54 +08:00
|
|
|
|
// ִ<>ж<EFBFBD><D0B6><EFBFBD>
|
|
|
|
|
|
action->_update();
|
2017-10-19 12:48:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-02-06 21:11:54 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
action->release();
|
|
|
|
|
|
action->m_pTarget = nullptr;
|
|
|
|
|
|
s_vActions.erase(s_vActions.begin() + i);
|
2017-10-19 12:48:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|