Skip to content

Commit

Permalink
fix: Repair broken changes from the merge
Browse files Browse the repository at this point in the history
Camera controls, context menu, and transform gizmos are now integrated.
  • Loading branch information
HunterBarclay committed Nov 10, 2024
1 parent ad6cb23 commit 9f72176
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 52 deletions.
3 changes: 3 additions & 0 deletions fission/src/mirabuf/MirabufSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { CustomOrbitControls } from "@/systems/scene/CameraControls"
import GizmoSceneObject from "@/systems/scene/GizmoSceneObject"
import { ConfigMode, setNextConfigurePanelSettings } from "@/ui/panels/configuring/assembly-config/ConfigurePanelControls"
import { Global_OpenPanel } from "@/ui/components/GlobalUIControls"
import { ConfigurationType, setSelectedConfigurationType } from "@/ui/panels/configuring/assembly-config/ConfigurationType"

const DEBUG_BODIES = false

Expand Down Expand Up @@ -484,10 +485,12 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
data.items.push({
name: "Move",
func: () => {
setSelectedConfigurationType(this.miraType == MiraType.ROBOT ? ConfigurationType.ROBOT : ConfigurationType.FIELD)
setNextConfigurePanelSettings({
configMode: ConfigMode.MOVE,
selectedAssembly: this
})
Global_OpenPanel?.("configure")
},
})

