From 633d20da62e4072df6e418c28df7c5022b972e3c Mon Sep 17 00:00:00 2001 From: HunterBarclay Date: Fri, 11 Oct 2024 12:07:08 -0600 Subject: [PATCH] fix: Readd delete controls to buttons WIP!: Currently not working for removing input schemes from deleted robots. --- fission/src/mirabuf/MirabufSceneObject.ts | 4 +- .../synthesis_brain/SynthesisBrain.ts | 8 +++- .../initial-config/InitialConfigPanel.tsx | 38 +++++++++++++++++-- .../initial-config/InputSchemeSelection.tsx | 1 + 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/fission/src/mirabuf/MirabufSceneObject.ts b/fission/src/mirabuf/MirabufSceneObject.ts index 0b62699e6..13725e913 100644 --- a/fission/src/mirabuf/MirabufSceneObject.ts +++ b/fission/src/mirabuf/MirabufSceneObject.ts @@ -244,7 +244,9 @@ class MirabufSceneObject extends SceneObject { this._debugBodies?.clear() this._physicsLayerReserve?.Release() - if (this._brain && this._brain instanceof SynthesisBrain) this._brain?.clearControls() + if (this._brain && this._brain instanceof SynthesisBrain) { + this._brain.clearControls() + } } public Eject() { diff --git a/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts b/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts index c98225cf5..4fc9511f5 100644 --- a/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts +++ b/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts @@ -18,6 +18,7 @@ import PreferencesSystem from "@/systems/preferences/PreferencesSystem" import { DefaultSequentialConfig } from "@/systems/preferences/PreferenceTypes" import InputSystem from "@/systems/input/InputSystem" import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" +import { Global_AddToast } from "@/ui/components/GlobalUIControls" class SynthesisBrain extends Brain { public static brainIndexMap = new Map() @@ -94,7 +95,12 @@ class SynthesisBrain extends Brain { } public clearControls(): void { - InputSystem.brainIndexSchemeMap.delete(this._brainIndex) + if (InputSystem.brainIndexSchemeMap.delete(this._brainIndex)) { + Global_AddToast?.("info", "Controls", "Successfully cleared controls.") + } else { + Global_AddToast?.("warning", "Controls", "Failed to cleared controls.") + } + } /** Creates an instance of ArcadeDriveBehavior and automatically configures it. */ diff --git a/fission/src/ui/panels/configuring/initial-config/InitialConfigPanel.tsx b/fission/src/ui/panels/configuring/initial-config/InitialConfigPanel.tsx index de3465cd7..84e4dd30b 100644 --- a/fission/src/ui/panels/configuring/initial-config/InitialConfigPanel.tsx +++ b/fission/src/ui/panels/configuring/initial-config/InitialConfigPanel.tsx @@ -5,7 +5,7 @@ import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain" import { SynthesisIcons } from "@/ui/components/StyledComponents" import { useModalControlContext } from "@/ui/ModalContext" import { usePanelControlContext } from "@/ui/PanelContext" -import { useEffect, useMemo } from "react" +import { useCallback, useEffect, useMemo } from "react" import { ConfigurationType, setSelectedConfigurationType } from "../assembly-config/ConfigurationType" import { setSelectedScheme } from "../assembly-config/interfaces/inputs/ConfigureInputsInterface" import InputSchemeSelection from "./InputSchemeSelection" @@ -56,6 +56,33 @@ const InitialConfigPanel: React.FC = ({ panelId }) => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [targetAssembly]) + const closeFinish = useCallback(() => { + if (targetAssembly?.miraType == MiraType.ROBOT) { + const brainIndex = SynthesisBrain.GetBrainIndex(targetAssembly) + + if (brainIndex == undefined) return + + if (InputSystem.brainIndexSchemeMap.has(brainIndex)) return + + const scheme = InputSchemeManager.availableInputSchemes[0] + + InputSystem.brainIndexSchemeMap.set(brainIndex, scheme) + + setSelectedConfigurationType(ConfigurationType.INPUTS) + setSelectedScheme(scheme) + } + + closePanel(panelId) + }, [closePanel, panelId, targetAssembly]) + + const closeDelete = useCallback(() => { + if (targetAssembly) { + World.SceneRenderer.RemoveSceneObject(targetAssembly.id) + } + + closePanel(panelId) + }, [closePanel, panelId, targetAssembly]) + const brainIndex = useMemo(() => { return SynthesisBrain.GetBrainIndex(targetAssembly) }, [targetAssembly]) @@ -66,10 +93,13 @@ const InitialConfigPanel: React.FC = ({ panelId }) => { panelId={panelId} openLocation={"right"} sidePadding={8} - acceptEnabled={false} + acceptEnabled={true} + acceptName="Finish" + onAccept={() => closeFinish()} icon={SynthesisIcons.Gamepad} cancelEnabled={true} - cancelName="Close" + cancelName="Delete" + onCancel={() => closeDelete()} > {/** A scroll view with buttons to select default and custom input schemes */}
@@ -87,7 +117,7 @@ const InitialConfigPanel: React.FC = ({ panelId }) => { {brainIndex != undefined ? ( closePanel(panelId)} + onSelect={() => {}} onEdit={() => openPanel("configure")} onCreateNew={() => openModal("assign-new-scheme")} /> diff --git a/fission/src/ui/panels/configuring/initial-config/InputSchemeSelection.tsx b/fission/src/ui/panels/configuring/initial-config/InputSchemeSelection.tsx index 0d34f5a13..8543e3387 100644 --- a/fission/src/ui/panels/configuring/initial-config/InputSchemeSelection.tsx +++ b/fission/src/ui/panels/configuring/initial-config/InputSchemeSelection.tsx @@ -56,6 +56,7 @@ function InputSchemeSelection({ brainIndex, onSelect, onEdit, onCreateNew }: Inp {SelectButton(() => { InputSystem.brainIndexSchemeMap.set(brainIndex, scheme) onSelect?.() + update() })} {/** Edit button - same as select but opens the inputs modal */} {EditButton(() => {