import { _decorator, Component, Node, Label, Prefab, instantiate } from 'cc'; import { RewardVideoSystem } from '../../ad/RewardVideoSystem'; import { DataSystem } from '../../core/data/DataSystem'; import { Http, HttpResponseCode } from '../../core/net/Http'; import { CountDown } from '../../core/ui/CountDown'; import { WindowSystem } from '../../core/ui/window/WindowSystem'; import { Utils } from '../../core/utils/Utils'; import { ConfigData } from '../../data/ConfigData'; import { FormationData } from '../../hero/formation/FormationData'; import { UserHeroData } from '../../hero/UserHeroData'; import { ReportThinking } from '../../ReportThinking'; import { MarshalData } from '../MarshalData'; import { MarshalSkillSystem } from '../MarshalSkillSystem'; import { SwitchSkillItem } from './SwitchSkillItem'; const { ccclass, property } = _decorator; /** * 统帅技能切换界面 * @author 郑聂华 */ @ccclass('MarshalSkillSwitchUI') export class MarshalSkillSwitchUI extends Component { @property({ type: Label, displayName: "计时器", tooltip: "计时器" }) txtTime: Label = null; @property({ type: Node, displayName: "广告节点", tooltip: "广告节点" }) nodeAd: Node = null; @property({ type: Node, displayName: "广告按钮", tooltip: "广告按钮" }) btnAd: Node = null; @property({ type: Node, displayName: "广告按钮灰色", tooltip: "广告按钮灰色" }) btnAdNo: Node = null; @property({ type: Node, displayName: "文本剩余广告节点", tooltip: "文本剩余广告节点" }) txtAdtimesNode: Node = null; @property({ type: Label, displayName: "文本剩余广告次数", tooltip: "文本剩余广告次数" }) txtRemaindAdtimes: Label = null; @property({ type: Node, displayName: "技能内容节点", tooltip: "技能内容节点" }) contentSkill: Node = null; @property({ type: CountDown, displayName: "倒计时组件", tooltip: "倒计时组件" }) countDown: CountDown = null; @property({ type: Prefab, displayName: "技能Item预制体", tooltip: "技能Item预制体" }) skillItemPrefab: Prefab = null; //注意 MarshalData数据的创建 目前在GameInit中初始化 private clearAdNum: number = 0; //剩余清除cd次数 private cfg: any; private remaindTime = 0; start() { this.initMarshalSkillClearNum(); this.initPanel(); } /**倒计时更新方法*/ public updateTxt(progress) { this.txtTime.string = "技能冷却中:" + Utils.formatCountDown(progress * 1000); } /**倒计时结束方法*/ public async finishCooling() { this.remaindTime = 0; this.updateAdInfo(); } /**界面初始化*/ private async initPanel() { this.cfg = DataSystem.getData(ConfigData).get("serverConfig"); let formationData = DataSystem.getData(FormationData); await formationData.pull(this.getComponent(Http)); let marshalData = DataSystem.getData(MarshalData); await MarshalSkillSystem.updateSkillLvData(this.getComponent(Http)); let date = new Date(); let detlaTime = date.getTime() - marshalData.skillCoolingTime; if (detlaTime >= this.cfg.skillCD * 1000) { this.remaindTime = 0; } else { this.remaindTime = this.cfg.skillCD - detlaTime * 0.001; } this.countDown.value = this.remaindTime > 0 ? this.remaindTime : 0; this.updateAdInfo(); if (!this.countDown.running && this.remaindTime) { this.countDown.value = this.remaindTime; this.countDown.play(); } let tempKeys = marshalData.marshalSkillData.lvNeedStarsMap.keys(); let hero = formationData.get(5) ? DataSystem.getData(UserHeroData).get(formationData.get(5)).client : DataSystem.getData(ConfigData).get("general")[111001]; for (let id of tempKeys) { if (marshalData.marshalSkillData.lvMarshalSkill.get(id) > 0) { let tempNode = instantiate(this.skillItemPrefab); tempNode.active = true; this.contentSkill.addChild(tempNode); let scr = tempNode.getComponent(SwitchSkillItem); scr.updateInfo(hero, id, marshalData.marshalSkillData.lvMarshalSkill.get(id)); } } } /**跟新广告节点显示*/ private updateAdInfo() { this.nodeAd.active = this.btnAd.active = this.remaindTime > 0; this.btnAdNo.active = this.clearAdNum == 0; this.txtAdtimesNode.active = this.clearAdNum > 0; this.txtRemaindAdtimes.string = this.clearAdNum > 0 ? this.clearAdNum + "次" : "今日次数已用完"; this.txtTime.string = this.remaindTime > 0 ? "技能冷却中:" + Utils.formatCountDown(this.remaindTime * 1000) : ""; } /**获取清除cd次数*/ private initMarshalSkillClearNum() { let date = new Date(); if (!localStorage.getItem("ClearCdDay") || localStorage.getItem("ClearCdDay") != date.getDate() + "") { localStorage.setItem("ClearCdDay", date.getDate() + ""); localStorage.setItem("ClearCdNum", "3"); } this.clearAdNum = parseInt(localStorage.getItem("ClearCdNum")); } private async onClickAdBtn() { let resultAd = await this.getComponent(Http).send("/api/ad/watchVideoAD"); if (resultAd && resultAd.code == HttpResponseCode.Success) { //可以观看视频 ReportThinking.ad_init('marshalskillcd_clear'); let adData = await RewardVideoSystem.show(); if (adData) { ReportThinking.ad_end('marshalskillcd_clear'); let marshalData = DataSystem.getData(MarshalData); this.clearAdNum--; marshalData.skillCoolingTime -= this.cfg.skillCD * 1000; localStorage.setItem("MarshalCoolTime", marshalData.skillCoolingTime.toString()); this.remaindTime = 0; this.updateAdInfo(); localStorage.setItem("ClearCdNum", this.clearAdNum + ""); this.getComponent(Http).send("/api/task/AddWatchVideoADTimes", { adData: adData.obj }); } else { WindowSystem.showTips("观看视频失败"); } } else { WindowSystem.showTips("观看视频失败"); } } private onClickAdNoBtn() { console.log("today has no clear times"); WindowSystem.showTips("今日清除次数已用完"); } }