264 lines
6.1 KiB
C++
264 lines
6.1 KiB
C++
|
|
#include "DismissScene.h"
|
|||
|
|
#include "Define.h"
|
|||
|
|
#include "ImagicDownManager.h"
|
|||
|
|
|
|||
|
|
SINGLETON_STORAGE(DismissScene);
|
|||
|
|
|
|||
|
|
DismissScene::DismissScene()
|
|||
|
|
{
|
|||
|
|
m_isStart = false;
|
|||
|
|
|
|||
|
|
init();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DismissScene::~DismissScene()
|
|||
|
|
{
|
|||
|
|
unschedule(schedule_selector(DismissScene::OnEventGameClock));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool DismissScene::init()
|
|||
|
|
{
|
|||
|
|
if (!Node::init())
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
auto rootPanel = CSLoader::createNode("Platform/DismissScene.csb");
|
|||
|
|
CC_ASSERT(rootPanel != nullptr);
|
|||
|
|
this->addChild(rootPanel);
|
|||
|
|
|
|||
|
|
m_ImageViewBg = (ImageView*)rootPanel->getChildByName("Image_bg");
|
|||
|
|
CC_ASSERT(m_ImageViewBg);
|
|||
|
|
|
|||
|
|
m_btnClose = (Button*)m_ImageViewBg->getChildByName("btnClose");
|
|||
|
|
CC_ASSERT(m_btnClose);
|
|||
|
|
m_btnClose->addClickEventListener([this](Ref*){
|
|||
|
|
|
|||
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|||
|
|
|
|||
|
|
if (m_btnRefused->isVisible())
|
|||
|
|
{
|
|||
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|||
|
|
EventCustom event(DISMISS_ROOM_EVENT);
|
|||
|
|
__Bool* bAgree = __Bool::create(false);
|
|||
|
|
event.setUserData(bAgree);
|
|||
|
|
|
|||
|
|
//<2F>ɷ<EFBFBD><C9B7>ܾ<EFBFBD><DCBE><EFBFBD>ɢ<EFBFBD><C9A2><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>MainScene
|
|||
|
|
dispatcher->dispatchEvent(&event);
|
|||
|
|
|
|||
|
|
m_btnAgree->setEnabled(false);
|
|||
|
|
m_btnRefused->setEnabled(false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this->removeFromParent();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
//<2F><>ȡͬ<C8A1>ⰴť
|
|||
|
|
m_btnAgree = (Button*)m_ImageViewBg->getChildByName("btnAgree");
|
|||
|
|
CC_ASSERT(m_btnAgree != nullptr);
|
|||
|
|
|
|||
|
|
//<2F><>ȡ<EFBFBD>ܾ<EFBFBD><DCBE><EFBFBD>ť
|
|||
|
|
m_btnRefused = (Button*)m_ImageViewBg->getChildByName("btnRefused");
|
|||
|
|
CC_ASSERT(m_btnRefused != nullptr);
|
|||
|
|
|
|||
|
|
m_ALNumber = (Text*)m_ImageViewBg->getChildByName("txtTimer");
|
|||
|
|
CC_ASSERT(m_ALNumber != nullptr);
|
|||
|
|
|
|||
|
|
//ע<><D7A2>ͬ<EFBFBD>ⰴť<E2B0B4>¼<EFBFBD>
|
|||
|
|
m_btnAgree->addClickEventListener([this](Ref*){
|
|||
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|||
|
|
|
|||
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|||
|
|
EventCustom event(DISMISS_ROOM_EVENT);
|
|||
|
|
__Bool* bAgree = __Bool::create(true);
|
|||
|
|
event.setUserData(bAgree);
|
|||
|
|
|
|||
|
|
//<2F>ɷ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>ɢ<EFBFBD><C9A2><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>MainScene
|
|||
|
|
dispatcher->dispatchEvent(&event);
|
|||
|
|
|
|||
|
|
m_btnAgree->setEnabled(false);
|
|||
|
|
m_btnRefused->setEnabled(false);
|
|||
|
|
//this->removeFromParent();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
//ע<><D7A2><EFBFBD>ܾ<EFBFBD><DCBE><EFBFBD>ť<EFBFBD>¼<EFBFBD>
|
|||
|
|
m_btnRefused->addClickEventListener([this](Ref*){
|
|||
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|||
|
|
|
|||
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|||
|
|
EventCustom event(DISMISS_ROOM_EVENT);
|
|||
|
|
__Bool* bAgree = __Bool::create(false);
|
|||
|
|
event.setUserData(bAgree);
|
|||
|
|
|
|||
|
|
//<2F>ɷ<EFBFBD><C9B7>ܾ<EFBFBD><DCBE><EFBFBD>ɢ<EFBFBD><C9A2><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>MainScene
|
|||
|
|
dispatcher->dispatchEvent(&event);
|
|||
|
|
|
|||
|
|
m_btnAgree->setEnabled(false);
|
|||
|
|
m_btnRefused->setEnabled(false);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
m_PanelList = (Layout*)m_ImageViewBg->getChildByName("PanelList");
|
|||
|
|
CC_ASSERT(m_PanelList != nullptr);
|
|||
|
|
|
|||
|
|
//<2F><>ȡ<EFBFBD>ı<EFBFBD>
|
|||
|
|
for (int i = 0; i < TABLE_PLAYER_COUNT; i++)
|
|||
|
|
{
|
|||
|
|
std::string strKey = StringUtils::format("player_%d", i);
|
|||
|
|
m_aryUserInfo[i] = (Layout*)m_PanelList->getChildByName(strKey);
|
|||
|
|
if (m_aryUserInfo[i])
|
|||
|
|
{
|
|||
|
|
m_aryUserInfo[i]->setVisible(false);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DismissScene::show(BYTE aryResult[], GamePlayer* players[TABLE_PLAYER_COUNT], bool bBtnsVisiable, BYTE cbCount)
|
|||
|
|
{
|
|||
|
|
if (getParent() == nullptr)
|
|||
|
|
{
|
|||
|
|
Scene* pScene = Director::getInstance()->getRunningScene();
|
|||
|
|
pScene->addChild(this);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int iUserCount = 0; // <20><><EFBFBD>Ҹ<EFBFBD><D2B8><EFBFBD>;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
|||
|
|
for (int i = 0; i < cbCount; i++)
|
|||
|
|
{
|
|||
|
|
if (m_aryUserInfo[i] == nullptr) continue;
|
|||
|
|
|
|||
|
|
// ͷ<><CDB7>
|
|||
|
|
GamePlayer* pPlayer = players[i];
|
|||
|
|
if (pPlayer == nullptr) continue;
|
|||
|
|
|
|||
|
|
auto txtResult = (Text*)m_aryUserInfo[i]->getChildByName("txtResult");
|
|||
|
|
if (txtResult != nullptr)
|
|||
|
|
{
|
|||
|
|
if (aryResult[i] == 0)
|
|||
|
|
{
|
|||
|
|
txtResult->setTextColor(Color4B(0x1F, 0x88, 0x8A, 0xff));
|
|||
|
|
txtResult->setString(utility::a_u8("<EFBFBD>ȴ<EFBFBD>ѡ<EFBFBD><EFBFBD>"));
|
|||
|
|
}
|
|||
|
|
else if (aryResult[i] == 1)
|
|||
|
|
{
|
|||
|
|
txtResult->setTextColor(Color4B(0x6A, 0xB1, 0x30, 0xff));
|
|||
|
|
txtResult->setString(utility::a_u8("ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɢ"));
|
|||
|
|
}
|
|||
|
|
else if (aryResult[i] == 2)
|
|||
|
|
{
|
|||
|
|
txtResult->setTextColor(Color4B(0xff, 0x60, 0x60, 0xff));
|
|||
|
|
txtResult->setString(utility::a_u8("<EFBFBD>ܾ<EFBFBD><EFBFBD><EFBFBD>ɢ"));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
auto sphead = (Sprite*)m_aryUserInfo[i]->getChildByName("head");
|
|||
|
|
if (sphead)
|
|||
|
|
{
|
|||
|
|
ImagicDownManager::Instance().addDown(sphead, pPlayer->GetHeadHttp(), pPlayer->GetUserID());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_aryUserInfo[i]->setVisible(true);
|
|||
|
|
|
|||
|
|
iUserCount++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>;
|
|||
|
|
if (iUserCount > 0)
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
|
float fPlanelWidth = m_PanelList->getContentSize().width;
|
|||
|
|
// <20>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
|
float fItemWidth = m_aryUserInfo[0]->getContentSize().width;
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>*<2A>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>+1<><31>;
|
|||
|
|
float fIntervalWidth = (fPlanelWidth - fItemWidth*iUserCount) / (iUserCount + 1);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>;
|
|||
|
|
for (int i = 0; i < iUserCount; i++)
|
|||
|
|
{
|
|||
|
|
if (m_aryUserInfo[i])
|
|||
|
|
{
|
|||
|
|
m_aryUserInfo[i]->setPositionX(fIntervalWidth + (fItemWidth + fIntervalWidth)*i);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!bBtnsVisiable)
|
|||
|
|
{
|
|||
|
|
m_btnAgree->setEnabled(false);
|
|||
|
|
m_btnRefused->setEnabled(false);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
m_btnAgree->setEnabled(true);
|
|||
|
|
m_btnRefused->setEnabled(true);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!m_isStart)
|
|||
|
|
{
|
|||
|
|
m_isStart = true;
|
|||
|
|
m_nSecondCount = 300;
|
|||
|
|
m_ALNumber->setString(StringUtils::format("%d", m_nSecondCount));
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
schedule(schedule_selector(DismissScene::OnEventGameClock), 1.0f);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DismissScene::hide()
|
|||
|
|
{
|
|||
|
|
//for (int i = 0; i < TABLE_PLAYER_COUNT; i++)
|
|||
|
|
//{
|
|||
|
|
// m_aryResult[i]->setString("");
|
|||
|
|
// m_aryHead[i]->setVisible(false);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
for (int i = 0; i < TABLE_PLAYER_COUNT; i++)
|
|||
|
|
{
|
|||
|
|
if (m_aryUserInfo[i])
|
|||
|
|
{
|
|||
|
|
m_aryUserInfo[i]->setVisible(false);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_btnAgree->setEnabled(true);
|
|||
|
|
m_btnRefused->setEnabled(true);
|
|||
|
|
|
|||
|
|
unschedule(schedule_selector(DismissScene::OnEventGameClock));
|
|||
|
|
|
|||
|
|
this->removeFromParent();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>Ϸ<EFBFBD><CFB7>ʱ<EFBFBD><CAB1>
|
|||
|
|
void DismissScene::OnEventGameClock(float dt)
|
|||
|
|
{
|
|||
|
|
if (m_nSecondCount <= 0)
|
|||
|
|
{
|
|||
|
|
unschedule(schedule_selector(DismissScene::OnEventGameClock));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_nSecondCount--;
|
|||
|
|
m_ALNumber->setString(StringUtils::format("%d", m_nSecondCount));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DismissScene::pushScene()
|
|||
|
|
{
|
|||
|
|
if (m_ImageViewBg)
|
|||
|
|
{
|
|||
|
|
this->setVisible(true);
|
|||
|
|
m_ImageViewBg->setScale(0.8f);
|
|||
|
|
m_ImageViewBg->runAction(Sequence::create(ScaleTo::create(0.2f, 1.2f), ScaleTo::create(0.1f, 1.f), nullptr));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DismissScene::popScene()
|
|||
|
|
{
|
|||
|
|
if (m_ImageViewBg)
|
|||
|
|
{
|
|||
|
|
m_ImageViewBg->runAction(Sequence::create(Hide::create(), ScaleTo::create(0.1f, 0.1f), CallFunc::create([&]()
|
|||
|
|
{
|
|||
|
|
this->removeFromParentAndCleanup(true);
|
|||
|
|
}), nullptr));
|
|||
|
|
}
|
|||
|
|
}
|