UIWaiting.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { GameUILayers, gui, ui_base } from "../../core/ui/ui";
  2. import { ModuleDef } from "../../scripts/ModuleDef";
  3. import { Layout_UIWaiting } from "./Layout_UIWaiting";
  4. const loadingTxtArr = ['.', '..', '...'];
  5. let _inst: UIWaiting = null;
  6. export class UIWaiting extends ui_base {
  7. private _contentStr: string = 'Loading';
  8. constructor(){
  9. super(ModuleDef.BASIC,'ui_waiting/UI_Waiting',GameUILayers.LOADING,Layout_UIWaiting);
  10. }
  11. protected onCreated(): void {
  12. }
  13. public static show(contentStr?: string): UIWaiting {
  14. if (!_inst) {
  15. gui.show(UIWaiting).then((ui)=>{
  16. _inst=ui;
  17. });
  18. }
  19. _inst._contentStr = contentStr || 'Loading';
  20. return _inst;
  21. }
  22. public static hide(): void {
  23. if (_inst) {
  24. _inst.close();
  25. _inst = null;
  26. }
  27. }
  28. protected onUpdate() {
  29. let layout = this.layout as Layout_UIWaiting;
  30. if (layout.loadingIcon) {
  31. let euler = layout.loadingIcon.eulerAngles;
  32. let rot = (Date.now() / 1000) * 90;
  33. layout.loadingIcon.setRotationFromEuler(euler.x, euler.y, rot);
  34. }
  35. if (layout.loadingTxt) {
  36. let idx = Math.floor(Date.now() / 500) % 3;
  37. layout.loadingTxt.string = this._contentStr + loadingTxtArr[idx];
  38. }
  39. }
  40. onDispose() {
  41. _inst = null;
  42. }
  43. }