mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-24 02:51:20 -08:00
new settings
This commit is contained in:
1 parent
f6e1cc7747
commit
3e554c1b8a
13 files changed
+265
-241
No files matched your search
+16
-4
@@ -3,15 +3,18 @@ import {
|
||||
BrowserRouter as Router,
|
||||
Routes,
|
||||
Route,
|
||||
Outlet,
|
||||
} from "react-router-dom";
|
||||
import { Overview } from './components/Overview';
|
||||
import { BodyProportions } from './components/proportions/BodyProportions';
|
||||
import { AppContextProvider } from './components/providers/AppContext';
|
||||
import { useEffect } from 'react';
|
||||
import { DataFeedConfigT, DataFeedMessage, DeviceDataMaskT, StartDataFeedT, TrackerDataMaskT } from 'solarxr-protocol';
|
||||
import { Settings } from './components/settings/Settings';
|
||||
import { MainLayoutRoute } from './components/MainLayout';
|
||||
import { SettingsLayoutRoute } from './components/settings/SettingsLayout';
|
||||
import { TrackersSettings } from './components/settings/pages/TrackersSettings';
|
||||
import { Navbar } from './components/Navbar';
|
||||
import { Serial } from './components/settings/pages/Serial';
|
||||
|
||||
function Layout() {
|
||||
const { sendDataFeedPacket } = useWebsocketAPI();
|
||||
@@ -53,9 +56,13 @@ function Layout() {
|
||||
}/>
|
||||
<Route path="/settings" element={
|
||||
<SettingsLayoutRoute>
|
||||
<Settings/>
|
||||
<Outlet></Outlet>
|
||||
</SettingsLayoutRoute>
|
||||
}/>
|
||||
}>
|
||||
<Route path="trackers" element={<TrackersSettings />} />
|
||||
<Route path="serial" element={<Serial />} />
|
||||
</Route>
|
||||
<Route path="*" element={<Navbar></Navbar>}></Route>
|
||||
</Routes>
|
||||
</>
|
||||
)
|
||||
@@ -70,7 +77,12 @@ function App() {
|
||||
<Router>
|
||||
<div className='bg-primary-1 h-full w-full overflow-hidden'>
|
||||
<div className='flex-col h-full'>
|
||||
{!websocketAPI.isConnected && <div className='flex w-full h-full justify-center items-center text-white p-2'>Connection lost to server</div>}
|
||||
{!websocketAPI.isConnected && (
|
||||
<>
|
||||
<Navbar></Navbar>
|
||||
<div className='flex w-full h-full justify-center items-center text-white p-2'>Connection lost to server</div>
|
||||
</>
|
||||
)}
|
||||
{websocketAPI.isConnected && <Layout></Layout>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -12,7 +12,7 @@ import { ResetButton } from "./ResetButton";
|
||||
|
||||
export function MainLayoutRoute({ children }: { children: ReactChild }) {
|
||||
|
||||
const { layoutHeight, ref } = useLayout();
|
||||
const { layoutHeight, ref } = useLayout<HTMLDivElement>();
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -39,7 +39,7 @@ export function MainLayoutRoute({ children }: { children: ReactChild }) {
|
||||
</div>
|
||||
<div className='flex flex-grow flex-col justify-end'>
|
||||
{/* <Button variant='primary' className='w-full'>Debug</Button> */}
|
||||
<NavLink to="/settings" className="flex gap-5 group cursor-pointer">
|
||||
<NavLink to="/settings/trackers" className="flex gap-5 group cursor-pointer">
|
||||
<div className="flex bg-primary-4 rounded-full p-2 fill-purple-300 group-hover:fill-white"><GearIcon></GearIcon></div>
|
||||
<div className="flex flex-col justify-around text-purple-300 group-hover:text-white font-bold">Settings</div>
|
||||
</NavLink>
|
||||
|
||||
@@ -36,9 +36,9 @@ export function Navbar({ children }: { children?: ReactChild }) {
|
||||
<div data-tauri-drag-region className='flex bg-primary-1 gap-2'>
|
||||
<div className="flex px-8 py-2 pt-3 justify-around" data-tauri-drag-region>
|
||||
<div className="flex flex-row gap-3" data-tauri-drag-region>
|
||||
<div className="flex justify-around flex-col select-all" data-tauri-drag-region>
|
||||
<SlimeVRIcon drag></SlimeVRIcon>
|
||||
</div>
|
||||
<NavLink to="/" className="flex justify-around flex-col select-all" data-tauri-drag-region>
|
||||
<SlimeVRIcon></SlimeVRIcon>
|
||||
</NavLink>
|
||||
<div className="flex text-white text-xl justify-around flex-col font-bold" data-tauri-drag-region>SlimeVR</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
import { ReactChild, useEffect, useRef, useState } from "react";
|
||||
import { useWebsocketAPI } from "../hooks/websocket-api";
|
||||
import { Button } from "./commons/Button";
|
||||
import { AppModal } from "./Modal";
|
||||
import { CloseSerialRequestT, OpenSerialRequestT, RpcMessage, SerialUpdateResponseT, SetWifiRequestT } from "solarxr-protocol"
|
||||
import { Input } from "./commons/Input";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
export interface WifiForm {
|
||||
ssid: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export function WIFIButton({ children }: { children: ReactChild }) {
|
||||
|
||||
const { useRPCPacket, sendRPCPacket } = useWebsocketAPI();
|
||||
const consoleRef = useRef<HTMLPreElement>(null);
|
||||
const [consoleContent, setConsole] = useState("");
|
||||
const [isSerialOpen, setSerialOpen] = useState(false);
|
||||
const { register, reset, handleSubmit } = useForm<WifiForm>({ defaultValues: {} });
|
||||
|
||||
const [isOpen, setOpen] = useState(false);
|
||||
|
||||
const openModal = () => {
|
||||
setOpen(true);
|
||||
setConsole('');
|
||||
setSerialOpen(false);
|
||||
sendRPCPacket(RpcMessage.OpenSerialRequest, new OpenSerialRequestT())
|
||||
}
|
||||
|
||||
const closeModal = () => {
|
||||
setOpen(false);
|
||||
reset({ ssid: '', password: '' })
|
||||
sendRPCPacket(RpcMessage.CloseSerialRequest, new CloseSerialRequestT());
|
||||
}
|
||||
|
||||
useRPCPacket(RpcMessage.SerialUpdateResponse, (data: SerialUpdateResponseT) => {
|
||||
if (data.closed && isOpen) {
|
||||
setSerialOpen(false)
|
||||
setTimeout(() => {
|
||||
sendRPCPacket(RpcMessage.OpenSerialRequest, new OpenSerialRequestT())
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
if (!data.closed) {
|
||||
setSerialOpen(true);
|
||||
}
|
||||
|
||||
if (data.log && consoleRef.current) {
|
||||
setConsole((console) => console + data.log)
|
||||
}
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (consoleRef.current)
|
||||
consoleRef.current.scrollTo({ top: consoleRef.current.scrollHeight })
|
||||
}, [consoleContent])
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => {
|
||||
if (!isSerialOpen)
|
||||
sendRPCPacket(RpcMessage.OpenSerialRequest, new OpenSerialRequestT())
|
||||
else
|
||||
clearInterval(id);
|
||||
}, 1000);
|
||||
|
||||
return () => {
|
||||
clearInterval(id);
|
||||
}
|
||||
}, [isSerialOpen, sendRPCPacket])
|
||||
|
||||
const sendWifiCredentials = (value: WifiForm) => {
|
||||
const wifi = new SetWifiRequestT();
|
||||
|
||||
wifi.password = value.password;
|
||||
wifi.ssid = value.ssid;
|
||||
|
||||
sendRPCPacket(RpcMessage.SetWifiRequest, wifi)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button variant="primary" onClick={openModal}>{children}</Button>
|
||||
<AppModal
|
||||
isOpen={isOpen}
|
||||
name={<>Wifi Settings</>}
|
||||
onRequestClose={closeModal}
|
||||
>
|
||||
<form className="flex flex-col gap-2" onSubmit={handleSubmit(sendWifiCredentials)}>
|
||||
<pre ref={consoleRef} className="flex w-full bg-gray-800 h-80 rounded-lg overflow-y-auto select-text">
|
||||
{isSerialOpen ? consoleContent : 'Connection to serial lost, Reconnecting...'}
|
||||
</pre>
|
||||
<div className="flex flex-col gap-2" >
|
||||
<Input {...register('ssid', { required: true })} type="text" placeholder="SSID"></Input>
|
||||
<Input {...register('password', { required: true })} type="password" placeholder="Password"></Input>
|
||||
<Button variant="primary" type="submit">Send</Button>
|
||||
</div>
|
||||
</form>
|
||||
</AppModal>
|
||||
</>
|
||||
)
|
||||
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
|
||||
|
||||
export function SlimeVRIcon({ drag }: { drag: boolean }) {
|
||||
export function SlimeVRIcon({ drag }: { drag?: boolean }) {
|
||||
return (
|
||||
<svg width="49" height="29" viewBox="0 0 49 29" fill="none" xmlns="http://www.w3.org/2000/svg" data-tauri-drag-region>
|
||||
<svg width="49" height="29" viewBox="0 0 49 29" fill="none" xmlns="http://www.w3.org/2000/svg" data-tauri-drag-region={drag}>
|
||||
<path d="M2 26.996C10.44 25.59 29.16 23.1571 46.509 26.9091C46.509 26.9091 48.89 -0.199966 35.761 2.14503" stroke="#A44FED" strokeWidth="3" strokeLinecap="round"/>
|
||||
<path d="M7.52161 15.0107L12.3649 9.20459L17.5044 13.9572" stroke="#A44FED" strokeWidth="3.00157" strokeLinecap="round"/>
|
||||
<path d="M27.9566 14.1435L33.7372 9.27062L37.9695 14.8458" stroke="#A44FED" strokeWidth="3.00136" strokeLinecap="round"/>
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
import { useWebsocketAPI } from "../../hooks/websocket-api";
|
||||
import { CheckBox } from "../commons/Checkbox";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { useEffect } from "react";
|
||||
import { Select } from "../commons/Select";
|
||||
import { NumberSelector } from "../commons/NumberSelector";
|
||||
import { WIFIButton } from "../WifiButton";
|
||||
import { ChangeSettingsRequestT, FilteringSettingsT, RpcMessage, SettingsRequestT, SettingsResponseT, SteamVRTrackersSettingT } from "solarxr-protocol";
|
||||
|
||||
interface SettingsForm {
|
||||
trackers: {
|
||||
waist: boolean,
|
||||
chest: boolean,
|
||||
legs: boolean,
|
||||
knees: boolean,
|
||||
elbows: boolean,
|
||||
}
|
||||
filtering: {
|
||||
type: number;
|
||||
intensity: number;
|
||||
ticks: number;
|
||||
}
|
||||
}
|
||||
|
||||
export function Settings() {
|
||||
|
||||
const { sendRPCPacket, useRPCPacket } = useWebsocketAPI();
|
||||
const { register, reset, control, watch, handleSubmit } = useForm<SettingsForm>({ defaultValues: { filtering: { intensity: 0, ticks: 0 } } });
|
||||
|
||||
const onSubmit = (values: SettingsForm) => {
|
||||
const settings = new ChangeSettingsRequestT();
|
||||
|
||||
if (values.trackers) {
|
||||
const trackers = new SteamVRTrackersSettingT();
|
||||
trackers.waist = values.trackers.waist;
|
||||
trackers.chest = values.trackers.chest;
|
||||
trackers.legs = values.trackers.legs;
|
||||
trackers.knees = values.trackers.knees;
|
||||
trackers.elbows = values.trackers.elbows;
|
||||
settings.steamVrTrackers = trackers;
|
||||
}
|
||||
|
||||
const filtering = new FilteringSettingsT();
|
||||
filtering.type = values.filtering.type;
|
||||
filtering.intensity = values.filtering.intensity;
|
||||
filtering.ticks = values.filtering.ticks;
|
||||
|
||||
settings.filtering = filtering;
|
||||
sendRPCPacket(RpcMessage.ChangeSettingsRequest, settings)
|
||||
}
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const subscription = watch(() => handleSubmit(onSubmit)());
|
||||
return () => subscription.unsubscribe();
|
||||
}, [])
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(RpcMessage.SettingsRequest, new SettingsRequestT());
|
||||
}, [])
|
||||
|
||||
useRPCPacket(RpcMessage.SettingsResponse, (settings: SettingsResponseT) => {
|
||||
reset({
|
||||
...(settings.steamVrTrackers ? {trackers: settings.steamVrTrackers} : {}),
|
||||
...(settings.filtering ? {filtering: settings.filtering} : {})
|
||||
})
|
||||
})
|
||||
|
||||
return (
|
||||
<form className="px-8 flex flex-col gap-4 pt-4">
|
||||
<div className="flex text-white text-2xl font-bold">
|
||||
Settings
|
||||
</div>
|
||||
<div className="flex flex-col gap-8">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex text-gray-300 text-xl font-bold gap-5">
|
||||
SteamVR Trackers
|
||||
</div>
|
||||
<div className="flex text-gray-300 text-xl font-bold gap-5">
|
||||
<CheckBox {...register('trackers.waist')} label="Waist" />
|
||||
<CheckBox {...register('trackers.chest')} label="Chest"/>
|
||||
<CheckBox {...register('trackers.legs')} label="Legs"/>
|
||||
<CheckBox {...register('trackers.knees')} label="Knees"/>
|
||||
<CheckBox {...register('trackers.elbows')} label="Elbows"/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex text-gray-300 text-xl font-bold gap-5">
|
||||
Trackers Filtering
|
||||
</div>
|
||||
<div className="flex text-gray-300 text-xl font-bold gap-5">
|
||||
<Select {...register('filtering.type')} label="Filtering Type" options={[{ label: 'None', value: 0 }, { label: 'Interpolation', value: 1 }, {label: 'Extrapolation', value: 2 }]}></Select>
|
||||
<NumberSelector variant="smol" control={control} name="filtering.intensity" label="Intensity" valueLabelFormat={(value) => `${value}%`} min={0} max={100} step={10}></NumberSelector>
|
||||
<NumberSelector variant="smol" control={control} name="filtering.ticks" label="Ticks" min={0} max={80} step={1}></NumberSelector>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex text-gray-300 text-xl font-bold gap-5">
|
||||
Wifi Settings
|
||||
</div>
|
||||
<div className="flex text-gray-300 text-xl font-bold gap-5">
|
||||
<WIFIButton>Open Wifi Settings</WIFIButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
import { ReactChild } from "react";
|
||||
import { NavLink } from "react-router-dom";
|
||||
import { useLayout } from "../../hooks/layout";
|
||||
import { IconButton } from "../commons/ButtonIcon";
|
||||
import { CloseIcon } from "../commons/icon/CloseIcon";
|
||||
import { Navbar } from "../Navbar";
|
||||
import { SettingsSidebar } from "./SettingsSidebar";
|
||||
|
||||
export function SettingsLayoutRoute({ children }: { children: ReactChild }) {
|
||||
|
||||
const { layoutHeight, ref } = useLayout();
|
||||
const { layoutHeight, ref } = useLayout<HTMLDivElement>();
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -16,12 +15,12 @@ export function SettingsLayoutRoute({ children }: { children: ReactChild }) {
|
||||
<div ref={ref} className='flex-grow' style={{ height: layoutHeight }}>
|
||||
<div className="flex bg-primary-1 h-full ">
|
||||
<SettingsSidebar></SettingsSidebar>
|
||||
<div className="flex flex-grow gap-10 flex-col bg-primary-2 rounded-tl-3xl">
|
||||
<div className="relative">
|
||||
<div className="flex flex-grow gap-10 flex-col bg-primary-2 rounded-tl-3xl overflow-hidden">
|
||||
<div className="relative overflow-y-auto overflow-x-hidden">
|
||||
{children}
|
||||
<div className="absolute top-0 right-0 p-5">
|
||||
<NavLink to="/" className="flex gap-5 group cursor-pointer">
|
||||
<div className="flex bg-primary-4 rounded-full p-2 fill-purple-300 group-hover:fill-white"><CloseIcon></CloseIcon></div>
|
||||
<div className="flex bg-primary-4 rounded-full p-2 fill-purple-300 group-hover:fill-white"><CloseIcon></CloseIcon></div>
|
||||
</NavLink>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -8,16 +8,17 @@ export function SettingsSidebar() {
|
||||
<div className="flex flex-col gap-3 pt-4 text-purple-100 font-bold">
|
||||
<div className="flex">TRACKER SETTINGS</div>
|
||||
<div className="flex flex-col gap-2 font-medium">
|
||||
<NavLink to="/settings/tracker/steamvr" className="pl-5 py-2 hover:bg-primary-5 rounded-lg">SteamVR</NavLink>
|
||||
<NavLink to="/settings/tracker/steamvr" className="pl-5 py-2 hover:bg-primary-5 rounded-lg">Filtering</NavLink>
|
||||
<NavLink to="/settings/trackers" state={{ scrollTo: 'steamvr' }} className="pl-5 py-2 hover:bg-primary-5 rounded-lg">SteamVR</NavLink>
|
||||
<NavLink to="/settings/trackers" state={{ scrollTo: 'filtering' }} className="pl-5 py-2 hover:bg-primary-5 rounded-lg">Filtering</NavLink>
|
||||
<NavLink to="/settings/serial" className="pl-5 py-2 hover:bg-primary-5 rounded-lg">Serial</NavLink>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-3 pt-4 text-purple-100 font-bold">
|
||||
{/* <div className="flex flex-col gap-3 pt-4 text-purple-100 font-bold">
|
||||
<div className="flex">USER INTERFACE</div>
|
||||
<div className="flex flex-col gap-2 font-medium">
|
||||
<NavLink to="" className="pl-3 py-2 hover:bg-primary-5 rounded-lg">Widgets</NavLink>
|
||||
</div>
|
||||
</div>
|
||||
</div> */}
|
||||
</div>
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { CloseSerialRequestT, OpenSerialRequestT, RpcMessage, SerialUpdateResponseT, SetWifiRequestT } from "solarxr-protocol";
|
||||
import { useLayout } from "../../../hooks/layout";
|
||||
import { useWebsocketAPI } from "../../../hooks/websocket-api";
|
||||
import { Button } from "../../commons/Button";
|
||||
import { Input } from "../../commons/Input";
|
||||
|
||||
export interface WifiForm {
|
||||
ssid: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export function Serial() {
|
||||
|
||||
const { layoutHeight, layoutWidth, ref: consoleRef } = useLayout<HTMLDivElement>();
|
||||
|
||||
const { useRPCPacket, sendRPCPacket } = useWebsocketAPI();
|
||||
// const consoleRef = useRef<HTMLPreElement>(null);
|
||||
const [consoleContent, setConsole] = useState("");
|
||||
const [isSerialOpen, setSerialOpen] = useState(false);
|
||||
const { register, reset, handleSubmit } = useForm<WifiForm>({ defaultValues: {} });
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(RpcMessage.OpenSerialRequest, new OpenSerialRequestT())
|
||||
return () => {
|
||||
sendRPCPacket(RpcMessage.CloseSerialRequest, new CloseSerialRequestT());
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
useRPCPacket(RpcMessage.SerialUpdateResponse, (data: SerialUpdateResponseT) => {
|
||||
if (data.closed) {
|
||||
setSerialOpen(false)
|
||||
setTimeout(() => {
|
||||
sendRPCPacket(RpcMessage.OpenSerialRequest, new OpenSerialRequestT())
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
if (!data.closed) {
|
||||
setSerialOpen(true);
|
||||
}
|
||||
|
||||
if (data.log && consoleRef.current) {
|
||||
setConsole((console) => console + data.log)
|
||||
}
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (consoleRef.current)
|
||||
consoleRef.current.scrollTo({ top: consoleRef.current.scrollHeight })
|
||||
}, [consoleContent])
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => {
|
||||
if (!isSerialOpen)
|
||||
sendRPCPacket(RpcMessage.OpenSerialRequest, new OpenSerialRequestT())
|
||||
else
|
||||
clearInterval(id);
|
||||
}, 1000);
|
||||
|
||||
return () => {
|
||||
clearInterval(id);
|
||||
}
|
||||
}, [isSerialOpen, sendRPCPacket])
|
||||
|
||||
const sendWifiCredentials = (value: WifiForm) => {
|
||||
const wifi = new SetWifiRequestT();
|
||||
|
||||
wifi.password = value.password;
|
||||
wifi.ssid = value.ssid;
|
||||
|
||||
sendRPCPacket(RpcMessage.SetWifiRequest, wifi)
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<form className="flex flex-col h-full gap-2" onSubmit={handleSubmit(sendWifiCredentials)}>
|
||||
<div ref={consoleRef} style={{ height: layoutHeight, width: layoutWidth }} className="overflow-x-auto overflow-y-auto flex bg-gray-800 text-white select-text">
|
||||
<pre>
|
||||
{isSerialOpen ? consoleContent : 'Connection to serial lost, Reconnecting...'}
|
||||
</pre>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2 p-3" >
|
||||
<Input {...register('ssid', { required: true })} type="text" placeholder="SSID"></Input>
|
||||
<Input {...register('password', { required: true })} type="password" placeholder="Password"></Input>
|
||||
<Button variant="primary" type="submit">Send</Button>
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import { ChangeSettingsRequestT, FilteringSettingsT, RpcMessage, SettingsRequestT, SettingsResponseT, SteamVRTrackersSettingT } from "solarxr-protocol";
|
||||
import { useWebsocketAPI } from "../../../hooks/websocket-api";
|
||||
import { CheckBox } from "../../commons/Checkbox";
|
||||
import { NumberSelector } from "../../commons/NumberSelector";
|
||||
import { Select } from "../../commons/Select";
|
||||
|
||||
interface SettingsForm {
|
||||
trackers: {
|
||||
waist: boolean,
|
||||
chest: boolean,
|
||||
legs: boolean,
|
||||
knees: boolean,
|
||||
elbows: boolean,
|
||||
}
|
||||
filtering: {
|
||||
type: number;
|
||||
intensity: number;
|
||||
ticks: number;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function TrackersSettings() {
|
||||
|
||||
const { state } = useLocation();
|
||||
const pageRef = useRef<HTMLFormElement | null>(null);
|
||||
|
||||
|
||||
const { sendRPCPacket, useRPCPacket } = useWebsocketAPI();
|
||||
const { register, reset, control, watch, handleSubmit } = useForm<SettingsForm>({ defaultValues: { filtering: { intensity: 0, ticks: 0 } } });
|
||||
|
||||
const onSubmit = (values: SettingsForm) => {
|
||||
const settings = new ChangeSettingsRequestT();
|
||||
|
||||
if (values.trackers) {
|
||||
const trackers = new SteamVRTrackersSettingT();
|
||||
trackers.waist = values.trackers.waist;
|
||||
trackers.chest = values.trackers.chest;
|
||||
trackers.legs = values.trackers.legs;
|
||||
trackers.knees = values.trackers.knees;
|
||||
trackers.elbows = values.trackers.elbows;
|
||||
settings.steamVrTrackers = trackers;
|
||||
}
|
||||
|
||||
const filtering = new FilteringSettingsT();
|
||||
filtering.type = values.filtering.type;
|
||||
filtering.intensity = values.filtering.intensity;
|
||||
filtering.ticks = values.filtering.ticks;
|
||||
|
||||
settings.filtering = filtering;
|
||||
sendRPCPacket(RpcMessage.ChangeSettingsRequest, settings)
|
||||
}
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const subscription = watch(() => handleSubmit(onSubmit)());
|
||||
return () => subscription.unsubscribe();
|
||||
}, [])
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(RpcMessage.SettingsRequest, new SettingsRequestT());
|
||||
}, [])
|
||||
|
||||
useRPCPacket(RpcMessage.SettingsResponse, (settings: SettingsResponseT) => {
|
||||
reset({
|
||||
...(settings.steamVrTrackers ? {trackers: settings.steamVrTrackers} : {}),
|
||||
...(settings.filtering ? {filtering: settings.filtering} : {})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
const typedState: { scrollTo: string } = state as any;
|
||||
|
||||
if (!pageRef.current || (!typedState || !typedState.scrollTo))
|
||||
return ;
|
||||
|
||||
const elem = pageRef.current.querySelector(`#${typedState.scrollTo}`)
|
||||
if (elem)
|
||||
elem.scrollIntoView({ behavior: 'smooth' })
|
||||
}, [state])
|
||||
|
||||
|
||||
return (
|
||||
<form className="px-8 flex flex-col gap-20 py-4" ref={pageRef}>
|
||||
<div className="flex flex-col gap-2" id="steamvr">
|
||||
<div className="flex text-white text-3xl font-bold gap-5">
|
||||
SteamVR Trackers
|
||||
</div>
|
||||
<div className="flex text-gray-300 flex-col">
|
||||
<p>Enable or disable specific tracking parts.</p>
|
||||
<p>Useful if you want more control over what SlimeVR does.</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 text-gray-300 text-xl font-bold gap-5 pt-5">
|
||||
<div className="bg-primary-4 p-3 rounded-md"><CheckBox {...register('trackers.waist')} label="Waist" /></div>
|
||||
<div className="bg-primary-4 p-3 rounded-md"><CheckBox {...register('trackers.chest')} label="Chest"/></div>
|
||||
<div className="bg-primary-4 p-3 rounded-md"><CheckBox {...register('trackers.legs')} label="Legs"/></div>
|
||||
<div className="bg-primary-4 p-3 rounded-md"><CheckBox {...register('trackers.knees')} label="Knees"/></div>
|
||||
<div className="bg-primary-4 p-3 rounded-md"><CheckBox {...register('trackers.elbows')} label="Elbows"/></div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2" id="filtering">
|
||||
<div className="flex text-white text-3xl font-bold gap-5">
|
||||
Filtering
|
||||
</div>
|
||||
<div className="flex text-gray-300 flex-col">
|
||||
<p>I don't know what this does, but I'm</p>
|
||||
<p>designing something for it anyway</p>
|
||||
</div>
|
||||
<div className="flex text-gray-300 text-xl font-bold gap-5 pt-5">
|
||||
<Select {...register('filtering.type')} label="Filtering Type" options={[{ label: 'None', value: 0 }, { label: 'Interpolation', value: 1 }, {label: 'Extrapolation', value: 2 }]}></Select>
|
||||
<NumberSelector variant="smol" control={control} name="filtering.intensity" label="Intensity" valueLabelFormat={(value) => `${value}%`} min={0} max={100} step={10}></NumberSelector>
|
||||
<NumberSelector variant="smol" control={control} name="filtering.ticks" label="Ticks" min={0} max={80} step={1}></NumberSelector>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
@@ -62,7 +62,7 @@ export function TrackerSettings({ tracker, device, children }: { tracker: Tracke
|
||||
|
||||
return (
|
||||
<>
|
||||
<div onClick={openSettings}>
|
||||
<div onClick={openSettings} className="cursor-pointer">
|
||||
{children}
|
||||
</div>
|
||||
<AppModal
|
||||
@@ -73,7 +73,7 @@ export function TrackerSettings({ tracker, device, children }: { tracker: Tracke
|
||||
<form onSubmit={handleSubmit(handleSaveSettings)} className="flex flex-col gap-5">
|
||||
<div className="flex flex-col gap-5">
|
||||
<Select {...register("bodyPosition")} label="Tracker role" options={positions}></Select>
|
||||
<Select {...register("mountingRotation")} label="Mounting Rotation" options={rotations}></Select>
|
||||
<Select {...register("mountingRotation")} label="Mounting rotation" options={rotations}></Select>
|
||||
</div>
|
||||
<div className="flex items-center justify-between">
|
||||
<Button variant="primary" type="submit" >Save</Button>
|
||||
|
||||
+8
-5
@@ -2,23 +2,25 @@ import { useEffect, useRef, useState } from "react";
|
||||
|
||||
|
||||
|
||||
export function useLayout() {
|
||||
export function useLayout<T extends HTMLElement>() {
|
||||
const [layoutHeight, setLayoutHeigt] = useState(window.innerHeight);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const [layoutWidth, setLayoutWidth] = useState(window.innerWidth);
|
||||
const ref = useRef<T | null>(null);
|
||||
|
||||
const computeLayoutHeight = (windowHeight: number) => {
|
||||
const computeLayoutHeight = (windowHeight: number, windowWidth: number) => {
|
||||
if (ref.current) {
|
||||
setLayoutHeigt(windowHeight - ref.current.getBoundingClientRect().top)
|
||||
setLayoutWidth(windowWidth - ref.current.getBoundingClientRect().left)
|
||||
}
|
||||
}
|
||||
|
||||
const onWindowResize = () => {
|
||||
computeLayoutHeight(window.innerHeight)
|
||||
computeLayoutHeight(window.innerHeight, window.innerWidth)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener('resize', onWindowResize);
|
||||
computeLayoutHeight(window.innerHeight)
|
||||
computeLayoutHeight(window.innerHeight, window.innerWidth)
|
||||
return () => {
|
||||
window.removeEventListener('resize', onWindowResize);
|
||||
}
|
||||
@@ -27,6 +29,7 @@ export function useLayout() {
|
||||
|
||||
return {
|
||||
layoutHeight,
|
||||
layoutWidth,
|
||||
ref
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
|
||||
export function usePageScrollTo() {
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user