2021-07-12 17:39:16 +02:00
|
|
|
<script lang="typescript">
|
2021-08-09 14:49:17 +02:00
|
|
|
import {fly} from "svelte/transition";
|
|
|
|
import SettingsSubMenu from "./SettingsSubMenu.svelte";
|
|
|
|
import ProfileSubMenu from "./ProfileSubMenu.svelte";
|
2021-08-11 14:07:34 +02:00
|
|
|
import CreateMapSubMenu from "./CreateMapSubMenu.svelte";
|
2021-08-09 14:49:17 +02:00
|
|
|
import AboutRoomSubMenu from "./AboutRoomSubMenu.svelte";
|
2021-08-11 14:07:34 +02:00
|
|
|
import GlobalMessageSubMenu from "./GlobalMessagesSubMenu.svelte";
|
|
|
|
import ContactSubMenu from "./ContactSubMenu.svelte";
|
2021-08-24 17:35:06 +02:00
|
|
|
import CustomSubMenu from "./CustomSubMenu.svelte"
|
|
|
|
import {customMenuIframe, menuVisiblilityStore, SubMenusInterface, subMenusStore} from "../../Stores/MenuStore";
|
2021-08-27 10:34:03 +02:00
|
|
|
import {onDestroy, onMount} from "svelte";
|
|
|
|
import {get, Unsubscriber} from "svelte/store";
|
2021-08-18 11:15:46 +02:00
|
|
|
import {sendMenuClickedEvent} from "../../Api/iframe/Ui/MenuItem";
|
2021-08-11 14:07:34 +02:00
|
|
|
|
|
|
|
let activeSubMenu: string = SubMenusInterface.settings;
|
2021-08-27 10:34:03 +02:00
|
|
|
let activeComponent: typeof SettingsSubMenu | typeof CustomSubMenu = SettingsSubMenu;
|
|
|
|
let props: { url: string, allowApi: boolean };
|
|
|
|
let unsubscriberSubMenuStore: Unsubscriber;
|
2021-08-11 14:07:34 +02:00
|
|
|
|
|
|
|
onMount(() => {
|
2021-08-27 10:34:03 +02:00
|
|
|
unsubscriberSubMenuStore = subMenusStore.subscribe(() => {
|
|
|
|
if(!get(subMenusStore).includes(activeSubMenu)) {
|
|
|
|
switchMenu(SubMenusInterface.settings);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-08-11 14:07:34 +02:00
|
|
|
switchMenu(SubMenusInterface.settings);
|
|
|
|
})
|
2021-07-12 17:39:16 +02:00
|
|
|
|
2021-08-27 10:34:03 +02:00
|
|
|
onDestroy(() => {
|
|
|
|
if(unsubscriberSubMenuStore) {
|
|
|
|
unsubscriberSubMenuStore();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-08-09 14:49:17 +02:00
|
|
|
function switchMenu(menu: string) {
|
2021-08-11 14:07:34 +02:00
|
|
|
if (get(subMenusStore).find((subMenu) => subMenu === menu)) {
|
|
|
|
activeSubMenu = menu;
|
|
|
|
switch (menu) {
|
|
|
|
case SubMenusInterface.settings:
|
|
|
|
activeComponent = SettingsSubMenu;
|
|
|
|
break;
|
|
|
|
case SubMenusInterface.profile:
|
|
|
|
activeComponent = ProfileSubMenu;
|
|
|
|
break;
|
|
|
|
case SubMenusInterface.createMap:
|
|
|
|
activeComponent = CreateMapSubMenu;
|
|
|
|
break;
|
|
|
|
case SubMenusInterface.aboutRoom:
|
|
|
|
activeComponent = AboutRoomSubMenu;
|
|
|
|
break;
|
|
|
|
case SubMenusInterface.globalMessages:
|
|
|
|
activeComponent = GlobalMessageSubMenu;
|
|
|
|
break;
|
|
|
|
case SubMenusInterface.contact:
|
|
|
|
activeComponent = ContactSubMenu;
|
|
|
|
break;
|
|
|
|
default:
|
2021-08-24 17:35:06 +02:00
|
|
|
const customMenu = customMenuIframe.get(menu);
|
|
|
|
if (customMenu !== undefined) {
|
2021-08-27 10:34:03 +02:00
|
|
|
props = { url: customMenu.url, allowApi: customMenu.allowApi };
|
2021-08-24 17:35:06 +02:00
|
|
|
activeComponent = CustomSubMenu;
|
|
|
|
} else {
|
|
|
|
sendMenuClickedEvent(menu);
|
|
|
|
menuVisiblilityStore.set(false);
|
|
|
|
}
|
2021-08-11 14:07:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else throw ("There is no menu called " + menu);
|
2021-07-12 17:39:16 +02:00
|
|
|
}
|
2021-07-13 12:00:09 +02:00
|
|
|
|
2021-08-09 14:49:17 +02:00
|
|
|
function closeMenu() {
|
|
|
|
menuVisiblilityStore.set(false);
|
|
|
|
}
|
|
|
|
function onKeyDown(e:KeyboardEvent) {
|
|
|
|
if (e.key === 'Escape') {
|
|
|
|
closeMenu();
|
|
|
|
}
|
2021-07-13 12:00:09 +02:00
|
|
|
}
|
2021-07-12 17:39:16 +02:00
|
|
|
</script>
|
|
|
|
|
2021-08-09 14:49:17 +02:00
|
|
|
<svelte:window on:keydown={onKeyDown}/>
|
2021-07-12 17:39:16 +02:00
|
|
|
|
2021-08-09 14:49:17 +02:00
|
|
|
|
|
|
|
<div class="menu-container-main">
|
|
|
|
<div class="menu-nav-sidebar nes-container is-rounded" transition:fly="{{ x: -1000, duration: 500 }}">
|
|
|
|
<h2>Menu</h2>
|
2021-07-12 17:39:16 +02:00
|
|
|
<nav>
|
2021-08-11 14:07:34 +02:00
|
|
|
{#each $subMenusStore as submenu}
|
|
|
|
<button type="button" class="nes-btn {activeSubMenu === submenu ? 'is-disabled' : ''}" on:click|preventDefault={() => switchMenu(submenu)}>
|
|
|
|
{submenu}
|
|
|
|
</button>
|
2021-08-09 14:49:17 +02:00
|
|
|
{/each}
|
2021-07-12 17:39:16 +02:00
|
|
|
</nav>
|
2021-08-09 14:49:17 +02:00
|
|
|
</div>
|
|
|
|
<div class="menu-submenu-container nes-container is-rounded" transition:fly="{{ y: -1000, duration: 500 }}">
|
|
|
|
<h2>{activeSubMenu}</h2>
|
2021-08-24 17:35:06 +02:00
|
|
|
<svelte:component this={activeComponent} {...props}/>
|
2021-08-09 14:49:17 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-12 17:39:16 +02:00
|
|
|
|
|
|
|
<style lang="scss">
|
2021-08-09 14:49:17 +02:00
|
|
|
.nes-container {
|
|
|
|
padding: 5px;
|
|
|
|
}
|
2021-07-12 17:39:16 +02:00
|
|
|
|
2021-08-09 14:49:17 +02:00
|
|
|
div.menu-container-main {
|
2021-08-18 15:34:26 +02:00
|
|
|
--size-first-columns-grid: 200px;
|
2021-08-09 14:49:17 +02:00
|
|
|
|
|
|
|
font-family: "Press Start 2P";
|
|
|
|
pointer-events: auto;
|
2021-08-19 11:17:46 +02:00
|
|
|
height: 80vh;
|
2021-08-09 14:49:17 +02:00
|
|
|
width: 75vw;
|
2021-08-18 15:34:26 +02:00
|
|
|
top: 10vh;
|
2021-08-09 14:49:17 +02:00
|
|
|
|
|
|
|
position: relative;
|
|
|
|
margin: auto;
|
|
|
|
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: var(--size-first-columns-grid) calc(100% - var(--size-first-columns-grid));
|
|
|
|
grid-template-rows: 100%;
|
|
|
|
|
|
|
|
h2 {
|
|
|
|
text-align: center;
|
|
|
|
margin-bottom: 20px;
|
2021-07-12 17:39:16 +02:00
|
|
|
}
|
|
|
|
|
2021-08-09 14:49:17 +02:00
|
|
|
div.menu-nav-sidebar {
|
|
|
|
background-color: #333333;
|
|
|
|
color: whitesmoke;
|
|
|
|
|
|
|
|
nav button {
|
|
|
|
width: calc(100% - 10px);
|
|
|
|
margin-bottom: 10px;
|
|
|
|
}
|
2021-07-12 17:39:16 +02:00
|
|
|
}
|
|
|
|
|
2021-08-09 14:49:17 +02:00
|
|
|
div.menu-submenu-container {
|
|
|
|
background-color: #333333;
|
|
|
|
color: whitesmoke;
|
|
|
|
}
|
|
|
|
}
|
2021-08-17 14:44:43 +02:00
|
|
|
|
2021-08-18 15:34:26 +02:00
|
|
|
@media only screen and (max-width: 800px) {
|
2021-08-17 14:44:43 +02:00
|
|
|
div.menu-container-main {
|
2021-08-18 15:34:26 +02:00
|
|
|
--size-first-columns-grid: 120px;
|
2021-08-19 11:17:46 +02:00
|
|
|
height: 70vh;
|
2021-08-18 15:34:26 +02:00
|
|
|
top: 55px;
|
2021-08-17 14:44:43 +02:00
|
|
|
width: 100vw;
|
|
|
|
font-size: 0.5em;
|
|
|
|
}
|
|
|
|
}
|
2021-07-12 17:39:16 +02:00
|
|
|
</style>
|