//#region 文件引入 import { _decorator, Button, Component, Label, Node, sp, Sprite,Animation, RichText, ToggleContainer, instantiate, Toggle, SpriteFrame } from "cc"; import FrameLayout from "../../CComEx/FrameLayout"; import FrameScrollView from "../../CComEx/FrameScrollView"; import { EGongFaType, EGongFaTypeZh, GameTotalType, PropType, QualityType } from "../../const/GameEnum"; import { IWuGong, IGongFa } from "../../Mgr_CSV/CsvEnum"; import BaseUIForm from "../../Mgr_UI/BaseUIForm"; import { Global } from "../../Global"; import GFitem_Proxy from "./GFitem_Proxy"; import WuGongData from "../../const/WuGongData"; import RoleDataMgr from "../../Mgr_LocalData/RoleDataMgr"; import { IData } from "../../const/GameInterface"; import UIMgr from "../../Mgr_UI/UIMgr"; import { COLOR_PARAMS } from "../../const/GGameData"; import MesMgr from "../../MesEvent/MesMgr"; import { EGlobalEvent } from "../../MesEvent/EGlobalEvent"; import StringUtils from "../../ExUtils/StringUtils"; import { EUIForms } from "../../const/UIFormCnf"; import wugongitem_Proxy from "../UIPackage/wugongitem_Proxy"; import CsvMgr from "../../Mgr_CSV/CsvMgr"; //#endregion 文件引入 const {ccclass, property,menu} = _decorator; @ccclass("WuGongUI_Proxy") export default class WuGongUI_Proxy extends BaseUIForm{ //#region 节点自动生成 @property(RichText) ric_title: RichText = null; @property(RichText) ric_des: RichText = null; @property(Node) n_emptxt: Node = null; //#endregion 节点自动生成 @property(ToggleContainer) private mToggleGroup: ToggleContainer; @property(FrameScrollView) protected mScrollViewFrame: FrameScrollView; @property({type:[Label]}) protected mLabBookNums: Label[] = []; // 武功各品质数量 private mArrQualityNums: number[] = [0, 0, 0, 0, 0]; // 已学武功各品质数量 private mArrQualityLearnedNums: number[] = [0, 0, 0, 0, 0]; // @property(FrameLayout) // private mArrStarLayout: FrameLayout; // @property({type:[SpriteFrame]}) // protected mBgs: SpriteFrame[] = []; // @property({type:[SpriteFrame]}) // protected mBgts: SpriteFrame[] = []; /**需要显示的目标功法 */ private mShowTypes:EGongFaType[] = [EGongFaType.剑法,EGongFaType.枪法,EGongFaType.刀法,EGongFaType.轻功,EGongFaType.内功]; /**当前选择的目标功法类型 */ private mSelectType: EGongFaType; private mWuGongs: WuGongData[] = []; // private mSelectWGData:WuGongData; private mGongFaTypeCnf:IGongFa; // private ArrZhNames:string[] =["上手","成长","基础"] // private ArrStarNums:number[]=[]; // /**升级当前功法所需金钱 */ // private canUpLv:boolean = true; // private mUpNeedCoin:number = 10000; onButtonClick(button:Button){ /**点击事件触发*/ switch (button) { // case this.btn_UpArr: // if(!this.canUpLv) return; // const result = RoleDataMgr.Ins.canUpgrade(this.mSelectWGData.config.type, this.mSelectWGData.id); // // 可升级 // if(result.res === 0){ // this.mDataMgr.Token.subToken(PropType.eGold, result.data.levelUp_paycoin); // RoleDataMgr.Ins.levelUpWg(result.data); // this.setSelectConfig(this.mSelectWGData); // }else if(result.res == -1){ // UIMgr.Ins.ShowTipsUI("升级失败,还没学会该功法"); // }else if(result.res == 1){ // // 钱不够,看视频免费升级 // UIMgr.Ins.ShowUI(EUIForms.GongFaUpUI,{param:{ // success:()=>{ // let wugong = RoleDataMgr.Ins.getWugong(this.mSelectWGData.config.type, this.mSelectWGData.id); // if (wugong) { // RoleDataMgr.Ins.levelUpWg(wugong); // this.setSelectConfig(this.mSelectWGData); // } // }, // fail:()=>{ // UIMgr.Ins.ShowTipsUI("升级失败,铜币不足") // }}}); // }else if(result.res == 2){ // UIMgr.Ins.ShowTipsUI("升级失败,根基不足"); // } // // 成功则更新进度并进入冷却 // this.canUpLv = false; // setTimeout(() => { // this.canUpLv = true; // }, 200); // break; default: ConsoleEx.Log(button); break; } } addEvent(): void { MesMgr.on(EGlobalEvent.E_UPDATE_TOKEN, this.refreshRedPoint, this); MesMgr.on(EGlobalEvent.USENEW_WUGONG, this.refreshUseNewWg, this); this.mScrollViewFrame.m_ItemRendererFuntion = this.ItemRenderer.bind(this) // this.mArrStarLayout.m_ItemRendererFuntion = this.ArrItemRender.bind(this) this.CreateToggle(); } protected start(): void { this.setTypeList(EGongFaType.剑法); const csvwugong = Global.CsvMgr.WuGong_csv; for (const key in csvwugong) { const cfg = csvwugong[key]; this.mArrQualityNums[cfg.quality - 1]++; if(this.mDataMgr.Role.isLearned(cfg.id)){ this.mArrQualityLearnedNums[cfg.quality - 1]++; } } for(let i = 0; i < this.mLabBookNums.length; i++){ this.mLabBookNums[i].string = `${this.mArrQualityLearnedNums[i]}/${this.mArrQualityNums[i]}`; } } //#region 武功信息展示 private setTypeList(type:EGongFaType){ // this.canUpLv = true; if(this.mSelectType == type){ return;} this.mSelectType = type; this.mWuGongs = RoleDataMgr.Ins.wugongs[type]; this.mGongFaTypeCnf = Global.CsvMgr.GongFa_csv[type]; CNodeUtils.switchRichText(this.ric_title, `*自动启用${this.mGongFaTypeCnf.key_name}最高的武学`); // CNodeUtils.switchText(this.lab_gongfaDes, this.mGongFaTypeCnf.desc); const wgnum = this.mWuGongs.length; // if(wgnum > 0){ // this.setSelectConfig(this.mWuGongs[0]); // }else{ // this.mSelectWGData = null; this.reflashScrollView(); // } CNodeUtils.setActive(this.n_emptxt,wgnum == 0); // CNodeUtils.setActive(this.n_hline, wgnum > 0); // CNodeUtils.setActive(this.n_gfnode, wgnum > 0); // CNodeUtils.setActive(this.n_gfctlnode, wgnum > 0); } // private setSelectConfig(wgData:WuGongData){ // this.mSelectWGData = wgData; // this.reflshWugongInfo(); // this.reflashScrollView(); // } // refreshNeedCoin():boolean{ // const cost = this.mSelectWGData.levelUp_paycoin; // const enough = this.mDataMgr.Token.checkToken(PropType.eGold, cost); // this.lab_NeedCoin.color = enough? COLOR_PARAMS.BLACK:COLOR_PARAMS.RED; // CNodeUtils.switchText(this.lab_NeedCoin, StringUtils.formatLargeNumber(cost)); // return enough; // } // reflshWugongInfo(){ // this.spr_gfbg.spriteFrame = this.mBgs[this.mSelectWGData.config.quality - 1]; // this.spr_gfpbg.spriteFrame = this.mBgts[this.mSelectWGData.config.quality - 1]; // const iData:IData = { // type: GameTotalType.WUGONG, // id: this.mSelectWGData.config.id, // num:1, // } // CNodeUtils.SwitchTextureByData(this.spr_shadow, iData); // this.ArrStarNums = [ // this.mSelectWGData.config.talent, // this.mSelectWGData.config.grow, // this.mSelectWGData.config.overAll, // ]; // this.mArrStarLayout.m_ItemCount = this.ArrZhNames.length; // const need = this.mSelectWGData.levelUp_condition > 0; // CNodeUtils.setActive(this.n_need, need); // if(need){ // // const strcondition = this.mSelectWGData.levelUp_condition > 0? (`根基要求 ${this.mSelectWGData.levelUp_condition}`) : ''; // this.lab_upCondtion.color = RoleDataMgr.Ins.wuxue >= this.mSelectWGData.levelUp_condition? COLOR_PARAMS.BLACK:COLOR_PARAMS.RED; // CNodeUtils.switchText(this.lab_upCondtion, this.mSelectWGData.levelUp_condition); // } // // 升级消费 // const enough = this.refreshNeedCoin(); // // 等级名字 // CNodeUtils.switchText(this.lab_gongfaLv, `Lv.${this.mSelectWGData.level}`); // CNodeUtils.switchText(this.lab_gongfaName, this.mSelectWGData.config.name); // /**基础属性 */ // CNodeUtils.switchText(this.lab_Arr_num1, `${this.mGongFaTypeCnf.key_name} ${this.mSelectWGData.value_keyAtt}`); // /**属性1 */ // CNodeUtils.switchText(this.lab_Arr_num2, `${this.mGongFaTypeCnf.prop1} +${this.mSelectWGData.attainment}`); // /**属性2 */ // const haveprop2 = this.mGongFaTypeCnf.prop2 && this.mGongFaTypeCnf.prop2.length > 0; // CNodeUtils.setActive(this.lab_Arr_num3, haveprop2); // if (haveprop2) { // CNodeUtils.switchText(this.lab_Arr_num3, `${this.mGongFaTypeCnf.prop2} +${this.mSelectWGData.attainment}`); // } // /**红点 */ // CNodeUtils.setActive(this.n_red, enough && (!need || RoleDataMgr.Ins.wuxue >= this.mSelectWGData.levelUp_condition)); // } // private ArrItemRender(idx:number,tNode:Node){ // const title = tNode.getChildByName("title"); // CNodeUtils.switchText(title, this.ArrZhNames[idx]) // const Layout = tNode.getChildByName("Layout").getComponent(FrameLayout); // Layout.m_ItemCount = this.ArrStarNums[idx]; // } //#endregion //#region 武功列表渲染 //#region 拥有的目标功法类型 列表 ItemRenderer(idx:number,tNode:Node){ const wgdata = this.mWuGongs[idx]; // CNodeUtils.addBtnComponent(tNode,this.ItemClick.bind(this,wgdata),this); // const uplvres = RoleDataMgr.Ins.canUpgrade(wgdata.config.type, wgdata.id); const ClassPoxy: wugongitem_Proxy = tNode.getComponent(wugongitem_Proxy); ClassPoxy.initWGInfo(wgdata); // ClassPoxy.setInfo(wgdata); // ClassPoxy.setShow(this.mSelectWGData.id == wgdata.config.id); // ClassPoxy.setRedPoint(uplvres.res === 0); // (uplvres.res === 0) && (this.canUpLv = true); } // private ItemClick(wgdata:WuGongData){ // if (this.mSelectWGData.id == wgdata.config.id) {return;} // this.setSelectConfig(wgdata); // } private reflashScrollView(){ // this.canUpLv = false; this.mScrollViewFrame.m_ItemCount = this.mWuGongs.length; } //#endregion //#endregion //#region 功法Toggle列表 onToggle_ToggleGroup(toggle:Toggle){ const type = +toggle.node.name; ConsoleEx.Log("选择了,",type) this.setTypeList(type); } private CreateToggle() { const ToggleChild = this.mToggleGroup.node.children; for (let i = 0; i < this.mShowTypes.length; i++) { const Type = this.mShowTypes[i]; let tNode = ToggleChild[i]; if (!tNode) { tNode = instantiate(ToggleChild[0]); tNode.setParent(this.mToggleGroup.node); tNode.setPosition(0, 0); tNode.active = true; } tNode.name = `${Type}`; const red = tNode.getChildByName("red"); const title = tNode.getChildByName("title"); const title2 = tNode.getChildByName("Checkmark").getChildByName("title"); CNodeUtils.switchText(title, EGongFaTypeZh[Type]); CNodeUtils.switchText(title2, EGongFaTypeZh[Type]); CNodeUtils.setActive(red, this.mDataMgr.Role.canUpgradeByType(Type)); } } //#endregion //#region 刷新红点 private refreshRedPoint(type:PropType) { if(type !== PropType.eGold){ return; } for (let i = 0; i < this.mShowTypes.length; i++) { let tNode = this.mToggleGroup.node.children[i]; const red = tNode.getChildByName("red"); CNodeUtils.setActive(red, this.mDataMgr.Role.canUpgradeByType(this.mShowTypes[i])); } for (let i = 0; i < this.mScrollViewFrame.m_ItemCount; i++){ let tNode = this.mScrollViewFrame.getChildItem(i); if(tNode){ // const wgdata = this.mWuGongs[i]; // const uplvres = RoleDataMgr.Ins.canUpgrade(wgdata.config.type, wgdata.id); const ClassPoxy: wugongitem_Proxy = tNode.getComponent(wugongitem_Proxy); ClassPoxy.refreshCoin(); // ClassPoxy.setRedPoint(uplvres.res === 0); } } // this.refreshNeedCoin(); } private refreshUseNewWg(oldwgid:number) { if(oldwgid === 0){ return; } for (let i = 0; i < this.mScrollViewFrame.m_ItemCount; i++){ let tNode = this.mScrollViewFrame.getChildItem(i); if(tNode){ const ClassPoxy: wugongitem_Proxy = tNode.getComponent(wugongitem_Proxy); ClassPoxy.refreshUseNew(oldwgid); } } // this.refreshNeedCoin(); } //#endregion }