From 16b5e89a3eee5f9c8faf75ff45bc15ff4ed772b1 Mon Sep 17 00:00:00 2001 From: dpassoni Date: Tue, 14 Mar 2023 17:30:16 +0100 Subject: [PATCH] Added code to show spawn menu from airbase spawn --- client/src/controls/airbasecontextmenu.ts | 17 +++++++++-- client/src/controls/contextmenu.ts | 10 ++++++ client/src/controls/mapcontextmenu.ts | 37 +++++++++++++++-------- client/views/contextmenus.ejs | 2 +- 4 files changed, 51 insertions(+), 15 deletions(-) diff --git a/client/src/controls/airbasecontextmenu.ts b/client/src/controls/airbasecontextmenu.ts index 96cd7255..d88603d3 100644 --- a/client/src/controls/airbasecontextmenu.ts +++ b/client/src/controls/airbasecontextmenu.ts @@ -1,4 +1,4 @@ -import { getUnitsManager } from ".."; +import { getMap, getUnitsManager, setActiveCoalition } from ".."; import { Airbase } from "../missionhandler/airbase"; import { ContextMenu } from "./contextmenu"; @@ -8,6 +8,9 @@ export class AirbaseContextMenu extends ContextMenu { constructor(id: string) { super(id); + document.addEventListener("contextMenuSpawnAirbase", (e: any) => { + this.showSpawnMenu(); + }) } setAirbase(airbase: Airbase) @@ -53,6 +56,16 @@ export class AirbaseContextMenu extends ContextMenu { enableLandButton(enableLandButton: boolean) { this.getContainer()?.querySelector("#land-here-button")?.classList.toggle("hide", !enableLandButton); - + } + + showSpawnMenu() + { + if (this.#airbase != null) + { + setActiveCoalition(this.#airbase.getCoalition()); + getMap().showMapContextMenu({originalEvent: {x: this.getX(), y: this.getY(), latlng: this.getLatLng()}}); + getMap().getMapContextMenu().hideUpperBar(); + getMap().getMapContextMenu().showSubMenu("aircraft"); + } } } \ No newline at end of file diff --git a/client/src/controls/contextmenu.ts b/client/src/controls/contextmenu.ts index b0a5e913..4f8db9ae 100644 --- a/client/src/controls/contextmenu.ts +++ b/client/src/controls/contextmenu.ts @@ -33,6 +33,16 @@ export class ContextMenu { return this.#latlng; } + getX() + { + return this.#x; + } + + getY() + { + return this.#y; + } + clip() { if (this.#container != null) { diff --git a/client/src/controls/mapcontextmenu.ts b/client/src/controls/mapcontextmenu.ts index 1879b576..1723dc22 100644 --- a/client/src/controls/mapcontextmenu.ts +++ b/client/src/controls/mapcontextmenu.ts @@ -34,18 +34,7 @@ export class MapContextMenu extends ContextMenu { this.#groundUnitTypeDropdown = new Dropdown("ground-unit-type-options", (type: string) => this.#setGroundUnitType(type)); document.addEventListener("contextMenuShow", (e: any) => { - this.getContainer()?.querySelector("#aircraft-spawn-menu")?.classList.toggle("hide", e.detail.type !== "aircraft"); - this.getContainer()?.querySelector("#aircraft-spawn-button")?.classList.toggle("is-open", e.detail.type === "aircraft"); - this.getContainer()?.querySelector("#ground-unit-spawn-menu")?.classList.toggle("hide", e.detail.type !== "ground-unit"); - this.getContainer()?.querySelector("#ground-unit-spawn-button")?.classList.toggle("is-open", e.detail.type === "ground-unit"); - this.getContainer()?.querySelector("#smoke-spawn-menu")?.classList.toggle("hide", e.detail.type !== "smoke"); - this.getContainer()?.querySelector("#smoke-spawn-button")?.classList.toggle("is-open", e.detail.type === "smoke"); - - this.#resetAircraftRole(); - this.#resetAircraftType(); - this.#resetGroundUnitRole(); - this.#resetGroundUnitType(); - this.clip(); + this.showSubMenu(e.detail.type); }) document.addEventListener("contextMenuDeployAircraft", () => { @@ -68,6 +57,30 @@ export class MapContextMenu extends ContextMenu { show(x: number, y: number, latlng: LatLng) { super.show(x, y, latlng); this.#spawnOptions.latlng = latlng; + this.showUpperBar(); + } + + showSubMenu(type: string){ + this.getContainer()?.querySelector("#aircraft-spawn-menu")?.classList.toggle("hide", type !== "aircraft"); + this.getContainer()?.querySelector("#aircraft-spawn-button")?.classList.toggle("is-open", type === "aircraft"); + this.getContainer()?.querySelector("#ground-unit-spawn-menu")?.classList.toggle("hide", type !== "ground-unit"); + this.getContainer()?.querySelector("#ground-unit-spawn-button")?.classList.toggle("is-open", type === "ground-unit"); + this.getContainer()?.querySelector("#smoke-spawn-menu")?.classList.toggle("hide", type !== "smoke"); + this.getContainer()?.querySelector("#smoke-spawn-button")?.classList.toggle("is-open", type === "smoke"); + + this.#resetAircraftRole(); + this.#resetAircraftType(); + this.#resetGroundUnitRole(); + this.#resetGroundUnitType(); + this.clip(); + } + + showUpperBar() { + this.getContainer()?.querySelector("#upper-bar")?.classList.toggle("hide", false); + } + + hideUpperBar() { + this.getContainer()?.querySelector("#upper-bar")?.classList.toggle("hide", true); } #onSwitch(e: any) { diff --git a/client/views/contextmenus.ejs b/client/views/contextmenus.ejs index 4fde3221..8160a5c0 100644 --- a/client/views/contextmenus.ejs +++ b/client/views/contextmenus.ejs @@ -1,6 +1,6 @@
-
+