ShopPowerItem.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { __BuyPowerData, __PayData } from "../../data/sdata/SManage";
  2. /**
  3. * 充值节点
  4. */
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class ShopPowerItem 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: ShopPowerItem) => void
  26. public _buyPowerData: __BuyPowerData
  27. public init(_buyPowerData: __BuyPowerData, useData: Map<string, number>) {
  28. this._buyPowerData = _buyPowerData
  29. this.shopId = _buyPowerData.id;
  30. this.addNum.string = `+${_buyPowerData.power}`;
  31. this.video.active = _buyPowerData.gold == 0;
  32. this.diamond.active = _buyPowerData.gold > 0;
  33. this.diamondNum.string = _buyPowerData.gold == 0 ? "免费" : _buyPowerData.gold + "";
  34. if (_buyPowerData.maxCount < 0) {
  35. this.maxCount.node.active = false;
  36. } else {
  37. let useNum = !useData[this.shopId] ? 0 : useData[this.shopId];
  38. this.maxCount.string = `剩余次数${_buyPowerData.maxCount - useNum}`;
  39. }
  40. if (_buyPowerData.gold == 0) {
  41. let useNum = !useData[this.shopId] ? 0 : useData[this.shopId];
  42. this.videoMap[this.shopId] = _buyPowerData.maxCount - useNum;
  43. this.videoId = this.shopId;
  44. }
  45. this.initIcon(_buyPowerData.id);
  46. }
  47. public initIcon(id: number) {
  48. cc.resources.load('icon/shop/vigor/' + 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: ShopPowerItem) => void) {
  61. this.callback = callback
  62. }
  63. public onclick() {
  64. this.callback(this)
  65. }
  66. }