168 lines
3.4 KiB
C++
168 lines
3.4 KiB
C++
|
|
#include "PopScene.h"
|
|||
|
|
|
|||
|
|
SINGLETON_STORAGE(PopScene);
|
|||
|
|
|
|||
|
|
PopScene::PopScene():m_fnOKHander(nullptr), m_fnCancelHander(nullptr)
|
|||
|
|
{
|
|||
|
|
m_ImgBg = nullptr;
|
|||
|
|
|
|||
|
|
init();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
PopScene::~PopScene()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool PopScene::init()
|
|||
|
|
{
|
|||
|
|
if (!Node::init())
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
auto rootPanel = CSLoader::createNode("Platform/PopScene.csb");
|
|||
|
|
CC_ASSERT(rootPanel != nullptr);
|
|||
|
|
this->addChild(rootPanel);
|
|||
|
|
|
|||
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
|
|||
|
|
m_ImgBg = (ImageView*)rootPanel->getChildByName("imgBg");
|
|||
|
|
CC_ASSERT(m_ImgBg != nullptr);
|
|||
|
|
m_fWndWidth = m_ImgBg->getContentSize().width;
|
|||
|
|
|
|||
|
|
////<2F><>ȡ<EFBFBD>رհ<D8B1>ť
|
|||
|
|
//auto btnClose = (Button*)pImgBg->getChildByName("btnClose");
|
|||
|
|
//CC_ASSERT(btnClose != nullptr);
|
|||
|
|
//
|
|||
|
|
////ע<><D7A2><EFBFBD>رհ<D8B1>ť<EFBFBD>¼<EFBFBD>
|
|||
|
|
//btnClose->addClickEventListener([this](Ref*){
|
|||
|
|
// YSAudioEngine::Instance().playBtnClickEffect();
|
|||
|
|
// this->removeFromParent();
|
|||
|
|
//});
|
|||
|
|
|
|||
|
|
//<2F><>ȡȷ<C8A1><C8B7><EFBFBD><EFBFBD>ť
|
|||
|
|
m_btnOK = (Button*)m_ImgBg->getChildByName("btnOK");
|
|||
|
|
CC_ASSERT(m_btnOK != nullptr);
|
|||
|
|
|
|||
|
|
//ע<><D7A2>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>ť<EFBFBD>¼<EFBFBD>
|
|||
|
|
m_btnOK->addClickEventListener(CC_CALLBACK_1(PopScene::onClickOK, this));
|
|||
|
|
|
|||
|
|
//<2F><>ȡȡ<C8A1><C8A1><EFBFBD><EFBFBD>ť
|
|||
|
|
m_btnCancel = (Button*)m_ImgBg->getChildByName("btnCancel");
|
|||
|
|
CC_ASSERT(m_btnCancel != nullptr);
|
|||
|
|
|
|||
|
|
//ע<><D7A2>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ť<EFBFBD>¼<EFBFBD>
|
|||
|
|
m_btnCancel->addClickEventListener(CC_CALLBACK_1(PopScene::onClickCancel, this));
|
|||
|
|
|
|||
|
|
//<2F><>ȡȡ<C8A1><C8A1><EFBFBD><EFBFBD>ť
|
|||
|
|
m_txtContent = (Text*)m_ImgBg->getChildByName("txtContent");
|
|||
|
|
CC_ASSERT(m_txtContent != nullptr);
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PopScene::onEnter()
|
|||
|
|
{
|
|||
|
|
Node::onEnter();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PopScene::onEnterTransitionDidFinish()
|
|||
|
|
{
|
|||
|
|
Node::onEnterTransitionDidFinish();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PopScene::onExit()
|
|||
|
|
{
|
|||
|
|
Node::onExit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PopScene::show(std::string strContent, const std::function<void()>& fnOKHander)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD>볡<EFBFBD><EBB3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뵱ǰ<EBB5B1><C7B0><EFBFBD>г<EFBFBD><D0B3><EFBFBD>;
|
|||
|
|
if (getParent() == nullptr)
|
|||
|
|
{
|
|||
|
|
Scene* pScene = Director::getInstance()->getRunningScene();
|
|||
|
|
pScene->addChild(this, 999);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
cocos2d::log("%s", strContent.c_str());
|
|||
|
|
|
|||
|
|
m_txtContent->setString(strContent);
|
|||
|
|
|
|||
|
|
m_fnOKHander = fnOKHander;
|
|||
|
|
m_fnCancelHander = nullptr;
|
|||
|
|
|
|||
|
|
m_btnCancel->setVisible(false);
|
|||
|
|
m_btnOK->setVisible(true);
|
|||
|
|
|
|||
|
|
float fButnWidth = m_btnOK->getContentSize().width;
|
|||
|
|
m_btnOK->setPositionX((m_fWndWidth - fButnWidth) / 2.f);
|
|||
|
|
|
|||
|
|
this->pushScene();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PopScene::show(std::string strContent, const std::function<void()>& fnOKHander, const std::function<void()>& fnCancelHander)
|
|||
|
|
{
|
|||
|
|
if (getParent() == nullptr)
|
|||
|
|
{
|
|||
|
|
Scene* pScene = Director::getInstance()->getRunningScene();
|
|||
|
|
pScene->addChild(this, 999);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_txtContent->setString(strContent);
|
|||
|
|
|
|||
|
|
m_fnOKHander = fnOKHander;
|
|||
|
|
m_fnCancelHander = fnCancelHander;
|
|||
|
|
|
|||
|
|
m_btnCancel->setVisible(true);
|
|||
|
|
m_btnOK->setVisible(true);
|
|||
|
|
|
|||
|
|
float fButnWidth = m_btnOK->getContentSize().width;
|
|||
|
|
m_btnOK->setPositionX((m_fWndWidth / 2.0f - fButnWidth) / 2.0f);
|
|||
|
|
m_btnCancel->setPositionX(m_fWndWidth / 2.0f + (m_fWndWidth / 2.0f - fButnWidth) / 2.0f);
|
|||
|
|
|
|||
|
|
this->pushScene();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PopScene::onClickCancel(Ref*)
|
|||
|
|
{
|
|||
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|||
|
|
|
|||
|
|
if (m_fnCancelHander)
|
|||
|
|
{
|
|||
|
|
m_fnCancelHander();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this->removeFromParent();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PopScene::onClickOK(Ref*)
|
|||
|
|
{
|
|||
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|||
|
|
|
|||
|
|
if (m_fnOKHander)
|
|||
|
|
{
|
|||
|
|
m_fnOKHander();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this->removeFromParent();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PopScene::pushScene()
|
|||
|
|
{
|
|||
|
|
if (m_ImgBg)
|
|||
|
|
{
|
|||
|
|
m_ImgBg->setScale(0.8f);
|
|||
|
|
m_ImgBg->runAction(Sequence::create(ScaleTo::create(0.2f, 1.2f), ScaleTo::create(0.1f, 1.f), nullptr));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PopScene::popScene()
|
|||
|
|
{
|
|||
|
|
if (m_ImgBg)
|
|||
|
|
{
|
|||
|
|
m_ImgBg->runAction(Sequence::create(Hide::create(), ScaleTo::create(0.1f, 0.1f), CallFunc::create([&]()
|
|||
|
|
{
|
|||
|
|
this->removeFromParent();
|
|||
|
|
}), nullptr));
|
|||
|
|
}
|
|||
|
|
}
|