Refactor Login Scene

This commit is contained in:
Gregoire Parant 2021-04-20 18:49:42 +02:00
parent 5dc2f0ac47
commit 2c862fe7e7
4 changed files with 176 additions and 77 deletions

View File

@ -0,0 +1,101 @@
<style>
#loginScene {
background: #eceeee;
border: 1px solid #42464b;
border-radius: 6px;
margin: 20px auto 0;
width: 200px;
height: 200px;
}
#loginScene h1 {
background-image: linear-gradient(top, #f1f3f3, #d4dae0);
border-bottom: 1px solid #a6abaf;
border-radius: 6px 6px 0 0;
box-sizing: border-box;
color: #727678;
display: block;
height: 43px;
padding-top: 10px;
margin: 0;
text-align: center;
text-shadow: 0 -1px 0 rgba(0,0,0,0.2), 0 1px 0 #fff;
}
#loginScene input {
font-size: 70%;
background: linear-gradient(top, #d6d7d7, #dee0e0);
border: 1px solid #a1a3a3;
border-radius: 4px;
box-shadow: 0 1px #fff;
box-sizing: border-box;
color: #696969;
height: 30px;
transition: box-shadow 0.3s;
width: 100%;
text-align: center;
}
#loginScene section {
margin: 10px;
}
#loginScene section.action{
text-align: center;
margin: 0;
}
#loginScene button {
margin-top: 10px;
background-color: black;
color: white;
border-radius: 7px;
padding-bottom: 4px;
width: 100px;
}
#loginScene button#loginSceneFormCancel {
background-color: #c7c7c700;
color: #292929;
}
#loginScene section h6,
#loginScene section h5{
margin: 1px;
}
#loginScene section.text-center{
text-align: center;
}
#loginScene section a{
font-size: 8px;
text-decoration: underline;
color: black;
}
#loginScene section a:hover{
font-weight: 700;
}
#loginScene section p{
text-align: left;
font-size: 8px;
margin: 10px 10px;
}
#loginScene section p.err{
color: red;
text-align: center;
}
#loginScene section p.info{
display: none;
text-align: center;
}
#loginScene section input#loginSceneLink{
background-color: #a1a3a3;
}
</style>
<form id="loginScene" hidden>
<section class="text-center">
<h5>Enter your name</h5>
<p class="info">9 chars maximum</p>
<p class="err" id="errorLoginScene"></p>
</section>
<section>
<input type="text" name="email" id="loginSceneName">
<p>By continuing, you are agreeing our <a href="https://workadventu.re/terms-of-use" target="_blank">terms of use</a>, <a href="https://workadventu.re/privacy-policy" target="_blank">privacy policy</a> and <a href="https://workadventu.re/cookie-policy" target="_blank">cookie policy</a>.</p>
</section>
<section class="action">
<button type="submit" id="loginSceneFormSubmit">Continue</button>
</section>
</form>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 969 B

View File

@ -0,0 +1,17 @@
@media only screen and (max-width: 600px) {
.sidebar > div {
max-height: 240px;
}
.sidebar > div {
max-height: 240px;
}
.sidebar{
max-width: 200px;
}
.btn-cam-action div{
bottom: 50px;
}
}

View File

