ShopPandoraItem.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { __BuyPandoraData } from "../../data/sdata/SManage";
  2. /**
  3. * 充值节点
  4. */
  5. const { ccclass, property } = cc._decorator;
  6. interface PlayerPandora {
  7. count: number
  8. data: Map<string, number>
  9. }
  10. const descList = {
  11. 1001: "<color=#FFFFFF>包含1件</c>普通、<color=#3DFF00>精良</color>、<color=#0fffff>稀有</color>的物品",
  12. 1002: "<color=#FFFFFF>包含1件</c><color=#0fffff>稀有</color>、<color=#E62CFF>史诗</color>、<color=#FFE000>传说</color>的物品",
  13. 1003: "<color=#FFFFFF>包含10件</c><color=#0fffff>稀有</color>、<color=#E62CFF>史诗</color>、<color=#FFE000>传说</color>的物品"
  14. }
  15. @ccclass
  16. export default class ShopPandoraItem extends cc.Component {
  17. @property(cc.RichText)
  18. lbdesc: cc.RichText = null;
  19. @property(cc.Label)
  20. lbtime: cc.Label = null;
  21. @property(cc.RichText)
  22. lbtext: cc.RichText = null;
  23. @property(cc.Label)
  24. videoNum: cc.Label = null;
  25. @property(cc.Label)
  26. diamondNum: cc.Label = null;
  27. @property(cc.Node)
  28. diamondButtom: cc.Node = null;
  29. @property(cc.Node)
  30. videoButtom: cc.Node = null;
  31. @property(cc.Sprite)
  32. icon: cc.Sprite = null;
  33. @property(cc.Label)
  34. lbname: cc.Label = null;
  35. shopId: number = 0;
  36. videoMap: Map<string, number> = new Map;
  37. drawMap: Map<string, number> = new Map;
  38. pandoraDrawCount: number = 0;
  39. needAmethyst: number = 0;
  40. public callback: (item: ShopPandoraItem) => void
  41. public _buyPandoraData: __BuyPandoraData
  42. public init(_buyPandoraData: __BuyPandoraData, useData: PlayerPandora) {
  43. this._buyPandoraData = _buyPandoraData;
  44. this.shopId = _buyPandoraData.id;
  45. this.lbdesc.string = descList[_buyPandoraData.id];
  46. this.lbname.string = _buyPandoraData.name;
  47. if (_buyPandoraData.adCount > 0) {
  48. let use = !useData.data[_buyPandoraData.id] ? 0 : useData.data[_buyPandoraData.id];
  49. if (_buyPandoraData.adCount - use > 0) {
  50. this.videoMap[String(_buyPandoraData.id)] = `${_buyPandoraData.adCount - use}`;
  51. this.videoNum.string = `${_buyPandoraData.adCount - use}`;
  52. this.videoButtom.active = true;
  53. this.diamondButtom.active = false;
  54. } else {
  55. this.videoButtom.active = false;
  56. this.diamondButtom.active = true;
  57. this.diamondNum.string = `${_buyPandoraData.goodId}`;
  58. }
  59. } else {
  60. this.videoButtom.active = false;
  61. this.diamondButtom.active = true;
  62. this.diamondNum.string = `${_buyPandoraData.goodId}`;
  63. }
  64. this.lbtime.node.active = _buyPandoraData.flushTime > 0;
  65. this.initIcon(_buyPandoraData.id);
  66. this.initText(_buyPandoraData.id, useData);
  67. }
  68. initText(id: number, useData: PlayerPandora) {
  69. if (id == 1001) {
  70. this.lbtext.node.active = false;
  71. this.pandoraDrawCount = 1;
  72. } else if (id == 1002) {
  73. this.pandoraDrawCount = 1;
  74. let count = !useData.count ? 0 : useData.count;
  75. this.drawMap[id] = 10 - count;
  76. this.lbtext.string = `<color=#0fffff>${10 - count}次内</c><color=#ffffff>必得<color=#ffff00>传说<color=#ffffff>物品</color>`;
  77. } else if (id == 1003) {
  78. this.pandoraDrawCount = 10;
  79. this.lbtext.string = `<color=#ffffff>必得<color=#ffff00>传说<color=#ffffff>物品</color>`;
  80. }
  81. this.needAmethyst = this._buyPandoraData.goodId;
  82. }
  83. public initIcon(id: number) {
  84. cc.resources.load('icon/magic_box/' + id, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
  85. if (err) {
  86. cc.error(err);
  87. } else {
  88. this.icon.spriteFrame = spriteFrame;
  89. }
  90. });
  91. }
  92. public refresh(id: number) {
  93. if (this.videoMap[id]) {
  94. this.videoMap[id]--;
  95. if (this.videoMap[id] == 0) {
  96. this.videoButtom.active = false;
  97. this.diamondButtom.active = true;
  98. this.diamondNum.string = `${this._buyPandoraData.goodId}`;
  99. } else {
  100. this.videoNum.string = this.videoMap[id];
  101. }
  102. }
  103. }
  104. public refreshDraw(id: number) {
  105. if (this.drawMap[id]) {
  106. this.drawMap[id]--;
  107. if (this.drawMap[id] == 0) {
  108. this.drawMap[id] = 10;
  109. }
  110. this.lbtext.string = `<color=#0fffff>${this.drawMap[id]}次内</c><color=#ffffff>必得<color=#ffff00>传说<color=#ffffff>物品</color>`;
  111. }
  112. }
  113. public setCallback(callback: (item: ShopPandoraItem) => void) {
  114. this.callback = callback
  115. }
  116. public onclick() {
  117. this.callback(this)
  118. }
  119. }