PayShopItem.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import Main from "../../main/Main";
  2. import { __PayData } from "../data/sdata/SManage";
  3. /**
  4. * 充值节点
  5. */
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class PayShopItem extends cc.Component {
  9. @property(cc.Label)
  10. mGold: cc.Label = null;
  11. @property(cc.Label)
  12. mGaveGold: cc.Label = null;
  13. @property(cc.Label)
  14. mRMB: cc.Label = null;
  15. @property(cc.Sprite)
  16. icon: cc.Sprite = null;
  17. @property(cc.Node)
  18. text: cc.Node = null;
  19. public callback: (item: PayShopItem) => void
  20. public _payData: __PayData
  21. public main: Main
  22. public init(_payData: __PayData, main: Main) {
  23. this._payData = _payData
  24. this.main = main;
  25. this.mGold.string = '' + _payData.gold
  26. this.mGaveGold.string = '+' + _payData.firstGive
  27. this.mRMB.string = '$' + _payData.usd
  28. this.initIcon(_payData.id);
  29. this.showFirstGave();
  30. }
  31. public initIcon(id: number) {
  32. cc.resources.load('icon/shop/gold/' + id, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
  33. if (err) {
  34. cc.error(err);
  35. } else {
  36. this.icon.spriteFrame = spriteFrame;
  37. }
  38. });
  39. }
  40. public isFirstPay() {
  41. if (this.main.player.firstPayGave.indexOf(this._payData.id) > -1) {
  42. return true;
  43. }
  44. return false;
  45. }
  46. public showFirstGave() {
  47. this.text.active = !this.isFirstPay();
  48. this.mGaveGold.node.active = !this.isFirstPay();
  49. }
  50. public setCallback(callback: (item: PayShopItem) => void) {
  51. this.callback = callback
  52. }
  53. public onclick() {
  54. this.callback(this)
  55. }
  56. }