Table.js 8.9 KB

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