mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
More work on context actions
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
}} />
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user