center grid if possible

This commit is contained in:
Piotr 'pwh' Hanusiak 2022-03-30 13:20:49 +02:00
parent d0ad5f8299
commit 42e71411b5

View File

@ -126,7 +126,7 @@ export class CustomizeScene extends AbstractCharacterScene {
this.bodyPartsDraggableGridLeftShadow = this.add this.bodyPartsDraggableGridLeftShadow = this.add
.image(0, this.cameras.main.worldView.y + this.cameras.main.height, "gridEdgeShadow") .image(0, this.cameras.main.worldView.y + this.cameras.main.height, "gridEdgeShadow")
.setAlpha(1, 0, 1, 0) .setAlpha(1, 0, 1, 0)
.setOrigin(0, 1); .setOrigin(0, 0.5);
this.bodyPartsDraggableGridRightShadow = this.add this.bodyPartsDraggableGridRightShadow = this.add
.image( .image(
@ -136,7 +136,7 @@ export class CustomizeScene extends AbstractCharacterScene {
) )
.setAlpha(1, 0, 1, 0) .setAlpha(1, 0, 1, 0)
.setFlipX(true) .setFlipX(true)
.setOrigin(1, 1); .setOrigin(1, 0.5);
this.bodyPartsSlots = { this.bodyPartsSlots = {
[CustomWokaBodyPart.Hair]: new WokaBodyPartSlot(this, 0, 0, { [CustomWokaBodyPart.Hair]: new WokaBodyPartSlot(this, 0, 0, {
@ -186,9 +186,9 @@ export class CustomizeScene extends AbstractCharacterScene {
public onResize(): void { public onResize(): void {
this.handleCustomWokaPreviewerOnResize(); this.handleCustomWokaPreviewerOnResize();
this.handleBodyPartSlotsOnResize(); this.handleBodyPartSlotsOnResize();
this.handleBodyPartsDraggableGridOnResize();
this.handleRandomizeButtonOnResize(); this.handleRandomizeButtonOnResize();
this.handleFinishButtonOnResize(); this.handleFinishButtonOnResize();
this.handleBodyPartsDraggableGridOnResize();
} }
public nextSceneToCamera() { public nextSceneToCamera() {
@ -340,15 +340,24 @@ export class CustomizeScene extends AbstractCharacterScene {
private handleBodyPartsDraggableGridOnResize(): void { private handleBodyPartsDraggableGridOnResize(): void {
const gridHeight = 110; const gridHeight = 110;
const gridWidth = innerWidth / waScaleManager.getActualZoom(); const gridWidth = innerWidth / waScaleManager.getActualZoom();
const gridTopMargin = Math.max(
this.finishButton.y + this.finishButton.displayHeight * 0.5,
this.bodyPartsSlots.Hair.y + this.bodyPartsSlots.Hair.displayHeight * 0.5
);
const gridBottomMargin = this.cameras.main.worldView.y + this.cameras.main.height;
const yPos = gridTopMargin + (gridBottomMargin - gridTopMargin) * 0.5;
const gridPos = { const gridPos = {
x: this.cameras.main.worldView.x + this.cameras.main.width / 2, x: this.cameras.main.worldView.x + this.cameras.main.width / 2,
y: this.cameras.main.worldView.y + this.cameras.main.height - gridHeight * 0.5 - 5, y: yPos,
}; };
this.bodyPartsDraggableGridLeftShadow.setPosition(0, this.cameras.main.worldView.y + this.cameras.main.height); this.bodyPartsDraggableGridLeftShadow.setPosition(0, yPos);
this.bodyPartsDraggableGridRightShadow.setPosition( this.bodyPartsDraggableGridRightShadow.setPosition(
this.cameras.main.worldView.x + this.cameras.main.width, this.cameras.main.worldView.x + this.cameras.main.width,
this.cameras.main.worldView.y + this.cameras.main.height yPos
); );
try { try {