2017-10-12 23:34:13 +08:00
|
|
|
|
#include "..\ebase.h"
|
|
|
|
|
|
#include "..\enodes.h"
|
2017-10-14 01:07:34 +08:00
|
|
|
|
#include "..\emsg.h"
|
2017-10-14 18:43:32 +08:00
|
|
|
|
#include <algorithm>
|
2017-09-10 23:56:52 +08:00
|
|
|
|
|
2017-10-14 18:43:32 +08:00
|
|
|
|
e2d::EScene::EScene()
|
|
|
|
|
|
: m_bWillSave(true)
|
|
|
|
|
|
, m_bSortNeeded(false)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2017-09-10 23:56:52 +08:00
|
|
|
|
|
2017-10-12 23:34:13 +08:00
|
|
|
|
e2d::EScene::~EScene()
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
clearAllChildren();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-14 18:43:32 +08:00
|
|
|
|
void e2d::EScene::_onRender()
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-10-14 18:43:32 +08:00
|
|
|
|
this->_sortChildren();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>нڵ<D0BD>
|
|
|
|
|
|
for (auto child : m_vChildren)
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-10-14 18:43:32 +08:00
|
|
|
|
child->callOn();
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
2017-09-10 23:56:52 +08:00
|
|
|
|
|
2017-10-14 18:43:32 +08:00
|
|
|
|
void e2d::EScene::_sortChildren()
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-10-14 18:43:32 +08:00
|
|
|
|
if (m_bSortNeeded)
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-10-14 18:43:32 +08:00
|
|
|
|
m_bSortNeeded = false;
|
|
|
|
|
|
|
|
|
|
|
|
// <20>ӽڵ<D3BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
std::sort(
|
|
|
|
|
|
std::begin(m_vChildren),
|
|
|
|
|
|
std::end(m_vChildren),
|
|
|
|
|
|
[](ENode * n1, ENode * n2) {
|
|
|
|
|
|
return n1->getOrder() < n2->getOrder();
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:34:13 +08:00
|
|
|
|
void e2d::EScene::onEnter()
|
2017-09-18 23:59:08 +08:00
|
|
|
|
{
|
2017-10-14 18:43:32 +08:00
|
|
|
|
// <20><><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>ж<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
|
|
|
|
|
//Timer::notifyAllSceneTimers(m_pNextScene);
|
|
|
|
|
|
EMsgManager::notifyAllListenersBindWithScene(this);
|
|
|
|
|
|
//ActionManager::notifyAllSceneActions(m_pNextScene);
|
2017-09-18 23:59:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:34:13 +08:00
|
|
|
|
void e2d::EScene::onExit()
|
2017-09-18 23:59:08 +08:00
|
|
|
|
{
|
2017-10-14 18:43:32 +08:00
|
|
|
|
if (m_bWillSave)
|
|
|
|
|
|
{
|
|
|
|
|
|
//Timer::waitAllSceneTimers(m_pCurrentScene);
|
|
|
|
|
|
EMsgManager::waitAllListenersBindWithScene(this);
|
|
|
|
|
|
//ActionManager::waitAllSceneActions(m_pCurrentScene);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//Timer::clearAllSceneTimers(m_pCurrentScene);
|
|
|
|
|
|
EMsgManager::clearAllListenersBindWithScene(this);
|
|
|
|
|
|
//ActionManager::stopAllSceneActions(m_pCurrentScene);
|
|
|
|
|
|
}
|
2017-09-18 23:59:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-14 18:43:32 +08:00
|
|
|
|
void e2d::EScene::add(ENode * child, int order /* = 0 */)
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-10-14 01:07:34 +08:00
|
|
|
|
ASSERT(child != nullptr, "Scene::add NULL pointer exception.");
|
2017-10-14 18:43:32 +08:00
|
|
|
|
ASSERT(child->getParentScene() == nullptr, "Child already added. It can't be added again!");
|
|
|
|
|
|
|
|
|
|
|
|
if (child)
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-10-14 18:43:32 +08:00
|
|
|
|
child->setParentScene(this);
|
|
|
|
|
|
|
|
|
|
|
|
child->setOrder(order);
|
|
|
|
|
|
|
|
|
|
|
|
child->retain();
|
|
|
|
|
|
|
|
|
|
|
|
m_vChildren.push_back(child);
|
|
|
|
|
|
|
|
|
|
|
|
m_bSortNeeded = true;
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-14 18:43:32 +08:00
|
|
|
|
bool e2d::EScene::remove(ENode * child, bool autoRelease /* = true */)
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-09-27 17:56:28 +08:00
|
|
|
|
if (child == nullptr) return false;
|
2017-09-10 23:56:52 +08:00
|
|
|
|
|
|
|
|
|
|
// Ѱ<><D1B0><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD>ڵ<EFBFBD>
|
2017-10-12 23:34:13 +08:00
|
|
|
|
std::vector<ENode*>::iterator iter;
|
2017-09-10 23:56:52 +08:00
|
|
|
|
for (iter = m_vChildren.begin(); iter != m_vChildren.end(); iter++)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20>ҵ<EFBFBD><D2B5><EFBFBD>ͬ<EFBFBD>ڵ<EFBFBD>
|
|
|
|
|
|
if (*iter == child)
|
|
|
|
|
|
{
|
2017-10-14 18:43:32 +08:00
|
|
|
|
if (autoRelease)
|
|
|
|
|
|
(*iter)->autoRelease();
|
2017-09-10 23:56:52 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>һ
|
|
|
|
|
|
(*iter)->release();
|
|
|
|
|
|
// ȥ<><C8A5><EFBFBD>ýڵ<C3BD>
|
|
|
|
|
|
m_vChildren.erase(iter);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// δ<>ҵ<EFBFBD><D2B5>ýڵ㷵<DAB5><E3B7B5> false
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:34:13 +08:00
|
|
|
|
std::vector<e2d::ENode*>& e2d::EScene::getChildren()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_vChildren;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-14 18:43:32 +08:00
|
|
|
|
size_t e2d::EScene::getChildrenCount() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_vChildren.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e2d::ENode * e2d::EScene::getChild(EString childName) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return ENode::getChild(childName, m_vChildren);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:34:13 +08:00
|
|
|
|
void e2d::EScene::clearAllChildren()
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD>нڵ<D0BD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>һ
|
|
|
|
|
|
for (auto child : m_vChildren)
|
|
|
|
|
|
{
|
2017-10-05 01:14:45 +08:00
|
|
|
|
child->autoRelease();
|
2017-09-10 23:56:52 +08:00
|
|
|
|
child->release();
|
|
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
m_vChildren.clear();
|
2017-10-14 01:07:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EScene::bindListener(EMouseListener * listener)
|
|
|
|
|
|
{
|
2017-10-14 10:02:15 +08:00
|
|
|
|
EMsgManager::bindListenerWith(listener, this);
|
2017-10-14 01:07:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EScene::bindListener(EKeyboardListener * listener)
|
|
|
|
|
|
{
|
2017-10-14 10:02:15 +08:00
|
|
|
|
EMsgManager::bindListenerWith(listener, this);
|
2017-10-14 01:07:34 +08:00
|
|
|
|
}
|