RoosterTakeGoblet.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { _decorator, Component, ERaycast2DType, find, Label, Node, NodeEventType, PhysicsSystem2D, Tween, tween, v2, v3, Vec2, Vec3 } from 'cc';
  2. import { EventDispatcher } from '../core_tgx/easy_ui_framework/EventDispatcher';
  3. import { TakeGobletGlobalInstance } from './Script/TakeGobletGlobalInstance';
  4. import { GameEvent } from './Script/Enum/GameEvent';
  5. import { LevelManager } from './Script/Manager/LevelMgr';
  6. import { GameUtil } from './Script/GameUtil';
  7. import { tgxUIMgr } from '../core_tgx/tgx';
  8. import { UI_Setting } from '../scripts/UIDef';
  9. import { TakeGobletAudioMgr } from './Script/Manager/TakeGobletAudioMgr';
  10. const { ccclass, property } = _decorator;
  11. const duration = 0.3;
  12. @ccclass('RoosterTakeGoblet')
  13. export class RoosterTakeGoblet extends Component {
  14. onLoad() {
  15. TakeGobletAudioMgr.initilize();
  16. // TakeGobletAudioMgr.play(TakeGobletAudioMgr.getMusicIdName(2), 1.0);
  17. LevelManager.instance.initilizeModel();
  18. TakeGobletGlobalInstance.instance.levels = find('Canvas/Scene/Levels')!;
  19. this.registerListener();
  20. }
  21. protected start(): void {
  22. this.startGame();
  23. }
  24. async startGame() {
  25. await LevelManager.instance.gameStart();
  26. }
  27. registerListener() {
  28. EventDispatcher.instance.on(GameEvent.EVENT_BATTLE_SUCCESS_LEVEL_UP, this.onUpdateLvl, this);
  29. const btnRefresh = find('Canvas/GameUI/TopLeft/BtnRefresh')!;
  30. const btnSet = find('Canvas/GameUI/TopLeft/BtnSet')!;
  31. btnRefresh.on(NodeEventType.TOUCH_END, () => this.onClickRefresh(), this);
  32. btnSet.on(NodeEventType.TOUCH_END, () => this.onClickSet(), this);
  33. }
  34. private async onClickRefresh(): Promise<void> {
  35. TakeGobletAudioMgr.playOneShot(TakeGobletAudioMgr.getMusicIdName(2), 1.0);
  36. Tween.stopAll();
  37. EventDispatcher.instance.emit(GameEvent.EVENT_BATTLE_FAIL_LEVEL_RESET);
  38. }
  39. private onClickSet(): void {
  40. TakeGobletAudioMgr.playOneShot(TakeGobletAudioMgr.getMusicIdName(2), 1.0);
  41. const show = tgxUIMgr.inst.isShowing(UI_Setting);
  42. if (!show) {
  43. tgxUIMgr.inst.showUI(UI_Setting);
  44. }
  45. }
  46. onUpdateLvl() {
  47. const lbScrews = find('Canvas/GameUI/TitleLvl/LbLvl')!.getComponent(Label);
  48. const { level } = LevelManager.instance.levelModel;
  49. lbScrews.string = `Level:${level}`;
  50. }
  51. }