From 1691b0b30c4bf950c5826cfd90543b3faf666288 Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Wed, 18 Oct 2023 12:13:51 +0100 Subject: [PATCH] Range rings only showing when necessary --- client/src/contextmenus/mapcontextmenu.ts | 6 ++++-- client/src/controls/unitspawnmenu.ts | 14 +++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/client/src/contextmenus/mapcontextmenu.ts b/client/src/contextmenus/mapcontextmenu.ts index 34ce3a80..f7924fcd 100644 --- a/client/src/contextmenus/mapcontextmenu.ts +++ b/client/src/contextmenus/mapcontextmenu.ts @@ -18,6 +18,7 @@ export class MapContextMenu extends ContextMenu { #groundUnitSpawnMenu: GroundUnitSpawnMenu; #navyUnitSpawnMenu: NavyUnitSpawnMenu; #coalitionArea: CoalitionArea | null = null; + #selectedUnitCategory: string = ""; /** * @@ -39,9 +40,10 @@ export class MapContextMenu extends ContextMenu { /* Event listeners */ document.addEventListener("mapContextMenuShow", (e: any) => { - if (this.getVisibleSubMenu() !== e.detail.type) + if (this.getVisibleSubMenu() !== e.detail.type) { this.#showSubMenu(e.detail.type); - else + this.#selectedUnitCategory = e.detail.type; + } else this.#hideSubMenus(e.detail.type); }); diff --git a/client/src/controls/unitspawnmenu.ts b/client/src/controls/unitspawnmenu.ts index 37787c1f..0115add5 100644 --- a/client/src/controls/unitspawnmenu.ts +++ b/client/src/controls/unitspawnmenu.ts @@ -50,6 +50,7 @@ export class UnitSpawnMenu { /* Range circle previews */ #engagementCircle: Circle; #acquisitionCircle: Circle; + protected showRangeCircles: boolean = false; constructor(ID: string, unitDatabase: UnitDatabase, orderByRole: boolean) { this.#container = document.getElementById(ID) as HTMLElement; @@ -244,6 +245,10 @@ export class UnitSpawnMenu { return this.#container; } + getVisible() { + return !this.getContainer().classList.contains( "hide" ); + } + reset() { this.#deployUnitButtonEl.disabled = true; this.#unitRoleTypeDropdown.reset(); @@ -286,11 +291,15 @@ export class UnitSpawnMenu { showCirclesPreviews() { this.clearCirclesPreviews(); + + if ( !this.showRangeCircles || this.spawnOptions.name === "" || !this.getVisible() ) { + return; + } var acquisitionRange = this.#unitDatabase.getByName(this.spawnOptions.name)?.acquisitionRange ?? 0; var engagementRange = this.#unitDatabase.getByName(this.spawnOptions.name)?.engagementRange ?? 0; - if ( engagementRange === 0 && acquisitionRange === 0 ) { + if ( acquisitionRange === 0 && engagementRange === 0 ) { return; } @@ -576,6 +585,9 @@ export class HelicopterSpawnMenu extends UnitSpawnMenu { } export class GroundUnitSpawnMenu extends UnitSpawnMenu { + + protected showRangeCircles: boolean = true; + /** * * @param ID - the ID of the HTML element which will contain the context menu