2021-07-07 11:24:51 +02:00
|
|
|
import { MenuScene } from "./MenuScene";
|
|
|
|
import { gameManager } from "../Game/GameManager";
|
|
|
|
import { blackListManager } from "../../WebRtc/BlackListManager";
|
|
|
|
import { playersStore } from "../../Stores/PlayersStore";
|
2021-02-02 18:19:51 +01:00
|
|
|
|
2021-07-07 11:24:51 +02:00
|
|
|
export const gameReportKey = "gameReport";
|
|
|
|
export const gameReportRessource = "resources/html/gameReport.html";
|
2021-02-02 18:19:51 +01:00
|
|
|
|
|
|
|
export class ReportMenu extends Phaser.GameObjects.DOMElement {
|
|
|
|
private opened: boolean = false;
|
2021-04-23 13:44:04 +02:00
|
|
|
|
2021-07-07 11:24:51 +02:00
|
|
|
private userUuid!: string;
|
|
|
|
private userName!: string | undefined;
|
2021-02-02 18:19:51 +01:00
|
|
|
private anonymous: boolean;
|
2021-04-23 13:44:04 +02:00
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
constructor(scene: Phaser.Scene, anonymous: boolean) {
|
|
|
|
super(scene, -2000, -2000);
|
|
|
|
this.anonymous = anonymous;
|
|
|
|
this.createFromCache(gameReportKey);
|
|
|
|
|
|
|
|
if (this.anonymous) {
|
2021-07-07 11:24:51 +02:00
|
|
|
const divToHide = this.getChildByID("reportSection") as HTMLElement;
|
2021-02-02 18:19:51 +01:00
|
|
|
divToHide.hidden = true;
|
2021-07-07 11:24:51 +02:00
|
|
|
const textToHide = this.getChildByID("askActionP") as HTMLElement;
|
2021-02-02 18:19:51 +01:00
|
|
|
textToHide.hidden = true;
|
|
|
|
}
|
2021-04-23 13:44:04 +02:00
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
scene.add.existing(this);
|
|
|
|
MenuScene.revealMenusAfterInit(this, gameReportKey);
|
|
|
|
|
2021-07-07 11:24:51 +02:00
|
|
|
this.addListener("click");
|
|
|
|
this.on("click", (event: MouseEvent) => {
|
2021-02-02 18:19:51 +01:00
|
|
|
event.preventDefault();
|
2021-07-07 11:24:51 +02:00
|
|
|
if ((event?.target as HTMLInputElement).id === "gameReportFormSubmit") {
|
2021-02-02 18:19:51 +01:00
|
|
|
this.submitReport();
|
2021-07-07 11:24:51 +02:00
|
|
|
} else if ((event?.target as HTMLInputElement).id === "gameReportFormCancel") {
|
2021-02-02 18:19:51 +01:00
|
|
|
this.close();
|
2021-07-07 11:24:51 +02:00
|
|
|
} else if ((event?.target as HTMLInputElement).id === "toggleBlockButton") {
|
2021-02-02 18:19:51 +01:00
|
|
|
this.toggleBlock();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-07 11:24:51 +02:00
|
|
|
public open(userUuid: string, userName: string | undefined): void {
|
2021-02-02 18:19:51 +01:00
|
|
|
if (this.opened) {
|
|
|
|
this.close();
|
|
|
|
return;
|
|
|
|
}
|
2021-04-23 13:44:04 +02:00
|
|
|
|
2021-07-07 11:24:51 +02:00
|
|
|
this.userUuid = userUuid;
|
2021-02-02 18:19:51 +01:00
|
|
|
this.userName = userName;
|
2021-04-23 13:44:04 +02:00
|
|
|
|
2021-07-07 11:24:51 +02:00
|
|
|
const mainEl = this.getChildByID("gameReport") as HTMLElement;
|
2021-02-02 18:19:51 +01:00
|
|
|
this.x = this.getCenteredX(mainEl);
|
|
|
|
this.y = this.getHiddenY(mainEl);
|
|
|
|
|
2021-07-07 11:24:51 +02:00
|
|
|
const gameTitleReport = this.getChildByID("nameReported") as HTMLElement;
|
|
|
|
gameTitleReport.innerText = userName || "";
|
2021-02-02 18:19:51 +01:00
|
|
|
|
2021-07-07 11:24:51 +02:00
|
|
|
const blockButton = this.getChildByID("toggleBlockButton") as HTMLElement;
|
|
|
|
blockButton.innerText = blackListManager.isBlackListed(this.userUuid) ? "Unblock this user" : "Block this user";
|
2021-02-02 18:19:51 +01:00
|
|
|
|
|
|
|
this.opened = true;
|
|
|
|
|
2021-03-22 16:10:21 +01:00
|
|
|
gameManager.getCurrentGameScene(this.scene).userInputManager.disableControls();
|
2021-02-02 18:19:51 +01:00
|
|
|
|
|
|
|
this.scene.tweens.add({
|
|
|
|
targets: this,
|
|
|
|
y: this.getCenteredY(mainEl),
|
|
|
|
duration: 1000,
|
2021-07-07 11:24:51 +02:00
|
|
|
ease: "Power3",
|
2021-02-02 18:19:51 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public close(): void {
|
2021-04-12 18:17:04 +02:00
|
|
|
gameManager.getCurrentGameScene(this.scene).userInputManager.restoreControls();
|
2021-02-02 18:19:51 +01:00
|
|
|
this.opened = false;
|
2021-07-07 11:24:51 +02:00
|
|
|
const mainEl = this.getChildByID("gameReport") as HTMLElement;
|
2021-02-02 18:19:51 +01:00
|
|
|
this.scene.tweens.add({
|
|
|
|
targets: this,
|
|
|
|
y: this.getHiddenY(mainEl),
|
|
|
|
duration: 1000,
|
2021-07-07 11:24:51 +02:00
|
|
|
ease: "Power3",
|
2021-02-02 18:19:51 +01:00
|
|
|
});
|
|
|
|
}
|
2021-04-23 13:44:04 +02:00
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
//todo: into a parent class?
|
|
|
|
private getCenteredX(mainEl: HTMLElement): number {
|
|
|
|
return window.innerWidth / 4 - mainEl.clientWidth / 2;
|
|
|
|
}
|
|
|
|
private getHiddenY(mainEl: HTMLElement): number {
|
2021-07-07 11:24:51 +02:00
|
|
|
return -mainEl.clientHeight - 50;
|
2021-02-02 18:19:51 +01:00
|
|
|
}
|
|
|
|
private getCenteredY(mainEl: HTMLElement): number {
|
|
|
|
return window.innerHeight / 4 - mainEl.clientHeight / 2;
|
|
|
|
}
|
2021-04-23 13:44:04 +02:00
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
private toggleBlock(): void {
|
2021-07-07 11:24:51 +02:00
|
|
|
!blackListManager.isBlackListed(this.userUuid)
|
|
|
|
? blackListManager.blackList(this.userUuid)
|
|
|
|
: blackListManager.cancelBlackList(this.userUuid);
|
2021-02-02 18:19:51 +01:00
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
|
2021-07-07 11:24:51 +02:00
|
|
|
private submitReport(): void {
|
|
|
|
const gamePError = this.getChildByID("gameReportErr") as HTMLParagraphElement;
|
|
|
|
gamePError.innerText = "";
|
|
|
|
gamePError.style.display = "none";
|
|
|
|
const gameTextArea = this.getChildByID("gameReportInput") as HTMLInputElement;
|
|
|
|
if (!gameTextArea || !gameTextArea.value) {
|
|
|
|
gamePError.innerText = "Report message cannot to be empty.";
|
|
|
|
gamePError.style.display = "block";
|
2021-02-02 18:19:51 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-07-07 11:24:51 +02:00
|
|
|
gameManager
|
|
|
|
.getCurrentGameScene(this.scene)
|
|
|
|
.connection?.emitReportPlayerMessage(this.userUuid, gameTextArea.value);
|
2021-02-02 18:19:51 +01:00
|
|
|
this.close();
|
|
|
|
}
|
2021-04-23 13:44:04 +02:00
|
|
|
}
|