mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: better ui sizing
This commit is contained in:
1 parent
14fb62bda4
commit
6753a72d97
4 files changed
+202
-149
No files matched your search
@@ -46,115 +46,120 @@ export function RotationInputs({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
gap="2"
|
justify="center"
|
||||||
align="center"
|
align="center"
|
||||||
style={{
|
style={{
|
||||||
|
width: 'calc(100% - 16px)',
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
left: 16,
|
left: 8,
|
||||||
bottom: 16,
|
bottom: 8,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TextField.Root
|
<Flex
|
||||||
variant="surface"
|
gap="2"
|
||||||
style={{
|
style={{
|
||||||
width: 115,
|
width: 352,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TextField.Slot>Hull</TextField.Slot>
|
<TextField.Root
|
||||||
<TextField.Input
|
style={{
|
||||||
defaultValue={Math.round(model.hullYaw * (180 / Math.PI))}
|
flex: 1,
|
||||||
onBlur={() => {
|
|
||||||
const normalized = normalizeAnglePI(
|
|
||||||
-Number(hullYawInput.current?.value) * (Math.PI / 180),
|
|
||||||
);
|
|
||||||
mutateTankopedia((state) => {
|
|
||||||
state.model.hullYaw = normalized;
|
|
||||||
});
|
|
||||||
hullYawInput.current!.value = `${Math.round(normalized)}`;
|
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
>
|
||||||
if (event.key === 'Enter') {
|
<TextField.Slot>Hull</TextField.Slot>
|
||||||
hullYawInput.current?.blur();
|
<TextField.Input
|
||||||
}
|
defaultValue={Math.round(model.hullYaw * (180 / Math.PI))}
|
||||||
}}
|
onBlur={() => {
|
||||||
onFocus={() => hullYawInput.current?.focus()}
|
const normalized = normalizeAnglePI(
|
||||||
ref={hullYawInput}
|
-Number(hullYawInput.current?.value) * (Math.PI / 180),
|
||||||
style={{ textAlign: 'right' }}
|
);
|
||||||
/>
|
mutateTankopedia((state) => {
|
||||||
<TextField.Slot>°</TextField.Slot>
|
state.model.hullYaw = normalized;
|
||||||
</TextField.Root>
|
});
|
||||||
|
hullYawInput.current!.value = `${Math.round(normalized)}`;
|
||||||
|
}}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
hullYawInput.current?.blur();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onFocus={() => hullYawInput.current?.focus()}
|
||||||
|
ref={hullYawInput}
|
||||||
|
style={{ textAlign: 'right' }}
|
||||||
|
/>
|
||||||
|
<TextField.Slot>°</TextField.Slot>
|
||||||
|
</TextField.Root>
|
||||||
|
|
||||||
<TextField.Root
|
<TextField.Root
|
||||||
variant="surface"
|
style={{
|
||||||
style={{
|
flex: 1,
|
||||||
width: 115,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TextField.Slot>Turret</TextField.Slot>
|
|
||||||
<TextField.Input
|
|
||||||
defaultValue={Math.round(model.turretYaw * (180 / Math.PI))}
|
|
||||||
onBlur={() => {
|
|
||||||
const [pitch, yaw] = applyPitchYawLimits(
|
|
||||||
model.gunPitch,
|
|
||||||
-Number(turretYawInput.current?.value) * (Math.PI / 180),
|
|
||||||
gunModelDefinition.pitch,
|
|
||||||
turretModelDefinition.yaw,
|
|
||||||
);
|
|
||||||
mutateTankopedia((state) => {
|
|
||||||
state.model.gunPitch = pitch;
|
|
||||||
state.model.turretYaw = yaw;
|
|
||||||
});
|
|
||||||
turretYawInput.current!.value = `${Math.round(
|
|
||||||
yaw * (180 / Math.PI),
|
|
||||||
)}`;
|
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
>
|
||||||
if (event.key === 'Enter') {
|
<TextField.Slot>Turret</TextField.Slot>
|
||||||
turretYawInput.current?.blur();
|
<TextField.Input
|
||||||
}
|
defaultValue={Math.round(model.turretYaw * (180 / Math.PI))}
|
||||||
}}
|
onBlur={() => {
|
||||||
onFocus={() => turretYawInput.current?.focus()}
|
const [pitch, yaw] = applyPitchYawLimits(
|
||||||
ref={turretYawInput}
|
model.gunPitch,
|
||||||
style={{ textAlign: 'right' }}
|
-Number(turretYawInput.current?.value) * (Math.PI / 180),
|
||||||
/>
|
gunModelDefinition.pitch,
|
||||||
<TextField.Slot>°</TextField.Slot>
|
turretModelDefinition.yaw,
|
||||||
</TextField.Root>
|
);
|
||||||
|
mutateTankopedia((state) => {
|
||||||
|
state.model.gunPitch = pitch;
|
||||||
|
state.model.turretYaw = yaw;
|
||||||
|
});
|
||||||
|
turretYawInput.current!.value = `${Math.round(
|
||||||
|
yaw * (180 / Math.PI),
|
||||||
|
)}`;
|
||||||
|
}}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
turretYawInput.current?.blur();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onFocus={() => turretYawInput.current?.focus()}
|
||||||
|
ref={turretYawInput}
|
||||||
|
style={{ textAlign: 'right' }}
|
||||||
|
/>
|
||||||
|
<TextField.Slot>°</TextField.Slot>
|
||||||
|
</TextField.Root>
|
||||||
|
|
||||||
<TextField.Root
|
<TextField.Root
|
||||||
variant="surface"
|
style={{
|
||||||
style={{
|
flex: 1,
|
||||||
width: 115,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TextField.Slot>Gun</TextField.Slot>
|
|
||||||
<TextField.Input
|
|
||||||
defaultValue={-Math.round(model.gunPitch * (180 / Math.PI))}
|
|
||||||
onBlur={() => {
|
|
||||||
const [pitch, yaw] = applyPitchYawLimits(
|
|
||||||
-Number(gunPitchInput.current?.value) * (Math.PI / 180),
|
|
||||||
model.turretYaw,
|
|
||||||
gunModelDefinition.pitch,
|
|
||||||
turretModelDefinition.yaw,
|
|
||||||
);
|
|
||||||
mutateTankopedia((state) => {
|
|
||||||
state.model.gunPitch = pitch;
|
|
||||||
state.model.turretYaw = yaw;
|
|
||||||
});
|
|
||||||
gunPitchInput.current!.value = `${Math.round(
|
|
||||||
pitch * (180 / Math.PI),
|
|
||||||
)}`;
|
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
>
|
||||||
if (event.key === 'Enter') {
|
<TextField.Slot>Gun</TextField.Slot>
|
||||||
gunPitchInput.current?.blur();
|
<TextField.Input
|
||||||
}
|
defaultValue={-Math.round(model.gunPitch * (180 / Math.PI))}
|
||||||
}}
|
onBlur={() => {
|
||||||
onFocus={() => gunPitchInput.current?.focus()}
|
const [pitch, yaw] = applyPitchYawLimits(
|
||||||
ref={gunPitchInput}
|
-Number(gunPitchInput.current?.value) * (Math.PI / 180),
|
||||||
style={{ textAlign: 'right' }}
|
model.turretYaw,
|
||||||
/>
|
gunModelDefinition.pitch,
|
||||||
<TextField.Slot>°</TextField.Slot>
|
turretModelDefinition.yaw,
|
||||||
</TextField.Root>
|
);
|
||||||
|
mutateTankopedia((state) => {
|
||||||
|
state.model.gunPitch = pitch;
|
||||||
|
state.model.turretYaw = yaw;
|
||||||
|
});
|
||||||
|
gunPitchInput.current!.value = `${Math.round(
|
||||||
|
pitch * (180 / Math.PI),
|
||||||
|
)}`;
|
||||||
|
}}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
gunPitchInput.current?.blur();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onFocus={() => gunPitchInput.current?.focus()}
|
||||||
|
ref={gunPitchInput}
|
||||||
|
style={{ textAlign: 'right' }}
|
||||||
|
/>
|
||||||
|
<TextField.Slot>°</TextField.Slot>
|
||||||
|
</TextField.Root>
|
||||||
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
import {
|
import {
|
||||||
ArrowLeftIcon,
|
ArrowLeftIcon,
|
||||||
CaretRightIcon,
|
CaretRightIcon,
|
||||||
|
EnterFullScreenIcon,
|
||||||
|
ExitFullScreenIcon,
|
||||||
MagnifyingGlassIcon,
|
MagnifyingGlassIcon,
|
||||||
} from '@radix-ui/react-icons';
|
} from '@radix-ui/react-icons';
|
||||||
import {
|
import {
|
||||||
@@ -24,7 +26,7 @@ import { Canvas } from '@react-three/fiber';
|
|||||||
import { go } from 'fuzzysort';
|
import { go } from 'fuzzysort';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { Suspense, use, useRef, useState } from 'react';
|
import { Suspense, use, useEffect, useRef, useState } from 'react';
|
||||||
import { Group, Vector3 } from 'three';
|
import { Group, Vector3 } from 'three';
|
||||||
import { Flag } from '../../../../components/Flag';
|
import { Flag } from '../../../../components/Flag';
|
||||||
import { ModuleButtons } from '../../../../components/ModuleButton';
|
import { ModuleButtons } from '../../../../components/ModuleButton';
|
||||||
@@ -37,7 +39,6 @@ import {
|
|||||||
} from '../../../../core/blitzkrieg/tankDefinitions';
|
} from '../../../../core/blitzkrieg/tankDefinitions';
|
||||||
import { theme } from '../../../../stitches.config';
|
import { theme } from '../../../../stitches.config';
|
||||||
import { Loader } from '../../components/Loader';
|
import { Loader } from '../../components/Loader';
|
||||||
import * as styles from '../page.css';
|
|
||||||
import { Controls } from './components/Control';
|
import { Controls } from './components/Control';
|
||||||
import { RotationInputs } from './components/RotationInputs';
|
import { RotationInputs } from './components/RotationInputs';
|
||||||
import { SceneProps } from './components/SceneProps';
|
import { SceneProps } from './components/SceneProps';
|
||||||
@@ -64,6 +65,8 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
const [versusGun, setVersusGun] = useState(versusTurret.guns.at(-1)!);
|
const [versusGun, setVersusGun] = useState(versusTurret.guns.at(-1)!);
|
||||||
const [versusTankTab, setVersusTankTab] = useState('search');
|
const [versusTankTab, setVersusTankTab] = useState('search');
|
||||||
const canvas = useRef<HTMLCanvasElement>(null);
|
const canvas = useRef<HTMLCanvasElement>(null);
|
||||||
|
const canvasWrapper = useRef<HTMLDivElement>(null);
|
||||||
|
const [isFullScreen, setIsFullScreen] = useState(false);
|
||||||
|
|
||||||
function handlePointerDown() {
|
function handlePointerDown() {
|
||||||
window.addEventListener('pointermove', handlePointerMove);
|
window.addEventListener('pointermove', handlePointerMove);
|
||||||
@@ -79,6 +82,18 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
window.removeEventListener('pointerup', handlePointerUp);
|
window.removeEventListener('pointerup', handlePointerUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function handleFullScreenChange() {
|
||||||
|
setIsFullScreen(document.fullscreenElement !== null);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('fullscreenchange', handleFullScreenChange);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('fullscreenchange', handleFullScreenChange);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageWrapper color="purple">
|
<PageWrapper color="purple">
|
||||||
<Flex gap="8" direction="column">
|
<Flex gap="8" direction="column">
|
||||||
@@ -90,7 +105,7 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
>
|
>
|
||||||
<Flex gap="1" align="center">
|
<Flex gap="1" align="center">
|
||||||
<ArrowLeftIcon />
|
<ArrowLeftIcon />
|
||||||
<Text>Back to tankopedia</Text>
|
<Text>Back</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
@@ -100,59 +115,91 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
</Flex>
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
<Card style={{ position: 'relative' }}>
|
<Theme radius={isFullScreen ? 'none' : undefined}>
|
||||||
<Flex direction="column" gap="2">
|
<Card
|
||||||
<Tabs.Root value={mode} onValueChange={setMode}>
|
style={{
|
||||||
<Tabs.List>
|
position: 'relative',
|
||||||
<Tabs.Trigger value="model">Model</Tabs.Trigger>
|
border: isFullScreen ? 'none' : 'unset',
|
||||||
<Tabs.Trigger value="armor">Armor</Tabs.Trigger>
|
}}
|
||||||
</Tabs.List>
|
ref={canvasWrapper}
|
||||||
</Tabs.Root>
|
>
|
||||||
|
<Theme radius="full" style={{ height: '100%' }}>
|
||||||
<div style={{ height: '50vh', maxHeight: 576 }}>
|
<Flex
|
||||||
<Canvas
|
style={{
|
||||||
shadows
|
height: isFullScreen ? '100%' : '75vh',
|
||||||
ref={canvas}
|
maxHeight: isFullScreen ? 'unset' : 576,
|
||||||
camera={{ fov: 20 }}
|
}}
|
||||||
onPointerDown={handlePointerDown}
|
direction="column"
|
||||||
|
gap="2"
|
||||||
>
|
>
|
||||||
<Controls />
|
<Tabs.Root value={mode} onValueChange={setMode}>
|
||||||
<SceneProps />
|
<Tabs.List>
|
||||||
|
<Tabs.Trigger value="model">Model</Tabs.Trigger>
|
||||||
|
<Tabs.Trigger value="armor">Armor</Tabs.Trigger>
|
||||||
|
</Tabs.List>
|
||||||
|
</Tabs.Root>
|
||||||
|
|
||||||
<Suspense
|
<div style={{ height: '100%' }}>
|
||||||
fallback={
|
<Canvas
|
||||||
<Html center position={[0, 1.5, 0]}>
|
shadows
|
||||||
<Loader
|
ref={canvas}
|
||||||
naked
|
camera={{ fov: 20 }}
|
||||||
color={theme.colors.textHighContrast_purple}
|
onPointerDown={handlePointerDown}
|
||||||
|
>
|
||||||
|
<Controls />
|
||||||
|
<SceneProps />
|
||||||
|
|
||||||
|
<Suspense
|
||||||
|
fallback={
|
||||||
|
<Html center position={[0, 1.5, 0]}>
|
||||||
|
<Loader
|
||||||
|
naked
|
||||||
|
color={theme.colors.textHighContrast_purple}
|
||||||
|
/>
|
||||||
|
</Html>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<TankModel
|
||||||
|
gunId={gun.id}
|
||||||
|
tankId={tank.id}
|
||||||
|
turretId={turret.id}
|
||||||
|
ref={hullContainer}
|
||||||
/>
|
/>
|
||||||
</Html>
|
</Suspense>
|
||||||
}
|
</Canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 18,
|
||||||
|
right: 18,
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
if (isFullScreen) {
|
||||||
|
document.exitFullscreen();
|
||||||
|
} else {
|
||||||
|
canvasWrapper.current?.requestFullscreen();
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<TankModel
|
{isFullScreen ? (
|
||||||
gunId={gun.id}
|
<ExitFullScreenIcon />
|
||||||
tankId={tank.id}
|
) : (
|
||||||
turretId={turret.id}
|
<EnterFullScreenIcon />
|
||||||
ref={hullContainer}
|
)}
|
||||||
/>
|
</Button>
|
||||||
</Suspense>
|
|
||||||
</Canvas>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{mode === 'armor' && (
|
<RotationInputs
|
||||||
<Flex gap="2" align="center" className={styles.enhancedArmor}>
|
gunId={gun.id}
|
||||||
<Checkbox defaultChecked />
|
tankId={tank.id}
|
||||||
<Text>Enhanced armor</Text>
|
turretId={turret.id}
|
||||||
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
)}
|
</Theme>
|
||||||
|
</Card>
|
||||||
<RotationInputs
|
</Theme>
|
||||||
gunId={gun.id}
|
|
||||||
tankId={tank.id}
|
|
||||||
turretId={turret.id}
|
|
||||||
/>
|
|
||||||
</Flex>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<Theme radius="small">
|
<Theme radius="small">
|
||||||
<Flex gap="4">
|
<Flex gap="4">
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export const listingImage = style({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const enhancedArmor = style({
|
export const alignTopRight = style({
|
||||||
'@media': {
|
'@media': {
|
||||||
'screen and (min-width: 400px)': {
|
'screen and (min-width: 400px)': {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
TextField,
|
TextField,
|
||||||
} from '@radix-ui/themes';
|
} from '@radix-ui/themes';
|
||||||
import { go } from 'fuzzysort';
|
import { go } from 'fuzzysort';
|
||||||
|
import Link from 'next/link';
|
||||||
import { Suspense, use, useEffect, useMemo, useRef, useState } from 'react';
|
import { Suspense, use, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import PageWrapper from '../../../components/PageWrapper';
|
import PageWrapper from '../../../components/PageWrapper';
|
||||||
import { asset } from '../../../core/blitzkrieg/asset';
|
import { asset } from '../../../core/blitzkrieg/asset';
|
||||||
@@ -198,7 +199,7 @@ export default function Page() {
|
|||||||
<Flex wrap="wrap" gap="3" justify="center">
|
<Flex wrap="wrap" gap="3" justify="center">
|
||||||
{searchedList
|
{searchedList
|
||||||
.map((tank) => (
|
.map((tank) => (
|
||||||
<a
|
<Link
|
||||||
key={tank.id}
|
key={tank.id}
|
||||||
href={`/tools/tankopedia/${tank.id}`}
|
href={`/tools/tankopedia/${tank.id}`}
|
||||||
style={{
|
style={{
|
||||||
@@ -309,7 +310,7 @@ export default function Page() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
</Inset>
|
</Inset>
|
||||||
</Card>
|
</Card>
|
||||||
</a>
|
</Link>
|
||||||
))
|
))
|
||||||
.slice(page * TANKS_PER_PAGE, (page + 1) * TANKS_PER_PAGE)}
|
.slice(page * TANKS_PER_PAGE, (page + 1) * TANKS_PER_PAGE)}
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
Reference in new issue
Block a user