ButtomList.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { _decorator, Button, Component, Node } from 'cc';
  2. import { rootMgr } from '../../scene/RootMgr';
  3. import { Board } from '../board/Board';
  4. import { aa } from 'db://assets/scripts/aa';
  5. import { EventType } from '../../util/Enum';
  6. import { Container } from '../container/Container';
  7. import { BoardState } from '../../util/Enum';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('ButtomList')
  10. export class ButtomList extends Component {
  11. @property(Node)
  12. swapcolors: Node//交换颜色
  13. @property(Node)
  14. withdraw: Node//撤回一步
  15. @property(Node)
  16. addbottles: Node//增加空瓶
  17. start() {
  18. // this.swapcolors.on(Node.EventType.TOUCH_END, this.swapColors, this);
  19. // rootMgr.game.evt.on('openbottlesBtn', this.withdrawBtnActive, this);
  20. // rootMgr.game.evt.on('openaddbottlesBtn', this.addbottlesBtnActive, this);
  21. // this.withdraw.getComponent(Button).interactable = false;
  22. // this.addbottles.getComponent(Button).interactable = false;
  23. }
  24. // withdrawBtnActive(rebtn: boolean = false) {
  25. // // 只有当不在打乱状态时才允许设置按钮状态
  26. // const board = rootMgr.gameCompent.getCompent(Board);
  27. // if (board && board.state !== BoardState.SHUFFLING) {
  28. // const withdrawButton = this.withdraw.getComponent(Button);
  29. // if (withdrawButton) {
  30. // withdrawButton.interactable = rebtn;
  31. // }
  32. // if (rebtn) {
  33. // this.withdraw.on(Node.EventType.TOUCH_END, this.withDraw, this);
  34. // }
  35. // }
  36. // }
  37. // addbottlesBtnActive(rebtn: boolean = false) {
  38. // // 只有当不在打乱状态时才允许设置按钮状态
  39. // const board = rootMgr.gameCompent.getCompent(Board);
  40. // if (board && board.state !== BoardState.SHUFFLING) {
  41. // const addbottlesButton = this.addbottles.getComponent(Button);
  42. // if (addbottlesButton) {
  43. // addbottlesButton.interactable = rebtn;
  44. // }
  45. // if (rebtn) {
  46. // this.addbottles.on(Node.EventType.TOUCH_END, this.addBottles, this);
  47. // }
  48. // }
  49. // }
  50. // swapColors() {
  51. // //aa.eventDispatch.emit(EventType.puase);
  52. // aa.sdk.playRewardAd("打乱水的排序").then((ok) => {
  53. // if (ok) {
  54. // rootMgr.game.evt.emit('swapcolors');
  55. // // 禁用撤回和增加瓶子按钮
  56. // this.setButtonInteractable(this.withdraw, false);
  57. // this.setButtonInteractable(this.addbottles, false);
  58. // }
  59. // aa.eventDispatch.emit(EventType.resume);
  60. // const board = rootMgr.gameCompent.getCompent(Board);
  61. // if (board) {
  62. // board.clearSelect(); // 重置选中状态
  63. // }
  64. // });
  65. // }
  66. // withDraw() {
  67. // // 检查按钮是否可用,不可用时直接返回
  68. // const withdrawButton = this.withdraw.getComponent(Button);
  69. // if (!withdrawButton || !withdrawButton.interactable) {
  70. // return;
  71. // }
  72. // // aa.eventDispatch.emit(EventType.puase);
  73. // aa.sdk.playRewardAd("撤回一步").then((ok) => {
  74. // if (ok) {
  75. // rootMgr.game.evt.emit('withdraw');
  76. // }
  77. // aa.eventDispatch.emit(EventType.resume);
  78. // const board = rootMgr.gameCompent.getCompent(Board);
  79. // if (board) {
  80. // board.clearSelect(); // 重置选中状态
  81. // }
  82. // });
  83. // if (withdrawButton) {
  84. // withdrawButton.interactable = false;
  85. // }
  86. // }
  87. // addBottles() {
  88. // // 检查按钮是否可用,不可用时直接返回
  89. // const addbottlesButton = this.addbottles.getComponent(Button);
  90. // if (!addbottlesButton || !addbottlesButton.interactable) {
  91. // return;
  92. // }
  93. // if (Container.clearFinishedPositions.length <= 0) {
  94. // if (addbottlesButton) {
  95. // addbottlesButton.interactable = false;
  96. // }
  97. // return;
  98. // }
  99. // //aa.eventDispatch.emit(EventType.puase);
  100. // aa.sdk.playRewardAd("增加一个空瓶子").then((ok) => {
  101. // if (ok) {
  102. // rootMgr.game.evt.emit('addbottles');
  103. // }
  104. // aa.eventDispatch.emit(EventType.resume);
  105. // const board = rootMgr.gameCompent.getCompent(Board);
  106. // if (board) {
  107. // board.clearSelect(); // 重置选中状态
  108. // }
  109. // });
  110. // }
  111. // // 设置按钮交互状态的辅助方法
  112. // private setButtonInteractable(buttonNode: Node, interactable: boolean) {
  113. // const button = buttonNode.getComponent(Button);
  114. // if (button) {
  115. // button.interactable = interactable;
  116. // }
  117. // }
  118. // protected onDestroy(): void {
  119. // rootMgr.game.evt.off('openbottlesBtn', this.withdrawBtnActive, this);
  120. // rootMgr.game.evt.off('openaddbottlesBtn', this.addbottlesBtnActive, this);
  121. // }
  122. }