Expand Down
3 changes: 2 additions & 1 deletion fission/src/systems/scene/CameraControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export class CustomOrbitControls extends CameraControls {
public update(deltaT: number): void {
deltaT = Math.max(1.0 / 60.0, Math.min(1 / 144.0, deltaT))

this._focusProvider?.LoadFocusTransform(this._focus)
if (this.enabled)
this._focusProvider?.LoadFocusTransform(this._focus)

// Generate delta of spherical coordinates
const omega: SphericalCoords = this.enabled
Expand Down
2 changes: 1 addition & 1 deletion fission/src/systems/scene/GizmoSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class GizmoSceneObject extends SceneObject {
this._gizmo.addEventListener("dragging-changed", (event: { target: TransformControls; value: unknown }) => {
// disable orbit controls when dragging the transform gizmo
const gizmoDragging = World.SceneRenderer.IsAnyGizmoDragging()
World.SceneRenderer.orbitControls.enabled = !event.value && !gizmoDragging
World.SceneRenderer.currentCameraControls.enabled = !event.value && !gizmoDragging

const isShift = InputSystem.isKeyPressed("ShiftRight") || InputSystem.isKeyPressed("ShiftLeft")
const isAlt = InputSystem.isKeyPressed("AltRight") || InputSystem.isKeyPressed("AltLeft")
Expand Down
15 changes: 8 additions & 7 deletions fission/src/ui/components/MainHUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,22 @@ const MainHUD: React.FC = () => {
flexDirection={"column"}
sx={{ backgroundColor: "black", borderRadius: "7px", padding: "3px" }}
>
<MainHUDButton
value={"Configure Assets"}
icon={SynthesisIcons.Wrench}
onClick={() => openPanel("configure")}
/>
<MainHUDButton
value={"General Settings"}
icon={SynthesisIcons.Gear}
onClick={() => openModal("settings")}
/>
<MainHUDButton
{ /** Will be coming soonish...tm */ }
{/* <MainHUDButton
value={"View"}
icon={SynthesisIcons.MagnifyingGlass}
onClick={() => openModal("view")}
/>
<MainHUDButton
value={"Configure Assets"}
icon={SynthesisIcons.Wrench}
onClick={() => openPanel("configure")}
/>
/> */}
<MainHUDButton
value={"Debug Tools"}
icon={SynthesisIcons.Bug}
Expand Down
11 changes: 8 additions & 3 deletions fission/src/ui/components/SelectMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ interface SelectMenuProps {
onOptionSelected: (val: SelectMenuOption | undefined) => void

// Function to return a default value
defaultSelectedOption?: (options: SelectMenuOption[]) => SelectMenuOption | undefined
defaultSelectedOption?: SelectMenuOption | undefined
defaultHeaderText: string
noOptionsText?: string
indentation?: number
Expand Down Expand Up @@ -160,11 +160,16 @@ const SelectMenu: React.FC<SelectMenuProps> = ({
deleteCondition,
onAddClicked,
}) => {
const [selectedOption, setSelectedOption] = useState<SelectMenuOption | undefined>(defaultSelectedOption?.(options))
const [selectedOption, setSelectedOption] = useState<SelectMenuOption | undefined>(defaultSelectedOption)

// I have no idea why, but this would actually update state to default selection.
useEffect(() => {
setSelectedOption(defaultSelectedOption)
}, [defaultSelectedOption])

// If the selected option no longer exists as an option, deselect it
useEffect(() => {
if (!options.some(o => o.name === selectedOption?.name)) {
if (selectedOption && !options.some(o => o.name === selectedOption.name)) {
setSelectedOption(undefined)
onOptionSelected(undefined)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Label from "@/ui/components/Label"
import Panel, { PanelPropsImpl } from "@/ui/components/Panel"
import SelectMenu, { SelectMenuOption } from "@/ui/components/SelectMenu"
import { ToggleButton, ToggleButtonGroup } from "@/ui/components/ToggleButtonGroup"
import { useEffect, useMemo, useReducer, useState } from "react"
import { useEffect, useMemo, useReducer, useState, MouseEvent } from "react"
import ConfigureScoringZonesInterface from "./interfaces/scoring/ConfigureScoringZonesInterface"
import ChangeInputsInterface from "./interfaces/inputs/ConfigureInputsInterface"
import InputSystem from "@/systems/input/InputSystem"
Expand All @@ -21,7 +21,7 @@ import ConfigureGamepiecePickupInterface from "./interfaces/ConfigureGamepiecePi
import { ConfigurationSavedEvent } from "./ConfigurationSavedEvent"
import { ConfigurationType, getConfigurationType, setSelectedConfigurationType } from "./ConfigurationType"
import TransformGizmoControl from "@/ui/components/TransformGizmoControl"
import { ConfigMode } from "./ConfigurePanelControls"
import { ConfigMode, popConfigurePanelSettings } from "./ConfigurePanelControls"

/** Option for selecting a robot of field */
class AssemblySelectionOption extends SelectMenuOption {
Expand All @@ -36,9 +36,17 @@ class AssemblySelectionOption extends SelectMenuOption {
interface ConfigurationSelectionProps {
configurationType: ConfigurationType
onAssemblySelected: (assembly: MirabufSceneObject | undefined) => void
selectedAssembly?: MirabufSceneObject
}

const AssemblySelection: React.FC<ConfigurationSelectionProps> = ({ configurationType, onAssemblySelected }) => {
function makeSelectionOption(configurationType: ConfigurationType, assembly: MirabufSceneObject) {
return new AssemblySelectionOption(
`${configurationType == ConfigurationType.ROBOT ? `[${InputSystem.brainIndexSchemeMap.get((assembly.brain as SynthesisBrain).brainIndex)?.schemeName ?? "-"}]` : ""} ${assembly.assemblyName}`,
assembly
)
}

const AssemblySelection: React.FC<ConfigurationSelectionProps> = ({ configurationType, onAssemblySelected, selectedAssembly }) => {
// Update is used when a robot or field is deleted to update the select menu
const [u, update] = useReducer(x => !x, false)
const { openPanel } = usePanelControlContext()
Expand Down Expand Up @@ -70,12 +78,7 @@ const AssemblySelection: React.FC<ConfigurationSelectionProps> = ({ configuratio
/** Robot or field select menu */
return (
<SelectMenu
options={(configurationType == ConfigurationType.ROBOT ? robots : fields).map(assembly => {
return new AssemblySelectionOption(
`${configurationType == ConfigurationType.ROBOT ? `[${InputSystem.brainIndexSchemeMap.get((assembly.brain as SynthesisBrain).brainIndex)?.schemeName ?? "-"}]` : ""} ${assembly.assemblyName}`,
assembly
)
})}
options={(configurationType == ConfigurationType.ROBOT ? robots : fields).map(assembly => makeSelectionOption(configurationType, assembly))}
onOptionSelected={val => {
onAssemblySelected((val as AssemblySelectionOption)?.assemblyObject)
}}
Expand All @@ -89,6 +92,7 @@ const AssemblySelection: React.FC<ConfigurationSelectionProps> = ({ configuratio
openPanel("import-mirabuf")
}}
noOptionsText={`No ${configurationType == ConfigurationType.ROBOT ? "robots" : "fields"} spawned!`}
defaultSelectedOption={selectedAssembly ? makeSelectionOption(configurationType, selectedAssembly) : undefined}
/>
)
}
Expand All @@ -102,41 +106,43 @@ class ConfigModeSelectionOption extends SelectMenuOption {
}
}

const robotModes: ConfigModeSelectionOption[] = [
new ConfigModeSelectionOption("Move", ConfigMode.MOVE),
new ConfigModeSelectionOption("Intake", ConfigMode.INTAKE),
new ConfigModeSelectionOption("Ejector", ConfigMode.EJECTOR),
new ConfigModeSelectionOption(
const robotModes: Map<ConfigMode, ConfigModeSelectionOption> = new Map<ConfigMode, ConfigModeSelectionOption>([
[ ConfigMode.MOVE, new ConfigModeSelectionOption("Move", ConfigMode.MOVE) ],
[ ConfigMode.INTAKE, new ConfigModeSelectionOption("Intake", ConfigMode.INTAKE) ],
[ ConfigMode.EJECTOR, new ConfigModeSelectionOption("Ejector", ConfigMode.EJECTOR) ],
[ ConfigMode.SUBSYSTEMS, new ConfigModeSelectionOption(
"Configure Joints",
ConfigMode.SUBSYSTEMS,
"Set the velocities, torques, and accelerations of your robot's motors."
),
new ConfigModeSelectionOption(
)],
[ ConfigMode.SEQUENTIAL, new ConfigModeSelectionOption(
"Sequence Joints",
ConfigMode.SEQUENTIAL,
"Set which joints follow each other. For example, the second stage of an elevator could follow the first, moving in unison with it."
),
new ConfigModeSelectionOption("Controls", ConfigMode.CONTROLS),
]
const fieldModes: ConfigModeSelectionOption[] = [
new ConfigModeSelectionOption("Move", ConfigMode.MOVE),
new ConfigModeSelectionOption("Scoring Zones", ConfigMode.SCORING_ZONES),
]
)],
[ ConfigMode.CONTROLS, new ConfigModeSelectionOption("Controls", ConfigMode.CONTROLS) ],
])
const fieldModes: Map<ConfigMode, ConfigModeSelectionOption> = new Map<ConfigMode, ConfigModeSelectionOption>([
[ ConfigMode.MOVE, new ConfigModeSelectionOption("Move", ConfigMode.MOVE) ],
[ ConfigMode.SCORING_ZONES, new ConfigModeSelectionOption("Scoring Zones", ConfigMode.SCORING_ZONES) ],
])

interface ConfigModeSelectionProps {
configurationType: ConfigurationType
onModeSelected: (mode: ConfigMode | undefined) => void
selectedMode?: ConfigMode
}

const ConfigModeSelection: React.FC<ConfigModeSelectionProps> = ({ configurationType, onModeSelected }) => {
const ConfigModeSelection: React.FC<ConfigModeSelectionProps> = ({ configurationType, onModeSelected, selectedMode }) => {
return (
<SelectMenu
options={configurationType == ConfigurationType.ROBOT ? robotModes : fieldModes}
options={configurationType == ConfigurationType.ROBOT ? [...robotModes.values()] : [...fieldModes.values()]}
onOptionSelected={val => {
onModeSelected((val as ConfigModeSelectionOption)?.configMode)
}}
defaultHeaderText="Select a Configuration Mode"
indentation={1}
defaultSelectedOption={selectedMode ? (configurationType == ConfigurationType.ROBOT ? robotModes.get(selectedMode)! : fieldModes.get(selectedMode)!) : undefined}
/>
)
}
Expand All @@ -145,10 +151,11 @@ interface ConfigInterfaceProps {
configMode: ConfigMode
assembly: MirabufSceneObject
openPanel: (panelId: string) => void
closePanel: (panelId: string) => void
}

/** The interface for the actual configuration */
const ConfigInterface: React.FC<ConfigInterfaceProps> = ({ configMode, assembly, openPanel }) => {
const ConfigInterface: React.FC<ConfigInterfaceProps> = ({ configMode, assembly, openPanel, closePanel }) => {
switch (configMode) {
case ConfigMode.INTAKE:
return <ConfigureGamepiecePickupInterface selectedRobot={assembly} />
Expand Down Expand Up @@ -191,6 +198,8 @@ const ConfigInterface: React.FC<ConfigInterfaceProps> = ({ configMode, assembly,
scaleDisabled={true}
size={3.0}
parent={assembly}
onAccept={() => closePanel("configure")}
onCancel={() => closePanel("configure")}
/>
)
}
Expand All @@ -206,6 +215,12 @@ const ConfigurePanel: React.FC<PanelPropsImpl> = ({ panelId }) => {
const [configMode, setConfigMode] = useState<ConfigMode | undefined>(undefined)

useEffect(() => {
const settings = popConfigurePanelSettings()
if (settings) {
setConfigMode(settings.configMode)
setSelectedAssembly(settings.selectedAssembly)
}

closePanel("choose-scheme")
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
Expand All @@ -230,8 +245,11 @@ const ConfigurePanel: React.FC<PanelPropsImpl> = ({ panelId }) => {
<ToggleButtonGroup
value={configurationType}
exclusive
onChange={(_: never, v: ConfigurationType) => {
v != null && setConfigurationType(v)
onChange={(_: MouseEvent<HTMLElement>, v: ConfigurationType) => {
if (v != null) {
setConfigurationType(v)
setSelectedConfigurationType(v)
}
setSelectedAssembly(undefined)
new ConfigurationSavedEvent()
setConfigMode(undefined)
Expand All @@ -258,6 +276,7 @@ const ConfigurePanel: React.FC<PanelPropsImpl> = ({ panelId }) => {
setConfigMode(undefined)
setSelectedAssembly(a)
}}
selectedAssembly={selectedAssembly}
/>
{/** Nested select menu to pick a configuration mode */}
{selectedAssembly != undefined && (
Expand All @@ -267,6 +286,7 @@ const ConfigurePanel: React.FC<PanelPropsImpl> = ({ panelId }) => {
if (configMode != undefined) new ConfigurationSavedEvent()
setConfigMode(mode)
}}
selectedMode={configMode}
/>
)}
{/** The interface for the selected configuration mode */}
Expand All @@ -275,6 +295,7 @@ const ConfigurePanel: React.FC<PanelPropsImpl> = ({ panelId }) => {
configMode={configMode}
assembly={selectedAssembly}
openPanel={openPanel}
closePanel={closePanel}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ export type ConfigurePanelSettings = {

let configurePanelSettings: ConfigurePanelSettings | undefined = undefined

export function getConfigurePanelSettings(): ConfigurePanelSettings | undefined {
return configurePanelSettings
export function popConfigurePanelSettings(): ConfigurePanelSettings | undefined {
const tmp = configurePanelSettings
configurePanelSettings = undefined;
return tmp
}

export function setNextConfigurePanelSettings(settings: ConfigurePanelSettings) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from "react"
import { useCallback, useEffect, useState, useMemo } from "react"
import { ConfigurationSavedEvent } from "../../ConfigurationSavedEvent"
import SelectMenu, { SelectMenuOption } from "@/ui/components/SelectMenu"
import InputSystem from "@/systems/input/InputSystem"
Expand Down Expand Up @@ -59,11 +59,17 @@ const ConfigureInputsInterface = () => {
}
}, [saveEvent])

const schemeOptionMap = useMemo(() => {
const map = new Map<InputScheme, SchemeSelectionOption>()
schemes.forEach(x => map.set(x, new SchemeSelectionOption(x)))
return map
}, [schemes])

return (
<>
{/** Select menu with input schemes */}
<SelectMenu
options={schemes.map(s => new SchemeSelectionOption(s))}
options={[...schemeOptionMap.values()]}
onOptionSelected={val => {
setSelectedScheme((val as SchemeSelectionOption)?.scheme)
if (val == undefined) {
Expand Down Expand Up @@ -107,11 +113,7 @@ const ConfigureInputsInterface = () => {
onAddClicked={() => {
openModal("new-scheme")
}}
defaultSelectedOption={options => {
if (options.length < 0 || !(options[0] instanceof SchemeSelectionOption)) return undefined

return options.find(o => (o as SchemeSelectionOption).scheme == getSelectedScheme())
}}
defaultSelectedOption={selectedScheme ? schemeOptionMap.get(selectedScheme) : undefined}
/>
{selectedScheme && <ConfigureSchemeInterface selectedScheme={selectedScheme} />}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ const InitialConfigPanel: React.FC<PanelPropsImpl> = ({ panelId }) => {

const closeFinish = useCallback(() => {
if (targetAssembly?.miraType == MiraType.ROBOT) {
setSelectedConfigurationType(ConfigurationType.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)
} else {
setSelectedConfigurationType(ConfigurationType.FIELD)
}

closePanel(panelId)
Expand Down

0 comments on commit 9f72176

Please sign in to comment.