From d9da5544bbdc784ef5aca46ebe4123b02763d6e3 Mon Sep 17 00:00:00 2001 From: Ondrej Hruska <11602729+ZycaR@users.noreply.github.com> Date: Mon, 17 Jun 2024 08:45:06 -0700 Subject: [PATCH] GUI - Tracker assignment options (#1009) Co-authored-by: Erimel Co-authored-by: loucass003 --- gui/public/i18n/en/translation.ftl | 18 + gui/src/components/commons/Radio.tsx | 9 +- .../components/onboarding/BodyAssignment.tsx | 328 +++++++++++------- .../onboarding/OnboardingLayout.tsx | 4 +- .../pages/mounting/ManualMounting.tsx | 4 +- .../trackers-assign/TrackerAssignment.tsx | 111 ++++-- .../SingleTrackerBodyAssignmentMenu.tsx | 15 +- gui/src/hooks/config.ts | 12 +- 8 files changed, 333 insertions(+), 168 deletions(-) diff --git a/gui/public/i18n/en/translation.ftl b/gui/public/i18n/en/translation.ftl index 5ae38477f..93f1b5bdf 100644 --- a/gui/public/i18n/en/translation.ftl +++ b/gui/public/i18n/en/translation.ftl @@ -688,6 +688,24 @@ onboarding-assign_trackers-assigned = { $assigned } of { $trackers -> onboarding-assign_trackers-advanced = Show advanced assign locations onboarding-assign_trackers-next = I assigned all the trackers onboarding-assign_trackers-mirror_view = Mirror view +onboarding-assign_trackers-option-amount = { $trackersCount -> + [one] x{ $trackersCount } + *[other] x{ $trackersCount } +} +onboarding-assign_trackers-option-label = { $mode -> + [lower-body] Lower-Body Set + [core] Core Set + [enhanced-core] Enhanced Core Set + [full-body] Full-Body Set + *[all] All Trackers +} +onboarding-assign_trackers-option-description = { $mode -> + [lower-body] Minimum for VR full-body tracking + [core] + Enhanced spine tracking + [enhanced-core] + Foot rotation + [full-body] + Elbow tracking + *[all] All available tracker assignments +} ## Tracker assignment warnings # Note for devs, number is used for representing boolean states per bit. diff --git a/gui/src/components/commons/Radio.tsx b/gui/src/components/commons/Radio.tsx index fa7cc4623..eedbf0c17 100644 --- a/gui/src/components/commons/Radio.tsx +++ b/gui/src/components/commons/Radio.tsx @@ -1,6 +1,7 @@ import classNames from 'classnames'; import { Control, Controller } from 'react-hook-form'; import { Typography } from './Typography'; +import { ReactNode } from 'react'; export function Radio({ control, @@ -8,15 +9,17 @@ export function Radio({ label, value, description, + children, // input props disabled, ...props }: { control: Control; name: string; - label: string; + label?: string; value: string; description?: string | null; + children?: ReactNode; } & React.HTMLProps) { return ( @@ -46,7 +49,7 @@ export function Radio({ {...props} />
- {label} + {children ? children : {label}} {description && ( {description} diff --git a/gui/src/components/onboarding/BodyAssignment.tsx b/gui/src/components/onboarding/BodyAssignment.tsx index 90af2f731..dd9c7455b 100644 --- a/gui/src/components/onboarding/BodyAssignment.tsx +++ b/gui/src/components/onboarding/BodyAssignment.tsx @@ -1,19 +1,29 @@ -import { useMemo } from 'react'; +import { useCallback, useMemo } from 'react'; import { BodyPart } from 'solarxr-protocol'; import { FlatDeviceTracker } from '@/hooks/app'; +import { AssignMode } from '@/hooks/config'; import { useTrackers } from '@/hooks/tracker'; import { BodyInteractions } from '@/components/commons/BodyInteractions'; import { TrackerPartCard } from '@/components/tracker/TrackerPartCard'; import { BodyPartError } from './pages/trackers-assign/TrackerAssignment'; import { SIDES } from '@/components/commons/PersonFrontIcon'; +export const ARMS_PARTS = new Set([ + BodyPart.LEFT_UPPER_ARM, + BodyPart.RIGHT_UPPER_ARM, + BodyPart.LEFT_LOWER_ARM, + BodyPart.RIGHT_LOWER_ARM, +]); +export const LEGS_PARTS = new Set([ + BodyPart.LEFT_UPPER_LEG, + BodyPart.RIGHT_UPPER_LEG, + BodyPart.LEFT_LOWER_LEG, + BodyPart.RIGHT_LOWER_LEG, +]); export const LOWER_BODY = new Set([ BodyPart.LEFT_FOOT, BodyPart.RIGHT_FOOT, - BodyPart.LEFT_LOWER_LEG, - BodyPart.RIGHT_LOWER_LEG, - BodyPart.LEFT_UPPER_LEG, - BodyPart.RIGHT_UPPER_LEG, + ...LEGS_PARTS, ]); export const SPINE_PARTS = [ BodyPart.UPPER_CHEST, @@ -44,8 +54,47 @@ export const ASSIGNMENT_RULES: Partial< // Also don't warn if no legs. }; +export const ASSIGNMENT_MODES: Record = { + // x5 + [AssignMode.LowerBody]: [BodyPart.CHEST, ...LEGS_PARTS], + // x6 (5 + 1) + [AssignMode.Core]: [BodyPart.CHEST, BodyPart.HIP, ...LEGS_PARTS], + // x8 (5 + 3) + [AssignMode.EnhancedCore]: [ + BodyPart.CHEST, + BodyPart.HIP, + ...LEGS_PARTS, + BodyPart.LEFT_FOOT, + BodyPart.RIGHT_FOOT, + ], + // x10 (7 + 3) + [AssignMode.FullBody]: [ + BodyPart.CHEST, + BodyPart.HIP, + BodyPart.LEFT_UPPER_ARM, + BodyPart.RIGHT_UPPER_ARM, + ...LEGS_PARTS, + BodyPart.LEFT_FOOT, + BodyPart.RIGHT_FOOT, + ], + // special case with all body parts + [AssignMode.All]: [ + BodyPart.HEAD, + BodyPart.NECK, + BodyPart.LEFT_SHOULDER, + BodyPart.RIGHT_SHOULDER, + BodyPart.LEFT_HAND, + BodyPart.RIGHT_HAND, + BodyPart.LEFT_FOOT, + BodyPart.RIGHT_FOOT, + ...SPINE_PARTS, + ...ARMS_PARTS, + ...LEGS_PARTS, + ], +}; + export function BodyAssignment({ - advanced, + assignMode, mirror, onRoleSelected, rolesWithErrors = {}, @@ -53,7 +102,7 @@ export function BodyAssignment({ onlyAssigned = false, width, }: { - advanced: boolean; + assignMode: AssignMode; mirror: boolean; onlyAssigned?: boolean; rolesWithErrors?: Partial>; @@ -94,6 +143,13 @@ export function BodyAssignment({ const left = +!mirror; const right = +mirror; + const hasBodyPart = useCallback( + (part: BodyPart) => + assignMode === AssignMode.All || + ASSIGNMENT_MODES[assignMode].indexOf(part) > -1, + [assignMode] + ); + return ( <>
- {advanced && ( + {hasBodyPart(BodyPart.HEAD) && ( )} - {advanced && ( + + {hasBodyPart(BodyPart.NECK) && ( )}
-
- {advanced && ( + {hasBodyPart(SIDES[left].shoulder) && ( )} - onRoleSelected(SIDES[left].upperArm)} - direction="right" - /> + + {hasBodyPart(SIDES[left].upperArm) && ( + onRoleSelected(SIDES[left].upperArm)} + direction="right" + /> + )}
- onRoleSelected(SIDES[left].lowerArm)} - direction="right" - /> + {hasBodyPart(SIDES[left].lowerArm) && ( + onRoleSelected(SIDES[left].lowerArm)} + direction="right" + /> + )} - {advanced && ( + {hasBodyPart(SIDES[left].hand) && (
- onRoleSelected(SIDES[left].upperLeg)} - direction="right" - /> + {hasBodyPart(SIDES[left].upperLeg) && ( + onRoleSelected(SIDES[left].upperLeg)} + direction="right" + /> + )} - onRoleSelected(SIDES[left].lowerLeg)} - direction="right" - /> - onRoleSelected(SIDES[left].foot)} - direction="right" - /> + {hasBodyPart(SIDES[left].lowerLeg) && ( + onRoleSelected(SIDES[left].lowerLeg)} + direction="right" + /> + )} + + {hasBodyPart(SIDES[left].foot) && ( + onRoleSelected(SIDES[left].foot)} + direction="right" + /> + )}
} rightControls={
- {advanced && ( + {hasBodyPart(BodyPart.UPPER_CHEST) && ( )} - onRoleSelected(BodyPart.CHEST)} - direction="left" - /> + {hasBodyPart(BodyPart.CHEST) && ( + onRoleSelected(BodyPart.CHEST)} + direction="left" + /> + )}
- {advanced && ( + {hasBodyPart(SIDES[right].shoulder) && ( )} - onRoleSelected(SIDES[right].upperArm)} - direction="left" - /> + {hasBodyPart(SIDES[right].upperArm) && ( + onRoleSelected(SIDES[right].upperArm)} + direction="left" + /> + )}
-
- onRoleSelected(BodyPart.WAIST)} - role={BodyPart.WAIST} - direction="left" - /> - onRoleSelected(BodyPart.HIP)} - role={BodyPart.HIP} - direction="left" - /> + {hasBodyPart(BodyPart.WAIST) && ( + onRoleSelected(BodyPart.WAIST)} + role={BodyPart.WAIST} + direction="left" + /> + )} + + {hasBodyPart(BodyPart.HIP) && ( + onRoleSelected(BodyPart.HIP)} + role={BodyPart.HIP} + direction="left" + /> + )}
-
- onRoleSelected(SIDES[right].lowerArm)} - direction="left" - /> - {advanced && ( + {hasBodyPart(SIDES[right].lowerArm) && ( + onRoleSelected(SIDES[right].lowerArm)} + direction="left" + /> + )} + + {hasBodyPart(SIDES[right].hand) && ( )}
-
- onRoleSelected(SIDES[right].upperLeg)} - direction="left" - /> + {hasBodyPart(SIDES[right].upperLeg) && ( + onRoleSelected(SIDES[right].upperLeg)} + direction="left" + /> + )} - onRoleSelected(SIDES[right].lowerLeg)} - direction="left" - /> - onRoleSelected(SIDES[right].foot)} - direction="left" - /> + {hasBodyPart(SIDES[right].lowerLeg) && ( + onRoleSelected(SIDES[right].lowerLeg)} + direction="left" + /> + )} + + {hasBodyPart(SIDES[right].foot) && ( + onRoleSelected(SIDES[right].foot)} + direction="left" + /> + )}
} diff --git a/gui/src/components/onboarding/OnboardingLayout.tsx b/gui/src/components/onboarding/OnboardingLayout.tsx index 0bd458cd5..4fb33e5aa 100644 --- a/gui/src/components/onboarding/OnboardingLayout.tsx +++ b/gui/src/components/onboarding/OnboardingLayout.tsx @@ -38,7 +38,9 @@ export function OnboardingLayout({ children }: { children: ReactNode }) { ) : ( -
{children}
+
+ {children} +
); } diff --git a/gui/src/components/onboarding/pages/mounting/ManualMounting.tsx b/gui/src/components/onboarding/pages/mounting/ManualMounting.tsx index 78287a767..49b4709e8 100644 --- a/gui/src/components/onboarding/pages/mounting/ManualMounting.tsx +++ b/gui/src/components/onboarding/pages/mounting/ManualMounting.tsx @@ -13,7 +13,7 @@ import { MountingSelectionMenu } from './MountingSelectionMenu'; import { useLocalization } from '@fluent/react'; import { useBreakpoint } from '@/hooks/breakpoint'; import { Quaternion } from 'three'; -import { defaultConfig, useConfig } from '@/hooks/config'; +import { AssignMode, defaultConfig, useConfig } from '@/hooks/config'; export function ManualMountingPage() { const { isMobile } = useBreakpoint('mobile'); @@ -104,7 +104,7 @@ export function ManualMountingPage() { width={isMobile ? 160 : undefined} mirror={config?.mirrorView ?? defaultConfig.mirrorView} onlyAssigned={true} - advanced={true} + assignMode={AssignMode.All} onRoleSelected={setSelectRole} >
diff --git a/gui/src/components/onboarding/pages/trackers-assign/TrackerAssignment.tsx b/gui/src/components/onboarding/pages/trackers-assign/TrackerAssignment.tsx index 33c8aa5e6..1a7d333e7 100644 --- a/gui/src/components/onboarding/pages/trackers-assign/TrackerAssignment.tsx +++ b/gui/src/components/onboarding/pages/trackers-assign/TrackerAssignment.tsx @@ -24,15 +24,17 @@ import { CheckBox } from '@/components/commons/Checkbox'; import { TipBox } from '@/components/commons/TipBox'; import { Typography } from '@/components/commons/Typography'; import { + ASSIGNMENT_MODES, ASSIGNMENT_RULES, BodyAssignment, LOWER_BODY, } from '@/components/onboarding/BodyAssignment'; import { NeckWarningModal } from '@/components/onboarding/NeckWarningModal'; import { TrackerSelectionMenu } from './TrackerSelectionMenu'; -import { useConfig } from '@/hooks/config'; +import { AssignMode, defaultConfig, useConfig } from '@/hooks/config'; import { playTapSetupSound } from '@/sounds/sounds'; import { useBreakpoint } from '@/hooks/breakpoint'; +import { Radio } from '@/components/commons/Radio'; export type BodyPartError = { label: string | undefined; @@ -46,27 +48,54 @@ interface FlatDeviceTrackerDummy { }; } +// Ordered collection of assign modes with the number of IMU trackers +const ASSIGN_MODE_OPTIONS = [ + AssignMode.LowerBody, + AssignMode.Core, + AssignMode.EnhancedCore, + AssignMode.FullBody, + AssignMode.All, +].reduce( + (options, mode) => ({ ...options, [mode]: ASSIGNMENT_MODES[mode].length }), + {} as Record +); + export function TrackersAssignPage() { const { isMobile } = useBreakpoint('mobile'); const { l10n } = useLocalization(); const { config, setConfig } = useConfig(); - const { useAssignedTrackers, trackers } = useTrackers(); + const { useAssignedTrackers, useConnectedIMUTrackers, trackers } = + useTrackers(); const { applyProgress, state } = useOnboarding(); const { sendRPCPacket, useRPCPacket } = useWebsocketAPI(); const defaultValues = { - advanced: config?.advancedAssign ?? false, - mirrorView: config?.mirrorView ?? true, + assignMode: config?.assignMode ?? defaultConfig.assignMode, + mirrorView: config?.mirrorView ?? defaultConfig.mirrorView, }; - const { control, watch } = useForm<{ - advanced: boolean; + const { control, watch, setValue } = useForm<{ + assignMode: AssignMode; mirrorView: boolean; }>({ defaultValues }); - const { advanced, mirrorView } = watch(); + const { assignMode, mirrorView } = watch(); const [selectedRole, setSelectRole] = useState(BodyPart.NONE); const assignedTrackers = useAssignedTrackers(); useEffect(() => { - setConfig({ advancedAssign: advanced, mirrorView }); - }, [advanced, mirrorView]); + setConfig({ assignMode, mirrorView }); + }, [assignMode, mirrorView]); + + const connectedIMUTrackers = useConnectedIMUTrackers().length; + useEffect(() => { + if (connectedIMUTrackers <= ASSIGN_MODE_OPTIONS[assignMode]) return; + + const selectedAssignMode = + (Object.entries(ASSIGN_MODE_OPTIONS).find( + ([_, count]) => count >= connectedIMUTrackers + )?.[0] as AssignMode) ?? AssignMode.All; + + if (assignMode !== selectedAssignMode) { + setValue('assignMode', selectedAssignMode); + } + }, [connectedIMUTrackers, assignMode]); const [tapDetectionSettings, setTapDetectionSettings] = useState {l10n.getString('tips-find_tracker')} -
- + {!!firstError && ( +
+
+ {firstError.label} +
+
+ )} +
+ {Object.entries(ASSIGN_MODE_OPTIONS).map( + ([mode, trackersCount]) => ( + trackersCount && + mode !== AssignMode.All + } + className="hidden" + > +
+
+ + {l10n.getString( + 'onboarding-assign_trackers-option-amount', + { trackersCount } + )} + +
+
+ + {l10n.getString( + 'onboarding-assign_trackers-option-label', + { mode } + )} + + + {l10n.getString( + 'onboarding-assign_trackers-option-description', + { mode } + )} + +
+
+
+ ) + )}
- {!!firstError && ( -
-
- {firstError.label} -
-
- )}
{!state.alonePage && ( <> @@ -342,7 +405,7 @@ export function TrackersAssignPage() { onlyAssigned={false} highlightedRoles={firstError?.affectedRoles || []} rolesWithErrors={rolesWithErrors} - advanced={advanced ?? defaultValues.advanced} + assignMode={assignMode ?? defaultValues.assignMode} mirror={mirrorView ?? defaultValues.mirrorView} onRoleSelected={tryOpenChokerWarning} > diff --git a/gui/src/components/tracker/SingleTrackerBodyAssignmentMenu.tsx b/gui/src/components/tracker/SingleTrackerBodyAssignmentMenu.tsx index aa05c38e4..2bd348926 100644 --- a/gui/src/components/tracker/SingleTrackerBodyAssignmentMenu.tsx +++ b/gui/src/components/tracker/SingleTrackerBodyAssignmentMenu.tsx @@ -1,9 +1,7 @@ import classNames from 'classnames'; -import { useForm } from 'react-hook-form'; import ReactModal from 'react-modal'; import { BodyPart } from 'solarxr-protocol'; import { Button } from '@/components/commons/Button'; -import { CheckBox } from '@/components/commons/Checkbox'; import { Typography } from '@/components/commons/Typography'; import { BodyAssignment } from '@/components/onboarding/BodyAssignment'; import { useLocalization } from '@fluent/react'; @@ -24,9 +22,6 @@ export function SingleTrackerBodyAssignmentMenu({ const { isMobile } = useBreakpoint('mobile'); const { l10n } = useLocalization(); const { config } = useConfig(); - const defaultValues = { advanced: false }; - const { control, watch } = useForm<{ advanced: boolean }>({ defaultValues }); - const { advanced } = watch(); const { closeChokerWarning, tryOpenChokerWarning, shouldShowChokerWarn } = useChokerWarning({ @@ -56,14 +51,6 @@ export function SingleTrackerBodyAssignmentMenu({ {l10n.getString('body_assignment_menu-description')} -