RoosterTakeGoblet.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 { LevelAction } from './Script/LevelAction';
  8. import { GlobalConfig } from '../start/Config/GlobalConfig';
  9. import { AdvertMgr } from '../core_tgx/base/ad/AdvertMgr';
  10. import { tgxUIMgr } from '../core_tgx/tgx';
  11. import { UI_Setting } from '../scripts/UIDef';
  12. import { TakeGobletAudioMgr } from './Script/Manager/TakeGobletAudioMgr';
  13. const { ccclass, property } = _decorator;
  14. const duration = 0.3;
  15. @ccclass('RoosterTakeGoblet')
  16. export class RoosterTakeGoblet extends Component {
  17. onLoad() {
  18. TakeGobletAudioMgr.initilize();
  19. TakeGobletAudioMgr.play(TakeGobletAudioMgr.getMusicIdName(2), 1.0);
  20. LevelManager.instance.initilizeModel();
  21. TakeGobletGlobalInstance.instance.levels = find('Canvas/Scene/Levels')!;
  22. this.registerListener();
  23. }
  24. protected start(): void {
  25. this.startGame();
  26. }
  27. async startGame() {
  28. await LevelManager.instance.gameStart();
  29. }
  30. registerListener() {
  31. EventDispatcher.instance.on(GameEvent.EVENT_BATTLE_SUCCESS_LEVEL_UP, this.onUpdateLvl, this);
  32. const btnRefresh = find('Canvas/GameUI/TopLeft/BtnRefresh')!;
  33. const btnSet = find('Canvas/GameUI/TopLeft/BtnSet')!;
  34. btnRefresh.on(NodeEventType.TOUCH_END, () => this.onClickRefresh(), this);
  35. btnSet.on(NodeEventType.TOUCH_END, () => this.onClickSet(), this);
  36. }
  37. private async onClickRefresh(): Promise<void> {
  38. TakeGobletAudioMgr.playOneShot(TakeGobletAudioMgr.getMusicIdName(3), 1.0);
  39. Tween.stopAll();
  40. LevelManager.instance.clearLevelData();
  41. const { level } = LevelManager.instance.levelModel;
  42. LevelManager.instance.loadLevel(level);
  43. await GameUtil.delay(0.2);
  44. }
  45. private onClickSet(): void {
  46. TakeGobletAudioMgr.playOneShot(TakeGobletAudioMgr.getMusicIdName(3), 1.0);
  47. const show = tgxUIMgr.inst.isShowing(UI_Setting);
  48. if (!show) {
  49. tgxUIMgr.inst.showUI(UI_Setting);
  50. }
  51. }
  52. onUpdateLvl() {
  53. const lbScrews = find('Canvas/GameUI/TitleLvl/LbLvl')!.getComponent(Label);
  54. const { level } = LevelManager.instance.levelModel;
  55. lbScrews.string = `${level}`;
  56. }
  57. }