import { _decorator, Component, Node, Label, Sprite, Animation, SpriteFrame, Texture2D, assetManager, ImageAsset, Slider, tween, Tween, Vec3 } from 'cc'; import { ClientEvent } from '../../clientEvent'; import { Constant } from '../../constant'; import { fill } from '../../fill'; import { fnt_count } from '../../fnt_count'; import { GameMng } from '../../GameMng'; import { ResMng } from '../../gcommon/ResMng'; import { UIButton } from '../../gcommon/UIButton'; import { UIManager } from '../../gcommon/UIManager'; import { emote } from '../../Main/emote'; import { msgManager } from '../../socket/msgManager'; import { Tools } from '../../Tools'; import { roomData } from '../../UserData/roomData'; import { timeCountData } from '../../UserData/timeCountData'; import ChessMng, { ChessType } from '../DiffSel/ChessMng'; import UIDiffSel from '../DiffSel/UIDiffSel'; import { waitJifen } from '../waitJifen'; import GBoardChess from './GBoardChess'; const { ccclass, property } = _decorator; @ccclass('ChessThink') export class ChessThink extends Component { @property(Node) self_head: Node = null; @property(Node) self_think: Node = null; @property(Node) self_think_bai: Node = null; @property(Node) self_name: Node = null; @property(Node) self_allTime: Node = null;//总剩余时间 @property(Node) self_curCountTime: Node = null; //当前思考倒计时 @property(Node) self_time_node: Node = null; // @property(Node) self_fnt_count: Node = null; // @property(Node) self_emote: Node = null; // @property(Node) self_head_btn: Node = null; // @property(Node) rival_head_btn: Node = null; // @property(Node) rival_emote: Node = null; //对手 @property(Node) self_chat: Node = null; // @property(Node) rival_chat: Node = null; //对手 @property(Node) rival_head: Node = null; //对手 @property(Node) rival_think: Node = null; //对手 @property(Node) rival_think_bai: Node = null; //对手 @property(Node) rival_name: Node = null; @property(Node) rival_allTime: Node = null;//总剩余时间 @property(Node) rival_curCountTime: Node = null; //当前思考倒计时 @property(Node) rival_time_node: Node = null; // @property(Node) rival_ready_status_lab: Node = null; //对手准备状态信息 @property(Node) btn_kick: Node = null; //踢出 @property(Node) rival_offline: Node = null; @property(Node) rival_fnt_count: Node = null; // @property(Node) sf_rival_offline: Node = null; //对手离线 @property(Node) rival_ready: Node = null; //对手准备 @property(Node) ti_rival: Node = null; //踢出对手 @property(Node) rival_dumiao_node: Node = null; //对手读秒 @property(Node) rival_dumiao_lab: Node = null; //对手读秒 @property(Node) self_dumiao_node: Node = null; //自己读秒 @property(Node) self_dumiao_lab: Node = null; //自己读秒 isThink:boolean = false; isPause:boolean = false; self_total_time:number = 0; self_every_step_time:number = 0; rival_total_time:number = 0; rival_every_step_time:number = 0; start() { //this.ti_rival.active = false; UIButton.BindClick(this.btn_kick,this.kickRival,this) UIButton.BindClick(this.self_head_btn,()=>{ UIManager.addUserInfoViewPrefab(GameMng._userData) },this) UIButton.BindClick(this.rival_head_btn,()=>{ if(GameMng._userData.room!=null&&GameMng._userData.room.rival!=null&&GameMng._userData.room.rival!=undefined){ UIManager.addUserInfoViewPrefab(GameMng._userData.room.rival) } },this) ClientEvent.on(Constant.EVENT_TYPE.MSG_JOIN_ROOM,this.onJoinRoom,this) ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_RIVAL_CHAT,this.showRivalChat,this) ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_SELF_CHAT,this.showSelfChat,this) ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_SELF_EMOTE,this.showSelfEmote,this) ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_RIVAL_EMOTE,this.showRivalEmote,this) } onDestroy(){ ClientEvent.off(Constant.EVENT_TYPE.MSG_JOIN_ROOM,this.onJoinRoom,this) ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_RIVAL_CHAT,this.showRivalChat,this) ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_SELF_CHAT,this.showSelfChat,this) ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_SELF_EMOTE,this.showSelfEmote,this) ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_RIVAL_EMOTE,this.showRivalEmote,this) this.unschedule(this.updateTime) } showSelfEmote(em_id:number){ this.self_emote.active = true; this.self_emote.getComponent(emote).show(em_id) Tween.stopAllByTarget(this.self_emote) tween(this.self_emote).delay(2).call(()=>{ this.self_emote.active = false; }).start() } showRivalEmote(em_id:number){ this.rival_emote.active = true; this.rival_emote.getComponent(emote).show(em_id) Tween.stopAllByTarget(this.rival_emote) tween(this.rival_emote).delay(2).call(()=>{ this.rival_emote.active = false; }).start() } showSelfChat(chat_str:string){ this.self_chat.active = true; GameMng.add_chat_history(GameMng._userData.user_name+": "+chat_str) this.self_chat.getChildByName("Label").getComponent(Label).string = chat_str; tween(this.self_chat).delay(2).call(()=>{ this.self_chat.active = false; }).start() } showRivalChat(chat_str:string){ this.rival_chat.active = true; if(GameMng._userData.room.rival!=null){ GameMng.add_chat_history(GameMng._userData.room.rival.user_name+": "+chat_str) }else{ GameMng.add_chat_history("对手10001: "+chat_str) } this.rival_chat.getChildByName("Label").getComponent(Label).string = chat_str; tween(this.rival_chat).delay(2).call(()=>{ this.rival_chat.active = false; }).start() } startThink(loacl_reset?:boolean,sever_reset?:boolean){ var temp = new timeCountData() if(loacl_reset){ if(GameMng._userData.room.time_count_data!=null&&GameMng._userData.room.time_count_data!=undefined){ temp.self_total_time = GameMng._userData.room.time_count_data.self_total_time temp.self_every_step_time = temp.self_total_time>GameMng._userData.room.time_count_data.self_every_step_time?GameMng._userData.room.everysteptime:GameMng._userData.room.time_count_data.self_every_step_time temp.rival_total_time = GameMng._userData.room.time_count_data.rival_total_time temp.rival_every_step_time = temp.rival_total_time>GameMng._userData.room.time_count_data.rival_every_step_time?GameMng._userData.room.everysteptime:GameMng._userData.room.time_count_data.rival_every_step_time }else{ temp.self_total_time = GameMng._userData.room.totaltime temp.self_every_step_time = GameMng._userData.room.everysteptime temp.rival_total_time = GameMng._userData.room.totaltime temp.rival_every_step_time = GameMng._userData.room.everysteptime } if(!sever_reset){ }else{ this.isPause = false; temp = GameMng._userData.room.time_count_data } }else{ temp = GameMng._userData.room.time_count_data } this.self_total_time = temp.self_total_time this.self_every_step_time = temp.self_every_step_time this.rival_total_time = temp.rival_total_time this.rival_every_step_time = temp.rival_every_step_time if(sever_reset){ this.updateTimeLab() } if(!this.isThink){ this.isThink = true; this.isPause = false; this.unschedule(this.updateTime) this.schedule(this.updateTime,1) this.self_fnt_count.active = false; this.rival_fnt_count.active = false; this.self_time_node.active = true; this.rival_time_node.active = true; this.updateTime() } // if(!this.self_time_node.active){ // } } stopThink(){ this.isThink = false; this.isPause = true; this.unschedule(this.updateTime) this.self_time_node.active = false; this.rival_time_node.active = false; this.self_fnt_count.active = false; this.rival_fnt_count.active = false; this.stopAni() } stopAni(){ this.self_think.getComponent(fill).stopAni(); this.self_think_bai.getComponent(fill).stopAni(); this.rival_think.getComponent(fill).stopAni(); this.rival_think_bai.getComponent(fill).stopAni(); } updateTime(){ if(!GameMng._userData.room||this.isPause)return if(GBoardChess.instance.isStartGame&&GameMng._userData.room.time_count_data){ this.updateTimeLab() if(GBoardChess.instance.who_round==1){ this.self_think.active = true; this.self_think_bai.active = true; this.rival_think.active = false; this.rival_think_bai.active = false; this.self_total_time-=1; this.self_every_step_time-=1; if(this.self_total_time<0){ this.self_total_time = 0; } if(this.self_every_step_time<0){ this.self_every_step_time = 0; } }else{ this.self_think.active = false; this.self_think_bai.active = false; this.rival_think.active = true; this.rival_think_bai.active = true; this.rival_total_time-=1; this.rival_every_step_time-=1; if(this.rival_total_time<0){ this.rival_total_time = 0; } if(this.rival_every_step_time<0){ this.rival_every_step_time = 0; } } } } updateLab(){ } updateTimeLab(){ this.self_allTime.getComponent(Label).string = Tools.ms_time(this.self_total_time) this.rival_allTime.getComponent(Label).string = Tools.ms_time(this.rival_total_time) this.self_curCountTime.getComponent(Label).string = Tools.ms_time(this.self_every_step_time) this.rival_curCountTime.getComponent(Label).string = Tools.ms_time(this.rival_every_step_time) this.self_dumiao_lab.getComponent(Label).string = Tools.ms_time(this.self_every_step_time) this.rival_dumiao_lab.getComponent(Label).string = Tools.ms_time(this.rival_every_step_time) var is_self_du_miao = GameMng._userData.room.time_count_data.self_countdown>0; var is_rival_du_miao = GameMng._userData.room.time_count_data.rival_countdown>0 if(GBoardChess.instance.who_round==1){ if(is_self_du_miao){ //说明有读秒要走 this.self_dumiao_node.active = true; this.self_time_node.active = false; } }else{ if(is_rival_du_miao){ //说明有读秒要走 this.rival_dumiao_node.active = true; this.rival_time_node.active = false; } } let everysteptime = GameMng._userData.room.everysteptime; if(ChessMng.Instance.isJiFenRoom()){ if(GBoardChess.instance.rund_number<6){ everysteptime = 30 } } let self_du_miao_time = everysteptime; let rival_du_miao_time = everysteptime; if(is_self_du_miao){ //说明有读秒要走 self_du_miao_time = GameMng._userData.room.countdown; } if(is_rival_du_miao){ //说明有读秒要走 rival_du_miao_time = GameMng._userData.room.countdown; } if(GBoardChess.instance.who_round==1){ this.self_think_bai.getComponent(fill).startAni(this.self_every_step_time+self_du_miao_time*0.03,self_du_miao_time) this.self_think.getComponent(fill).startAni(this.self_every_step_time,self_du_miao_time) }else{ this.rival_think_bai.getComponent(fill).startAni(this.rival_every_step_time+rival_du_miao_time*0.03,rival_du_miao_time) this.rival_think.getComponent(fill).startAni(this.rival_every_step_time,rival_du_miao_time) } if(GameMng._userData.room.time_count_data!=null){ if(GameMng._userData.room.time_count_data.self_every_step_time<=0||GameMng._userData.room.time_count_data.rival_every_step_time<=0){ this.isPause = true this.stopAni() } if(GameMng._userData.room.time_count_data.self_every_step_time>10||GBoardChess.instance.who_round==0){ this.self_name.active = true; if(is_self_du_miao){ this.self_dumiao_node.active = true; }else{ this.self_time_node.active = true; } this.self_fnt_count.active = false; }else{ this.self_time_node.active = false; this.self_dumiao_node.active = false; this.self_name.active = false; this.self_fnt_count.active = true; this.self_fnt_count.getComponent(fnt_count).show(this.self_every_step_time) } if(GameMng._userData.room.time_count_data.rival_every_step_time>10||GBoardChess.instance.who_round==1){ this.rival_name.active = true; if(is_rival_du_miao){ this.rival_dumiao_node.active = true; }else{ this.rival_dumiao_node.active = false; this.rival_time_node.active = true; } this.rival_fnt_count.active = false; }else{ this.rival_dumiao_node.active = false; this.rival_name.active = false; this.rival_time_node.active = false; this.rival_fnt_count.active = true; this.rival_fnt_count.getComponent(fnt_count).show(this.rival_every_step_time) } } } kickRival(){ this.ti_rival.active = true; this.scheduleOnce(()=>{ msgManager.kickRival() this.ti_rival.getComponent(Animation).stop() this.rival_head.active = false; this.rival_head.position = new Vec3(0,0,0) this.rival_head.angle = 0; },0.8) this.btn_kick.active = false; this.rival_name.active = false; this.rival_time_node.active = false; this.ti_rival.getComponent(Animation).play() } //对手加入房间 onJoinRoom(room:roomData){ GameMng.updateRoomData(room) this.StatusShow() UIManager.removeLoadingLayer() console.log("onJoinRoom",room) } setData(){ } round_time_count(){ if(GameMng._userData.room.time_count_data!=null){ } } //等待状态显示 StatusShow(){ if(!GBoardChess.instance.isStartGame||ChessMng.Instance.chesstype==ChessType.renjiboyi){ this.self_time_node.active = false; this.rival_time_node.active = false; this.self_think.active = false; this.rival_think.active = false; this.rival_offline.active = false; this.btn_kick.active = false; this.rival_ready_status_lab.active = false; this.sf_rival_offline.active = false; this.rival_ready.active = false; this.self_dumiao_node.active = false; } let self = this; if(ChessMng.Instance.chesstype==ChessType.renjiboyi){ this.rival_head.active = true; this.rival_name.getComponent(Label).string = UIDiffSel.lvArr[UIDiffSel.selectIndex]; ResMng.LoadAvatar(Tools.getAvatarByIndex(UIDiffSel.selectIndex+1),this.rival_head.getComponent(Sprite)) }else{ if(GameMng._userData.room!=null){ console.log("GameMng._userData.room.wait_rival_status",GameMng._userData.room.wait_rival_startGame_status) //GameMng._userData.room.wait_rival_status===undefined||GameMng._userData.room.wait_rival_status===0|| if(GameMng._userData.room.rival===null||GameMng._userData.room.rival===undefined){ //房间没有来人 this.rival_head.active = false; this.rival_name.active = false; this.rival_head.getComponent(Sprite).spriteFrame = null; //this.rival_ready_status_lab.getComponent(Label).string = "暂无人员加入" if(ChessMng.Instance.isJiFenRoom()){ if(GameMng._userData.room.wait_rival_startGame_status===1){ if(ChessMng.Instance.isJiFenRoom()){ GBoardChess.instance.wait_jifen.getComponent(waitJifen).recvReady(GameMng._userData.room) } this.rival_ready_status_lab.active = true; this.rival_ready_status_lab.getComponent(Label).string = "正在匹配..." } } }else{ this.rival_head.active = true; this.rival_name.active = true; if(GameMng._userData.room.rival.user_avatar!=""){ Tools.loadWeiXinHead(GameMng._userData.room.rival.user_avatar,this.rival_head.getComponent(Sprite)) } let rival_name = GameMng._userData.room.rival.user_name; if(ChessMng.Instance.isJiFenRoom()){ rival_name = "["+ GameMng._userData.room.rival.integral_level_name +"] "+rival_name } this.rival_name.getComponent(Label).string =rival_name switch(GameMng._userData.room.wait_rival_startGame_status){ case 0:case 1:{ this.stopThink() this.rival_ready.active = false; //this.rival_ready_status_lab.getComponent(Label).string = "未准备" break; } case 2:{ this.rival_ready.active = true; // this.rival_ready_status_lab.getComponent(Label).string = "已准备" break; } case 3:{ this.rival_ready.active = false; break; } } if(GameMng._userData.room.ownerid===GameMng._userData.userid){ //说明我是房主 if(GameMng._userData.room.wait_rival_startGame_status!=3){ //还没开局 this.btn_kick.active = true; } } } if(GameMng._userData.room.rival!=null){ this.rival_offline.active = false; if(GameMng._userData.room.rivalIsOffline==1){ this.sf_rival_offline.active = true; //this.rival_offline.getComponent(Label).string = "离线" }else{ this.sf_rival_offline.active = false; //this.rival_offline.getComponent(Label).string = "在线" } } } } let self_name = GameMng._userData.user_name; if(ChessMng.Instance.isJiFenRoom()){ self_name = "["+ GameMng._userData.integral_level_name +"] "+self_name } this.self_name.getComponent(Label).string = self_name; if(this.self_head.getComponent(Sprite).spriteFrame ==null&&GameMng._userData.user_avatar!=""){ Tools.loadWeiXinHead(GameMng._userData.user_avatar,this.self_head.getComponent(Sprite)) } } update(deltaTime: number) { } }