123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- 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";
- 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)
- 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()
- 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)
- }
- 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;
- }
-
- }
- })
- }
-
- }
|