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:
@@ -99,7 +99,7 @@ export class Map extends L.Map {
|
|||||||
#bradcastPositionXmlHttp: XMLHttpRequest | null = null;
|
#bradcastPositionXmlHttp: XMLHttpRequest | null = null;
|
||||||
#cameraZoomRatio: number = 1.0;
|
#cameraZoomRatio: number = 1.0;
|
||||||
|
|
||||||
#contextAction: null | ContextAction = null;
|
#contextAction: null | ContextAction = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -324,7 +324,7 @@ export class Map extends L.Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* State machine */
|
/* State machine */
|
||||||
setState(state: string, options?: { spawnRequestTable?: SpawnRequestTable, contextAction?: ContextAction }) {
|
setState(state: string, options?: { spawnRequestTable?: SpawnRequestTable, contextAction?: ContextAction | null }) {
|
||||||
this.#state = state;
|
this.#state = state;
|
||||||
|
|
||||||
/* Operations to perform if you are NOT in a state */
|
/* Operations to perform if you are NOT in a state */
|
||||||
@@ -333,7 +333,9 @@ export class Map extends L.Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Operations to perform if you ARE in a state */
|
/* Operations to perform if you ARE in a state */
|
||||||
if (this.#state === SPAWN_UNIT) {
|
if (this.#state === IDLE) {
|
||||||
|
getApp().getUnitsManager().deselectAllUnits();
|
||||||
|
} else if (this.#state === SPAWN_UNIT) {
|
||||||
this.#spawnRequestTable = options?.spawnRequestTable ?? null;
|
this.#spawnRequestTable = options?.spawnRequestTable ?? null;
|
||||||
this.#spawnCursor?.removeFrom(this);
|
this.#spawnCursor?.removeFrom(this);
|
||||||
this.#spawnCursor = new TemporaryUnitMarker(new L.LatLng(0, 0), this.#spawnRequestTable?.unit.unitType ?? "unknown", this.#spawnRequestTable?.coalition ?? 'blue');
|
this.#spawnCursor = new TemporaryUnitMarker(new L.LatLng(0, 0), this.#spawnRequestTable?.unit.unitType ?? "unknown", this.#spawnRequestTable?.coalition ?? 'blue');
|
||||||
@@ -648,6 +650,10 @@ export class Map extends L.Map {
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
executeContextAction(targetUnit: Unit | null, targetPosition: L.LatLng | null) {
|
||||||
|
this.#contextAction?.executeCallback(targetUnit, targetPosition);
|
||||||
|
}
|
||||||
|
|
||||||
/* Event handlers */
|
/* Event handlers */
|
||||||
#onClick(e: any) {
|
#onClick(e: any) {
|
||||||
if (!this.#preventLeftClick) {
|
if (!this.#preventLeftClick) {
|
||||||
@@ -678,6 +684,8 @@ export class Map extends L.Map {
|
|||||||
else {
|
else {
|
||||||
this.deselectAllCoalitionAreas();
|
this.deselectAllCoalitionAreas();
|
||||||
}
|
}
|
||||||
|
} else if (this.#state === CONTEXT_ACTION) {
|
||||||
|
this.executeContextAction(null, e.latlng);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.setState(IDLE);
|
this.setState(IDLE);
|
||||||
@@ -687,7 +695,7 @@ export class Map extends L.Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#onDoubleClick(e: any) {
|
#onDoubleClick(e: any) {
|
||||||
|
this.setState(IDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#onContextMenu(e: any) {
|
#onContextMenu(e: any) {
|
||||||
@@ -729,10 +737,6 @@ export class Map extends L.Map {
|
|||||||
this.#computeDestinationRotation = false;
|
this.#computeDestinationRotation = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (this.#state === CONTEXT_ACTION) {
|
|
||||||
if (this.#contextAction)
|
|
||||||
this.#contextAction.executeCallback(null, e.latlng);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
this.setState(IDLE);
|
this.setState(IDLE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ export class ServerManager {
|
|||||||
callback(res);
|
callback(res);
|
||||||
};
|
};
|
||||||
xmlHttp.send(JSON.stringify(request));
|
xmlHttp.send(JSON.stringify(request));
|
||||||
|
console.log(`Sending PUT request:`);
|
||||||
|
console.log(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
getConfig(callback: CallableFunction) {
|
getConfig(callback: CallableFunction) {
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Unit } from '../../unit/unit';
|
import { Unit } from '../../unit/unit';
|
||||||
import { ContextActionSet } from '../../unit/contextactionset';
|
import { ContextActionSet } from '../../unit/contextactionset';
|
||||||
import { OlStateButton } from '../components/olstatebutton';
|
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 { getApp } from '../../olympusapp';
|
||||||
import { ContextAction } from '../../unit/contextaction';
|
import { ContextAction } from '../../unit/contextaction';
|
||||||
import { CONTEXT_ACTION } from '../../constants/constants';
|
import { CONTEXT_ACTION } from '../../constants/constants';
|
||||||
import { FaInfoCircle, FaQuestionCircle } from 'react-icons/fa';
|
import { FaInfoCircle } from 'react-icons/fa';
|
||||||
|
|
||||||
export function UnitMouseControlBar(props: {
|
export function UnitMouseControlBar(props: {
|
||||||
|
|
||||||
@@ -38,6 +36,12 @@ export function UnitMouseControlBar(props: {
|
|||||||
updateData();
|
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 */
|
/* Update the current values of the shown data */
|
||||||
function updateData() {
|
function updateData() {
|
||||||
var newContextActionSet = new ContextActionSet();
|
var newContextActionSet = new ContextActionSet();
|
||||||
@@ -52,7 +56,7 @@ export function UnitMouseControlBar(props: {
|
|||||||
|
|
||||||
return <> {
|
return <> {
|
||||||
open && <>
|
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) => {
|
Object.values(contextActionsSet.getContextActions()).map((contextAction) => {
|
||||||
return <OlStateButton checked={contextAction === activeContextAction} icon={contextAction.getIcon()} tooltip={contextAction.getLabel()} onClick={() => {
|
return <OlStateButton checked={contextAction === activeContextAction} icon={contextAction.getIcon()} tooltip={contextAction.getLabel()} onClick={() => {
|
||||||
@@ -60,8 +64,13 @@ export function UnitMouseControlBar(props: {
|
|||||||
setActiveContextAction(null);
|
setActiveContextAction(null);
|
||||||
contextAction.executeCallback(null, null);
|
contextAction.executeCallback(null, null);
|
||||||
} else {
|
} else {
|
||||||
setActiveContextAction(contextAction);
|
if (activeContextAction != contextAction) {
|
||||||
getApp().getMap().setState(CONTEXT_ACTION, { contextAction: contextAction });
|
setActiveContextAction(contextAction);
|
||||||
|
getApp().getMap().setState(CONTEXT_ACTION, { contextAction: contextAction });
|
||||||
|
} else {
|
||||||
|
setActiveContextAction(null);
|
||||||
|
getApp().getMap().setState(CONTEXT_ACTION, { contextAction: null });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}} />
|
}} />
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { CustomMarker } from '../map/markers/custommarker';
|
|||||||
import { SVGInjector } from '@tanem/svg-injector';
|
import { SVGInjector } from '@tanem/svg-injector';
|
||||||
import { UnitDatabase } from './databases/unitdatabase';
|
import { UnitDatabase } from './databases/unitdatabase';
|
||||||
import { TargetMarker } from '../map/markers/targetmarker';
|
import { TargetMarker } from '../map/markers/targetmarker';
|
||||||
import { DLINK, DataIndexes, GAME_MASTER, IDLE, IRST, MOVE_UNIT, OPTIC, RADAR, ROEs, RWR, VISUAL, emissionsCountermeasures, reactionsToThreat, states, GROUPING_ZOOM_TRANSITION, MAX_SHOTS_SCATTER, SHOTS_SCATTER_DEGREES, GROUND_UNIT_AIR_DEFENCE_REGEX } from '../constants/constants';
|
import { DLINK, DataIndexes, GAME_MASTER, IDLE, IRST, MOVE_UNIT, OPTIC, RADAR, ROEs, RWR, VISUAL, emissionsCountermeasures, reactionsToThreat, states, GROUPING_ZOOM_TRANSITION, MAX_SHOTS_SCATTER, SHOTS_SCATTER_DEGREES, GROUND_UNIT_AIR_DEFENCE_REGEX, CONTEXT_ACTION } from '../constants/constants';
|
||||||
import { DataExtractor } from '../server/dataextractor';
|
import { DataExtractor } from '../server/dataextractor';
|
||||||
import { groundUnitDatabase } from './databases/groundunitdatabase';
|
import { groundUnitDatabase } from './databases/groundunitdatabase';
|
||||||
import { navyUnitDatabase } from './databases/navyunitdatabase';
|
import { navyUnitDatabase } from './databases/navyunitdatabase';
|
||||||
@@ -1065,6 +1065,8 @@ export abstract class Unit extends CustomMarker {
|
|||||||
getApp().getUnitsManager().deselectAllUnits();
|
getApp().getUnitsManager().deselectAllUnits();
|
||||||
|
|
||||||
this.setSelected(!this.getSelected());
|
this.setSelected(!this.getSelected());
|
||||||
|
} else if (getApp().getMap().getState() === CONTEXT_ACTION) {
|
||||||
|
getApp().getMap().executeContextAction(this, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user