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);
|
||
|
||
//派发拒绝解散房间事件至MainScene
|
||
dispatcher->dispatchEvent(&event);
|
||
|
||
m_btnAgree->setEnabled(false);
|
||
m_btnRefused->setEnabled(false);
|
||
}
|
||
|
||
this->removeFromParent();
|
||
});
|
||
|
||
//获取同意按钮
|
||
m_btnAgree = (Button*)m_ImageViewBg->getChildByName("btnAgree");
|
||
CC_ASSERT(m_btnAgree != nullptr);
|
||
|
||
//获取拒绝按钮
|
||
m_btnRefused = (Button*)m_ImageViewBg->getChildByName("btnRefused");
|
||
CC_ASSERT(m_btnRefused != nullptr);
|
||
|
||
m_ALNumber = (Text*)m_ImageViewBg->getChildByName("txtTimer");
|
||
CC_ASSERT(m_ALNumber != nullptr);
|
||
|
||
//注册同意按钮事件
|
||
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);
|
||
|
||
//派发同意解散房间事件至MainScene
|
||
dispatcher->dispatchEvent(&event);
|
||
|
||
m_btnAgree->setEnabled(false);
|
||
m_btnRefused->setEnabled(false);
|
||
//this->removeFromParent();
|
||
});
|
||
|
||
//注册拒绝按钮事件
|
||
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);
|
||
|
||
//派发拒绝解散房间事件至MainScene
|
||
dispatcher->dispatchEvent(&event);
|
||
|
||
m_btnAgree->setEnabled(false);
|
||
m_btnRefused->setEnabled(false);
|
||
});
|
||
|
||
m_PanelList = (Layout*)m_ImageViewBg->getChildByName("PanelList");
|
||
CC_ASSERT(m_PanelList != nullptr);
|
||
|
||
//获取文本
|
||
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; // 玩家个数;
|
||
|
||
//设置文本
|
||
for (int i = 0; i < cbCount; i++)
|
||
{
|
||
if (m_aryUserInfo[i] == nullptr) continue;
|
||
|
||
// 头像
|
||
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("等待选择"));
|
||
}
|
||
else if (aryResult[i] == 1)
|
||
{
|
||
txtResult->setTextColor(Color4B(0x6A, 0xB1, 0x30, 0xff));
|
||
txtResult->setString(utility::a_u8("同意解散"));
|
||
}
|
||
else if (aryResult[i] == 2)
|
||
{
|
||
txtResult->setTextColor(Color4B(0xff, 0x60, 0x60, 0xff));
|
||
txtResult->setString(utility::a_u8("拒绝解散"));
|
||
}
|
||
}
|
||
|
||
auto sphead = (Sprite*)m_aryUserInfo[i]->getChildByName("head");
|
||
if (sphead)
|
||
{
|
||
ImagicDownManager::Instance().addDown(sphead, pPlayer->GetHeadHttp(), pPlayer->GetUserID());
|
||
}
|
||
|
||
m_aryUserInfo[i]->setVisible(true);
|
||
|
||
iUserCount++;
|
||
}
|
||
|
||
// 调玩家位置;
|
||
if (iUserCount > 0)
|
||
{
|
||
// 容器宽度;
|
||
float fPlanelWidth = m_PanelList->getContentSize().width;
|
||
// 节点宽度;
|
||
float fItemWidth = m_aryUserInfo[0]->getContentSize().width;
|
||
// 间隔宽度 = (容器宽度 - 节点宽度*节点个数)/(节点个数+1);
|
||
float fIntervalWidth = (fPlanelWidth - fItemWidth*iUserCount) / (iUserCount + 1);
|
||
|
||
// 重置位置;
|
||
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));
|
||
|
||
// 启动定时器
|
||
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();
|
||
}
|
||
|
||
// 游戏定时器
|
||
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));
|
||
}
|
||
} |