import { __BuyPandoraData } from "../../data/sdata/SManage"; /** * 充值节点 */ const { ccclass, property } = cc._decorator; interface PlayerPandora { count: number data: Map } const descList = { 1001: "包含1件普通、精良、稀有的物品", 1002: "包含1件稀有、史诗、传说的物品", 1003: "包含10件稀有、史诗、传说的物品" } @ccclass export default class ShopPandoraItem extends cc.Component { @property(cc.RichText) lbdesc: cc.RichText = null; @property(cc.Label) lbtime: cc.Label = null; @property(cc.RichText) lbtext: cc.RichText = null; @property(cc.Label) videoNum: cc.Label = null; @property(cc.Label) diamondNum: cc.Label = null; @property(cc.Node) diamondButtom: cc.Node = null; @property(cc.Node) videoButtom: cc.Node = null; @property(cc.Sprite) icon: cc.Sprite = null; @property(cc.Label) lbname: cc.Label = null; shopId: number = 0; videoMap: Map = new Map; drawMap: Map = new Map; pandoraDrawCount: number = 0; needAmethyst: number = 0; public callback: (item: ShopPandoraItem) => void public _buyPandoraData: __BuyPandoraData public init(_buyPandoraData: __BuyPandoraData, useData: PlayerPandora) { this._buyPandoraData = _buyPandoraData; this.shopId = _buyPandoraData.id; this.lbdesc.string = descList[_buyPandoraData.id]; this.lbname.string = _buyPandoraData.name; if (_buyPandoraData.adCount > 0) { let use = !useData.data[_buyPandoraData.id] ? 0 : useData.data[_buyPandoraData.id]; if (_buyPandoraData.adCount - use > 0) { this.videoMap[String(_buyPandoraData.id)] = `${_buyPandoraData.adCount - use}`; this.videoNum.string = `${_buyPandoraData.adCount - use}`; this.videoButtom.active = true; this.diamondButtom.active = false; } else { this.videoButtom.active = false; this.diamondButtom.active = true; this.diamondNum.string = `${_buyPandoraData.goodId}`; } } else { this.videoButtom.active = false; this.diamondButtom.active = true; this.diamondNum.string = `${_buyPandoraData.goodId}`; } this.lbtime.node.active = _buyPandoraData.flushTime > 0; this.initIcon(_buyPandoraData.id); this.initText(_buyPandoraData.id, useData); } initText(id: number, useData: PlayerPandora) { if (id == 1001) { this.lbtext.node.active = false; this.pandoraDrawCount = 1; } else if (id == 1002) { this.pandoraDrawCount = 1; let count = !useData.count ? 0 : useData.count; this.drawMap[id] = 10 - count; this.lbtext.string = `${10 - count}次内必得传说物品`; } else if (id == 1003) { this.pandoraDrawCount = 10; this.lbtext.string = `必得传说物品`; } this.needAmethyst = this._buyPandoraData.goodId; } public initIcon(id: number) { cc.resources.load('icon/magic_box/' + id, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => { if (err) { cc.error(err); } else { this.icon.spriteFrame = spriteFrame; } }); } public refresh(id: number) { if (this.videoMap[id]) { this.videoMap[id]--; if (this.videoMap[id] == 0) { this.videoButtom.active = false; this.diamondButtom.active = true; this.diamondNum.string = `${this._buyPandoraData.goodId}`; } else { this.videoNum.string = this.videoMap[id]; } } } public refreshDraw(id: number) { if (this.drawMap[id]) { this.drawMap[id]--; if (this.drawMap[id] == 0) { this.drawMap[id] = 10; } this.lbtext.string = `${this.drawMap[id]}次内必得传说物品`; } } public setCallback(callback: (item: ShopPandoraItem) => void) { this.callback = callback } public onclick() { this.callback(this) } }