361 lines
9.7 KiB
C++
361 lines
9.7 KiB
C++
#include "PDK_GameEndNode.h"
|
|
#include "Define.h"
|
|
#include "PDK_CMD.h"
|
|
#include "ActionEx.h"
|
|
#include "PDK_SmallCardSprite.h"
|
|
#include "SelectShareScene.h"
|
|
|
|
PDKGameEndNode::PDKGameEndNode()
|
|
{
|
|
//init();
|
|
}
|
|
|
|
PDKGameEndNode::~PDKGameEndNode()
|
|
{
|
|
|
|
}
|
|
|
|
bool PDKGameEndNode::init()
|
|
{
|
|
if (!Node::init())
|
|
{
|
|
return false;
|
|
};
|
|
|
|
auto root = CSLoader::createNodeWithVisibleSize("Games/PDK/ResultLayer.csb");
|
|
CC_ASSERT(root != nullptr);
|
|
this->addChild(root);
|
|
|
|
m_rootPanel = root->getChildByName("sprResult");
|
|
CC_ASSERT(m_rootPanel != nullptr);
|
|
|
|
//查看结算信息;
|
|
m_btnPrivate = static_cast<Button*>(m_rootPanel->getChildByName("btnPrivate"));
|
|
CC_ASSERT(m_btnPrivate != nullptr);
|
|
ASSERT(m_btnPrivate);
|
|
m_btnPrivate->setVisible(false);
|
|
m_btnPrivate->addClickEventListener([=](Ref *pSender){
|
|
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(SHOW_PRIVATE_END);
|
|
this->hide();
|
|
});
|
|
|
|
//继续按钮;
|
|
m_btnContinue = static_cast<Button*>(m_rootPanel->getChildByName("btnContinue"));
|
|
CC_ASSERT(m_btnContinue != nullptr);
|
|
m_btnContinue->addClickEventListener(CC_CALLBACK_1(PDKGameEndNode::onButtonContinueClick, this));
|
|
|
|
//分享按钮;
|
|
m_btnShare = static_cast<Button*>(m_rootPanel->getChildByName("btnShare"));
|
|
CC_ASSERT(m_btnShare != nullptr);
|
|
m_btnShare->addClickEventListener([=](Ref *pSender){
|
|
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(WEIXIN_SHOW);
|
|
});
|
|
|
|
//胜利背景;
|
|
m_sprTitleWin = static_cast<Sprite*>(m_rootPanel->getChildByName("sprTitleWin"));
|
|
CC_ASSERT(m_sprTitleWin != nullptr);
|
|
|
|
////地主标志;
|
|
//m_sprLandlord = static_cast<Sprite*>(m_rootPanel->getChildByName("sprLandlord"));
|
|
//CC_ASSERT(m_sprLandlord != nullptr);
|
|
|
|
//胜利标志;
|
|
m_sprWin = static_cast<Sprite*>(m_rootPanel->getChildByName("sprWin"));
|
|
CC_ASSERT(m_sprWin != nullptr);
|
|
|
|
//春天标志;
|
|
m_sprChunTian = static_cast<Sprite*>(m_rootPanel->getChildByName("sprChunTian"));
|
|
CC_ASSERT(m_sprChunTian != nullptr);
|
|
m_sprChunTian->setVisible(false);
|
|
|
|
return true;
|
|
}
|
|
|
|
//显示;
|
|
void PDKGameEndNode::show(uint16 wLandChairID, uint16 wSelfChairID, std::string aryNickName[], PDK_CMD_S_GameConclude* pGameConclude, uint16 wTime)
|
|
{
|
|
uint8 cbCardIndex = 0;
|
|
|
|
//获取文本;
|
|
for (int i = 0; i < PDK_GAME_PLAYER; i++)
|
|
{
|
|
//获取玩家面板;
|
|
auto panelPlayer = static_cast<Layout*>(m_rootPanel->getChildByName(StringUtils::format("panelPlayer_%d", i)));
|
|
CC_ASSERT(panelPlayer != nullptr);
|
|
panelPlayer->setVisible(true);
|
|
|
|
if (!pGameConclude->bActiveStatus[i])
|
|
{
|
|
panelPlayer->setVisible(false);
|
|
continue;
|
|
}
|
|
|
|
auto txtNickName = static_cast<Text*>(panelPlayer->getChildByName("txtNickName"));
|
|
CC_ASSERT(txtNickName != nullptr);
|
|
|
|
txtNickName->setString(aryNickName[i]);
|
|
|
|
// 地主;
|
|
auto splandlord = static_cast<Sprite*>(panelPlayer->getChildByName("landlord"));
|
|
CC_ASSERT(splandlord != nullptr);
|
|
splandlord->setVisible(false);
|
|
|
|
// 游戏积分;
|
|
auto txtGameScore = static_cast<TextBMFont*>(panelPlayer->getChildByName("txtGameScore"));
|
|
CC_ASSERT(txtGameScore != nullptr);
|
|
|
|
if (pGameConclude->lGameScore[i] > 0)
|
|
{
|
|
txtGameScore->setFntFile(PDK_WIN_NUMBER_FNT_FILE);
|
|
txtGameScore->setString(StringUtils::format("+%d", pGameConclude->lGameScore[i]));
|
|
}
|
|
else
|
|
{
|
|
txtGameScore->setFntFile(PDK_LOSE_NUMBER_FNT_FILE);
|
|
txtGameScore->setString(StringUtils::format("%d", pGameConclude->lGameScore[i]));
|
|
}
|
|
|
|
// 炸弹积分;
|
|
auto txtBombScore = static_cast<TextBMFont*>(panelPlayer->getChildByName("txtBombScore"));
|
|
CC_ASSERT(txtBombScore != nullptr);
|
|
|
|
if (pGameConclude->lBombScore[i] > 0)
|
|
{
|
|
txtBombScore->setFntFile(PDK_WIN_NUMBER_FNT_FILE);
|
|
txtBombScore->setString(StringUtils::format("+%d", pGameConclude->lBombScore[i]));
|
|
}
|
|
else
|
|
{
|
|
txtBombScore->setFntFile(PDK_LOSE_NUMBER_FNT_FILE);
|
|
txtBombScore->setString(StringUtils::format("%d", pGameConclude->lBombScore[i]));
|
|
}
|
|
|
|
// 总积分;
|
|
auto txtAllScore = static_cast<TextBMFont*>(panelPlayer->getChildByName("txtAllScore"));
|
|
CC_ASSERT(txtAllScore != nullptr);
|
|
|
|
if (pGameConclude->lAllScore[i] > 0)
|
|
{
|
|
txtAllScore->setFntFile(PDK_WIN_NUMBER_FNT_FILE);
|
|
txtAllScore->setString(StringUtils::format("+%d", pGameConclude->lAllScore[i]));
|
|
}
|
|
else
|
|
{
|
|
txtAllScore->setFntFile(PDK_LOSE_NUMBER_FNT_FILE);
|
|
txtAllScore->setString(StringUtils::format("%d", pGameConclude->lAllScore[i]));
|
|
}
|
|
|
|
auto panelLeftCard = static_cast<Layout*>(panelPlayer->getChildByName("panelLeftCard"));
|
|
CC_ASSERT(panelLeftCard != nullptr);
|
|
panelLeftCard->removeAllChildren();
|
|
|
|
if (pGameConclude->cbCardCount[i] > 0)
|
|
{
|
|
showLeftCard(panelLeftCard, &pGameConclude->cbHandCardData[cbCardIndex], pGameConclude->cbCardCount[i]);
|
|
|
|
cbCardIndex += pGameConclude->cbCardCount[i];
|
|
}
|
|
}
|
|
|
|
//如果自已赢了;
|
|
CC_ASSERT(wSelfChairID <= PDK_GAME_PLAYER);
|
|
if (pGameConclude->lGameScore[wSelfChairID] > 0)
|
|
{
|
|
////如果自已是地主;
|
|
//if (wLandChairID == wSelfChairID)
|
|
//{
|
|
// m_sprLandlord->setTexture(PDK_DIZHU_SHENG_PNG_FILE);
|
|
//}
|
|
//else
|
|
//{
|
|
// m_sprLandlord->setTexture(PDK_NONGMIN_SHENG_PNG_FILE);
|
|
//}
|
|
|
|
m_sprTitleWin->setTexture(PDK_END_TITLE_WIN_PNG_FILE);
|
|
m_sprWin->setTexture(PDK_SHENG_PNG_FILE);
|
|
}
|
|
else
|
|
{
|
|
//如果自已是地主;
|
|
//if (wLandChairID == wSelfChairID)
|
|
//{
|
|
// m_sprLandlord->setTexture(PDK_DIZHU_SHU_PNG_FILE);
|
|
//}
|
|
//else
|
|
//{
|
|
// m_sprLandlord->setTexture(PDK_NONGMIN_SHU_PNG_FILE);
|
|
//}
|
|
|
|
m_sprTitleWin->setTexture(PDK_END_TITLE_LOSE_PNG_FILE);
|
|
m_sprWin->setTexture(PDK_SHU_PNG_FILE);
|
|
}
|
|
|
|
//if (pGameConclude->bChunTian)
|
|
//{
|
|
// m_sprChunTian->setTexture("Games/DDZ/Result/chuntian.png");
|
|
//}
|
|
//else if (pGameConclude->bFanChunTian)
|
|
//{
|
|
// m_sprChunTian->setTexture("Games/DDZ/Result/fanchuntian.png");
|
|
//}
|
|
//else
|
|
{
|
|
m_sprChunTian->setVisible(false);
|
|
}
|
|
|
|
this->setVisible(true);
|
|
}
|
|
|
|
void PDKGameEndNode::show(uint16 wLandChairID, uint16 wSelfChairID, std::string aryNickName[], PDK_CMD_S_GameConclude* pGameConclude, uint16 wTurnWiner, uint8 cbTurnCardCount, uint8 cbTurnCardData[])
|
|
{
|
|
uint8 cbCardIndex = 0;
|
|
|
|
//获取文本;
|
|
for (int i = 0; i < PDK_GAME_PLAYER; i++)
|
|
{
|
|
//获取玩家面板;
|
|
auto panelPlayer = static_cast<Layout*>(m_rootPanel->getChildByName(StringUtils::format("panelPlayer_%d", i)));
|
|
CC_ASSERT(panelPlayer != nullptr);
|
|
panelPlayer->setVisible(true);
|
|
|
|
if (!pGameConclude->bActiveStatus[i])
|
|
{
|
|
panelPlayer->setVisible(false);
|
|
continue;
|
|
}
|
|
|
|
auto txtNickName = static_cast<Text*>(panelPlayer->getChildByName("txtNickName"));
|
|
CC_ASSERT(txtNickName != nullptr);
|
|
|
|
txtNickName->setString(aryNickName[i]);
|
|
|
|
// 地主;
|
|
auto splandlord = static_cast<Sprite*>(panelPlayer->getChildByName("landlord"));
|
|
CC_ASSERT(splandlord != nullptr);
|
|
splandlord->setVisible(false);
|
|
|
|
// 游戏积分;
|
|
auto txtGameScore = static_cast<TextBMFont*>(panelPlayer->getChildByName("txtGameScore"));
|
|
CC_ASSERT(txtGameScore != nullptr);
|
|
|
|
if (pGameConclude->lGameScore[i] > 0)
|
|
{
|
|
txtGameScore->setFntFile(PDK_WIN_NUMBER_FNT_FILE);
|
|
txtGameScore->setString(StringUtils::format("+%d", pGameConclude->lGameScore[i]));
|
|
}
|
|
else
|
|
{
|
|
txtGameScore->setFntFile(PDK_LOSE_NUMBER_FNT_FILE);
|
|
txtGameScore->setString(StringUtils::format("%d", pGameConclude->lGameScore[i]));
|
|
}
|
|
|
|
// 炸弹积分;
|
|
auto txtBombScore = static_cast<TextBMFont*>(panelPlayer->getChildByName("txtBombScore"));
|
|
CC_ASSERT(txtBombScore != nullptr);
|
|
|
|
if (pGameConclude->lBombScore[i] > 0)
|
|
{
|
|
txtBombScore->setFntFile(PDK_WIN_NUMBER_FNT_FILE);
|
|
txtBombScore->setString(StringUtils::format("+%d", pGameConclude->lBombScore[i]));
|
|
}
|
|
else
|
|
{
|
|
txtBombScore->setFntFile(PDK_LOSE_NUMBER_FNT_FILE);
|
|
txtBombScore->setString(StringUtils::format("%d", pGameConclude->lBombScore[i]));
|
|
}
|
|
|
|
// 总积分;
|
|
auto txtAllScore = static_cast<TextBMFont*>(panelPlayer->getChildByName("txtAllScore"));
|
|
CC_ASSERT(txtAllScore != nullptr);
|
|
|
|
if (pGameConclude->lAllScore[i] > 0)
|
|
{
|
|
txtAllScore->setFntFile(PDK_WIN_NUMBER_FNT_FILE);
|
|
txtAllScore->setString(StringUtils::format("+%d", pGameConclude->lAllScore[i]));
|
|
}
|
|
else
|
|
{
|
|
txtAllScore->setFntFile(PDK_LOSE_NUMBER_FNT_FILE);
|
|
txtAllScore->setString(StringUtils::format("%d", pGameConclude->lAllScore[i]));
|
|
}
|
|
|
|
auto panelLeftCard = static_cast<Layout*>(panelPlayer->getChildByName("panelLeftCard"));
|
|
CC_ASSERT(panelLeftCard != nullptr);
|
|
panelLeftCard->removeAllChildren();
|
|
|
|
if (pGameConclude->cbCardCount[i] > 0)
|
|
{
|
|
showLeftCard(panelLeftCard, &pGameConclude->cbHandCardData[cbCardIndex], pGameConclude->cbCardCount[i]);
|
|
|
|
cbCardIndex += pGameConclude->cbCardCount[i];
|
|
}
|
|
else if (i == wTurnWiner)// 显示赢家牌;
|
|
{
|
|
showLeftCard(panelLeftCard, cbTurnCardData, cbTurnCardCount);
|
|
}
|
|
}
|
|
|
|
//如果自已赢了;
|
|
CC_ASSERT(wSelfChairID <= PDK_GAME_PLAYER);
|
|
if (pGameConclude->lGameScore[wSelfChairID] > 0)
|
|
{
|
|
m_sprTitleWin->setTexture(PDK_END_TITLE_WIN_PNG_FILE);
|
|
m_sprWin->setTexture(PDK_SHENG_PNG_FILE);
|
|
}
|
|
else
|
|
{
|
|
m_sprTitleWin->setTexture(PDK_END_TITLE_LOSE_PNG_FILE);
|
|
m_sprWin->setTexture(PDK_SHU_PNG_FILE);
|
|
}
|
|
|
|
m_sprChunTian->setVisible(false);
|
|
|
|
this->setVisible(true);
|
|
}
|
|
|
|
void PDKGameEndNode::hide()
|
|
{
|
|
this->setVisible(false);
|
|
}
|
|
|
|
//继续按钮点击事件;
|
|
void PDKGameEndNode::onButtonContinueClick(Ref*)
|
|
{
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|
EventCustom event(CONTINUE_GAME);
|
|
|
|
//派发拒绝解散房间事件至DDZGameScene
|
|
dispatcher->dispatchEvent(&event);
|
|
|
|
hide();
|
|
}
|
|
|
|
void PDKGameEndNode::onButtonShareClick(Ref*)
|
|
{
|
|
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(WEIXIN_SHOW);
|
|
}
|
|
|
|
void PDKGameEndNode::SetShowPrivate()
|
|
{
|
|
m_btnContinue->setVisible(false);
|
|
m_btnPrivate->setVisible(true);
|
|
}
|
|
|
|
//显示剩余扑克;
|
|
void PDKGameEndNode::showLeftCard(Layout* pRootPanel, uint8 aryCardData[], uint8 cbCardCount)
|
|
{
|
|
CC_ASSERT(pRootPanel != nullptr);
|
|
|
|
//创建扑克牌;
|
|
for (uint8 i = 0; i < cbCardCount; i++)
|
|
{
|
|
PDKSmallCardSprite* pCard = PDKSmallCardSprite::create(aryCardData[i]);
|
|
|
|
CC_ASSERT(pCard != nullptr);
|
|
if (pCard)
|
|
{
|
|
pCard->setPositionX(i * 15);
|
|
pRootPanel->addChild(pCard);
|
|
}
|
|
}
|
|
} |