import React, { useCallback, useEffect, useState } from "react"; import { OlDropdown, OlDropdownItem } from "../components/oldropdown"; import { getApp } from "../../olympusapp"; import { colors, NO_SUBSTATE, OlympusState, OlympusSubState, SpawnSubState } from "../../constants/constants"; import { OlStateButton } from "../components/olstatebutton"; import { faArrowLeft, faSmog } from "@fortawesome/free-solid-svg-icons"; import { LatLng } from "leaflet"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { AppStateChangedEvent } from "../../events"; import { FaQuestionCircle } from "react-icons/fa"; export function EffectSpawnMenu(props: { visible: boolean; compact: boolean; effect: string | null; latlng?: LatLng | null; onBack?: () => void }) { const [appState, setAppState] = useState(OlympusState.NOT_INITIALIZED); const [appSubState, setAppSubState] = useState(NO_SUBSTATE as OlympusSubState); const [explosionType, setExplosionType] = useState("High explosive"); const [smokeColor, setSmokeColor] = useState("white"); useEffect(() => { AppStateChangedEvent.on((state, subState) => { setAppState(state); setAppSubState(subState); }); }, []); /* When the menu is opened show the effect preview on the map as a cursor */ const updateEffectRequestTable = useCallback(() => { if (!props.compact) { if (props.effect !== null) { if (props.effect === "explosion") getApp()?.getMap()?.setEffectRequestTable({ type: props.effect, explosionType, }); else if (props.effect === "smoke") { let colorName = "white"; if (smokeColor === colors.BLUE) colorName = "blue"; else if (smokeColor === colors.RED) colorName = "red"; else if (smokeColor === colors.GREEN) colorName = "green"; else if (smokeColor === colors.ORANGE) colorName = "orange"; getApp()?.getMap()?.setEffectRequestTable({ type: props.effect, smokeColor: colorName, }); } getApp().setState(OlympusState.SPAWN, SpawnSubState.SPAWN_EFFECT); } else { if (appState === OlympusState.SPAWN && appSubState === SpawnSubState.SPAWN_EFFECT) getApp().setState(OlympusState.IDLE); } } }, [props.visible, explosionType, smokeColor, props.effect]); useEffect(updateEffectRequestTable, [props.visible, explosionType, smokeColor]); return ( <> {props.visible ? ( <>
{props.effect === "explosion" && ( <>
{props.compact && ( )} Explosion type
{["High explosive", "Napalm", "White phosphorous", "Fire"].map((optionExplosionType) => { return ( { setExplosionType(optionExplosionType); }} > {optionExplosionType} ); })}
Click on the map to generate an explosion effect. The type of explosion will be the one selected above. The possible explosion effects are:
  • High explosive: a normal explosion, like the one from a conventional bomb;
  • Napalm: an explosion with a longer lasting fire effect;
  • White phosphorous: an explosion with multiple white flares ejecting from the blast;
  • Fire: a long lasting static fire.
  • )} {props.effect === "smoke" && ( <>
    {props.compact && ( )} Smoke color
    {[colors.WHITE, colors.BLUE, colors.RED, colors.GREEN, colors.ORANGE].map((optionSmokeColor) => { return ( { setSmokeColor(optionSmokeColor); }} tooltip="" buttonColor={optionSmokeColor} /> ); })}
    Click on the map to generate a colored smoke effect. The color of the smoke will be the one selected above.
    )} {props.compact && ( )}
    ) : ( <> )} ); }