Content_Button.js 4.5 KB

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