Content_Button.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. bgSprite:{
  44. default:null,
  45. type:cc.Sprite,
  46. },
  47. NumLabel:{
  48. default:null,
  49. type:cc.Label,
  50. },
  51. NameLabel:{
  52. default:null,
  53. type:cc.Label,
  54. },
  55. clickEvents: {
  56. default: [],
  57. type: cc.Component.EventHandler,
  58. tooltip: CC_DEV && 'i18n:COMPONENT.button.click_events',
  59. }
  60. },
  61. onPressed() {
  62. //建筑数量为零,也不需要提示购买
  63. let NameNode = this.node.getChildByName('Name');
  64. if (NameNode) {
  65. let Num = NameNode.getChildByName('Num');
  66. if (Num) {
  67. let NumLabel = Num.getComponent(cc.Label);
  68. if (parseInt(NumLabel.string) < 1) {
  69. switch (this.consumeType) {
  70. /**
  71. * todo 目前只有特殊购买开放购买
  72. */
  73. case CurrencyType.CNT:
  74. case CurrencyType.SNB:
  75. console.warn("Content_Button 不需要购买!");
  76. // GlobalD.game._ManageUIScript.onPurchaseTips(this);
  77. break;
  78. default:
  79. console.warn("Content_Button 不需要购买!");
  80. break;
  81. }
  82. // GlobalD.game._ManageUIScript.onPurchaseTips(this);
  83. return;
  84. }
  85. }
  86. }
  87. let item = { Name: this.Name, Price: this.Price, Synopsis: this.Synopsis };
  88. switch (this.consumeType) {
  89. case CurrencyType.CNT:
  90. item.Price = this.CNT;
  91. break;
  92. case CurrencyType.SNB:
  93. item.Price = this.SNB;
  94. break;
  95. default:
  96. item.Price = this.Price;
  97. break;
  98. }
  99. GlobalD.game._ManageUIScript.onSetButtonState({ Target: this },item);
  100. },
  101. onPressedInfo(event, customEventData) {
  102. let item = { Name: this.Name, Price: this.Price, Synopsis: this.Synopsis };
  103. switch (this.consumeType) {
  104. case CurrencyType.CNT:
  105. item.Price = this.CNT;
  106. break;
  107. case CurrencyType.SNB:
  108. item.Price = this.SNB;
  109. break;
  110. default:
  111. item.Price = this.Price;
  112. break;
  113. }
  114. GlobalD.game._ManageUIScript.onSetButtonInfoState({ Target: this }, item );
  115. }
  116. });