219 lines
5.5 KiB
C++
219 lines
5.5 KiB
C++
#include "DDZ_GameEndNode.h"
|
|
#include "Define.h"
|
|
#include "DDZ_CMD.h"
|
|
#include "ActionEx.h"
|
|
#include "DDZ_SmallCardSprite.h"
|
|
|
|
//SINGLETON_STORAGE(DDZGameEndNode);
|
|
|
|
DDZGameEndNode::DDZGameEndNode()
|
|
{
|
|
//init();
|
|
}
|
|
|
|
DDZGameEndNode::~DDZGameEndNode()
|
|
{
|
|
|
|
}
|
|
|
|
bool DDZGameEndNode::init()
|
|
{
|
|
if (!Node::init())
|
|
{
|
|
return false;
|
|
};
|
|
|
|
auto root = CSLoader::createNodeWithVisibleSize("Games/DDZ/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(DDZGameEndNode::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);
|
|
|
|
return true;
|
|
}
|
|
|
|
//显示;
|
|
void DDZGameEndNode::show(uint16 wLandChairID, uint16 wSelfChairID, std::string aryNickName[], DDZ_CMD_S_GameConclude* pGameConclude, uint16 wTime)
|
|
{
|
|
uint8 cbCardIndex = 0;
|
|
|
|
//获取文本;
|
|
for (int i = 0; i < DDZ_GAME_PLAYER; i++)
|
|
{
|
|
//获取玩家面板;
|
|
auto panelPlayer = static_cast<Layout*>(m_rootPanel->getChildByName(StringUtils::format("panelPlayer_%d", i)));
|
|
CC_ASSERT(panelPlayer != nullptr);
|
|
|
|
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(i == wLandChairID);
|
|
|
|
auto txtScore = static_cast<TextBMFont*>(panelPlayer->getChildByName("txtScore"));
|
|
CC_ASSERT(txtScore != nullptr);
|
|
|
|
if (pGameConclude->lGameScore[i] > 0)
|
|
{
|
|
txtScore->setFntFile(DDZ_WIN_NUMBER_FNT_FILE);
|
|
txtScore->setString(StringUtils::format("+%d", pGameConclude->lGameScore[i]));
|
|
}
|
|
else
|
|
{
|
|
txtScore->setFntFile(DDZ_LOSE_NUMBER_FNT_FILE);
|
|
txtScore->setString(StringUtils::format("%d", pGameConclude->lGameScore[i]));
|
|
}
|
|
|
|
//txtCellScore->setString(StringUtils::format("%d", nCellScore));
|
|
//txtTimes->setString(StringUtils::format("%d", nTimes));
|
|
|
|
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 <= DDZ_GAME_PLAYER);
|
|
if (pGameConclude->lGameScore[wSelfChairID] > 0)
|
|
{
|
|
//如果自已是地主;
|
|
if (wLandChairID == wSelfChairID)
|
|
{
|
|
m_sprLandlord->setTexture(DDZ_DIZHU_SHENG_PNG_FILE);
|
|
}
|
|
else
|
|
{
|
|
m_sprLandlord->setTexture(DDZ_NONGMIN_SHENG_PNG_FILE);
|
|
}
|
|
|
|
m_sprTitleWin->setTexture(DDZ_END_TITLE_WIN_PNG_FILE);
|
|
m_sprWin->setTexture(DDZ_SHENG_PNG_FILE);
|
|
}
|
|
else
|
|
{
|
|
//如果自已是地主;
|
|
if (wLandChairID == wSelfChairID)
|
|
{
|
|
m_sprLandlord->setTexture(DDZ_DIZHU_SHU_PNG_FILE);
|
|
}
|
|
else
|
|
{
|
|
m_sprLandlord->setTexture(DDZ_NONGMIN_SHU_PNG_FILE);
|
|
}
|
|
|
|
m_sprTitleWin->setTexture(DDZ_END_TITLE_LOSE_PNG_FILE);
|
|
m_sprWin->setTexture(DDZ_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 DDZGameEndNode::hide()
|
|
{
|
|
this->setVisible(false);
|
|
}
|
|
|
|
//继续按钮点击事件;
|
|
void DDZGameEndNode::onButtonContinueClick(Ref*)
|
|
{
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|
EventCustom event(CONTINUE_GAME);
|
|
|
|
//派发拒绝解散房间事件至DDZGameScene
|
|
dispatcher->dispatchEvent(&event);
|
|
|
|
hide();
|
|
}
|
|
|
|
void DDZGameEndNode::onButtonShareClick(Ref*)
|
|
{
|
|
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(WEIXIN_SHOW);
|
|
}
|
|
|
|
void DDZGameEndNode::SetShowPrivate()
|
|
{
|
|
m_btnContinue->setVisible(false);
|
|
m_btnPrivate->setVisible(true);
|
|
}
|
|
|
|
//显示剩余扑克;
|
|
void DDZGameEndNode::showLeftCard(Layout* pRootPanel, uint8 aryCardData[], uint8 cbCardCount)
|
|
{
|
|
CC_ASSERT(pRootPanel != nullptr);
|
|
|
|
//创建扑克牌;
|
|
for (uint8 i = 0; i < cbCardCount; i++)
|
|
{
|
|
DDZSmallCardSprite* pCard = DDZSmallCardSprite::create(aryCardData[i]);
|
|
|
|
CC_ASSERT(pCard != nullptr);
|
|
if (pCard)
|
|
{
|
|
pCard->setPositionX(i * 20);
|
|
pRootPanel->addChild(pCard);
|
|
}
|
|
}
|
|
} |