import { _decorator, Component, Label, Node } from "cc"; import li_BaseView from "../../../Main/Common/li_BaseView"; import Utils from "../../../Main/Common/Utils"; import { CommercialData } from "../../data/CommercialData"; import ConfigManager from "../../manager/ConfigManager"; import { GButton } from "../../../Main/Common/GButton"; import { PurchasePanelItem } from "../../uiitems/PurchasePanelItem"; import { ViewManager } from "../../../Main/Manager/ViewManager"; import LanguageUtils from "../../../Main/Common/LanguageUtils"; import { InnerEventCode } from "../../../Main/Config/InnerMsgCode"; const { ccclass, property } = _decorator; @ccclass("PurchasePanel") export class PurchasePanel extends li_BaseView { private _nodeTab: any = {}; private diamondCount: Label; private vipLeftTime: Label; private vipPriceTag: Label; private tryBuyId: number; @property([PurchasePanelItem]) public items: PurchasePanelItem[] = []; onLoadCT(): void { Utils.parseNode(this.node, this._nodeTab); this.diamondCount = this._nodeTab.diamondNumber.getComponent(Label); this.vipLeftTime = this._nodeTab.vipText.getComponent(Label); this.vipPriceTag = this._nodeTab.vipPrice.getComponent(Label); this.bandBtn(); //订阅商业化数据事件 Utils.addInnerEL( InnerEventCode.DiamondCountChanged, this, this.onDiamondCountChanged ); Utils.addInnerEL( InnerEventCode.VipEndDayChange, this, this.onVipEndDayChange ); //获取商业化数据 this.getPlayerMerData(); const cfg = ConfigManager.tables.TbPurchaseConfig; for (let index = 0; index < this.items.length; index++) { const element = this.items[index]; element.init(this, cfg.get(1001 + index)); } this.updateView(); } bandBtn() { GButton.BandClick( this._nodeTab.BuyVipBtn, () => { //TODO:购买vip console.log("购买Vip"); }, this ); GButton.BandClick( this._nodeTab.BuyDiamondBtn, () => { //TODO:购买钻石 console.log("购买钻石,商品id:" + this.tryBuyId); }, this ); GButton.BandClick( this._nodeTab.QUIT, () => { //TODO:购买钻石 ViewManager.I.closeView(this.node); }, this ); } updateView() { this.getPlayerMerData(); const vipPrice = ConfigManager.tables.TbPurchaseConfig.get(2001).count; this.vipPriceTag.string = `$ ${vipPrice}`; this.items.forEach((item) => item.show()); } setDiamondTag(id: number) { this.tryBuyId = id; } getPlayerMerData() { //todo: 获取服务器玩家商业化数据 this.diamondCount.string = CommercialData.Instance.diamondCount.toString(); const leftTime = CommercialData.Instance.getVipLeftTime(); this.vipLeftTime.string = LanguageUtils.getText( "purchasepanel.vip_left" ).replace("${leftTime}", leftTime); } onDiamondCountChanged(data: any) { this.diamondCount.string = data.count.toString(); } onVipEndDayChange(data: any) { const leftTime = CommercialData.Instance.getVipLeftTime(); this.vipLeftTime.string = LanguageUtils.getText( "purchasepanel.vip_left" ).replace("${leftTime}", leftTime); } onDestroy() { Utils.removeInnerEL( InnerEventCode.DiamondCountChanged, this, this.onDiamondCountChanged ); Utils.removeInnerEL( InnerEventCode.VipEndDayChange, this, this.onVipEndDayChange ); super.onDestroy(); } }