feat: implemented map toolbar

This commit is contained in:
Davide Passoni
2024-12-10 16:58:51 +01:00
parent 3d204af60f
commit 8f00e8a9e2
15 changed files with 491 additions and 277 deletions

View File

@@ -836,6 +836,9 @@ export abstract class Unit extends CustomMarker {
contextActionSet.addContextAction(this, ContextActions.PATH);
contextActionSet.addContextAction(this, ContextActions.DELETE);
contextActionSet.addContextAction(this, ContextActions.EXPLODE);
contextActionSet.addContextAction(this, ContextActions.CENTER_MAP);
contextActionSet.addContextAction(this, ContextActions.CLONE);
contextActionSet.addContextAction(this, ContextActions.ATTACK);
contextActionSet.addDefaultContextAction(this, ContextActions.MOVE);
}
@@ -1357,16 +1360,18 @@ export abstract class Unit extends CustomMarker {
this.#debounceTimeout = window.setTimeout(() => {
console.log(`Left short click on ${this.getUnitName()}`);
if (!e.originalEvent.ctrlKey) getApp().getUnitsManager().deselectAllUnits();
this.setSelected(!this.getSelected());
if (getApp().getState() === OlympusState.UNIT_CONTROL && getApp().getMap().getContextAction()) {
if (getApp().getMap().getContextAction()?.getTarget() === ContextActionTarget.UNIT) getApp().getMap().executeContextAction(this, null, e.originalEvent);
else getApp().getMap().executeContextAction(null, this.getPosition(), e.originalEvent);
} else {
if (!e.originalEvent.ctrlKey) getApp().getUnitsManager().deselectAllUnits();
this.setSelected(!this.getSelected());
}
}, SHORT_PRESS_MILLISECONDS);
}
#onRightShortClick(e: any) {
console.log(`Right short click on ${this.getUnitName()}`);
if (getApp().getState() === OlympusState.UNIT_CONTROL && getApp().getMap().getContextAction()?.getTarget() === ContextActionTarget.UNIT)
getApp().getMap().executeContextAction(this, null, e.originalEvent);
}
#onRightLongClick(e: any) {
@@ -1848,7 +1853,7 @@ export abstract class AirUnit extends Unit {
showAmmo: belongsToCommandedCoalition,
showSummary: belongsToCommandedCoalition || this.getDetectionMethods().some((value) => [VISUAL, OPTIC, RADAR, IRST, DLINK].includes(value)),
showCallsign: belongsToCommandedCoalition && (!getApp().getMap().getOptions().AWACSMode || this.getHuman()),
rotateToHeading: false
rotateToHeading: false,
} as ObjectIconOptions;
}
@@ -1857,10 +1862,8 @@ export abstract class AirUnit extends Unit {
/* Context actions to be executed immediately */
contextActionSet.addContextAction(this, ContextActions.REFUEL);
contextActionSet.addContextAction(this, ContextActions.CENTER_MAP);
/* Context actions that require a target unit */
contextActionSet.addContextAction(this, ContextActions.ATTACK);
contextActionSet.addContextAction(this, ContextActions.FOLLOW);
contextActionSet.addContextAction(this, ContextActions.SET_AWACS_REFERENCE);
@@ -1946,10 +1949,6 @@ export class GroundUnit extends Unit {
/* Context actions to be executed immediately */
contextActionSet.addContextAction(this, ContextActions.GROUP);
contextActionSet.addContextAction(this, ContextActions.CENTER_MAP);
/* Context actions that require a target unit */
contextActionSet.addContextAction(this, ContextActions.ATTACK);
/* Context actions that require a target position */
if (this.canTargetPoint()) {
@@ -2015,10 +2014,6 @@ export class NavyUnit extends Unit {
/* Context actions to be executed immediately */
contextActionSet.addContextAction(this, ContextActions.GROUP);
contextActionSet.addContextAction(this, ContextActions.CENTER_MAP);
/* Context actions that require a target unit */
contextActionSet.addContextAction(this, ContextActions.ATTACK);
/* Context actions that require a target position */
contextActionSet.addContextAction(this, ContextActions.FIRE_AT_AREA);

View File

@@ -17,6 +17,7 @@ import {
AWACSReferenceChangedEvent,
CommandModeOptionsChangedEvent,
ContactsUpdatedEvent,
CopiedUnitsEvents,
HotgroupsChangedEvent,
SelectedUnitsChangedEvent,
SelectionClearedEvent,
@@ -1234,6 +1235,8 @@ export class UnitsManager {
)
); /* Can be applied to humans too */
getApp().addInfoMessage(`${this.#copiedUnits.length} units copied`);
CopiedUnitsEvents.dispatch(this.#copiedUnits)
}
/*********************** Unit manipulation functions ************************/
@@ -1241,7 +1244,7 @@ export class UnitsManager {
*
* @returns True if units were pasted successfully
*/
paste() {
paste(location?: LatLng) {
let spawnPoints = 0;
/* If spawns are restricted, check that the user has the necessary spawn points */
@@ -1285,7 +1288,10 @@ export class UnitsManager {
var units: { ID: number; location: LatLng }[] = [];
let markers: TemporaryUnitMarker[] = [];
groups[groupName].forEach((unit: UnitData) => {
var position = new LatLng(
var position = location ? new LatLng(
location.lat + unit.position.lat - avgLat,
location.lng + unit.position.lng - avgLng
) : new LatLng(
getApp().getMap().getMouseCoordinates().lat + unit.position.lat - avgLat,
getApp().getMap().getMouseCoordinates().lng + unit.position.lng - avgLng
);