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