diff --git a/client/src/index.ts b/client/src/index.ts index c2f8a1b6..8d57b546 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -97,6 +97,7 @@ function readConfig(config: any) { } function setupEvents() { + /* Generic clicks */ document.addEventListener("click", (ev) => { if (ev instanceof MouseEvent && ev.target instanceof HTMLElement) { diff --git a/client/src/units/unit.ts b/client/src/units/unit.ts index d54034a7..d2c70b46 100644 --- a/client/src/units/unit.ts +++ b/client/src/units/unit.ts @@ -511,7 +511,6 @@ export class Unit extends CustomMarker { } delete() { - // TODO: add confirmation popup deleteUnit(this.ID); } diff --git a/client/src/units/unitsmanager.ts b/client/src/units/unitsmanager.ts index 07f5ac9c..95fbb744 100644 --- a/client/src/units/unitsmanager.ts +++ b/client/src/units/unitsmanager.ts @@ -20,7 +20,7 @@ export class UnitsManager { document.addEventListener('paste', () => this.pasteUnits()); document.addEventListener('unitSelection', (e: CustomEvent) => this.#onUnitSelection(e.detail)); document.addEventListener('unitDeselection', (e: CustomEvent) => this.#onUnitDeselection(e.detail)); - document.addEventListener('keydown', (event) => this.#onKeyDown(event)); + document.addEventListener('keyup', (event) => this.#onKeyUp(event)); document.addEventListener('deleteSelectedUnits', () => this.selectedUnitsDelete()) } @@ -426,9 +426,18 @@ export class UnitsManager { } /***********************************************/ - #onKeyDown(event: KeyboardEvent) { - if (!keyEventWasInInput(event) && event.key === "Delete") { - this.selectedUnitsDelete(); + #onKeyUp(event: KeyboardEvent) { + if (!keyEventWasInInput(event) && event.key === "Delete" ) { + + const selectedUnits = this.getSelectedUnits(); + const selectionContainsAHuman = selectedUnits.some( ( unit:Unit ) => { + return unit.getMissionData().flags.Human === true; + }); + + if ( !selectionContainsAHuman || confirm( "Your selection includes a human player. Deleting humans causes their vehicle to crash.\n\nAre you sure you want to do this?" ) ) { + this.selectedUnitsDelete(); + } + } }