123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import { __BuyPandoraData } from "../../data/sdata/SManage";
- /**
- * 充值节点
- */
- const { ccclass, property } = cc._decorator;
- interface PlayerPandora {
- count: number
- data: Map<string, number>
- }
- const descList = {
- 1001: "<color=#FFFFFF>包含1件</c>普通、<color=#3DFF00>精良</color>、<color=#0fffff>稀有</color>的物品",
- 1002: "<color=#FFFFFF>包含1件</c><color=#0fffff>稀有</color>、<color=#E62CFF>史诗</color>、<color=#FFE000>传说</color>的物品",
- 1003: "<color=#FFFFFF>包含10件</c><color=#0fffff>稀有</color>、<color=#E62CFF>史诗</color>、<color=#FFE000>传说</color>的物品"
- }
- @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<string, number> = new Map;
- drawMap: Map<string, number> = 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 = `<color=#0fffff>${10 - count}次内</c><color=#ffffff>必得<color=#ffff00>传说<color=#ffffff>物品</color>`;
- } else if (id == 1003) {
- this.pandoraDrawCount = 10;
- this.lbtext.string = `<color=#ffffff>必得<color=#ffff00>传说<color=#ffffff>物品</color>`;
- }
- 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 = `<color=#0fffff>${this.drawMap[id]}次内</c><color=#ffffff>必得<color=#ffff00>传说<color=#ffffff>物品</color>`;
- }
- }
- public setCallback(callback: (item: ShopPandoraItem) => void) {
- this.callback = callback
- }
- public onclick() {
- this.callback(this)
- }
- }
|