TipView.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. confirmButton: {
  14. default: null,
  15. type: cc.Button,
  16. serializable: true,
  17. },
  18. cancelButton: {
  19. default: null,
  20. type: cc.Button,
  21. serializable: true,
  22. },
  23. closeButton: {
  24. default: null,
  25. type: cc.Button,
  26. serializable: true,
  27. },
  28. showNum: cc.Label,
  29. },
  30. // LIFE-CYCLE CALLBACKS:
  31. onLoad() {
  32. let clickEventHandler_Sound = new cc.Component.EventHandler();
  33. clickEventHandler_Sound.target = cc.find('GameNode/ManageSound'); //这个 node 节点是你的事件处理代码组件所属的节点,这里就是Button1
  34. clickEventHandler_Sound.component = "PlaySound";//这个是脚本文件名
  35. clickEventHandler_Sound.handler = "PlayPressBtn"; //回调函名称
  36. //确定按钮
  37. let clickEventHandler1 = new cc.Component.EventHandler();
  38. clickEventHandler1.target = this.node; //这个 node 节点是你的事件处理代码组件所属的节点,这里就是Button1
  39. clickEventHandler1.component = "TipView";//这个是脚本文件名
  40. clickEventHandler1.handler = "btnConfirmClick"; //回调函名称
  41. // clickEventHandler1.customEventData = "click1 user data"; //用户数据
  42. //this._confirmButton = this.node.getChildByName('Container').getChildByName('ConfirmButton').getComponent(cc.Button); //获取cc.Button组件
  43. this.confirmButton.clickEvents.push(clickEventHandler1); //增加处理
  44. this.confirmButton.clickEvents.push(clickEventHandler_Sound); //添加声音
  45. //取消按钮
  46. let clickEventHandler2 = new cc.Component.EventHandler();
  47. clickEventHandler2.target = this.node; //这个 node 节点是你的事件处理代码组件所属的节点,这里就是Button2
  48. clickEventHandler2.component = "TipView";//这个是脚本文件名
  49. clickEventHandler2.handler = "btnCancelClick"; //回调函名称
  50. // clickEventHandler2.customEventData = "click2 user data"; //用户数据
  51. //this._cancelButton = this.node.getChildByName('Container').getChildByName('CancelButton').getComponent(cc.Button); //获取cc.Button组件
  52. this.cancelButton.clickEvents.push(clickEventHandler2); //增加处理
  53. this.cancelButton.clickEvents.push(clickEventHandler_Sound); //添加声音
  54. //关闭按钮
  55. let clickEventHandler3 = new cc.Component.EventHandler();
  56. clickEventHandler3.target = this.node; //这个 node 节点是你的事件处理代码组件所属的节点,这里就是Button2
  57. clickEventHandler3.component = "TipView";//这个是脚本文件名
  58. clickEventHandler3.handler = "btnCancelClick"; //回调函名称
  59. this.closeButton.clickEvents.push(clickEventHandler3); //增加处理
  60. this.closeButton.clickEvents.push(clickEventHandler_Sound); //添加声音
  61. },
  62. start() {
  63. if (GlobalD.GameData.GetGolden() < this.Data.ContentButton.DiamondPrice) {
  64. //禁用按钮
  65. this.confirmButton.enableAutoGrayEffect = true;
  66. this.confirmButton.interactable = false;
  67. return;
  68. }
  69. //设置按钮
  70. this.confirmButton.enableAutoGrayEffect = false;
  71. this.confirmButton.interactable = true;
  72. },
  73. onShowTip(data) {
  74. // cc.log('传送过来的对象:', data.ContentButton);
  75. this.Data = data;
  76. if (GlobalD.GameData.GetGolden() < this.Data.ContentButton.DiamondPrice) {
  77. this.showNum.string = this.Data.ContentButton.DiamondPrice ;
  78. //禁用按钮
  79. if (this.confirmButton) {
  80. this.confirmButton.enableAutoGrayEffect = true;
  81. this.confirmButton.interactable = false;
  82. }
  83. return;
  84. }
  85. //设置按钮
  86. if (this.confirmButton) {
  87. this.confirmButton.enableAutoGrayEffect = false;
  88. this.confirmButton.interactable = true;
  89. }
  90. this.showNum.string = this.Data.ContentButton.DiamondPrice;
  91. },
  92. //确定
  93. btnConfirmClick: function (event, customEventData) {
  94. // this.Data.TipViewNode.active = false;
  95. //扣去钻石
  96. // GlobalD.GameData.PlusDiamond(-this.Data.ContentButton.DiamondPrice);
  97. GlobalD.GameData.PlusGolden(-this.Data.ContentButton.DiamondPrice);
  98. //后面需要判断是否扣去钻石成功,才能进行添加。 todo...
  99. //购买后添加
  100. GlobalD.game.AddBuildingNum(this.Data.ContentButton.node.name);
  101. this.node.destroy();
  102. },
  103. //取消
  104. btnCancelClick: function (event, customEventData) {
  105. // this.Data.TipViewNode.active = false;
  106. this.node.destroy();
  107. },
  108. btnCloseClick: function (event, customEventData) {
  109. this.node.destroy();
  110. }
  111. });