import { _decorator, Node, tween, Tween } from 'cc'; import { Framework } from '../../../framework/Framework'; import { BaseView } from '../../../framework/layer/BaseView'; import { GameEvent } from '../../data/GameEvent'; import { LoadQueue } from '../../../framework/res/LoadQueue'; import { ViewID } from '../../../framework/config/LayerConf'; import { LoginMgr } from '../../common/LoginManager'; const { ccclass, property } = _decorator; @ccclass('LoadingUI') export class LoadingUI extends BaseView { protected onLoad() { super.onLoad(); } protected onDestroy() { Framework.event.removeEvent(this); } //UI开打时会调用,如果有初始化代码应该放到此函数 onOpen(data) { LoadQueue.loadPreload((now: number, total: number) => { // 设置进度条 let progress: number = now / total Tween.stopAllByTarget(this.Sprite.Bar); tween(this.Sprite.Bar) .to(0.5, { fillRange: progress }) .call(() => { Framework.layer.open(ViewID.SelectServer, null, false, data) }) .start() // 设置进度条文字 let percentage = Math.floor(progress * 100) if (percentage > 100) { percentage = 100; } this.Label.progress.string = percentage + '%'; }, () => { // Framework.layer.open(ViewID.MainUI, () => { // Framework.layer.close(this) // }); }) } //UI关闭时会调用,该函数在onDestroy前调用 onClose() { } //框架管理UI层级时会调用,可根据UI情况修改 onShow() { super.onShow(); } //框架管理UI层级时会调用,可根据UI情况修改 onHide() { super.onHide(); } //UI事件处理 private onTouchButton(event: Event) { //Framework.audio.playEffect(AudioID.Click); let target: any = event.target; } private _updateBar(progress: number) { // progress = Math.floor(progress); // this.ProgressBar.loading.progress += progress; // if (this.ProgressBar.loading.progress >= 100) { // this.ProgressBar.loading.progress = 100; // } // this.Label.progress.string = this.ProgressBar.loading.progress + "%"; } protected update(dt: number) { // if (this.ProgressBar.loading.progress < 100) { // this._updateBar(dt * 100); // } } }