// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import { SaveDataManager } from "../../component/SaveDataManager"; import { SoundManager } from "../../component/SoundManager"; import { ADID, SoundName, WindowName } from "../../Global"; import { BattleManager } from "../../kernel/battle/BattleManager"; import { UserSkillShuriken } from "../../kernel/battle/userSkill/UserSkillShuriken"; import { UIBase } from "../UIBase"; import { UIManager } from "../UIManager"; const { ccclass, property } = cc._decorator; @ccclass export default class UIRevive extends UIBase { private _reviveCount: number = 0; private _diamondCount: number = 0; private _countDown: number = 5; private _countDownNodeList: cc.Node[] = []; @property(cc.Node) btn_ad: cc.Node = null; @property(cc.Node) btn_start: cc.Node = null; @property(cc.Node) btn_bonus: cc.Node = null; //#region LIFE-CYCLE CALLBACKS: openCount: number = 0; onLoad() { for (let i = 0; i < 6; ++i) { this._countDownNodeList.push(this.node.getChildByName('countdownNode').getChildByName('imgCount' + i.toString())) } } protected onEnable(): void { this._reviveCount = BattleManager.ins.curBattle.reviveCount; this._diamondCount = (this._reviveCount + 1) * 100; this.node.getChildByName('btnDelete3').getComponentInChildren(cc.Label).string = this._diamondCount.toString(); this.node.getChildByName('btnDelete3').getComponent(cc.Button).interactable = (SaveDataManager.ins.runtimeData.diamond >= this._diamondCount); this._countDown = 5; this.startCountDown(); this.onCountDown(); SoundManager.ins.playEffect(SoundName.CONTINUE); this.btn_ad.getChildByName('Background').getChildByName('UI_General_Btn_yellow_ckgg').active = true; this.btn_ad.getChildByName('Background').getChildByName('UI_Finish_kxsx').active = false; this.openCount++; if (this.openCount > 1) { this.BtnPos_Change(); } } //按钮位置轮换 BtnPos_Change() { let tempPos = this.btn_start.position; this.btn_start.position = this.btn_bonus.position; this.btn_bonus.position = this.btn_ad.position; this.btn_ad.position = tempPos; } protected onDisable(): void { this.unschedule(this.onCountDown); } // update (dt) {} //#endregion //#region public method //#endregion //#region event onDelete3Click() { if (SaveDataManager.ins.adjustDiamond(-this._diamondCount)) { //删除3行 for (let i = 0; i < 3; ++i) { new UserSkillShuriken(BattleManager.ins.curBattle).doSkillRevive(); } BattleManager.ins.curBattle.reviveCount++; BattleManager.ins.shootTouchEnable = true; //弹出此界面表示已经输了,操作被锁定,用技能后解锁 this.leave(); } else { //钻石不足 } } onReviveClick() { this.unschedule(this.onCountDown);//暂停倒计时 //AD 放广告, 然后调用 doRevive // HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => { if (true) { this.doRevive(); } else { console.log('视频播放失败'); } // }); } onAdClick() { this.unschedule(this.onCountDown);//暂停倒计时 //AD 放广告 放完后调 this.startCountDown } onCloseClick() { this.leave(); // UIManager.ins.openWindow(WindowName.BATTLE_RESULT, false);//弹出失败窗口 BattleManager.ins.curBattle.finishBattle(false, false); } private onCountDown() { if (this._countDown <= 0) { this.unschedule(this.onCountDown); this.onCloseClick(); } this._countDown--; this.updateCountDown(this._countDown); } //#endregion //#region private method private startCountDown() { this.schedule(this.onCountDown, 1, 5); } private doRevive() { new UserSkillShuriken(BattleManager.ins.curBattle).doSkillRevive(); BattleManager.ins.shootTouchEnable = true; //弹出此界面表示已经输了,操作被锁定,用技能后解锁 this.leave(); } private leave() { UIManager.ins.closeWindow(WindowName.REVIVE); } private updateCountDown(num: number) { for (let i = 0; i < this._countDownNodeList.length; ++i) { this._countDownNodeList[i].active = (i == num); } } //#endregion }