LoadingUI.ts 2.1 KB

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