Actions menu api (#1862)
* wip * wip * random action on click * removing actions * register single key per command use * change removeActionsMenu action name * fixed actions menu not hiding content properly: * actions menu fix * added mock Block Player action * ActionsMenu buttons styling * added displaying priority for menu actions * moved utils actionMenu features to the UI * import as a type: * more object oriented style for API * removed registered actions from RemotePlayer instance * readme update * Fixing typos / Improving wording * added instructions on AlterActionsMenu test map Co-authored-by: Hanusiak Piotr <piotr@ltmp.co> Co-authored-by: David Négrier <d.negrier@thecodingmachine.com>
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
import { actionsMenuStore } from "../../Stores/ActionsMenuStore";
|
||||
import { onDestroy } from "svelte";
|
||||
|
||||
import type { ActionsMenuAction } from "../../Stores/ActionsMenuStore";
|
||||
import type { Unsubscriber } from "svelte/store";
|
||||
import type { ActionsMenuData } from "../../Stores/ActionsMenuStore";
|
||||
|
||||
let actionsMenuData: ActionsMenuData | undefined;
|
||||
let sortedActions: ActionsMenuAction[] | undefined;
|
||||
|
||||
let actionsMenuStoreUnsubscriber: Unsubscriber | null;
|
||||
|
||||
@@ -21,6 +23,20 @@
|
||||
|
||||
actionsMenuStoreUnsubscriber = actionsMenuStore.subscribe((value) => {
|
||||
actionsMenuData = value;
|
||||
if (actionsMenuData) {
|
||||
sortedActions = [...actionsMenuData.actions.values()].sort((a, b) => {
|
||||
const ap = a.priority ?? 0;
|
||||
const bp = b.priority ?? 0;
|
||||
if (ap > bp) {
|
||||
return -1;
|
||||
}
|
||||
if (ap < bp) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
@@ -37,15 +53,15 @@
|
||||
<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 }}
|
||||
{#each sortedActions ?? [] as action}
|
||||
<button
|
||||
type="button"
|
||||
class="nes-btn"
|
||||
class="nes-btn {action.style ?? ''}"
|
||||
on:click|preventDefault={() => {
|
||||
callback();
|
||||
action.callback();
|
||||
}}
|
||||
>
|
||||
{actionName}
|
||||
{action.actionName}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -68,7 +84,7 @@
|
||||
color: whitesmoke;
|
||||
|
||||
.actions {
|
||||
max-height: calc(100% - 50px);
|
||||
max-height: 30vh;
|
||||
width: 100%;
|
||||
display: block;
|
||||
overflow-x: hidden;
|
||||
|
||||
Reference in New Issue
Block a user