Fix loader logo WA (#991)

This commit is contained in:
grégoire parant 2021-05-04 14:28:30 +02:00 committed by GitHub
parent 622e0c6130
commit fa3ffe4d7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 23 deletions

View File

@ -5,17 +5,18 @@ const TextName: string = 'Loading...';
const LogoResource: string = 'resources/logos/logo.png';
const LogoFrame: ImageFrameConfig = {frameWidth: 307, frameHeight: 59};
let promiseLoadLogoTexture: Promise<Phaser.GameObjects.Image>|null = null;
let loadingText: Phaser.GameObjects.Text|null = null;
let progressContainer: Phaser.GameObjects.Graphics|null = null;
let progress: Phaser.GameObjects.Graphics|null = null;
export const addLoader = (scene: Phaser.Scene): void => {
// If there is nothing to load, do not display the loader.
if (scene.load.list.entries.length === 0) {
return;
}
let loadingText: Phaser.GameObjects.Text|null = null;
const loadingBarWidth: number = Math.floor(scene.game.renderer.width / 3);
const loadingBarHeight: number = 16;
const padding: number = 5;
const promiseLoadLogoTexture = new Promise<Phaser.GameObjects.Image>((res) => {
promiseLoadLogoTexture = new Promise<Phaser.GameObjects.Image>((res) => {
if(scene.load.textureManager.exists(LogoNameIndex)){
return res(scene.add.image(scene.game.renderer.width / 2, scene.game.renderer.height / 2 - 150, LogoNameIndex));
}else{
@ -31,24 +32,36 @@ export const addLoader = (scene: Phaser.Scene): void => {
});
});
const progressContainer = scene.add.graphics();
const progress = scene.add.graphics();
progressContainer = scene.add.graphics();
progress = scene.add.graphics();
progressContainer.fillStyle(0x444444, 0.8);
progressContainer.fillRect((scene.game.renderer.width - loadingBarWidth) / 2 - padding, scene.game.renderer.height / 2 + 50 - padding, loadingBarWidth + padding * 2, loadingBarHeight + padding * 2);
scene.load.on('progress', (value: number) => {
progress.clear();
progress.fillStyle(0xBBBBBB, 1);
progress.fillRect((scene.game.renderer.width - loadingBarWidth) / 2, scene.game.renderer.height / 2 + 50, loadingBarWidth * value, loadingBarHeight);
if(progress){
progress.clear();
progress.fillStyle(0xBBBBBB, 1);
progress.fillRect((scene.game.renderer.width - loadingBarWidth) / 2, scene.game.renderer.height / 2 + 50, loadingBarWidth * value, loadingBarHeight);
}
});
scene.load.on('complete', () => {
if(loadingText){
loadingText.destroy();
}
endLoader(scene);
});
}
export const endLoader = (scene: Phaser.Scene): void => {
if(loadingText){
loadingText.destroy();
}
if(promiseLoadLogoTexture){
promiseLoadLogoTexture.then((resLoadingImage: Phaser.GameObjects.Image) => {
resLoadingImage.destroy();
});
}
if(progress){
progress.destroy();
}
if(progressContainer){
progressContainer.destroy();
});
}
}

View File

@ -71,7 +71,7 @@ import {ChatModeIcon} from "../Components/ChatModeIcon";
import {OpenChatIcon, openChatIconName} from "../Components/OpenChatIcon";
import {SelectCharacterScene, SelectCharacterSceneName} from "../Login/SelectCharacterScene";
import {TextureError} from "../../Exception/TextureError";
import {addLoader} from "../Components/Loader";
import {addLoader, endLoader} from "../Components/Loader";
import {ErrorSceneName} from "../Reconnecting/ErrorScene";
import {localUserStore} from "../../Connexion/LocalUserStore";
import {iframeListener} from "../../Api/IframeListener";
@ -497,6 +497,8 @@ export class GameScene extends ResizableScene implements CenterListener {
if (!this.room.isDisconnected()) {
this.connect();
}
endLoader(this);
}
/**

View File

@ -5,7 +5,7 @@ import Sprite = Phaser.GameObjects.Sprite;
import Container = Phaser.GameObjects.Container;
import {gameManager} from "../Game/GameManager";
import {localUserStore} from "../../Connexion/LocalUserStore";
import {addLoader} from "../Components/Loader";
import {addLoader, endLoader} from "../Components/Loader";
import {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures";
import {AbstractCharacterScene} from "./AbstractCharacterScene";
import {areCharacterLayersValid} from "../../Connexion/LocalUser";
@ -112,6 +112,8 @@ export class CustomizeScene extends AbstractCharacterScene {
this.moveLayers();
this.updateSelectedLayer();
}
endLoader(this);
}
private moveCursorHorizontally(index: number): void {

View File

@ -6,7 +6,6 @@ import {EnableCameraSceneName} from "./EnableCameraScene";
import {CustomizeSceneName} from "./CustomizeScene";
import {localUserStore} from "../../Connexion/LocalUserStore";
import {loadAllDefaultModels} from "../Entity/PlayerTexturesLoadingManager";
import {addLoader} from "../Components/Loader";
import {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures";
import {AbstractCharacterScene} from "./AbstractCharacterScene";
import {areCharacterLayersValid} from "../../Connexion/LocalUser";

View File

@ -5,7 +5,7 @@ import {EnableCameraSceneName} from "./EnableCameraScene";
import {CustomizeSceneName} from "./CustomizeScene";
import {localUserStore} from "../../Connexion/LocalUserStore";
import {loadAllDefaultModels} from "../Entity/PlayerTexturesLoadingManager";
import {addLoader} from "../Components/Loader";
import {addLoader, endLoader} from "../Components/Loader";
import {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures";
import {AbstractCharacterScene} from "./AbstractCharacterScene";
import {areCharacterLayersValid} from "../../Connexion/LocalUser";
@ -47,7 +47,6 @@ export class SelectCharacterScene extends AbstractCharacterScene {
});
})
this.playerModels = loadAllDefaultModels(this.load);
addLoader(this);
}
create() {
@ -98,6 +97,7 @@ export class SelectCharacterScene extends AbstractCharacterScene {
this.input.keyboard.on('keydown-DOWN', () => {
this.moveToDown();
});
endLoader(this);
}
protected nextSceneToCameraScene(): void {

View File

@ -1,6 +1,6 @@
import Image = Phaser.GameObjects.Image;
import Rectangle = Phaser.GameObjects.Rectangle;
import { addLoader } from "../Components/Loader";
import { addLoader, endLoader } from "../Components/Loader";
import { gameManager} from "../Game/GameManager";
import { ResizableScene } from "./ResizableScene";
import { EnableCameraSceneName } from "./EnableCameraScene";
@ -38,8 +38,6 @@ export class SelectCompanionScene extends ResizableScene {
getAllCompanionResources(this.load).forEach(model => {
this.companionModels.push(model);
});
addLoader(this);
}
create() {
@ -85,6 +83,8 @@ export class SelectCompanionScene extends ResizableScene {
this.createCurrentCompanion();
this.updateSelectedCompanion();
endLoader(this);
}
update(time: number, delta: number): void {