//#region 文件引入 import { _decorator, Button, Component, Label, Node, sp, Sprite,Animation, RichText, ProgressBar, Toggle, random, SpriteFrame, Material } from "cc"; import BaseUIForm from "../../Mgr_UI/BaseUIForm"; import { ResUrlLoad } from "../../CComEx/ResUrlLoad"; import FrameScrollView from "../../CComEx/FrameScrollView"; import { IData, IGoodsData } from "../../const/GameInterface"; import { EBundleName, GameTotalType, PropType } from "../../const/GameEnum"; import MathUtils from "../../ExUtils/MathUtils"; import { Global } from "../../Global"; import TimeUtils from "../../ExUtils/TimeUtils"; import UIMgr from "../../Mgr_UI/UIMgr"; import { EUIForms } from "../../const/UIFormCnf"; import MesMgr from "../../MesEvent/MesMgr"; import { EGlobalEvent } from "../../MesEvent/EGlobalEvent"; import { MINIGAME } from "cc/env"; //#endregion 文件引入 const {ccclass, property,menu} = _decorator; @ccclass("FinalTrialUI_Proxy") export default class FinalTrialUI_Proxy extends BaseUIForm{ //#region 节点自动生成 @property(Label) lab_title: Label = null; @property(Node) n_trial: Node = null; @property(Node) n_binfo: Node = null; @property(ProgressBar) pro_BossHp: ProgressBar = null; @property(Label) lab_bossName: Label = null; @property(Label) lab_bossHp: Label = null; @property(Label) lab_refreshDesc: Label = null; @property(sp.Skeleton) spi_boss: sp.Skeleton = null; @property(Node) n_dialogue: Node = null; @property(Label) lab_dialogue: Label = null; @property(Label) lab_challengenum: Label = null; @property(Button) btn_help: Button = null; @property(Node) n_times: Node = null; @property(Label) lab_lefttimes: Label = null; @property(Label) lab_addhurt: Label = null; @property(Node) n_coin: Node = null; @property(Label) lab_rankreward: Label = null; @property(Button) btn_rankhurt: Button = null; @property(Button) btn_chanllenge: Button = null; @property(Button) btn_nochanllenge: Button = null; @property(Button) btn_rankreward: Button = null; @property(Node) n_CanNotLabel: Node = null; @property(Node) n_shop: Node = null; @property(sp.Skeleton) spi_redlight: sp.Skeleton = null; //#endregion 节点自动生成 //#region 试炼 @property(ResUrlLoad) rewardIcon:ResUrlLoad = null; @property({type:[Node]}) chanllengeNode:Node[] = []; //#endregion 试炼 //#region 藏经阁 @property(FrameScrollView) protected mScrollViewFrame: FrameScrollView; @property({type:[Label]}) tokenlabels:Label[] = []; //#endregion 藏经阁 @property({type:[SpriteFrame]}) protected mBgs: SpriteFrame[] = []; @property(Material) protected mSpineGrayMat: Material; private mToggleType:string = ""; private mSelectedBoss: number = -1; private _leftSec: number = 0; // 挑战刷新时间 onButtonClick(button:Button){ /**点击事件触发*/ switch (button) { case this.btn_help: UIMgr.Ins.ShowUI(EUIForms.FinalTrialDetailsUI) break; case this.btn_rankhurt: UIMgr.Ins.ShowUI(EUIForms.FinalTrialRankUI, { param: this.mSelectedBoss }) break; case this.btn_chanllenge: this.mDataMgr.Trial.startTrial(this.mSelectedBoss); this.CloseUI(); break; case this.btn_rankreward: UIMgr.Ins.ShowUI(EUIForms.FinalTrialReWardUI, { param: this.mSelectedBoss }) break; default: ConsoleEx.Log(button); break; } } protected CloseUI(btn?: Node): void { this.mSelectedBoss = -1; this.unscheduleAllCallbacks(); super.CloseUI(btn); } addEvent(): void { this.mScrollViewFrame.m_ItemRendererFuntion = this.ItemRenderer.bind(this); MesMgr.on(EGlobalEvent.SHOP_REFRESH, this.refreshTrialShop, this); MesMgr.on(EGlobalEvent.TRIALREWARD_REFRESH, this.refreshRankReward, this); } protected start(): void { for (let i = 0; i < this.chanllengeNode.length; i++) { const btn_boss = this.chanllengeNode[i]; this.initBossInfo(btn_boss, i); btn_boss.off("click"); btn_boss.on("click", () => { this.selectTrialInfo(i); }) } // 剩余时间 this._leftSec = TimeUtils.GetRemainingTime(); CNodeUtils.switchText(this.lab_lefttimes, TimeUtils.makeTimeLeftString(this._leftSec)); this.schedule(()=>{ if(--this._leftSec >= 0){ CNodeUtils.switchText(this.lab_lefttimes, TimeUtils.makeTimeLeftString(this._leftSec)); }else{ this._leftSec = 0; this.CloseUI(); } }, 1) this.selectTrialInfo(this.mDataMgr.Trial.getCurrTrialBossIdx()); this.switchToggle("trial"); this.refreshTrialShop(); this.reflashScrollView(); } onToggle_ToggleGroup(tToggle:Toggle){ this.switchToggle(tToggle.node.name); } switchToggle(type) { this.mToggleType = type; switch (type) { case 'trial': CNodeUtils.setActive(this.n_trial,true); CNodeUtils.setActive(this.n_shop,false); break; case 'shop': CNodeUtils.setActive(this.n_trial,false); CNodeUtils.setActive(this.n_shop,true); break; } } //#region 挑战 // 只有在非周末领奖之后,才会关闭对应周末的领奖入口 private refreshRankReward(idx:number) { const tweek = TimeUtils.getWeek(); if(MINIGAME && ((tweek !== 6 && idx === 1) || (tweek !== 7 && idx === 2))){ CNodeUtils.setActive(this.btn_rankreward, false); } } private initBossInfo(node:Node, idx:number){ const icon = node.getChildByName("icon"); let data:IData = { type: GameTotalType.ENEMYICON, id: this.mDataMgr.Trial.getTrialConfig(idx).bossid, num:0 } CNodeUtils.SwitchTextureByData(icon, data); } selectTrialInfo(idx:number){ if(this.mSelectedBoss == idx) return; if(this.mSelectedBoss !== -1){ const goldbg = this.chanllengeNode[this.mSelectedBoss].getChildByName("goldbg"); CNodeUtils.setActive(goldbg, false); } this.mSelectedBoss = idx; const goldbg = this.chanllengeNode[idx].getChildByName("goldbg"); CNodeUtils.setActive(goldbg, true); // info const cfg = this.mDataMgr.Trial.getTrialConfig(idx); const bossConfig = Global.CsvMgr.Enemy_csv[cfg.bossid]; CNodeUtils.switchText(this.lab_bossName, bossConfig.name); // spine if(this.spi_boss.skeletonData?.name !== bossConfig.sp){ ConsoleEx.Warn("目标皮肤:",bossConfig.sp) CNodeUtils.SwitchSpine(this.spi_boss, `${bossConfig.sp}/${bossConfig.sp}`, EBundleName.Spine); } const tweek = TimeUtils.getWeek(); if(!MINIGAME || (idx === 0) || (tweek === 6 && idx === 1) || (tweek === 7 && idx === 2)){ CNodeUtils.setActive(this.btn_rankreward, true); CNodeUtils.setActive(this.n_binfo, true); CNodeUtils.setActive(this.n_CanNotLabel, false); this.spi_boss.customMaterial = null; }else{ CNodeUtils.setActive(this.btn_rankreward, this.mDataMgr.Trial.canGetReWards(idx)); CNodeUtils.setActive(this.n_binfo, false); CNodeUtils.setActive(this.n_CanNotLabel, true); this.spi_boss.customMaterial = this.mSpineGrayMat; return; } // hp const HpInfo = this.mDataMgr.Trial.getTrialBossHp(idx); let pro = HpInfo.hp / HpInfo.totalHP; const fixed = MathUtils.fixedDecimal(pro * 100, 2); CNodeUtils.switchText(this.lab_bossHp, fixed + "%"); this.pro_BossHp.progress = pro; CNodeUtils.setActive(this.btn_nochanllenge, HpInfo.hp <= 0); CNodeUtils.setActive(this.n_times, HpInfo.hp > 0); // dialog CNodeUtils.switchText(this.lab_dialogue, cfg.dialog); // 挑战人数 const passSec = TimeUtils.OneDayTime - this._leftSec; const passMin = Math.floor(passSec / 60); let addnum = passSec; if(passMin > 10){ addnum += MathUtils.randomRangeInt(0, passMin); } CNodeUtils.switchText(this.lab_challengenum, addnum); // 奖励 const tokenicon = this.n_coin.getComponent(ResUrlLoad); tokenicon.showResInfo(GameTotalType.TOKEN, cfg.rewardtoken); CNodeUtils.switchText(this.lab_addhurt, `+${this.mDataMgr.Pass.passed_times * 5}%`); CNodeUtils.switchText(this.lab_rankreward, `+${this.mDataMgr.Pass.passed_times * 10}`); } //#endregion //#region 商店 private refreshTrialShop(){ for (let i = 0; i < this.tokenlabels.length; i++) { const token = this.tokenlabels[i]; CNodeUtils.switchText(token, this.mDataMgr.Token.getTokenCount(i + PropType.eJXStone)); } } ItemRenderer(idx:number,tNode:Node){ const shop = this.mDataMgr.Trial.getTrialShopConfig(idx); const itemcfg = Global.CsvMgr.Items_csv[shop.id]; const tokenicon = tNode.getChildByPath("Layout/coin").getComponent(ResUrlLoad); const tokennum = tNode.getChildByPath("Layout/num"); const item_bg = tNode.getChildByName("item_bg").getComponent(Sprite); const item_icon = tNode.getChildByName("item_icon"); const item_name = tNode.getChildByName("item_name"); // 图标 item_bg.spriteFrame = this.mBgs[itemcfg.quality - 1]; const iData:IData = { type: GameTotalType.ITEM, id: shop.id, num:0, } CNodeUtils.SwitchTextureByData(item_icon, iData); CNodeUtils.switchTextByQuality(item_name, itemcfg.name, itemcfg.quality); // CNodeUtils.switchText(item_name, itemcfg.name); CNodeUtils.switchText(tokennum, itemcfg.price); tokenicon.showResInfo(GameTotalType.TOKEN, itemcfg.pricetype); // 品质特效 // if(itemcfg.quality === 6){ // CNodeUtils.setActive(this.spi_redlight, true); // this.spi_redlight.setAnimation(0, "idle", true); // }else{ // CNodeUtils.setActive(this.spi_redlight, false); // } // 道具 const goodData:IGoodsData = { id: shop.id, lock: false, }; CNodeUtils.addBtnComponent(tNode, this.ItemClick.bind(this, goodData, "trial"), this); } private ItemClick(gData: IGoodsData, stype:string) { UIMgr.Ins.ShowUI(EUIForms.ShopInfoUI, { param: {gData:gData, stype:stype} }); // UIMgr.Ins.ShowUI(EUIForms.ShopInfoUI, { param: gData }); } private reflashScrollView(){ this.mScrollViewFrame.m_ItemCount = this.mDataMgr.Trial.getTrialShopNum(); } //#endregion }