Files
wnmj-normal/Classes/Games/ZJH/ZJH_OpenResultScene.cpp

131 lines
3.2 KiB
C++
Raw Permalink Normal View History

2026-03-03 13:56:44 +08:00
#include "ZJH_OpenResultScene.h"
#include "cocostudio/CocoStudio.h"
using namespace cocostudio;
ZJHOpenResultScene::ZJHOpenResultScene()
{
}
ZJHOpenResultScene::~ZJHOpenResultScene()
{
}
bool ZJHOpenResultScene::init()
{
if (!Node::init())
{
return false;
}
// 加载界面数据;
auto rootNode = CSLoader::createNodeWithVisibleSize("Games/ZJH/OpenResultScene.csb");
addChild(rootNode);
// 绑定界面元素;
_MainPanel = static_cast<ImageView*>(rootNode->getChildByName("imgBg"));
CC_ASSERT(_MainPanel != nullptr);
_FinishListView = static_cast<Layout*>(_MainPanel->getChildByName("FinishListView"));
CC_ASSERT(_FinishListView != nullptr);
// 分享按钮;
_btnShare = static_cast<Button*>(_MainPanel->getChildByName("btnShare"));
CC_ASSERT(_btnShare != nullptr);
// 返回大厅;
_btnLobby = static_cast<Button*>(_MainPanel->getChildByName("btnLobby"));
CC_ASSERT(_btnLobby != nullptr);
// 时间;
_txtTime = static_cast<Text*>(_MainPanel->getChildByName("txtTime"));
CC_ASSERT(_txtTime != nullptr);
// 房间号;
_txtRoomID = static_cast<Text*>(_MainPanel->getChildByName("txtRoomID"));
CC_ASSERT(_txtRoomID != nullptr);
// 绑定事件;
// 退出按钮;
_btnLobby->addClickEventListener([=](Ref* pSender) {
stopAllActions();
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->dispatchCustomEvent(LEAVE_GAME);
});
// 分享按钮;
_btnShare->addClickEventListener([=](Ref* pSender) {
stopAllActions();
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(WEIXIN_SHOW);
});
return true;
}
void ZJHOpenResultScene::updateUIData(uint32 dwRoomID, std::vector<tagZJHOpenResultItem>* pAryItem, bool bUnionGoldOpen /*= false*/)
{
_txtRoomID->setString(StringUtils::format("%d", dwRoomID));
_FinishListView->removeAllChildren();
int iItemPerNum = 5;
int nCount = pAryItem->size();
Size winSize = Director::getInstance()->getWinSize();
//单个玩家信息框宽度为242高度为442;
//算出间隙;
float fDis = (winSize.width - 242 * nCount) / (nCount + 1);
float fItemSpaceX = fDis + 242;
float fItemStartY = (_FinishListView->getContentSize().height - 442) / 2;
// 寻找大赢家;
SCORE lMaxScore = 0;
for (size_t i = 0; i < nCount; i++)
{
tagZJHOpenResultItem* pData = &(pAryItem->at(i));
if (pData->lTotalScore > lMaxScore)
{
lMaxScore = pData->lTotalScore;
}
}
// 设置玩家信息;
for (size_t i = 0; i<nCount; i++)
{
tagZJHOpenResultItem* pData = &(pAryItem->at(i));
if ((pData->lTotalScore == lMaxScore) && (lMaxScore > 0))
{
pData->bBigWinner = true;
}
ZJHOpenResultItem* pItem = ZJHOpenResultItem::create();
pItem->initUIData(pData, bUnionGoldOpen);
_FinishListView->addChild(pItem);
int iXIndex = i % iItemPerNum;
int iYIndex = i / iItemPerNum;
int iXPos = fDis + iXIndex * fItemSpaceX;
int iYPos = fItemStartY;
pItem->setAnchorPoint(Vec2(0, 0));
pItem->setPosition(Vec2(iXPos, iYPos));
}
updateTime();
}
void ZJHOpenResultScene::updateTime()
{
time_t t = time(NULL);
struct tm* tt = localtime(&t);
char timeString[32] = { 0 };
sprintf(timeString, "%04d-%02d-%02d %02d:%02d", tt->tm_year + 1900, tt->tm_mon + 1, tt->tm_mday, tt->tm_hour, tt->tm_min);
_txtTime->setString(timeString);
}