GameLaunch.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import CanjuModel, { CanjuData } from "./Game/ChessCanJuSel/CanjuModel";
  2. import ChessMng, { ChessType } from "./Game/DiffSel/ChessMng";
  3. import UIDiffSel from "./Game/DiffSel/UIDiffSel";
  4. import AudioMng from "./gcommon/AudioMng";
  5. import { UIButton } from "./gcommon/UIButton";
  6. import GameData from "./gcommon/GameData";
  7. import ScenceMng from "./gcommon/ScenceMng";
  8. import { GameMng, quit_chess_show_view } from "./GameMng";
  9. import { _decorator,Component,TextAsset,Node,setDisplayStats, game, sys, native, EventTouch } from "cc";
  10. import gameSocket from "./socket/gameSocket";
  11. import UIduizhan from "./Game/UIduizhan";
  12. import UITips from "./gcommon/UITips";
  13. import { ClientEvent } from "./clientEvent";
  14. import { Constant } from "./constant";
  15. import { Tools } from "./Tools";
  16. import { page_btn } from "./Main/page_btn";
  17. import UIDialog from "./Game/UIDialog";
  18. import { native_manager } from "./native_manager";
  19. import { UIManager } from "./gcommon/UIManager";
  20. import { roomData } from "./UserData/roomData";
  21. import { recv_firend_duizhan } from "./Main/haoyou/recv_firend_duizhan";
  22. const {ccclass, property} = _decorator;
  23. var pageList = new Map();
  24. var pageBtnList = new Map();
  25. @ccclass
  26. export default class GameLaunch extends Component {
  27. @property(TextAsset)
  28. fen: TextAsset = null;
  29. static isLaunch:boolean=false;
  30. // @property(Node)
  31. // btn1: Node = null;
  32. // @property(Node)
  33. // btn2: Node = null;
  34. @property(Node)
  35. btn_duizhan: Node = null;
  36. @property(Node)
  37. login_view: Node = null;
  38. @property(Node)
  39. xiaqi_page: Node = null;
  40. @property(Node)
  41. xueqi_page: Node = null;
  42. @property(Node)
  43. qijie_page: Node = null;
  44. @property(Node)
  45. faxian_page: Node = null;
  46. @property(Node)
  47. wode_page: Node = null;
  48. @property(Node)
  49. xiaqi_page_btn: Node = null;
  50. @property(Node)
  51. xueqi_page_btn: Node = null;
  52. @property(Node)
  53. qijie_page_btn: Node = null;
  54. @property(Node)
  55. faxian_page_btn: Node = null;
  56. @property(Node)
  57. wode_page_btn: Node = null;
  58. cur_select_page:string = ""
  59. start() {
  60. if(!GameLaunch.isLaunch){
  61. this.initGame();
  62. GameLaunch.isLaunch=true;
  63. }
  64. this.clearList()
  65. // UIButton.BindClick(this.btn1,()=>{
  66. // ChessMng.Instance.chesstype=ChessType.renjiboyi;
  67. // ScenceMng.Instance.load('ChessDiffSel')
  68. // },this);
  69. // UIButton.BindClick(this.btn2,()=>{
  70. // ChessMng.Instance.chesstype=ChessType.canju;
  71. // ScenceMng.Instance.load('ChessCanJuSel')
  72. // },this);
  73. if(CanjuModel.Instance.canjuDataArr.length==0){
  74. let arr=this.fen.text.split('\n')
  75. arr.forEach((item,index)=>{
  76. let arr = item.split(';');
  77. let canjudata: CanjuData = { fen: arr[0], name: arr[1] }
  78. CanjuModel.Instance.canjuDataArr.push(canjudata)
  79. })
  80. }
  81. UIButton.BindClick(this.btn_duizhan,()=>{
  82. UIduizhan.Show();
  83. },this);
  84. if(GameMng._userData == null){
  85. this.login_view.active = true;
  86. }else{
  87. this.login_view.active = false;
  88. }
  89. gameSocket.Instance.connect(Tools.makeUrl())
  90. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_FIREND,this.show_firend,this)
  91. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_RENJI,this.show_renji,this)
  92. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_JIFEN,this.show_jifen,this)
  93. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_LOGIN,this.show_login,this)
  94. ClientEvent.on(Constant.UI_EVENT.UI_MSG_LOGIN_FINISH,this.onRecvLogin,this)
  95. ClientEvent.on(Constant.EVENT_TYPE.MSG_JOIN_ROOM,this.onJoinRoom,this)
  96. ClientEvent.on(Constant.EVENT_TYPE.MSG_CREATE_ROOM,this.onRecvCreateRoom,this)
  97. ClientEvent.on(Constant.EVENT_TYPE.MSG_JIE_SHOU_YUE_ZHAN,this.jie_shou_yue_zhan,this)
  98. if(GameMng.Instance.quit_view!=null){
  99. switch(GameMng.Instance.quit_view){
  100. case quit_chess_show_view.haoyou:{
  101. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_FIREND)
  102. break;
  103. }
  104. case quit_chess_show_view.renji:{
  105. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_RENJI)
  106. break;
  107. }
  108. case quit_chess_show_view.jifen:{
  109. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_JIFEN)
  110. break;
  111. }
  112. case quit_chess_show_view.login:{
  113. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_LOGIN)
  114. break;
  115. }
  116. case quit_chess_show_view.beitichu:{
  117. UIDialog.Show(()=>{
  118. },()=>{
  119. },"你已被桌主踢出房间!",null,false)
  120. break;
  121. }
  122. }
  123. }
  124. GameMng.Instance.quit_view = null;
  125. this.initPage()
  126. this.initPageBtns()
  127. if(GameMng._userData!=null){
  128. this.onRecvLogin()
  129. }
  130. }
  131. onJoinRoom(room:roomData){
  132. UIManager.removeLoadingLayer()
  133. GameMng.updateRoomData(room)
  134. ScenceMng.Instance.load('Chess')
  135. console.log("room",room)
  136. }
  137. onRecvCreateRoom(room:roomData){
  138. console.log("room",room)
  139. UIManager.removeLoadingLayer()
  140. GameMng.updateRoomData(room);
  141. ScenceMng.Instance.load('Chess')
  142. }
  143. jie_shou_yue_zhan(obj:any){
  144. console.log("friend",obj.friend_id+"")
  145. let rival_data = GameMng.getFriedDataById(parseInt(obj.friend_id));
  146. if(rival_data!=null){
  147. let node = UIManager.AddPrefab(GameMng.Instance.recv_firend_duizhan)
  148. node.getComponent(recv_firend_duizhan).show(rival_data)
  149. }
  150. }
  151. onRecvLogin(){
  152. this.showPage(0,'xiaqi',true)
  153. }
  154. initPage(){
  155. if(pageList.get(Constant.PAGE_XIAQI)===null){
  156. pageList.set(Constant.PAGE_XIAQI,this.xiaqi_page)
  157. }
  158. if(pageList.get(Constant.PAGE_XUEQI)===null){
  159. pageList.set(Constant.PAGE_XUEQI,this.xueqi_page)
  160. }
  161. if(pageList.get(Constant.PAGE_QIJIE)===null){
  162. pageList.set(Constant.PAGE_QIJIE,this.qijie_page)
  163. }
  164. if(pageList.get(Constant.PAGE_FAXIAN)===null){
  165. pageList.set(Constant.PAGE_FAXIAN,this.faxian_page)
  166. }
  167. if(pageList.get(Constant.PAGE_WODE)===null){
  168. pageList.set(Constant.PAGE_WODE,this.wode_page)
  169. }
  170. }
  171. initPageBtns(){
  172. if(pageBtnList.get(Constant.PAGE_XIAQI)===null){
  173. pageBtnList.set(Constant.PAGE_XIAQI,this.xiaqi_page_btn)
  174. }
  175. if(pageBtnList.get(Constant.PAGE_XUEQI)===null){
  176. pageBtnList.set(Constant.PAGE_XUEQI,this.xueqi_page_btn)
  177. }
  178. if(pageBtnList.get(Constant.PAGE_QIJIE)===null){
  179. pageBtnList.set(Constant.PAGE_QIJIE,this.qijie_page_btn)
  180. }
  181. if(pageBtnList.get(Constant.PAGE_FAXIAN)===null){
  182. pageBtnList.set(Constant.PAGE_FAXIAN,this.faxian_page_btn)
  183. }
  184. if(pageBtnList.get(Constant.PAGE_WODE)===null){
  185. pageBtnList.set(Constant.PAGE_WODE,this.wode_page_btn)
  186. }
  187. }
  188. onEnable(){
  189. native_manager.hideSplash()
  190. }
  191. show_firend(){
  192. UIduizhan.Show(quit_chess_show_view.haoyou);
  193. }
  194. show_renji(){
  195. UIduizhan.Show(quit_chess_show_view.renji);
  196. }
  197. show_jifen(){
  198. UIduizhan.Show(quit_chess_show_view.jifen);
  199. }
  200. show_login(){
  201. this.login_view.active = true;
  202. GameMng._userData = null;
  203. gameSocket.Instance.stopConnected = false;
  204. }
  205. onDestroy(){
  206. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_FIREND,this.show_firend,this)
  207. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_RENJI,this.show_renji,this)
  208. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_JIFEN,this.show_jifen,this)
  209. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_LOGIN,this.show_login,this)
  210. ClientEvent.off(Constant.UI_EVENT.UI_MSG_LOGIN_FINISH,this.onRecvLogin,this)
  211. ClientEvent.off(Constant.EVENT_TYPE.MSG_JOIN_ROOM,this.onJoinRoom,this)
  212. ClientEvent.off(Constant.EVENT_TYPE.MSG_CREATE_ROOM,this.onRecvCreateRoom,this)
  213. ClientEvent.off(Constant.EVENT_TYPE.MSG_JIE_SHOU_YUE_ZHAN,this.jie_shou_yue_zhan,this)
  214. }
  215. clearList(){
  216. pageList.set(Constant.PAGE_XIAQI, null);
  217. pageList.set(Constant.PAGE_XUEQI, null);
  218. pageList.set(Constant.PAGE_QIJIE, null);
  219. pageList.set(Constant.PAGE_FAXIAN, null);
  220. pageList.set(Constant.PAGE_WODE, null);
  221. pageBtnList.set(Constant.PAGE_XIAQI, null);
  222. pageBtnList.set(Constant.PAGE_XUEQI, null);
  223. pageBtnList.set(Constant.PAGE_QIJIE, null);
  224. pageBtnList.set(Constant.PAGE_FAXIAN, null);
  225. pageBtnList.set(Constant.PAGE_WODE, null);
  226. }
  227. clickNot(){
  228. UITips.show("暂未开放,敬请期待!");
  229. }
  230. initGame(){
  231. setDisplayStats(false);
  232. console.log("initGame")
  233. GameData.LoadGame();
  234. AudioMng.Instance.PlayBGM(GameMng.Instance.mainbgm);
  235. }
  236. showPage(event:any,name:string,isFirst:boolean=false){
  237. console.log("name",name)
  238. if(pageList.get(name+"")!=null&&this.cur_select_page!=name){
  239. console.log("data",name)
  240. this.hideAllPage(name)
  241. this.showPageBtn(name)
  242. if(!isFirst){
  243. AudioMng.Instance.PlaySoundByName(GameMng.Instance.buttonclick);
  244. }
  245. this.cur_select_page = name;
  246. }
  247. }
  248. showPageBtn(name:string){
  249. pageBtnList.forEach((element, key, map) =>{
  250. if(element){
  251. if(name!=key){
  252. element.getComponent(page_btn).status_unselect()
  253. }else{
  254. element.getComponent(page_btn).status_select()
  255. }
  256. }
  257. })
  258. }
  259. hideAllPage(name){
  260. pageList.forEach((element, key, map) =>{
  261. if(element){
  262. if(name!=key){
  263. element.active = false;
  264. }else{
  265. element.active = true;
  266. }
  267. }
  268. })
  269. }
  270. }