Added ability to hide spawn menu

This commit is contained in:
Davide Passoni
2024-07-05 12:12:21 +02:00
parent fa48d1f905
commit 61e52efc07
11 changed files with 74 additions and 57 deletions

View File

@@ -763,13 +763,8 @@ export class Map extends L.Map {
if (this.#state === IDLE) { if (this.#state === IDLE) {
this.deselectAllCoalitionAreas(); this.deselectAllCoalitionAreas();
} else if (this.#state === MOVE_UNIT) { } else if (this.#state === MOVE_UNIT) {
getApp().getUnitsManager().clearDestinations(); getApp().getUnitsManager().clearDestinations();
getApp() getApp().getUnitsManager().addDestination(e.latlng, false, 0);
.getUnitsManager()
.addDestination(e.latlng,
false,
0
);
} else if (this.#state === SPAWN_UNIT) { } else if (this.#state === SPAWN_UNIT) {
if (this.#spawnRequestTable !== null) { if (this.#spawnRequestTable !== null) {
const location = e.latlng; const location = e.latlng;
@@ -821,9 +816,7 @@ export class Map extends L.Map {
this.setState(IDLE); this.setState(IDLE);
} }
#onContextMenu(e: any) { #onContextMenu(e: any) {}
}
#onSelectionStart(e: any) { #onSelectionStart(e: any) {
this.#selecting = true; this.#selecting = true;
@@ -841,9 +834,7 @@ export class Map extends L.Map {
this.#updateCursor(); this.#updateCursor();
} }
#onMouseDown(e: any) { #onMouseDown(e: any) {}
}
#onMouseMove(e: any) { #onMouseMove(e: any) {
this.#lastMousePosition.x = e.originalEvent.x; this.#lastMousePosition.x = e.originalEvent.x;

View File

