2022-01-24 16:27:57 +01:00
|
|
|
<script lang="typescript">
|
2022-02-02 13:30:49 +01:00
|
|
|
import { actionsMenuStore } from "../../Stores/ActionsMenuStore";
|
2022-01-26 10:40:13 +01:00
|
|
|
import { onDestroy } from "svelte";
|
2022-01-25 17:13:52 +01:00
|
|
|
|
|
|
|
import type { Unsubscriber } from "svelte/store";
|
2022-02-02 13:30:49 +01:00
|
|
|
import type { ActionsMenuData } from "../../Stores/ActionsMenuStore";
|
2022-01-24 16:27:57 +01:00
|
|
|
|
2022-01-26 10:40:13 +01:00
|
|
|
let actionsMenuData: ActionsMenuData | undefined;
|
2022-01-25 17:13:52 +01:00
|
|
|
|
|
|
|
let actionsMenuStoreUnsubscriber: Unsubscriber | null;
|
2022-01-24 16:27:57 +01:00
|
|
|
|
|
|
|
function onKeyDown(e: KeyboardEvent) {
|
|
|
|
if (e.key === "Escape") {
|
|
|
|
closeActionsMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeActionsMenu() {
|
2022-01-26 10:40:13 +01:00
|
|
|
actionsMenuStore.clear();
|
2022-01-24 16:27:57 +01:00
|
|
|
}
|
|
|
|
|
2022-02-02 13:30:49 +01:00
|
|
|
actionsMenuStoreUnsubscriber = actionsMenuStore.subscribe((value) => {
|
2022-01-26 10:40:13 +01:00
|
|
|
actionsMenuData = value;
|
2022-01-25 17:13:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
onDestroy(() => {
|
|
|
|
if (actionsMenuStoreUnsubscriber) {
|
|
|
|
actionsMenuStoreUnsubscriber();
|
|
|
|
}
|
|
|
|
});
|
2022-01-24 16:27:57 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<svelte:window on:keydown={onKeyDown} />
|
|
|
|
|
2022-01-26 10:40:13 +01:00
|
|
|
{#if actionsMenuData}
|
|
|
|
<div class="actions-menu nes-container is-rounded">
|
|
|
|
<button type="button" class="nes-btn is-error close" on:click={closeActionsMenu}>×</button>
|
|
|
|
<h2>{actionsMenuData.playerName}</h2>
|
|
|
|
<div class="actions">
|
|
|
|
{#each [...actionsMenuData.actions] as { actionName, callback }}
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="nes-btn"
|
2022-02-02 13:30:49 +01:00
|
|
|
on:click|preventDefault={() => {
|
|
|
|
callback();
|
|
|
|
}}
|
2022-01-26 10:40:13 +01:00
|
|
|
>
|
|
|
|
{actionName}
|
|
|
|
</button>
|
2022-02-02 13:30:49 +01:00
|
|
|
{/each}
|
2022-01-26 10:40:13 +01:00
|
|
|
</div>
|
2022-01-25 15:09:34 +01:00
|
|
|
</div>
|
2022-01-26 10:40:13 +01:00
|
|
|
{/if}
|
2022-01-24 16:27:57 +01:00
|
|
|
|
|
|
|
<style lang="scss">
|
2022-02-02 13:30:49 +01:00
|
|
|
.actions-menu {
|
2022-01-24 16:27:57 +01:00
|
|
|
position: absolute;
|
|
|
|
left: 50%;
|
|
|
|
transform: translate(-50%, 0);
|
2022-01-25 15:09:34 +01:00
|
|
|
width: 260px !important;
|
2022-01-27 16:50:25 +01:00
|
|
|
height: max-content !important;
|
|
|
|
max-height: 40vh;
|
2022-01-24 16:27:57 +01:00
|
|
|
margin-top: 200px;
|
|
|
|
|
|
|
|
pointer-events: auto;
|
|
|
|
font-family: "Press Start 2P";
|
|
|
|
background-color: #333333;
|
|
|
|
color: whitesmoke;
|
|
|
|
|
2022-01-25 15:09:34 +01:00
|
|
|
.actions {
|
2022-01-27 16:50:25 +01:00
|
|
|
max-height: calc(100% - 50px);
|
2022-01-25 15:09:34 +01:00
|
|
|
width: 100%;
|
2022-02-02 13:30:49 +01:00
|
|
|
display: block;
|
|
|
|
overflow-x: hidden;
|
|
|
|
overflow-y: auto;
|
2022-01-25 15:09:34 +01:00
|
|
|
|
|
|
|
button {
|
|
|
|
width: calc(100% - 10px);
|
|
|
|
margin-bottom: 10px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.actions::-webkit-scrollbar {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2022-01-24 16:27:57 +01:00
|
|
|
h2 {
|
|
|
|
text-align: center;
|
|
|
|
margin-bottom: 20px;
|
2022-01-25 15:09:34 +01:00
|
|
|
font-family: "Press Start 2P";
|
2022-01-24 16:27:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.nes-btn.is-error.close {
|
|
|
|
position: absolute;
|
|
|
|
top: -20px;
|
|
|
|
right: -20px;
|
|
|
|
}
|
|
|
|
}
|
2022-02-02 13:30:49 +01:00
|
|
|
</style>
|