Temp commit for hotfix

This commit is contained in:
dpassoni 2023-03-14 15:51:23 +01:00
parent d3dc041c91
commit fa9945a3cc
7 changed files with 84 additions and 38 deletions

View File

@ -1,9 +1,42 @@
import { ContextMenu } from "./contextmenu";
export class AirbaseContextMenu extends ContextMenu {
#airbaseName: string | null = null;
constructor(id: string)
{
super(id);
}
setAirbaseName(airbaseName: string)
{
this.#airbaseName = airbaseName;
var nameDiv = <HTMLElement>this.getContainer()?.querySelector("#airbase-name");
if (nameDiv != null)
nameDiv.innerText = airbaseName;
}
setAirbaseProperties(airbaseProperties: string[])
{
this.getContainer()?.querySelector("#airbase-properties")?.replaceChildren(...airbaseProperties.map((property: string) => {
var div = document.createElement("div");
div.innerText = property;
return div;
}));
}
setAirbaseParkings(airbaseParkings: string[])
{
this.getContainer()?.querySelector("#airbase-parking")?.replaceChildren(...airbaseParkings.map((parking: string) => {
var div = document.createElement("div");
div.innerText = parking;
return div;
}));
}
enableLandButton(enableLandButton: boolean)
{
this.getContainer()?.querySelector("#land-here-button")?.classList.toggle("hide", !enableLandButton);
}
}

View File

@ -151,11 +151,16 @@ export class Map extends L.Map {
this.#unitContextMenu.hide();
}
showAirbaseContextMenu(e: any) {
showAirbaseContextMenu(e: any, airbaseName: string, airbaseProperties: string[], airbaseParkings: string[], enableLandButton: boolean, airbaseCoalition: string) {
this.hideAllContextMenus();
var x = e.originalEvent.x;
var y = e.originalEvent.y;
this.#airbaseContextMenu.show(x, y, e.latlng);
this.#airbaseContextMenu.setAirbaseName(airbaseName);
this.#airbaseContextMenu.setAirbaseProperties(airbaseProperties);
this.#airbaseContextMenu.setAirbaseParkings(airbaseParkings);
this.#airbaseContextMenu.enableLandButton(enableLandButton);
this.#airbaseContextMenu.setCoalition(airbaseCoalition);
}
getAirbaseContextMenu(){

View File

@ -34,13 +34,13 @@ export class Airbase extends L.Marker
(<HTMLElement> this.getElement()?.querySelector(".airbase")).dataset.coalition = this.#coalition;
}
getName()
{
return this.#name;
}
getCoalition()
{
return this.#coalition;
}
getName()
{
return this.#name;
}
}

View File

@ -78,27 +78,7 @@ export class MissionHandler
#onAirbaseClick(e: any)
{
var options = [];
if (getUnitsManager().getSelectedUnits().length > 0)
options = ["Spawn unit", "Land here"];
else
options = ["Spawn unit"];
getMap().showAirbaseContextMenu(e);
//getMap().showContextMenu(e.originalEvent, e.sourceTarget.getName(),
// options.map((option) => {return {tooltip: option, src: "", callback: (label: string) => {this.#onAirbaseOptionSelection(e, label)}}}, false)
//)
}
#onAirbaseOptionSelection(e: any, option: string) {
//if (option === "Spawn unit") {
// var spawnEvent: SpawnEvent = {x: e.originalEvent.x, y: e.originalEvent.y, latlng: e.latlng, airbaseName: e.sourceTarget.getName(), coalitionID: e.sourceTarget.getCoalitionID()};
// getMap().spawnFromAirbase(spawnEvent);
//}
//else if (option === "Land here")
//{
// getMap().hideContextMenu();
// getUnitsManager().selectedUnitsLandAt(e.latlng);
//}
var enableLandHere = getUnitsManager().getSelectedUnitsType() === "Aircraft" && (getUnitsManager().getSelectedUnitsCoalition() === e.sourceTarget.getCoalition() || e.sourceTarget.getActiveCoalition === "neutral");
getMap().showAirbaseContextMenu(e, e.sourceTarget.getName(), ["test1", "tes2"], ["2x small", "3x large"], enableLandHere, e.sourceTarget.getActiveCoalition);
}
}

