ShopCoinItem.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { __BuyCoinData, __PayData } from "../../data/sdata/SManage";
  2. /**
  3. * 充值节点
  4. */
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class ShopCoinItem extends cc.Component {
  8. @property(cc.Label)
  9. addNum: cc.Label = null;
  10. @property(cc.Label)
  11. diamondNum: cc.Label = null;
  12. @property(cc.Node)
  13. diamond: cc.Node = null;
  14. @property(cc.Node)
  15. video: cc.Node = null;
  16. @property(cc.Label)
  17. maxCount: cc.Label = null;
  18. @property(cc.Sprite)
  19. icon: cc.Sprite = null;
  20. @property(cc.Node)
  21. lbtime: cc.Node = null;
  22. shopId: number = 0;
  23. videoId: number = 0;
  24. videoMap: Map<string, number> = new Map();
  25. public callback: (item: ShopCoinItem) => void
  26. public _buyCoinData: __BuyCoinData
  27. public init(_buyCoinData: __BuyCoinData, useData: Map<string, number>) {
  28. this._buyCoinData = _buyCoinData
  29. this.shopId = _buyCoinData.id;
  30. this.addNum.string = `+${_buyCoinData.money + _buyCoinData.gave}`;
  31. this.video.active = _buyCoinData.gold == 0;
  32. this.diamond.active = _buyCoinData.gold > 0;
  33. this.diamondNum.string = _buyCoinData.gold == 0 ? "免费" : _buyCoinData.gold + "";
  34. if (_buyCoinData.maxCount < 0) {
  35. this.maxCount.node.active = false;
  36. } else {
  37. let useNum = !useData[this.shopId] ? 0 : useData[this.shopId];
  38. this.maxCount.string = `剩余次数${_buyCoinData.maxCount - useNum}`;
  39. }
  40. if (_buyCoinData.gold == 0) {
  41. let useNum = !useData[this.shopId] ? 0 : useData[this.shopId];
  42. this.videoMap[this.shopId] = _buyCoinData.maxCount - useNum;
  43. this.videoId = this.shopId;
  44. }
  45. this.initIcon(_buyCoinData.id);
  46. }
  47. public initIcon(id: number) {
  48. cc.resources.load('icon/shop/money/' + id, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
  49. if (err) {
  50. cc.error(err);
  51. } else {
  52. this.icon.spriteFrame = spriteFrame;
  53. }
  54. });
  55. }
  56. public refresh(id: number) {
  57. this.videoMap[id]--;
  58. this.maxCount.string = `剩余次数${this.videoMap[id]}`;
  59. }
  60. public setCallback(callback: (item: ShopCoinItem) => void) {
  61. this.callback = callback
  62. }
  63. public onclick() {
  64. this.callback(this)
  65. }
  66. }