ChooseMode.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { _decorator, Component, isValid, Node, Vec3 } from "cc";
  2. import { ModuleDef } from "../../scripts/ModuleDef";
  3. import { GameUILayers } from "../../scripts/GameUILayers";
  4. import BaseUI from "../base/BaseUI";
  5. import { SceneUtil } from "../../core_tgx/base/SceneUtils";
  6. import { SceneDef } from "../../scripts/SceneDef";
  7. import { BallUISoloMatch } from "./BallUISoloMatch";
  8. import UIUtils from "../base/UIUtils";
  9. import { Lobby } from "./Lobby";
  10. const { ccclass, property } = _decorator;
  11. @ccclass("ChooseMode")
  12. export class ChooseMode extends BaseUI {
  13. static show() {
  14. tgx.UIMgr.inst.show(
  15. ModuleDef.BALL,
  16. "ui_lobby/ui_choose_mode",
  17. GameUILayers.POPUP
  18. );
  19. }
  20. protected onDestroy(): void {
  21. Lobby.ins.enter();
  22. }
  23. private _isLoading: boolean = false;
  24. protected closePage(): void {
  25. super.closePage();
  26. this._isLoading = false;
  27. }
  28. protected onLoad(): void {
  29. super.onLoad();
  30. let index = 0;
  31. let self = this;
  32. this.FindNode("content").children.forEach((child) => {
  33. self.playAnimation(child, index);
  34. index++;
  35. });
  36. }
  37. playAnimation(child: Node, index: number) {
  38. child.active = false;
  39. let moveY = 0;
  40. let moveX =0;
  41. child.setPosition(
  42. child.position.x + moveX,
  43. child.position.y + moveY,
  44. child.position.z
  45. );
  46. child.setScale(0.8, 0.8, 0.8);
  47. setTimeout(() => {
  48. if (!isValid(child)) {
  49. return;
  50. }
  51. child.active = true;
  52. UIUtils.AnimBezierMoveAndScale(
  53. child,
  54. new Vec3(
  55. child.position.x - moveX,
  56. child.position.y - moveY,
  57. child.position.z
  58. ),
  59. 1,
  60. 0.3,
  61. () => {}
  62. );
  63. }, index * 80);
  64. }
  65. protected simpleOnBtnClick(name: string): void {
  66. if (this._isLoading) {
  67. return;
  68. }
  69. this._isLoading = true;
  70. switch (name) {
  71. case "btn_close":
  72. this.closePage();
  73. break;
  74. case "btn_1":
  75. tgx.UIWaiting.show();
  76. SceneUtil.loadScene(SceneDef.GAME_LOCAL);
  77. setTimeout(() => {
  78. this.closePage();
  79. tgx.UIWaiting.hide();
  80. }, 2000);
  81. break;
  82. case "btn_2":
  83. tgx.UIMgr.inst.closeAll();
  84. BallUISoloMatch.show();
  85. this._isLoading = false;
  86. break;
  87. }
  88. }
  89. }