85 lines
7.1 KiB
TypeScript
85 lines
7.1 KiB
TypeScript
/** 用户端保留取景画面、血量和链路读数;调整入口统一放在 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<ViewTransform>(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 <div className="op cockpit">
|
||
<div className="op__stage" ref={control.target}>
|
||
<VideoSurface camera={camera} label="" emptyText={emptyText} signalLost={!hasVideo}
|
||
mirrored={snapshot.mirrored} mirroredVertical={snapshot.mirroredVertical} crosshair={hasVideo ? hud.crosshair : null} grid={hasVideo ? hud.grid : null} view={view} onView={setView}
|
||
calibrating={calibrating} inputCaptured={control.activeMode !== null || control.pending} onCalibrate={calibrating ? onCalibrate : undefined} hit={pulse} hitFeedback={hud.hitFeedback} showZoom={hud.showZoom} showResetControl={false}>
|
||
<div className="cockpit__overlay">
|
||
<div className="cockpit__health">
|
||
{hud.health.visible && mine && <div className="cockpit__health-side"><HealthBar health={mine} config={healthConfig} align="left" tag={healthTag(mine, snapshot.team)} /></div>}
|
||
<TeamMatchClock snapshot={snapshot} />
|
||
{hud.health.visible && theirs && <div className="cockpit__health-side cockpit__health-side--right"><HealthBar health={theirs} config={healthConfig} align="right" tag={healthTag(theirs, snapshot.team)} /></div>}
|
||
</div>
|
||
<div className="cockpit__header">
|
||
<div className="cockpit__identity"><span className="label">RMIC / OPERATOR</span><span title={myName}>{myName}</span>{snapshot.demo && <b>演示 · 合成数据</b>}</div>
|
||
<div className="cockpit__links" aria-label="连接状态">
|
||
<span className={cameraLive ? "is-live" : "is-offline"}><i />图传 <b>{cameraState}</b></span>
|
||
<span className={armorLive ? "is-live" : "is-offline"}><i />装甲板 <b>{armorState}</b></span>
|
||
</div>
|
||
</div>
|
||
<div className="cockpit__frame" aria-hidden="true"><i /><i /><i /><i /></div>
|
||
<div className="cockpit__telemetry">
|
||
<div className="cockpit__feed"><span className="label">VIDEO SOURCE</span><strong className="num">{camera === null ? "NO BINDING" : boundCamera?.idText ?? idText(camera)}</strong><span>{cameraLive && stats?.hasFrames ? `${stats.width} × ${stats.height}${snapshot.mirrored ? " / 左右镜像" : ""}${snapshot.mirroredVertical ? " / 上下镜像" : ""}` : "等待图传连接"}</span></div>
|
||
<div className="cockpit__fps"><span className="label">RECEIVE / FPS</span><strong className="num">{cameraLive && stats?.hasFrames ? stats.fps.toFixed(1) : "—"}</strong>{hud.showStats && snapshot.diagnostics && <span>丢包 {cameraLive && stats?.hasFrames ? `${stats.lossPercent.toFixed(1)}%` : "—"}</span>}</div>
|
||
</div>
|
||
<div className="cockpit__footer"><span><kbd>ESC</kbd> 菜单 / 设置</span><span className="num">{calibrating ? "瞄准校准中" : hud.showZoom ? `OPTICAL ×${view.zoom.toFixed(1)}` : ""}</span><span>{snapshot.config.armorId === null ? "ARMOR / —" : `ARMOR / ${board?.idText ?? idText(snapshot.config.armorId)}`}</span></div>
|
||
</div>
|
||
<MatchBanner outcome={mine?.outcome ?? null} mine={myName} theirs={theirName} detail={mine?.outcome === "defeat" && theirs?.hp != null ? `对手剩余 ${theirs.hp}` : mine?.outcome === "victory" && mine?.hp != null ? `剩余 ${mine.hp}` : undefined} />
|
||
<HitFlash hit={lastHit} config={hud.hitFeedback} relevant={hitIsMine} />
|
||
<TeamMatchCountdown snapshot={snapshot} />
|
||
<OperatorControls control={control} snapshot={snapshot} connected={connected} blocked={controlsBlocked || calibrating} />
|
||
{boundCamera && !boundCamera.compatible && <div className="fwfault" role="alert"><span className="fwfault__tag label">协议不匹配</span><span className="fwfault__text">图传固件 {firmwareLabel(boundCamera)} · 协议 {boundCamera.protocol} / 客户端 {BUILD.protocol}。按 ESC 进入固件维护。</span></div>}
|
||
</VideoSurface>
|
||
</div>
|
||
</div>;
|
||
}
|