/** 用户端保留取景画面、血量和链路读数;调整入口统一放在 ESC 菜单。 */ import { useState } from "react"; import { IDENTITY_VIEW, VideoSurface, type ViewTransform } from "../components/VideoSurface"; import { HealthBar, healthTag } from "../components/HealthBar"; import { HitFlash } from "../components/HitFlash"; import { MatchBanner } from "../components/MatchBanner"; import { TeamMatchClock, TeamMatchCountdown } from "../components/MatchClock"; import { firmwareLabel, teamName, idText } from "../lib/format"; import { useAppStore } from "../lib/store"; import { BUILD } from "../lib/version"; import type { HudView, Snapshot } from "../lib/types"; import { useOperatorControl } from "../lib/use-operator-control"; import { OperatorControls } from "../components/OperatorControls"; interface Props { snapshot: Snapshot; hud: HudView; calibrating: boolean; controlsBlocked: boolean; onCalibrate: (dxFraction: number, dyFraction: number) => void; } export function TeamPage({ snapshot, hud, calibrating, controlsBlocked, onCalibrate }: Props) { const [view, setView] = useState(IDENTITY_VIEW); const { lastHit, connected } = useAppStore(); const control = useOperatorControl({ snapshot, connected, blocked: controlsBlocked || calibrating }); const camera = snapshot.config.cameraId; const stats = snapshot.stats.find(entry => entry.camera === camera); const boundCamera = snapshot.cameras.find(entry => entry.id === camera); const board = snapshot.armorBoards.find(entry => entry.id === snapshot.config.armorId); const mine = snapshot.health.find(entry => entry.team === snapshot.team) ?? null; const theirs = snapshot.health.find(entry => entry.team !== snapshot.team) ?? null; const myName = mine?.name ?? teamName(snapshot.team, snapshot.config.teamNames); const theirName = theirs?.name ?? teamName(snapshot.team === 0 ? 1 : 0, snapshot.config.teamNames); const cameraLive = connected && !!boundCamera?.online && !!stats?.online && boundCamera.compatible; const armorLive = connected && !!board?.online && board.team === snapshot.team; const cameraState = camera === null ? "未绑定" : !connected ? "服务断开" : boundCamera && !boundCamera.compatible ? "协议不匹配" : cameraLive ? (stats?.hasFrames ? "接收中" : "等待画面") : "离线"; const armorState = snapshot.config.armorId === null ? "未绑定" : !connected ? "服务断开" : board?.team === 255 ? "等待队伍设置" : board && board.team !== snapshot.team ? "队伍不符" : armorLive ? "在线" : "离线"; const hitIsMine = Boolean(lastHit && (mine?.board != null ? lastHit.board === mine.board : lastHit.team === snapshot.team)); const pulse = hitIsMine && lastHit ? { seq: lastHit.seq, damage: lastHit.damage, at: lastHit.receivedAt } : null; // 两侧各自使用独立列;放大血条也不能跨过中线压住对方。 const healthConfig = { ...hud.health, width: Math.min(1, hud.health.width * 2) }; const hasVideo = cameraLive && !!stats?.hasFrames; const emptyText = camera === null ? "未绑定图传板 · 按 ESC 配置" : !connected ? "本机服务断开,正在重连" : !boundCamera ? "尚未发现绑定的图传板 · 按 ESC 检查设备" : !boundCamera.compatible ? "图传协议不匹配 · 按 ESC 检查固件" : !cameraLive ? "图传板离线,等待重新连接" : !stats?.hasFrames ? "已连接,等待画面" : ""; return
{hud.health.visible && mine &&
} {hud.health.visible && theirs &&
}
RMIC / OPERATOR{myName}{snapshot.demo && 演示 · 合成数据}
图传 {cameraState} 装甲板 {armorState}
VIDEO SOURCE{camera === null ? "NO BINDING" : boundCamera?.idText ?? idText(camera)}{cameraLive && stats?.hasFrames ? `${stats.width} × ${stats.height}${snapshot.mirrored ? " / 左右镜像" : ""}${snapshot.mirroredVertical ? " / 上下镜像" : ""}` : "等待图传连接"}
RECEIVE / FPS{cameraLive && stats?.hasFrames ? stats.fps.toFixed(1) : "—"}{hud.showStats && snapshot.diagnostics && 丢包 {cameraLive && stats?.hasFrames ? `${stats.lossPercent.toFixed(1)}%` : "—"}}
ESC 菜单 / 设置{calibrating ? "瞄准校准中" : hud.showZoom ? `OPTICAL ×${view.zoom.toFixed(1)}` : ""}{snapshot.config.armorId === null ? "ARMOR / —" : `ARMOR / ${board?.idText ?? idText(snapshot.config.armorId)}`}
{boundCamera && !boundCamera.compatible &&
协议不匹配图传固件 {firmwareLabel(boundCamera)} · 协议 {boundCamera.protocol} / 客户端 {BUILD.protocol}。按 ESC 进入固件维护。
}
; }