ButtonComponent.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Button, Component, Label, Node, NodeEventType, _decorator, find } from 'cc';
  2. import { GameEvent } from '../Enum/GameEvent';
  3. import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
  4. import { GlobalConfig } from 'db://assets/start/Config/GlobalConfig';
  5. import { AdvertMgr } from 'db://assets/core_tgx/base/ad/AdvertMgr';
  6. import { TYPE_ITEM } from '../TakeGobletGlobalInstance';
  7. import { tgxUIAlert } from 'db://assets/core_tgx/tgx';
  8. import { TakeGobletAudioMgr } from '../Manager/TakeGobletAudioMgr';
  9. const { ccclass, property } = _decorator;
  10. /**
  11. * 底部按钮控制器
  12. */
  13. @ccclass('ButtonComponent')
  14. export class ButtonComponent extends Component {
  15. @property(Button) btnFillUp: Button = null!;
  16. @property(Button) btMoveOut: Button = null!;
  17. @property(Button) btRefresh: Button = null!;
  18. protected start(): void {
  19. this.addUIEvent();
  20. }
  21. private addUIEvent(): void {
  22. this.btnFillUp.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.FillUp), this);
  23. this.btMoveOut.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.MoveOut), this);
  24. this.btRefresh.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.Refresh), this);
  25. }
  26. private onClickHandler(type: TYPE_ITEM): void {
  27. TakeGobletAudioMgr.playOneShot(TakeGobletAudioMgr.getMusicIdName(2), 1.0);
  28. let alerType = '';
  29. switch (type) {
  30. case TYPE_ITEM.FillUp:
  31. alerType = 'FillUp';
  32. break;
  33. case TYPE_ITEM.MoveOut:
  34. alerType = 'Remove';
  35. break;
  36. case TYPE_ITEM.Refresh:
  37. alerType = 'Refresh';
  38. break;
  39. }
  40. const options = tgxUIAlert.show("", alerType, true);
  41. options.onClick((ok: boolean) => {
  42. if (ok) {
  43. if (type == TYPE_ITEM.FillUp) {
  44. if (!GlobalConfig.isDebug) {
  45. AdvertMgr.instance.showReawardVideo(() => {
  46. EventDispatcher.instance.emit(GameEvent.EVENT_FILL_UP);
  47. })
  48. } else {
  49. EventDispatcher.instance.emit(GameEvent.EVENT_FILL_UP);
  50. }
  51. } else if (type == TYPE_ITEM.MoveOut) {
  52. if (!GlobalConfig.isDebug) {
  53. AdvertMgr.instance.showReawardVideo(() => {
  54. EventDispatcher.instance.emit(GameEvent.EVENT_MOVE_OUT);
  55. })
  56. } else {
  57. EventDispatcher.instance.emit(GameEvent.EVENT_MOVE_OUT);
  58. }
  59. } else {
  60. if (!GlobalConfig.isDebug) {
  61. AdvertMgr.instance.showReawardVideo(() => {
  62. EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_COLOR);
  63. })
  64. } else {
  65. EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_COLOR);
  66. }
  67. }
  68. }
  69. })
  70. }
  71. }