2020-12-16 15:09:58 +01:00
|
|
|
import {LoginScene, LoginSceneName} from "../Login/LoginScene";
|
|
|
|
import {SelectCharacterScene, SelectCharacterSceneName} from "../Login/SelectCharacterScene";
|
2021-04-02 23:13:03 +02:00
|
|
|
import {SelectCompanionScene, SelectCompanionSceneName} from "../Login/SelectCompanionScene";
|
2020-12-04 11:30:35 +01:00
|
|
|
import {gameManager} from "../Game/GameManager";
|
|
|
|
import {localUserStore} from "../../Connexion/LocalUserStore";
|
2021-02-02 18:19:51 +01:00
|
|
|
import {mediaManager} from "../../WebRtc/MediaManager";
|
|
|
|
import {gameReportKey, gameReportRessource, ReportMenu} from "./ReportMenu";
|
2021-02-03 23:14:31 +01:00
|
|
|
import {connectionManager} from "../../Connexion/ConnectionManager";
|
2021-02-02 18:19:51 +01:00
|
|
|
import {GameConnexionTypes} from "../../Url/UrlManager";
|
2021-03-11 16:14:34 +01:00
|
|
|
import {WarningContainer, warningContainerHtml, warningContainerKey} from "../Components/WarningContainer";
|
|
|
|
import {worldFullWarningStream} from "../../Connexion/WorldFullWarningStream";
|
2020-12-04 11:30:35 +01:00
|
|
|
|
|
|
|
export const MenuSceneName = 'MenuScene';
|
|
|
|
const gameMenuKey = 'gameMenu';
|
|
|
|
const gameMenuIconKey = 'gameMenuIcon';
|
|
|
|
const gameSettingsMenuKey = 'gameSettingsMenu';
|
2021-01-04 17:13:41 +01:00
|
|
|
const gameShare = 'gameShare';
|
2020-12-04 11:30:35 +01:00
|
|
|
|
|
|
|
const closedSideMenuX = -200;
|
|
|
|
const openedSideMenuX = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The scene that manages the game menu, rendered using a DOM element.
|
|
|
|
*/
|
|
|
|
export class MenuScene extends Phaser.Scene {
|
|
|
|
private menuElement!: Phaser.GameObjects.DOMElement;
|
|
|
|
private gameQualityMenuElement!: Phaser.GameObjects.DOMElement;
|
2021-01-04 17:13:41 +01:00
|
|
|
private gameShareElement!: Phaser.GameObjects.DOMElement;
|
2021-02-02 18:19:51 +01:00
|
|
|
private gameReportElement!: ReportMenu;
|
2020-12-04 11:30:35 +01:00
|
|
|
private sideMenuOpened = false;
|
|
|
|
private settingsMenuOpened = false;
|
2021-01-04 17:13:41 +01:00
|
|
|
private gameShareOpened = false;
|
2020-12-04 11:30:35 +01:00
|
|
|
private gameQualityValue: number;
|
|
|
|
private videoQualityValue: number;
|
|
|
|
private menuButton!: Phaser.GameObjects.DOMElement;
|
2021-03-11 16:14:34 +01:00
|
|
|
private warningContainer: WarningContainer | null = null;
|
|
|
|
private warningContainerTimeout: NodeJS.Timeout | null = null;
|
2020-12-04 11:30:35 +01:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super({key: MenuSceneName});
|
2020-12-17 15:18:12 +01:00
|
|
|
|
2020-12-04 11:30:35 +01:00
|
|
|
this.gameQualityValue = localUserStore.getGameQualityValue();
|
|
|
|
this.videoQualityValue = localUserStore.getVideoQualityValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
preload () {
|
|
|
|
this.load.html(gameMenuKey, 'resources/html/gameMenu.html');
|
|
|
|
this.load.html(gameMenuIconKey, 'resources/html/gameMenuIcon.html');
|
|
|
|
this.load.html(gameSettingsMenuKey, 'resources/html/gameQualityMenu.html');
|
2021-01-04 17:13:41 +01:00
|
|
|
this.load.html(gameShare, 'resources/html/gameShare.html');
|
2021-02-02 18:19:51 +01:00
|
|
|
this.load.html(gameReportKey, gameReportRessource);
|
2021-03-11 16:14:34 +01:00
|
|
|
this.load.html(warningContainerKey, warningContainerHtml);
|
2020-12-04 11:30:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
create() {
|
2020-12-16 12:23:34 +01:00
|
|
|
this.menuElement = this.add.dom(closedSideMenuX, 30).createFromCache(gameMenuKey);
|
2020-12-04 11:30:35 +01:00
|
|
|
this.menuElement.setOrigin(0);
|
2021-02-02 18:19:51 +01:00
|
|
|
MenuScene.revealMenusAfterInit(this.menuElement, 'gameMenu');
|
2020-12-04 11:30:35 +01:00
|
|
|
|
2020-12-17 22:35:38 +01:00
|
|
|
const middleX = (window.innerWidth / 3) - 298;
|
2020-12-17 21:58:18 +01:00
|
|
|
this.gameQualityMenuElement = this.add.dom(middleX, -400).createFromCache(gameSettingsMenuKey);
|
2021-02-02 18:19:51 +01:00
|
|
|
MenuScene.revealMenusAfterInit(this.gameQualityMenuElement, 'gameQuality');
|
2020-12-17 15:18:12 +01:00
|
|
|
|
2021-01-04 17:13:41 +01:00
|
|
|
|
|
|
|
this.gameShareElement = this.add.dom(middleX, -400).createFromCache(gameShare);
|
2021-02-02 18:19:51 +01:00
|
|
|
MenuScene.revealMenusAfterInit(this.gameShareElement, gameShare);
|
2021-01-04 17:13:41 +01:00
|
|
|
this.gameShareElement.addListener('click');
|
|
|
|
this.gameShareElement.on('click', (event:MouseEvent) => {
|
|
|
|
event.preventDefault();
|
|
|
|
if((event?.target as HTMLInputElement).id === 'gameShareFormSubmit') {
|
|
|
|
this.copyLink();
|
|
|
|
}else if((event?.target as HTMLInputElement).id === 'gameShareFormCancel') {
|
|
|
|
this.closeGameShare();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
this.gameReportElement = new ReportMenu(this, connectionManager.getConnexionType === GameConnexionTypes.anonymous);
|
|
|
|
mediaManager.setShowReportModalCallBacks((userId, userName) => {
|
|
|
|
this.closeAll();
|
|
|
|
this.gameReportElement.open(parseInt(userId), userName);
|
2021-01-29 21:09:10 +01:00
|
|
|
});
|
|
|
|
|
2020-12-04 11:30:35 +01:00
|
|
|
this.input.keyboard.on('keyup-TAB', () => {
|
|
|
|
this.sideMenuOpened ? this.closeSideMenu() : this.openSideMenu();
|
|
|
|
});
|
2020-12-16 15:09:58 +01:00
|
|
|
this.menuButton = this.add.dom(0, 0).createFromCache(gameMenuIconKey);
|
2020-12-04 11:30:35 +01:00
|
|
|
this.menuButton.addListener('click');
|
|
|
|
this.menuButton.on('click', () => {
|
|
|
|
this.sideMenuOpened ? this.closeSideMenu() : this.openSideMenu();
|
|
|
|
});
|
2020-12-17 14:16:10 +01:00
|
|
|
|
|
|
|
this.menuElement.addListener('click');
|
|
|
|
this.menuElement.on('click', this.onMenuClick.bind(this));
|
2021-03-11 16:14:34 +01:00
|
|
|
|
|
|
|
worldFullWarningStream.stream.subscribe(() => this.showWorldCapacityWarning());
|
2020-12-04 11:30:35 +01:00
|
|
|
}
|
2020-12-17 15:18:12 +01:00
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
//todo put this method in a parent menuElement class
|
|
|
|
static revealMenusAfterInit(menuElement: Phaser.GameObjects.DOMElement, rootDomId: string) {
|
2020-12-16 12:23:34 +01:00
|
|
|
//Dom elements will appear inside the viewer screen when creating before being moved out of it, which create a flicker effect.
|
|
|
|
//To prevent this, we put a 'hidden' attribute on the root element, we remove it only after the init is done.
|
|
|
|
setTimeout(() => {
|
|
|
|
(menuElement.getChildByID(rootDomId) as HTMLElement).hidden = false;
|
|
|
|
}, 250);
|
|
|
|
}
|
2020-12-17 15:18:12 +01:00
|
|
|
|
2020-12-16 15:09:58 +01:00
|
|
|
public revealMenuIcon(): void {
|
|
|
|
(this.menuButton.getChildByID('menuIcon') as HTMLElement).hidden = false
|
|
|
|
}
|
2020-12-17 15:18:12 +01:00
|
|
|
|
2020-12-04 11:30:35 +01:00
|
|
|
openSideMenu() {
|
|
|
|
if (this.sideMenuOpened) return;
|
2021-01-04 17:13:41 +01:00
|
|
|
this.closeAll();
|
2020-12-04 11:30:35 +01:00
|
|
|
this.sideMenuOpened = true;
|
2020-12-16 17:17:31 +01:00
|
|
|
this.menuButton.getChildByID('openMenuButton').innerHTML = 'X';
|
2020-12-17 21:58:18 +01:00
|
|
|
if (gameManager.getCurrentGameScene(this).connection && gameManager.getCurrentGameScene(this).connection.isAdmin()) {
|
2020-12-04 11:30:35 +01:00
|
|
|
const adminSection = this.menuElement.getChildByID('adminConsoleSection') as HTMLElement;
|
|
|
|
adminSection.hidden = false;
|
|
|
|
}
|
2021-02-04 16:05:05 +01:00
|
|
|
//TODO bind with future metadata of card
|
|
|
|
//if (connectionManager.getConnexionType === GameConnexionTypes.anonymous){
|
2021-02-03 23:14:31 +01:00
|
|
|
const adminSection = this.menuElement.getChildByID('socialLinks') as HTMLElement;
|
|
|
|
adminSection.hidden = false;
|
2021-02-04 16:05:05 +01:00
|
|
|
//}
|
2020-12-04 11:30:35 +01:00
|
|
|
this.tweens.add({
|
|
|
|
targets: this.menuElement,
|
|
|
|
x: openedSideMenuX,
|
|
|
|
duration: 500,
|
|
|
|
ease: 'Power3'
|
|
|
|
});
|
|
|
|
}
|
2021-03-11 16:14:34 +01:00
|
|
|
|
|
|
|
private showWorldCapacityWarning() {
|
|
|
|
if (!this.warningContainer) {
|
|
|
|
this.warningContainer = new WarningContainer(this);
|
|
|
|
}
|
|
|
|
if (this.warningContainerTimeout) {
|
|
|
|
clearTimeout(this.warningContainerTimeout);
|
|
|
|
}
|
|
|
|
this.warningContainerTimeout = setTimeout(() => {
|
|
|
|
this.warningContainer?.destroy();
|
|
|
|
this.warningContainer = null
|
|
|
|
this.warningContainerTimeout = null
|
2021-03-24 17:35:59 +01:00
|
|
|
}, 120000);
|
2021-03-11 16:14:34 +01:00
|
|
|
|
|
|
|
}
|
2020-12-17 15:18:12 +01:00
|
|
|
|
2020-12-04 11:30:35 +01:00
|
|
|
private closeSideMenu(): void {
|
|
|
|
if (!this.sideMenuOpened) return;
|
|
|
|
this.sideMenuOpened = false;
|
2021-01-04 17:13:41 +01:00
|
|
|
this.closeAll();
|
2021-01-12 19:48:48 +01:00
|
|
|
this.menuButton.getChildByID('openMenuButton').innerHTML = `<img src="/static/images/menu.svg">`;
|
2020-12-16 18:52:11 +01:00
|
|
|
gameManager.getCurrentGameScene(this).ConsoleGlobalMessageManager.disabledMessageConsole();
|
2020-12-04 11:30:35 +01:00
|
|
|
this.tweens.add({
|
|
|
|
targets: this.menuElement,
|
|
|
|
x: closedSideMenuX,
|
|
|
|
duration: 500,
|
|
|
|
ease: 'Power3'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private openGameSettingsMenu(): void {
|
2020-12-17 21:58:18 +01:00
|
|
|
if (this.settingsMenuOpened) {
|
2021-01-12 19:48:48 +01:00
|
|
|
this.closeGameQualityMenu();
|
2020-12-17 21:58:18 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-01-04 17:13:41 +01:00
|
|
|
//close all
|
|
|
|
this.closeAll();
|
|
|
|
|
2020-12-04 11:30:35 +01:00
|
|
|
this.settingsMenuOpened = true;
|
|
|
|
|
|
|
|
const gameQualitySelect = this.gameQualityMenuElement.getChildByID('select-game-quality') as HTMLInputElement;
|
|
|
|
gameQualitySelect.value = ''+this.gameQualityValue;
|
|
|
|
const videoQualitySelect = this.gameQualityMenuElement.getChildByID('select-video-quality') as HTMLInputElement;
|
|
|
|
videoQualitySelect.value = ''+this.videoQualityValue;
|
|
|
|
|
|
|
|
this.gameQualityMenuElement.addListener('click');
|
|
|
|
this.gameQualityMenuElement.on('click', (event:MouseEvent) => {
|
|
|
|
event.preventDefault();
|
|
|
|
if ((event?.target as HTMLInputElement).id === 'gameQualityFormSubmit') {
|
2020-12-17 15:18:12 +01:00
|
|
|
const gameQualitySelect = this.gameQualityMenuElement.getChildByID('select-game-quality') as HTMLInputElement;
|
2020-12-04 11:30:35 +01:00
|
|
|
const videoQualitySelect = this.gameQualityMenuElement.getChildByID('select-video-quality') as HTMLInputElement;
|
|
|
|
this.saveSetting(parseInt(gameQualitySelect.value), parseInt(videoQualitySelect.value));
|
|
|
|
} else if((event?.target as HTMLInputElement).id === 'gameQualityFormCancel') {
|
|
|
|
this.closeGameQualityMenu();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-12-17 21:58:18 +01:00
|
|
|
let middleY = (window.innerHeight / 3) - (257);
|
|
|
|
if(middleY < 0){
|
|
|
|
middleY = 0;
|
|
|
|
}
|
|
|
|
let middleX = (window.innerWidth / 3) - 298;
|
|
|
|
if(middleX < 0){
|
|
|
|
middleX = 0;
|
|
|
|
}
|
2020-12-04 11:30:35 +01:00
|
|
|
this.tweens.add({
|
|
|
|
targets: this.gameQualityMenuElement,
|
2020-12-17 21:58:18 +01:00
|
|
|
y: middleY,
|
|
|
|
x: middleX,
|
2020-12-04 11:30:35 +01:00
|
|
|
duration: 1000,
|
|
|
|
ease: 'Power3'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private closeGameQualityMenu(): void {
|
|
|
|
if (!this.settingsMenuOpened) return;
|
|
|
|
this.settingsMenuOpened = false;
|
|
|
|
|
|
|
|
this.gameQualityMenuElement.removeListener('click');
|
|
|
|
this.tweens.add({
|
|
|
|
targets: this.gameQualityMenuElement,
|
|
|
|
y: -400,
|
|
|
|
duration: 1000,
|
|
|
|
ease: 'Power3'
|
|
|
|
});
|
|
|
|
}
|
2020-12-17 15:18:12 +01:00
|
|
|
|
|
|
|
|
2021-01-04 17:13:41 +01:00
|
|
|
private openGameShare(): void{
|
|
|
|
if (this.gameShareOpened) {
|
|
|
|
this.closeGameShare();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//close all
|
|
|
|
this.closeAll();
|
|
|
|
|
|
|
|
const gameShareLink = this.gameShareElement.getChildByID('gameShareLink') as HTMLInputElement;
|
|
|
|
gameShareLink.value = location.toString();
|
|
|
|
|
|
|
|
this.gameShareOpened = true;
|
|
|
|
|
|
|
|
let middleY = (window.innerHeight / 3) - (257);
|
|
|
|
if(middleY < 0){
|
|
|
|
middleY = 0;
|
|
|
|
}
|
|
|
|
let middleX = (window.innerWidth / 3) - 298;
|
|
|
|
if(middleX < 0){
|
|
|
|
middleX = 0;
|
|
|
|
}
|
|
|
|
this.tweens.add({
|
|
|
|
targets: this.gameShareElement,
|
|
|
|
y: middleY,
|
|
|
|
x: middleX,
|
|
|
|
duration: 1000,
|
|
|
|
ease: 'Power3'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private closeGameShare(): void{
|
|
|
|
const gameShareInfo = this.gameShareElement.getChildByID('gameShareInfo') as HTMLParagraphElement;
|
|
|
|
gameShareInfo.innerText = '';
|
|
|
|
gameShareInfo.style.display = 'none';
|
|
|
|
this.gameShareOpened = false;
|
|
|
|
this.tweens.add({
|
|
|
|
targets: this.gameShareElement,
|
|
|
|
y: -400,
|
|
|
|
duration: 1000,
|
|
|
|
ease: 'Power3'
|
|
|
|
});
|
|
|
|
}
|
2020-12-17 15:18:12 +01:00
|
|
|
|
2020-12-04 11:30:35 +01:00
|
|
|
private onMenuClick(event:MouseEvent) {
|
2021-02-03 23:14:31 +01:00
|
|
|
if((event?.target as HTMLInputElement).classList.contains('not-button')){
|
|
|
|
return;
|
|
|
|
}
|
2020-12-04 11:30:35 +01:00
|
|
|
event.preventDefault();
|
2020-12-17 15:18:12 +01:00
|
|
|
|
2020-12-04 11:30:35 +01:00
|
|
|
switch ((event?.target as HTMLInputElement).id) {
|
|
|
|
case 'changeNameButton':
|
|
|
|
this.closeSideMenu();
|
2020-12-16 15:09:58 +01:00
|
|
|
gameManager.leaveGame(this, LoginSceneName, new LoginScene());
|
2020-12-04 11:30:35 +01:00
|
|
|
break;
|
|
|
|
case 'sparkButton':
|
2020-12-17 18:19:47 +01:00
|
|
|
this.gotToCreateMapPage();
|
2020-12-04 11:30:35 +01:00
|
|
|
break;
|
|
|
|
case 'changeSkinButton':
|
|
|
|
this.closeSideMenu();
|
2020-12-16 15:09:58 +01:00
|
|
|
gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene());
|
2020-12-04 11:30:35 +01:00
|
|
|
break;
|
2021-04-02 23:13:03 +02:00
|
|
|
case 'changeCompanionButton':
|
|
|
|
this.closeSideMenu();
|
|
|
|
gameManager.leaveGame(this, SelectCompanionSceneName, new SelectCompanionScene());
|
|
|
|
break;
|
2020-12-04 11:30:35 +01:00
|
|
|
case 'closeButton':
|
|
|
|
this.closeSideMenu();
|
|
|
|
break;
|
|
|
|
case 'shareButton':
|
2021-01-04 17:13:41 +01:00
|
|
|
this.openGameShare();
|
2020-12-04 11:30:35 +01:00
|
|
|
break;
|
|
|
|
case 'editGameSettingsButton':
|
|
|
|
this.openGameSettingsMenu();
|
|
|
|
break;
|
2021-02-03 23:28:46 +01:00
|
|
|
case 'showJoystick':
|
|
|
|
this.showJoystick();
|
|
|
|
break;
|
2020-12-04 11:30:35 +01:00
|
|
|
case 'adminConsoleButton':
|
|
|
|
gameManager.getCurrentGameScene(this).ConsoleGlobalMessageManager.activeMessageConsole();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-12-17 15:18:12 +01:00
|
|
|
|
2021-01-04 17:13:41 +01:00
|
|
|
private async copyLink() {
|
2020-12-04 11:30:35 +01:00
|
|
|
await navigator.clipboard.writeText(location.toString());
|
2021-01-04 17:13:41 +01:00
|
|
|
const gameShareInfo = this.gameShareElement.getChildByID('gameShareInfo') as HTMLParagraphElement;
|
|
|
|
gameShareInfo.innerText = 'Link copied, you can share it now!';
|
|
|
|
gameShareInfo.style.display = 'block';
|
2020-12-04 11:30:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private saveSetting(valueGame: number, valueVideo: number){
|
|
|
|
if (valueGame !== this.gameQualityValue) {
|
|
|
|
this.gameQualityValue = valueGame;
|
|
|
|
localUserStore.setGameQualityValue(valueGame);
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
if (valueVideo !== this.videoQualityValue) {
|
|
|
|
this.videoQualityValue = valueVideo;
|
|
|
|
localUserStore.setVideoQualityValue(valueVideo);
|
|
|
|
mediaManager.updateCameraQuality(valueVideo);
|
|
|
|
}
|
|
|
|
this.closeGameQualityMenu();
|
|
|
|
}
|
|
|
|
|
2020-12-17 18:19:47 +01:00
|
|
|
private gotToCreateMapPage() {
|
|
|
|
const sparkHost = 'https://'+window.location.host.replace('play.', '')+'/choose-map.html';
|
2020-12-16 19:02:10 +01:00
|
|
|
window.open(sparkHost, '_blank');
|
2020-12-04 11:30:35 +01:00
|
|
|
}
|
2021-01-04 17:13:41 +01:00
|
|
|
|
|
|
|
private closeAll(){
|
|
|
|
this.closeGameQualityMenu();
|
|
|
|
this.closeGameShare();
|
2021-02-02 18:19:51 +01:00
|
|
|
this.gameReportElement.close();
|
2021-01-04 17:13:41 +01:00
|
|
|
}
|
2021-02-03 23:28:46 +01:00
|
|
|
|
|
|
|
private showJoystick() {
|
|
|
|
const gameScene = gameManager.getCurrentGameScene(this)
|
|
|
|
if (gameScene?.virtualJoystick) {
|
|
|
|
const joystickVisible = !gameScene.virtualJoystick.visible
|
|
|
|
gameScene.virtualJoystick.visible = joystickVisible
|
|
|
|
localUserStore.setJoystick(joystickVisible)
|
|
|
|
}
|
|
|
|
const body = document.querySelector('body')
|
|
|
|
if (body) {
|
|
|
|
if (document.fullscreenElement ?? document.fullscreen) {
|
|
|
|
document.exitFullscreen()
|
|
|
|
} else {
|
|
|
|
body.requestFullscreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-17 15:18:12 +01:00
|
|
|
}
|