createRoom.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import GameConstant from 'GameConstant'
  2. var Global = require("Global");
  3. var BaseDefine = require("BaseDefine");
  4. var UIHelper = require("UIHelper");
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {//局数 规则 人数 支付方式
  8. _mGameBtnNodeObj:null, //存放游戏选择按钮节点,当服务器都开启时,此结构体为空
  9. mGameListContent: cc.Node,
  10. _mPlayCoutIdex: null, //局数
  11. _mPlayPersonCoutIdex: null, //人数
  12. _mPlayRulesIdex: null, //规则
  13. _bPYQ:false,
  14. _pyqID:0,
  15. _userID:0,
  16. _buildType: 2, //正常,AA
  17. },
  18. onLoad :function() {
  19. UIHelper.addButtonListener(this.node.getChildByName("TopInfo").getChildByName("btn_createClose"), this.node, "createRoom", "onBtnCloseClicked");
  20. UIHelper.addButtonListener(this.node.getChildByName("TopInfo").getChildByName("playerFK"), cc.find("Canvas"), "homeStart", "onClickRoomCard","FK");
  21. this.node.active = false;
  22. this._mGameBtnNodeObj = {};
  23. },
  24. onBtnCloseClicked :function(){
  25. cc.vv.GetHallScript().playButtonEffect("close");
  26. this.node.active = false;
  27. cc.vv.GetHallScript().showAniBottomNode();
  28. },
  29. //创建房间入口
  30. showCreatRoom: function(bPYQ,pyqID,userID) {
  31. this.node.active = true;
  32. this._bPYQ = bPYQ;
  33. this._pyqID = pyqID;
  34. this._userID = userID;
  35. this.node.getChildByName("TopInfo").getChildByName("playerFK").getChildByName("fk").getComponent(cc.Label).string = cc.vv.globalUserInfo.getUserInsure();
  36. this.node.getChildByName("rootNode").getChildByName("DDZPanel").getComponent("RoomPanleDDZ").initRoom(bPYQ,pyqID,userID);
  37. this.node.getChildByName("rootNode").getChildByName("GJMJPanel").getComponent("RoomPanleGJMJ").initRoom(bPYQ,pyqID,userID);
  38. this.node.getChildByName("rootNode").getChildByName("LYCPanel").getComponent("RoomPanleLYC").initRoom(bPYQ,pyqID,userID);
  39. this.node.getChildByName("rootNode").getChildByName("XLCHPanel").getComponent("RoomPanleXLCH").initRoom(bPYQ,pyqID,userID);
  40. this.node.getChildByName("rootNode").getChildByName("XZDDPanel").getComponent("RoomPanleXZDD").initRoom(bPYQ,pyqID,userID);
  41. this.node.getChildByName("rootNode").getChildByName("PSPanel").getComponent("RoomPanlePS").initRoom(bPYQ,pyqID,userID);
  42. this.node.getChildByName("rootNode").getChildByName("JSMJPanel").getComponent("RoomPanleJSMJ").initRoom(bPYQ,pyqID,userID);
  43. this.node.getChildByName("rootNode").getChildByName("CTPKPanel").getComponent("RoomPanleCTPK").initRoom(bPYQ,pyqID,userID);
  44. this.node.getChildByName("rootNode").getChildByName("SPMJPanel").getComponent("RoomPanleSPMJ").initRoom(bPYQ,pyqID,userID);
  45. this.node.getChildByName("rootNode").getChildByName("SDYPKPanel").getComponent("RoomPanleSDYPK").initRoom(bPYQ,pyqID,userID);
  46. this.node.getChildByName("rootNode").getChildByName("QXZBPanel").getComponent("RoomPanleQXZB").initRoom(bPYQ,pyqID,userID);
  47. //根据服务器状态,显示创建房间显示状态
  48. this.setGameItemStateByServer();
  49. //选择游戏
  50. this.seleceGame(null, this.sureInitCurrentGame());
  51. var ani = this.node.getComponent(cc.Animation);
  52. if (ani) {
  53. ani.play();
  54. }
  55. //this.node.getChildByName("TopInfo").getComponent(cc.Animation).play();
  56. },
  57. //回收选择游戏按钮节点
  58. recycleGameBtnNode: function(gametype) {
  59. let content = this.node.getChildByName("rootNode").getChildByName("gameList").getChildByName("view").getChildByName("content");
  60. if (this._mGameBtnNodeObj[gametype]) return;
  61. var btn = content.getChildByName(gametype);
  62. if (btn) {
  63. this._mGameBtnNodeObj[gametype] = btn;
  64. btn.removeFromParent(false);
  65. }
  66. },
  67. //放出选择游戏按钮节点
  68. popGameBtnNode: function(gametype) {
  69. let gameBtnNode = this._mGameBtnNodeObj[gametype];
  70. if (gameBtnNode) {
  71. delete this._mGameBtnNodeObj[gametype];
  72. return gameBtnNode;
  73. }
  74. },
  75. //决定点开创建房间时显示哪个创建界面
  76. sureInitCurrentGame: function() {
  77. let currentGame = Global.getLocalStorageVaule("PrivateCurrentGame", "GJMJ");
  78. var gamekind = GameConstant.getGameKindIdByKey(currentGame);
  79. if (this.checkServering(gamekind)) {
  80. return currentGame;
  81. } else {
  82. for (let index = 0; index < GameConstant.Game_List.length; index++) {
  83. const element = GameConstant.Game_List[index];
  84. if (this.checkServering(element.KindId)) {
  85. currentGame = element.Key;
  86. }
  87. }
  88. }
  89. return currentGame;
  90. },
  91. //检查服务器开启状态
  92. checkServering: function(gamekind) {
  93. return cc.vv.serverListData.getGameServerByKind(gamekind, BaseDefine.GAME_GENRE_EDUCATE)
  94. },
  95. setGameItemStateByServerEX: function(key, gamekind) {
  96. var btnname = "Btn" + key;
  97. var panelname = key + "Panel";
  98. var panel = this.node.getChildByName("rootNode").getChildByName(panelname);
  99. if (panel) {
  100. var itemServer = this.checkServering(gamekind);
  101. if (itemServer) { //服务器开启
  102. panel.active = true;
  103. if (!this.mGameListContent.getChildByName(btnname)) {
  104. this.mGameListContent.addChild(this.popGameBtnNode(btnname), 0, btnname);
  105. }
  106. UIHelper.addButtonListener(this.mGameListContent.getChildByName(btnname), this.node, "createRoom", "seleceGame", key); //添加游戏选择按钮事件
  107. if (itemServer.GameKindItem.TypeID == 0) { //限时免费
  108. var playCntNode = panel.getChildByName("playCntNode").getChildByName("playCntGroup");
  109. for(var i = 0;i < playCntNode.children.length;i++){
  110. playCntNode.children[i].getChildByName("FK").active = false;
  111. playCntNode.children[i].getChildByName("freeFK").active = true;
  112. }
  113. panel.getChildByName("btn_freeCreate").active = true
  114. panel.getChildByName("btn_create").active = false
  115. }
  116. } else {
  117. panel.active = false;
  118. this.recycleGameBtnNode(btnname);
  119. }
  120. }
  121. },
  122. //根据服务器状态,显示创建房间显示状态
  123. setGameItemStateByServer: function() {
  124. GameConstant.Game_List.forEach(element => {
  125. this.setGameItemStateByServerEX(element.Key, element.KindId);
  126. });
  127. },
  128. //选择游戏
  129. seleceGame: function(event,optdata) {
  130. if (event) {
  131. cc.vv.GetHallScript().playButtonEffect("open");
  132. }
  133. this.setGameShow(optdata);
  134. if (event == null) {
  135. var content = this.node.getChildByName("rootNode").getChildByName("gameList").getChildByName("view").getChildByName("content");
  136. if (content.getChildByName("Btn" + optdata).getComponent(cc.Toggle).isChecked) {
  137. if(content.getChildByName("Btn" + optdata).y < 0 - this.node.getChildByName("rootNode").getChildByName("gameList").getChildByName("view").getContentSize().height)
  138. {
  139. this.node.getChildByName("rootNode").getChildByName("gameList").getComponent(cc.ScrollView).scrollToBottom(0.1);
  140. }
  141. }
  142. }
  143. },
  144. //设置游戏显示隐藏
  145. setGameShow: function(currentgame) {
  146. var content = this.node.getChildByName("rootNode").getChildByName("gameList").getChildByName("view").getChildByName("content");
  147. GameConstant.Game_List.forEach(element => {//element.Key
  148. var gameName = element.Key;
  149. var panel = this.node.getChildByName("rootNode").getChildByName(gameName + "Panel");
  150. if (panel) {
  151. if (currentgame == gameName) {
  152. panel.active = true;
  153. panel.getComponent("RoomPanle"+gameName).initRoom(this._bPYQ,this._pyqID,this._userID);
  154. if (content.getChildByName("Btn" + gameName)) {
  155. content.getChildByName("Btn" + gameName).getComponent(cc.Toggle).check();
  156. }
  157. } else {
  158. panel.active = false;
  159. }
  160. }
  161. });
  162. },
  163. });