Save zoom level in the gameScene and restore it after the SelectCharacterScene and CustomizeScene

This commit is contained in:
GRL 2021-06-02 18:01:36 +02:00
parent ba038dc75a
commit 59d60f54fe
4 changed files with 25 additions and 15 deletions

View File

@ -29,8 +29,6 @@ export class CustomizeScene extends AbstractCharacterScene {
public activeRow:number = 0;
private layers: BodyResourceDescriptionInterface[][] = [];
private customizeSceneElement!: Phaser.GameObjects.DOMElement;
constructor() {
super({
key: CustomizeSceneName
@ -54,15 +52,16 @@ export class CustomizeScene extends AbstractCharacterScene {
addLoader(this);
}
create(data: { from: string; }) {
create() {
customCharacterSceneVisibleStore.set(true);
this.events.addListener('wake', () => { customCharacterSceneVisibleStore.set(true); });
if (data.from === 'NoScene') {
//Save the zoom level only if the previous scene didn't already save it
this.events.addListener('wake', () => {
waScaleManager.saveZoom();
}
waScaleManager.zoomModifier = isMobile() ? 2 : 1;
waScaleManager.zoomModifier = isMobile() ? 3 : 1;
customCharacterSceneVisibleStore.set(true);
});
waScaleManager.saveZoom();
waScaleManager.zoomModifier = isMobile() ? 3 : 1;
this.Rectangle = this.add.rectangle(this.cameras.main.worldView.x + this.cameras.main.width / 2, this.cameras.main.worldView.y + this.cameras.main.height / 3, 32, 33)
this.Rectangle.setStrokeStyle(2, 0xFFFFFF);
@ -246,12 +245,14 @@ export class CustomizeScene extends AbstractCharacterScene {
gameManager.setCharacterLayers(layers);
this.scene.sleep(CustomizeSceneName);
waScaleManager.restoreZoom();
this.events.removeListener('wake');
gameManager.tryResumingGame(this, EnableCameraSceneName);
customCharacterSceneVisibleStore.set(false);
}
private backToPreviousScene(){
this.scene.sleep(CustomizeSceneName);
waScaleManager.restoreZoom();
this.scene.run(SelectCharacterSceneName);
customCharacterSceneVisibleStore.set(false);
}

View File

@ -1,11 +1,9 @@
import { SelectCharacterScene } from "./SelectCharacterScene";
import {waScaleManager} from "../Services/WaScaleManager";
export class SelectCharacterMobileScene extends SelectCharacterScene {
create(){
super.create();
waScaleManager.zoomModifier = 2;
this.onResize();
this.selectedRectangle.destroy();
}

View File

@ -14,6 +14,7 @@ import {MenuScene} from "../Menu/MenuScene";
import {selectCharacterSceneVisibleStore} from "../../Stores/SelectCharacterStore";
import {customCharacterSceneVisibleStore} from "../../Stores/CustomCharacterStore";
import {waScaleManager} from "../Services/WaScaleManager";
import {isMobile} from "../../Enum/EnvironmentVariable";
//todo: put this constants in a dedicated file
export const SelectCharacterSceneName = "SelectCharacterScene";
@ -30,6 +31,7 @@ export class SelectCharacterScene extends AbstractCharacterScene {
protected selectCharacterSceneElement!: Phaser.GameObjects.DOMElement;
protected currentSelectUser = 0;
protected pointerClicked: boolean = false;
constructor() {
super({
@ -53,14 +55,18 @@ export class SelectCharacterScene extends AbstractCharacterScene {
create() {
selectCharacterSceneVisibleStore.set(true);
this.events.addListener('wake', () => {selectCharacterSceneVisibleStore.set(true);});
this.events.addListener('wake', () => {
waScaleManager.saveZoom();
waScaleManager.zoomModifier = isMobile() ? 2 : 1;
selectCharacterSceneVisibleStore.set(true);
});
if (touchScreenManager.supportTouchScreen) {
new PinchManager(this);
}
waScaleManager.saveZoom();
waScaleManager.zoomModifier = 1;
waScaleManager.zoomModifier = isMobile() ? 2 : 1;
const rectangleXStart = this.game.renderer.width / 2 - (this.nbCharactersPerRow / 2) * 32 + 16;
this.selectedRectangle = this.add.rectangle(rectangleXStart, 90, 32, 32).setStrokeStyle(2, 0xFFFFFF);
@ -100,6 +106,7 @@ export class SelectCharacterScene extends AbstractCharacterScene {
gameManager.tryResumingGame(this, EnableCameraSceneName);
this.players = [];
selectCharacterSceneVisibleStore.set(false);
this.events.removeListener('wake');
}
protected nextSceneToCustomizeScene(): void {
@ -107,7 +114,8 @@ export class SelectCharacterScene extends AbstractCharacterScene {
return;
}
this.scene.sleep(SelectCharacterSceneName);
this.scene.run(CustomizeSceneName, {from: 'SelectCharacter'});
waScaleManager.restoreZoom();
this.scene.run(CustomizeSceneName);
selectCharacterSceneVisibleStore.set(false);
}
@ -125,11 +133,13 @@ export class SelectCharacterScene extends AbstractCharacterScene {
repeat: -1
});
player.setInteractive().on("pointerdown", () => {
if(this.currentSelectUser === i){
if (this.pointerClicked || this.currentSelectUser === i) {
return;
}
this.pointerClicked = true;
this.currentSelectUser = i;
this.moveUser();
setTimeout(() => {this.pointerClicked = false;}, 100);
});
this.players.push(player);
}

View File

@ -60,6 +60,7 @@ class WaScaleManager {
public saveZoom(): void {
this._saveZoom = this.hdpiManager.zoomModifier;
console.log(this._saveZoom);
}
public restoreZoom(): void{