init
This commit is contained in:
260
Classes/Scenes/AutoReadyScene.cpp
Normal file
260
Classes/Scenes/AutoReadyScene.cpp
Normal file
@@ -0,0 +1,260 @@
|
||||
#include "AutoReadyScene.h"
|
||||
#include "Define.h"
|
||||
#include "ImagicDownManager.h"
|
||||
|
||||
SINGLETON_STORAGE(AutoReadyScene);
|
||||
|
||||
AutoReadyScene::AutoReadyScene()
|
||||
{
|
||||
m_isStart = false;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
AutoReadyScene::~AutoReadyScene()
|
||||
{
|
||||
//unschedule(schedule_selector(AutoReadyScene::OnEventGameClock));
|
||||
}
|
||||
|
||||
bool AutoReadyScene::init()
|
||||
{
|
||||
if (!Node::init())
|
||||
{
|
||||
return false;
|
||||
};
|
||||
|
||||
auto rootPanel = CSLoader::createNode("Platform/StartGame.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_txtStartPlayer = (Text*)m_ImageViewBg->getChildByName("txtStartPlayer");
|
||||
CC_ASSERT(m_txtStartPlayer != nullptr);
|
||||
m_txtStartPlayer->setText("");
|
||||
|
||||
//注册同意按钮事件
|
||||
m_btnAgree->addClickEventListener([this](Ref*){
|
||||
YSAudioEngine::Instance().playBtnClickEffect();
|
||||
|
||||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||||
EventCustom event(AUTO_USER_READY_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(AUTO_USER_READY_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 AutoReadyScene::show(CMD_GR_Private_ReadyInfo* pNetInfo, GamePlayer* players[], bool bBtnsVisiable, uint8 cbPlayCount)
|
||||
{
|
||||
if (getParent() == nullptr)
|
||||
{
|
||||
Scene* pScene = Director::getInstance()->getRunningScene();
|
||||
pScene->addChild(this);
|
||||
}
|
||||
|
||||
GamePlayer* pfirst = players[pNetInfo->wChairID];
|
||||
if (pfirst != nullptr)
|
||||
{
|
||||
m_txtStartPlayer->setString(pfirst->GetNickName(true));
|
||||
}
|
||||
|
||||
int iUserCount = 0; // 玩家个数;
|
||||
bool bRefused = false;
|
||||
|
||||
//设置文本
|
||||
for (int i = 0; i < cbPlayCount; i++)
|
||||
{
|
||||
// 头像
|
||||
GamePlayer* pPlayer = players[i];
|
||||
if (pPlayer == nullptr) continue;
|
||||
|
||||
if (m_aryUserInfo[iUserCount] == nullptr) continue;
|
||||
auto txtResult = (Text*)m_aryUserInfo[iUserCount]->getChildByName("txtResult");
|
||||
if (txtResult != nullptr)
|
||||
{
|
||||
if (pNetInfo->cbReady[i] == 0)
|
||||
{
|
||||
txtResult->setTextColor(Color4B(0x1F, 0x88, 0x8A, 0xff));
|
||||
txtResult->setString(utility::a_u8("等待"));
|
||||
}
|
||||
else if (pNetInfo->cbReady[i] == 1)
|
||||
{
|
||||
txtResult->setTextColor(Color4B(0x6A, 0xB1, 0x30, 0xff));
|
||||
txtResult->setString(utility::a_u8("同意"));
|
||||
}
|
||||
else if (pNetInfo->cbReady[i] == 2)
|
||||
{
|
||||
txtResult->setTextColor(Color4B(0xff, 0x60, 0x60, 0xff));
|
||||
txtResult->setString(utility::a_u8("拒绝"));
|
||||
|
||||
bRefused = true;
|
||||
}
|
||||
}
|
||||
|
||||
auto sphead = (Sprite*)m_aryUserInfo[iUserCount]->getChildByName("head");
|
||||
if (sphead)
|
||||
{
|
||||
ImagicDownManager::Instance().addDown(sphead, pPlayer->GetHeadHttp(), pPlayer->GetUserID());
|
||||
}
|
||||
|
||||
m_aryUserInfo[iUserCount]->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_btnAgree->setEnabled(bBtnsVisiable);
|
||||
m_btnRefused->setEnabled(bBtnsVisiable);
|
||||
|
||||
if (bRefused)
|
||||
{
|
||||
m_ImageViewBg->runAction(Sequence::create(DelayTime::create(5.0f), CallFunc::create([&]()
|
||||
{
|
||||
hide();
|
||||
}), nullptr));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AutoReadyScene::hide()
|
||||
{
|
||||
if (!this->isVisible()) return;
|
||||
|
||||
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(AutoReadyScene::OnEventGameClock));
|
||||
|
||||
this->removeFromParent();
|
||||
}
|
||||
|
||||
//// 游戏定时器
|
||||
//void AutoReadyScene::OnEventGameClock(float dt)
|
||||
//{
|
||||
// if (m_nSecondCount <= 0)
|
||||
// {
|
||||
// unschedule(schedule_selector(AutoReadyScene::OnEventGameClock));
|
||||
// }
|
||||
//
|
||||
// m_nSecondCount--;
|
||||
// m_ALNumber->setString(StringUtils::format("%d", m_nSecondCount));
|
||||
//}
|
||||
|
||||
void AutoReadyScene::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 AutoReadyScene::popScene()
|
||||
{
|
||||
if (m_ImageViewBg)
|
||||
{
|
||||
m_ImageViewBg->runAction(Sequence::create(Hide::create(), ScaleTo::create(0.1f, 0.1f), CallFunc::create([&]()
|
||||
{
|
||||
this->removeFromParentAndCleanup(true);
|
||||
}), nullptr));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user