Content_Button.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * 货币类型,游戏币为默认
  3. */
  4. var CurrencyType = cc.Enum({
  5. GAME: 0,
  6. CNT: 1,
  7. SNB: 2
  8. });
  9. cc.Class({
  10. extends: cc.Component,
  11. properties: {
  12. Name: {
  13. default: '',
  14. tooltip: '建筑名称',
  15. },
  16. Price: {
  17. default: '',
  18. tooltip: '需要金币的价格',
  19. },
  20. DiamondPrice: {
  21. default: 1,
  22. type: cc.Integer,
  23. tooltip: '需要钻石的价格',
  24. },
  25. CNT: {
  26. default: '',
  27. tooltip: '需要CNT货币的价格',
  28. },
  29. SNB: {
  30. default: '',
  31. tooltip: '需要SNB货币的价格',
  32. },
  33. Synopsis: {
  34. default: '',
  35. tooltip: '简介',
  36. },
  37. //消耗的货币类型,默认是游戏币
  38. consumeType: {
  39. default: CurrencyType.GAME,
  40. type: cc.Enum(CurrencyType),
  41. tooltip: '需要消耗的货币类型',
  42. },
  43. clickEvents: {
  44. default: [],
  45. type: cc.Component.EventHandler,
  46. tooltip: CC_DEV && 'i18n:COMPONENT.button.click_events',
  47. }
  48. },
  49. onPressed() {
  50. //建筑数量为零,也不需要提示购买
  51. let NameNode = this.node.getChildByName('Name');
  52. if (NameNode) {
  53. let Num = NameNode.getChildByName('Num');
  54. if (Num) {
  55. let NumLabel = Num.getComponent(cc.Label);
  56. if (parseInt(NumLabel.string) < 1) {
  57. switch (this.consumeType) {
  58. /**
  59. * todo 目前只有特殊购买开放购买
  60. */
  61. case CurrencyType.CNT:
  62. case CurrencyType.SNB:
  63. console.warn("Content_Button 不需要购买!");
  64. // GlobalD.game._ManageUIScript.onPurchaseTips(this);
  65. break;
  66. default:
  67. console.warn("Content_Button 不需要购买!");
  68. break;
  69. }
  70. // GlobalD.game._ManageUIScript.onPurchaseTips(this);
  71. return;
  72. }
  73. }
  74. }
  75. let item = { Name: this.Name, Price: this.Price, Synopsis: this.Synopsis };
  76. switch (this.consumeType) {
  77. case CurrencyType.CNT:
  78. item.Price = this.CNT;
  79. break;
  80. case CurrencyType.SNB:
  81. item.Price = this.SNB;
  82. break;
  83. default:
  84. item.Price = this.Price;
  85. break;
  86. }
  87. GlobalD.game._ManageUIScript.onSetButtonState({ Target: this },item);
  88. },
  89. onPressedInfo(event, customEventData) {
  90. let item = { Name: this.Name, Price: this.Price, Synopsis: this.Synopsis };
  91. switch (this.consumeType) {
  92. case CurrencyType.CNT:
  93. item.Price = this.CNT;
  94. break;
  95. case CurrencyType.SNB:
  96. item.Price = this.SNB;
  97. break;
  98. default:
  99. item.Price = this.Price;
  100. break;
  101. }
  102. GlobalD.game._ManageUIScript.onSetButtonInfoState({ Target: this }, item );
  103. }
  104. });