Content_Button.js 4.2 KB

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