Table.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. cc.Class({
  2. extends: cc.BaseClass,
  3. properties: {
  4. },
  5. ctor: function () {
  6. this.mGameServerItem = null;
  7. this.mShowReLink = false;
  8. },
  9. onLoad: function () {
  10. cc.debug.setDisplayStats(false);
  11. FitSize(this.node);
  12. ShowO2I(this.node, 0.5);
  13. //设置背景
  14. this.m_gameNode = this.$("GameNode");
  15. this.m_BGSprite = this.m_gameNode.getComponent(cc.Sprite);
  16. this.m_bTipGPS = true;
  17. window.g_CntGameGPS = 0;
  18. this.schedule(this.NetworkHeartbeat, 5);
  19. this.$('BtInvite').active = false;
  20. this.m_Loading = this.$('loading');
  21. if (window.gGameBG == null) window.gGameBG = 'loading';
  22. // var bg = this.$('loading/logo@Sprite');
  23. // if (window.WPMJ==0){
  24. // cc.resources.load("Image/Login/bj/login-logo" , cc.SpriteFrame, function (err, spriteFrame) {
  25. // bg.spriteFrame = spriteFrame;
  26. // });
  27. // }else{
  28. // cc.resources.load("Image/Login/bj/logommh" , cc.SpriteFrame, function (err, spriteFrame) {
  29. // bg.spriteFrame = spriteFrame;
  30. // });
  31. // }
  32. if (window.WPMJ == 0) {
  33. this.$('loading/Logowp').active = true;
  34. this.$('loading/Logommh').active = false;
  35. } else {
  36. this.$('loading/Logowp').active = false;
  37. this.$('loading/Logommh').active = true;
  38. }
  39. },
  40. update: function (dt) {
  41. if (window.gGameBG == 'loading') {
  42. window.gGameBG = cc.gPreLoader.LoadRes(`${GameDef.BGPath}`, '' + GameDef.KIND_ID, function (res) {
  43. this.m_BGSprite.spriteFrame = res;
  44. }.bind(this));
  45. } else if (window.gGameBG instanceof cc.SpriteFrame) {
  46. this.m_BGSprite.spriteFrame = window.gGameBG;
  47. window.gGameBG = null;
  48. }
  49. },
  50. // use this for initialization
  51. start: function () {
  52. g_Launch = null;
  53. g_Login = null;
  54. g_Lobby = null;
  55. g_Table = this;
  56. g_CurScene = this;
  57. this.mGameServerItem = g_ServerListDataLast;
  58. console.log("房间列表:", this.mGameServerItem)
  59. this.m_ServerItem = this.node.getComponent("CServerItem")
  60. if (this.m_ServerItem == null) this.m_ServerItem = this.node.addComponent("CServerItem");
  61. var TableViewNode = new cc.Node('TableViewFrame');
  62. this.node.addChild(TableViewNode);
  63. this.m_TableViewFrame = TableViewNode.addComponent("TableViewFrame");
  64. this.m_ServerItem.SetServerItemSink(this);
  65. this.m_ServerItem.SetStringMessageSink(this);
  66. this.m_ServerItem.mTableViewFrame = this.m_TableViewFrame;
  67. this.m_TableViewFrame.SetServerItem(this.m_ServerItem);
  68. this.CreateKernel();
  69. window.isJoinGame = false;
  70. },
  71. InsertPromptString: function (pszString, iButtonType) {
  72. //提示信息
  73. this.ShowAlert(pszString);
  74. },
  75. OnAlertExitLogin: function (Res) {
  76. if (Res) this.ExitGameLogin();
  77. },
  78. InsertSystemString: function (pszString, iButtonType) {
  79. },
  80. InsertPromptStringAndClose: function (pszString, iButtonType) {
  81. //提示信息
  82. this.ShowAlert(pszString, Alert_Yes, "OnAlertExitLogin", this);
  83. },
  84. //登陆完成
  85. OnGRLogonFinish: function () {
  86. var pMySelfUserItem = this.m_ServerItem.GetMeUserItem();
  87. if (pMySelfUserItem.GetTableID() == INVALID_CHAIR) {
  88. if (g_ServerListDataLast.wServerType & (GAME_GENRE_PERSONAL | GAME_GENRE_PERSONAL_S | GAME_GENRE_PERSONAL_G)) {
  89. this.m_ServerItem.PerformEnterRoom();
  90. } else {
  91. this.m_ServerItem.PerformSitDownAction(this.mGameServerItem.wTableID, INVALID_CHAIR, false);
  92. }
  93. } else {
  94. this.m_ServerItem.OnGFGameReady();
  95. }
  96. },
  97. //比赛消息
  98. InsertMatchJoinString: function (lMatchFee) {
  99. this.m_lMatchFee = lMatchFee;
  100. if (confirm("參賽將扣除報名費 " + this.m_lMatchFee.toString() + " 遊戲幣,確認要參賽嗎?")) {
  101. this.OnJionCallBack();
  102. }
  103. return true;
  104. },
  105. OnJionCallBack: function () {
  106. pServerItem = IServerItem.get();
  107. var cbData = new Uint8Array(8);
  108. gCByte.w8(cbData, 0, this.m_lMatchFee);
  109. pServerItem.SendSocketData(MDM_GR_MATCH, SUB_GR_MATCH_FEE, cbData, 8);
  110. },
  111. //请求失败
  112. onGRRequestFailure: function (szDescribeString) {
  113. this.ShowAlert(szDescribeString, Alert_Yes, "OnAlertExitGame", this);
  114. },
  115. OnAlertExitGame: function (Res) {
  116. if (Res) this.ExitGame();
  117. },
  118. //创建游戏内核
  119. CreateKernel: function () {
  120. var kernel = gClientKernel.create();
  121. if (kernel == null) return false;
  122. kernel.SetServerItem(this.m_ServerItem);
  123. kernel.SetStringMessageSink(this);
  124. kernel.mIClientKernelSink = null;
  125. this.InitGameLayer();
  126. // this.schedule(this.InitGameLayer, 0.05);
  127. if (kernel.Init()) return true;
  128. gClientKernel.destory();
  129. return false;
  130. },
  131. //创建游戏
  132. InitGameLayer: function () {
  133. var kernel = gClientKernel.get();
  134. if (kernel.mIClientKernelSink) return
  135. this.ShowGamePrefab("GameClientEngine", GameDef.KIND_ID, this.m_gameNode, function (Js) {
  136. this.m_GameEngine = Js;
  137. Js.SetTableScene(this);
  138. kernel.SetClientKernelSink(Js);
  139. if (Js.LoadSound) Js.LoadSound();
  140. this.m_ServerItem.ConnectServer(this.mGameServerItem, 0, 0);
  141. }.bind(this));
  142. },
  143. //用户更新
  144. OnGRUserUpdate: function (pIClientUserItem) {
  145. },
  146. LoadingOver: function () {
  147. if (this.m_ReLinkTime != null) {
  148. this.OnGFServerReLink();
  149. } else {
  150. this.StopLoading();
  151. }
  152. },
  153. //房间退出
  154. OnGFServerClose: function (szMessage) {
  155. this.ShowAlert("您掉線了! 請檢查網路設備連接狀態! 點擊確定後將返回遊戲大廳.", Alert_Yes, "OnAlertExitGame", this);
  156. },
  157. OnGFServerReLink: function () {
  158. if (this.m_ServerItem.mInterval != null || this.mShowReLink) return this.StopLoading();
  159. if (window.ReLinkTime == null) window.ReLinkTime = 0;
  160. window.ReLinkTime++;
  161. this.StopLoading();
  162. if (window.ReLinkTime % 7 >= 6) {
  163. this.mShowReLink = true;
  164. this.ShowAlert('網路异常,是否嘗試重連?', Alert_YesNo, function (Res) {
  165. this.mShowReLink = false;
  166. if (Res) {
  167. this.ShowLoading();
  168. this.m_ServerItem.CloseSocket();
  169. this.m_ServerItem.ConnectServer(this.mGameServerItem, 0, 0);
  170. } else {
  171. this.OnGFServerClose();
  172. }
  173. }.bind(this));
  174. } else {
  175. this.ShowLoading();
  176. this.m_ServerItem.CloseSocket();
  177. this.m_ServerItem.ConnectServer(this.mGameServerItem, 0, 0);
  178. }
  179. },
  180. ExitGame: function () {
  181. if (this.m_TableViewFrame) {
  182. //退出游戏
  183. this.m_TableViewFrame.ExitGame();
  184. } else {
  185. gClientKernel.destory();
  186. ChangeScene('Lobby');
  187. }
  188. },
  189. ExitGameLogin: function () {
  190. //退出游戏
  191. this.m_TableViewFrame.ExitGame();
  192. },
  193. //网络心跳
  194. NetworkHeartbeat: function (dt) {
  195. if (this.m_ServerItem.mServiceStatus != ServiceStatus_ServiceIng) return
  196. if (this.m_ServerItem != null && this.m_ServerItem.mInterval == null) {
  197. this.m_ServerItem.mHeartStatTime = new Date().getTime(); //服务器心跳时间
  198. this.m_ServerItem.SendSocketClass(MDM_KN_COMMAND, SUB_KN_CLIENT_HEART);
  199. }
  200. },
  201. UpdateGPS: function (para) {
  202. var GameClientEngine = this['m_JsGameClientEngine_' + GameDef.KIND_ID]
  203. if (GameClientEngine) GameClientEngine.UpdateGPS(para);
  204. },
  205. UpdateSet: function () {
  206. var GameClientEngine = this['m_JsGameClientEngine_' + GameDef.KIND_ID]
  207. if (GameClientEngine) GameClientEngine.m_GameClientView.UpdateSet();
  208. },
  209. /////////////////////////////////////////////////////////////////////////////语音接口
  210. GetVoiceCtrl: function (para) {
  211. var GameClientEngine = this['m_JsGameClientEngine_' + GameDef.KIND_ID];
  212. if (GameClientEngine == null) return null;
  213. return GameClientEngine.GetVoiceCtrl();
  214. },
  215. //上传完成
  216. OnVoiceUpLoad: function (para) {
  217. var VoiceCtrl = this.GetVoiceCtrl();
  218. if (VoiceCtrl) VoiceCtrl.OnRecordOver(para);
  219. },
  220. OnVoiceLoad: function (para) {
  221. var VoiceCtrl = this.GetVoiceCtrl();
  222. if (VoiceCtrl) VoiceCtrl.OnLoadVoice(para);
  223. },
  224. //播放完成
  225. OnPlayFinish: function () {
  226. var VoiceCtrl = this.GetVoiceCtrl();
  227. if (VoiceCtrl) VoiceCtrl.OnPlayFinish();
  228. },
  229. onRecordFinish: function (str) {
  230. var VoiceCtrl = this.GetVoiceCtrl();
  231. if (VoiceCtrl) VoiceCtrl.onRecordFinish(str);
  232. },
  233. OnBtClick_Invite: function () {
  234. var GameClientEngine = this['m_JsGameClientEngine_' + GameDef.KIND_ID]
  235. if (GameClientEngine) {
  236. this.ShowPrefabDLG('ClubInviteUserList', null, function (Js) {
  237. Js.OnSetGameInfor(GameClientEngine);
  238. }.bind(this));
  239. }
  240. },
  241. OnSetInviteBtShow: function (pIClientUserItem) {
  242. var GameClientEngine = this['m_JsGameClientEngine_' + GameDef.KIND_ID]
  243. if (GameClientEngine && GameClientEngine.m_dwClubID != 0) {
  244. this.$('BtInvite').active = pIClientUserItem.GetUserStatus() != US_LOOKON;
  245. }
  246. },
  247. /////////////////////////////////////////////////////////////////////////////
  248. });