ROE and reaction to threat buttons are now updated to reflect the state of the selected units

This commit is contained in:
dpassoni 2023-03-21 10:32:11 +01:00
parent e8a476e1c7
commit 79d8ca260a
2 changed files with 16 additions and 26 deletions

View File

@ -11,7 +11,7 @@ const DEMO_UNIT_DATA = {
},
flightData: {
latitude: 37.20,
longitude: -115.8,
longitude: -115.80,
altitude: 2000,
heading: 0.5,
speed: 300
@ -52,8 +52,8 @@ const DEMO_UNIT_DATA = {
targetAltitude: 3000
},
optionsData: {
ROE: "None",
reactionToThreat: "None",
ROE: "Designated",
reactionToThreat: "Abort",
}
},
["2"]:{
@ -95,8 +95,8 @@ const DEMO_UNIT_DATA = {
targetAltitude: 3000
},
optionsData: {
ROE: "None",
reactionToThreat: "None",
ROE: "Designated",
reactionToThreat: "Abort",
}
},
["3"]:{

View File

@ -3,6 +3,7 @@ import { Slider } from "../controls/slider";
import { aircraftDatabase } from "../units/aircraftdatabase";
import { groundUnitsDatabase } from "../units/groundunitsdatabase";
import { Aircraft, GroundUnit, Unit } from "../units/unit";
import { UnitsManager } from "../units/unitsmanager";
import { Panel } from "./panel";
const ROEs: string[] = ["Free", "Designated free", "Designated", "Return", "Hold"];
@ -28,42 +29,31 @@ export class UnitControlPanel extends Panel {
this.#optionButtons["ROE"] = ROEs.map((option: string, index:number) => {
var button = document.createElement("button");
button.title = option;
if ( index === 0 ) {
button.classList.add( "selected" );
}
button.addEventListener("click", () => {
this.getElement().querySelector("#roe-buttons-container button.selected")?.classList.remove( "selected" );
button.classList.add( "selected" );
getUnitsManager().selectedUnitsSetROE(button.title);
});
button.value = option;
button.addEventListener("click", () => {getUnitsManager().selectedUnitsSetROE(button.title);});
return button;
});
this.#optionButtons["reactionToThreat"] = reactionsToThreat.map((option: string, index:number) => {
var button = document.createElement("button");
button.title = option;
if ( index === 0 ) {
button.classList.add( "selected" );
}
button.addEventListener("click", () => {
this.getElement().querySelector("#reaction-to-threat-buttons-container button.selected")?.classList.remove( "selected" );
button.classList.add( "selected" );
getUnitsManager().selectedUnitsSetROE(button.title);
});
button.value = option;
button.addEventListener("click", () => {getUnitsManager().selectedUnitsSetROE(button.title);});
return button;
});
this.getElement().querySelector("#roe-buttons-container")?.append(...this.#optionButtons["ROE"]);
this.getElement().querySelector("#reaction-to-threat-buttons-container")?.append(...this.#optionButtons["reactionToThreat"]);
document.addEventListener("unitsSelection", (e: CustomEvent<Unit[]>) => {this.show(); this.update(e.detail)});
document.addEventListener("unitUpdated", (e: CustomEvent<Unit>) => {if (e.detail.getSelected()) this.update()});
document.addEventListener("unitsSelection", (e: CustomEvent<Unit[]>) => {this.show(); this.update()});
document.addEventListener("clearSelection", () => {this.hide()});
this.hide();
}
update(units: Unit[]) {
update() {
var units = getUnitsManager().getSelectedUnits();
if (this.getElement() != null && units.length > 0)
{
this.#showFlightControlSliders(units);
@ -87,11 +77,11 @@ export class UnitControlPanel extends Panel {
}));
this.#optionButtons["ROE"].forEach((button: HTMLButtonElement) => {
button.classList.toggle("active", units.every((unit: Unit) => unit.getOptionsData().ROE === button.value))
button.classList.toggle("selected", units.every((unit: Unit) => unit.getOptionsData().ROE === button.value))
});
this.#optionButtons["reactionToThreat"].forEach((button: HTMLButtonElement) => {
button.classList.toggle("active", units.every((unit: Unit) => unit.getOptionsData().reactionToThreat === button.value))
button.classList.toggle("selected", units.every((unit: Unit) => unit.getOptionsData().reactionToThreat === button.value))
});
}
}