// // GameScene.cpp // MyGame // // Created by wh on 15/5/26. // // #include "WN_GameOver.h" #include "cocostudio/CocoStudio.h" #include "ui/CocosGUI.h" #include "GameDefine.h" #include "GameMission.h" #include "ImagicDownManager.h" #include "JniFun.h" USING_NS_CC; using namespace ui; using namespace std; using namespace WNMJ_SPACE; WN_OverNode::WN_OverNode() { m_pRootNode = nullptr; m_wChairID = INVALID_CHAIR; m_spriteBanker = nullptr; m_ResultType = nullptr; } WN_OverNode::~WN_OverNode() { m_pRootNode = nullptr; m_wChairID = INVALID_CHAIR; m_spriteBanker = nullptr; m_ResultType = nullptr; } void WN_OverNode::Init(WORD wChairID) { if (nullptr == m_pRootNode) return; m_wChairID = wChairID; // 初始化的时候赋值,之后不会改变 m_spriteBanker = (Sprite*)m_pRootNode->getChildByName("Banker"); ASSERT(m_spriteBanker); m_spriteBanker->setVisible(false); m_txtUserName = (Text*)m_pRootNode->getChildByName("txtUserName"); ASSERT(m_txtUserName); m_txtUserName->setString(""); m_txtResultType = (Text*)m_pRootNode->getChildByName("txtResultType"); ASSERT(m_txtResultType); m_txtResultType->setString(""); m_txtScore = (Text*)m_pRootNode->getChildByName("txtScore"); ASSERT(m_txtScore); m_txtScore->setString(""); m_ResultType = (Sprite*)m_pRootNode->getChildByName("ResultType"); ASSERT(m_ResultType); m_ResultType->setVisible(false); m_PanelCard = (Layout*)m_pRootNode->getChildByName("PanelCard"); ASSERT(m_PanelCard); } void WN_OverNode::ShowInfo(tagClientScoreInfo &ScoreInfo) { if (m_wChairID != ScoreInfo.wChairID) return; ReSet(); // 名称 m_txtUserName->setString(utility::a_u8(ScoreInfo.szNickName)); // 积分 string strScore = utility::ScoreToString(ScoreInfo.lGameScore); m_txtScore->setString(utility::a_u8(strScore)); // 庄家 if (m_wChairID == ScoreInfo.wBankerUser) { m_spriteBanker->setVisible(true); } // 胡牌 if (ScoreInfo.dwChiHuKind != CHK_NULL) { m_ResultType->setVisible(true); std::string strHuKind = WN_CGameLogic::getInstance()->GetHuKind(ScoreInfo.dwChiHuKind); std::string strHuRight = WN_CGameLogic::getInstance()->GetHuRight(ScoreInfo.dwChiHuRight); std::string strHuType = StringUtils::format("%s %s", strHuKind.c_str(), strHuRight.c_str()); m_txtResultType->setString(utility::a_u8(strHuType)); } else { m_ResultType->setVisible(false); //放炮 if (m_wChairID == ScoreInfo.wProvideUser) { m_txtResultType->setString(utility::a_u8("放炮")); } } if (m_PanelCard == nullptr) return; m_PanelCard->removeAllChildren(); // 显示牌 Point pos; // 显示组合牌 for (int w = 0; w < ScoreInfo.cbWeaveItemCount; w++) { tagWeaveItem* pWeaveItem = &ScoreInfo.WeaveItemArray[w]; WN_WeaveCard* pWeaveCard = WN_WeaveCard::create(); ASSERT(pWeaveCard); pWeaveCard->SetCardData(pWeaveItem->cbCenterCard, pWeaveItem->wWeaveKind); m_PanelCard->addChild(pWeaveCard); // 位置计算 Point tmpos; tmpos.x = pos.x + NCMJ_WEAVE_SELF * w; tmpos.y = pos.y; pWeaveCard->setPosition(tmpos); } bool isFindHuCard = false; uint8 cbShowCardCount = 0; // 手牌显示 for (int c = 0; c < ScoreInfo.cbCardCount; c++) { // 胡牌者; if (ScoreInfo.dwChiHuKind != CHK_NULL) { // 第一张和胡牌相同的牌不显示; if (!isFindHuCard && ScoreInfo.cbCardData[c] == ScoreInfo.cbChiHuCard) { isFindHuCard = true; continue; } } WN_SparrowCard* pCardSprite = WN_SparrowCard::createWithDirection(ScoreInfo.cbCardData[c], SP_ENDCARD); ASSERT(pCardSprite); pCardSprite->setAnchorPoint(Point(0, 0)); m_PanelCard->addChild(pCardSprite); Point tmpos; tmpos.x = pos.x + NCMJ_WEAVE_SELF * ScoreInfo.cbWeaveItemCount + cbShowCardCount * NCMJ_OPP_HAND_CARD_WIDHT + 10; tmpos.y = pos.y; pCardSprite->setPosition(tmpos); cbShowCardCount++; } // 胡牌者; if ((ScoreInfo.dwChiHuKind != CHK_NULL) && isFindHuCard && (0x0 != ScoreInfo.cbChiHuCard)) { SparrowCard* pCardSprite = WN_SparrowCard::createWithDirection(ScoreInfo.cbChiHuCard, SP_ENDCARD); ASSERT(pCardSprite); pCardSprite->setAnchorPoint(Point(0, 0)); m_PanelCard->addChild(pCardSprite); Point tmpos; tmpos.x = NCMJ_WEAVE_SELF * ScoreInfo.cbWeaveItemCount + cbShowCardCount * NCMJ_OPP_HAND_CARD_WIDHT + NCMJ_OPP_HAND_CARD_WIDHT; tmpos.y = 0; pCardSprite->setPosition(tmpos); } } void WN_OverNode::ReSet() { ASSERT(m_spriteBanker); m_spriteBanker->setVisible(false); m_txtUserName->setString(""); m_txtResultType->setString(""); m_txtScore->setString(""); m_ResultType->setVisible(false); m_PanelCard->removeAllChildren(); } Point WN_OverNode::getPosition() { return m_pRootNode->getPosition(); } ////////////////////////////////////////////////////////////////////////// WN_GameOver::WN_GameOver() { m_pRootLayout = nullptr; // 根节点 //m_btnleave = nullptr; // 用户离开 m_btnStart = nullptr; // 继续游戏 m_btnShow = nullptr; // 分享 m_wSelfChairID = INVALID_CHAIR; memset(m_ClientScoreInfoEx, 0x0, sizeof(m_ClientScoreInfoEx)); zeromemory(m_bActiveStatus, sizeof(m_bActiveStatus)); } WN_GameOver::~WN_GameOver() { } bool WN_GameOver::init() { if (!Node::init()) { return false; } m_pRootLayout = static_cast(CSLoader::createNode("Games/WNMJ/GameOverScene.csb")); this->addChild(m_pRootLayout); // 开始按钮 m_btnStart = (Button*)m_pRootLayout->getChildByName("btnStart"); ASSERT(m_btnStart); m_btnStart->addClickEventListener([=](Ref *pSender){ Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(NJSP_START_GAME); }); // 分享 m_btnShow = (Button*)m_pRootLayout->getChildByName("btnShow"); ASSERT(m_btnShow); m_btnShow->addClickEventListener([=](Ref *pSender){ Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(WEIXIN_SHOW); }); //结算信息; m_btnPrivate = (Button*)m_pRootLayout->getChildByName("btnPrivate"); ASSERT(m_btnPrivate); m_btnPrivate->setVisible(false); m_btnPrivate->addClickEventListener([=](Ref *pSender){ Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(SHOW_PRIVATE_END); }); // 抬头 m_Title = (Sprite*)m_pRootLayout->getChildByName("title"); ASSERT(m_Title); m_over_player = (Sprite*)m_pRootLayout->getChildByName("over_player"); ASSERT(m_over_player); std::string ctrl = ""; for (int i = 0; i < GAME_PLAYER; i++) { ctrl = __String::createWithFormat("UserNode_%d", i)->getCString(); auto node = (Node*)m_pRootLayout->getChildByName(ctrl); m_OverNode[i].SetRootNode((ImageView*)node->getChildByName("Image_bg")); m_OverNode[i].Init(i); } return true; } void WN_GameOver::onEnter() { Node::onEnter(); } void WN_GameOver::onEnterTransitionDidFinish() { Node::onEnterTransitionDidFinish(); } void WN_GameOver::onExit() { Node::onExit(); } void WN_GameOver::ResetDlg() { m_wSelfChairID = INVALID_CHAIR; m_wShowChairID = INVALID_CHAIR; memset(m_ClientScoreInfoEx, 0x0, sizeof(tagClientScoreInfo)*GAME_PLAYER); zeromemory(m_bActiveStatus, sizeof(m_bActiveStatus)); for (int i = 0; i < GAME_PLAYER; i++) { m_OverNode[i].ReSet(); } } void WN_GameOver::SetGameResultData(WORD wChairID, tagClientScoreInfo &ScoreInfo, bool isSelfData) { cocos2d::log("**************GameOver::SetGameResultData wChairID=%d ********************", wChairID); if (wChairID < 0 || wChairID > GAME_PLAYER) return; if (isSelfData) m_wSelfChairID = wChairID; m_bActiveStatus[wChairID] = true; CopyMemory(&m_ClientScoreInfoEx[wChairID], &ScoreInfo, sizeof(ScoreInfo)); } void WN_GameOver::ShowGameResult(bool isGameRecord /*= false*/) { cocos2d::log("**************GameOver::ShowGameResult ********************"); for (WORD i = 0; i < GAME_PLAYER; i++) { cocos2d::log("m_ClientScoreInfoEx[%d].wViewChairID = %d", i, m_ClientScoreInfoEx[i].wChairID); if (!m_bActiveStatus[i]) continue; ASSERT(i == m_ClientScoreInfoEx[i].wChairID); m_OverNode[i].ShowInfo(m_ClientScoreInfoEx[i]); } // 正常结算显示 if (m_wSelfChairID < 0 || m_wSelfChairID > GAME_PLAYER) return; if (m_wSelfChairID != m_ClientScoreInfoEx[m_wSelfChairID].wChairID) return; if (m_over_player) m_over_player->setTexture("Games/WNMJ/GamePrivate/over_ku.png"); // 抬头 if (m_ClientScoreInfoEx[m_wSelfChairID].lGameScore > 0) { m_Title->setTexture("Games/WNMJ/GamePrivate/over_hupai.png"); if (m_over_player) { m_over_player->setTexture("Games/WNMJ/GamePrivate/over_xiao.png"); } } else if (m_ClientScoreInfoEx[m_wSelfChairID].lGameScore < 0) { m_Title->setTexture("Games/WNMJ/GamePrivate/over_shule.png"); } else { m_Title->setTexture("Games/WNMJ/GamePrivate/over_peida.png"); } auto txtGameTime = (Text*)m_pRootLayout->getChildByName("txtGameTime"); ASSERT(txtGameTime != nullptr); if (txtGameTime) { std::string strSystemTime = JniFun::getDataTime(); txtGameTime->setString(utility::a_u8("时间:"+strSystemTime)); txtGameTime->setVisible(!isGameRecord); } } void WN_GameOver::SetShowPrivate() { m_btnStart->setVisible(false); m_btnPrivate->setVisible(true); }