import CanjuModel, { CanjuData } from "./Game/ChessCanJuSel/CanjuModel"; import ChessMng, { ChessType } from "./Game/DiffSel/ChessMng"; import UIDiffSel from "./Game/DiffSel/UIDiffSel"; import AudioMng from "./gcommon/AudioMng"; import { UIButton } from "./gcommon/UIButton"; import GameData from "./gcommon/GameData"; import ScenceMng from "./gcommon/ScenceMng"; import { GameMng, quit_chess_show_view } from "./GameMng"; import { _decorator,Component,TextAsset,Node,setDisplayStats, game, sys, native, EventTouch } from "cc"; import gameSocket from "./socket/gameSocket"; import UIduizhan from "./Game/UIduizhan"; import UITips from "./gcommon/UITips"; import { ClientEvent } from "./clientEvent"; import { Constant } from "./constant"; import { Tools } from "./Tools"; import { page_btn } from "./Main/page_btn"; import UIDialog from "./Game/UIDialog"; import { native_manager } from "./native_manager"; import { UIManager } from "./gcommon/UIManager"; import { roomData } from "./UserData/roomData"; import { recv_firend_duizhan } from "./Main/haoyou/recv_firend_duizhan"; const {ccclass, property} = _decorator; var pageList = new Map(); var pageBtnList = new Map(); @ccclass export default class GameLaunch extends Component { @property(TextAsset) fen: TextAsset = null; static isLaunch:boolean=false; // @property(Node) // btn1: Node = null; // @property(Node) // btn2: Node = null; @property(Node) btn_duizhan: Node = null; @property(Node) login_view: Node = null; @property(Node) xiaqi_page: Node = null; @property(Node) xueqi_page: Node = null; @property(Node) qijie_page: Node = null; @property(Node) faxian_page: Node = null; @property(Node) wode_page: Node = null; @property(Node) xiaqi_page_btn: Node = null; @property(Node) xueqi_page_btn: Node = null; @property(Node) qijie_page_btn: Node = null; @property(Node) faxian_page_btn: Node = null; @property(Node) wode_page_btn: Node = null; cur_select_page:string = "" start() { if(!GameLaunch.isLaunch){ this.initGame(); GameLaunch.isLaunch=true; } this.clearList() // UIButton.BindClick(this.btn1,()=>{ // ChessMng.Instance.chesstype=ChessType.renjiboyi; // ScenceMng.Instance.load('ChessDiffSel') // },this); // UIButton.BindClick(this.btn2,()=>{ // ChessMng.Instance.chesstype=ChessType.canju; // ScenceMng.Instance.load('ChessCanJuSel') // },this); if(CanjuModel.Instance.canjuDataArr.length==0){ let arr=this.fen.text.split('\n') arr.forEach((item,index)=>{ let arr = item.split(';'); let canjudata: CanjuData = { fen: arr[0], name: arr[1] } CanjuModel.Instance.canjuDataArr.push(canjudata) }) } UIButton.BindClick(this.btn_duizhan,()=>{ UIduizhan.Show(); },this); if(GameMng._userData == null){ this.login_view.active = true; }else{ this.login_view.active = false; } gameSocket.Instance.connect(Tools.makeUrl()) ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_FIREND,this.show_firend,this) ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_RENJI,this.show_renji,this) ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_JIFEN,this.show_jifen,this) ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_LOGIN,this.show_login,this) ClientEvent.on(Constant.UI_EVENT.UI_MSG_LOGIN_FINISH,this.onRecvLogin,this) ClientEvent.on(Constant.EVENT_TYPE.MSG_JOIN_ROOM,this.onJoinRoom,this) ClientEvent.on(Constant.EVENT_TYPE.MSG_CREATE_ROOM,this.onRecvCreateRoom,this) ClientEvent.on(Constant.EVENT_TYPE.MSG_JIE_SHOU_YUE_ZHAN,this.jie_shou_yue_zhan,this) if(GameMng.Instance.quit_view!=null){ switch(GameMng.Instance.quit_view){ case quit_chess_show_view.haoyou:{ ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_FIREND) break; } case quit_chess_show_view.renji:{ ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_RENJI) break; } case quit_chess_show_view.jifen:{ ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_JIFEN) break; } case quit_chess_show_view.login:{ ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_LOGIN) break; } case quit_chess_show_view.beitichu:{ UIDialog.Show(()=>{ },()=>{ },"你已被桌主踢出房间!",null,false) break; } } } GameMng.Instance.quit_view = null; this.initPage() this.initPageBtns() if(GameMng._userData!=null){ this.onRecvLogin() } } onJoinRoom(room:roomData){ UIManager.removeLoadingLayer() GameMng.updateRoomData(room) ScenceMng.Instance.load('Chess') console.log("room",room) } onRecvCreateRoom(room:roomData){ console.log("room",room) UIManager.removeLoadingLayer() GameMng.updateRoomData(room); ScenceMng.Instance.load('Chess') } jie_shou_yue_zhan(obj:any){ console.log("friend",obj.friend_id+"") let rival_data = GameMng.getFriedDataById(parseInt(obj.friend_id)); if(rival_data!=null){ let node = UIManager.AddPrefab(GameMng.Instance.recv_firend_duizhan) node.getComponent(recv_firend_duizhan).show(rival_data) } } onRecvLogin(){ this.showPage(0,'xiaqi',true) } initPage(){ if(pageList.get(Constant.PAGE_XIAQI)===null){ pageList.set(Constant.PAGE_XIAQI,this.xiaqi_page) } if(pageList.get(Constant.PAGE_XUEQI)===null){ pageList.set(Constant.PAGE_XUEQI,this.xueqi_page) } if(pageList.get(Constant.PAGE_QIJIE)===null){ pageList.set(Constant.PAGE_QIJIE,this.qijie_page) } if(pageList.get(Constant.PAGE_FAXIAN)===null){ pageList.set(Constant.PAGE_FAXIAN,this.faxian_page) } if(pageList.get(Constant.PAGE_WODE)===null){ pageList.set(Constant.PAGE_WODE,this.wode_page) } } initPageBtns(){ if(pageBtnList.get(Constant.PAGE_XIAQI)===null){ pageBtnList.set(Constant.PAGE_XIAQI,this.xiaqi_page_btn) } if(pageBtnList.get(Constant.PAGE_XUEQI)===null){ pageBtnList.set(Constant.PAGE_XUEQI,this.xueqi_page_btn) } if(pageBtnList.get(Constant.PAGE_QIJIE)===null){ pageBtnList.set(Constant.PAGE_QIJIE,this.qijie_page_btn) } if(pageBtnList.get(Constant.PAGE_FAXIAN)===null){ pageBtnList.set(Constant.PAGE_FAXIAN,this.faxian_page_btn) } if(pageBtnList.get(Constant.PAGE_WODE)===null){ pageBtnList.set(Constant.PAGE_WODE,this.wode_page_btn) } } onEnable(){ native_manager.hideSplash() } show_firend(){ UIduizhan.Show(quit_chess_show_view.haoyou); } show_renji(){ UIduizhan.Show(quit_chess_show_view.renji); } show_jifen(){ UIduizhan.Show(quit_chess_show_view.jifen); } show_login(){ this.login_view.active = true; GameMng._userData = null; gameSocket.Instance.stopConnected = false; } onDestroy(){ ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_FIREND,this.show_firend,this) ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_RENJI,this.show_renji,this) ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_JIFEN,this.show_jifen,this) ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_LOGIN,this.show_login,this) ClientEvent.off(Constant.UI_EVENT.UI_MSG_LOGIN_FINISH,this.onRecvLogin,this) ClientEvent.off(Constant.EVENT_TYPE.MSG_JOIN_ROOM,this.onJoinRoom,this) ClientEvent.off(Constant.EVENT_TYPE.MSG_CREATE_ROOM,this.onRecvCreateRoom,this) ClientEvent.off(Constant.EVENT_TYPE.MSG_JIE_SHOU_YUE_ZHAN,this.jie_shou_yue_zhan,this) } clearList(){ pageList.set(Constant.PAGE_XIAQI, null); pageList.set(Constant.PAGE_XUEQI, null); pageList.set(Constant.PAGE_QIJIE, null); pageList.set(Constant.PAGE_FAXIAN, null); pageList.set(Constant.PAGE_WODE, null); pageBtnList.set(Constant.PAGE_XIAQI, null); pageBtnList.set(Constant.PAGE_XUEQI, null); pageBtnList.set(Constant.PAGE_QIJIE, null); pageBtnList.set(Constant.PAGE_FAXIAN, null); pageBtnList.set(Constant.PAGE_WODE, null); } clickNot(){ UITips.show("暂未开放,敬请期待!"); } initGame(){ setDisplayStats(false); console.log("initGame") GameData.LoadGame(); AudioMng.Instance.PlayBGM(GameMng.Instance.mainbgm); } showPage(event:any,name:string,isFirst:boolean=false){ console.log("name",name) if(pageList.get(name+"")!=null&&this.cur_select_page!=name){ console.log("data",name) this.hideAllPage(name) this.showPageBtn(name) if(!isFirst){ AudioMng.Instance.PlaySoundByName(GameMng.Instance.buttonclick); } this.cur_select_page = name; } } showPageBtn(name:string){ pageBtnList.forEach((element, key, map) =>{ if(element){ if(name!=key){ element.getComponent(page_btn).status_unselect() }else{ element.getComponent(page_btn).status_select() } } }) } hideAllPage(name){ pageList.forEach((element, key, map) =>{ if(element){ if(name!=key){ element.active = false; }else{ element.active = true; } } }) } }