ButtonComponent.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. const { ccclass, property } = _decorator;
  8. /**
  9. * 底部按钮控制器
  10. */
  11. @ccclass('ButtonComponent')
  12. export class ButtonComponent extends Component {
  13. @property(Button) btnFillUp: Button = null!;
  14. @property(Button) btMoveOut: Button = null!;
  15. @property(Button) btRefresh: Button = null!;
  16. protected start(): void {
  17. this.addUIEvent();
  18. }
  19. private addUIEvent(): void {
  20. this.btnFillUp.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.FillUp), this);
  21. this.btMoveOut.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.MoveOut), this);
  22. this.btRefresh.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.Refresh), this);
  23. }
  24. private onClickHandler(type: TYPE_ITEM): void {
  25. // CarUnscrewAudioMgr.playOneShot(CarUnscrewAudioMgr.getMusicIdName(3), 1.0);
  26. if (type == TYPE_ITEM.FillUp) {
  27. if (!GlobalConfig.isDebug) {
  28. AdvertMgr.instance.showReawardVideo(() => {
  29. EventDispatcher.instance.emit(GameEvent.EVENT_FILL_UP);
  30. })
  31. } else {
  32. EventDispatcher.instance.emit(GameEvent.EVENT_FILL_UP);
  33. }
  34. } else if (type == TYPE_ITEM.MoveOut) {
  35. if (!GlobalConfig.isDebug) {
  36. AdvertMgr.instance.showReawardVideo(() => {
  37. EventDispatcher.instance.emit(GameEvent.EVENT_MOVE_OUT);
  38. })
  39. } else {
  40. EventDispatcher.instance.emit(GameEvent.EVENT_MOVE_OUT);
  41. }
  42. } else {
  43. if (!GlobalConfig.isDebug) {
  44. AdvertMgr.instance.showReawardVideo(() => {
  45. EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_COLOR);
  46. })
  47. } else {
  48. EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_COLOR);
  49. }
  50. }
  51. }
  52. }