ButtonComponent.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 { TYPE_ITEM } from '../CarColorsGlobalTypes';
  5. import { GlobalConfig } from 'db://assets/start/Config/GlobalConfig';
  6. import { AdvertMgr } from 'db://assets/core_tgx/base/ad/AdvertMgr';
  7. import { AliensAudioMgr } from '../Manager/CarUnscrewAudioMgr';
  8. const { ccclass, property } = _decorator;
  9. /**
  10. * 底部按钮控制器
  11. */
  12. @ccclass('ButtonComponent')
  13. export class ButtonComponent extends Component {
  14. @property(Button) btRefresh: Button = null!;
  15. @property(Button) btMagnet: Button = null!;
  16. protected start(): void {
  17. this.addUIEvent()
  18. }
  19. private addUIEvent(): void {
  20. this.btRefresh.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.REFRESH), this);
  21. this.btMagnet.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.MAGNET), this);
  22. }
  23. private onClickHandler(type: TYPE_ITEM): void {
  24. // AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(3), 1.0);
  25. if (type == TYPE_ITEM.REFRESH) {
  26. if (!GlobalConfig.isDebug) {
  27. AdvertMgr.instance.showReawardVideo(() => {
  28. // EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_COLOR);
  29. })
  30. } else {
  31. // EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_COLOR);
  32. }
  33. } else if (type == TYPE_ITEM.MAGNET) {
  34. if (!GlobalConfig.isDebug) {
  35. AdvertMgr.instance.showReawardVideo(() => {
  36. // EventDispatcher.instance.emit(GameEvent.EVENT_MAGNET);
  37. })
  38. } else {
  39. // EventDispatcher.instance.emit(GameEvent.EVENT_MAGNET);
  40. }
  41. }
  42. }
  43. }