RoosterTakeGoblet.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. import { LevelAction } from './Script/LevelAction';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('RoosterTakeGoblet')
  13. export class RoosterTakeGoblet extends Component {
  14. onLoad() {
  15. TakeGobletAudioMgr.initilize();
  16. TakeGobletAudioMgr.play(TakeGobletAudioMgr.getMusicIdName(1), 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. this.refreshCupCount();
  27. }
  28. registerListener() {
  29. EventDispatcher.instance.on(GameEvent.EVENT_REFRESH_REMAIN_CUP, this.refreshCupCount, this);
  30. EventDispatcher.instance.on(GameEvent.EVENT_BATTLE_SUCCESS_LEVEL_UP, this.onUpdateLvl, this);
  31. const btnRefresh = find('Canvas/GameUI/TopLeft/BtnRefresh')!;
  32. const btnSet = find('Canvas/GameUI/TopLeft/BtnSet')!;
  33. btnRefresh.on(NodeEventType.TOUCH_END, () => this.onClickRefresh(), this);
  34. btnSet.on(NodeEventType.TOUCH_END, () => this.onClickSet(), this);
  35. }
  36. private async onClickRefresh(): Promise<void> {
  37. TakeGobletAudioMgr.playOneShot(TakeGobletAudioMgr.getMusicIdName(2), 1.0);
  38. Tween.stopAll();
  39. EventDispatcher.instance.emit(GameEvent.EVENT_BATTLE_FAIL_LEVEL_RESET);
  40. }
  41. private onClickSet(): void {
  42. TakeGobletAudioMgr.playOneShot(TakeGobletAudioMgr.getMusicIdName(2), 1.0);
  43. const show = tgxUIMgr.inst.isShowing(UI_Setting);
  44. if (!show) {
  45. tgxUIMgr.inst.showUI(UI_Setting);
  46. }
  47. }
  48. onUpdateLvl() {
  49. const lbScrews = find('Canvas/GameUI/TitleLvl/LbLvl')!.getComponent(Label);
  50. const { level } = LevelManager.instance.levelModel;
  51. lbScrews.string = `Level:${level}`;
  52. }
  53. //刷新剩余杯子的数量
  54. private refreshCupCount() {
  55. const lbRemain = find('Canvas/Scene/Pai/LbRemaining')!.getComponent(Label);
  56. const lvlAction = find('Canvas/Scene/Levels')!.children[0].getComponent(LevelAction);
  57. const waitLength = lvlAction.waitArea!.getCups().length;
  58. const outLength = lvlAction.outArea!.getCups().length;
  59. lbRemain.string = `${waitLength + outLength} Cup`;
  60. }
  61. }