Files
wnmj/Classes/Games/13S/13S_OpenResultScene.cpp
2026-02-13 14:34:15 +08:00

131 lines
3.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "13S_OpenResultScene.h"
#include "cocostudio/CocoStudio.h"
using namespace cocostudio;
SSSOpenResultScene::SSSOpenResultScene()
{
}
SSSOpenResultScene::~SSSOpenResultScene()
{
}
bool SSSOpenResultScene::init()
{
if (!Node::init())
{
return false;
}
// 加载界面数据;
auto rootNode = CSLoader::createNodeWithVisibleSize("Games/13S/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 SSSOpenResultScene::updateUIData(uint32 dwRoomID, std::vector<tagSSSOpenResultItem>* pAryItem, bool bUnionScore)
{
_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++)
{
tagSSSOpenResultItem* pData = &(pAryItem->at(i));
if (pData->lGameScore > lMaxScore)
{
lMaxScore = pData->lGameScore;
}
}
// 设置玩家信息;
for (size_t i = 0; i<nCount; i++)
{
tagSSSOpenResultItem* pData = &(pAryItem->at(i));
if (pData->lGameScore == lMaxScore)
{
pData->bBigWinner = true;
}
SSSOpenResultItem* pItem = SSSOpenResultItem::create();
pItem->initUIData(pData, bUnionScore);
_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 SSSOpenResultScene::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);
}