More work on context actions

This commit is contained in:
Davide Passoni
2024-06-27 17:35:10 +02:00
parent 222a296b4f
commit 8cb8f7e108
4 changed files with 33 additions and 16 deletions

View File

@@ -1,13 +1,11 @@
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import { Unit } from '../../unit/unit';
import { ContextActionSet } from '../../unit/contextactionset';
import { OlStateButton } from '../components/olstatebutton';
import { faAccessibleIcon } from '@fortawesome/free-brands-svg-icons';
import { faCamera } from '@fortawesome/free-solid-svg-icons';
import { getApp } from '../../olympusapp';
import { ContextAction } from '../../unit/contextaction';
import { CONTEXT_ACTION } from '../../constants/constants';
import { FaInfoCircle, FaQuestionCircle } from 'react-icons/fa';
import { FaInfoCircle } from 'react-icons/fa';
export function UnitMouseControlBar(props: {
@@ -38,6 +36,12 @@ export function UnitMouseControlBar(props: {
updateData();
})
/* Deselect the context action when exiting state */
document.addEventListener("mapStateChanged", (ev) => {
setOpen(ev.detail === CONTEXT_ACTION);
})
/* Update the current values of the shown data */
function updateData() {
var newContextActionSet = new ContextActionSet();
@@ -52,7 +56,7 @@ export function UnitMouseControlBar(props: {
return <> {
open && <>
<div className='flex gap-2 rounded-md absolute top-20 left-[50%] translate-x-[-50%] bg-gray-200 dark:bg-olympus-900 z-ui-1 p-2'>
<div className='flex gap-2 rounded-md absolute top-20 left-[50%] translate-x-[-50%] bg-gray-200 dark:bg-olympus-900 z-ui-2 p-2'>
{
Object.values(contextActionsSet.getContextActions()).map((contextAction) => {
return <OlStateButton checked={contextAction === activeContextAction} icon={contextAction.getIcon()} tooltip={contextAction.getLabel()} onClick={() => {
@@ -60,8 +64,13 @@ export function UnitMouseControlBar(props: {
setActiveContextAction(null);
contextAction.executeCallback(null, null);
} else {
setActiveContextAction(contextAction);
getApp().getMap().setState(CONTEXT_ACTION, { contextAction: contextAction });
if (activeContextAction != contextAction) {
setActiveContextAction(contextAction);
getApp().getMap().setState(CONTEXT_ACTION, { contextAction: contextAction });
} else {
setActiveContextAction(null);
getApp().getMap().setState(CONTEXT_ACTION, { contextAction: null });
}
}
}} />
})