Files
wnmj-normal/Classes/Games/WNMJ/WN_PrivateScene.cpp
2026-03-03 13:56:44 +08:00

397 lines
11 KiB
C++

#include "WN_PrivateScene.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "GameDefine.h"
#include "ImagicDownManager.h"
#include "YSAudioEngine.h"
#include "JniFun.h"
USING_NS_CC;
using namespace ui;
using namespace std;
using namespace WNMJ_SPACE;
#define SETCTRLTEXT(pNode, ctrl, str) \
{ \
Text* pText = (Text*)pNode->getChildByName(ctrl);\
if (pText) pText->setString(str);\
}
WN_PrivateScene::WN_PrivateScene()
{
m_pRootLayout = nullptr; // 根节点
m_btnleave = nullptr; // 用户离开
m_btnShow = nullptr; // 分享
zeromemory(m_pPlayNode, sizeof(m_pPlayNode)); // 玩家结束信息
}
WN_PrivateScene::~WN_PrivateScene()
{
}
bool WN_PrivateScene::init()
{
if (!Node::init()) {
return false;
}
m_pRootLayout = static_cast<Layout*>(CSLoader::createNode("Games/WNMJ/PrivateEndScene.csb"));
this->addChild(m_pRootLayout);
// 离开按钮
m_btnleave = (Button*)m_pRootLayout->getChildByName("btnClose");
ASSERT(m_btnleave);
m_btnleave->addClickEventListener([=](Ref *pSender){
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(LEAVE_GAME);
});
// 分享
m_btnShow = (Button*)m_pRootLayout->getChildByName("btnShow");
ASSERT(m_btnShow);
m_btnShow->addClickEventListener([=](Ref *pSender){
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(WEIXIN_SHOW);
});
for (WORD i = 0; i < GAME_PLAYER; i++)
{
m_pPlayNode[i] = (Layout*)m_pRootLayout->getChildByName(StringUtils::format("FileNode_%d", i));
ASSERT(m_pPlayNode[i]);
m_pPlayNode[i]->setVisible(false);
}
return true;
}
void WN_PrivateScene::ShowGameResult(CMD_S_Private_End_Info* pNetInfo, GamePlayer* players[GAME_PLAYER], BYTE cbBaseScore)
{
if (pNetInfo == nullptr) return;
// 寻找大赢家;
SCORE lMaxScore = 0;
for (int i = 0; i < GAME_PLAYER; i++)
{
if (!pNetInfo->aryActiveStatus[i]) continue;
GamePlayer* pPlayer = players[i];
if (nullptr == pPlayer) continue;
// 找到大赢家;
if (lMaxScore < pNetInfo->lAllScore[i])
{
lMaxScore = pNetInfo->lAllScore[i];
}
}
for (int i = 0; i < GAME_PLAYER; i++)
{
if (!pNetInfo->aryActiveStatus[i]) continue;
GamePlayer* pPlayer = players[i];
if (nullptr == pPlayer) continue;
if (nullptr == m_pPlayNode[i]) continue;
// 头像
Sprite* pHead = (Sprite*)m_pPlayNode[i]->getChildByName("head");
if (pHead)
{
ImagicDownManager::Instance().addDown(pHead, pPlayer->GetHeadHttp(), pPlayer->GetGameID());
}
SETCTRLTEXT(m_pPlayNode[i], "txtUserName", pPlayer->GetNickName()); // 名称;
//SETCTRLTEXT(m_pPlayNode[i], "txtUnionName", pPlayer->GetUnionName()); // 公会;
SETCTRLTEXT(m_pPlayNode[i], "txtUserID", StringUtils::format("ID:%d", pPlayer->GetGameID())); // ID;
SETCTRLTEXT(m_pPlayNode[i], "txtGangScore", StringUtils::format("%d", pNetInfo->cbAllGangCounts[i])); // 杠次数;
SETCTRLTEXT(m_pPlayNode[i], "txtMaxScore", StringUtils::format("%d", pNetInfo->lMaxScore[i])); // 最高得分;
SETCTRLTEXT(m_pPlayNode[i], "txtZimo", StringUtils::format("%d", pNetInfo->cbZiMoCout[i])); // 自摸;
SETCTRLTEXT(m_pPlayNode[i], "txtDianPao", StringUtils::format("%d", pNetInfo->cbDianPaoCout[i])); // 点炮;
SETCTRLTEXT(m_pPlayNode[i], "txtAllScore", StringUtils::format("%d", pNetInfo->lAllScore[i])); // 总积分;
SETCTRLTEXT(m_pPlayNode[i], "txtAllUnionScore", ""); // 总积分;
auto master = (Sprite*)m_pPlayNode[i]->getChildByName("master");
ASSERT(master);
master->setVisible(i == 0);
// 是不是大赢家;
bool bMaxWinUser = false;
if ((lMaxScore > 0) && (lMaxScore == pNetInfo->lAllScore[i]))
{
bMaxWinUser = true;
}
// 大赢家;
auto big_winner = (Sprite*)m_pPlayNode[i]->getChildByName("big_winner");
if (big_winner) big_winner->setVisible(bMaxWinUser);
SCORE lUnionScore = pNetInfo->lAllScore[i] * cbBaseScore;
SETCTRLTEXT(m_pPlayNode[i], "txtUnionScore", utility::ScoreToString(lUnionScore)); // 总积分;
m_pPlayNode[i]->setVisible(true);
}
auto txtGameTime = (Text*)m_pRootLayout->getChildByName("txtGameTime");
ASSERT(txtGameTime != nullptr);
if (txtGameTime)
{
std::string strSystemTime = JniFun::getDataTime();
txtGameTime->setString(utility::a_u8("时间:" + strSystemTime));
}
this->setVisible(true);
}
void WN_PrivateScene::ShowGameResult(CMD_S_Private_End_Info* pNetInfo, GamePlayer* players[GAME_PLAYER],
bool bUnionScore, SCORE lGameGold, SCORE lScoreMultiple)
{
if (pNetInfo == nullptr) return;
// 寻找大赢家;
SCORE lMaxScore = 0;
for (int i = 0; i < GAME_PLAYER; i++)
{
if (!pNetInfo->aryActiveStatus[i]) continue;
GamePlayer* pPlayer = players[i];
if (nullptr == pPlayer) continue;
// 找到大赢家;
if (lMaxScore < pNetInfo->lAllScore[i])
{
lMaxScore = pNetInfo->lAllScore[i];
}
}
// 欢乐场计算税收;
SCORE lRevenue = 0;
if (bUnionScore)
{
// 统计大赢家数量;
int iMaxScoreCount = 0;
for (int j = 0; j < GAME_PLAYER; j++)
{
if (!pNetInfo->aryActiveStatus[j]) continue;
if ((lMaxScore > 0) && (pNetInfo->lAllScore[j] == lMaxScore))
{
iMaxScoreCount++;
}
}
if (iMaxScoreCount > 0)
{
// 计算玩家积分;
lRevenue = floor(lGameGold / iMaxScoreCount);
}
}
for (int i = 0; i < GAME_PLAYER; i++)
{
if (!pNetInfo->aryActiveStatus[i]) continue;
GamePlayer* pPlayer = players[i];
if (nullptr == pPlayer) continue;
if (nullptr == m_pPlayNode[i]) continue;
// 头像
Sprite* pHead = (Sprite*)m_pPlayNode[i]->getChildByName("head");
if (pHead)
{
ImagicDownManager::Instance().addDown(pHead, pPlayer->GetHeadHttp(), pPlayer->GetGameID());
}
SETCTRLTEXT(m_pPlayNode[i], "txtUserName", pPlayer->GetNickName()); // 名称;
//SETCTRLTEXT(m_pPlayNode[i], "txtUnionName", pPlayer->GetUnionName()); // 公会;
SETCTRLTEXT(m_pPlayNode[i], "txtUserID", StringUtils::format("ID:%d", pPlayer->GetGameID())); // ID;
SETCTRLTEXT(m_pPlayNode[i], "txtGangScore", StringUtils::format("%d", pNetInfo->cbAllGangCounts[i])); // 杠次数;
SETCTRLTEXT(m_pPlayNode[i], "txtMaxScore", StringUtils::format("%d", pNetInfo->lMaxScore[i])); // 最高得分;
SETCTRLTEXT(m_pPlayNode[i], "txtZimo", StringUtils::format("%d", pNetInfo->cbZiMoCout[i])); // 自摸;
SETCTRLTEXT(m_pPlayNode[i], "txtDianPao", StringUtils::format("%d", pNetInfo->cbDianPaoCout[i])); // 点炮;
SETCTRLTEXT(m_pPlayNode[i], "txtAllScore", StringUtils::format("%d", pNetInfo->lAllScore[i])); // 总积分;
auto master = (Sprite*)m_pPlayNode[i]->getChildByName("master");
ASSERT(master);
master->setVisible(i == 0);
// 是不是大赢家;
bool bMaxWinUser = false;
if ((lMaxScore > 0) && (lMaxScore == pNetInfo->lAllScore[i]))
{
bMaxWinUser = true;
}
// 大赢家;
auto big_winner = (Sprite*)m_pPlayNode[i]->getChildByName("big_winner");
if (big_winner) big_winner->setVisible(bMaxWinUser);
// 欢乐积分;
if (bUnionScore)
{
SCORE lUnionScore = pNetInfo->lAllScore[i] * lScoreMultiple;
if (bMaxWinUser)
{
if (lUnionScore > lRevenue)
{
lUnionScore -= lRevenue;
}
else
{
lUnionScore = 0;
}
}
SETCTRLTEXT(m_pPlayNode[i], "txtUnionScore", utility::ScoreToString(lUnionScore)); // 总积分;
}
else
{
SETCTRLTEXT(m_pPlayNode[i], "txtUnionScore", ""); // 总积分;
}
m_pPlayNode[i]->setVisible(true);
}
auto txtGameTime = (Text*)m_pRootLayout->getChildByName("txtGameTime");
ASSERT(txtGameTime != nullptr);
if (txtGameTime)
{
std::string strSystemTime = JniFun::getDataTime();
txtGameTime->setString(utility::a_u8("时间:" + strSystemTime));
}
this->setVisible(true);
}
void WN_PrivateScene::ShowGameResult(CMD_S_Private_End_Info* pNetInfo, GamePlayer* players[GAME_PLAYER],
CMD_GF_Private_Room_Info& RoomInfo, CMD_GF_Private_Score_Info& ScoreInfo)
{
if (pNetInfo == nullptr) return;
bool bUnionScore = (RoomInfo.cbUnionGoldOpen == 1);
//SCORE lScoreMultiple = RoomInfo.lScoreMultiple;
uint8 cbBaseScore = RoomInfo.cbBaseScore;
SCORE lGameGold = RoomInfo.lGameGold * RoomInfo.dwPlayCost;
// 寻找大赢家;
SCORE lMaxScore = 0;
for (int i = 0; i < GAME_PLAYER; i++)
{
if (!pNetInfo->aryActiveStatus[i]) continue;
GamePlayer* pPlayer = players[i];
if (nullptr == pPlayer) continue;
// 找到大赢家;
if (lMaxScore < pNetInfo->lAllScore[i])
{
lMaxScore = pNetInfo->lAllScore[i];
}
}
// 欢乐场计算税收;
SCORE lRevenue = 0;
if (bUnionScore)
{
// 统计大赢家数量;
int iMaxScoreCount = 0;
for (int j = 0; j < GAME_PLAYER; j++)
{
if (!pNetInfo->aryActiveStatus[j]) continue;
if ((lMaxScore > 0) && (pNetInfo->lAllScore[j] == lMaxScore))
{
iMaxScoreCount++;
}
}
if (iMaxScoreCount > 0)
{
// 计算玩家积分;
lRevenue = floor(lGameGold / iMaxScoreCount);
}
}
for (int i = 0; i < GAME_PLAYER; i++)
{
if (!pNetInfo->aryActiveStatus[i]) continue;
GamePlayer* pPlayer = players[i];
if (nullptr == pPlayer) continue;
if (nullptr == m_pPlayNode[i]) continue;
// 头像
Sprite* pHead = (Sprite*)m_pPlayNode[i]->getChildByName("head");
if (pHead)
{
ImagicDownManager::Instance().addDown(pHead, pPlayer->GetHeadHttp(), pPlayer->GetGameID());
}
SETCTRLTEXT(m_pPlayNode[i], "txtUserName", pPlayer->GetNickName()); // 名称;
//SETCTRLTEXT(m_pPlayNode[i], "txtUnionName", pPlayer->GetUnionName()); // 公会;
SETCTRLTEXT(m_pPlayNode[i], "txtUserID", StringUtils::format("ID:%d", pPlayer->GetGameID())); // ID;
SETCTRLTEXT(m_pPlayNode[i], "txtGangScore", StringUtils::format("%d", pNetInfo->cbAllGangCounts[i])); // 杠次数;
SETCTRLTEXT(m_pPlayNode[i], "txtMaxScore", StringUtils::format("%d", pNetInfo->lMaxScore[i])); // 最高得分;
SETCTRLTEXT(m_pPlayNode[i], "txtZimo", StringUtils::format("%d", pNetInfo->cbZiMoCout[i])); // 自摸;
SETCTRLTEXT(m_pPlayNode[i], "txtDianPao", StringUtils::format("%d", pNetInfo->cbDianPaoCout[i])); // 点炮;
SETCTRLTEXT(m_pPlayNode[i], "txtAllScore", StringUtils::format("%d", pNetInfo->lAllScore[i])); // 总积分;
auto master = (Sprite*)m_pPlayNode[i]->getChildByName("master");
ASSERT(master);
master->setVisible(i == 0);
// 是不是大赢家;
bool bMaxWinUser = false;
if ((lMaxScore > 0) && (lMaxScore == pNetInfo->lAllScore[i]))
{
bMaxWinUser = true;
}
// 大赢家;
auto big_winner = (Sprite*)m_pPlayNode[i]->getChildByName("big_winner");
if (big_winner) big_winner->setVisible(bMaxWinUser);
// 欢乐积分;
if (bUnionScore)
{
// 计算总积分
//SCORE lUnionScore = ScoreInfo.kScoreInfoArray[i] + (pNetInfo->lAllScore[i] * lScoreMultiple * cbBaseScore);
SCORE lUnionScore = pNetInfo->lAllScore[i] * cbBaseScore;
if (bMaxWinUser)
{
if (lUnionScore > lRevenue)
{
lUnionScore -= lRevenue;
}
else
{
lUnionScore = 0;
}
}
SCORE lAllUnionScore = ScoreInfo.kScoreInfoArray[i] + lUnionScore;
SETCTRLTEXT(m_pPlayNode[i], "txtUnionScore", utility::ScoreToString(lUnionScore)); // 总积分;
SETCTRLTEXT(m_pPlayNode[i], "txtAllUnionScore", StringUtils::format("%d", lAllUnionScore)); // 总积分;
}
else
{
SETCTRLTEXT(m_pPlayNode[i], "txtUnionScore", ""); // 总积分;
SETCTRLTEXT(m_pPlayNode[i], "txtAllUnionScore", ""); // 总积分;
}
m_pPlayNode[i]->setVisible(true);
}
auto txtGameTime = (Text*)m_pRootLayout->getChildByName("txtGameTime");
ASSERT(txtGameTime != nullptr);
if (txtGameTime)
{
std::string strSystemTime = JniFun::getDataTime();
txtGameTime->setString(utility::a_u8("时间:" + strSystemTime));
}
this->setVisible(true);
}