ButtonComponent.ts 3.0 KB

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