Table.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. },
  147. LoadingOver:function(){
  148. if(this.m_ReLinkTime != null){
  149. this.OnGFServerReLink();
  150. }else{
  151. this.StopLoading();
  152. }
  153. },
  154. //房间退出
  155. OnGFServerClose :function(szMessage){
  156. this.ShowAlert("您掉線了! 請檢查網路設備連接狀態! 點擊確定後將返回遊戲大廳.",Alert_Yes,"OnAlertExitGame",this);
  157. },
  158. OnGFServerReLink :function(){
  159. if(this.m_ServerItem.mInterval != null || this.mShowReLink) return this.StopLoading();
  160. if(window.ReLinkTime == null) window.ReLinkTime = 0;
  161. window.ReLinkTime++;
  162. this.StopLoading();
  163. if(window.ReLinkTime%7 >= 6){
  164. this.mShowReLink = true;
  165. this.ShowAlert('網路异常,是否嘗試重連?',Alert_YesNo,function(Res){
  166. this.mShowReLink = false;
  167. if(Res){
  168. this.ShowLoading();
  169. this.m_ServerItem.CloseSocket();
  170. this.m_ServerItem.ConnectServer(this.mGameServerItem, 0, 0);
  171. }else{
  172. this.OnGFServerClose();
  173. }
  174. }.bind(this));
  175. }else{
  176. this.ShowLoading();
  177. this.m_ServerItem.CloseSocket();
  178. this.m_ServerItem.ConnectServer(this.mGameServerItem, 0, 0);
  179. }
  180. },
  181. ExitGame :function(){
  182. if(this.m_TableViewFrame){
  183. //退出游戏
  184. this.m_TableViewFrame.ExitGame();
  185. }else {
  186. gClientKernel.destory();
  187. ChangeScene('Lobby');
  188. }
  189. },
  190. ExitGameLogin :function() {
  191. //退出游戏
  192. this.m_TableViewFrame.ExitGame();
  193. },
  194. //网络心跳
  195. NetworkHeartbeat :function(dt) {
  196. if(this.m_ServerItem.mServiceStatus != ServiceStatus_ServiceIng) return
  197. if (this.m_ServerItem != null && this.m_ServerItem.mInterval == null){
  198. this.m_ServerItem.mHeartStatTime = new Date().getTime(); //服务器心跳时间
  199. this.m_ServerItem.SendSocketClass(MDM_KN_COMMAND, SUB_KN_CLIENT_HEART);
  200. }
  201. },
  202. UpdateGPS:function(para) {
  203. var GameClientEngine = this['m_JsGameClientEngine_'+GameDef.KIND_ID]
  204. if(GameClientEngine)GameClientEngine.UpdateGPS(para);
  205. },
  206. UpdateSet:function() {
  207. var GameClientEngine = this['m_JsGameClientEngine_'+GameDef.KIND_ID]
  208. if(GameClientEngine)GameClientEngine.m_GameClientView.UpdateSet();
  209. },
  210. /////////////////////////////////////////////////////////////////////////////语音接口
  211. GetVoiceCtrl:function(para) {
  212. var GameClientEngine = this['m_JsGameClientEngine_'+GameDef.KIND_ID];
  213. if(GameClientEngine == null) return null;
  214. return GameClientEngine.GetVoiceCtrl();
  215. },
  216. //上传完成
  217. OnVoiceUpLoad:function(para) {
  218. var VoiceCtrl = this.GetVoiceCtrl();
  219. if(VoiceCtrl)VoiceCtrl.OnRecordOver(para);
  220. },
  221. OnVoiceLoad:function(para) {
  222. var VoiceCtrl = this.GetVoiceCtrl();
  223. if(VoiceCtrl)VoiceCtrl.OnLoadVoice(para);
  224. },
  225. //播放完成
  226. OnPlayFinish:function() {
  227. var VoiceCtrl = this.GetVoiceCtrl();
  228. if(VoiceCtrl)VoiceCtrl.OnPlayFinish();
  229. },
  230. onRecordFinish :function (str) {
  231. var VoiceCtrl = this.GetVoiceCtrl();
  232. if(VoiceCtrl)VoiceCtrl.onRecordFinish(str);
  233. },
  234. OnBtClick_Invite:function(){
  235. var GameClientEngine = this['m_JsGameClientEngine_'+GameDef.KIND_ID]
  236. if(GameClientEngine){
  237. this.ShowPrefabDLG('ClubInviteUserList',null,function(Js){
  238. Js.OnSetGameInfor(GameClientEngine);
  239. }.bind(this));
  240. }
  241. },
  242. OnSetInviteBtShow:function(pIClientUserItem){
  243. var GameClientEngine = this['m_JsGameClientEngine_'+GameDef.KIND_ID]
  244. if(GameClientEngine&&GameClientEngine.m_dwClubID!=0){
  245. this.$('BtInvite').active = pIClientUserItem.GetUserStatus()!= US_LOOKON;
  246. }
  247. },
  248. /////////////////////////////////////////////////////////////////////////////
  249. });