You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
6.4 KiB
162 lines
6.4 KiB
//#region 文件引入
|
|
import { _decorator, Button, Component, Label, Node, sp, Sprite,Animation, RichText, Toggle, NodeEventType } from "cc";
|
|
import BaseUIForm from "../../Mgr_UI/BaseUIForm";
|
|
import { PropType } from "../../const/GameEnum";
|
|
import FrameScrollView from "../../CComEx/FrameScrollView";
|
|
import GDUtils from "../../ExCUtils/GDUtils";
|
|
import TimeUtils from "../../ExUtils/TimeUtils";
|
|
import { Global } from "../../Global";
|
|
import treasureItem_Proxy from "./treasureItem_Proxy";
|
|
import { IProp } from "../../Mgr_CSV/CsvEnum";
|
|
import UIMgr from "../../Mgr_UI/UIMgr";
|
|
import { EUIForms } from "../../const/UIFormCnf";
|
|
import MesMgr from "../../MesEvent/MesMgr";
|
|
import { EGlobalEvent } from "../../MesEvent/EGlobalEvent";
|
|
//#endregion 文件引入
|
|
const {ccclass, property,menu} = _decorator;
|
|
@ccclass("TreasureUI_Proxy")
|
|
export default class TreasureUI_Proxy extends BaseUIForm{
|
|
//#region 节点自动生成
|
|
@property(Node)
|
|
n_shop: Node = null;
|
|
@property(Label)
|
|
lab_desc: Label = null;
|
|
@property(Label)
|
|
lab_num: Label = null;
|
|
@property(Button)
|
|
btn_Details: Button = null;
|
|
@property(Node)
|
|
n_record: Node = null;
|
|
@property(Label)
|
|
lab_time: Label = null;
|
|
@property(Label)
|
|
lab_time_title: Label = null;
|
|
@property(Node)
|
|
n_time_star: Node = null;
|
|
@property(Label)
|
|
lab_fight: Label = null;
|
|
@property(Label)
|
|
lab_fight_title: Label = null;
|
|
@property(Node)
|
|
n_fight_star: Node = null;
|
|
@property(Button)
|
|
btn_Restart: Button = null;
|
|
//#endregion 节点自动生成
|
|
@property(FrameScrollView)
|
|
protected mScrollViewFrame: FrameScrollView;
|
|
|
|
private mPageName:string = '';
|
|
|
|
// 首次免费
|
|
private isFirstFree:boolean = true;
|
|
|
|
onButtonClick(button:Button){
|
|
|
|
/**点击事件触发*/
|
|
switch (button) {
|
|
case this.btn_Restart:
|
|
UIMgr.Ins.ShowUI(EUIForms.PopRestartUI);
|
|
this.CloseUI();
|
|
break;
|
|
case this.btn_Details:
|
|
UIMgr.Ins.ShowUI(EUIForms.TreasureDetailUI);
|
|
break;
|
|
default:
|
|
ConsoleEx.Log(button);
|
|
break;
|
|
}
|
|
}
|
|
|
|
addEvent(): void {
|
|
MesMgr.on(EGlobalEvent.TREAS_BUY, this.refreshShop, this)
|
|
this.mScrollViewFrame.m_ItemRendererFuntion = this.ItemRenderer.bind(this)
|
|
}
|
|
|
|
protected start(): void {
|
|
CNodeUtils.setActive(this.btn_Restart, this.mDataMgr.Scene.level.passed);
|
|
this.refreshShop();
|
|
this.initPassRecord();
|
|
this.mPageName = "shop";
|
|
this.switchPage();
|
|
}
|
|
|
|
onToggle_ToggleGroup(tToggle:Toggle){
|
|
this.mPageName = tToggle.node.name;
|
|
this.switchPage();
|
|
}
|
|
|
|
switchPage() {
|
|
switch (this.mPageName) {
|
|
case "shop":
|
|
CNodeUtils.setActive(this.n_shop, true);
|
|
CNodeUtils.setActive(this.n_record, false);
|
|
// this.reflashScrollView();
|
|
break;
|
|
case "record":
|
|
CNodeUtils.setActive(this.n_shop, false);
|
|
CNodeUtils.setActive(this.n_record, true);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
//#region 珍宝列表
|
|
refreshShop(){
|
|
CNodeUtils.switchText(this.lab_num, this.mDataMgr.Token.getTokenCount(PropType.eAdopt));
|
|
this.isFirstFree = this.mDataMgr.Pass.passed_times == 1 && this.mDataMgr.Pass.free_times > 0;
|
|
CNodeUtils.setActive(this.lab_desc, this.isFirstFree);
|
|
this.reflashScrollView();
|
|
}
|
|
|
|
ItemRenderer(idx:number,tNode:Node){
|
|
const treascfg = Global.CsvMgr.Props_array_csv[idx];
|
|
const ClassPoxy: treasureItem_Proxy = tNode.getComponent(treasureItem_Proxy);
|
|
ClassPoxy.setData(treascfg,this.isFirstFree);
|
|
CNodeUtils.addBtnComponent(tNode, this.ItemClick.bind(this, treascfg), this);
|
|
}
|
|
|
|
private ItemClick(gData: IProp) {
|
|
UIMgr.Ins.ShowUI(EUIForms.PopBuyTreaUI, { param: {cfg:gData, isfree:this.isFirstFree} });
|
|
}
|
|
|
|
private reflashScrollView(){
|
|
this.mScrollViewFrame.m_ItemCount = Global.CsvMgr.Props_array_csv.length;
|
|
}
|
|
|
|
//#endregion
|
|
|
|
//#region 通关记录
|
|
private initPassRecord(){
|
|
const passtime = this.mDataMgr.Pass.record_times;
|
|
CNodeUtils.switchText(this.lab_time,TimeUtils.makeTimeLeftString(passtime, "分"));
|
|
CNodeUtils.switchText(this.lab_fight, this.mDataMgr.Pass.record_fight);
|
|
// 时间评级
|
|
const rating = this.mDataMgr.Pass.timeRatingConfig;
|
|
// 计算时间星星数量
|
|
const timeStars = rating.starFormula(passtime);
|
|
this.createStars(this.n_time_star, timeStars, rating.starLevel);
|
|
this.lab_time_title.color = this.lab_time_title.color.fromHEX(GDUtils.GetQualityColorHEX(rating.starLevel));
|
|
CNodeUtils.switchText(this.lab_time_title, rating.title);
|
|
|
|
// 战力评级
|
|
const fightingRating = this.mDataMgr.Pass.fightingRatingConfig;
|
|
// 计算战力星星数量
|
|
const fightStars = fightingRating.starFormula(this.mDataMgr.Role.fighting);
|
|
this.createStars(this.n_fight_star, fightStars, fightingRating.starLevel);
|
|
this.lab_fight_title.color = this.lab_fight_title.color.fromHEX(GDUtils.GetQualityColorHEX(fightingRating.starLevel));
|
|
CNodeUtils.switchText(this.lab_fight_title, fightingRating.title);
|
|
}
|
|
private createStars(tNode: Node, starCount: number, starLevel: number) {
|
|
// 限制星星数量不超过5个
|
|
starCount = Math.min(starCount, 5);
|
|
for (let i = 0; i < tNode.children.length; i++) {
|
|
let star = tNode.children[i];
|
|
CNodeUtils.setActive(star, i < starCount);
|
|
if(i < starCount){
|
|
let starIcon:Sprite = star.getComponent(Sprite);
|
|
starIcon.color = GDUtils.GetQualityColor(starLevel);
|
|
}
|
|
}
|
|
}
|
|
//#endregion
|
|
}
|