@ -1,30 +1,17 @@
import {gameManager} from "../Game/GameManager"; import {gameManager} from "../Game/GameManager";
import {TextField} from "../Components/TextField";
import {TextInput} from "../Components/TextInput";
import Image = Phaser.GameObjects.Image;
import {SelectCharacterSceneName} from "./SelectCharacterScene"; import {SelectCharacterSceneName} from "./SelectCharacterScene";
import {ResizableScene} from "./ResizableScene"; import {ResizableScene} from "./ResizableScene";
import {isUserNameValid, maxUserNameLength} from "../../Connexion/LocalUser";
import { localUserStore } from "../../Connexion/LocalUserStore"; import { localUserStore } from "../../Connexion/LocalUserStore";
import Rectangle = Phaser.GameObjects.Rectangle; import {MenuScene} from "../Menu/MenuScene";
import {touchScreenManager} from "../../Touch/TouchScreenManager";
import {PinchManager} from "../UserInput/PinchManager";
//todo: put this constants in a dedicated file
export const LoginSceneName = "LoginScene"; export const LoginSceneName = "LoginScene";
enum LoginTextures {
icon = "icon", const loginSceneKey = 'loginScene';
mainFont = "main_font"
}
export class LoginScene extends ResizableScene { export class LoginScene extends ResizableScene {
private nameInput!: TextInput;
private textField!: TextField; private loginSceneElement!: Phaser.GameObjects.DOMElement;
private infoTextField!: TextField;
private pressReturnField!: TextField;
private logo!: Image;
private name: string = ''; private name: string = '';
private mobileTapRectangle!: Rectangle;
constructor() { constructor() {
super({ super({
@ -34,81 +21,75 @@ export class LoginScene extends ResizableScene {
} }
preload() { preload() {
//this.load.image(LoginTextures.playButton, "resources/objects/play_button.png"); this.load.html(loginSceneKey, 'resources/html/loginScene.html');
this.load.image(LoginTextures.icon, "resources/logos/tcm_full.png");
// Note: arcade.png from the Phaser 3 examples at: https://github.com/photonstorm/phaser3-examples/tree/master/public/assets/fonts/bitmap
this.load.bitmapFont(LoginTextures.mainFont, 'resources/fonts/arcade.png', 'resources/fonts/arcade.xml');
} }
create() { create() {
if (touchScreenManager.supportTouchScreen) { const middleX = this.getMiddleX();
new PinchManager(this); this.loginSceneElement = this.add.dom((middleX/2), 0).createFromCache(loginSceneKey);
MenuScene.revealMenusAfterInit(this.loginSceneElement, loginSceneKey);
const pErrorElement = this.loginSceneElement.getChildByID('errorLoginScene') as HTMLInputElement;
const inputElement = this.loginSceneElement.getChildByID('loginSceneName') as HTMLInputElement;
inputElement.value = localUserStore.getName() ?? '';
inputElement.focus();
inputElement.addEventListener('keypress', (event: KeyboardEvent) => {
if(inputElement.value.length > 8){
event.preventDefault();
return;
} }
pErrorElement.innerHTML = '';
this.nameInput = new TextInput(this, this.game.renderer.width / 2, 70, maxUserNameLength, this.name,(text: string) => { if (event.key === 'Enter') {
this.name = text; event.preventDefault();
localUserStore.setName(text); this.login(inputElement);
}) return;
.setInteractive()
.on('pointerdown', () => {
this.nameInput.focus();
})
this.textField = new TextField(this, this.game.renderer.width / 2, 50, 'Enter your name:')
.setInteractive()
.on('pointerdown', () => {
this.nameInput.focus();
})
// For mobile purposes - we need a big enough touchable area.
this.mobileTapRectangle = this.add.rectangle(
this.game.renderer.width / 2,
130,
this.game.renderer.width / 2,
60,
).setInteractive()
.on('pointerdown', () => {
this.login(this.name)
})
this.pressReturnField = new TextField(this, this.game.renderer.width / 2, 130, 'Touch here\n\n or \n\nPress enter to start')
this.logo = new Image(this, this.game.renderer.width - 30, this.game.renderer.height - 20, LoginTextures.icon);
this.add.existing(this.logo);
const infoText = "Commands: \n - Arrows or W, A, S, D to move\n - SHIFT to run";
this.infoTextField = new TextField(this, 10, this.game.renderer.height - 35, infoText, false);
this.input.keyboard.on('keyup-ENTER', () => {
if (isUserNameValid(this.name)) {
this.login(this.name);
} }
}); });
const continuingButton = this.loginSceneElement.getChildByID('loginSceneFormSubmit') as HTMLButtonElement;
continuingButton.addEventListener('click', (e) => {
e.preventDefault();
this.login(inputElement);
});
} }
update(time: number, delta: number): void { private login(inputElement: HTMLInputElement): void {
if (this.name == '') { const pErrorElement = this.loginSceneElement.getChildByID('errorLoginScene') as HTMLInputElement;
this.pressReturnField?.setVisible(false); this.name = inputElement.value;
} else { if (this.name === '') {
this.pressReturnField?.setVisible(!!(Math.floor(time / 500) % 2)); pErrorElement.innerHTML = 'The name is empty';
return
} }
}
private login(name: string): void {
if (this.name === '') return if (this.name === '') return
gameManager.setPlayerName(name); gameManager.setPlayerName(this.name);
this.scene.stop(LoginSceneName) this.scene.stop(LoginSceneName)
gameManager.tryResumingGame(this, SelectCharacterSceneName); gameManager.tryResumingGame(this, SelectCharacterSceneName);
this.scene.remove(LoginSceneName) this.scene.remove(LoginSceneName)
} }
public onResize(ev: UIEvent): void { update(time: number, delta: number): void {
this.textField.x = this.game.renderer.width / 2; const middleX = this.getMiddleX();
this.nameInput.setX(this.game.renderer.width / 2 - 64); this.tweens.add({
this.pressReturnField.x = this.game.renderer.width / 2; targets: this.loginSceneElement,
this.mobileTapRectangle.x = this.game.renderer.width / 2; x: (middleX/2),
this.logo.x = this.game.renderer.width - 30; duration: 1000,
this.logo.y = this.game.renderer.height - 20; ease: 'Power3'
this.infoTextField.y = this.game.renderer.height - 35; });
} }
public onResize(ev: UIEvent): void {
const middleX = this.getMiddleX();
this.tweens.add({
targets: this.loginSceneElement,
x: (middleX/2),
duration: 1000,
ease: 'Power3'
});
}
private getMiddleX() : number{
const middleX = ((window.innerWidth) - ((this.loginSceneElement && this.loginSceneElement.width > 0 ? this.loginSceneElement.width : 200 /*FIXME to use a const will be injected in HTMLElement*/)*2)) / 2;
return (middleX > 0 ? middleX : 0);
}
} }