2020-05-06 01:50:01 +02:00
|
|
|
import {gameManager} from "../Game/GameManager";
|
2020-04-26 17:54:56 +02:00
|
|
|
import {TextField} from "../Components/TextField";
|
|
|
|
import {TextInput} from "../Components/TextInput";
|
2020-05-01 22:23:41 +02:00
|
|
|
import Image = Phaser.GameObjects.Image;
|
2020-07-28 15:53:44 +02:00
|
|
|
import {SelectCharacterSceneName} from "./SelectCharacterScene";
|
2020-10-07 18:03:34 +02:00
|
|
|
import {ResizableScene} from "./ResizableScene";
|
2021-04-07 14:09:45 +02:00
|
|
|
import {isUserNameValid, maxUserNameLength} from "../../Connexion/LocalUser";
|
2020-04-26 17:54:56 +02:00
|
|
|
|
|
|
|
//todo: put this constants in a dedicated file
|
|
|
|
export const LoginSceneName = "LoginScene";
|
|
|
|
enum LoginTextures {
|
2020-05-01 23:19:51 +02:00
|
|
|
icon = "icon",
|
|
|
|
mainFont = "main_font"
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
|
|
|
|
2020-10-07 18:03:34 +02:00
|
|
|
export class LoginScene extends ResizableScene {
|
|
|
|
private nameInput!: TextInput;
|
|
|
|
private textField!: TextField;
|
|
|
|
private infoTextField!: TextField;
|
|
|
|
private pressReturnField!: TextField;
|
|
|
|
private logo!: Image;
|
2020-06-03 11:55:31 +02:00
|
|
|
private name: string = '';
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
key: LoginSceneName
|
|
|
|
});
|
2020-12-04 11:30:35 +01:00
|
|
|
this.name = gameManager.getPlayerName() || '';
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
preload() {
|
2020-05-01 23:19:51 +02:00
|
|
|
//this.load.image(LoginTextures.playButton, "resources/objects/play_button.png");
|
2020-05-01 22:23:41 +02:00
|
|
|
this.load.image(LoginTextures.icon, "resources/logos/tcm_full.png");
|
2020-05-01 23:19:51 +02:00
|
|
|
// 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');
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
create() {
|
2020-05-04 18:38:04 +02:00
|
|
|
|
2020-05-01 23:19:51 +02:00
|
|
|
this.textField = new TextField(this, this.game.renderer.width / 2, 50, 'Enter your name:');
|
2021-04-07 14:09:45 +02:00
|
|
|
this.nameInput = new TextInput(this, this.game.renderer.width / 2, 70, maxUserNameLength, this.name,(text: string) => {
|
2020-05-26 22:17:00 +02:00
|
|
|
this.name = text;
|
|
|
|
});
|
2020-04-26 18:48:41 +02:00
|
|
|
|
2020-05-01 23:19:51 +02:00
|
|
|
this.pressReturnField = new TextField(this, this.game.renderer.width / 2, 130, 'Press enter to start');
|
|
|
|
|
2020-05-01 22:23:41 +02:00
|
|
|
this.logo = new Image(this, this.game.renderer.width - 30, this.game.renderer.height - 20, LoginTextures.icon);
|
|
|
|
this.add.existing(this.logo);
|
|
|
|
|
2020-06-09 23:13:26 +02:00
|
|
|
const infoText = "Commands: \n - Arrows or Z,Q,S,D to move\n - SHIFT to run";
|
2020-10-15 12:05:40 +02:00
|
|
|
this.infoTextField = new TextField(this, 10, this.game.renderer.height - 35, infoText, false);
|
2020-05-01 23:19:51 +02:00
|
|
|
|
|
|
|
this.input.keyboard.on('keyup-ENTER', () => {
|
2021-04-07 14:09:45 +02:00
|
|
|
if (isUserNameValid(this.name)) {
|
|
|
|
this.login(this.name);
|
2020-05-01 23:48:30 +02:00
|
|
|
}
|
2020-05-01 23:19:51 +02:00
|
|
|
});
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
update(time: number, delta: number): void {
|
2020-05-26 22:17:00 +02:00
|
|
|
if (this.name == '') {
|
2020-06-03 11:55:31 +02:00
|
|
|
this.pressReturnField?.setVisible(false);
|
2020-05-01 23:19:51 +02:00
|
|
|
} else {
|
2020-06-03 11:55:31 +02:00
|
|
|
this.pressReturnField?.setVisible(!!(Math.floor(time / 500) % 2));
|
2020-05-01 23:19:51 +02:00
|
|
|
}
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-05-26 17:25:29 +02:00
|
|
|
private login(name: string): void {
|
2020-07-28 15:53:44 +02:00
|
|
|
gameManager.setPlayerName(name);
|
|
|
|
|
2020-12-16 15:09:58 +01:00
|
|
|
this.scene.stop(LoginSceneName)
|
2020-12-15 18:00:04 +01:00
|
|
|
gameManager.tryResumingGame(this, SelectCharacterSceneName);
|
2020-12-16 15:09:58 +01:00
|
|
|
this.scene.remove(LoginSceneName)
|
2020-05-04 01:48:14 +02:00
|
|
|
}
|
2020-10-07 18:03:34 +02:00
|
|
|
|
|
|
|
public onResize(ev: UIEvent): void {
|
|
|
|
this.textField.x = this.game.renderer.width / 2;
|
|
|
|
this.nameInput.setX(this.game.renderer.width / 2 - 64);
|
|
|
|
this.pressReturnField.x = this.game.renderer.width / 2;
|
|
|
|
this.logo.x = this.game.renderer.width - 30;
|
|
|
|
this.logo.y = this.game.renderer.height - 20;
|
|
|
|
this.infoTextField.y = this.game.renderer.height - 35;
|
|
|
|
}
|
|
|
|
|
2020-05-01 22:23:41 +02:00
|
|
|
}
|