LoadingUI.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { _decorator, Node, tween, Tween } from 'cc';
  2. import { Framework } from '../../../framework/Framework';
  3. import { BaseView } from '../../../framework/layer/BaseView';
  4. import { GameEvent } from '../../data/GameEvent';
  5. import { LoadQueue } from '../../../framework/res/LoadQueue';
  6. import { ViewID } from '../../../framework/config/LayerConf';
  7. import { LoginMgr } from '../../common/LoginManager';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('LoadingUI')
  10. export class LoadingUI extends BaseView {
  11. protected onLoad() {
  12. super.onLoad();
  13. }
  14. protected onDestroy() {
  15. Framework.event.removeEvent(this);
  16. }
  17. //UI开打时会调用,如果有初始化代码应该放到此函数
  18. onOpen(data) {
  19. LoadQueue.loadPreload((now: number, total: number) => {
  20. // 设置进度条
  21. let progress: number = now / total
  22. Tween.stopAllByTarget(this.Sprite.Bar);
  23. tween(this.Sprite.Bar)
  24. .to(0.5, { fillRange: progress })
  25. .call(() => {
  26. Framework.layer.open(ViewID.SelectServer, null, false, data)
  27. })
  28. .start()
  29. // 设置进度条文字
  30. let percentage = Math.floor(progress * 100)
  31. if (percentage > 100) {
  32. percentage = 100;
  33. }
  34. this.Label.progress.string = percentage + '%';
  35. }, () => {
  36. // Framework.layer.open(ViewID.MainUI, () => {
  37. // Framework.layer.close(this)
  38. // });
  39. })
  40. }
  41. //UI关闭时会调用,该函数在onDestroy前调用
  42. onClose() {
  43. }
  44. //框架管理UI层级时会调用,可根据UI情况修改
  45. onShow() {
  46. super.onShow();
  47. }
  48. //框架管理UI层级时会调用,可根据UI情况修改
  49. onHide() {
  50. super.onHide();
  51. }
  52. //UI事件处理
  53. private onTouchButton(event: Event) {
  54. //Framework.audio.playEffect(AudioID.Click);
  55. let target: any = event.target;
  56. }
  57. private _updateBar(progress: number) {
  58. // progress = Math.floor(progress);
  59. // this.ProgressBar.loading.progress += progress;
  60. // if (this.ProgressBar.loading.progress >= 100) {
  61. // this.ProgressBar.loading.progress = 100;
  62. // }
  63. // this.Label.progress.string = this.ProgressBar.loading.progress + "%";
  64. }
  65. protected update(dt: number) {
  66. // if (this.ProgressBar.loading.progress < 100) {
  67. // this._updateBar(dt * 100);
  68. // }
  69. }
  70. }