mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-26 20:19:50 +01:00
feat: screenshot button
This commit is contained in:
1 parent
8bc4eab2c0
commit
ece0791a08
3 files changed
+48
-15
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
import { ChevronLeftIcon, MixIcon } from '@radix-ui/react-icons';
|
import { ChevronLeftIcon, MixIcon } from '@radix-ui/react-icons';
|
||||||
import { Box, Button, Flex, Heading, Text } from '@radix-ui/themes';
|
import { Box, Button, Flex, Heading, Text } from '@radix-ui/themes';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { Suspense, use, useEffect, useMemo, useState } from 'react';
|
import { Suspense, use, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { classIcons } from '../../../../../../components/ClassIcon';
|
import { classIcons } from '../../../../../../components/ClassIcon';
|
||||||
import { ScienceIcon } from '../../../../../../components/ScienceIcon';
|
import { ScienceIcon } from '../../../../../../components/ScienceIcon';
|
||||||
import { ThicknessRange } from '../../../../../../components/StaticArmor';
|
import { ThicknessRange } from '../../../../../../components/StaticArmor';
|
||||||
@@ -20,6 +20,7 @@ interface HeroSectionProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function HeroSection({ id }: HeroSectionProps) {
|
export function HeroSection({ id }: HeroSectionProps) {
|
||||||
|
const canvas = useRef<HTMLCanvasElement>(null);
|
||||||
const protagonist = Duel.use((state) => state.protagonist.tank);
|
const protagonist = Duel.use((state) => state.protagonist.tank);
|
||||||
const antagonist = Duel.use((state) => state.antagonist.tank);
|
const antagonist = Duel.use((state) => state.antagonist.tank);
|
||||||
const compareTanks =
|
const compareTanks =
|
||||||
@@ -169,11 +170,11 @@ export function HeroSection({ id }: HeroSectionProps) {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<TankSandbox thicknessRange={thicknessRange} />
|
<TankSandbox ref={canvas} thicknessRange={thicknessRange} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Options thicknessRange={thicknessRange} />
|
<Options canvas={canvas} thicknessRange={thicknessRange} />
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import { Canvas } from '@react-three/fiber';
|
import { Canvas } from '@react-three/fiber';
|
||||||
import { Suspense, useEffect, useRef } from 'react';
|
import {
|
||||||
|
forwardRef,
|
||||||
|
Suspense,
|
||||||
|
useEffect,
|
||||||
|
useImperativeHandle,
|
||||||
|
useRef,
|
||||||
|
} from 'react';
|
||||||
import { Armor } from '../../../../../../components/Armor';
|
import { Armor } from '../../../../../../components/Armor';
|
||||||
import { ArmorPlateDisplay } from '../../../../../../components/Armor/components/ArmorPlateDisplay';
|
import { ArmorPlateDisplay } from '../../../../../../components/Armor/components/ArmorPlateDisplay';
|
||||||
import { ShotDisplay } from '../../../../../../components/Armor/components/ShotDisplay';
|
import { ShotDisplay } from '../../../../../../components/Armor/components/ShotDisplay';
|
||||||
@@ -26,7 +32,8 @@ interface TankSandboxProps {
|
|||||||
thicknessRange: ThicknessRange;
|
thicknessRange: ThicknessRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TankSandbox({ thicknessRange }: TankSandboxProps) {
|
export const TankSandbox = forwardRef<HTMLCanvasElement, TankSandboxProps>(
|
||||||
|
({ thicknessRange }, ref) => {
|
||||||
const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation();
|
const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation();
|
||||||
const canvas = useRef<HTMLCanvasElement>(null);
|
const canvas = useRef<HTMLCanvasElement>(null);
|
||||||
const hasImprovedVerticalStabilizer = useEquipment(122);
|
const hasImprovedVerticalStabilizer = useEquipment(122);
|
||||||
@@ -38,6 +45,8 @@ export function TankSandbox({ thicknessRange }: TankSandboxProps) {
|
|||||||
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
||||||
const display = TankopediaPersistent.use((state) => state.display);
|
const display = TankopediaPersistent.use((state) => state.display);
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => canvas.current!, []);
|
||||||
|
|
||||||
function handlePointerDown() {
|
function handlePointerDown() {
|
||||||
window.addEventListener('pointermove', handlePointerMove);
|
window.addEventListener('pointermove', handlePointerMove);
|
||||||
window.addEventListener('pointerup', handlePointerUp);
|
window.addEventListener('pointerup', handlePointerUp);
|
||||||
@@ -146,7 +155,11 @@ export function TankSandbox({ thicknessRange }: TankSandboxProps) {
|
|||||||
return (
|
return (
|
||||||
<Canvas
|
<Canvas
|
||||||
frameloop="demand"
|
frameloop="demand"
|
||||||
gl={{ clippingPlanes: Object.freeze([]), localClippingEnabled: true }}
|
gl={{
|
||||||
|
clippingPlanes: Object.freeze([]),
|
||||||
|
localClippingEnabled: true,
|
||||||
|
preserveDrawingBuffer: true,
|
||||||
|
}}
|
||||||
shadows
|
shadows
|
||||||
ref={canvas}
|
ref={canvas}
|
||||||
onPointerDown={handlePointerDown}
|
onPointerDown={handlePointerDown}
|
||||||
@@ -176,4 +189,5 @@ export function TankSandbox({ thicknessRange }: TankSandboxProps) {
|
|||||||
</Suspense>
|
</Suspense>
|
||||||
</Canvas>
|
</Canvas>
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
);
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
CameraIcon,
|
||||||
EnterFullScreenIcon,
|
EnterFullScreenIcon,
|
||||||
ExitFullScreenIcon,
|
ExitFullScreenIcon,
|
||||||
EyeOpenIcon,
|
EyeOpenIcon,
|
||||||
@@ -19,7 +20,7 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
} from '@radix-ui/themes';
|
} from '@radix-ui/themes';
|
||||||
import { invalidate } from '@react-three/fiber';
|
import { invalidate } from '@react-three/fiber';
|
||||||
import { useEffect, useState } from 'react';
|
import { RefObject, useEffect, useState } from 'react';
|
||||||
import { ModuleButton } from '../../../../../../../components/ModuleButtons/ModuleButton';
|
import { ModuleButton } from '../../../../../../../components/ModuleButtons/ModuleButton';
|
||||||
import { SmallTankIcon } from '../../../../../../../components/SmallTankIcon';
|
import { SmallTankIcon } from '../../../../../../../components/SmallTankIcon';
|
||||||
import { ThicknessRange } from '../../../../../../../components/StaticArmor';
|
import { ThicknessRange } from '../../../../../../../components/StaticArmor';
|
||||||
@@ -45,9 +46,10 @@ import { Thicknesses } from '../../Thicknesses';
|
|||||||
|
|
||||||
interface OptionsProps {
|
interface OptionsProps {
|
||||||
thicknessRange: ThicknessRange;
|
thicknessRange: ThicknessRange;
|
||||||
|
canvas: RefObject<HTMLCanvasElement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Options({ thicknessRange }: OptionsProps) {
|
export function Options({ thicknessRange, canvas }: OptionsProps) {
|
||||||
const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation();
|
const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation();
|
||||||
const mutateTankopediaPersistent = TankopediaPersistent.useMutation();
|
const mutateTankopediaPersistent = TankopediaPersistent.useMutation();
|
||||||
const displayRaw = TankopediaPersistent.use((state) => state.display);
|
const displayRaw = TankopediaPersistent.use((state) => state.display);
|
||||||
@@ -73,6 +75,7 @@ export function Options({ thicknessRange }: OptionsProps) {
|
|||||||
(state) => state.model.visual.environment,
|
(state) => state.model.visual.environment,
|
||||||
);
|
);
|
||||||
const developerMode = App.useDeferred(false, (state) => state.developerMode);
|
const developerMode = App.useDeferred(false, (state) => state.developerMode);
|
||||||
|
const protagonist = Duel.use((state) => state.protagonist.tank);
|
||||||
const antagonistGun = Duel.use((state) => state.antagonist.gun);
|
const antagonistGun = Duel.use((state) => state.antagonist.gun);
|
||||||
const antagonistShell = Duel.use((state) => state.antagonist.shell);
|
const antagonistShell = Duel.use((state) => state.antagonist.shell);
|
||||||
const [antagonistSelectorOpen, setAntagonistSelectorOpen] = useState(false);
|
const [antagonistSelectorOpen, setAntagonistSelectorOpen] = useState(false);
|
||||||
@@ -122,12 +125,9 @@ export function Options({ thicknessRange }: OptionsProps) {
|
|||||||
<Flex
|
<Flex
|
||||||
gap="2"
|
gap="2"
|
||||||
direction="column"
|
direction="column"
|
||||||
style={{
|
top="50%"
|
||||||
position: 'absolute',
|
right="3"
|
||||||
right: 16,
|
style={{ position: 'absolute', transform: 'translateY(-50%)' }}
|
||||||
top: '50%',
|
|
||||||
transform: 'translateY(-50%)',
|
|
||||||
}}
|
|
||||||
align="end"
|
align="end"
|
||||||
>
|
>
|
||||||
<Text color="gray" size={{ initial: '1', sm: '2' }}>
|
<Text color="gray" size={{ initial: '1', sm: '2' }}>
|
||||||
@@ -302,6 +302,24 @@ export function Options({ thicknessRange }: OptionsProps) {
|
|||||||
</Flex>
|
</Flex>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<Box position="absolute" bottom="3" right="3">
|
||||||
|
<IconButton
|
||||||
|
size="3"
|
||||||
|
variant="soft"
|
||||||
|
onClick={() => {
|
||||||
|
if (!canvas.current) return;
|
||||||
|
|
||||||
|
const anchor = document.createElement('a');
|
||||||
|
|
||||||
|
anchor.setAttribute('download', `${protagonist.name}.png`);
|
||||||
|
anchor.setAttribute('href', canvas.current.toDataURL('image/png'));
|
||||||
|
anchor.click();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CameraIcon />
|
||||||
|
</IconButton>
|
||||||
|
</Box>
|
||||||
|
|
||||||
<Flex
|
<Flex
|
||||||
style={{
|
style={{
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
|||||||
Reference in new issue
Block a user