feat(match): 添加画面上下镜像、跳过准备和装甲板整局复位
This commit is contained in:
39 files changed
+1094
-54
No files matched your search
@@ -4,7 +4,7 @@ import { useCallback, useEffect, useMemo, useRef, useState, type KeyboardEvent }
|
||||
import { api } from "../lib/ipc";
|
||||
import { BUILD, VERSION_LABEL } from "../lib/version";
|
||||
import { firmwareLabel, teamName } from "../lib/format";
|
||||
import { paintCrosshair, paintGrid, type Geometry } from "../lib/reticle";
|
||||
import { aimPoint, paintCrosshair, paintGrid, type Geometry } from "../lib/reticle";
|
||||
import type { ConfigView, CrosshairConfig, HudView, Snapshot, TeamHealthDto } from "../lib/types";
|
||||
import { Button, Field, Select, Slider, Switch } from "./controls";
|
||||
import { HealthBar } from "./HealthBar";
|
||||
@@ -156,6 +156,10 @@ export function SettingsPanel({ snapshot, hud, onHud, calibrating, onCalibrating
|
||||
const board = snapshot.armorBoards.find(item => item.id === config.armorId);
|
||||
const cameraState = !connected ? "本地通道断开" : config.cameraId === null ? "未绑定" : !camera?.online ? "离线" : !camera.compatible ? "协议不匹配" : cameraStats?.online && cameraStats.hasFrames ? "正在接收" : "已发现 · 等待画面";
|
||||
const armorState = !connected ? "本地通道断开" : config.armorId === null ? "未绑定" : !board?.online ? "离线" : board.team === 255 ? "等待队伍设置" : board.team !== config.team ? "队伍不匹配" : "在线";
|
||||
const mirrorControls = <>
|
||||
<Switch checked={config.mirror} label="左右镜像画面" onChange={mirror => void run(() => api.setMirror(mirror))} />
|
||||
<Switch checked={config.mirrorVertical} label="上下镜像画面" onChange={mirror => void run(() => api.setMirrorVertical(mirror))} />
|
||||
</>;
|
||||
|
||||
const content = () => {
|
||||
switch (current.id) {
|
||||
@@ -185,7 +189,7 @@ export function SettingsPanel({ snapshot, hud, onHud, calibrating, onCalibrating
|
||||
{ value: 1, label: `${teamName(1, config.teamNames)}(蓝)` },
|
||||
]} onChange={team => void run(() => api.setTeam(team))} />
|
||||
</Field>
|
||||
<Switch checked={config.mirror} label="左右镜像画面" onChange={mirror => void run(() => api.setMirror(mirror))} />
|
||||
{mirrorControls}
|
||||
<div className="settings__device-state settings__span" aria-live="polite">
|
||||
<span><b>图传</b><strong>{config.cameraIdText ?? "—"}</strong><em>{cameraState}</em></span>
|
||||
<span><b>装甲板</b><strong>{config.armorIdText ?? "—"}</strong><em>{armorState}</em></span>
|
||||
@@ -228,6 +232,7 @@ export function SettingsPanel({ snapshot, hud, onHud, calibrating, onCalibrating
|
||||
{snapshot.diagnostics && <Switch checked={hud.showStats} label="显示丢包率(诊断模式)" onChange={showStats => update(draft => { draft.showStats = showStats; })} />}
|
||||
</>;
|
||||
case "slots": return <>
|
||||
{mirrorControls}
|
||||
<div className="settings__span"><Switch checked={snapshot.slots.manual} label="手动指定槽位" onChange={manual => void run(() => api.setRefereeSlots({ ...snapshot.slots, manual }))} /></div>
|
||||
<Field label={`左格 · ${teamName(0, config.teamNames)} 图传`}><Select value={snapshot.slots.cameraA} options={cameraOptions} disabled={!snapshot.slots.manual} onChange={cameraA => void run(() => api.setRefereeSlots({ ...snapshot.slots, cameraA, manual: true }))} /></Field>
|
||||
<Field label={`右格 · ${teamName(1, config.teamNames)} 图传`}><Select value={snapshot.slots.cameraB} options={cameraOptions} disabled={!snapshot.slots.manual} onChange={cameraB => void run(() => api.setRefereeSlots({ ...snapshot.slots, cameraB, manual: true }))} /></Field>
|
||||
@@ -288,7 +293,7 @@ export function SettingsPanel({ snapshot, hud, onHud, calibrating, onCalibrating
|
||||
<div className="settings__page-head"><span className="label">{current.en}</span><h2>{current.label}</h2><p>{current.hint}</p></div>
|
||||
<div className="settings__workspace">
|
||||
<fieldset className="settings__form" disabled={locked || closing}>{content()}</fieldset>
|
||||
{current.preview && <Preview hud={hud} team={snapshot.team} />}
|
||||
{current.preview && <Preview hud={hud} team={snapshot.team} mirrored={config.mirror} mirroredVertical={config.mirrorVertical} />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -307,7 +312,7 @@ export function SettingsPanel({ snapshot, hud, onHud, calibrating, onCalibrating
|
||||
*
|
||||
* 血量那根滑杆是刻意加的:低血阈值与脉动只有真的把血拖下去才看得见。
|
||||
*/
|
||||
function Preview({ hud, team }: { hud: HudView; team: number }) {
|
||||
function Preview({ hud, team, mirrored, mirroredVertical }: { hud: HudView; team: number; mirrored: boolean; mirroredVertical: boolean }) {
|
||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||
const [demoHp, setDemoHp] = useState(68);
|
||||
|
||||
@@ -329,6 +334,9 @@ function Preview({ hud, team }: { hud: HudView; team: number }) {
|
||||
|
||||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
ctx.save();
|
||||
ctx.translate(mirrored ? width : 0, mirroredVertical ? height : 0);
|
||||
ctx.scale(mirrored ? -1 : 1, mirroredVertical ? -1 : 1);
|
||||
|
||||
// 伪画面:一块低饱和的远景色 + 一条地平线。它的作用是让准星与网格有一个"深色背景
|
||||
// 之上"的参照,而不是浮在一片纯黑里看不出对比。
|
||||
@@ -354,12 +362,12 @@ function Preview({ hud, team }: { hud: HudView; team: number }) {
|
||||
};
|
||||
|
||||
if (hud.grid.visible) paintGrid(ctx, geometry, hud.grid);
|
||||
ctx.restore();
|
||||
|
||||
if (hud.crosshair.visible) {
|
||||
// 预览里的偏移按比例缩到这块小画布上,方向与真画面一致。
|
||||
const cx = width * (0.5 + hud.crosshair.offsetX);
|
||||
const cy = height * (0.5 + hud.crosshair.offsetY);
|
||||
paintCrosshair(ctx, cx, cy, Math.min(width, height), hud.crosshair);
|
||||
const aim = aimPoint(geometry, hud.crosshair, mirrored, width, height, mirroredVertical);
|
||||
paintCrosshair(ctx, aim.x, aim.y, Math.min(width, height), hud.crosshair);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -374,7 +382,7 @@ function Preview({ hud, team }: { hud: HudView; team: number }) {
|
||||
cancelAnimationFrame(raf);
|
||||
observer.disconnect();
|
||||
};
|
||||
}, [hud]);
|
||||
}, [hud, mirrored, mirroredVertical]);
|
||||
|
||||
// 预览用的血量。`available` 恒为 true:占位符的形态在真画面上看更清楚。
|
||||
const mock: TeamHealthDto = {
|
||||
|
||||
Reference in new issue
Block a user