260 lines
6.2 KiB
C++
260 lines
6.2 KiB
C++
|
|
#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);
|
|||
|
|
|
|||
|
|
// //<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_txtStartPlayer = (Text*)m_ImageViewBg->getChildByName("txtStartPlayer");
|
|||
|
|
CC_ASSERT(m_txtStartPlayer != nullptr);
|
|||
|
|
m_txtStartPlayer->setText("");
|
|||
|
|
|
|||
|
|
//ע<><D7A2>ͬ<EFBFBD>ⰴť<E2B0B4>¼<EFBFBD>
|
|||
|
|
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);
|
|||
|
|
|
|||
|
|
//<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(AUTO_USER_READY_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 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; // <20><><EFBFBD>Ҹ<EFBFBD><D2B8><EFBFBD>;
|
|||
|
|
bool bRefused = false;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
|||
|
|
for (int i = 0; i < cbPlayCount; i++)
|
|||
|
|
{
|
|||
|
|
// ͷ<><CDB7>
|
|||
|
|
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("<EFBFBD>ȴ<EFBFBD>"));
|
|||
|
|
}
|
|||
|
|
else if (pNetInfo->cbReady[i] == 1)
|
|||
|
|
{
|
|||
|
|
txtResult->setTextColor(Color4B(0x6A, 0xB1, 0x30, 0xff));
|
|||
|
|
txtResult->setString(utility::a_u8("ͬ<EFBFBD><EFBFBD>"));
|
|||
|
|
}
|
|||
|
|
else if (pNetInfo->cbReady[i] == 2)
|
|||
|
|
{
|
|||
|
|
txtResult->setTextColor(Color4B(0xff, 0x60, 0x60, 0xff));
|
|||
|
|
txtResult->setString(utility::a_u8("<EFBFBD>ܾ<EFBFBD>"));
|
|||
|
|
|
|||
|
|
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++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <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);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//// <20><>Ϸ<EFBFBD><CFB7>ʱ<EFBFBD><CAB1>
|
|||
|
|
//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));
|
|||
|
|
}
|
|||
|
|
}
|