Magic_Game/core/Manager/ActionManager.cpp

154 lines
2.8 KiB
C++
Raw Normal View History

#include "..\emanagers.h"
#include "..\eactions.h"
2017-10-19 00:50:04 +08:00
static std::vector<e2d::Action*> s_vActions;
2017-10-19 00:50:04 +08:00
void e2d::ActionManager::_add(Action * pAction, Node * pTargetNode)
2017-10-19 00:50:04 +08:00
{
WARN_IF(pAction == nullptr, "Action NULL pointer exception!");
2018-02-06 15:34:47 +08:00
if (pAction)
{
2018-02-06 15:34:47 +08:00
pAction->startWith(pTargetNode);
pAction->retain();
s_vActions.push_back(pAction);
}
2017-10-19 00:50:04 +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)
{
2018-02-03 22:04:43 +08:00
for (auto action : s_vActions)
{
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
}
}
2018-02-03 22:04:43 +08:00
for (auto child : pTargetNode->getChildren())
{
ActionManager::resumeAllActionsBindedWith(child);
}
}
2017-10-19 00:50:04 +08:00
}
void e2d::ActionManager::pauseAllActionsBindedWith(Node * pTargetNode)
2017-10-19 00:50:04 +08:00
{
if (pTargetNode)
{
2018-02-03 22:04:43 +08:00
for (auto action : s_vActions)
{
2018-02-03 22:04:43 +08:00
if (action->getTarget() == pTargetNode)
{
2018-02-03 22:04:43 +08:00
action->pause();
}
}
2018-02-03 22:04:43 +08:00
for (auto child : pTargetNode->getChildren())
{
ActionManager::pauseAllActionsBindedWith(child);
}
}
2017-10-19 00:50:04 +08:00
}
void e2d::ActionManager::stopAllActionsBindedWith(Node * pTargetNode)
2017-10-19 00:50:04 +08:00
{
if (pTargetNode)
{
2018-02-03 22:04:43 +08:00
for (auto action : s_vActions)
{
2018-02-03 22:04:43 +08:00
if (action->getTarget() == pTargetNode)
{
2018-02-03 22:04:43 +08:00
action->stop();
}
}
2018-02-03 22:04:43 +08:00
for (auto child : pTargetNode->getChildren())
{
ActionManager::stopAllActionsBindedWith(child);
}
}
2017-10-19 00:50:04 +08:00
}
void e2d::ActionManager::__clearAllActionsBindedWith(Node * pTargetNode)
2017-10-19 00:50:04 +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);
s_vActions.erase(s_vActions.begin() + i);
}
else
{
i++;
}
}
}
2017-10-19 00:50:04 +08:00
}
void e2d::ActionManager::resumeAllActions()
2017-10-19 00:50:04 +08:00
{
for (auto child : SceneManager::getCurrentScene()->getRoot()->getChildren())
2017-10-21 19:09:31 +08:00
{
ActionManager::resumeAllActionsBindedWith(child);
2017-10-21 19:09:31 +08:00
}
2017-10-19 00:50:04 +08:00
}
void e2d::ActionManager::pauseAllActions()
2017-10-19 00:50:04 +08:00
{
for (auto child : SceneManager::getCurrentScene()->getRoot()->getChildren())
2017-10-21 19:09:31 +08:00
{
ActionManager::pauseAllActionsBindedWith(child);
2017-10-21 19:09:31 +08:00
}
2017-10-19 00:50:04 +08:00
}
void e2d::ActionManager::stopAllActions()
2017-10-19 00:50:04 +08:00
{
for (auto child : SceneManager::getCurrentScene()->getRoot()->getChildren())
2017-10-21 19:09:31 +08:00
{
ActionManager::stopAllActionsBindedWith(child);
2017-10-21 19:09:31 +08:00
}
2017-10-19 00:50:04 +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)
{
2018-02-03 22:04:43 +08:00
action->_resetTime();
}
2017-10-19 00:50:04 +08:00
}
void e2d::ActionManager::__update()
2017-10-19 00:50:04 +08:00
{
if (s_vActions.empty() || Game::isPaused())
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++)
{
2018-02-06 21:11:54 +08:00
auto &action = s_vActions[i];
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
2018-02-06 15:34:47 +08:00
if (action->isRunning() &&
action->getTarget() &&
action->getTarget()->getParentScene() == SceneManager::getCurrentScene())
{
2018-02-06 21:11:54 +08:00
if (!action->_isEnding())
{
2018-02-06 21:11:54 +08:00
// ִ<>ж<EFBFBD><D0B6><EFBFBD>
action->_update();
}
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 00:50:04 +08:00
}