View File

@ -1,4 +1,4 @@
import { getMissionData, getUnitsManager } from "..";
import { getUnitsManager } from "..";
import { Slider } from "../controls/slider";
import { Unit } from "../units/unit";
import { Panel } from "./panel";
@ -96,14 +96,21 @@ export class UnitControlPanel extends Panel {
var targetAltitude = getUnitsManager().getSelectedUnitsTargetAltitude();
var targetSpeed = getUnitsManager().getSelectedUnitsTargetSpeed();
if (["GroundUnit", "NavyUnit"].includes(unitsType))
this.#altitudeSlider.hide()
if (unitsType != undefined && targetAltitude != undefined && targetSpeed != undefined)
{
if (["GroundUnit", "NavyUnit"].includes(unitsType))
this.#altitudeSlider.hide()
this.#airspeedSlider.setMinMax(minSpeedValues[unitsType], maxSpeedValues[unitsType]);
this.#altitudeSlider.setMinMax(minAltitudeValues[unitsType], maxAltitudeValues[unitsType]);
this.#airspeedSlider.setActive(targetSpeed != undefined);
this.#airspeedSlider.setValue(targetSpeed * 1.94384);
this.#altitudeSlider.setActive(targetAltitude != undefined);
this.#altitudeSlider.setValue(targetAltitude / 0.3048);
this.#airspeedSlider.setMinMax(minSpeedValues[unitsType], maxSpeedValues[unitsType]);
this.#altitudeSlider.setMinMax(minAltitudeValues[unitsType], maxAltitudeValues[unitsType]);
this.#airspeedSlider.setActive(true);
this.#airspeedSlider.setValue(targetSpeed * 1.94384);
this.#altitudeSlider.setActive(true);
this.#altitudeSlider.setValue(targetAltitude / 0.3048);
}
else {
this.#airspeedSlider.setActive(false);
this.#altitudeSlider.setActive(false);
}
}
}

View File

@ -128,6 +128,8 @@ export class UnitsManager {
}
getSelectedUnitsType () {
if (this.getSelectedUnits().length == 0)
return undefined;
return this.getSelectedUnits().map((unit: Unit) => {
return unit.constructor.name
})?.reduce((a: any, b: any) => {
@ -136,6 +138,8 @@ export class UnitsManager {
};
getSelectedUnitsTargetSpeed () {
if (this.getSelectedUnits().length == 0)
return undefined;
return this.getSelectedUnits().map((unit: Unit) => {
return unit.getTaskData().targetSpeed
})?.reduce((a: any, b: any) => {
@ -144,6 +148,8 @@ export class UnitsManager {
};
getSelectedUnitsTargetAltitude () {
if (this.getSelectedUnits().length == 0)
return undefined;
return this.getSelectedUnits().map((unit: Unit) => {
return unit.getTaskData().targetAltitude
})?.reduce((a: any, b: any) => {
@ -151,6 +157,16 @@ export class UnitsManager {
});
};
getSelectedUnitsCoalition () {
if (this.getSelectedUnits().length == 0)
return undefined;
return this.getSelectedUnits().map((unit: Unit) => {
return unit.getMissionData().coalition
})?.reduce((a: any, b: any) => {
return a == b? a: undefined
});
};
selectedUnitsAddDestination(latlng: L.LatLng) {
var selectedUnits = this.getSelectedUnits();
for (let idx in selectedUnits) {

View File

@ -80,5 +80,10 @@
</div>
<div id="airbase-contextmenu" class="ol-panel">
<h3 id="airbase-name"></h3>
<div id="airbase-properties"></div>
<h4>Parking available:</4>
<div id="airbase-parking"></div>
<button id="spawn-airbase-aircraft-button" data-active-coalition="blue" title="Spawn aircraft" data-on-click="contextMenuSpawnAirbase" class="deploy-unit-button">Spawn</button>
<button id="land-here-button" title="Land here" data-on-click="contextMenuLandAirbase">Land here</button>
</div>