Files
wnmj-normal/Classes/Games/WNMJ/WN_PrivateScene.cpp

397 lines
11 KiB
C++
Raw Permalink Normal View History

2026-03-03 13:56:44 +08:00
#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; // <20><><EFBFBD>ڵ<EFBFBD>
m_btnleave = nullptr; // <20>û<EFBFBD><C3BB>
m_btnShow = nullptr; // <20><><EFBFBD><EFBFBD>
zeromemory(m_pPlayNode, sizeof(m_pPlayNode)); // <20><><EFBFBD>ҽ<EFBFBD><D2BD><EFBFBD><EFBFBD><EFBFBD>Ϣ
}
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);
// <20><EFBFBD><EBBFAA>ť
m_btnleave = (Button*)m_pRootLayout->getChildByName("btnClose");
ASSERT(m_btnleave);
m_btnleave->addClickEventListener([=](Ref *pSender){
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(LEAVE_GAME);
});
// <20><><EFBFBD><EFBFBD>
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;
// Ѱ<>Ҵ<EFBFBD>Ӯ<EFBFBD><D3AE>;
SCORE lMaxScore = 0;
for (int i = 0; i < GAME_PLAYER; i++)
{
if (!pNetInfo->aryActiveStatus[i]) continue;
GamePlayer* pPlayer = players[i];
if (nullptr == pPlayer) continue;
// <20>ҵ<EFBFBD><D2B5><EFBFBD>Ӯ<EFBFBD><D3AE>;
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;
// ͷ<><CDB7>
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()); // <20><><EFBFBD><EFBFBD>;
//SETCTRLTEXT(m_pPlayNode[i], "txtUnionName", pPlayer->GetUnionName()); // <20><><EFBFBD><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtUserID", StringUtils::format("ID:%d", pPlayer->GetGameID())); // ID;
SETCTRLTEXT(m_pPlayNode[i], "txtGangScore", StringUtils::format("%d", pNetInfo->cbAllGangCounts[i])); // <20>ܴ<EFBFBD><DCB4><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtMaxScore", StringUtils::format("%d", pNetInfo->lMaxScore[i])); // <20><><EFBFBD>ߵ÷<DFB5>;
SETCTRLTEXT(m_pPlayNode[i], "txtZimo", StringUtils::format("%d", pNetInfo->cbZiMoCout[i])); // <20><><EFBFBD><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtDianPao", StringUtils::format("%d", pNetInfo->cbDianPaoCout[i])); // <20><><EFBFBD><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtAllScore", StringUtils::format("%d", pNetInfo->lAllScore[i])); // <20>ܻ<EFBFBD><DCBB><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtAllUnionScore", ""); // <20>ܻ<EFBFBD><DCBB><EFBFBD>;
auto master = (Sprite*)m_pPlayNode[i]->getChildByName("master");
ASSERT(master);
master->setVisible(i == 0);
// <20>Dz<EFBFBD><C7B2>Ǵ<EFBFBD>Ӯ<EFBFBD><D3AE>;
bool bMaxWinUser = false;
if ((lMaxScore > 0) && (lMaxScore == pNetInfo->lAllScore[i]))
{
bMaxWinUser = true;
}
// <20><>Ӯ<EFBFBD><D3AE>;
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)); // <20>ܻ<EFBFBD><DCBB><EFBFBD>;
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("ʱ<EFBFBD>" + 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;
// Ѱ<>Ҵ<EFBFBD>Ӯ<EFBFBD><D3AE>;
SCORE lMaxScore = 0;
for (int i = 0; i < GAME_PLAYER; i++)
{
if (!pNetInfo->aryActiveStatus[i]) continue;
GamePlayer* pPlayer = players[i];
if (nullptr == pPlayer) continue;
// <20>ҵ<EFBFBD><D2B5><EFBFBD>Ӯ<EFBFBD><D3AE>;
if (lMaxScore < pNetInfo->lAllScore[i])
{
lMaxScore = pNetInfo->lAllScore[i];
}
}
// <20><><EFBFBD>ֳ<EFBFBD><D6B3><EFBFBD><EFBFBD><EFBFBD>˰<EFBFBD><CBB0>;
SCORE lRevenue = 0;
if (bUnionScore)
{
// ͳ<>ƴ<EFBFBD>Ӯ<EFBFBD><D3AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
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)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>;
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;
// ͷ<><CDB7>
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()); // <20><><EFBFBD><EFBFBD>;
//SETCTRLTEXT(m_pPlayNode[i], "txtUnionName", pPlayer->GetUnionName()); // <20><><EFBFBD><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtUserID", StringUtils::format("ID:%d", pPlayer->GetGameID())); // ID;
SETCTRLTEXT(m_pPlayNode[i], "txtGangScore", StringUtils::format("%d", pNetInfo->cbAllGangCounts[i])); // <20>ܴ<EFBFBD><DCB4><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtMaxScore", StringUtils::format("%d", pNetInfo->lMaxScore[i])); // <20><><EFBFBD>ߵ÷<DFB5>;
SETCTRLTEXT(m_pPlayNode[i], "txtZimo", StringUtils::format("%d", pNetInfo->cbZiMoCout[i])); // <20><><EFBFBD><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtDianPao", StringUtils::format("%d", pNetInfo->cbDianPaoCout[i])); // <20><><EFBFBD><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtAllScore", StringUtils::format("%d", pNetInfo->lAllScore[i])); // <20>ܻ<EFBFBD><DCBB><EFBFBD>;
auto master = (Sprite*)m_pPlayNode[i]->getChildByName("master");
ASSERT(master);
master->setVisible(i == 0);
// <20>Dz<EFBFBD><C7B2>Ǵ<EFBFBD>Ӯ<EFBFBD><D3AE>;
bool bMaxWinUser = false;
if ((lMaxScore > 0) && (lMaxScore == pNetInfo->lAllScore[i]))
{
bMaxWinUser = true;
}
// <20><>Ӯ<EFBFBD><D3AE>;
auto big_winner = (Sprite*)m_pPlayNode[i]->getChildByName("big_winner");
if (big_winner) big_winner->setVisible(bMaxWinUser);
// <20><><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>;
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)); // <20>ܻ<EFBFBD><DCBB><EFBFBD>;
}
else
{
SETCTRLTEXT(m_pPlayNode[i], "txtUnionScore", ""); // <20>ܻ<EFBFBD><DCBB><EFBFBD>;
}
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("ʱ<EFBFBD>" + 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;
// Ѱ<>Ҵ<EFBFBD>Ӯ<EFBFBD><D3AE>;
SCORE lMaxScore = 0;
for (int i = 0; i < GAME_PLAYER; i++)
{
if (!pNetInfo->aryActiveStatus[i]) continue;
GamePlayer* pPlayer = players[i];
if (nullptr == pPlayer) continue;
// <20>ҵ<EFBFBD><D2B5><EFBFBD>Ӯ<EFBFBD><D3AE>;
if (lMaxScore < pNetInfo->lAllScore[i])
{
lMaxScore = pNetInfo->lAllScore[i];
}
}
// <20><><EFBFBD>ֳ<EFBFBD><D6B3><EFBFBD><EFBFBD><EFBFBD>˰<EFBFBD><CBB0>;
SCORE lRevenue = 0;
if (bUnionScore)
{
// ͳ<>ƴ<EFBFBD>Ӯ<EFBFBD><D3AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
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)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>;
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;
// ͷ<><CDB7>
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()); // <20><><EFBFBD><EFBFBD>;
//SETCTRLTEXT(m_pPlayNode[i], "txtUnionName", pPlayer->GetUnionName()); // <20><><EFBFBD><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtUserID", StringUtils::format("ID:%d", pPlayer->GetGameID())); // ID;
SETCTRLTEXT(m_pPlayNode[i], "txtGangScore", StringUtils::format("%d", pNetInfo->cbAllGangCounts[i])); // <20>ܴ<EFBFBD><DCB4><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtMaxScore", StringUtils::format("%d", pNetInfo->lMaxScore[i])); // <20><><EFBFBD>ߵ÷<DFB5>;
SETCTRLTEXT(m_pPlayNode[i], "txtZimo", StringUtils::format("%d", pNetInfo->cbZiMoCout[i])); // <20><><EFBFBD><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtDianPao", StringUtils::format("%d", pNetInfo->cbDianPaoCout[i])); // <20><><EFBFBD><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtAllScore", StringUtils::format("%d", pNetInfo->lAllScore[i])); // <20>ܻ<EFBFBD><DCBB><EFBFBD>;
auto master = (Sprite*)m_pPlayNode[i]->getChildByName("master");
ASSERT(master);
master->setVisible(i == 0);
// <20>Dz<EFBFBD><C7B2>Ǵ<EFBFBD>Ӯ<EFBFBD><D3AE>;
bool bMaxWinUser = false;
if ((lMaxScore > 0) && (lMaxScore == pNetInfo->lAllScore[i]))
{
bMaxWinUser = true;
}
// <20><>Ӯ<EFBFBD><D3AE>;
auto big_winner = (Sprite*)m_pPlayNode[i]->getChildByName("big_winner");
if (big_winner) big_winner->setVisible(bMaxWinUser);
// <20><><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>;
if (bUnionScore)
{
// <20><><EFBFBD><EFBFBD><EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD>
//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)); // <20>ܻ<EFBFBD><DCBB><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtAllUnionScore", StringUtils::format("%d", lAllUnionScore)); // <20>ܻ<EFBFBD><DCBB><EFBFBD>;
}
else
{
SETCTRLTEXT(m_pPlayNode[i], "txtUnionScore", ""); // <20>ܻ<EFBFBD><DCBB><EFBFBD>;
SETCTRLTEXT(m_pPlayNode[i], "txtAllUnionScore", ""); // <20>ܻ<EFBFBD><DCBB><EFBFBD>;
}
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("ʱ<EFBFBD>" + strSystemTime));
}
this->setVisible(true);
}