1021 lines
27 KiB
C++
1021 lines
27 KiB
C++
#include "GameUnionScene.h"
|
|
#include "GlobalJosn.h"
|
|
#include "GlobalUserInfo.h"
|
|
#include "PopScene.h"
|
|
#include "Utility.h"
|
|
#include "UserInfo.h"
|
|
#include "ImagicDownManager.h"
|
|
#include "WN_GameScene.h"
|
|
#include "DDZ_GameScene.h"
|
|
#include "NN_GameScene.h"
|
|
#include "DZ_GameScene.h"
|
|
#include "13S_GameScene.h"
|
|
#include "ZJH_GameScene.h"
|
|
#include "PDK_GameScene.h"
|
|
#include "JniFun.h"
|
|
|
|
GameUnionScene::GameUnionScene()
|
|
{
|
|
m_ImageView = nullptr;
|
|
m_ImageTop = nullptr;
|
|
m_CreateNode = nullptr;
|
|
m_UnionList = nullptr;
|
|
m_RoomList = nullptr;
|
|
m_DaikaiList = nullptr;
|
|
|
|
//m_btnAuto = nullptr;
|
|
m_btnRefresh = nullptr;
|
|
m_btnUnionItem0 = nullptr;
|
|
m_btnRoomItem0 = nullptr;
|
|
m_btnRoomItem1 = nullptr;
|
|
//m_btnRoomItem2 = nullptr;
|
|
//m_btnRoomItem3 = nullptr;
|
|
//m_btnRoomItem4 = nullptr;
|
|
//m_btnRoomItem5 = nullptr;
|
|
|
|
m_DaikaiItem = nullptr;
|
|
m_btnCreate = nullptr;
|
|
|
|
//m_chRoomInfo = nullptr;
|
|
//m_chAutoInfo = nullptr;
|
|
|
|
m_nRefreshErr = 0;
|
|
m_isRefreshing = false;
|
|
//m_isPresident = false;
|
|
m_dwSelectUnionCode = 0;
|
|
m_cbUnionGoldOpen = 0;
|
|
//zeromemory(m_btnUnionItem, sizeof(m_btnUnionItem));
|
|
}
|
|
|
|
GameUnionScene::~GameUnionScene()
|
|
{
|
|
|
|
}
|
|
|
|
bool GameUnionScene::init()
|
|
{
|
|
if (!Node::init())
|
|
{
|
|
return false;
|
|
};
|
|
|
|
auto rootPanel = CSLoader::createNode("Platform/UnionScene.csb");
|
|
CC_ASSERT(rootPanel != nullptr);
|
|
this->addChild(rootPanel);
|
|
|
|
m_ImageView = (ImageView*)rootPanel->getChildByName("Imagebg");
|
|
CC_ASSERT(nullptr != m_ImageView);
|
|
|
|
// 节点;
|
|
m_btnUnionItem0 = (Button*)m_ImageView->getChildByName("btnItem_0");
|
|
CC_ASSERT(nullptr != m_btnUnionItem0);
|
|
m_btnUnionItem0->setVisible(false);
|
|
|
|
//m_btnRoomItem2 = (Button*)m_ImageView->getChildByName("btnRoomItem2");
|
|
//CC_ASSERT(nullptr != m_btnRoomItem2);
|
|
//m_btnRoomItem2->setVisible(false);
|
|
|
|
//m_btnRoomItem3 = (Button*)m_ImageView->getChildByName("btnRoomItem3");
|
|
//CC_ASSERT(nullptr != m_btnRoomItem3);
|
|
//m_btnRoomItem3->setVisible(false);
|
|
|
|
//m_btnRoomItem4 = (Button*)m_ImageView->getChildByName("btnRoomItem4");
|
|
//CC_ASSERT(nullptr != m_btnRoomItem4);
|
|
//m_btnRoomItem4->setVisible(false);
|
|
|
|
//m_btnRoomItem5 = (Button*)m_ImageView->getChildByName("btnRoomItem5");
|
|
//CC_ASSERT(nullptr != m_btnRoomItem5);
|
|
//m_btnRoomItem5->setVisible(false);
|
|
|
|
m_btnRoomItem0 = (Button*)m_ImageView->getChildByName("btnRoomItem0");
|
|
CC_ASSERT(nullptr != m_btnRoomItem0);
|
|
m_btnRoomItem0->setVisible(false);
|
|
|
|
m_btnRoomItem1 = (Button*)m_ImageView->getChildByName("btnRoomItem1");
|
|
CC_ASSERT(nullptr != m_btnRoomItem1);
|
|
m_btnRoomItem1->setVisible(false);
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
std::string strkey = StringUtils::format("imghead_%d", i);
|
|
|
|
auto sp5 = (ImageView*)m_btnRoomItem1->getChildByName(strkey);
|
|
assert(sp5 != nullptr);
|
|
sp5->setVisible(false);
|
|
|
|
auto sp0 = (ImageView*)m_btnRoomItem0->getChildByName(strkey);
|
|
assert(sp0 != nullptr);
|
|
sp0->setVisible(false);
|
|
|
|
//if (i < 4)
|
|
//{
|
|
// auto sp4 = (ImageView*)m_btnRoomItem4->getChildByName(strkey);
|
|
// assert(sp4 != nullptr);
|
|
// sp4->setVisible(false);
|
|
//}
|
|
|
|
//if (i < 3)
|
|
//{
|
|
// auto sp3 = (ImageView*)m_btnRoomItem3->getChildByName(strkey);
|
|
// assert(sp3 != nullptr);
|
|
// sp3->setVisible(false);
|
|
//}
|
|
|
|
//if (i < 2)
|
|
//{
|
|
// auto sp2 = (ImageView*)m_btnRoomItem2->getChildByName(strkey);
|
|
// assert(sp2 != nullptr);
|
|
// sp2->setVisible(false);
|
|
//}
|
|
}
|
|
|
|
m_DaikaiItem = (ImageView*)m_ImageView->getChildByName("daiKaiitem");
|
|
CC_ASSERT(nullptr != m_DaikaiItem);
|
|
m_DaikaiItem->setVisible(false);
|
|
|
|
// 信息头;
|
|
m_PanelTip = (Layout*)m_ImageView->getChildByName("PanelTip");
|
|
CC_ASSERT(nullptr != m_PanelTip);
|
|
m_PanelTip->setVisible(false);
|
|
|
|
m_txtGameInfo = (Text*)m_PanelTip->getChildByName("txtGameInfo");
|
|
CC_ASSERT(nullptr != m_txtGameInfo);
|
|
m_txtGameInfo->setString("");
|
|
|
|
// 房间列表;
|
|
m_txtRoomList = (Text*)m_PanelTip->getChildByName("txtRoomList");
|
|
CC_ASSERT(nullptr != m_txtRoomList);
|
|
m_txtRoomList->setVisible(false);
|
|
m_txtRoomList->addClickEventListener([this](Ref*){
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
|
|
m_RoomList->setVisible(true);
|
|
m_DaikaiList->setVisible(false);
|
|
|
|
m_txtAuto->setVisible(false);
|
|
m_txtRoomList->setVisible(false);
|
|
|
|
m_btnRefresh->setVisible(true);
|
|
m_txtAutoList->setVisible(true);
|
|
|
|
RequsetUnionRoomList();
|
|
});
|
|
|
|
// 代开管理;
|
|
m_txtAutoList = (Text*)m_PanelTip->getChildByName("txtAutoList");
|
|
CC_ASSERT(nullptr != m_txtAutoList);
|
|
m_txtAutoList->setVisible(false);
|
|
m_txtAutoList->addClickEventListener([this](Ref*){
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
|
|
m_RoomList->setVisible(false);
|
|
m_DaikaiList->setVisible(true);
|
|
|
|
m_txtAuto->setVisible(true);
|
|
m_txtRoomList->setVisible(true);
|
|
|
|
m_btnRefresh->setVisible(false);
|
|
m_txtAutoList->setVisible(false);
|
|
|
|
if (m_DaikaiList->isVisible())
|
|
{
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|
EventCustom event(Get_AUTO_ROOM_INFO);
|
|
dispatcher->dispatchEvent(&event);
|
|
}
|
|
});
|
|
|
|
// 代开房间;
|
|
m_txtAuto = (Text*)m_PanelTip->getChildByName("txtAuto");
|
|
CC_ASSERT(nullptr != m_txtAuto);
|
|
m_txtAuto->setVisible(false);
|
|
m_txtAuto->addClickEventListener([this](Ref*){
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
|
|
if (m_dwSelectUnionCode == 0) return;
|
|
|
|
// 打开创建面板;
|
|
if (m_CreateNode == nullptr)
|
|
{
|
|
m_CreateNode = CreateScene::create();
|
|
this->addChild(m_CreateNode);
|
|
}
|
|
|
|
if (m_CreateNode)
|
|
{
|
|
m_CreateNode->pushScene(CDT_CREATE_AUTO, m_dwSelectUnionCode, m_cbUnionGoldOpen);
|
|
}
|
|
|
|
//// 打开创建面板;
|
|
//if (m_CreateNode == nullptr)
|
|
//{
|
|
// m_CreateNode = CreateScene::create();
|
|
// this->addChild(m_CreateNode);
|
|
//}
|
|
|
|
//if (m_CreateNode)
|
|
//{
|
|
// m_CreateNode->pushScene(CDT_CREATE_AUTO);
|
|
//}
|
|
});
|
|
|
|
// 刷新按钮
|
|
m_btnRefresh = (Button*)m_PanelTip->getChildByName("btnRefresh");
|
|
CC_ASSERT(nullptr != m_btnRefresh);
|
|
m_btnRefresh->addClickEventListener([this](Ref* ref){
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
|
|
RequsetUnionRoomList();
|
|
});
|
|
|
|
// 列表;
|
|
m_UnionList = (ListView*)m_ImageView->getChildByName("UnionList");
|
|
CC_ASSERT(nullptr != m_UnionList);
|
|
|
|
m_RoomList = (ScrollView*)m_ImageView->getChildByName("RoomList");
|
|
CC_ASSERT(nullptr != m_RoomList);
|
|
|
|
m_DaikaiList = (ScrollView*)m_ImageView->getChildByName("DaikaiList");
|
|
CC_ASSERT(nullptr != m_DaikaiList);
|
|
m_DaikaiList->setVisible(false);
|
|
|
|
// 顶部;
|
|
m_ImageTop = (ImageView*)rootPanel->getChildByName("top");
|
|
CC_ASSERT(nullptr != m_ImageTop);
|
|
|
|
m_btnCreate = (Button*)m_ImageTop->getChildByName("btnCreate");
|
|
CC_ASSERT(nullptr != m_btnCreate);
|
|
m_btnCreate->setVisible(false);
|
|
m_btnCreate->addClickEventListener([this](Ref*){
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
|
|
if (m_dwSelectUnionCode == 0) return;
|
|
|
|
// 打开创建面板;
|
|
if (m_CreateNode == nullptr)
|
|
{
|
|
m_CreateNode = CreateScene::create();
|
|
this->addChild(m_CreateNode);
|
|
}
|
|
|
|
if (m_CreateNode)
|
|
{
|
|
m_CreateNode->pushScene(CDT_CREATE_UNION, m_dwSelectUnionCode, m_cbUnionGoldOpen);
|
|
}
|
|
});
|
|
|
|
//获取关闭按钮
|
|
auto btnClose = (Button*)m_ImageTop->getChildByName("btnClose");
|
|
CC_ASSERT(btnClose != nullptr);
|
|
|
|
//注册关闭按钮事件
|
|
btnClose->addClickEventListener(CC_CALLBACK_1(GameUnionScene::onClickClose, this));
|
|
|
|
//对手机返回键的监听
|
|
auto keyListener = EventListenerKeyboard::create();
|
|
//和回调函数绑定
|
|
keyListener->onKeyReleased = CC_CALLBACK_2(GameUnionScene::onKeyReleased, this);
|
|
//添加到事件分发器中
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);
|
|
|
|
return true;
|
|
}
|
|
|
|
void GameUnionScene::onEnter()
|
|
{
|
|
Node::onEnter();
|
|
}
|
|
|
|
void GameUnionScene::onEnterTransitionDidFinish()
|
|
{
|
|
Node::onEnterTransitionDidFinish();
|
|
}
|
|
|
|
void GameUnionScene::onExit()
|
|
{
|
|
Node::onExit();
|
|
}
|
|
|
|
void GameUnionScene::pushScene()
|
|
{
|
|
m_isRefreshing = false;
|
|
this->setVisible(true);
|
|
|
|
// 界面控制;
|
|
if (m_DaikaiList->isVisible())
|
|
{
|
|
m_DaikaiList->setVisible(false);
|
|
m_txtRoomList->setVisible(false);
|
|
m_txtAuto->setVisible(false);
|
|
|
|
m_RoomList->setVisible(true);
|
|
m_btnRefresh->setVisible(true);
|
|
}
|
|
|
|
float height = Director::getInstance()->getWinSize().height;
|
|
|
|
if (m_ImageTop)
|
|
{
|
|
float top_h = m_ImageTop->getContentSize().height;
|
|
|
|
m_ImageTop->setPositionY(height + top_h/2);
|
|
m_ImageTop->runAction(MoveBy::create(0.2f, Vec2(0, 0 - top_h)));
|
|
}
|
|
|
|
if (m_ImageView)
|
|
{
|
|
float b_h = m_ImageView->getContentSize().height - 20;
|
|
|
|
m_ImageView->setPositionY(0);
|
|
m_ImageView->setOpacity(0);
|
|
|
|
auto act = MoveBy::create(0.2f, Vec2(0, b_h / 2));
|
|
auto spawn = Spawn::create(FadeIn::create(0.2f), act, nullptr);
|
|
|
|
m_ImageView->runAction(Sequence::create(spawn, CallFunc::create([&]()
|
|
{
|
|
LoadingScene::Instance().show(this);
|
|
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|
EventCustom event(INPUT_UNION_ID);
|
|
dispatcher->dispatchEvent(&event);
|
|
|
|
}), nullptr));
|
|
}
|
|
}
|
|
|
|
void GameUnionScene::popScene()
|
|
{
|
|
float height = Director::getInstance()->getWinSize().height;
|
|
|
|
if (m_ImageTop)
|
|
{
|
|
float top_h = m_ImageTop->getContentSize().height;
|
|
m_ImageTop->runAction(MoveBy::create(0.2f, Vec2(0, top_h)));
|
|
}
|
|
|
|
if (m_ImageView)
|
|
{
|
|
float b_h = m_ImageView->getContentSize().height - 20;
|
|
|
|
auto act = MoveBy::create(0.2f, Vec2(0, 0 - b_h/2));
|
|
auto spawn = Spawn::create(FadeOut::create(0.2f), act, nullptr);
|
|
m_ImageView->runAction(Sequence::create(spawn, CallFunc::create([&]()
|
|
{
|
|
//this->removeFromParent();
|
|
this->setVisible(false);
|
|
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|
EventCustom event(Get_Union_Room_List);
|
|
|
|
CMD_GR_GetUnionRoomInfo getUnionRoom;
|
|
memset(&getUnionRoom, 0, sizeof(getUnionRoom));
|
|
getUnionRoom.dwUserID = UserInfo::getInstance()->getUserID();
|
|
getUnionRoom.dwUnionCode = m_dwSelectUnionCode;
|
|
event.setUserData(&getUnionRoom);
|
|
|
|
dispatcher->dispatchEvent(&event);
|
|
|
|
}), nullptr));
|
|
}
|
|
}
|
|
|
|
// 关闭弹窗;
|
|
void GameUnionScene::onClickClose(Ref*)
|
|
{
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
this->popScene();
|
|
}
|
|
|
|
//按键处理
|
|
void GameUnionScene::onKeyReleased(EventKeyboard::KeyCode keyCode, Event * pEvent)
|
|
{
|
|
//返回值处理
|
|
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
|
|
{
|
|
pEvent->stopPropagation();
|
|
|
|
onClickClose(nullptr);
|
|
}
|
|
}
|
|
|
|
// 显示工会列表;
|
|
void GameUnionScene::ShowUnionList(tagUnionAndGameList* pUnionAndGameList)
|
|
{
|
|
if (m_UnionList == nullptr) return;
|
|
if (pUnionAndGameList == nullptr) return;
|
|
|
|
m_UnionList->removeAllChildren();
|
|
//m_isPresident = false;
|
|
|
|
int iUnionCount = pUnionAndGameList->kUnionList.size();
|
|
// 没有工会;
|
|
if (iUnionCount <= 0)
|
|
{
|
|
m_PanelTip->setVisible(false);
|
|
m_btnCreate->setVisible(false);
|
|
LoadingScene::Instance().hide();
|
|
return;
|
|
}
|
|
|
|
uint32 dwMeUserID = CGlobalUserInfo::GetInstance()->getUserID();
|
|
|
|
std::string strUnionCode = StringUtils::format("UnionCode_%d", UserInfo::Instance().getGameID());
|
|
m_dwSelectUnionCode = UserDefault::getInstance()->getIntegerForKey(strUnionCode.c_str(), 0);
|
|
|
|
for (int i = 0; i < iUnionCount; i++)
|
|
{
|
|
tagUnionItem* pUnionItem = &pUnionAndGameList->kUnionList[i];
|
|
|
|
uint32 dwUnionUserID = pUnionItem->dwUserID;
|
|
uint32 dwUnionCode = pUnionItem->dwUnionCode;
|
|
uint8 cbUnionGoldOpen = pUnionItem->cbUnionGoldOpen;
|
|
uint8 cbUnionOpen = pUnionItem->cbUnionOpen;
|
|
|
|
// 默认选择第一个;
|
|
if (m_dwSelectUnionCode == 0)
|
|
{
|
|
m_dwSelectUnionCode = dwUnionCode;
|
|
}
|
|
|
|
Button* btnUnionItem = nullptr;
|
|
btnUnionItem = (Button*)m_btnUnionItem0->clone();
|
|
ASSERT(btnUnionItem != nullptr);
|
|
if (btnUnionItem == nullptr) break;
|
|
|
|
// 名称;
|
|
Text* txtUnionName = (Text*)btnUnionItem->getChildByName("GameName");
|
|
ASSERT(txtUnionName != nullptr);
|
|
std::string strUnionName = pUnionItem->szUnionName;
|
|
if (cbUnionGoldOpen == 1)
|
|
{
|
|
strUnionName += "-欢乐场";
|
|
}
|
|
txtUnionName->setString(utility::a_u8(strUnionName));
|
|
|
|
// 人数;
|
|
Text* txtPlayerCount = (Text*)btnUnionItem->getChildByName("PlayerCount");
|
|
ASSERT(txtPlayerCount != nullptr);
|
|
std::string strPlayerCount = StringUtils::format("%d人", pUnionItem->lPeople);
|
|
txtPlayerCount->setString(utility::a_u8(strPlayerCount.c_str()));
|
|
|
|
// 房卡;
|
|
Text* txtCardCount = (Text*)btnUnionItem->getChildByName("CardCount");
|
|
ASSERT(txtCardCount != nullptr);
|
|
std::string strCardCount = StringUtils::format("%d张", pUnionItem->lUnionCard);
|
|
txtCardCount->setString(utility::a_u8(strCardCount.c_str()));
|
|
txtCardCount->setVisible(dwUnionUserID == dwMeUserID);
|
|
|
|
btnUnionItem->addClickEventListener([this, dwUnionCode, cbUnionGoldOpen, dwUnionUserID, cbUnionOpen](Ref* ref){
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
|
|
Button* btnSelf = (Button*)ref;
|
|
if (btnSelf) btnSelf->loadTextureNormal("Platform/Set/set_btn_yichang2.png");
|
|
SaveSelectUnionCode(dwUnionCode);
|
|
|
|
auto children = m_UnionList->getChildren();
|
|
for (ssize_t i = 0; i < children.size(); i++)
|
|
{
|
|
Button* btn = static_cast<Button*>(children.at(i));
|
|
|
|
if (btn != nullptr && btnSelf != btn)
|
|
{
|
|
btn->loadTextureNormal("Platform/Set/set_btn_yichang1.png");
|
|
}
|
|
}
|
|
|
|
// 界面控制;
|
|
if (m_DaikaiList->isVisible())
|
|
{
|
|
m_DaikaiList->setVisible(false);
|
|
m_txtRoomList->setVisible(false);
|
|
m_txtAuto->setVisible(false);
|
|
|
|
m_RoomList->setVisible(true);
|
|
m_btnRefresh->setVisible(true);
|
|
}
|
|
|
|
// 自己是不是会长;
|
|
m_txtAutoList->setVisible(CGlobalUserInfo::GetInstance()->getUserID() == dwUnionUserID);
|
|
m_btnCreate->setVisible(cbUnionOpen == 1);
|
|
|
|
m_dwSelectUnionCode = dwUnionCode;
|
|
m_cbUnionGoldOpen = cbUnionGoldOpen;
|
|
|
|
RequsetUnionRoomList();
|
|
});
|
|
|
|
// 设置默认选择房间;
|
|
if (m_dwSelectUnionCode != 0 && m_dwSelectUnionCode == dwUnionCode)
|
|
{
|
|
// 自己是不是会长;
|
|
m_txtAutoList->setVisible(CGlobalUserInfo::GetInstance()->getUserID() == dwUnionUserID);
|
|
m_btnCreate->setVisible(cbUnionOpen == 1);
|
|
|
|
// 默认选择公会模式;
|
|
m_cbUnionGoldOpen = cbUnionGoldOpen;
|
|
|
|
btnUnionItem->loadTextureNormal("Platform/Set/set_btn_yichang2.png");
|
|
}
|
|
|
|
btnUnionItem->setVisible(true);
|
|
|
|
m_UnionList->pushBackCustomItem(btnUnionItem);
|
|
}
|
|
|
|
// 加载房间;
|
|
if (m_dwSelectUnionCode != 0 && !m_isRefreshing)
|
|
{
|
|
RequsetUnionRoomList(false);
|
|
}
|
|
else
|
|
{
|
|
LoadingScene::Instance().hide();
|
|
}
|
|
|
|
m_PanelTip->setVisible(true);
|
|
m_btnCreate->setVisible(true);
|
|
|
|
// 启动定时器;
|
|
startUnionRoomTime();
|
|
}
|
|
|
|
void GameUnionScene::ShowRoomList(tagRoomItemList* pRoomItemList)
|
|
{
|
|
LoadingScene::Instance().hide();
|
|
|
|
m_isRefreshing = false;
|
|
if (m_RoomList == nullptr) return;
|
|
if (pRoomItemList == nullptr) return;
|
|
|
|
m_RoomList->removeAllChildren();
|
|
|
|
// 正在游戏房间数量;
|
|
if (m_txtGameInfo != nullptr)
|
|
{
|
|
std::string strGameInfo = StringUtils::format("%d个房间正在游戏", pRoomItemList->cbPlayRoomCount);
|
|
m_txtGameInfo->setString(utility::a_u8(strGameInfo));
|
|
}
|
|
|
|
// 房间列表;
|
|
int iUnionCount = pRoomItemList->kList.size();
|
|
int btnRoomItemH = m_btnRoomItem0->getContentSize().height + 20;
|
|
|
|
// 列表调整;
|
|
Size svSize = m_RoomList->getInnerContainerSize();
|
|
if (iUnionCount > 12)
|
|
{
|
|
svSize.height = ceil(iUnionCount / 3.0l) * (btnRoomItemH + 20);
|
|
m_RoomList->setInnerContainerSize(svSize);
|
|
}
|
|
else
|
|
{
|
|
svSize.height = m_RoomList->getContentSize().height;
|
|
m_RoomList->setInnerContainerSize(svSize);
|
|
}
|
|
|
|
uint8 cbChairCount = 0;
|
|
//uint32 dwLastUnionCode = 0;
|
|
|
|
bool isWhiteColor = false;
|
|
|
|
long long llNetWorkTime = JniFun::getCurrTime() / 1000;
|
|
|
|
for (int i = 0; i < iUnionCount; i++)
|
|
{
|
|
tagRoomItem* pUnionRoomItem = &pRoomItemList->kList[i];
|
|
|
|
uint8 cbUnionGoldOpen = pUnionRoomItem->cbUnionGoldOpen;
|
|
uint32 dwRoomID = pUnionRoomItem->dwRoomID;
|
|
uint8 cbGameStatus = pUnionRoomItem->cbGameOK;
|
|
|
|
std::string strGameName = "";
|
|
if (DDZ_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = DDZ_GAME_NAME;
|
|
cbChairCount = DDZ_GAME_PLAYER;
|
|
}
|
|
else if (WN_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = WN_GAME_NAME;
|
|
cbChairCount = WNMJ_SPACE::WN_GameScene::GetRealChairCount(pUnionRoomItem->dwGameRule);
|
|
}
|
|
else if (NN_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = NN_GAME_NAME;
|
|
cbChairCount = NN_GAME_PLAYER;
|
|
}
|
|
else if (SSS_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = SSS_GAME_NAME;
|
|
cbChairCount = SSS_GAME_PLAYER;
|
|
}
|
|
else if (ZJH_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = ZJH_GAME_NAME;
|
|
cbChairCount = ZJH_GAME_PLAYER;
|
|
}
|
|
else if (DZ_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = DZ_GAME_NAME;
|
|
cbChairCount = DZ_GAME_PLAYER;
|
|
}
|
|
else if (PDK_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = PDK_GAME_NAME;
|
|
cbChairCount = PDK_SPACE::PDKGameScene::getRealChairCount(pUnionRoomItem->dwGameRule);
|
|
}
|
|
|
|
Button* btnRoomItem = nullptr;
|
|
|
|
//switch (cbChairCount)
|
|
//{
|
|
//case 5:
|
|
// btnRoomItem = (Button*)m_btnRoomItem5->clone();
|
|
// break;
|
|
//case 4:
|
|
// btnRoomItem = (Button*)m_btnRoomItem4->clone();
|
|
// break;
|
|
//case 3:
|
|
// btnRoomItem = (Button*)m_btnRoomItem3->clone();
|
|
// break;
|
|
//case 2:
|
|
// btnRoomItem = (Button*)m_btnRoomItem2->clone();
|
|
// break;
|
|
//default:
|
|
// break;
|
|
//}
|
|
|
|
btnRoomItem = (Button*)m_btnRoomItem0->clone();
|
|
|
|
//// 欢乐场;
|
|
//if (1 == cbUnionGoldOpen)
|
|
//{
|
|
// btnRoomItem = (Button*)m_btnRoomItem0->clone();
|
|
//}
|
|
//else
|
|
//{
|
|
// btnRoomItem = (Button*)m_btnRoomItem1->clone();
|
|
//}
|
|
|
|
ASSERT(btnRoomItem != nullptr);
|
|
if (btnRoomItem == nullptr) break;
|
|
|
|
// 游戏名称;
|
|
Text* txtGameName = (Text*)btnRoomItem->getChildByName("txtGameName");
|
|
ASSERT(txtGameName != nullptr);
|
|
txtGameName->setString(utility::a_u8(strGameName));
|
|
|
|
// 游戏类型;
|
|
Text* txtGameType = (Text*)btnRoomItem->getChildByName("txtGameType");
|
|
ASSERT(txtGameType != nullptr);
|
|
|
|
std::string strGameType = "";
|
|
// 欢乐场;
|
|
if (1 == cbUnionGoldOpen)
|
|
{
|
|
strGameType = "欢乐场";
|
|
}
|
|
else
|
|
{
|
|
strGameType = StringUtils::format("%d分", pUnionRoomItem->cbBaseScore);
|
|
}
|
|
txtGameType->setString(utility::a_u8(strGameType));
|
|
|
|
// 工会名称;
|
|
Text* txtUnionName = (Text*)btnRoomItem->getChildByName("txtUnoinName");
|
|
ASSERT(txtUnionName != nullptr);
|
|
std::string strUnionName = pUnionRoomItem->szUnionName;
|
|
txtUnionName->setString(utility::a_u8(strUnionName));
|
|
|
|
// 已游戏局数
|
|
uint8 cbPlaycout = pUnionRoomItem->cbPlayCout;
|
|
|
|
// 房间信息;
|
|
Text* txtRoomInfo = (Text*)btnRoomItem->getChildByName("txtRoomInfo");
|
|
ASSERT(txtRoomInfo != nullptr);
|
|
|
|
Text* txtBaseScore = (Text*)btnRoomItem->getChildByName("txtBaseScore");
|
|
ASSERT(txtBaseScore != nullptr);
|
|
|
|
if (cbGameStatus == 2)
|
|
{
|
|
cbPlaycout++;
|
|
|
|
//txtRoomInfo->setString(utility::a_u8("正在游戏中..."));
|
|
//txtRoomInfo->setTextColor(Color4B(0xDB, 0x08, 0x93, 0xff));
|
|
}
|
|
//else
|
|
//{
|
|
// std::string strRoomInfo = StringUtils::format("房号:%d", dwRoomID);
|
|
// txtRoomInfo->setString(utility::a_u8(strRoomInfo));
|
|
// txtRoomInfo->setTextColor(Color4B(0x1a, 0x1a, 0x1a, 0xff));
|
|
//}
|
|
|
|
if (cbPlaycout > pUnionRoomItem->cbPlayCoutIdex)
|
|
{
|
|
cbPlaycout = pUnionRoomItem->cbPlayCoutIdex;
|
|
}
|
|
|
|
std::string strRoomInfo = "";
|
|
std::string strBaseScore = "";
|
|
|
|
// 欢乐场;
|
|
if (1 == cbUnionGoldOpen)
|
|
{
|
|
strRoomInfo = StringUtils::format("房号:%d,%d局", dwRoomID, cbPlaycout);
|
|
strBaseScore = StringUtils::format("底分:%d分", pUnionRoomItem->cbBaseScore);
|
|
}
|
|
else
|
|
{
|
|
strRoomInfo = StringUtils::format("房号:%d,%d局", dwRoomID, cbPlaycout);
|
|
}
|
|
txtRoomInfo->setString(utility::a_u8(strRoomInfo));
|
|
txtBaseScore->setString(utility::a_u8(strBaseScore));
|
|
|
|
// 游戏名称;
|
|
Text* txtGameRule = (Text*)btnRoomItem->getChildByName("txtGameRule");
|
|
ASSERT(txtGameRule != nullptr);
|
|
|
|
if (cbGameStatus == 2)
|
|
{
|
|
txtGameRule->setString(utility::a_u8("正在游戏中..."));
|
|
txtGameRule->setTextColor(Color4B(0xDB, 0x08, 0x93, 0xff));
|
|
}
|
|
else
|
|
{
|
|
std::string strGameRule = getGameRule(pUnionRoomItem->wKindID, pUnionRoomItem->dwGameRule);
|
|
txtGameRule->setString(utility::a_u8(strGameRule));
|
|
txtGameRule->setTextColor(Color4B(0x1a, 0x1a, 0x1a, 0xff));
|
|
}
|
|
|
|
//// 欢乐场;
|
|
//if (1 == cbUnionGoldOpen)
|
|
//{
|
|
// std::string strGameScoreName = StringUtils::format("%s-欢乐场,%d/%d局", strGameName.c_str(), cbPlaycout, pUnionRoomItem->cbPlayCoutIdex);
|
|
// txtGameName->setString(utility::a_u8(strGameScoreName));
|
|
//}
|
|
//else
|
|
//{
|
|
// std::string strGameScoreName = StringUtils::format("%d分%s,%d/%d局", pUnionRoomItem->cbBaseScore, strGameName.c_str(), cbPlaycout, pUnionRoomItem->cbPlayCoutIdex);
|
|
// txtGameName->setString(utility::a_u8(strGameScoreName));
|
|
//}
|
|
|
|
btnRoomItem->addClickEventListener([this, dwRoomID, cbGameStatus](Ref* ref){
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
|
|
__Integer* pnNum = __Integer::create(dwRoomID);
|
|
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|
EventCustom event(JOIN_PRIVATE_ROOM_EVENT);
|
|
event.setUserData(pnNum);
|
|
dispatcher->dispatchEvent(&event);
|
|
});
|
|
|
|
// 玩家头像;
|
|
for (int nIndex = 0; nIndex < cbChairCount; nIndex++)
|
|
{
|
|
std::string strkey = StringUtils::format("imghead_%d", nIndex);
|
|
auto sphead = (ImageView*)btnRoomItem->getChildByName(strkey);
|
|
if (sphead != nullptr)
|
|
{
|
|
uint32 dwUserID = pUnionRoomItem->dwUserIDs[nIndex];
|
|
if (dwUserID != 0 && dwUserID != INVALID_CHAIR)
|
|
{
|
|
std::string strHttp = StringUtils::format(HEAD_HTTP_ADDRESS, dwUserID);
|
|
ImagicDownManager::Instance().addDown(sphead, strHttp, dwUserID, true);
|
|
}
|
|
|
|
sphead->setVisible(true);
|
|
}
|
|
}
|
|
|
|
btnRoomItem->setVisible(true);
|
|
|
|
// 节点调整位置;
|
|
float x = (btnRoomItem->getContentSize().width + 20)*(i % 3);
|
|
float y = svSize.height - btnRoomItemH - (i / 3)*(btnRoomItemH + 20);
|
|
|
|
btnRoomItem->setPositionX(x);
|
|
btnRoomItem->setPositionY(y);
|
|
m_RoomList->addChild(btnRoomItem);
|
|
}
|
|
}
|
|
|
|
void GameUnionScene::ShowAutoRoomList(tagAutoRoomItemList* pRoomItemList)
|
|
{
|
|
LoadingScene::Instance().hide();
|
|
if (m_DaikaiItem == nullptr) return;
|
|
if (m_DaikaiList == nullptr) return;
|
|
if (pRoomItemList == nullptr) return;
|
|
if (m_CreateNode != nullptr)m_CreateNode->setVisible(false);
|
|
|
|
m_DaikaiList->removeAllChildren();
|
|
|
|
int iUnionCount = pRoomItemList->kList.size();
|
|
int iItemheight = m_DaikaiItem->getContentSize().height + 5;
|
|
|
|
// 列表调整;
|
|
Size svSize = m_DaikaiList->getInnerContainerSize();
|
|
if (iUnionCount > 3)
|
|
{
|
|
svSize.height = iItemheight * iUnionCount;
|
|
m_DaikaiList->setInnerContainerSize(svSize);
|
|
}
|
|
|
|
for (int i = 0; i < iUnionCount; i++)
|
|
{
|
|
tagAutoRoomItem* pUnionRoomItem = &pRoomItemList->kList[i];
|
|
|
|
uint32 dwIndex = pUnionRoomItem->dwIndex;
|
|
uint16 wServerID = pUnionRoomItem->wServerID;
|
|
uint8 cbUnionGoldOpen = pUnionRoomItem->cbUnionGoldOpen;
|
|
|
|
ImageView* dkItem = (ImageView*)m_DaikaiItem->clone();
|
|
if (dkItem == nullptr) break;
|
|
dkItem->setVisible(true);
|
|
|
|
// 工会名称;
|
|
Text* txtUnionName = (Text*)dkItem->getChildByName("txtUnionName");
|
|
ASSERT(txtUnionName != nullptr);
|
|
std::string strUnionName = StringUtils::format("[%s", pUnionRoomItem->szUnionName);
|
|
if (1 == cbUnionGoldOpen)
|
|
{
|
|
strUnionName += "-欢乐场]";
|
|
}
|
|
else
|
|
{
|
|
strUnionName += "]";
|
|
}
|
|
txtUnionName->setString(utility::a_u8(strUnionName));
|
|
|
|
// 创建时间;
|
|
Text* txtCreateTime = (Text*)dkItem->getChildByName("txtCreateTime");
|
|
ASSERT(txtCreateTime != nullptr);
|
|
txtCreateTime->setString(utility::a_u8(pUnionRoomItem->szCreateTime));
|
|
|
|
// 游戏名称;
|
|
Text* txtGameName = (Text*)dkItem->getChildByName("txtGameName");
|
|
ASSERT(txtGameName != nullptr);
|
|
std::string strGameName="";
|
|
if (DDZ_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = DDZ_GAME_NAME;
|
|
}
|
|
else if (WN_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = WN_GAME_NAME;
|
|
}
|
|
else if (NN_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = NN_GAME_NAME;
|
|
}
|
|
else if (SSS_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = SSS_GAME_NAME;
|
|
}
|
|
else if (ZJH_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = ZJH_GAME_NAME;
|
|
}
|
|
else if (DZ_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = DZ_GAME_NAME;
|
|
}
|
|
else if (PDK_KIND_ID == pUnionRoomItem->wKindID)
|
|
{
|
|
strGameName = PDK_GAME_NAME;
|
|
}
|
|
txtGameName->setString(utility::a_u8(strGameName));
|
|
|
|
// 游戏规则;
|
|
Text* txtGameRule = (Text*)dkItem->getChildByName("txtGameRule");
|
|
ASSERT(txtGameRule != nullptr);
|
|
std::string strGameRule = getGameRule(pUnionRoomItem->wKindID, pUnionRoomItem->dwGameRule);
|
|
std::string strRoomInfo = StringUtils::format("%d局,%d分,%s", pUnionRoomItem->cbPlayCout, pUnionRoomItem->cbBaseScore, strGameRule.c_str());;
|
|
txtGameRule->setString(utility::a_u8(strRoomInfo));
|
|
|
|
// 删除按钮;
|
|
Button* btnCanel = (Button*)dkItem->getChildByName("btnCancel");
|
|
ASSERT(btnCanel != nullptr);
|
|
btnCanel->addClickEventListener([this, dwIndex, wServerID](Ref* ref){
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|
EventCustom event(DEL_AUTO_ROOM_EVENT);
|
|
|
|
CMD_GP_DelAutoRoomInfo del;
|
|
del.dwIndex = dwIndex;
|
|
del.wServerID = wServerID;
|
|
event.setUserData(&del);
|
|
|
|
dispatcher->dispatchEvent(&event);
|
|
});
|
|
|
|
// 节点调整位置;
|
|
float y = svSize.height - iItemheight * (i+1);
|
|
dkItem->setPositionX(0);
|
|
dkItem->setPositionY(y);
|
|
m_DaikaiList->addChild(dkItem);
|
|
}
|
|
}
|
|
|
|
void GameUnionScene::HideCreateNode()
|
|
{
|
|
if (m_CreateNode == nullptr) return;
|
|
|
|
if (m_CreateNode->isVisible())
|
|
{
|
|
m_CreateNode->setVisible(false);
|
|
}
|
|
|
|
this->setVisible(false);
|
|
}
|
|
|
|
// 定时刷新列表;
|
|
void GameUnionScene::startUnionRoomTime()
|
|
{
|
|
// 先停止;
|
|
m_PanelTip->stopAllActions();
|
|
|
|
int nRefreshTime = GlobalJosn::getInstance()->GetRefreshTime();
|
|
|
|
// 再启动;
|
|
auto act = Sequence::createWithTwoActions(DelayTime::create(nRefreshTime), CallFunc::create([this](){
|
|
RequsetUnionRoomList(false);
|
|
}));
|
|
|
|
auto seq = RepeatForever::create(act);
|
|
m_PanelTip->runAction(seq);
|
|
}
|
|
|
|
void GameUnionScene::RequsetUnionRoomList(bool isLoading /*= true*/)
|
|
{
|
|
if (this->isVisible() && m_RoomList->isVisible() && m_dwSelectUnionCode > 0 && m_dwSelectUnionCode < 100000000)
|
|
{
|
|
// 连续三次刷新失败,强制刷新;
|
|
if (m_isRefreshing && m_nRefreshErr < 3)
|
|
{
|
|
m_nRefreshErr++;
|
|
return;
|
|
}
|
|
|
|
if (isLoading) LoadingScene::Instance().show(this);
|
|
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|
EventCustom event(Get_Union_Room_List);
|
|
|
|
CMD_GR_GetUnionRoomInfo getUnionRoom;
|
|
memset(&getUnionRoom, 0, sizeof(getUnionRoom));
|
|
getUnionRoom.dwUserID = UserInfo::getInstance()->getUserID();
|
|
getUnionRoom.dwUnionCode = m_dwSelectUnionCode;
|
|
event.setUserData(&getUnionRoom);
|
|
|
|
dispatcher->dispatchEvent(&event);
|
|
|
|
m_isRefreshing = true;
|
|
m_nRefreshErr = 0;
|
|
}
|
|
}
|
|
|
|
void GameUnionScene::SaveSelectUnionCode(uint32 dwUnionCode)
|
|
{
|
|
std::string strUnionCode = StringUtils::format("UnionCode_%d", UserInfo::Instance().getGameID());
|
|
UserDefault::getInstance()->setIntegerForKey(strUnionCode.c_str(), dwUnionCode);
|
|
}
|
|
|
|
std::string GameUnionScene::getGameRule(uint16 wKindID, uint32 dwGameRule)
|
|
{
|
|
std::string strGameRule;
|
|
|
|
if (DDZ_KIND_ID == wKindID)
|
|
{
|
|
strGameRule = DDZ_SPACE::DDZGameScene::getGameRule(dwGameRule);
|
|
}
|
|
else if (WN_KIND_ID == wKindID)
|
|
{
|
|
strGameRule = WNMJ_SPACE::WN_GameScene::getGameRule(dwGameRule);
|
|
}
|
|
else if (NN_KIND_ID == wKindID)
|
|
{
|
|
strGameRule = NiuNiu_SPACE::NNGameScene::getGameRule(dwGameRule);
|
|
}
|
|
else if (SSS_KIND_ID == wKindID)
|
|
{
|
|
strGameRule = SSS_SPACE::SSSGameScene::getGameRule(dwGameRule);
|
|
}
|
|
else if (ZJH_KIND_ID == wKindID)
|
|
{
|
|
strGameRule = ZJH_SPACE::ZJHGameScene::getGameRule(dwGameRule);
|
|
}
|
|
else if (DZ_KIND_ID == wKindID)
|
|
{
|
|
strGameRule = DZ_SPACE::DZGameScene::getGameRule(dwGameRule);
|
|
}
|
|
else if (PDK_KIND_ID == wKindID)
|
|
{
|
|
strGameRule = PDK_SPACE::PDKGameScene::getGameRule(dwGameRule);
|
|
}
|
|
|
|
return strGameRule;
|
|
} |