@@ -11,7 +11,7 @@ export function OlLabelToggle(props: {
onClick={props.onClick} onClick={props.onClick}
className={` className={`
relative flex h-10 w-[120px] flex-none cursor-pointer select-none relative flex h-10 w-[120px] flex-none cursor-pointer select-none
flex-row justify-between rounded-md border border px-1 py-[5px] text-sm flex-row justify-between rounded-md border px-1 py-[5px] text-sm
contents-center contents-center
dark:border-gray-600 dark:border-transparent dark:bg-gray-700 dark:border-gray-600 dark:border-transparent dark:bg-gray-700
dark:hover:bg-gray-600 dark:focus:ring-blue-800 dark:hover:bg-gray-600 dark:focus:ring-blue-800
@@ -33,7 +33,6 @@ export function OlLabelToggle(props: {
className={` className={`
my-auto pl-3 font-normal transition-colors z-ui-2 my-auto pl-3 font-normal transition-colors z-ui-2
dark:data-[active='false']:text-gray-400 dark:data-[active='false']:text-gray-400
dark:data-[active='false']:text-gray-400
dark:data-[active='true']:text-white dark:data-[active='true']:text-white
`} `}
> >

View File

@@ -13,7 +13,6 @@ import { OlTooltip } from "./oltooltip";
export function OlStateButton(props: { export function OlStateButton(props: {
className?: string; className?: string;
checked: boolean; checked: boolean;
highlighted?: boolean;
icon: IconProp; icon: IconProp;
tooltip: string; tooltip: string;
onClick: () => void; onClick: () => void;
@@ -26,8 +25,6 @@ export function OlStateButton(props: {
` `
h-[40px] w-[40px] flex-none rounded-md text-lg font-medium h-[40px] w-[40px] flex-none rounded-md text-lg font-medium
dark:bg-olympus-600 dark:text-gray-300 dark:hover:bg-olympus-300 dark:bg-olympus-600 dark:text-gray-300 dark:hover:bg-olympus-300
dark:data-[highlighted='true']:border-[2px]
dark:data-[highlighted='true']:border-blue-800
dark:data-[checked='true']:bg-blue-500 dark:data-[checked='true']:bg-blue-500
dark:data-[checked='true']:text-white dark:data-[checked='true']:text-white
`; `;
@@ -41,7 +38,6 @@ export function OlStateButton(props: {
setHover(false); setHover(false);
}} }}
data-checked={props.checked} data-checked={props.checked}
data-highlighted={props.highlighted ?? false}
type="button" type="button"
className={className} className={className}
onMouseEnter={() => { onMouseEnter={() => {
@@ -61,7 +57,6 @@ export function OlStateButton(props: {
export function OlRoundStateButton(props: { export function OlRoundStateButton(props: {
className?: string; className?: string;
checked: boolean; checked: boolean;
highlighted?: boolean;
icon: IconProp; icon: IconProp;
tooltip: string; tooltip: string;
onClick: () => void; onClick: () => void;

View File

@@ -1,57 +1,78 @@
import { faArrowLeft, faClose } from "@fortawesome/free-solid-svg-icons"; import { faArrowLeft, faClose } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import React from "react"; import React, { useState } from "react";
import { FaChevronDown, FaChevronUp } from "react-icons/fa";
export function Menu(props: { export function Menu(props: {
title: string; title: string;
open: boolean; open: boolean;
onClose: () => void; onClose: () => void;
canBeHidden?: boolean;
onBack?: () => void; onBack?: () => void;
showBackButton?: boolean; showBackButton?: boolean;
children?: JSX.Element | JSX.Element[]; children?: JSX.Element | JSX.Element[];
}) { }) {
const [hide, setHide] = useState(true);
if (!props.open && hide) setHide(false);
return ( return (
<div <div
data-open={props.open} data-open={props.open}
data-hide={hide}
className={` className={`
absolute left-16 right-0 top-[58px] bg-gray-200 backdrop-grayscale absolute left-16 right-0 top-[58px] bg-gray-200 backdrop-grayscale
z-ui-3 h-screen overflow-y-auto backdrop-blur-lg transition-transform z-ui-3 h-[calc(100vh-58px)] backdrop-blur-lg transition-transform
dark:bg-olympus-800/90 dark:bg-olympus-800/90
data-[hide='true']:-translate-y-[calc(100vh-1.5rem-58px)]
data-[open='false']:-translate-x-full data-[open='false']:-translate-x-full
sm:w-[400px] sm:w-[400px]
`} `}
tabIndex={-1} tabIndex={-1}
> >
<h5 <div className={`
className={` h-[calc(100vh-58px-1.5rem)] overflow-y-auto overflow-x-hidden
inline-flex w-full items-center px-5 py-3 pb-2 font-semibold `}>
text-gray-800 shadow-lg <h5
dark:text-gray-400 className={`
`} inline-flex w-full items-center px-5 py-3 pb-2 font-semibold
> text-gray-800 shadow-lg
{props.showBackButton && ( dark:text-gray-400
`}
>
{props.showBackButton && (
<FontAwesomeIcon
onClick={props.onBack ?? (() => {})}
icon={faArrowLeft}
className={`
mr-1 cursor-pointer rounded-md p-2
dark:text-gray-500 dark:hover:bg-gray-700 dark:hover:text-white
`}
/>
)}{" "}
{props.title}
<FontAwesomeIcon <FontAwesomeIcon
onClick={props.onBack ?? (() => {})} onClick={props.onClose}
icon={faArrowLeft} icon={faClose}
className={` className={`
mr-1 cursor-pointer rounded-md p-2 ml-auto flex cursor-pointer items-center justify-center rounded-md
p-2 text-lg
dark:text-gray-500 dark:hover:bg-gray-700 dark:hover:text-white dark:text-gray-500 dark:hover:bg-gray-700 dark:hover:text-white
hover:bg-gray-200
`} `}
/> />
)}{" "} </h5>
{props.title} {props.children}
<FontAwesomeIcon </div>
onClick={props.onClose} {props.canBeHidden == true && (
icon={faClose} <div className="flex h-6 justify-center" onClick={() => setHide(!hide)}>
className={` {hide ? (
ml-auto flex cursor-pointer items-center justify-center rounded-md <FaChevronDown className="mx-auto my-auto text-gray-400" />
p-2 text-lg ) : (
dark:text-gray-500 dark:hover:bg-gray-700 dark:hover:text-white <FaChevronUp className="mx-auto my-auto text-gray-400" />
hover:bg-gray-200 )}
`} </div>
/> )}
</h5>
{props.children}
</div> </div>
); );
} }

View File

@@ -39,7 +39,7 @@ export function Header() {
<nav <nav
className={` className={`
flex w-full gap-4 border-gray-200 bg-gray-300 px-3 flex w-full gap-4 border-gray-200 bg-gray-300 px-3
drop-shadow-md z-ui-2 align-center drop-shadow-md z-ui-4 align-center
dark:border-gray-800 dark:bg-olympus-900 dark:border-gray-800 dark:bg-olympus-900
`} `}
> >

View File

@@ -72,7 +72,7 @@ export function MiniMapPanel(props: {}) {
onClick={() => setShowMissionTime(!showMissionTime)} onClick={() => setShowMissionTime(!showMissionTime)}
className={` className={`
absolute right-[10px] absolute right-[10px]
${showMinimap ? `top-[232px]` : `top-[70px]`} ${showMinimap ? `top-[232px]` : `top-[90px]`}
w-[288px] z-ui-0 flex items-center justify-between w-[288px] z-ui-0 flex items-center justify-between
${showMinimap ? `rounded-b-lg` : `rounded-lg`} ${showMinimap ? `rounded-b-lg` : `rounded-lg`}
bg-gray-200 p-3 text-sm backdrop-blur-lg backdrop-grayscale bg-gray-200 p-3 text-sm backdrop-blur-lg backdrop-grayscale
@@ -114,13 +114,13 @@ export function MiniMapPanel(props: {}) {
onClick={() => { onClick={() => {
getApp().getMap().setOption("showMinimap", false); getApp().getMap().setOption("showMinimap", false);
}} }}
></FaChevronUp> />
) : ( ) : (
<FaChevronDown <FaChevronDown
onClick={() => { onClick={() => {
getApp().getMap().setOption("showMinimap", true); getApp().getMap().setOption("showMinimap", true);
}} }}
></FaChevronDown> />
)} )}
</div> </div>
); );

View File

@@ -52,7 +52,6 @@ export function SideBar() {
checked={appState.spawnMenuVisible} checked={appState.spawnMenuVisible}
icon={faPlusSquare} icon={faPlusSquare}
tooltip="Hide/show unit spawn menu" tooltip="Hide/show unit spawn menu"
highlighted={mapState === SPAWN_UNIT}
></OlStateButton> ></OlStateButton>
<OlStateButton <OlStateButton
onClick={events.toggleUnitControlMenuVisible} onClick={events.toggleUnitControlMenuVisible}

View File

@@ -15,7 +15,7 @@ import {
olButtonsVisibilityHelicopter, olButtonsVisibilityHelicopter,
olButtonsVisibilityNavyunit, olButtonsVisibilityNavyunit,
} from "../components/olicons"; } from "../components/olicons";
import { IDLE } from "../../constants/constants"; import { IDLE, SPAWN_UNIT } from "../../constants/constants";
library.add(faPlus); library.add(faPlus);
@@ -75,11 +75,19 @@ export function SpawnMenu(props: {
filteredAirDefense = filterUnits(filteredAirDefense, filterString); filteredAirDefense = filterUnits(filteredAirDefense, filterString);
filteredGroundUnits = filterUnits(filteredGroundUnits, filterString); filteredGroundUnits = filterUnits(filteredGroundUnits, filterString);
if (!props.open) {
if (getApp()?.getMap()?.getState() === SPAWN_UNIT)
getApp().getMap().setState(IDLE);
if (blueprint !== null)
setBlueprint(null);
}
return ( return (
<Menu <Menu
{...props} {...props}
title="Spawn menu" title="Spawn menu"
showBackButton={blueprint !== null} showBackButton={blueprint !== null}
canBeHidden={true}
onBack={() => { onBack={() => {
getApp().getMap().setState(IDLE); getApp().getMap().setState(IDLE);
setBlueprint(null); setBlueprint(null);

View File

@@ -36,7 +36,8 @@ import { Coalition } from "../../types/types";
import { ftToM, knotsToMs, mToFt, msToKnots } from "../../other/utils"; import { ftToM, knotsToMs, mToFt, msToKnots } from "../../other/utils";
export function UnitControlMenu(props: { export function UnitControlMenu(props: {
open: boolean open: boolean;
onClose: () => void;
}) { }) {
var [selectedUnits, setSelectedUnits] = useState([] as Unit[]); var [selectedUnits, setSelectedUnits] = useState([] as Unit[]);
@@ -184,7 +185,7 @@ export function UnitControlMenu(props: {
getApp()?.getUnitsManager()?.getSelectedUnitsCategories() ?? []; getApp()?.getUnitsManager()?.getSelectedUnitsCategories() ?? [];
return ( return (
<Menu open={props.open} title="Units selected (x)" onClose={() => {}}> <Menu open={props.open} title="Units selected (x)" onClose={props.onClose}>
{/* Units list */} {/* Units list */}
<div <div
className={` className={`

View File

@@ -54,7 +54,7 @@ export function UnitSpawnMenu(props: { blueprint: UnitBlueprint }) {
}); });
} else { } else {
if (getApp()?.getMap()?.getState() === SPAWN_UNIT) if (getApp()?.getMap()?.getState() === SPAWN_UNIT)
getApp()?.getMap()?.setState(IDLE); getApp().getMap().setState(IDLE);
} }
}); });

View File

@@ -224,7 +224,10 @@ export function UI() {
options={mapOptions} options={mapOptions}
/> />
<MiniMapPanel /> <MiniMapPanel />
<UnitControlMenu open={unitControlMenuVisible} /> <UnitControlMenu
open={unitControlMenuVisible}
onClose={() => setUnitControlMenuVisible(false)}
/>
<div id="map-container" className="h-full w-screen" /> <div id="map-container" className="h-full w-screen" />
<UnitMouseControlBar /> <UnitMouseControlBar />
</div> </div>