import { _decorator, Node, Sprite, tween, UIOpacity, UITransform, Vec3, view } from 'cc'; import { GButton } from '../../Main/Common/GButton'; import Utils from '../../Main/Common/Utils'; import { InnerMsgCode } from '../../Main/Config/InnerMsgCode'; import li_BaseView from '../../Main/Common/li_BaseView'; import GameManager, { E_TalkStage } from '../../Main/Manager/GameManager'; import ResManager from '../../Main/Manager/ResManager'; import GameRootUI from '../../Main/Common/GameRootUI'; import { ViewManager } from '../../Main/Manager/ViewManager'; import { I_LevelStepData } from '../../Main/Config/CommonConfig'; import AudioManager from '../../Main/Manager/AudioManager'; import { SDKManager } from '../../Main/Channel/SDKManager'; import SubManager from '../SubManager'; import HttpUnit from '../../Main/Common/HttpUnit'; const { ccclass, property } = _decorator; //结算界面 @ccclass('Finish_UI') export class Finish_UI extends li_BaseView { private _nodeTab: any = {}; private _data: I_LevelStepData = null; private picDefScale:Vec3; //图片默认缩放 private isPicFull:boolean = false; //图片是否全屏 //----重写父类接口--------------------------------------- onLoadCT() { this.registerListenner(); Utils.parseNode(this.node, this._nodeTab) this.picDefScale = (this._nodeTab.cgPic as Node).scale.clone(); GameRootUI.DisableOper(1) } openUIDataCT(data: any): void { this._data = data } registerListenner() { Utils.addInnerEL(InnerMsgCode.UI_ResartGame, this, this.resiveResartGame) } start() { // GButton.BandClick(this._nodeTab.mask, ()=>{ // this.onBackClick(); // }, this, 0, null, null, false); GButton.BandClick(this._nodeTab.cgPic, ()=>{ this.changePicScale(); }, this, 0, null, null, false); GButton.BandClick(this._nodeTab.btnClose, ()=>{ this.onBackClick(); }, this); GButton.BandClick(this._nodeTab.btnBack, ()=>{ this.onBackClick(); }, this); GButton.BandClick(this._nodeTab.btnShare, ()=>{ SDKManager.show_reward_share(this.node.uuid, 1) }, this); GButton.BandClick(this._nodeTab.btnRestart, ()=>{ this.onRestartClick(); }, this); GButton.BandClick(this._nodeTab.btnContinue, ()=>{ this.onContinueClick(); }, this); SDKManager.register_share_reward(this.node.uuid, (tag:number)=>{ console.log("结算界面分享回调", tag) if (tag == 1) { SubManager.ShowPrompt("分享成功") // let sptShare:Sprite = this._nodeTab.btnShare.getComponent(Sprite) // sptShare.grayscale = true // GButton.RemoveClick(this._nodeTab.btnShare) this.backToMain() } }) let lvCfg = GameManager.getLevelCfg(GameManager.CurLevelId) //星级 for (let i = 1; i <= 3; i++) { let starSpt = this._nodeTab["star" + i].getComponent(Sprite) let starPath = "" let showAct = false if(this._data.end_star == 3) { starPath = "lv_23" showAct = true } else if (this._data.end_star < i) { starPath = "lv_21" } else { starPath = "lv_22" showAct = true } ResManager.I.changeBundleSpriteFrame(starSpt, starPath, "Zhujiemian") //动作 let starNode = this._nodeTab["starNode"+i] if (showAct) { this.doStarAction1(starNode, (i-1)*0.2) } else { this.doStarAction2(starNode, (i-1)*0.2) } } //成功失败 let iswin = this._data.status == 0 let endPath = iswin ? "lv_19" : "lv_20" let winSpt = this._nodeTab.winSpt.getComponent(Sprite) ResManager.I.changeBundleSpriteFrame(winSpt, endPath, "Zhujiemian") if (iswin) { AudioManager.I.PlayEffect(10003); //胜利音效 } else { AudioManager.I.PlayEffect(10001); //失败音效 } //结算显示 let picPath = "" //表情图 let talkStr = "" //对话 if (this._data.end_star == 3) { picPath = `cg3/${lvCfg.threeStarCG}` talkStr = lvCfg.threeStarSummary } else if (this._data.end_star == 2) { picPath = `cg2/${lvCfg.twoStarCG}` talkStr = lvCfg.twoStarSummary } else if (this._data.end_star == 1) { picPath = `cg1/${lvCfg.oneStarCG}` talkStr = lvCfg.oneStarSummary } else { picPath = `cg0/${lvCfg.failureCG}` talkStr = lvCfg.failureSummary } let cgPic = this._nodeTab.cgPic.getComponent(Sprite) ResManager.I.changeBundleSpriteFrame(cgPic, picPath, "Raw") Utils.setString(this._nodeTab.labTalk, talkStr) //保存关卡星级 if (lvCfg.star < this._data.end_star) { GameManager.SetLevelStar(GameManager.CurLevelId, this._data.end_star) } //按钮显示 let swtRestart = false let swtContinue = false let swtShare = false if (this._data.end_star == 0) { swtRestart = true } else { let curCnt = GameManager.srouceCnt let stepData = GameManager.CurLevelData if (curCnt < stepData.total_cnt) { swtContinue = true } else { swtShare = true } } this._nodeTab.btnRestart.active = swtRestart this._nodeTab.btnContinue.active = swtContinue this._nodeTab.btnShare.active = swtShare this._nodeTab.labXQCount.active = swtRestart //刷新npc表情 let emoInfo = GameManager.GetNpcEmoPic("") let videoPath = HttpUnit.GetBgVideoUrl(emoInfo.emoName) Utils.sendInnerMsg(InnerMsgCode.SceneLayerBgUp, {rolePath:emoInfo.rolePath, videoPath:videoPath, videoType: emoInfo.videoType}) //刷新玩家数据 Utils.setString(this._nodeTab.labXQCount, "") HttpUnit.ins.getUserData((userData) => { //剩余相亲次数 let xqnum = HttpUnit.GetXiangqinTickets() Utils.setString(this._nodeTab.labXQCount, `剩余相亲次数:${xqnum}`) }) } update(deltaTime: number) { } //接收重玩消息 resiveResartGame(data:any) { this.onClose() } //返回主界面 backToMain() { GameManager.EndGame() ViewManager.I.closeAllView(); Utils.sendInnerMsg(InnerMsgCode.UI_Talk_Back, {}) } //点击返回 onBackClick() { this.backToMain() } //点击重玩 onRestartClick() { GameRootUI.DisableOper(1) GameManager.RestartGame() } //点击继续 onContinueClick() { this._doContinueGame() } //继续游戏 private _doContinueGame() { GameRootUI.DisableOper(0.5) HttpUnit.ins.sendGameContinue({record_id:GameManager.RecordId, level_id:GameManager.CurLevelId}, (data) => { if (data == null) return Utils.sendInnerMsg(InnerMsgCode.Data_LevelStarUp, {level:GameManager.CurLevelId, star:this._data.end_star}) GameManager.TurnToStage(E_TalkStage.upTalkStatus, true) this.onClose() }) } /**肖像放大缩小 */ changePicScale() { let ttime = 0.3; GameRootUI.DisableOper(ttime+0.1) if (this.isPicFull) { this.isPicFull = false; tween((this._nodeTab.cgPic as Node)) .to(ttime, { scale: this.picDefScale }, { easing: 'quadOut' }) .start(); let hideNodeOpa:UIOpacity = this._nodeTab.hideNode.getComponent(UIOpacity) tween(hideNodeOpa) .delay(ttime*0.7) .to(ttime*0.3, { opacity: 255 }, { easing: 'quadOut' }) .start(); } else { this.isPicFull = true; let s = 1 let windowSize = view.getVisibleSize(); // 获取窗口大小 let picTf:UITransform = this._nodeTab.cgPic.getComponent(UITransform); if (picTf.height < windowSize.height) { s = windowSize.height / picTf.height; } let centerScale = this._nodeTab.center.scale; if (centerScale.y < 1) { s = s / centerScale.y; //根节点有做适配,这里还原适配做的缩放 } tween((this._nodeTab.cgPic as Node)) .to(ttime, { scale: new Vec3(s, s, s) }, { easing: 'quadOut' }) .start(); let hideNodeOpa:UIOpacity = this._nodeTab.hideNode.getComponent(UIOpacity) tween(hideNodeOpa) .to(ttime*0.3, { opacity: 0 }, { easing: 'quadOut' }) .start(); } } /**星星动作 */ private doStarAction1(node:Node, tdelay:number) { let ttime = 0.5; //透明效果 let opa = node.getComponent(UIOpacity) if (!opa) { opa = node.addComponent(UIOpacity) } opa.opacity = 0 tween(opa) .delay(tdelay) .to(ttime, { opacity: 255 }, { easing: 'quadIn' }) .start(); //缩放效果 node.setScale(new Vec3(3, 3, 3)) tween(node) .delay(tdelay) .to(ttime, { scale: new Vec3(1, 1, 1) }, { easing: 'quadIn' }) .start(); //旋转效果 tween(node) .delay(tdelay) // .to(ttime, { angle: 720 }, { easing: 'quadOut' }) .to(ttime, { eulerAngles: new Vec3(0, 0, 360) }, { easing: 'quadIn' }) .start(); } private doStarAction2(node:Node, tdelay:number) { let ttime = 0.5; //透明效果 let opa = node.getComponent(UIOpacity) if (!opa) { opa = node.addComponent(UIOpacity) } opa.opacity = 0 tween(opa) .delay(tdelay) .to(ttime, { opacity: 255 }, { easing: 'quadIn' }) .start(); //缩放效果 tween(node) .delay(tdelay) .to(ttime*0.5, { scale: new Vec3(1.3, 1.3, 1.3) }, { easing: 'quadIn' }) .to(ttime*0.5, { scale: new Vec3(1, 1, 1) }, { easing: 'quadOut' }) .start(); } }