workadventure/front/src/Components/FollowMenu/FollowMenu.svelte

181 lines
5.5 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { gameManager } from "../../Phaser/Game/GameManager";
import { followStateStore, followRoleStore, followUsersStore } from "../../Stores/FollowStore";
2022-01-21 17:06:03 +01:00
import LL from "../../i18n/i18n-svelte";
const gameScene = gameManager.getCurrentGameScene();
2021-12-19 16:01:51 +01:00
function name(userId: number): string {
const user = gameScene.MapPlayersByKey.get(userId);
return user ? user.PlayerValue : "";
2021-12-15 14:48:45 +01:00
}
function acceptFollowRequest() {
2021-12-27 15:55:00 +01:00
gameScene.CurrentPlayer.startFollowing();
}
function abortEnding() {
followStateStore.set("active");
}
function reset() {
2021-12-15 14:48:45 +01:00
gameScene.connection?.emitFollowAbort();
followUsersStore.stopFollowing();
}
function onKeyDown(e: KeyboardEvent) {
if (e.key === "Escape") {
reset();
}
}
</script>
<svelte:window on:keydown={onKeyDown} />
2021-12-27 15:55:00 +01:00
{#if $followStateStore === "requesting" && $followRoleStore === "follower"}
<div class="interact-menu nes-container is-rounded">
2021-12-27 15:55:00 +01:00
<section class="interact-menu-title">
2022-01-21 17:06:03 +01:00
<h2>{$LL.follow.interactMenu.title.follow({ leader: name($followUsersStore[0]) })}</h2>
2021-12-27 15:55:00 +01:00
</section>
<section class="interact-menu-action">
2021-12-19 16:01:51 +01:00
<button type="button" class="nes-btn is-success" on:click|preventDefault={acceptFollowRequest}
2022-01-21 17:06:03 +01:00
>{$LL.follow.interactMenu.yes()}</button
2021-12-19 16:01:51 +01:00
>
<button type="button" class="nes-btn is-error" on:click|preventDefault={reset}
2022-01-21 17:06:03 +01:00
>{$LL.follow.interactMenu.no()}</button
2021-12-19 16:01:51 +01:00
>
2021-12-27 15:55:00 +01:00
</section>
</div>
{/if}
{#if $followStateStore === "ending"}
<div class="interact-menu nes-container is-rounded">
<section class="interact-menu-title">
2022-01-21 17:06:03 +01:00
<h2>{$LL.follow.interactMenu.title.interact()}</h2>
</section>
{#if $followRoleStore === "follower"}
<section class="interact-menu-question">
2022-01-21 17:06:03 +01:00
<p>{$LL.follow.interactMenu.stop.follower({ leader: name($followUsersStore[0]) })}</p>
</section>
{:else if $followRoleStore === "leader"}
<section class="interact-menu-question">
2022-01-21 17:06:03 +01:00
<p>{$LL.follow.interactMenu.stop.leader()}</p>
</section>
{/if}
<section class="interact-menu-action">
2021-12-19 16:01:51 +01:00
<button type="button" class="nes-btn is-success" on:click|preventDefault={reset}
2022-01-21 17:06:03 +01:00
>{$LL.follow.interactMenu.yes()}</button
2021-12-19 16:01:51 +01:00
>
<button type="button" class="nes-btn is-error" on:click|preventDefault={abortEnding}
2022-01-21 17:06:03 +01:00
>{$LL.follow.interactMenu.no()}</button
2021-12-19 16:01:51 +01:00
>
</section>
</div>
{/if}
{#if $followStateStore === "active" || $followStateStore === "ending"}
<div class="interact-status nes-container is-rounded">
2022-01-05 10:27:40 +01:00
<section>
{#if $followRoleStore === "follower"}
2022-01-21 17:06:03 +01:00
<p>{$LL.follow.interactStatus.following({ leader: name($followUsersStore[0]) })}</p>
{:else if $followUsersStore.length === 0}
2022-01-21 17:06:03 +01:00
<p>{$LL.follow.interactStatus.waitingFollowers()}</p>
{:else if $followUsersStore.length === 1}
2022-01-21 17:06:03 +01:00
<p>{$LL.follow.interactStatus.followed.one({ follower: name($followUsersStore[0]) })}</p>
{:else if $followUsersStore.length === 2}
2021-12-19 16:01:51 +01:00
<p>
2022-01-21 17:06:03 +01:00
{$LL.follow.interactStatus.followed.two({
2021-12-19 16:01:51 +01:00
firstFollower: name($followUsersStore[0]),
secondFollower: name($followUsersStore[1]),
})}
</p>
{:else}
<p>
2022-01-21 17:06:03 +01:00
{$LL.follow.interactStatus.followed.many({
2021-12-19 16:01:51 +01:00
followers: $followUsersStore.slice(0, -1).map(name).join(", "),
lastFollower: name($followUsersStore[$followUsersStore.length - 1]),
})}
</p>
{/if}
</section>
</div>
{/if}
<style lang="scss">
2022-01-05 10:27:40 +01:00
@import "../../../style/breakpoints.scss";
.nes-container {
padding: 5px;
}
2022-01-05 10:27:40 +01:00
.interact-status {
background-color: #333333;
color: whitesmoke;
2022-01-05 10:27:40 +01:00
position: absolute;
max-height: 2.7em;
width: 40vw;
top: 87vh;
text-align: center;
2022-01-05 10:27:40 +01:00
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
2022-01-05 10:30:27 +01:00
z-index: 400;
}
div.interact-menu {
pointer-events: auto;
background-color: #333333;
color: whitesmoke;
2022-01-05 10:27:40 +01:00
position: absolute;
width: 60vw;
top: 60vh;
2022-01-05 10:27:40 +01:00
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
z-index: 150;
section.interact-menu-title {
margin-bottom: 20px;
display: flex;
justify-content: center;
}
section.interact-menu-question {
margin: 4px;
margin-bottom: 20px;
p {
font-size: 1.05em;
font-weight: bold;
}
}
section.interact-menu-action {
display: grid;
grid-gap: 10%;
grid-template-columns: 45% 45%;
margin-bottom: 20px;
margin-left: 5%;
margin-right: 5%;
}
}
2022-01-05 10:27:40 +01:00
@include media-breakpoint-up(md) {
.interact-status {
width: 90vw;
top: 78vh;
font-size: 0.75em;
}
div.interact-menu {
2022-01-05 10:27:40 +01:00
max-height: 21vh;
width: 90vw;
font-size: 0.75em;
}
}
</style>