Controlling panels and spawn menu from context

This commit is contained in:
PeekabooSteam
2023-11-03 22:36:35 +00:00
parent 7e05bbf5e3
commit b1ad2f409e
5 changed files with 94 additions and 4 deletions

View File

@@ -253,6 +253,8 @@ declare module "constants/constants" {
export const MGRS_PRECISION_100M = 4; export const MGRS_PRECISION_100M = 4;
export const MGRS_PRECISION_10M = 5; export const MGRS_PRECISION_10M = 5;
export const MGRS_PRECISION_1M = 6; export const MGRS_PRECISION_1M = 6;
export const DELETE_CYCLE_TIME = 0.05;
export const DELETE_SLOW_THRESHOLD = 50;
} }
declare module "map/markers/custommarker" { declare module "map/markers/custommarker" {
import { Map, Marker } from "leaflet"; import { Map, Marker } from "leaflet";
@@ -303,7 +305,7 @@ declare module "controls/dropdown" {
#private; #private;
constructor(ID: string | null, callback: CallableFunction, options?: string[] | null, defaultText?: string); constructor(ID: string | null, callback: CallableFunction, options?: string[] | null, defaultText?: string);
getContainer(): HTMLElement; getContainer(): HTMLElement;
setOptions(optionsList: string[], sortAlphabetically?: boolean): void; setOptions(optionsList: string[], sort?: "" | "string" | "number"): void;
setOptionsElements(optionsElements: HTMLElement[]): void; setOptionsElements(optionsElements: HTMLElement[]): void;
getOptionElements(): HTMLCollection; getOptionElements(): HTMLCollection;
addOptionElement(optionElement: HTMLElement): void; addOptionElement(optionElement: HTMLElement): void;
@@ -604,6 +606,7 @@ declare module "interfaces" {
export interface ShortcutOptions { export interface ShortcutOptions {
altKey?: boolean; altKey?: boolean;
callback: CallableFunction; callback: CallableFunction;
context?: string;
ctrlKey?: boolean; ctrlKey?: boolean;
name?: string; name?: string;
shiftKey?: boolean; shiftKey?: boolean;
@@ -786,9 +789,11 @@ declare module "controls/unitspawnmenu" {
import { UnitSpawnOptions } from "interfaces"; import { UnitSpawnOptions } from "interfaces";
export class UnitSpawnMenu { export class UnitSpawnMenu {
#private; #private;
spawnOptions: UnitSpawnOptions; protected showRangeCircles: boolean;
protected spawnOptions: UnitSpawnOptions;
constructor(ID: string, unitDatabase: UnitDatabase, orderByRole: boolean); constructor(ID: string, unitDatabase: UnitDatabase, orderByRole: boolean);
getContainer(): HTMLElement; getContainer(): HTMLElement;
getVisible(): boolean;
reset(): void; reset(): void;
setCountries(): void; setCountries(): void;
refreshOptions(): void; refreshOptions(): void;
@@ -824,6 +829,7 @@ declare module "controls/unitspawnmenu" {
deployUnits(spawnOptions: UnitSpawnOptions, unitsCount: number): void; deployUnits(spawnOptions: UnitSpawnOptions, unitsCount: number): void;
} }
export class GroundUnitSpawnMenu extends UnitSpawnMenu { export class GroundUnitSpawnMenu extends UnitSpawnMenu {
protected showRangeCircles: boolean;
/** /**
* *
* @param ID - the ID of the HTML element which will contain the context menu * @param ID - the ID of the HTML element which will contain the context menu
@@ -1331,6 +1337,20 @@ declare module "contextmenus/airbasespawnmenu" {
setAirbase(airbase: Airbase): void; setAirbase(airbase: Airbase): void;
} }
} }
declare module "context/context" {
export interface ContextInterface {
useSpawnMenu?: boolean;
useUnitControlPanel?: boolean;
useUnitInfoPanel?: boolean;
}
export class Context {
#private;
constructor(config: ContextInterface);
getUseSpawnMenu(): boolean;
getUseUnitControlPanel(): boolean;
getUseUnitInfoPanel(): boolean;
}
}
declare module "other/manager" { declare module "other/manager" {
export class Manager { export class Manager {
#private; #private;
@@ -1569,6 +1589,7 @@ declare module "panels/unitinfopanel" {
export class UnitInfoPanel extends Panel { export class UnitInfoPanel extends Panel {
#private; #private;
constructor(ID: string); constructor(ID: string);
show(): void;
} }
} }
declare module "plugin/pluginmanager" { declare module "plugin/pluginmanager" {
@@ -1647,6 +1668,14 @@ declare module "unit/citiesDatabase" {
pop: number; pop: number;
}[]; }[];
} }
declare module "dialog/dialog" {
import { Panel } from "panels/panel";
export class Dialog extends Panel {
constructor(element: string);
hide(): void;
show(): void;
}
}
declare module "unit/unitsmanager" { declare module "unit/unitsmanager" {
import { LatLng, LatLngBounds } from "leaflet"; import { LatLng, LatLngBounds } from "leaflet";
import { Unit } from "unit/unit"; import { Unit } from "unit/unit";
@@ -2094,6 +2123,18 @@ declare module "panels/unitlistpanel" {
toggle(): void; toggle(): void;
} }
} }
declare module "context/contextmanager" {
import { Manager } from "other/manager";
import { ContextInterface } from "context/context";
export class ContextManager extends Manager {
#private;
constructor();
add(name: string, contextConfig: ContextInterface): this;
currentContextIs(contextName: string): boolean;
getCurrentContext(): any;
setContext(contextName: string): false | undefined;
}
}
declare module "olympusapp" { declare module "olympusapp" {
import { Map } from "map/map"; import { Map } from "map/map";
import { MissionManager } from "mission/missionmanager"; import { MissionManager } from "mission/missionmanager";
@@ -2103,10 +2144,15 @@ declare module "olympusapp" {
import { WeaponsManager } from "weapon/weaponsmanager"; import { WeaponsManager } from "weapon/weaponsmanager";
import { Manager } from "other/manager"; import { Manager } from "other/manager";
import { ServerManager } from "server/servermanager"; import { ServerManager } from "server/servermanager";
import { ContextManager } from "context/contextmanager";
import { Context } from "context/context";
export class OlympusApp { export class OlympusApp {
#private; #private;
constructor(); constructor();
getDialogManager(): Manager;
getMap(): Map; getMap(): Map;
getCurrentContext(): Context;
getContextManager(): ContextManager;
getServerManager(): ServerManager; getServerManager(): ServerManager;
getPanelsManager(): Manager; getPanelsManager(): Manager;
getPopupsManager(): Manager; getPopupsManager(): Manager;
@@ -2158,3 +2204,11 @@ declare module "index" {
import { OlympusApp } from "olympusapp"; import { OlympusApp } from "olympusapp";
export function getApp(): OlympusApp; export function getApp(): OlympusApp;
} }
declare module "context/contextmenumanager" {
import { ContextMenu } from "contextmenus/contextmenu";
import { Manager } from "other/manager";
export class ContextMenuManager extends Manager {
constructor();
add(name: string, contextMenu: ContextMenu): this;
}
}

View File

@@ -1,11 +1,31 @@
export interface ContextInterface { export interface ContextInterface {
useSpawnMenu?: boolean;
useUnitControlPanel?: boolean;
useUnitInfoPanel?: boolean;
} }
export class Context { export class Context {
constructor( config:ContextInterface ) { #useSpawnMenu:boolean;
#useUnitControlPanel:boolean;
#useUnitInfoPanel:boolean;
constructor( config:ContextInterface ) {
this.#useSpawnMenu = ( config.useSpawnMenu !== false );
this.#useUnitControlPanel = ( config.useUnitControlPanel !== false );
this.#useUnitInfoPanel = ( config.useUnitInfoPanel !== false );
}
getUseSpawnMenu() {
return this.#useSpawnMenu;
}
getUseUnitControlPanel() {
return this.#useUnitControlPanel;
}
getUseUnitInfoPanel() {
return this.#useUnitInfoPanel;
} }
} }

View File

@@ -99,6 +99,9 @@ export class MapContextMenu extends ContextMenu {
* @param latlng Leaflet latlng object of the mouse click * @param latlng Leaflet latlng object of the mouse click
*/ */
show(x: number, y: number, latlng: LatLng) { show(x: number, y: number, latlng: LatLng) {
if (!getApp().getCurrentContext().getUseSpawnMenu())
return false;
super.show(x, y, latlng); super.show(x, y, latlng);
this.#aircraftSpawnMenu.setLatLng(latlng); this.#aircraftSpawnMenu.setLatLng(latlng);

View File

@@ -131,6 +131,10 @@ export class UnitControlPanel extends Panel {
} }
show() { show() {
const context = getApp().getCurrentContext();
if ( !context.getUseUnitControlPanel() )
return;
super.show(); super.show();
this.#speedTypeSwitch.resetExpectedValue(); this.#speedTypeSwitch.resetExpectedValue();
this.#altitudeTypeSwitch.resetExpectedValue(); this.#altitudeTypeSwitch.resetExpectedValue();

View File

@@ -1,3 +1,4 @@
import { getApp } from "..";
import { Ammo } from "../interfaces"; import { Ammo } from "../interfaces";
import { aircraftDatabase } from "../unit/databases/aircraftdatabase"; import { aircraftDatabase } from "../unit/databases/aircraftdatabase";
import { Unit } from "../unit/unit"; import { Unit } from "../unit/unit";
@@ -92,4 +93,12 @@ export class UnitInfoPanel extends Panel {
else else
this.hide(); this.hide();
} }
show() {
const context = getApp().getCurrentContext();
if ( !context.getUseUnitInfoPanel() )
return;
super.show();
}
} }