//#region 文件引入
import { _decorator, Button, Component, Label, Node, sp, Sprite,Animation, RichText, SpriteFrame } from "cc";
import BaseUIForm from "../../Mgr_UI/BaseUIForm";
import ConfidanteDataPoxy from "../../const/ConfidanteDataPoxy";
import { ConfidanteData } from "../../const/GameInterface";
import StringUtils from "../../ExUtils/StringUtils";
import { EVideoType, PropType } from "../../const/GameEnum";
import GDUtils from "../../ExCUtils/GDUtils";
import { COLOR_PARAMS } from "../../const/GGameData";
import { Global } from "../../Global";
import MesMgr from "../../MesEvent/MesMgr";
import { EGlobalEvent } from "../../MesEvent/EGlobalEvent";
import UIMgr from "../../Mgr_UI/UIMgr";
import { EUIForms } from "../../const/UIFormCnf";
//#endregion 文件引入
const {ccclass, property,menu} = _decorator;
@ccclass("MeridianUI_Proxy")
export default class MeridianUI_Proxy extends BaseUIForm{
//#region 节点自动生成
@property(Button)
btn_Close: Button = null;
@property(Node)
n_Notice: Node = null;
@property(Button)
btn_boxBgClose: Button = null;
@property(Button)
btn_boxClose: Button = null;
@property(Node)
n_upLvBox: Node = null;
@property(Sprite)
spr_uplvicon: Sprite = null;
@property(Label)
lab_paytj: Label = null;
@property(Label)
lab_uplvname: Label = null;
@property(RichText)
ric_currProp: RichText = null;
@property(RichText)
ric_nextProp: RichText = null;
@property(Button)
btn_UpLv: Button = null;
//#endregion 节点自动生成
@property(Node)
mMerList: Node = null;
@property({type:[SpriteFrame]})
protected mMerIcon: SpriteFrame[] = [];
private mMerData: ConfidanteData[] = [];
private currUpLvId: number = 0;
onButtonClick(button:Button){
/**点击事件触发*/
switch (button) {
case this.btn_boxBgClose:
case this.btn_boxClose:
CNodeUtils.setActive(this.n_Notice, false);
break;
// case this.btn_Ad:
// Global.showvideo({name: EVideoType.AddTjCoin, gamelv: this.mDataMgr.Scene.getRealLevel()},()=>{
// this.mDataMgr.Token.addToken(PropType.eTaiJi, 5);
// this.openUpLvBox(this.currUpLvId);
// UIMgr.Ins.ShowTipsUI("真气+ 5");
// });
// break;
case this.btn_Close:
this.CloseUI();
break;
default:
ConsoleEx.Log(button);
break;
}
}
addEvent(): void {
}
protected onEnable(): void {
MesMgr.event(EGlobalEvent.SHOW_MAINTOP_BUTTOM, false);
}
protected onDisable(): void {
MesMgr.event(EGlobalEvent.SHOW_MAINTOP_BUTTOM, true);
}
protected start(): void {
this.mDataMgr.Confidante.checkConfState();
this.mMerData = this.mDataMgr.Confidante.getConfidantes();
for(let i = 0; i < this.mMerList.children.length; i++){
const merData = this.mDataMgr.Confidante.getConfidanteById(this.mMerData[i].id);
let mer = this.mMerList.children[i];
let btnMer = mer.getComponent(Button);
let icon = mer.getComponent(Sprite);
let bg = mer.getChildByName("bg");
let lv = bg.getChildByName("txt_lv").getComponent(Label);
let desc = bg.getChildByName("txt_desc").getComponent(Label);
let name = bg.getChildByName("txt_name").getComponent(Label);
CNodeUtils.switchText(name, merData.config.name);
icon.spriteFrame = this.mMerIcon[merData.config.index];
if(merData.state){
btnMer.interactable = true;
icon.grayscale = false;
bg.getComponent(Sprite).grayscale = false;
lv.string = "Lv." + (merData.level);
desc.string = StringUtils.format(merData.config.display, this.mDataMgr.Confidante.getProp(merData.id));
}else{
btnMer.interactable = false;
icon.grayscale = true;
bg.getComponent(Sprite).grayscale = true;
lv.string = merData.config.unlockdesc;
desc.string = "";
}
mer.on(Button.EventType.CLICK, () => {
this.openUpLvBox(merData.id, i);
});
}
}
openUpLvBox(id:number, idx:number){
this.currUpLvId = id;
const merData = this.mDataMgr.Confidante.getConfidanteById(id);
let mer = this.mMerList.children[idx];
let lv = mer.getChildByPath("bg/txt_lv").getComponent(Label);
lv.string = "Lv." + (merData.level);
CNodeUtils.setActive(this.n_Notice, true);
CNodeUtils.switchText(this.lab_uplvname, merData.config.name);
this.spr_uplvicon.spriteFrame = this.mMerIcon[merData.config.index];
const tjcoin = this.mDataMgr.Token.getTokenCount(PropType.eTaiJi);
const enough = tjcoin >= merData.cost;
if(enough){
this.lab_paytj.color = COLOR_PARAMS.BLACK;
}else{
this.lab_paytj.color = COLOR_PARAMS.RED;
}
CNodeUtils.switchText(this.lab_paytj,`${tjcoin}/${merData.cost}`);
const currProp = this.mDataMgr.Confidante.getProp(merData.id);
const nextProp = merData.config.prop_add * (merData.level + 1);
const currtxt = StringUtils.format(merData.config.display, `${currProp}`);
CNodeUtils.switchRichText(this.ric_currProp,currtxt);
const nexttxt = StringUtils.format(merData.config.display, `${nextProp}`);
CNodeUtils.switchRichText(this.ric_nextProp,nexttxt);
this.btn_UpLv.node.off(Button.EventType.CLICK);
this.btn_UpLv.node.on(Button.EventType.CLICK,()=>{
const tjcoin = this.mDataMgr.Token.getTokenCount(PropType.eTaiJi);
if(tjcoin >= merData.cost){
this.mDataMgr.Token.subToken(PropType.eTaiJi,merData.cost);
this.mDataMgr.Confidante.addConfidante(id);
UIMgr.Ins.ShowTipsUI(`${merData.config.name}突破成功!`);
// 直接刷新
this.openUpLvBox(id,idx);
}else{
UIMgr.Ins.ShowUI(EUIForms.LookAdGetTJUI, {param:{isMain:false, okcallback:()=>{
this.openUpLvBox(this.currUpLvId, idx);
}}});
}
});
}
}