Merge pull request #281 from Pax1601/164-add-confirmation-message-when-deleting-a-player

Added (crude) confirm function
This commit is contained in:
Pax1601 2023-05-29 14:38:00 +02:00 committed by GitHub
commit 2db035457c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -97,6 +97,7 @@ function readConfig(config: any) {
}
function setupEvents() {
/* Generic clicks */
document.addEventListener("click", (ev) => {
if (ev instanceof MouseEvent && ev.target instanceof HTMLElement) {

View File

@ -511,7 +511,6 @@ export class Unit extends CustomMarker {
}
delete() {
// TODO: add confirmation popup
deleteUnit(this.ID);
}

View File

@ -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();
}
}
}