2879 lines
113 KiB
C#
2879 lines
113 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using Godot;
|
|
using RustToDust.Core;
|
|
using RustToDust.HbGpu;
|
|
|
|
namespace RustToDust.Client;
|
|
|
|
public enum HitMarkerKind
|
|
{
|
|
None = 0,
|
|
Armor = 1,
|
|
Core = 2,
|
|
Kill = 3
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rust to Dust industrial HUD rendered in a single Vulkan draw call via <see cref="HbGpuCanvas"/>:
|
|
/// - Top-Left: Chassis badge (DORSAL/CORONAL), Core HP bar, Speed/Alt/Alive/Kills, Safe Circle, Detection, Wave, Net, Prompt.
|
|
/// - Top-Right: Tactical Radar (Safe Circle, RadarSignature-scaled Spectator Wall, lock lines, contenders, salvage).
|
|
/// - Bottom-Left: Live clickable Aetheria Hardpoint & Heat Schematic + Cargo Salvage Rack (Tab expands Garage details).
|
|
/// - Bottom-Right: Imperial Broadcast Chyron (Weksa commentary).
|
|
/// - Center & 3D World: Crosshair + heat arc + incoming/outgoing hit feedback + squad chevrons + target boxes + offscreen arrows.
|
|
/// </summary>
|
|
public partial class Hud : CanvasLayer
|
|
{
|
|
private static readonly Color BgDark = new(0.075f, 0.086f, 0.075f, 0.88f);
|
|
private static readonly Color BgInner = Color.FromHtml("#1b1f1b");
|
|
private static readonly Color BgRowHover = new(0.16f, 0.20f, 0.16f, 0.92f);
|
|
private static readonly Color BorderCol = Color.FromHtml("#3e4638");
|
|
private static readonly Color OliveCol = Color.FromHtml("#9bb06a");
|
|
private static readonly Color OrangeCol = Color.FromHtml("#e08a4a");
|
|
private static readonly Color TextLight = Color.FromHtml("#e4dfd2");
|
|
private static readonly Color TextMuted = Color.FromHtml("#989487");
|
|
private static readonly Color CyanCol = Color.FromHtml("#44d9e8");
|
|
private static readonly Color AlliedCol = Color.FromHtml("#52e3a8");
|
|
private static readonly Color GoldCol = Color.FromHtml("#e6b838");
|
|
private static readonly Color RedCol = Color.FromHtml("#d93829");
|
|
private static readonly Color PatronColor = Color.FromHtml("#4ba8a5");
|
|
private static readonly Color ShadowCol = new(0.04f, 0.05f, 0.04f, 0.88f);
|
|
|
|
private const float HitArcDuration = 0.65f;
|
|
private const float BorderPad = 36f;
|
|
private const float PanelAvoidPad = 18f;
|
|
private const float OffscreenHostileMaxDistance = 220f;
|
|
private const int MaxOffscreenHostileArrows = 6;
|
|
private const int MaxCargoHitRects = 16;
|
|
|
|
private struct IncomingHitArc
|
|
{
|
|
public float SourceX;
|
|
public float SourceZ;
|
|
public WeaponVisualClass WeaponClass;
|
|
public float Age;
|
|
}
|
|
|
|
private readonly struct OffscreenMarker
|
|
{
|
|
public readonly System.Numerics.Vector3 CamLocal;
|
|
public readonly float Distance;
|
|
public readonly Color Color;
|
|
public readonly bool IsLockedOnLocal;
|
|
|
|
public OffscreenMarker(System.Numerics.Vector3 camLocal, float distance, Color color, bool isLockedOnLocal)
|
|
{
|
|
CamLocal = camLocal;
|
|
Distance = distance;
|
|
Color = color;
|
|
IsLockedOnLocal = isLockedOnLocal;
|
|
}
|
|
}
|
|
|
|
private readonly Func<IClientArenaSession?> _getSession;
|
|
private readonly Action<int, string> _onEquipCargo;
|
|
private readonly Func<float> _getCameraYaw;
|
|
private readonly Func<System.Numerics.Vector3, (bool Valid, bool InFront, Vector2 ScreenPos, System.Numerics.Vector3 CamLocal)>? _projectWorld;
|
|
|
|
private ColorRect _vignetteRect = null!;
|
|
private ShaderMaterial _vignetteMat = null!;
|
|
private ColorRect _bottomLeftBg = null!;
|
|
private InventoryGridControl _schematic = null!;
|
|
private HbGpuCanvas _hbCanvas = null!;
|
|
|
|
// Interactive [F9] multiplayer input panel (kept on Godot Controls until Thing 2 Cut 14c)
|
|
private PanelContainer _netPanel = null!;
|
|
private Label _netModeBadge = null!;
|
|
private Label _netPanelStatus = null!;
|
|
private LineEdit _callsignEdit = null!;
|
|
private LineEdit _endpointEdit = null!;
|
|
private string? _uiNetError;
|
|
|
|
// Layout rects (logical pixels)
|
|
private Rect2 _topLeftRect;
|
|
private Rect2 _topRightRect;
|
|
private Rect2 _bottomLeftRect;
|
|
private Rect2 _schematicRect;
|
|
private Rect2 _chyronRect;
|
|
private Rect2 _outcomeRect;
|
|
private bool _outcomeVisible;
|
|
private Vector2 _lastViewportSize = new(1280f, 720f);
|
|
|
|
// Cargo click hitboxes (zero Button allocations)
|
|
private readonly Rect2[] _cargoRowRects = new Rect2[MaxCargoHitRects];
|
|
private readonly Rect2[] _cargoFitRects = new Rect2[MaxCargoHitRects];
|
|
private int _cargoHitCount;
|
|
private ChassisGrid? _lastCargoGrid;
|
|
private int _selectedCargoIndex = -1;
|
|
private bool _garageExpanded;
|
|
private Vector2I? _lastHoveredCell;
|
|
|
|
// Vignette & combat feedback
|
|
private float _damagePulse;
|
|
private float _lowCoreRatio;
|
|
private float _overheatPulse;
|
|
private float _vignetteTime;
|
|
private readonly IncomingHitArc[] _incomingArcs = new IncomingHitArc[8];
|
|
private int _incomingArcCount;
|
|
private HitMarkerKind _hitMarkerKind;
|
|
private float _hitMarkerRemaining;
|
|
private float _hitMarkerDuration;
|
|
private MatchState? _lastCrosshairState;
|
|
|
|
// Zero-GC scratch & change-detected text caches
|
|
private readonly char[] _scratch = new char[512];
|
|
private readonly List<OffscreenMarker> _offscreenHostiles = new(16);
|
|
private static readonly Comparison<OffscreenMarker> OffscreenSortComparison = static (a, b) =>
|
|
{
|
|
int lockCmp = b.IsLockedOnLocal.CompareTo(a.IsLockedOnLocal);
|
|
return lockCmp != 0 ? lockCmp : a.Distance.CompareTo(b.Distance);
|
|
};
|
|
|
|
private readonly List<string> _promptLines = new(3);
|
|
private string _cachedPromptText = string.Empty;
|
|
private int _lastPromptKey = int.MinValue;
|
|
private bool _lastPromptPod;
|
|
private int _lastPodAglRounded = int.MinValue;
|
|
private int _lastPodHorizRounded = int.MinValue;
|
|
private int _lastPodVertRounded = int.MinValue;
|
|
private bool _lastPodBurn;
|
|
|
|
private readonly List<string> _hoverLines = new(3);
|
|
private string _cachedHoverText = "HOVER CELL FOR TELEMETRY";
|
|
private Color _cachedHoverColor = TextMuted;
|
|
|
|
private readonly List<string> _garageLines = new(24);
|
|
private string _cachedGarageDetails = string.Empty;
|
|
private int _lastGarageHash = int.MinValue;
|
|
|
|
private BroadcastFeed? _lastBroadcastFeed;
|
|
private long _lastChyronVersion = -1;
|
|
private readonly string[] _chyronDisplayLines = new string[3];
|
|
private readonly bool[] _chyronIsLatest = new bool[3];
|
|
private readonly List<string> _chyronWrapScratch = new(8);
|
|
private int _chyronLineCount;
|
|
|
|
private readonly List<string> _hintLines = new(2);
|
|
private int _lastHintMode = -1;
|
|
|
|
private IClientArenaSession? _latestSession;
|
|
private string? _cachedChassisName;
|
|
private string _cachedChassisUpper = "CHASSIS";
|
|
private bool _inputBlocked;
|
|
private bool _dirtyEmit;
|
|
private bool _emittedThisFrame;
|
|
|
|
public event Action<string, string>? JoinRequested;
|
|
public event Action<int, string>? HostRequested;
|
|
public event Action? SoloRequested;
|
|
public event Action<bool>? NetworkPanelToggled;
|
|
|
|
public Hud(
|
|
Func<IClientArenaSession?> getSession,
|
|
Action<int, string> onEquipCargo,
|
|
Func<float>? getCameraYaw = null,
|
|
Func<System.Numerics.Vector3, (bool Valid, bool InFront, Vector2 ScreenPos, System.Numerics.Vector3 CamLocal)>? projectWorld = null)
|
|
{
|
|
_getSession = getSession;
|
|
_onEquipCargo = onEquipCargo;
|
|
_getCameraYaw = getCameraYaw ?? (() => 0f);
|
|
_projectWorld = projectWorld;
|
|
Layer = 10;
|
|
}
|
|
|
|
public HbGpuCanvas HbCanvas => _hbCanvas;
|
|
public bool GarageExpanded => _garageExpanded;
|
|
public bool NetworkPanelOpen => _netPanel.Visible;
|
|
public bool IsUiTextInputFocused => _netPanel.Visible && (_callsignEdit.HasFocus() || _endpointEdit.HasFocus());
|
|
public InventoryGridControl Schematic => _schematic;
|
|
internal int ActiveHitArcCount => _incomingArcCount;
|
|
internal bool HasActiveHitMarker => _hitMarkerRemaining > 0f && _hitMarkerKind != HitMarkerKind.None;
|
|
internal HitMarkerKind ActiveHitMarkerKind => HasActiveHitMarker ? _hitMarkerKind : HitMarkerKind.None;
|
|
internal bool IsVignetteVisible => _vignetteRect is not null && _vignetteRect.Visible;
|
|
internal Rect2 BottomLeftPanelRect => _bottomLeftRect;
|
|
internal Rect2 ChyronPanelRect => _chyronRect;
|
|
internal string HoverLabelText => _cachedHoverText;
|
|
internal string PromptLabelText => _cachedPromptText;
|
|
internal string GarageDetailsText => _cachedGarageDetails;
|
|
|
|
internal void PushTestHitArc(float sourceX, float sourceZ, WeaponVisualClass weaponClass)
|
|
{
|
|
if (_incomingArcCount >= _incomingArcs.Length)
|
|
{
|
|
for (int i = 1; i < _incomingArcs.Length; i++)
|
|
{
|
|
_incomingArcs[i - 1] = _incomingArcs[i];
|
|
}
|
|
_incomingArcCount = _incomingArcs.Length - 1;
|
|
}
|
|
_incomingArcs[_incomingArcCount++] = new IncomingHitArc
|
|
{
|
|
SourceX = sourceX,
|
|
SourceZ = sourceZ,
|
|
WeaponClass = weaponClass,
|
|
Age = 0f
|
|
};
|
|
_dirtyEmit = true;
|
|
}
|
|
|
|
internal void ResetFeedback()
|
|
{
|
|
_damagePulse = 0f;
|
|
_lowCoreRatio = 0f;
|
|
_overheatPulse = 0f;
|
|
_vignetteTime = 0f;
|
|
_incomingArcCount = 0;
|
|
_hitMarkerKind = HitMarkerKind.None;
|
|
_hitMarkerRemaining = 0f;
|
|
_hitMarkerDuration = 0f;
|
|
if (_vignetteRect is not null)
|
|
{
|
|
_vignetteRect.Visible = false;
|
|
}
|
|
_dirtyEmit = true;
|
|
}
|
|
|
|
internal void SimulateCellHover(Vector2I? cell, HardpointSpec? hp) => OnSchematicHoverChanged(cell, hp);
|
|
|
|
public override void _Ready()
|
|
{
|
|
Shader vigShader = GD.Load<Shader>("res://hud_vignette.gdshader")
|
|
?? throw new InvalidOperationException("Failed to load res://hud_vignette.gdshader");
|
|
_vignetteMat = new ShaderMaterial { Shader = vigShader };
|
|
_vignetteRect = new ColorRect
|
|
{
|
|
Name = "HudVignette",
|
|
Material = _vignetteMat,
|
|
MouseFilter = Control.MouseFilterEnum.Ignore,
|
|
Visible = false
|
|
};
|
|
_vignetteRect.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
|
AddChild(_vignetteRect);
|
|
|
|
// Dark backdrop under _schematic so inactive holes (e.g. Raptor) show panel BgDark instead of 3D world
|
|
_bottomLeftBg = new ColorRect
|
|
{
|
|
Name = "BottomLeftBackdrop",
|
|
Color = BgDark,
|
|
MouseFilter = Control.MouseFilterEnum.Ignore
|
|
};
|
|
AddChild(_bottomLeftBg);
|
|
|
|
_schematic = new InventoryGridControl
|
|
{
|
|
Name = "SchematicGrid",
|
|
ExternalHbGpuOwner = true,
|
|
CustomMinimumSize = new Vector2(180f, 188f)
|
|
};
|
|
_schematic.HardpointClicked += OnHardpointClicked;
|
|
_schematic.HoverChanged += OnSchematicHoverChanged;
|
|
AddChild(_schematic);
|
|
|
|
// Single-draw-call HarfBuzz hb-gpu overlay sits strictly ABOVE _schematic's bilinear thermal backdrop
|
|
_hbCanvas = new HbGpuCanvas
|
|
{
|
|
Name = "HbGpuCanvas",
|
|
MouseFilter = Control.MouseFilterEnum.Ignore
|
|
};
|
|
_hbCanvas.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.FullRect);
|
|
AddChild(_hbCanvas);
|
|
|
|
BuildNetworkPanel();
|
|
|
|
_lastViewportSize = GetViewportSizeSafe();
|
|
RecomputeLayoutRects(_lastViewportSize, _latestSession);
|
|
}
|
|
|
|
public void ToggleNetworkPanel() => SetNetworkPanelOpen(!_netPanel.Visible);
|
|
|
|
public void SetNetworkPanelOpen(bool open)
|
|
{
|
|
if (_netPanel.Visible == open) return;
|
|
_netPanel.Visible = open;
|
|
if (!open)
|
|
{
|
|
_callsignEdit.ReleaseFocus();
|
|
_endpointEdit.ReleaseFocus();
|
|
}
|
|
NetworkPanelToggled?.Invoke(open);
|
|
}
|
|
|
|
public void SetNetworkDefaults(string endpoint, string callsign)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(endpoint))
|
|
{
|
|
_endpointEdit.Text = endpoint.Trim();
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(callsign))
|
|
{
|
|
_callsignEdit.Text = callsign.Trim();
|
|
}
|
|
}
|
|
|
|
public void SetNetworkError(string? err)
|
|
{
|
|
_uiNetError = string.IsNullOrWhiteSpace(err) ? null : err;
|
|
}
|
|
|
|
public void ToggleGarage()
|
|
{
|
|
_garageExpanded = !_garageExpanded;
|
|
_lastGarageHash = int.MinValue;
|
|
_schematic.CustomMinimumSize = _garageExpanded ? new Vector2(198f, 208f) : new Vector2(180f, 188f);
|
|
RecomputeLayoutRects(GetViewportSizeSafe(), _latestSession);
|
|
_dirtyEmit = true;
|
|
}
|
|
|
|
public void SetInputBlocked(bool blocked)
|
|
{
|
|
_inputBlocked = blocked;
|
|
}
|
|
|
|
public void SetMatchHudActive(bool active)
|
|
{
|
|
Visible = active;
|
|
if (!active)
|
|
{
|
|
_inputBlocked = false;
|
|
if (_netPanel.Visible)
|
|
{
|
|
_netPanel.Visible = false;
|
|
_callsignEdit.ReleaseFocus();
|
|
_endpointEdit.ReleaseFocus();
|
|
}
|
|
if (_garageExpanded)
|
|
{
|
|
ToggleGarage();
|
|
}
|
|
ResetFeedback();
|
|
}
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
if (!Visible || _inputBlocked || _netPanel.Visible)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (@event is InputEventMouseButton mb && mb.Pressed && mb.ButtonIndex == MouseButton.Left)
|
|
{
|
|
if (_lastCargoGrid is not null &&
|
|
_bottomLeftRect.HasPoint(mb.Position) &&
|
|
!_schematic.GetGlobalRect().HasPoint(mb.Position))
|
|
{
|
|
for (int i = 0; i < _cargoHitCount; i++)
|
|
{
|
|
if (_cargoFitRects[i].HasPoint(mb.Position))
|
|
{
|
|
AutoFitCargo(_lastCargoGrid, i);
|
|
GetViewport().SetInputAsHandled();
|
|
_dirtyEmit = true;
|
|
return;
|
|
}
|
|
if (_cargoRowRects[i].HasPoint(mb.Position))
|
|
{
|
|
_selectedCargoIndex = (_selectedCargoIndex == i) ? -1 : i;
|
|
if (_lastHoveredCell is null)
|
|
{
|
|
UpdateCargoSelectionTooltip(_lastCargoGrid);
|
|
}
|
|
GetViewport().SetInputAsHandled();
|
|
_dirtyEmit = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (!Visible)
|
|
{
|
|
_emittedThisFrame = false;
|
|
return;
|
|
}
|
|
|
|
float dt = (float)delta;
|
|
bool timerAdvanced = AdvanceTimers(dt);
|
|
|
|
if (_vignetteRect is not null)
|
|
{
|
|
if (_damagePulse > 0f && dt > 0f)
|
|
{
|
|
_damagePulse = MathF.Max(0f, _damagePulse - dt * 2.4f);
|
|
if (_damagePulse < 0.005f) _damagePulse = 0f;
|
|
}
|
|
bool active = _damagePulse >= 0.01f || _lowCoreRatio >= 0.01f || _overheatPulse >= 0.01f;
|
|
_vignetteRect.Visible = active;
|
|
if (active)
|
|
{
|
|
_vignetteTime += MathF.Max(0f, dt);
|
|
_vignetteMat.SetShaderParameter("damage_pulse", _damagePulse);
|
|
_vignetteMat.SetShaderParameter("low_core_ratio", _lowCoreRatio);
|
|
_vignetteMat.SetShaderParameter("overheat_pulse", _overheatPulse);
|
|
_vignetteMat.SetShaderParameter("time_sec", _vignetteTime);
|
|
}
|
|
}
|
|
else if (dt > 0f)
|
|
{
|
|
_vignetteTime += dt;
|
|
}
|
|
|
|
if ((_dirtyEmit || timerAdvanced) && !_emittedThisFrame && _latestSession is not null)
|
|
{
|
|
EmitHudFrame(_latestSession);
|
|
}
|
|
|
|
_emittedThisFrame = false;
|
|
_dirtyEmit = false;
|
|
}
|
|
|
|
private bool AdvanceTimers(float dt)
|
|
{
|
|
bool dirty = false;
|
|
if (_incomingArcCount > 0 && dt > 0f)
|
|
{
|
|
int write = 0;
|
|
for (int i = 0; i < _incomingArcCount; i++)
|
|
{
|
|
_incomingArcs[i].Age += dt;
|
|
if (_incomingArcs[i].Age < HitArcDuration)
|
|
{
|
|
_incomingArcs[write++] = _incomingArcs[i];
|
|
}
|
|
}
|
|
_incomingArcCount = write;
|
|
dirty = true;
|
|
}
|
|
|
|
if (_hitMarkerRemaining > 0f && dt > 0f)
|
|
{
|
|
_hitMarkerRemaining = MathF.Max(0f, _hitMarkerRemaining - dt);
|
|
if (_hitMarkerRemaining <= 0.001f)
|
|
{
|
|
_hitMarkerRemaining = 0f;
|
|
_hitMarkerKind = HitMarkerKind.None;
|
|
}
|
|
dirty = true;
|
|
}
|
|
|
|
return dirty;
|
|
}
|
|
|
|
public void ConsumeEvents(
|
|
IReadOnlyList<ISimEvent> events,
|
|
int localContenderId,
|
|
float localCoreHpRatio,
|
|
float localMaxThermalRatio)
|
|
{
|
|
for (int i = 0; i < events.Count; i++)
|
|
{
|
|
switch (events[i])
|
|
{
|
|
case MatchResetEvent:
|
|
ResetFeedback();
|
|
break;
|
|
|
|
case HitImpactEvent hit:
|
|
if (hit.TargetKind == (byte)HitTargetKind.Contender && hit.TargetId == localContenderId)
|
|
{
|
|
var wc = (WeaponVisualClass)hit.WeaponClass;
|
|
PushTestHitArc(hit.SourceX, hit.SourceZ, wc);
|
|
float pulse = wc is WeaponVisualClass.Explosive or WeaponVisualClass.RocketSalvo or WeaponVisualClass.GaussRail
|
|
? 0.95f
|
|
: 0.62f;
|
|
_damagePulse = MathF.Max(_damagePulse, pulse);
|
|
}
|
|
bool targetIsVehicle = hit.TargetKind == (byte)HitTargetKind.Contender
|
|
|| hit.TargetKind == (byte)HitTargetKind.Spectator;
|
|
if (targetIsVehicle && hit.IsContenderShooter && hit.ShooterId == localContenderId)
|
|
{
|
|
TriggerHitMarker(hit.CoreDamage > 0.001f, hit.Killed);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
_lowCoreRatio = localCoreHpRatio < 0.35f
|
|
? Math.Clamp((0.35f - localCoreHpRatio) / 0.35f, 0f, 1f)
|
|
: 0f;
|
|
_overheatPulse = localMaxThermalRatio >= 0.85f
|
|
? Math.Clamp((localMaxThermalRatio - 0.85f) / 0.25f, 0.35f, 1.0f)
|
|
: 0f;
|
|
|
|
if (_vignetteRect is not null)
|
|
{
|
|
bool active = _damagePulse >= 0.01f || _lowCoreRatio >= 0.01f || _overheatPulse >= 0.01f;
|
|
_vignetteRect.Visible = active;
|
|
if (active)
|
|
{
|
|
_vignetteMat.SetShaderParameter("damage_pulse", _damagePulse);
|
|
_vignetteMat.SetShaderParameter("low_core_ratio", _lowCoreRatio);
|
|
_vignetteMat.SetShaderParameter("overheat_pulse", _overheatPulse);
|
|
_vignetteMat.SetShaderParameter("time_sec", _vignetteTime);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void TriggerHitMarker(bool coreHit, bool killed)
|
|
{
|
|
HitMarkerKind nextKind = killed
|
|
? HitMarkerKind.Kill
|
|
: (coreHit ? HitMarkerKind.Core : HitMarkerKind.Armor);
|
|
if (_hitMarkerRemaining > 0f && (int)nextKind < (int)_hitMarkerKind)
|
|
{
|
|
nextKind = _hitMarkerKind;
|
|
}
|
|
_hitMarkerKind = nextKind;
|
|
_hitMarkerDuration = nextKind switch
|
|
{
|
|
HitMarkerKind.Kill => 0.38f,
|
|
HitMarkerKind.Core => 0.26f,
|
|
_ => 0.18f
|
|
};
|
|
_hitMarkerRemaining = _hitMarkerDuration;
|
|
_dirtyEmit = true;
|
|
}
|
|
|
|
public bool IsPointerOverInteractiveHud(Vector2 screenPos)
|
|
{
|
|
return (Visible && _topLeftRect.HasPoint(screenPos))
|
|
|| (Visible && _topRightRect.HasPoint(screenPos))
|
|
|| (Visible && _bottomLeftRect.HasPoint(screenPos))
|
|
|| (Visible && _chyronRect.HasPoint(screenPos))
|
|
|| (Visible && _outcomeVisible && _outcomeRect.HasPoint(screenPos))
|
|
|| (_netPanel.Visible && _netPanel.GetGlobalRect().HasPoint(screenPos));
|
|
}
|
|
|
|
public bool HasPanelOverlapOrClip(Vector2 viewportSize)
|
|
{
|
|
RecomputeLayoutRects(viewportSize, _latestSession);
|
|
Span<Rect2> rects = stackalloc Rect2[5];
|
|
int count = 0;
|
|
rects[count++] = _topLeftRect;
|
|
rects[count++] = _topRightRect;
|
|
rects[count++] = _bottomLeftRect;
|
|
rects[count++] = _chyronRect;
|
|
if (_netPanel.Visible)
|
|
{
|
|
rects[count++] = _netPanel.GetGlobalRect();
|
|
}
|
|
|
|
var bounds = new Rect2(Vector2.Zero, viewportSize + new Vector2(1f, 1f));
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
if (!bounds.Encloses(rects[i]))
|
|
{
|
|
return true;
|
|
}
|
|
for (int j = i + 1; j < count; j++)
|
|
{
|
|
if (rects[i].Intersects(rects[j]))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void Sync(IClientArenaSession session)
|
|
{
|
|
_latestSession = session;
|
|
var state = session.ViewState;
|
|
if (!ReferenceEquals(_lastCrosshairState, state))
|
|
{
|
|
_lastCrosshairState = state;
|
|
_incomingArcCount = 0;
|
|
_hitMarkerKind = HitMarkerKind.None;
|
|
_hitMarkerRemaining = 0f;
|
|
_hitMarkerDuration = 0f;
|
|
}
|
|
|
|
var player = session.LocalContender;
|
|
var net = session.ConnectionStatus;
|
|
|
|
OrbitalPod? localPod = FindLocalContenderPod(session, player);
|
|
|
|
if (_netPanel.Visible)
|
|
{
|
|
SyncNetworkPanel(net);
|
|
}
|
|
|
|
UpdatePromptCache(state, player, localPod);
|
|
UpdateHintCache(player);
|
|
|
|
_schematic.SetGrid(player.Grid, _selectedCargoIndex);
|
|
_lastCargoGrid = player.Grid;
|
|
|
|
if (_lastHoveredCell is null)
|
|
{
|
|
UpdateCargoSelectionTooltip(player.Grid);
|
|
}
|
|
|
|
if (_garageExpanded)
|
|
{
|
|
UpdateGarageDetailsCache(player.Grid);
|
|
}
|
|
|
|
SyncBroadcastChyron(state.Broadcast);
|
|
|
|
RecomputeLayoutRects(GetViewportSizeSafe(), session);
|
|
EmitHudFrame(session);
|
|
_emittedThisFrame = true;
|
|
_dirtyEmit = false;
|
|
}
|
|
|
|
private Vector2 GetViewportSizeSafe()
|
|
{
|
|
Viewport? vp = GetViewport();
|
|
if (vp is not null)
|
|
{
|
|
Vector2 vis = vp.GetVisibleRect().Size;
|
|
if (vis.X >= 64f && vis.Y >= 64f)
|
|
{
|
|
_lastViewportSize = vis;
|
|
return vis;
|
|
}
|
|
}
|
|
return _lastViewportSize;
|
|
}
|
|
|
|
private static OrbitalPod? FindLocalContenderPod(IClientArenaSession session, ContenderState player)
|
|
{
|
|
if (!player.IsInDropPod) return null;
|
|
var pods = session.ActivePods;
|
|
for (int i = 0; i < pods.Count; i++)
|
|
{
|
|
if (pods[i].PodKind == OrbitalPodKind.Contender && pods[i].ContenderId == player.Id)
|
|
{
|
|
return pods[i];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private void RecomputeLayoutRects(Vector2 vpSize, IClientArenaSession? session)
|
|
{
|
|
float vw = MathF.Max(320f, vpSize.X);
|
|
float vh = MathF.Max(240f, vpSize.Y);
|
|
|
|
// Top-Left panel
|
|
float tlW = 396f;
|
|
float tlH = 138f + Math.Max(1, _hintLines.Count) * 14f;
|
|
if (session is not null && session.ConnectionStatus.Mode != NetworkMode.Solo)
|
|
{
|
|
tlH += 17f;
|
|
}
|
|
if (_promptLines.Count > 0)
|
|
{
|
|
tlH += 4f + _promptLines.Count * 16f;
|
|
}
|
|
_topLeftRect = new Rect2(14f, 14f, tlW, tlH);
|
|
|
|
// Top-Right Radar panel
|
|
float trW = 234f;
|
|
float trH = 264f;
|
|
_topRightRect = new Rect2(vw - 14f - trW, 14f, trW, trH);
|
|
|
|
// Bottom-Left Schematic + Cargo + optional Garage panel
|
|
float gridW = _garageExpanded ? 198f : 180f;
|
|
float gridH = _garageExpanded ? 208f : 188f;
|
|
const float cargoW = 156f;
|
|
float garageW = _garageExpanded ? 186f : 0f;
|
|
float blW = 10f + gridW + 8f + cargoW + (_garageExpanded ? 8f + garageW : 0f) + 10f;
|
|
|
|
float hoverH = MathF.Max(28f, _hoverLines.Count * 14f);
|
|
float leftColH = 18f + gridH + 4f + hoverH;
|
|
|
|
int cargoCount = session?.LocalContender.Grid.Cargo.Count ?? 0;
|
|
float cargoColH = 18f + (cargoCount > 0 ? cargoCount * 21f : 34f);
|
|
float garageColH = _garageExpanded ? MathF.Max(140f, _garageLines.Count * 13.5f + 8f) : 0f;
|
|
float blH = 8f + MathF.Max(leftColH, MathF.Max(cargoColH, garageColH)) + 8f;
|
|
|
|
_bottomLeftRect = new Rect2(14f, vh - 14f - blH, blW, blH);
|
|
_schematicRect = new Rect2(_bottomLeftRect.Position.X + 10f, _bottomLeftRect.Position.Y + 8f + 18f, gridW, gridH);
|
|
|
|
if (_bottomLeftBg is not null)
|
|
{
|
|
if (_bottomLeftBg.Position != _bottomLeftRect.Position) _bottomLeftBg.Position = _bottomLeftRect.Position;
|
|
if (_bottomLeftBg.Size != _bottomLeftRect.Size) _bottomLeftBg.Size = _bottomLeftRect.Size;
|
|
}
|
|
if (_schematic is not null)
|
|
{
|
|
if (_schematic.Position != _schematicRect.Position) _schematic.Position = _schematicRect.Position;
|
|
if (_schematic.Size != _schematicRect.Size) _schematic.Size = _schematicRect.Size;
|
|
}
|
|
|
|
// Bottom-Right Chyron panel
|
|
const float chW = 570f;
|
|
const float chH = 92f;
|
|
_chyronRect = new Rect2(vw - 14f - chW, vh - 14f - chH, chW, chH);
|
|
|
|
// Outcome banner
|
|
_outcomeRect = new Rect2(vw * 0.5f - 210f, vh * 0.28f - 40f, 420f, 80f);
|
|
_outcomeVisible = false;
|
|
if (session is not null)
|
|
{
|
|
var outcome = session.LocalOutcome;
|
|
_outcomeVisible = outcome == ClientMatchOutcome.Victory
|
|
|| outcome == ClientMatchOutcome.Defeat
|
|
|| session.LocalContender.WaitingForRespawn;
|
|
}
|
|
}
|
|
|
|
private void EmitHudFrame(IClientArenaSession session)
|
|
{
|
|
if (_hbCanvas is null || !Visible)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Vector2 vpSize = GetViewportSizeSafe();
|
|
var state = session.ViewState;
|
|
var player = session.LocalContender;
|
|
var net = session.ConnectionStatus;
|
|
OrbitalPod? localPod = FindLocalContenderPod(session, player);
|
|
|
|
_hbCanvas.BeginFrame();
|
|
|
|
// 1. 3D Projected World Markers (behind panels, above scene)
|
|
EmitWorldMarkers(session, state, player, vpSize);
|
|
|
|
// 2. Center Crosshair, Thermal Heat Arc, Incoming Hit Arcs, Hit-Marker X, Pod Altimeter
|
|
EmitCrosshairAndCombatFeedback(state, player, localPod, vpSize * 0.5f);
|
|
|
|
// 3. Top-Left Telemetry Panel
|
|
EmitTopLeftPanel(session, state, player, net, localPod);
|
|
|
|
// 4. Top-Right Radar Panel
|
|
EmitTopRightRadarPanel(session, state);
|
|
|
|
// 5. Bottom-Left Schematic Panel Frame + Hardpoint Overlay + Hover + Cargo Rack + Garage
|
|
EmitBottomLeftPanel(player.Grid);
|
|
|
|
// 6. Bottom-Right Broadcast Chyron
|
|
EmitChyronPanel();
|
|
|
|
// 7. Outcome / Awaiting Wave Banner
|
|
if (_outcomeVisible)
|
|
{
|
|
EmitOutcomeBanner(session, state, player, net);
|
|
}
|
|
|
|
// 8. Optional [F9] Network panel chrome + cyan brackets (drawn behind transparent _netPanel controls)
|
|
if (_netPanel.Visible)
|
|
{
|
|
_hbCanvas.DrawPanelFrame(_netPanel.GetGlobalRect(), BgDark, CyanCol, CyanCol, cornerLen: 14f, borderPx: 1.5f, drawBg: true);
|
|
}
|
|
|
|
_hbCanvas.EndFrameAndSubmit();
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// 1. Top-Left Panel (0 GC allocs)
|
|
// -------------------------------------------------------------------------
|
|
private void EmitTopLeftPanel(
|
|
IClientArenaSession session,
|
|
MatchState state,
|
|
ContenderState player,
|
|
NetworkStatusSnapshot net,
|
|
OrbitalPod? localPod)
|
|
{
|
|
_hbCanvas.DrawPanelFrame(_topLeftRect, BgDark, BorderCol, OliveCol, cornerLen: 12f, borderPx: 1.5f);
|
|
|
|
float x = _topLeftRect.Position.X + 10f;
|
|
float rightX = _topLeftRect.End.X - 10f;
|
|
float y = _topLeftRect.Position.Y + 8f;
|
|
|
|
int aliveCount = 0;
|
|
for (int i = 0; i < state.Contenders.Count; i++)
|
|
{
|
|
if (state.Contenders[i].Alive) aliveCount++;
|
|
}
|
|
|
|
// Header + Dorsal/Coronal/Pod badge
|
|
if (player.IsInDropPod)
|
|
{
|
|
bool burning = localPod?.Phase == OrbitalPodPhase.RetroBurn;
|
|
_hbCanvas.DrawText("ORBITAL DROP POD", x, y + 14f, 16f, TextLight, wght: 700f);
|
|
ReadOnlySpan<char> badge = burning ? "RETRO BURN" : "FREEFALL";
|
|
Color bCol = burning ? OrangeCol : CyanCol;
|
|
float bw = _hbCanvas.MeasureTextWidth(badge, 12.5f, wght: 600f);
|
|
_hbCanvas.DrawText(badge, rightX - bw, y + 13f, 12.5f, bCol, wght: 600f);
|
|
}
|
|
else
|
|
{
|
|
string rawName = player.Grid.Spec.Name;
|
|
if (!ReferenceEquals(_cachedChassisName, rawName))
|
|
{
|
|
_cachedChassisName = rawName;
|
|
_cachedChassisUpper = rawName.ToUpperInvariant();
|
|
}
|
|
_hbCanvas.DrawText(_cachedChassisUpper, x, y + 14f, 16f, TextLight, wght: 700f);
|
|
bool isCoronal = player.Grid.Spec.Plane == GridPlane.Coronal;
|
|
ReadOnlySpan<char> badge = isCoronal ? "CORONAL" : "DORSAL";
|
|
Color bCol = isCoronal ? CyanCol : OliveCol;
|
|
float bw = _hbCanvas.MeasureTextWidth(badge, 12.5f, wght: 600f);
|
|
_hbCanvas.DrawText(badge, rightX - bw, y + 13f, 12.5f, bCol, wght: 600f);
|
|
}
|
|
y += 22f;
|
|
|
|
// Core HP vector bar + label
|
|
float maxCore = MathF.Max(1f, player.Grid.MaxCoreHp);
|
|
float coreHp = MathF.Max(0f, player.Grid.CoreHp);
|
|
float hpFrac = Math.Clamp(coreHp / maxCore, 0f, 1f);
|
|
|
|
SpanWriter sw = new(_scratch);
|
|
sw.Append("CORE ");
|
|
sw.AppendFloat(coreHp, "F0");
|
|
sw.Append(" / ");
|
|
sw.AppendFloat(maxCore, "F0");
|
|
ReadOnlySpan<char> hpSpan = sw.Span;
|
|
float hpLabelW = _hbCanvas.MeasureTextWidth(hpSpan, 12.5f, wght: 550f);
|
|
float barW = MathF.Max(80f, rightX - x - hpLabelW - 10f);
|
|
|
|
_hbCanvas.DrawRectFilled(x, y, barW, 15f, BgInner);
|
|
_hbCanvas.DrawRectOutline(x, y, barW, 15f, 1.0f, BorderCol);
|
|
if (hpFrac > 0.001f)
|
|
{
|
|
Color fillCol = hpFrac < 0.35f ? RedCol : OliveCol;
|
|
_hbCanvas.DrawRectFilled(x + 1f, y + 1f, MathF.Max(1f, (barW - 2f) * hpFrac), 13f, fillCol);
|
|
}
|
|
_hbCanvas.DrawText(hpSpan, x + barW + 8f, y + 12f, 12.5f, TextLight, wght: 550f);
|
|
y += 21f;
|
|
|
|
// Stats line
|
|
sw = new SpanWriter(_scratch);
|
|
if (player.IsInDropPod)
|
|
{
|
|
float agl = localPod is not null
|
|
? MathF.Max(0f, localPod.LastAgl)
|
|
: MathF.Max(0f, player.Y - state.Terrain.SampleHeight(player.X, player.Z));
|
|
float velDown = localPod is not null ? MathF.Max(0f, -localPod.VelY) : MathF.Max(0f, -player.VelY);
|
|
float horizSpeed = localPod is not null
|
|
? MathF.Sqrt(localPod.VelX * localPod.VelX + localPod.VelZ * localPod.VelZ)
|
|
: player.Speed;
|
|
sw.Append("ALT "); sw.AppendFloat(agl, "F0"); sw.Append("m | HORIZ ");
|
|
sw.AppendFloat(horizSpeed, "F0"); sw.Append(" m/s | VERT ");
|
|
sw.AppendFloat(velDown, "F0"); sw.Append(" m/s | ALIVE ");
|
|
sw.AppendInt(aliveCount); sw.Append(" / "); sw.AppendInt(state.Contenders.Count);
|
|
}
|
|
else if (player.Grid.Spec.IsVtol)
|
|
{
|
|
float agl = MathF.Max(0f, player.Y - player.Grid.Spec.HalfHeight - state.Terrain.SampleHeight(player.X, player.Z));
|
|
sw.Append("SPD "); sw.AppendFloat(player.Speed, "F1"); sw.Append(" m/s | ALT ");
|
|
sw.AppendFloat(agl, "F1"); sw.Append("m | ALIVE ");
|
|
sw.AppendInt(aliveCount); sw.Append(" / "); sw.AppendInt(state.Contenders.Count);
|
|
sw.Append(" | KILLS "); sw.AppendInt(player.Kills);
|
|
}
|
|
else
|
|
{
|
|
sw.Append("SPD "); sw.AppendFloat(player.Speed, "F1"); sw.Append(" m/s | ALIVE ");
|
|
sw.AppendInt(aliveCount); sw.Append(" / "); sw.AppendInt(state.Contenders.Count);
|
|
sw.Append(" | KILLS "); sw.AppendInt(player.Kills);
|
|
}
|
|
_hbCanvas.DrawText(sw.Span, x, y + 11f, 12f, TextMuted, wght: 400f);
|
|
y += 18f;
|
|
|
|
// Safe ring status
|
|
float distCenter = MathF.Sqrt(player.X * player.X + player.Z * player.Z);
|
|
float outside = distCenter - state.Spectators.SafeRadius;
|
|
int cleared = state.Spectators.CountClearedFor(player.Id);
|
|
int provoked = state.Spectators.CountProvokedFor(player.Id);
|
|
|
|
sw = new SpanWriter(_scratch);
|
|
Color safeCol;
|
|
if (outside <= 0f)
|
|
{
|
|
sw.Append("RING SAFE ("); sw.AppendFloat(-outside, "F0"); sw.Append("m margin)");
|
|
if (provoked > 0)
|
|
{
|
|
sw.Append(" • "); sw.AppendInt(provoked); sw.Append(" PROVOKED!");
|
|
}
|
|
safeCol = provoked > 0 ? OrangeCol : OliveCol;
|
|
}
|
|
else
|
|
{
|
|
sw.Append("OUTSIDE +"); sw.AppendFloat(outside, "F0"); sw.Append("m — ");
|
|
sw.AppendInt(cleared); sw.Append(" CLEARED");
|
|
if (provoked > 0)
|
|
{
|
|
sw.Append(" / "); sw.AppendInt(provoked); sw.Append(" PROVOKED!");
|
|
}
|
|
else
|
|
{
|
|
sw.Append("!");
|
|
}
|
|
safeCol = RedCol;
|
|
}
|
|
_hbCanvas.DrawText(sw.Span, x, y + 11f, 12.5f, safeCol, wght: 500f);
|
|
y += 18f;
|
|
|
|
// Detection status
|
|
int detectedBy = session.LocalDetectedByCount;
|
|
sw = new SpanWriter(_scratch);
|
|
Color detCol;
|
|
if (detectedBy > 0)
|
|
{
|
|
sw.Append("DETECTED BY "); sw.AppendInt(detectedBy);
|
|
detCol = RedCol;
|
|
}
|
|
else
|
|
{
|
|
sw.Append("CONCEALED (TERRAIN)");
|
|
detCol = OliveCol;
|
|
}
|
|
_hbCanvas.DrawText(sw.Span, x, y + 11f, 12.5f, detCol, wght: 500f);
|
|
y += 18f;
|
|
|
|
// Drop wave / respawn status
|
|
var wave = session.DropWaveState;
|
|
sw = new SpanWriter(_scratch);
|
|
Color waveCol;
|
|
if (wave.RespawnCutoffReached)
|
|
{
|
|
sw.Append("FINAL RING — RESPAWNS CLOSED");
|
|
waveCol = RedCol;
|
|
}
|
|
else if (wave.NextWaveAtSec is float nextWaveAt)
|
|
{
|
|
float eta = MathF.Max(0f, nextWaveAt - state.Time);
|
|
sw.Append("PATRON WAVE "); sw.AppendInt(wave.NextWaveIndex);
|
|
sw.Append(" IN "); sw.AppendFloat(eta, "F0");
|
|
sw.Append("s • RESP "); sw.AppendInt(player.RespawnsRemaining);
|
|
waveCol = eta <= 10f ? GoldCol : CyanCol;
|
|
}
|
|
else
|
|
{
|
|
sw.Append("WAVE "); sw.AppendInt(wave.CurrentWaveIndex);
|
|
sw.Append(" ACTIVE • RESP "); sw.AppendInt(player.RespawnsRemaining);
|
|
waveCol = OliveCol;
|
|
}
|
|
_hbCanvas.DrawText(sw.Span, x, y + 11f, 11.8f, waveCol, wght: 450f);
|
|
y += 17f;
|
|
|
|
// Network status (only non-Solo)
|
|
if (net.Mode != NetworkMode.Solo)
|
|
{
|
|
sw = new SpanWriter(_scratch);
|
|
Color netCol;
|
|
if (net.Mode == NetworkMode.ListenHost)
|
|
{
|
|
sw.Append(net.StateLabel); sw.Append(" • HUMANS ");
|
|
sw.AppendInt(net.ConnectedHumans); sw.Append("/"); sw.AppendInt(net.MaxHumans);
|
|
sw.Append(" • [F9] NET");
|
|
netCol = CyanCol;
|
|
}
|
|
else if (net.Connected)
|
|
{
|
|
sw.Append("PING "); sw.AppendInt(net.PingMs); sw.Append(" ms • HUMANS ");
|
|
sw.AppendInt(net.ConnectedHumans); sw.Append("/"); sw.AppendInt(net.MaxHumans);
|
|
sw.Append(" • [F9] NET");
|
|
netCol = net.PingMs > 120 ? OrangeCol : CyanCol;
|
|
}
|
|
else
|
|
{
|
|
sw.Append(net.StateLabel); sw.Append(" • [F9] NET");
|
|
netCol = net.LastError is not null ? RedCol : OrangeCol;
|
|
}
|
|
_hbCanvas.DrawText(sw.Span, x, y + 11f, 11.8f, netCol, wght: 450f);
|
|
y += 17f;
|
|
}
|
|
|
|
// Interaction or orbital prompt
|
|
if (_promptLines.Count > 0)
|
|
{
|
|
y += 4f;
|
|
for (int i = 0; i < _promptLines.Count; i++)
|
|
{
|
|
_hbCanvas.DrawText(_promptLines[i], x, y + 11f, 12f, CyanCol, wght: 550f);
|
|
y += 16f;
|
|
}
|
|
}
|
|
|
|
// Controls hint (wrapped & clipped cleanly inside panel width)
|
|
HbGpuCommandWriter.PackClipRect(
|
|
_topLeftRect.Position.X + 8f,
|
|
_topLeftRect.Position.Y + 6f,
|
|
_topLeftRect.Size.X - 16f,
|
|
_topLeftRect.Size.Y - 12f,
|
|
out uint tlClipMin,
|
|
out uint tlClipMax);
|
|
|
|
if (_hintLines.Count == 0)
|
|
{
|
|
UpdateHintCache(player);
|
|
}
|
|
float hintY = _topLeftRect.End.Y - 8f - Math.Max(0, _hintLines.Count - 1) * 13.5f;
|
|
for (int i = 0; i < _hintLines.Count; i++)
|
|
{
|
|
_hbCanvas.DrawText(
|
|
_hintLines[i],
|
|
x,
|
|
hintY,
|
|
10.0f,
|
|
TextMuted,
|
|
wght: 350f,
|
|
clipMinPacked: tlClipMin,
|
|
clipMaxPacked: tlClipMax);
|
|
hintY += 13.5f;
|
|
}
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// 2. Top-Right Radar Panel (0 GC allocs)
|
|
// -------------------------------------------------------------------------
|
|
private void EmitTopRightRadarPanel(IClientArenaSession session, MatchState state)
|
|
{
|
|
_hbCanvas.DrawPanelFrame(_topRightRect, BgDark, BorderCol, OrangeCol, cornerLen: 12f, borderPx: 1.5f);
|
|
|
|
float panelCenterX = _topRightRect.Position.X + _topRightRect.Size.X * 0.5f;
|
|
ReadOnlySpan<char> title = state.MapKind == ArenaMapKind.Sion
|
|
? "SION 3KM • RADAR"
|
|
: "DESERT RING • RADAR";
|
|
float titleW = _hbCanvas.MeasureTextWidth(title, 12f, wght: 650f);
|
|
_hbCanvas.DrawText(title, panelCenterX - titleW * 0.5f, _topRightRect.Position.Y + 20f, 12f, OrangeCol, wght: 650f);
|
|
|
|
Vector2 center = new(panelCenterX, _topRightRect.Position.Y + 26f + 107f);
|
|
const float radius = 214f * 0.47f;
|
|
float maxBlipRadius = MathF.Max(4f, radius - 3f);
|
|
float arenaHalf = MathF.Max(1f, state.Terrain.MapHalfExtent);
|
|
float scale = radius / arenaHalf;
|
|
float cameraYaw = _getCameraYaw();
|
|
int localId = session.LocalContenderId;
|
|
|
|
_hbCanvas.DrawCircleFilled(center.X, center.Y, radius, BgInner);
|
|
_hbCanvas.DrawCircleRing(center.X, center.Y, radius, 1.5f, BorderCol);
|
|
_hbCanvas.DrawLineSegment(center.X, center.Y - radius, center.X, center.Y - radius + 6f, 2.0f, CyanCol);
|
|
|
|
// Safe Circle
|
|
float safePx = MathF.Min(state.Spectators.SafeRadius * scale, maxBlipRadius);
|
|
_hbCanvas.DrawCircleRing(center.X, center.Y, safePx, 1.6f, OrangeCol);
|
|
|
|
// Ground drops
|
|
for (int i = 0; i < state.GroundDrops.Count; i++)
|
|
{
|
|
var d = state.GroundDrops[i];
|
|
if (d.PickedUp) continue;
|
|
var p = ClampToRadarDisc(center, MathF.Max(4f, radius - 4f), WorldToRadar(center, scale, d.X, d.Z, cameraYaw));
|
|
if (d.Chassis is not null)
|
|
{
|
|
_hbCanvas.DrawRectFilled(p.X - 2.5f, p.Y - 2.5f, 5f, 5f, CyanCol);
|
|
}
|
|
else if (d.Module is { IsImperial: true })
|
|
{
|
|
_hbCanvas.DrawCircleFilled(p.X, p.Y, 3.0f, GoldCol);
|
|
}
|
|
}
|
|
|
|
// Active descending Orbital Pods
|
|
var pods = session.ActivePods;
|
|
for (int i = 0; i < pods.Count; i++)
|
|
{
|
|
var pod = pods[i];
|
|
if (pod.Phase == OrbitalPodPhase.Popped) continue;
|
|
var pp = ClampToRadarDisc(center, MathF.Max(4f, radius - 5f), WorldToRadar(center, scale, pod.X, pod.Z, cameraYaw));
|
|
if (pod.PodKind == OrbitalPodKind.Contender)
|
|
{
|
|
bool isLocalPod = pod.ContenderId == localId;
|
|
bool isAllyPod = !isLocalPod && state.AreAllies(localId, pod.ContenderId);
|
|
if (isAllyPod)
|
|
{
|
|
_hbCanvas.DrawDiamond(pp.X, pp.Y, 4.6f, AlliedCol);
|
|
}
|
|
else
|
|
{
|
|
Color pCol = isLocalPod ? OliveCol : OrangeCol;
|
|
float sz = isLocalPod ? 10.5f : 7.0f;
|
|
_hbCanvas.DrawChevron(pp.X, pp.Y, sz, -MathF.PI * 0.5f, pCol);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool isImp = pod.WaveIndex > 0 || pod.Module?.IsImperial == true;
|
|
_hbCanvas.DrawDiamond(pp.X, pp.Y, 3.2f, isImp ? GoldCol : CyanCol);
|
|
}
|
|
}
|
|
|
|
// Spectator Wall (LOS / Tourist horizon rule / 5s ghost memory)
|
|
var contenderContacts = session.LocalContenderContacts;
|
|
var spectatorContacts = session.LocalSpectatorContacts;
|
|
var specs = state.Spectators.Spectators;
|
|
for (int i = 0; i < specs.Count; i++)
|
|
{
|
|
var s = specs[i];
|
|
if (!s.Alive) continue;
|
|
|
|
spectatorContacts.TryGetValue(s.Id, out var mem);
|
|
if (!MatchState.IsContactOnRadar(mem)) continue;
|
|
|
|
bool live = mem!.VisibleToPlayer;
|
|
bool hasLivePos = session.IsSpectatorVisible(s.Id) && (live || mem.FaintHorizonPing);
|
|
if (!hasLivePos && !mem.HasEverBeenSeen) continue;
|
|
|
|
float drawX = hasLivePos ? s.X : mem.LastSeenX;
|
|
float drawZ = hasLivePos ? s.Z : mem.LastSeenZ;
|
|
float blipR = 1.6f + s.RadarSignature * 3.1f;
|
|
float specClampR = MathF.Max(4f, radius - blipR - 1f);
|
|
var p = ClampToRadarDisc(center, specClampR, WorldToRadar(center, scale, drawX, drawZ, cameraYaw));
|
|
|
|
Color col = s.Tier switch
|
|
{
|
|
SpectatorTier.Tourist => GoldCol,
|
|
SpectatorTier.Patron => PatronColor,
|
|
_ => RedCol
|
|
};
|
|
|
|
if (live && s.Stance != SpectatorStance.Neutral && s.HasTargetLos && s.TargetContenderId.HasValue)
|
|
{
|
|
int tid = s.TargetContenderId.Value;
|
|
if (tid >= 0 && tid < state.Contenders.Count && state.Contenders[tid].Alive)
|
|
{
|
|
var tgt = state.Contenders[tid];
|
|
bool targetVisible = tgt.Id == localId ||
|
|
(session.IsContenderVisible(tgt.Id) && contenderContacts.TryGetValue(tgt.Id, out var tgtMem) && tgtMem.VisibleToPlayer);
|
|
if (targetVisible)
|
|
{
|
|
float tgtClampR = MathF.Max(4f, radius - (tgt.Id == localId ? 7.5f : 4.3f));
|
|
var tp = ClampToRadarDisc(center, tgtClampR, WorldToRadar(center, scale, tgt.X, tgt.Z, cameraYaw));
|
|
_hbCanvas.DrawLineSegment(p.X, p.Y, tp.X, tp.Y, 1.3f, new Color(RedCol.R, RedCol.G, RedCol.B, 0.65f));
|
|
}
|
|
}
|
|
col = RedCol;
|
|
}
|
|
|
|
if (!live)
|
|
{
|
|
float alpha = mem.FaintHorizonPing
|
|
? 0.42f
|
|
: Math.Clamp((1f - mem.LastSeenAge / MatchState.ContactGhostDuration) * 0.48f, 0.08f, 0.48f);
|
|
Color ghostCol = mem.FaintHorizonPing ? GoldCol : col;
|
|
_hbCanvas.DrawCircleFilled(p.X, p.Y, blipR, new Color(ghostCol.R, ghostCol.G, ghostCol.B, alpha));
|
|
}
|
|
else
|
|
{
|
|
_hbCanvas.DrawCircleFilled(p.X, p.Y, blipR, col);
|
|
}
|
|
}
|
|
|
|
// Contenders (player live chevron; allies diamond; rivals LOS + 5s ghost memory)
|
|
float sinY = MathF.Sin(cameraYaw);
|
|
float cosY = MathF.Cos(cameraYaw);
|
|
for (int i = 0; i < state.Contenders.Count; i++)
|
|
{
|
|
var c = state.Contenders[i];
|
|
if (!c.IsGroundedActive) continue;
|
|
|
|
if (c.Id == localId)
|
|
{
|
|
float playerClampR = MathF.Max(4f, radius - 6.5f - 1f);
|
|
var (lPos, _, _) = session.GetInterpolatedContenderPose(localId, 1f);
|
|
var p = ClampToRadarDisc(center, playerClampR, WorldToRadar(center, scale, lPos.X, lPos.Z, cameraYaw));
|
|
var dir = new Vector2(
|
|
-MathF.Sin(c.Yaw) * cosY + MathF.Cos(c.Yaw) * sinY,
|
|
-(MathF.Sin(c.Yaw) * sinY + MathF.Cos(c.Yaw) * cosY));
|
|
float ang = MathF.Atan2(dir.Y, dir.X);
|
|
_hbCanvas.DrawChevron(p.X, p.Y, 12.5f, ang, OliveCol);
|
|
continue;
|
|
}
|
|
|
|
if (state.AreAllies(localId, c.Id))
|
|
{
|
|
float allyClampR = MathF.Max(4f, radius - 4.6f - 1f);
|
|
var (aPos, _, _) = session.GetInterpolatedContenderPose(c.Id, 1f);
|
|
var p = ClampToRadarDisc(center, allyClampR, WorldToRadar(center, scale, aPos.X, aPos.Z, cameraYaw));
|
|
_hbCanvas.DrawDiamond(p.X, p.Y, 4.6f, AlliedCol);
|
|
continue;
|
|
}
|
|
|
|
contenderContacts.TryGetValue(c.Id, out var mem);
|
|
if (!MatchState.IsContactOnRadar(mem)) continue;
|
|
|
|
if (mem!.VisibleToPlayer)
|
|
{
|
|
float rivalClampR = MathF.Max(4f, radius - 3.3f - 1f);
|
|
float rx = session.IsContenderVisible(c.Id) ? c.X : mem.LastSeenX;
|
|
float rz = session.IsContenderVisible(c.Id) ? c.Z : mem.LastSeenZ;
|
|
var p = ClampToRadarDisc(center, rivalClampR, WorldToRadar(center, scale, rx, rz, cameraYaw));
|
|
_hbCanvas.DrawCircleFilled(p.X, p.Y, 3.3f, OrangeCol);
|
|
}
|
|
else
|
|
{
|
|
float ghostClampR = MathF.Max(4f, radius - 2.8f - 1f);
|
|
var p = ClampToRadarDisc(center, ghostClampR, WorldToRadar(center, scale, mem.LastSeenX, mem.LastSeenZ, cameraYaw));
|
|
float alpha = Math.Clamp((1f - mem.LastSeenAge / MatchState.ContactGhostDuration) * 0.48f, 0.08f, 0.48f);
|
|
_hbCanvas.DrawCircleFilled(p.X, p.Y, 2.8f, new Color(OrangeCol.R, OrangeCol.G, OrangeCol.B, alpha));
|
|
}
|
|
}
|
|
|
|
ReadOnlySpan<char> attrib = state.MapKind == ArenaMapKind.Sion
|
|
? "Data: swisstopo | [M] Switch Map"
|
|
: "[M] Switch to Sion 3 km";
|
|
float attribW = _hbCanvas.MeasureTextWidth(attrib, 10f, wght: 350f);
|
|
_hbCanvas.DrawText(attrib, panelCenterX - attribW * 0.5f, _topRightRect.End.Y - 9f, 10f, TextMuted, wght: 350f);
|
|
}
|
|
|
|
private static Vector2 WorldToRadar(Vector2 center, float scale, float wx, float wz, float camYaw)
|
|
{
|
|
float sinY = MathF.Sin(camYaw);
|
|
float cosY = MathF.Cos(camYaw);
|
|
float rx = -wx * cosY + wz * sinY;
|
|
float fy = wx * sinY + wz * cosY;
|
|
return center + new Vector2(rx, -fy) * scale;
|
|
}
|
|
|
|
private static Vector2 ClampToRadarDisc(Vector2 center, float maxRadius, Vector2 pt)
|
|
{
|
|
Vector2 delta = pt - center;
|
|
float dist = delta.Length();
|
|
if (dist > maxRadius && dist > 1e-4f)
|
|
{
|
|
return center + delta * (maxRadius / dist);
|
|
}
|
|
return pt;
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// 3. Crosshair, Heat Arc, Incoming Hit Arcs, Hit-Marker X, Pod Altimeter
|
|
// -------------------------------------------------------------------------
|
|
private void EmitCrosshairAndCombatFeedback(
|
|
MatchState state,
|
|
ContenderState player,
|
|
OrbitalPod? localPod,
|
|
Vector2 center)
|
|
{
|
|
const float gap = 6f;
|
|
const float tick = 10f;
|
|
bool allDisabled = player.Alive &&
|
|
player.InArcWeaponCount == 0 && player.OutOfArcWeaponCount == 0 && player.DisabledWeaponCount > 0;
|
|
bool outOfArc = player.Alive && player.AllWeaponsOutOfArc;
|
|
Color retCol = (outOfArc || allDisabled)
|
|
? new Color(RedCol.R, RedCol.G, RedCol.B, 0.95f)
|
|
: new Color(TextLight.R, TextLight.G, TextLight.B, 0.88f);
|
|
|
|
_hbCanvas.DrawCircleFilled(center.X, center.Y, 1.8f, retCol);
|
|
_hbCanvas.DrawLineSegment(center.X - gap - tick, center.Y, center.X - gap, center.Y, 1.6f, retCol);
|
|
_hbCanvas.DrawLineSegment(center.X + gap, center.Y, center.X + gap + tick, center.Y, 1.6f, retCol);
|
|
_hbCanvas.DrawLineSegment(center.X, center.Y - gap - tick, center.X, center.Y - gap, 1.6f, retCol);
|
|
_hbCanvas.DrawLineSegment(center.X, center.Y + gap, center.X, center.Y + gap + tick, 1.6f, retCol);
|
|
|
|
// Outgoing hit-marker X-flash
|
|
if (_hitMarkerRemaining > 0f && _hitMarkerDuration > 0.001f && _hitMarkerKind != HitMarkerKind.None)
|
|
{
|
|
float frac = Math.Clamp(_hitMarkerRemaining / _hitMarkerDuration, 0f, 1f);
|
|
float pop = 1.0f + (1.0f - frac) * 0.25f;
|
|
Color xCol = _hitMarkerKind switch
|
|
{
|
|
HitMarkerKind.Kill => new Color(RedCol.R, RedCol.G, RedCol.B, frac * 0.98f),
|
|
HitMarkerKind.Core => new Color(1.0f, 0.28f, 0.16f, frac * 0.95f),
|
|
_ => new Color(1.0f, 0.95f, 0.78f, frac * 0.92f)
|
|
};
|
|
float xWidth = _hitMarkerKind == HitMarkerKind.Armor ? 2.0f : 2.8f;
|
|
float rIn = 6.5f * pop;
|
|
float rOut = (_hitMarkerKind == HitMarkerKind.Armor ? 13.5f : 15.5f) * pop;
|
|
const float diag = 0.70710678f;
|
|
for (int q = 0; q < 4; q++)
|
|
{
|
|
float sx = (q & 1) == 0 ? 1f : -1f;
|
|
float sy = (q & 2) == 0 ? 1f : -1f;
|
|
Vector2 dir = new(sx * diag, sy * diag);
|
|
_hbCanvas.DrawLineSegment(
|
|
center.X + dir.X * rIn, center.Y + dir.Y * rIn,
|
|
center.X + dir.X * rOut, center.Y + dir.Y * rOut,
|
|
xWidth, xCol);
|
|
if (_hitMarkerKind == HitMarkerKind.Kill)
|
|
{
|
|
_hbCanvas.DrawLineSegment(
|
|
center.X + dir.X * (rOut + 4f), center.Y + dir.Y * (rOut + 4f),
|
|
center.X + dir.X * (rOut + 10.5f), center.Y + dir.Y * (rOut + 10.5f),
|
|
2.2f, new Color(GoldCol.R, GoldCol.G, GoldCol.B, frac * 0.95f));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (allDisabled)
|
|
{
|
|
ReadOnlySpan<char> msg = "WEAPONS STRIPPED";
|
|
float mw = _hbCanvas.MeasureTextWidth(msg, 11.5f, wght: 600f);
|
|
_hbCanvas.DrawText(msg, center.X - mw * 0.5f, center.Y + 38f, 11.5f, RedCol, wght: 600f);
|
|
}
|
|
else if (outOfArc)
|
|
{
|
|
ReadOnlySpan<char> msg = "OUT OF ARC";
|
|
float mw = _hbCanvas.MeasureTextWidth(msg, 11.5f, wght: 600f);
|
|
_hbCanvas.DrawText(msg, center.X - mw * 0.5f, center.Y + 38f, 11.5f, RedCol, wght: 600f);
|
|
}
|
|
|
|
if (!player.Alive)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (player.IsInDropPod)
|
|
{
|
|
float agl = localPod is not null ? MathF.Max(0f, localPod.LastAgl) : 0f;
|
|
float vel = localPod is not null ? MathF.Max(0f, -localPod.VelY) : 0f;
|
|
float horizSpeed = localPod is not null
|
|
? MathF.Sqrt(localPod.VelX * localPod.VelX + localPod.VelZ * localPod.VelZ)
|
|
: player.Speed;
|
|
bool burning = localPod?.Phase == OrbitalPodPhase.RetroBurn;
|
|
Color bracketCol = burning ? OrangeCol : CyanCol;
|
|
|
|
float startAlt = OrbitalPodPreset.GetStartAltAgl(OrbitalPodKind.Contender, state.MapKind);
|
|
float altFrac = Math.Clamp(agl / MathF.Max(1f, startAlt), 0f, 1f);
|
|
const float barX = 72f;
|
|
const float barH = 76f;
|
|
float topY = center.Y - barH * 0.5f;
|
|
Color trackCol = new(BorderCol.R, BorderCol.G, BorderCol.B, 0.55f);
|
|
_hbCanvas.DrawLineSegment(center.X - barX, topY, center.X - barX, topY + barH, 2.0f, trackCol);
|
|
_hbCanvas.DrawLineSegment(center.X + barX, topY, center.X + barX, topY + barH, 2.0f, trackCol);
|
|
|
|
float fillH = barH * altFrac;
|
|
if (fillH > 0.5f)
|
|
{
|
|
_hbCanvas.DrawLineSegment(center.X - barX, topY + barH - fillH, center.X - barX, topY + barH, 3.0f, bracketCol);
|
|
_hbCanvas.DrawLineSegment(center.X + barX, topY + barH - fillH, center.X + barX, topY + barH, 3.0f, bracketCol);
|
|
}
|
|
|
|
SpanWriter sw = new(_scratch);
|
|
sw.Append("ALT "); sw.AppendFloat(agl, "F0"); sw.Append("m | HORIZ ");
|
|
sw.AppendFloat(horizSpeed, "F0"); sw.Append(" m/s | VERT ");
|
|
sw.AppendFloat(vel, "F0"); sw.Append(" m/s");
|
|
float tw = _hbCanvas.MeasureTextWidth(sw.Span, 11.5f, wght: 500f);
|
|
_hbCanvas.DrawText(sw.Span, center.X - tw * 0.5f, center.Y + 56f, 11.5f, bracketCol, wght: 500f);
|
|
|
|
if (burning)
|
|
{
|
|
ReadOnlySpan<char> burnTxt = "RETRO BURN ACTIVE";
|
|
float bw = _hbCanvas.MeasureTextWidth(burnTxt, 11.5f, wght: 650f);
|
|
_hbCanvas.DrawText(burnTxt, center.X - bw * 0.5f, center.Y - 50f, 11.5f, OrangeCol, wght: 650f);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Thermal heat-arc indicator around crosshair
|
|
float heatRatio = 0f;
|
|
bool overPlateau = false;
|
|
var mounted = player.Grid.Mounted;
|
|
for (int i = 0; i < mounted.Count; i++)
|
|
{
|
|
var m = mounted[i];
|
|
if (m.Spec.Kind == HardpointKind.Weapon)
|
|
{
|
|
float r = Math.Clamp(
|
|
(m.CurrentTemp - ChassisGrid.AmbientTemp) / MathF.Max(1f, m.Spec.MaxTemp - ChassisGrid.AmbientTemp),
|
|
0f, 1f);
|
|
if (r > heatRatio) heatRatio = r;
|
|
if (m.CurrentTemp > m.Spec.OptimalTemp + m.Spec.PlateauWidth * 0.5f)
|
|
{
|
|
overPlateau = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
const float arcRadius = 21f;
|
|
const float startAngle = -MathF.PI * 0.75f;
|
|
const float maxSweep = MathF.PI * 1.5f;
|
|
_hbCanvas.DrawArcStrokeStatic(
|
|
center.X, center.Y, arcRadius, 2.0f,
|
|
startAngle, startAngle + maxSweep,
|
|
rotationRadScreen: 0f,
|
|
new VectorBlobKey(VectorShapeKind.ThermalHeatArc, 0, 0),
|
|
new Color(BorderCol.R, BorderCol.G, BorderCol.B, 0.40f));
|
|
|
|
if (heatRatio > 0.01f)
|
|
{
|
|
const int heatSteps = 135; // 2-degree increments across 270 deg
|
|
int step = Math.Clamp((int)MathF.Round(heatRatio * heatSteps), 1, heatSteps);
|
|
float sweep = maxSweep * (step / (float)heatSteps);
|
|
Color heatCol = overPlateau ? RedCol : (heatRatio > 0.65f ? OrangeCol : OliveCol);
|
|
_hbCanvas.DrawArcStrokeStatic(
|
|
center.X, center.Y, arcRadius, 2.5f,
|
|
startAngle, startAngle + sweep,
|
|
rotationRadScreen: 0f,
|
|
new VectorBlobKey(VectorShapeKind.ThermalHeatArc, (ushort)step, 1),
|
|
heatCol);
|
|
}
|
|
|
|
// Directional incoming-hit indicator arcs (single cached static arc rotated per angle -> 0 dynamic atlas uploads)
|
|
if (_incomingArcCount > 0)
|
|
{
|
|
float cameraYaw = _getCameraYaw();
|
|
float sinY = MathF.Sin(cameraYaw);
|
|
float cosY = MathF.Cos(cameraYaw);
|
|
for (int i = 0; i < _incomingArcCount; i++)
|
|
{
|
|
var arc = _incomingArcs[i];
|
|
float alpha = Math.Clamp(1f - arc.Age / HitArcDuration, 0f, 1f);
|
|
if (alpha <= 0.01f) continue;
|
|
|
|
float dx = arc.SourceX - player.X;
|
|
float dz = arc.SourceZ - player.Z;
|
|
float rx = -dx * cosY + dz * sinY;
|
|
float fy = dx * sinY + dz * cosY;
|
|
float angle = (rx * rx + fy * fy) > 1e-4f ? MathF.Atan2(-fy, rx) : 0f;
|
|
|
|
Color arcCol = arc.WeaponClass switch
|
|
{
|
|
WeaponVisualClass.Explosive => new Color(1.0f, 0.36f, 0.12f, alpha * 0.96f),
|
|
WeaponVisualClass.RocketSalvo => new Color(1.0f, 0.56f, 0.14f, alpha * 0.96f),
|
|
WeaponVisualClass.ThermalBeam => new Color(0.30f, 0.90f, 1.0f, alpha * 0.96f),
|
|
WeaponVisualClass.GaussRail => new Color(0.24f, 0.78f, 1.0f, alpha * 0.98f),
|
|
WeaponVisualClass.PlasmaPpc => new Color(0.18f, 0.92f, 0.96f, alpha * 0.96f),
|
|
WeaponVisualClass.SwarmSmart => new Color(0.56f, 0.96f, 0.28f, alpha * 0.96f),
|
|
_ => new Color(0.96f, 0.72f, 0.22f, alpha * 0.94f)
|
|
};
|
|
|
|
const float hitR = 39f;
|
|
const float halfSpan = 0.34f;
|
|
_hbCanvas.DrawArcStrokeStatic(
|
|
center.X, center.Y, hitR, 4.2f,
|
|
-halfSpan, halfSpan,
|
|
rotationRadScreen: angle,
|
|
new VectorBlobKey(VectorShapeKind.IncomingHitArc, 0, 0),
|
|
arcCol);
|
|
if (arc.WeaponClass is WeaponVisualClass.ThermalBeam or WeaponVisualClass.GaussRail or WeaponVisualClass.PlasmaPpc)
|
|
{
|
|
_hbCanvas.DrawArcStrokeStatic(
|
|
center.X, center.Y, hitR - 3.5f, 2.0f,
|
|
-halfSpan * 0.75f, halfSpan * 0.75f,
|
|
rotationRadScreen: angle,
|
|
new VectorBlobKey(VectorShapeKind.IncomingHitArc, 1, 0),
|
|
new Color(GoldCol.R, GoldCol.G, GoldCol.B, alpha * 0.90f));
|
|
}
|
|
|
|
float cosA = MathF.Cos(angle);
|
|
float sinA = MathF.Sin(angle);
|
|
_hbCanvas.DrawDirectionalArrow(center.X + cosA * (hitR + 4.5f), center.Y + sinA * (hitR + 4.5f), 11f, angle, arcCol);
|
|
}
|
|
|
|
var latest = _incomingArcs[_incomingArcCount - 1];
|
|
float tagAlpha = Math.Clamp(1f - latest.Age / HitArcDuration, 0f, 1f);
|
|
(string tagText, Color tagCol) = latest.WeaponClass switch
|
|
{
|
|
WeaponVisualClass.Autocannon => ("20MM IMPACT", new Color(0.98f, 0.70f, 0.20f, tagAlpha)),
|
|
WeaponVisualClass.Explosive => ("BLAST IMPACT", new Color(1.0f, 0.38f, 0.14f, tagAlpha)),
|
|
WeaponVisualClass.RocketSalvo => ("ROCKET HIT", new Color(1.0f, 0.58f, 0.18f, tagAlpha)),
|
|
WeaponVisualClass.ThermalBeam => ("THERMAL HIT", new Color(0.36f, 0.92f, 1.0f, tagAlpha)),
|
|
WeaponVisualClass.GaussRail => ("GAUSS RAIL", new Color(0.28f, 0.84f, 1.0f, tagAlpha)),
|
|
WeaponVisualClass.PlasmaPpc => ("PLASMA BURN", new Color(0.24f, 0.94f, 0.98f, tagAlpha)),
|
|
WeaponVisualClass.SwarmSmart => ("SWARM HIT", new Color(0.58f, 0.96f, 0.30f, tagAlpha)),
|
|
_ => ("KINETIC HIT", new Color(0.96f, 0.78f, 0.28f, tagAlpha))
|
|
};
|
|
float tagW = _hbCanvas.MeasureTextWidth(tagText, 10.5f, wght: 600f);
|
|
_hbCanvas.DrawText(tagText, center.X - tagW * 0.5f, center.Y + 56f, 10.5f, tagCol, wght: 600f);
|
|
}
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// 4. Bottom-Left Panel: Schematic + Hover + Cargo + Garage
|
|
// -------------------------------------------------------------------------
|
|
private void EmitBottomLeftPanel(ChassisGrid grid)
|
|
{
|
|
// Draw frame & borders ONLY (backdrop is _bottomLeftBg behind _schematic so inactive holes stay BgDark)
|
|
_hbCanvas.DrawPanelFrame(_bottomLeftRect, BgDark, BorderCol, OrangeCol, cornerLen: 12f, borderPx: 1.5f, drawBg: false);
|
|
|
|
float leftX = _bottomLeftRect.Position.X + 10f;
|
|
float topY = _bottomLeftRect.Position.Y + 8f;
|
|
float gridW = _schematicRect.Size.X;
|
|
|
|
_hbCanvas.DrawText("HARDPOINTS & HEAT", leftX, topY + 12f, 12f, OrangeCol, wght: 650f);
|
|
|
|
// Hardpoint L-brackets, hull outlines, stripped X-marks, compatibility pulses, Krypton labels
|
|
_schematic.EmitHbGpuOverlay(_hbCanvas, _schematicRect.Position, _vignetteTime);
|
|
|
|
// Hover telemetry beneath schematic
|
|
float hoverY = _schematicRect.End.Y + 4f;
|
|
for (int i = 0; i < _hoverLines.Count; i++)
|
|
{
|
|
_hbCanvas.DrawText(_hoverLines[i], leftX, hoverY + 11f, 10f, _cachedHoverColor, wght: 400f);
|
|
hoverY += 13.5f;
|
|
}
|
|
|
|
// Middle column: Salvage Cargo Rack (0 dynamic Button nodes)
|
|
float cargoX = _schematicRect.End.X + 8f;
|
|
const float cargoW = 156f;
|
|
SpanWriter sw = new(_scratch);
|
|
sw.Append("SALVAGE CARGO (");
|
|
sw.AppendInt(grid.Cargo.Count);
|
|
sw.Append("/");
|
|
sw.AppendInt(grid.Spec.CargoCapacity);
|
|
sw.Append(")");
|
|
_hbCanvas.DrawText(sw.Span, cargoX, topY + 11f, 11f, OliveCol, wght: 600f);
|
|
|
|
float rowY = topY + 18f;
|
|
_cargoHitCount = 0;
|
|
if (grid.Cargo.Count == 0)
|
|
{
|
|
_hbCanvas.DrawText("No modules in rack.", cargoX, rowY + 11f, 10.5f, TextMuted, wght: 350f);
|
|
_hbCanvas.DrawText("Press [E] near crates.", cargoX, rowY + 24f, 10.5f, TextMuted, wght: 350f);
|
|
}
|
|
else
|
|
{
|
|
Viewport? vp = GetViewport();
|
|
Vector2 mousePos = (vp is not null && Input.MouseMode == Input.MouseModeEnum.Visible)
|
|
? vp.GetMousePosition()
|
|
: new Vector2(-9999f, -9999f);
|
|
|
|
int count = Math.Min(grid.Cargo.Count, MaxCargoHitRects);
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
var mod = grid.Cargo[i];
|
|
const float rowH = 19f;
|
|
const float fitW = 32f;
|
|
Rect2 rowRect = new(cargoX, rowY, cargoW - fitW - 3f, rowH);
|
|
Rect2 fitRect = new(cargoX + cargoW - fitW, rowY, fitW, rowH);
|
|
_cargoRowRects[i] = rowRect;
|
|
_cargoFitRects[i] = fitRect;
|
|
_cargoHitCount = i + 1;
|
|
|
|
bool rowHovered = rowRect.HasPoint(mousePos);
|
|
bool fitHovered = fitRect.HasPoint(mousePos);
|
|
bool selected = _selectedCargoIndex == i;
|
|
|
|
Color rowBg = selected ? new Color(0.24f, 0.18f, 0.10f, 0.92f) : (rowHovered ? BgRowHover : BgInner);
|
|
Color rowBorder = selected ? OrangeCol : (mod.IsImperial ? GoldCol : BorderCol);
|
|
_hbCanvas.DrawRectFilled(rowRect.Position.X, rowRect.Position.Y, rowRect.Size.X, rowRect.Size.Y, rowBg);
|
|
_hbCanvas.DrawRectOutline(rowRect.Position.X, rowRect.Position.Y, rowRect.Size.X, rowRect.Size.Y, 1.0f, rowBorder);
|
|
|
|
Color txtCol = selected ? OrangeCol : (mod.IsImperial ? GoldCol : TextLight);
|
|
float nameX = rowRect.Position.X + 5f;
|
|
float maxTextW = rowRect.Size.X - 10f;
|
|
if (mod.IsImperial)
|
|
{
|
|
float starW = _hbCanvas.DrawText("* ", nameX, rowRect.Position.Y + 13f, 10f, GoldCol, wght: 700f);
|
|
nameX += starW;
|
|
maxTextW = MathF.Max(8f, maxTextW - starW);
|
|
}
|
|
ReadOnlySpan<char> displayName = TruncateWithEllipsis(mod.Name, maxTextW, 10f, 450f, _scratch);
|
|
_hbCanvas.DrawText(displayName, nameX, rowRect.Position.Y + 13f, 10f, txtCol, wght: 450f);
|
|
|
|
Color fitBg = fitHovered ? new Color(0.22f, 0.28f, 0.20f, 0.96f) : BgInner;
|
|
_hbCanvas.DrawRectFilled(fitRect.Position.X, fitRect.Position.Y, fitRect.Size.X, fitRect.Size.Y, fitBg);
|
|
_hbCanvas.DrawRectOutline(fitRect.Position.X, fitRect.Position.Y, fitRect.Size.X, fitRect.Size.Y, 1.0f, fitHovered ? OliveCol : BorderCol);
|
|
float fw = _hbCanvas.MeasureTextWidth("FIT", 9.5f, wght: 650f);
|
|
_hbCanvas.DrawText("FIT", fitRect.Position.X + (fitW - fw) * 0.5f, fitRect.Position.Y + 13f, 9.5f, fitHovered ? Colors.White : TextLight, wght: 650f);
|
|
|
|
rowY += 21f;
|
|
}
|
|
}
|
|
|
|
// Optional Garage Details column when Tab is expanded
|
|
if (_garageExpanded)
|
|
{
|
|
float garageX = cargoX + cargoW + 8f;
|
|
float gy = topY + 11f;
|
|
for (int i = 0; i < _garageLines.Count; i++)
|
|
{
|
|
_hbCanvas.DrawText(_garageLines[i], garageX, gy, 10f, i <= 1 ? OliveCol : TextMuted, wght: i <= 1 ? 550f : 380f);
|
|
gy += 13.5f;
|
|
}
|
|
}
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// 5. Broadcast Chyron & Outcome Banner
|
|
// -------------------------------------------------------------------------
|
|
private void EmitChyronPanel()
|
|
{
|
|
_hbCanvas.DrawPanelFrame(_chyronRect, BgDark, BorderCol, GoldCol, cornerLen: 12f, borderPx: 1.5f);
|
|
|
|
float x = _chyronRect.Position.X + 10f;
|
|
float y = _chyronRect.Position.Y + 8f;
|
|
_hbCanvas.DrawText("IMPERIAL BROADCAST FEED", x, y + 11f, 11f, GoldCol, wght: 650f);
|
|
y += 17f;
|
|
|
|
HbGpuCommandWriter.PackClipRect(
|
|
_chyronRect.Position.X + 8f, _chyronRect.Position.Y + 6f,
|
|
_chyronRect.Size.X - 16f, _chyronRect.Size.Y - 12f,
|
|
out uint cMin, out uint cMax);
|
|
|
|
for (int i = 0; i < _chyronLineCount; i++)
|
|
{
|
|
bool latest = _chyronIsLatest[i];
|
|
_hbCanvas.DrawText(
|
|
_chyronDisplayLines[i],
|
|
x, y + 12f,
|
|
latest ? 11.5f : 10.8f,
|
|
latest ? TextLight : TextMuted,
|
|
wght: latest ? 500f : 380f,
|
|
clipMinPacked: cMin,
|
|
clipMaxPacked: cMax);
|
|
y += 19f;
|
|
}
|
|
}
|
|
|
|
private void EmitOutcomeBanner(
|
|
IClientArenaSession session,
|
|
MatchState state,
|
|
ContenderState player,
|
|
NetworkStatusSnapshot net)
|
|
{
|
|
var outcome = session.LocalOutcome;
|
|
Color accent;
|
|
ReadOnlySpan<char> title;
|
|
ReadOnlySpan<char> sub;
|
|
|
|
if (outcome == ClientMatchOutcome.Victory)
|
|
{
|
|
accent = OliveCol;
|
|
title = "VICTORY — LAST RIG STANDING";
|
|
sub = net.Mode == NetworkMode.RemoteClient ? "Next round starting soon..." : "[R] New Drop";
|
|
}
|
|
else if (outcome == ClientMatchOutcome.Defeat)
|
|
{
|
|
accent = RedCol;
|
|
title = !player.Alive ? "CHASSIS DESTROYED" : "MATCH COMPLETED — DEFEAT";
|
|
sub = net.Mode == NetworkMode.RemoteClient
|
|
? (state.Phase == MatchPhase.Completed ? "Waiting for server next round..." : "Spectating live match...")
|
|
: "[R] Redeploy";
|
|
}
|
|
else
|
|
{
|
|
accent = CyanCol;
|
|
var wave = session.DropWaveState;
|
|
float eta = wave.NextWaveAtSec is float nxt ? MathF.Max(0f, nxt - state.Time) : 0f;
|
|
SpanWriter sw = new(_scratch);
|
|
sw.Append("AWAITING PATRON WAVE ");
|
|
sw.AppendInt(wave.NextWaveIndex);
|
|
_hbCanvas.DrawPanelFrame(_outcomeRect, BgDark, BorderCol, accent, cornerLen: 16f, borderPx: 2.0f);
|
|
float cx = _outcomeRect.Position.X + _outcomeRect.Size.X * 0.5f;
|
|
float w1 = _hbCanvas.MeasureTextWidth(sw.Span, 20f, wght: 700f);
|
|
_hbCanvas.DrawText(sw.Span, cx - w1 * 0.5f, _outcomeRect.Position.Y + 36f, 20f, accent, wght: 700f);
|
|
|
|
sw = new SpanWriter(_scratch);
|
|
sw.Append("RESPAWN IN ");
|
|
sw.AppendFloat(eta, "F1");
|
|
sw.Append("s (RESP: ");
|
|
sw.AppendInt(player.RespawnsRemaining);
|
|
sw.Append(" LEFT)");
|
|
float w2 = _hbCanvas.MeasureTextWidth(sw.Span, 14f, wght: 500f);
|
|
_hbCanvas.DrawText(sw.Span, cx - w2 * 0.5f, _outcomeRect.Position.Y + 60f, 14f, accent, wght: 500f);
|
|
return;
|
|
}
|
|
|
|
_hbCanvas.DrawPanelFrame(_outcomeRect, BgDark, BorderCol, accent, cornerLen: 16f, borderPx: 2.0f);
|
|
float centerX = _outcomeRect.Position.X + _outcomeRect.Size.X * 0.5f;
|
|
float tw1 = _hbCanvas.MeasureTextWidth(title, 20f, wght: 700f);
|
|
float tw2 = _hbCanvas.MeasureTextWidth(sub, 14f, wght: 500f);
|
|
_hbCanvas.DrawText(title, centerX - tw1 * 0.5f, _outcomeRect.Position.Y + 36f, 20f, accent, wght: 700f);
|
|
_hbCanvas.DrawText(sub, centerX - tw2 * 0.5f, _outcomeRect.Position.Y + 60f, 14f, accent, wght: 500f);
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// 6. 3D World Markers: Squad Chevrons + Target Boxes + Offscreen Arrows
|
|
// Preserves ALL Soul-verified invariants from 8310246 (0 GC allocs on hot path)
|
|
// -------------------------------------------------------------------------
|
|
private void EmitWorldMarkers(
|
|
IClientArenaSession session,
|
|
MatchState state,
|
|
ContenderState localPlayer,
|
|
Vector2 viewSize)
|
|
{
|
|
if (_projectWorld is null || viewSize.X < 64f || viewSize.Y < 64f)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int localId = session.LocalContenderId;
|
|
if (localId < 0 || localId >= state.Contenders.Count || !localPlayer.Alive)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var (localPos, _, _) = session.GetInterpolatedContenderPose(localId, 1f);
|
|
Vector2 center = viewSize * 0.5f;
|
|
float halfW = MathF.Max(16f, center.X - BorderPad);
|
|
float halfH = MathF.Max(16f, center.Y - BorderPad);
|
|
|
|
// 1. Allied squad chevrons (only when SquadSize > 1: Solo vs Trio mutual exclusion)
|
|
if (state.SquadSize > 1)
|
|
{
|
|
for (int i = 0; i < state.Contenders.Count; i++)
|
|
{
|
|
var c = state.Contenders[i];
|
|
if (c.Id == localId || !c.Alive || !state.AreAllies(localId, c.Id)) continue;
|
|
|
|
var (allyPos, _, _) = session.GetInterpolatedContenderPose(c.Id, 1f);
|
|
float dist = (allyPos - localPos).Length();
|
|
float headOffset = c.IsInDropPod ? 3.4f : (c.Grid.Spec.HalfHeight + 1.9f);
|
|
var worldHead = new System.Numerics.Vector3(allyPos.X, allyPos.Y + headOffset, allyPos.Z);
|
|
var (valid, inFront, sp, camLocal) = _projectWorld(worldHead);
|
|
if (!valid) continue;
|
|
|
|
bool inFrame = inFront &&
|
|
sp.X >= BorderPad && sp.X <= viewSize.X - BorderPad &&
|
|
sp.Y >= BorderPad && sp.Y <= viewSize.Y - BorderPad;
|
|
|
|
SpanWriter sw = new(_scratch);
|
|
sw.Append(c.Name);
|
|
sw.Append(" ");
|
|
sw.AppendFloat(dist, "F0");
|
|
sw.Append("m");
|
|
ReadOnlySpan<char> label = sw.Span;
|
|
|
|
if (inFrame)
|
|
{
|
|
// Pointing down chevron above ally head (+PI/2 in screen coords)
|
|
_hbCanvas.DrawChevron(sp.X, sp.Y, 12f, MathF.PI * 0.5f, AlliedCol);
|
|
float lw = _hbCanvas.MeasureTextWidth(label, 10.5f, wght: 550f);
|
|
float lx = Math.Clamp(sp.X - lw * 0.5f, 6f, MathF.Max(6f, viewSize.X - lw - 6f));
|
|
float ly = sp.Y - 10f;
|
|
var aboveBox = new Rect2(lx - 1f, ly - 11f, lw + 2f, 13f);
|
|
if (IntersectsStaticHudPanel(aboveBox) || aboveBox.Position.Y < 2f)
|
|
{
|
|
ly = sp.Y + 19f;
|
|
}
|
|
var finalBox = new Rect2(lx - 1f, ly - 11f, lw + 2f, 13f);
|
|
if (!IntersectsStaticHudPanel(finalBox))
|
|
{
|
|
_hbCanvas.DrawText(label, lx, ly, 10.5f, AlliedCol, wght: 550f);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Vector2 dir = ComputeOffscreenDirection(camLocal);
|
|
Vector2 edge = ComputeSafeEdgePos(center, halfW, halfH, dir);
|
|
float angle = MathF.Atan2(dir.Y, dir.X);
|
|
_hbCanvas.DrawDirectionalArrow(edge.X, edge.Y, 13f, angle, new Color(AlliedCol.R, AlliedCol.G, AlliedCol.B, 0.88f));
|
|
Vector2 textPos = ComputeInwardLabelPos(edge, dir, viewSize, label);
|
|
_hbCanvas.DrawText(label, textPos.X, textPos.Y, 10.5f, new Color(AlliedCol.R, AlliedCol.G, AlliedCol.B, 0.90f), wght: 550f);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 2. Visible enemy contenders (strictly obeying fog-of-war / LOS)
|
|
var contenderContacts = session.LocalContenderContacts;
|
|
var spectatorContacts = session.LocalSpectatorContacts;
|
|
_offscreenHostiles.Clear();
|
|
|
|
for (int i = 0; i < state.Contenders.Count; i++)
|
|
{
|
|
var c = state.Contenders[i];
|
|
if (c.Id == localId || !c.Alive || state.AreAllies(localId, c.Id)) continue;
|
|
if (!session.IsContenderVisible(c.Id)) continue;
|
|
if (!contenderContacts.TryGetValue(c.Id, out var mem) || !mem.VisibleToPlayer) continue;
|
|
|
|
var (pos, rot, _) = session.GetInterpolatedContenderPose(c.Id, 1f);
|
|
float dist = (pos - localPos).Length();
|
|
bool targetingLocal = c.AiTargetContenderId == localId;
|
|
Color col = targetingLocal ? RedCol : OrangeCol;
|
|
float hpRatio = c.Grid.MaxCoreHp > 0f ? c.Grid.CoreHp / c.Grid.MaxCoreHp : 1f;
|
|
|
|
float halfBoundW = c.IsInDropPod ? 1.4f : c.Grid.Spec.HalfWidth;
|
|
float halfBoundH = c.IsInDropPod ? 1.8f : c.Grid.Spec.HalfHeight;
|
|
float halfBoundL = c.IsInDropPod ? 1.4f : c.Grid.Spec.HalfLength;
|
|
|
|
ProcessHostileTarget(
|
|
pos, rot, halfBoundW, halfBoundH, halfBoundL,
|
|
dist, hpRatio, col, targetingLocal, viewSize);
|
|
}
|
|
|
|
// 3. Visible hostile/provoked spectators (neutral tourists do NOT get hostile target boxes)
|
|
var specs = state.Spectators.Spectators;
|
|
for (int i = 0; i < specs.Count; i++)
|
|
{
|
|
var s = specs[i];
|
|
if (!s.Alive || s.Stance == SpectatorStance.Neutral) continue;
|
|
if (!session.IsSpectatorVisible(s.Id)) continue;
|
|
if (!spectatorContacts.TryGetValue(s.Id, out var mem) || !mem.VisibleToPlayer) continue;
|
|
|
|
var (pos, rot, _) = session.GetInterpolatedSpectatorPose(s.Id, 1f);
|
|
float dist = (pos - localPos).Length();
|
|
bool lockedOnLocal = s.TargetContenderId == localId;
|
|
float hpRatio = s.Grid.MaxCoreHp > 0f ? s.Grid.CoreHp / s.Grid.MaxCoreHp : 1f;
|
|
|
|
ProcessHostileTarget(
|
|
pos, rot, s.Grid.Spec.HalfWidth, s.Grid.Spec.HalfHeight, s.Grid.Spec.HalfLength,
|
|
dist, hpRatio, RedCol, lockedOnLocal, viewSize);
|
|
}
|
|
|
|
// 4. Off-screen hostile arrows (locked-on threats first, then nearest visible hostiles)
|
|
if (_offscreenHostiles.Count > 0)
|
|
{
|
|
_offscreenHostiles.Sort(OffscreenSortComparison);
|
|
int count = Math.Min(_offscreenHostiles.Count, MaxOffscreenHostileArrows);
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
EmitOffscreenArrow(_offscreenHostiles[i], viewSize, center, halfW, halfH);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ProcessHostileTarget(
|
|
System.Numerics.Vector3 worldCenter,
|
|
System.Numerics.Quaternion rot,
|
|
float halfBoundW,
|
|
float halfBoundH,
|
|
float halfBoundL,
|
|
float dist,
|
|
float hpRatio,
|
|
Color col,
|
|
bool isLockedOnLocal,
|
|
Vector2 viewSize)
|
|
{
|
|
var (cValid, cInFront, cSp, cCamLocal) = _projectWorld!(worldCenter);
|
|
if (!cValid) return;
|
|
|
|
bool inFrame = cInFront &&
|
|
cSp.X >= BorderPad && cSp.X <= viewSize.X - BorderPad &&
|
|
cSp.Y >= BorderPad && cSp.Y <= viewSize.Y - BorderPad;
|
|
|
|
if (!inFrame)
|
|
{
|
|
if (isLockedOnLocal || dist <= OffscreenHostileMaxDistance)
|
|
{
|
|
_offscreenHostiles.Add(new OffscreenMarker(cCamLocal, dist, col, isLockedOnLocal));
|
|
}
|
|
return;
|
|
}
|
|
|
|
float minX = float.PositiveInfinity, minY = float.PositiveInfinity;
|
|
float maxX = float.NegativeInfinity, maxY = float.NegativeInfinity;
|
|
bool allCornersInFront = true;
|
|
|
|
for (int sx = -1; sx <= 1; sx += 2)
|
|
{
|
|
for (int sy = -1; sy <= 1; sy += 2)
|
|
{
|
|
for (int sz = -1; sz <= 1; sz += 2)
|
|
{
|
|
var localCorner = new System.Numerics.Vector3(sx * halfBoundW, sy * halfBoundH, sz * halfBoundL);
|
|
var worldCorner = worldCenter + System.Numerics.Vector3.Transform(localCorner, rot);
|
|
var (valid, inFront, sp, _) = _projectWorld(worldCorner);
|
|
if (!valid || !inFront)
|
|
{
|
|
allCornersInFront = false;
|
|
break;
|
|
}
|
|
if (sp.X < minX) minX = sp.X;
|
|
if (sp.X > maxX) maxX = sp.X;
|
|
if (sp.Y < minY) minY = sp.Y;
|
|
if (sp.Y > maxY) maxY = sp.Y;
|
|
}
|
|
if (!allCornersInFront) break;
|
|
}
|
|
if (!allCornersInFront) break;
|
|
}
|
|
|
|
if (!allCornersInFront)
|
|
{
|
|
var (topValid, topFront, topSp, _) = _projectWorld(worldCenter + new System.Numerics.Vector3(0f, halfBoundH, 0f));
|
|
var (botValid, botFront, botSp, _) = _projectWorld(worldCenter - new System.Numerics.Vector3(0f, halfBoundH, 0f));
|
|
float rawH = (topValid && topFront && botValid && botFront)
|
|
? MathF.Abs(botSp.Y - topSp.Y) + 8f
|
|
: 44f;
|
|
float horizRadius = MathF.Max(halfBoundW, halfBoundL);
|
|
float rawW = rawH * (horizRadius / MathF.Max(0.4f, halfBoundH));
|
|
minX = cSp.X - rawW * 0.5f;
|
|
maxX = cSp.X + rawW * 0.5f;
|
|
minY = cSp.Y - rawH * 0.5f;
|
|
maxY = cSp.Y + rawH * 0.5f;
|
|
}
|
|
else
|
|
{
|
|
minX -= 3f;
|
|
maxX += 3f;
|
|
minY -= 3f;
|
|
maxY += 3f;
|
|
}
|
|
|
|
float boxW = Math.Clamp(maxX - minX, 22f, 220f);
|
|
float boxH = Math.Clamp(maxY - minY, 22f, 220f);
|
|
Vector2 boxCenter = new((minX + maxX) * 0.5f, (minY + maxY) * 0.5f);
|
|
var rect = new Rect2(boxCenter.X - boxW * 0.5f, boxCenter.Y - boxH * 0.5f, boxW, boxH);
|
|
|
|
EmitTargetBox(rect, col, dist, hpRatio, isLockedOnLocal, viewSize);
|
|
}
|
|
|
|
private void EmitTargetBox(Rect2 rect, Color col, float dist, float hpRatio, bool isLockedOnLocal, Vector2 viewSize)
|
|
{
|
|
float x0 = rect.Position.X;
|
|
float y0 = rect.Position.Y;
|
|
float x1 = x0 + rect.Size.X;
|
|
float y1 = y0 + rect.Size.Y;
|
|
float arm = Math.Clamp(MathF.Min(rect.Size.X, rect.Size.Y) * 0.22f, 5f, 26f);
|
|
|
|
Color shadowCol = new(0.04f, 0.05f, 0.04f, 0.78f);
|
|
Color strokeCol = new(col.R, col.G, col.B, 0.95f);
|
|
|
|
// Dark shadow pass then crisp target brackets across all 4 quadrants
|
|
_hbCanvas.DrawTargetBracketCorner(x0 - 0.8f, y0 - 0.8f, arm + 1.5f, 3.6f, 0, shadowCol);
|
|
_hbCanvas.DrawTargetBracketCorner(x1 + 0.8f, y0 - 0.8f, arm + 1.5f, 3.6f, 1, shadowCol);
|
|
_hbCanvas.DrawTargetBracketCorner(x1 + 0.8f, y1 + 0.8f, arm + 1.5f, 3.6f, 2, shadowCol);
|
|
_hbCanvas.DrawTargetBracketCorner(x0 - 0.8f, y1 + 0.8f, arm + 1.5f, 3.6f, 3, shadowCol);
|
|
|
|
_hbCanvas.DrawTargetBracketCorner(x0, y0, arm, 2.0f, 0, strokeCol);
|
|
_hbCanvas.DrawTargetBracketCorner(x1, y0, arm, 2.0f, 1, strokeCol);
|
|
_hbCanvas.DrawTargetBracketCorner(x1, y1, arm, 2.0f, 2, strokeCol);
|
|
_hbCanvas.DrawTargetBracketCorner(x0, y1, arm, 2.0f, 3, strokeCol);
|
|
|
|
// Format distance + LOCK tag
|
|
SpanWriter sw = new(_scratch);
|
|
sw.AppendFloat(dist, "F0");
|
|
sw.Append("m");
|
|
if (isLockedOnLocal)
|
|
{
|
|
sw.Append(" LOCK");
|
|
}
|
|
ReadOnlySpan<char> label = sw.Span;
|
|
float textW = _hbCanvas.MeasureTextWidth(label, 10.5f, wght: 600f);
|
|
|
|
float barW = Math.Clamp(rect.Size.X, 22f, 64f);
|
|
float centerX = (x0 + x1) * 0.5f;
|
|
float barX = Math.Clamp(centerX - barW * 0.5f, 6f, MathF.Max(6f, viewSize.X - barW - 6f));
|
|
float tx = Math.Clamp(centerX - textW * 0.5f, 6f, MathF.Max(6f, viewSize.X - textW - 6f));
|
|
|
|
// Prefer above-box; flip below-box if obstructed by static HUD panels (e.g. TopLeft/TopRight) or top edge
|
|
float aboveBarY = y0 - 7f;
|
|
float aboveTextY = aboveBarY - 3f;
|
|
Rect2 aboveBounds = MakeTagBounds(barX, aboveBarY, barW, tx, aboveTextY, textW, above: true);
|
|
|
|
float belowBarY = y1 + 5f;
|
|
float belowTextY = belowBarY + 14f;
|
|
Rect2 belowBounds = MakeTagBounds(barX, belowBarY, barW, tx, belowTextY, textW, above: false);
|
|
|
|
float chosenBarY;
|
|
float chosenTextY;
|
|
if (!IntersectsStaticHudPanel(aboveBounds) && aboveBounds.Position.Y >= 2f)
|
|
{
|
|
chosenBarY = aboveBarY;
|
|
chosenTextY = aboveTextY;
|
|
}
|
|
else if (!IntersectsStaticHudPanel(belowBounds) && belowBounds.End.Y <= viewSize.Y - 2f)
|
|
{
|
|
chosenBarY = belowBarY;
|
|
chosenTextY = belowTextY;
|
|
}
|
|
else
|
|
{
|
|
// Both top and bottom overlap static HUD panels: nudge horizontally out of top corner panels if possible, else omit unobstructed tag
|
|
float nudgedTx = tx;
|
|
float nudgedBarX = barX;
|
|
if (aboveBounds.Intersects(_topLeftRect))
|
|
{
|
|
float shift = _topLeftRect.End.X + 8f - MathF.Min(tx, barX);
|
|
if (shift > 0f && MathF.Max(tx + textW, barX + barW) + shift < _topRightRect.Position.X - 8f)
|
|
{
|
|
nudgedTx += shift;
|
|
nudgedBarX += shift;
|
|
}
|
|
}
|
|
else if (aboveBounds.Intersects(_topRightRect))
|
|
{
|
|
float shift = MathF.Max(tx + textW, barX + barW) - (_topRightRect.Position.X - 8f);
|
|
if (shift > 0f && MathF.Min(tx, barX) - shift > _topLeftRect.End.X + 8f)
|
|
{
|
|
nudgedTx -= shift;
|
|
nudgedBarX -= shift;
|
|
}
|
|
}
|
|
|
|
Rect2 nudgedBounds = MakeTagBounds(nudgedBarX, aboveBarY, barW, nudgedTx, aboveTextY, textW, above: true);
|
|
if (!IntersectsStaticHudPanel(nudgedBounds) && nudgedBounds.Position.Y >= 2f)
|
|
{
|
|
barX = nudgedBarX;
|
|
tx = nudgedTx;
|
|
chosenBarY = aboveBarY;
|
|
chosenTextY = aboveTextY;
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
_hbCanvas.DrawRectFilled(barX - 1f, chosenBarY - 1f, barW + 2f, 4f, shadowCol);
|
|
_hbCanvas.DrawRectFilled(barX, chosenBarY, barW * Math.Clamp(hpRatio, 0f, 1f), 2f, strokeCol);
|
|
|
|
_hbCanvas.DrawText(label, tx + 1f, chosenTextY + 1f, 10.5f, ShadowCol, wght: 600f);
|
|
_hbCanvas.DrawText(label, tx, chosenTextY, 10.5f, strokeCol, wght: 600f);
|
|
}
|
|
|
|
private static Rect2 MakeTagBounds(float barX, float barY, float barW, float tx, float ty, float textW, bool above)
|
|
{
|
|
float left = MathF.Min(barX - 1f, tx - 1f);
|
|
float right = MathF.Max(barX + barW + 1f, tx + textW + 1f);
|
|
if (above)
|
|
{
|
|
float top = ty - 11f;
|
|
float bottom = barY + 3f;
|
|
return new Rect2(left, top, right - left, bottom - top);
|
|
}
|
|
else
|
|
{
|
|
float top = barY - 1f;
|
|
float bottom = ty + 3f;
|
|
return new Rect2(left, top, right - left, bottom - top);
|
|
}
|
|
}
|
|
|
|
private bool IntersectsStaticHudPanel(Rect2 rect)
|
|
{
|
|
return rect.Intersects(_topLeftRect)
|
|
|| rect.Intersects(_topRightRect)
|
|
|| rect.Intersects(_bottomLeftRect)
|
|
|| rect.Intersects(_chyronRect);
|
|
}
|
|
|
|
private void EmitOffscreenArrow(OffscreenMarker m, Vector2 viewSize, Vector2 center, float halfW, float halfH)
|
|
{
|
|
Vector2 dir = ComputeOffscreenDirection(m.CamLocal);
|
|
Vector2 edge = ComputeSafeEdgePos(center, halfW, halfH, dir);
|
|
float angle = MathF.Atan2(dir.Y, dir.X);
|
|
|
|
_hbCanvas.DrawDirectionalArrow(edge.X, edge.Y, 18f, angle, new Color(0.04f, 0.05f, 0.04f, 0.74f));
|
|
Color arrowCol = new(m.Color.R, m.Color.G, m.Color.B, 0.94f);
|
|
_hbCanvas.DrawDirectionalArrow(edge.X, edge.Y, 14.5f, angle, arrowCol);
|
|
|
|
SpanWriter sw = new(_scratch);
|
|
sw.AppendFloat(m.Distance, "F0");
|
|
sw.Append("m");
|
|
if (m.IsLockedOnLocal)
|
|
{
|
|
sw.Append(" !");
|
|
}
|
|
ReadOnlySpan<char> label = sw.Span;
|
|
Vector2 textPos = ComputeInwardLabelPos(edge, dir, viewSize, label);
|
|
_hbCanvas.DrawText(label, textPos.X + 1f, textPos.Y + 1f, 10.5f, ShadowCol, wght: 600f);
|
|
_hbCanvas.DrawText(label, textPos.X, textPos.Y, 10.5f, arrowCol, wght: 600f);
|
|
}
|
|
|
|
private static Vector2 ComputeOffscreenDirection(System.Numerics.Vector3 camLocal)
|
|
{
|
|
if (!float.IsFinite(camLocal.X) || !float.IsFinite(camLocal.Y) || !float.IsFinite(camLocal.Z))
|
|
{
|
|
return Vector2.Down;
|
|
}
|
|
|
|
Vector2 dir;
|
|
if (camLocal.Z >= 0f)
|
|
{
|
|
dir = new Vector2(camLocal.X, -camLocal.Y);
|
|
}
|
|
else
|
|
{
|
|
float horiz = MathF.Sqrt(camLocal.X * camLocal.X + camLocal.Z * camLocal.Z);
|
|
float t = Math.Clamp(-camLocal.Z / MathF.Max(1e-4f, horiz * 0.35f), 0f, 1f);
|
|
Vector2 sideDir = new(camLocal.X, -camLocal.Y);
|
|
Vector2 behindArcDir = new(camLocal.X, MathF.Max(-camLocal.Z, 0.35f * horiz));
|
|
dir = sideDir.Lerp(behindArcDir, t);
|
|
if (MathF.Abs(camLocal.X) < 0.35f * horiz)
|
|
{
|
|
float minDown = 0.25f * dir.Length();
|
|
if (dir.Y < minDown)
|
|
{
|
|
dir.Y = MathF.Max(minDown, 0.25f);
|
|
}
|
|
}
|
|
}
|
|
|
|
float lenSq = dir.LengthSquared();
|
|
if (!float.IsFinite(lenSq) || lenSq < 1e-6f)
|
|
{
|
|
return camLocal.Z < 0f ? Vector2.Down : Vector2.Up;
|
|
}
|
|
return dir / MathF.Sqrt(lenSq);
|
|
}
|
|
|
|
private Vector2 ComputeSafeEdgePos(Vector2 center, float halfW, float halfH, Vector2 dir)
|
|
{
|
|
float tx = MathF.Abs(dir.X) > 1e-4f ? halfW / MathF.Abs(dir.X) : float.PositiveInfinity;
|
|
float ty = MathF.Abs(dir.Y) > 1e-4f ? halfH / MathF.Abs(dir.Y) : float.PositiveInfinity;
|
|
float tBest = MathF.Min(tx, ty);
|
|
|
|
Span<Rect2> avoid = stackalloc Rect2[4]
|
|
{
|
|
_topLeftRect,
|
|
_topRightRect,
|
|
_bottomLeftRect,
|
|
_chyronRect
|
|
};
|
|
for (int i = 0; i < avoid.Length; i++)
|
|
{
|
|
Rect2 r = avoid[i].Grow(PanelAvoidPad);
|
|
if (r.HasPoint(center)) continue;
|
|
if (TryRayEnterRect(center, dir, r, out float tEnter) && tEnter > 24f && tEnter < tBest)
|
|
{
|
|
tBest = tEnter;
|
|
}
|
|
}
|
|
|
|
tBest = MathF.Max(24f, tBest);
|
|
return center + dir * tBest;
|
|
}
|
|
|
|
private static bool TryRayEnterRect(Vector2 origin, Vector2 dir, Rect2 r, out float tEnter)
|
|
{
|
|
float tMin = 0f;
|
|
float tMax = float.PositiveInfinity;
|
|
|
|
if (MathF.Abs(dir.X) < 1e-5f)
|
|
{
|
|
if (origin.X < r.Position.X || origin.X > r.End.X)
|
|
{
|
|
tEnter = 0f;
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
float invX = 1f / dir.X;
|
|
float t1 = (r.Position.X - origin.X) * invX;
|
|
float t2 = (r.End.X - origin.X) * invX;
|
|
if (t1 > t2) (t1, t2) = (t2, t1);
|
|
tMin = MathF.Max(tMin, t1);
|
|
tMax = MathF.Min(tMax, t2);
|
|
if (tMin > tMax)
|
|
{
|
|
tEnter = 0f;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (MathF.Abs(dir.Y) < 1e-5f)
|
|
{
|
|
if (origin.Y < r.Position.Y || origin.Y > r.End.Y)
|
|
{
|
|
tEnter = 0f;
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
float invY = 1f / dir.Y;
|
|
float t1 = (r.Position.Y - origin.Y) * invY;
|
|
float t2 = (r.End.Y - origin.Y) * invY;
|
|
if (t1 > t2) (t1, t2) = (t2, t1);
|
|
tMin = MathF.Max(tMin, t1);
|
|
tMax = MathF.Min(tMax, t2);
|
|
if (tMin > tMax)
|
|
{
|
|
tEnter = 0f;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
tEnter = tMin;
|
|
return true;
|
|
}
|
|
|
|
private Vector2 ComputeInwardLabelPos(Vector2 edge, Vector2 dir, Vector2 viewSize, ReadOnlySpan<char> label)
|
|
{
|
|
float w = _hbCanvas.MeasureTextWidth(label, 10.5f, wght: 600f);
|
|
const float h = 11f;
|
|
Vector2 inward = edge - dir * 14f;
|
|
float textX;
|
|
float textY;
|
|
|
|
if (MathF.Abs(dir.X) >= MathF.Abs(dir.Y))
|
|
{
|
|
textX = dir.X > 0f ? (inward.X - w - 4f) : (inward.X + 6f);
|
|
textY = inward.Y + h * 0.3f;
|
|
}
|
|
else
|
|
{
|
|
textX = inward.X - w * 0.5f;
|
|
textY = dir.Y > 0f ? (inward.Y - 4f) : (inward.Y + h + 4f);
|
|
}
|
|
|
|
return new Vector2(
|
|
Math.Clamp(textX, 10f, MathF.Max(10f, viewSize.X - w - 10f)),
|
|
Math.Clamp(textY, 16f, MathF.Max(16f, viewSize.Y - 10f)));
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Cached Text Helpers (Rebuild ONLY on state delta -> 0 B/frame steady state)
|
|
// -------------------------------------------------------------------------
|
|
private void UpdatePromptCache(MatchState state, ContenderState player, OrbitalPod? localPod)
|
|
{
|
|
if (player.IsInDropPod)
|
|
{
|
|
int aglR = localPod is not null
|
|
? Mathf.RoundToInt(MathF.Max(0f, localPod.LastAgl))
|
|
: Mathf.RoundToInt(MathF.Max(0f, player.Y - state.Terrain.SampleHeight(player.X, player.Z)));
|
|
int velR = localPod is not null
|
|
? Mathf.RoundToInt(MathF.Max(0f, -localPod.VelY))
|
|
: Mathf.RoundToInt(MathF.Max(0f, -player.VelY));
|
|
int horR = localPod is not null
|
|
? Mathf.RoundToInt(MathF.Sqrt(localPod.VelX * localPod.VelX + localPod.VelZ * localPod.VelZ))
|
|
: Mathf.RoundToInt(player.Speed);
|
|
bool burn = localPod?.Phase == OrbitalPodPhase.RetroBurn;
|
|
|
|
if (_lastPromptPod && aglR == _lastPodAglRounded && horR == _lastPodHorizRounded && velR == _lastPodVertRounded && burn == _lastPodBurn)
|
|
{
|
|
return;
|
|
}
|
|
_lastPromptPod = true;
|
|
_lastPodAglRounded = aglR;
|
|
_lastPodHorizRounded = horR;
|
|
_lastPodVertRounded = velR;
|
|
_lastPodBurn = burn;
|
|
|
|
_cachedPromptText = $"ORBITAL INSERTION — ALT {aglR}m | HORIZ {horR} m/s | VERT {velR} m/s | [WASD] STEER"
|
|
+ (burn ? " [RETRO BURN]" : "");
|
|
WrapTextInto(_cachedPromptText, 344f, 12f, 550f, _promptLines);
|
|
return;
|
|
}
|
|
|
|
_lastPromptPod = false;
|
|
GroundDrop? nearest = state.FindNearestInteractableDrop(player.Id);
|
|
int promptKey = nearest is null
|
|
? -1
|
|
: HashCode.Combine(
|
|
nearest.Id,
|
|
nearest.Module?.Id ?? string.Empty,
|
|
nearest.Chassis?.Id ?? string.Empty,
|
|
nearest.Module is { } m ? (player.Grid.FindFirstEmptyCompatibleHardpoint(m)?.Id ?? string.Empty) : string.Empty);
|
|
|
|
if (promptKey == _lastPromptKey)
|
|
{
|
|
return;
|
|
}
|
|
_lastPromptKey = promptKey;
|
|
|
|
_cachedPromptText = BuildInteractionPrompt(player, nearest);
|
|
if (string.IsNullOrEmpty(_cachedPromptText))
|
|
{
|
|
_promptLines.Clear();
|
|
}
|
|
else
|
|
{
|
|
WrapTextInto(_cachedPromptText, 344f, 12f, 550f, _promptLines);
|
|
}
|
|
}
|
|
|
|
private static string BuildInteractionPrompt(ContenderState player, GroundDrop? nearest)
|
|
{
|
|
if (nearest is null) return string.Empty;
|
|
if (nearest.Module is { } mod)
|
|
{
|
|
var freeHp = player.Grid.FindFirstEmptyCompatibleHardpoint(mod);
|
|
if (mod.Procedural is { } proc)
|
|
{
|
|
string action = freeHp is not null
|
|
? $"[E] Bolt [{proc.ManufacturerLabel}] {mod.Name} -> {freeHp.Id}"
|
|
: $"[E] Loot [{proc.ManufacturerLabel}] {mod.Name}";
|
|
return $"{action}\n{proc.SummaryLine1} | {proc.SummaryLine2}";
|
|
}
|
|
return freeHp is not null
|
|
? $"[E] Bolt {(mod.IsImperial ? "IMPERIAL " : "")}{mod.Name} -> {freeHp.Id}"
|
|
: $"[E] Loot {(mod.IsImperial ? "IMPERIAL " : "")}{mod.Name}";
|
|
}
|
|
if (nearest.Chassis is { } ch)
|
|
{
|
|
return $"[E] Swap to {ch.Name} ({ch.Plane})";
|
|
}
|
|
return string.Empty;
|
|
}
|
|
|
|
private void UpdateHintCache(ContenderState player)
|
|
{
|
|
int mode = player.IsInDropPod ? 0 : (player.Grid.Spec.IsVtol ? 1 : 2);
|
|
if (mode == _lastHintMode && _hintLines.Count > 0)
|
|
{
|
|
return;
|
|
}
|
|
_lastHintMode = mode;
|
|
|
|
string hint = mode switch
|
|
{
|
|
0 => "WASD Steer Pod | Mouse Look | Retro-Burn Auto | Wheel Zoom",
|
|
1 => "WASD Fly | Space/C Alt | Mouse Aim | LMB Fire | E Bolt | Tab Garage | M Map | F9 Net",
|
|
_ => "WASD Drive | Mouse Aim | LMB Fire | E Bolt | Tab Garage | M Map | F9 Net | Wheel Zoom"
|
|
};
|
|
WrapTextInto(hint, 376f, 10.0f, 350f, _hintLines);
|
|
}
|
|
|
|
private ReadOnlySpan<char> TruncateWithEllipsis(string text, float maxWidthPx, float fontSizePx, float wght, char[] scratch)
|
|
{
|
|
if (string.IsNullOrEmpty(text) || _hbCanvas is null || _hbCanvas.MeasureTextWidth(text, fontSizePx, wght: wght) <= maxWidthPx)
|
|
{
|
|
return text;
|
|
}
|
|
|
|
const string ellipsis = "...";
|
|
int maxCopy = Math.Min(text.Length, scratch.Length - ellipsis.Length);
|
|
int bestLen = 0;
|
|
for (int len = 1; len <= maxCopy; len++)
|
|
{
|
|
scratch[len - 1] = text[len - 1];
|
|
scratch[len] = '.';
|
|
scratch[len + 1] = '.';
|
|
scratch[len + 2] = '.';
|
|
if (_hbCanvas.MeasureTextWidth(scratch.AsSpan(0, len + 3), fontSizePx, wght: wght) > maxWidthPx)
|
|
{
|
|
break;
|
|
}
|
|
bestLen = len;
|
|
}
|
|
for (int i = 0; i < bestLen; i++)
|
|
{
|
|
scratch[i] = text[i];
|
|
}
|
|
scratch[bestLen] = '.';
|
|
scratch[bestLen + 1] = '.';
|
|
scratch[bestLen + 2] = '.';
|
|
return scratch.AsSpan(0, bestLen + 3);
|
|
}
|
|
|
|
private void SyncBroadcastChyron(BroadcastFeed broadcast)
|
|
{
|
|
var lines = broadcast.Lines;
|
|
if (ReferenceEquals(_lastBroadcastFeed, broadcast) && broadcast.Version == _lastChyronVersion)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_lastBroadcastFeed = broadcast;
|
|
_lastChyronVersion = broadcast.Version;
|
|
|
|
// Evict by whole message from newest backwards so partial tail fragments of evicted messages never appear
|
|
int capacity = _chyronDisplayLines.Length;
|
|
int remaining = capacity;
|
|
int writeBack = capacity;
|
|
for (int m = lines.Count - 1; m >= 0 && remaining > 0; m--)
|
|
{
|
|
var line = lines[m];
|
|
bool isLatestMsg = m == lines.Count - 1;
|
|
string formatted = $"[{line.Timestamp:00.0}s] {line.Text}";
|
|
WrapTextInto(formatted, 548f, isLatestMsg ? 11.5f : 10.8f, isLatestMsg ? 500f : 380f, _chyronWrapScratch);
|
|
|
|
int msgLineCount = _chyronWrapScratch.Count;
|
|
if (msgLineCount == 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (isLatestMsg && msgLineCount > remaining)
|
|
{
|
|
int skip = msgLineCount - remaining;
|
|
for (int w = msgLineCount - 1; w >= skip; w--)
|
|
{
|
|
writeBack--;
|
|
_chyronDisplayLines[writeBack] = _chyronWrapScratch[w];
|
|
_chyronIsLatest[writeBack] = true;
|
|
}
|
|
remaining = 0;
|
|
break;
|
|
}
|
|
|
|
if (msgLineCount > remaining)
|
|
{
|
|
// Whole-message eviction: stop before emitting a partial tail of an older message
|
|
break;
|
|
}
|
|
|
|
for (int w = msgLineCount - 1; w >= 0; w--)
|
|
{
|
|
writeBack--;
|
|
_chyronDisplayLines[writeBack] = _chyronWrapScratch[w];
|
|
_chyronIsLatest[writeBack] = isLatestMsg;
|
|
}
|
|
remaining -= msgLineCount;
|
|
}
|
|
|
|
int total = capacity - writeBack;
|
|
if (writeBack > 0 && total > 0)
|
|
{
|
|
for (int i = 0; i < total; i++)
|
|
{
|
|
_chyronDisplayLines[i] = _chyronDisplayLines[writeBack + i];
|
|
_chyronIsLatest[i] = _chyronIsLatest[writeBack + i];
|
|
}
|
|
}
|
|
_chyronLineCount = total;
|
|
}
|
|
|
|
private void OnHardpointClicked(string hardpointId)
|
|
{
|
|
var session = _getSession();
|
|
if (session is null) return;
|
|
var cargo = session.LocalContender.Grid.Cargo;
|
|
if (_selectedCargoIndex >= 0 && _selectedCargoIndex < cargo.Count)
|
|
{
|
|
_onEquipCargo(_selectedCargoIndex, hardpointId);
|
|
_selectedCargoIndex = -1;
|
|
_lastGarageHash = int.MinValue;
|
|
_dirtyEmit = true;
|
|
}
|
|
}
|
|
|
|
private void AutoFitCargo(ChassisGrid grid, int cargoIndex)
|
|
{
|
|
if (cargoIndex < 0 || cargoIndex >= grid.Cargo.Count) return;
|
|
var mod = grid.Cargo[cargoIndex];
|
|
for (int i = 0; i < grid.Spec.Hardpoints.Length; i++)
|
|
{
|
|
var hp = grid.Spec.Hardpoints[i];
|
|
if (ChassisGrid.CanFit(hp, mod))
|
|
{
|
|
_onEquipCargo(cargoIndex, hp.Id);
|
|
_selectedCargoIndex = -1;
|
|
_lastGarageHash = int.MinValue;
|
|
_dirtyEmit = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnSchematicHoverChanged(Vector2I? cell, HardpointSpec? hp)
|
|
{
|
|
_lastHoveredCell = cell;
|
|
var grid = _schematic.Grid;
|
|
if (cell is null || grid is null)
|
|
{
|
|
if (!UpdateCargoSelectionTooltip(grid))
|
|
{
|
|
SetHoverText("HOVER CELL FOR TELEMETRY", TextMuted);
|
|
}
|
|
return;
|
|
}
|
|
|
|
var c = cell.Value;
|
|
float arm = grid.Armor[c.X, c.Y];
|
|
float maxArm = grid.MaxArmor[c.X, c.Y];
|
|
float temp = grid.Temperature[c.X, c.Y];
|
|
if (hp is not null)
|
|
{
|
|
var mounted = grid.GetMountedOn(hp.Id);
|
|
bool strippedHp = !grid.IsHardpointOperational(hp);
|
|
string hpStatus = strippedHp ? " [STRIPPED]" : "";
|
|
if (mounted is not null && mounted.Spec.Procedural is { } proc)
|
|
{
|
|
SetHoverText(
|
|
$"[{proc.ManufacturerLabel}] {proc.SummaryLine1}{hpStatus}\n{proc.SummaryLine2}",
|
|
(arm <= 0.01f || strippedHp) ? RedCol : ResolveManufacturerHudColor(proc.Manufacturer));
|
|
}
|
|
else
|
|
{
|
|
string txt = mounted is not null
|
|
? $"{hp.Kind.ToString().ToUpperInvariant()}: {mounted.Spec.Name} {mounted.CurrentTemp:F0}°C ({mounted.CurrentPerformance * 100f:F0}%){hpStatus}"
|
|
: $"{hp.Kind.ToString().ToUpperInvariant()} SLOT [{hp.Width}x{hp.Height}] EMPTY{hpStatus}";
|
|
SetHoverText(txt, (arm <= 0.01f || strippedHp) ? RedCol : TextLight);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string txt = arm <= 0.01f
|
|
? $"CELL ({c.X},{c.Y}) STRIPPED! {temp:F0}°C"
|
|
: $"HULL ({c.X},{c.Y}) ARM {arm:F0}/{maxArm:F0} {temp:F0}°C";
|
|
SetHoverText(txt, arm <= 0.01f ? RedCol : TextMuted);
|
|
}
|
|
}
|
|
|
|
private bool UpdateCargoSelectionTooltip(ChassisGrid? grid)
|
|
{
|
|
if (grid is null || _selectedCargoIndex < 0 || _selectedCargoIndex >= grid.Cargo.Count)
|
|
{
|
|
return false;
|
|
}
|
|
var mod = grid.Cargo[_selectedCargoIndex];
|
|
if (mod.Procedural is { } proc)
|
|
{
|
|
SetHoverText($"[{proc.ManufacturerLabel}] {proc.SummaryLine1}\n{proc.SummaryLine2}", ResolveManufacturerHudColor(proc.Manufacturer));
|
|
}
|
|
else
|
|
{
|
|
SetHoverText($"CARGO: {mod.Name} [{mod.Width}x{mod.Height}]", mod.IsImperial ? GoldCol : TextLight);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void SetHoverText(string text, Color color)
|
|
{
|
|
if (string.Equals(_cachedHoverText, text, StringComparison.Ordinal) && _cachedHoverColor == color)
|
|
{
|
|
return;
|
|
}
|
|
_cachedHoverText = text;
|
|
_cachedHoverColor = color;
|
|
float maxW = _garageExpanded ? 198f : 180f;
|
|
WrapTextInto(text, maxW, 10f, 400f, _hoverLines);
|
|
_dirtyEmit = true;
|
|
}
|
|
|
|
private void UpdateGarageDetailsCache(ChassisGrid grid)
|
|
{
|
|
var hc = new HashCode();
|
|
hc.Add(grid.Spec.Id);
|
|
hc.Add(grid.Mounted.Count);
|
|
hc.Add(_selectedCargoIndex);
|
|
if (_selectedCargoIndex >= 0 && _selectedCargoIndex < grid.Cargo.Count)
|
|
{
|
|
hc.Add(grid.Cargo[_selectedCargoIndex].Id);
|
|
}
|
|
for (int i = 0; i < grid.Mounted.Count; i++)
|
|
{
|
|
var m = grid.Mounted[i];
|
|
hc.Add(m.HardpointId);
|
|
hc.Add(m.Spec.Id);
|
|
hc.Add(Mathf.RoundToInt(m.CurrentTemp));
|
|
hc.Add(grid.IsHardpointOperational(m.HardpointId));
|
|
}
|
|
int sig = hc.ToHashCode();
|
|
if (sig == _lastGarageHash)
|
|
{
|
|
return;
|
|
}
|
|
_lastGarageHash = sig;
|
|
|
|
_garageLines.Clear();
|
|
var rawLines = new List<string>(16)
|
|
{
|
|
$"COND {grid.Spec.HullConductivity:F1} | THRUST {grid.ComputeDriveThrust():F0} N",
|
|
"MOUNTED:"
|
|
};
|
|
_garageLines.Add(rawLines[0]);
|
|
_garageLines.Add(rawLines[1]);
|
|
for (int i = 0; i < grid.Mounted.Count; i++)
|
|
{
|
|
var m = grid.Mounted[i];
|
|
string stateTag = grid.IsHardpointOperational(m.HardpointId) ? "" : " [STRIPPED]";
|
|
if (m.Spec.Procedural is { } proc)
|
|
{
|
|
string l0 = $"• [{proc.ManufacturerLabel}] {m.Spec.Name} {m.CurrentTemp:F0}°C{stateTag}";
|
|
rawLines.Add(l0);
|
|
rawLines.Add($" {proc.SummaryLine1}");
|
|
rawLines.Add($" {proc.SummaryLine2}");
|
|
WrapTextInto(l0, 184f, 10f, 400f, _garageLines, clearDest: false);
|
|
WrapTextInto($" {proc.SummaryLine1}", 184f, 10f, 400f, _garageLines, clearDest: false);
|
|
WrapTextInto($" {proc.SummaryLine2}", 184f, 10f, 400f, _garageLines, clearDest: false);
|
|
}
|
|
else
|
|
{
|
|
string l0 = $"• {m.HardpointId}: {m.Spec.Name} {m.CurrentTemp:F0}°C ({m.CurrentPerformance * 100f:F0}%){stateTag}";
|
|
rawLines.Add(l0);
|
|
WrapTextInto(l0, 184f, 10f, 400f, _garageLines, clearDest: false);
|
|
}
|
|
}
|
|
if (_selectedCargoIndex >= 0 && _selectedCargoIndex < grid.Cargo.Count &&
|
|
grid.Cargo[_selectedCargoIndex].Procedural is { } cargoProc)
|
|
{
|
|
string l0 = $"SEL [{cargoProc.ManufacturerLabel}]:";
|
|
rawLines.Add(l0);
|
|
rawLines.Add($" {cargoProc.SummaryLine1}");
|
|
rawLines.Add($" {cargoProc.SummaryLine2}");
|
|
_garageLines.Add(l0);
|
|
WrapTextInto($" {cargoProc.SummaryLine1}", 184f, 10f, 400f, _garageLines, clearDest: false);
|
|
WrapTextInto($" {cargoProc.SummaryLine2}", 184f, 10f, 400f, _garageLines, clearDest: false);
|
|
}
|
|
_cachedGarageDetails = string.Join("\n", rawLines);
|
|
}
|
|
|
|
private void WrapTextInto(string text, float maxWidthPx, float fontSizePx, float wght, List<string> dest, bool clearDest = true)
|
|
{
|
|
if (clearDest)
|
|
{
|
|
dest.Clear();
|
|
}
|
|
if (string.IsNullOrEmpty(text))
|
|
{
|
|
return;
|
|
}
|
|
|
|
int lineStart = 0;
|
|
for (int idx = 0; idx <= text.Length; idx++)
|
|
{
|
|
if (idx == text.Length || text[idx] == '\n')
|
|
{
|
|
WrapParagraph(text.AsSpan(lineStart, idx - lineStart), maxWidthPx, fontSizePx, wght, dest);
|
|
lineStart = idx + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void WrapParagraph(ReadOnlySpan<char> para, float maxWidthPx, float fontSizePx, float wght, List<string> dest)
|
|
{
|
|
if (para.IsEmpty)
|
|
{
|
|
dest.Add(string.Empty);
|
|
return;
|
|
}
|
|
|
|
if (_hbCanvas is null || _hbCanvas.MeasureTextWidth(para, fontSizePx, wght: wght) <= maxWidthPx)
|
|
{
|
|
dest.Add(new string(para));
|
|
return;
|
|
}
|
|
|
|
int pos = 0;
|
|
while (pos < para.Length)
|
|
{
|
|
int bestEnd = pos + 1;
|
|
int lastSpace = -1;
|
|
for (int end = pos + 1; end <= para.Length; end++)
|
|
{
|
|
if (end < para.Length && para[end] == ' ')
|
|
{
|
|
lastSpace = end;
|
|
}
|
|
float w = _hbCanvas.MeasureTextWidth(para.Slice(pos, end - pos), fontSizePx, wght: wght);
|
|
if (w > maxWidthPx)
|
|
{
|
|
break;
|
|
}
|
|
bestEnd = end;
|
|
}
|
|
|
|
int cut = (bestEnd < para.Length && lastSpace > pos) ? lastSpace : bestEnd;
|
|
dest.Add(new string(para.Slice(pos, cut - pos)));
|
|
pos = cut;
|
|
while (pos < para.Length && para[pos] == ' ')
|
|
{
|
|
pos++;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static Color ResolveManufacturerHudColor(ManufacturerId mfg) => mfg switch
|
|
{
|
|
ManufacturerId.ScrapFrontier => Color.FromHtml("#ffaa33"),
|
|
ManufacturerId.KorrathiIronworks => Color.FromHtml("#f2c422"),
|
|
ManufacturerId.AuralianOptics => Color.FromHtml("#38e8ff"),
|
|
ManufacturerId.VexNineCollective => Color.FromHtml("#7cf230"),
|
|
ManufacturerId.ThalassanForge => Color.FromHtml("#2cb8ff"),
|
|
_ => GoldCol
|
|
};
|
|
|
|
// -------------------------------------------------------------------------
|
|
// [F9] Interactive Multiplayer Link Panel (Godot Controls kept until Cut 14c)
|
|
// -------------------------------------------------------------------------
|
|
private void BuildNetworkPanel()
|
|
{
|
|
var panelStyle = new StyleBoxFlat
|
|
{
|
|
BgColor = new Color(0f, 0f, 0f, 0f),
|
|
BorderColor = new Color(0f, 0f, 0f, 0f),
|
|
ContentMarginLeft = 10,
|
|
ContentMarginRight = 10,
|
|
ContentMarginTop = 8,
|
|
ContentMarginBottom = 8
|
|
};
|
|
panelStyle.SetBorderWidthAll(0);
|
|
|
|
_netPanel = new PanelContainer
|
|
{
|
|
Name = "NetworkLinkPanel",
|
|
Visible = false
|
|
};
|
|
_netPanel.AddThemeStyleboxOverride("panel", panelStyle);
|
|
_netPanel.AnchorLeft = 0.5f;
|
|
_netPanel.AnchorRight = 0.5f;
|
|
_netPanel.AnchorTop = 0.32f;
|
|
_netPanel.AnchorBottom = 0.32f;
|
|
_netPanel.OffsetLeft = -188f;
|
|
_netPanel.OffsetRight = 188f;
|
|
_netPanel.OffsetTop = 0f;
|
|
_netPanel.OffsetBottom = 0f;
|
|
AddChild(_netPanel);
|
|
|
|
var vbox = new VBoxContainer();
|
|
vbox.AddThemeConstantOverride("separation", 6);
|
|
_netPanel.AddChild(vbox);
|
|
|
|
var headRow = new HBoxContainer();
|
|
headRow.AddThemeConstantOverride("separation", 8);
|
|
vbox.AddChild(headRow);
|
|
|
|
var title = new Label
|
|
{
|
|
Text = "MULTIPLAYER LINK [F9]",
|
|
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
|
|
};
|
|
title.AddThemeColorOverride("font_color", CyanCol);
|
|
title.AddThemeFontSizeOverride("font_size", 13);
|
|
headRow.AddChild(title);
|
|
|
|
_netModeBadge = new Label { Text = "SOLO" };
|
|
_netModeBadge.AddThemeColorOverride("font_color", OliveCol);
|
|
_netModeBadge.AddThemeFontSizeOverride("font_size", 12);
|
|
headRow.AddChild(_netModeBadge);
|
|
|
|
_netPanelStatus = new Label
|
|
{
|
|
Text = "LOCAL SOLO SESSION",
|
|
AutowrapMode = TextServer.AutowrapMode.Word
|
|
};
|
|
_netPanelStatus.AddThemeColorOverride("font_color", TextMuted);
|
|
_netPanelStatus.AddThemeFontSizeOverride("font_size", 11);
|
|
vbox.AddChild(_netPanelStatus);
|
|
|
|
var nameRow = new HBoxContainer();
|
|
nameRow.AddThemeConstantOverride("separation", 6);
|
|
vbox.AddChild(nameRow);
|
|
|
|
var nameLbl = new Label { Text = "CALLSIGN", CustomMinimumSize = new Vector2(74f, 0f) };
|
|
nameLbl.AddThemeColorOverride("font_color", TextMuted);
|
|
nameLbl.AddThemeFontSizeOverride("font_size", 11);
|
|
nameRow.AddChild(nameLbl);
|
|
|
|
_callsignEdit = new LineEdit
|
|
{
|
|
Text = "Pilot",
|
|
MaxLength = 24,
|
|
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
|
|
PlaceholderText = "Callsign"
|
|
};
|
|
_callsignEdit.AddThemeFontSizeOverride("font_size", 12);
|
|
nameRow.AddChild(_callsignEdit);
|
|
|
|
var epRow = new HBoxContainer();
|
|
epRow.AddThemeConstantOverride("separation", 6);
|
|
vbox.AddChild(epRow);
|
|
|
|
var epLbl = new Label { Text = "HOST:PORT", CustomMinimumSize = new Vector2(74f, 0f) };
|
|
epLbl.AddThemeColorOverride("font_color", TextMuted);
|
|
epLbl.AddThemeFontSizeOverride("font_size", 11);
|
|
epRow.AddChild(epLbl);
|
|
|
|
_endpointEdit = new LineEdit
|
|
{
|
|
Text = "127.0.0.1:3076",
|
|
MaxLength = 96,
|
|
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
|
|
PlaceholderText = "127.0.0.1:3076"
|
|
};
|
|
_endpointEdit.AddThemeFontSizeOverride("font_size", 12);
|
|
epRow.AddChild(_endpointEdit);
|
|
|
|
var btnRow = new HBoxContainer();
|
|
btnRow.AddThemeConstantOverride("separation", 6);
|
|
vbox.AddChild(btnRow);
|
|
|
|
var hostBtn = new Button { Text = "Host", SizeFlagsHorizontal = Control.SizeFlags.ExpandFill, FocusMode = Control.FocusModeEnum.None };
|
|
hostBtn.AddThemeFontSizeOverride("font_size", 12);
|
|
hostBtn.Pressed += () =>
|
|
{
|
|
_uiNetError = null;
|
|
int port = ParsePort(_endpointEdit.Text, 3076);
|
|
HostRequested?.Invoke(port, _callsignEdit.Text);
|
|
};
|
|
btnRow.AddChild(hostBtn);
|
|
|
|
var joinBtn = new Button { Text = "Join", SizeFlagsHorizontal = Control.SizeFlags.ExpandFill, FocusMode = Control.FocusModeEnum.None };
|
|
joinBtn.AddThemeFontSizeOverride("font_size", 12);
|
|
joinBtn.Pressed += () =>
|
|
{
|
|
_uiNetError = null;
|
|
JoinRequested?.Invoke(_endpointEdit.Text, _callsignEdit.Text);
|
|
};
|
|
btnRow.AddChild(joinBtn);
|
|
|
|
var soloBtn = new Button { Text = "Solo", SizeFlagsHorizontal = Control.SizeFlags.ExpandFill, FocusMode = Control.FocusModeEnum.None };
|
|
soloBtn.AddThemeFontSizeOverride("font_size", 12);
|
|
soloBtn.Pressed += () =>
|
|
{
|
|
_uiNetError = null;
|
|
SoloRequested?.Invoke();
|
|
};
|
|
btnRow.AddChild(soloBtn);
|
|
|
|
var closeBtn = new Button { Text = "Close", FocusMode = Control.FocusModeEnum.None };
|
|
closeBtn.AddThemeFontSizeOverride("font_size", 12);
|
|
closeBtn.Pressed += () => SetNetworkPanelOpen(false);
|
|
btnRow.AddChild(closeBtn);
|
|
}
|
|
|
|
private void SyncNetworkPanel(NetworkStatusSnapshot net)
|
|
{
|
|
_netModeBadge.Text = net.Mode switch
|
|
{
|
|
NetworkMode.ListenHost => "HOST",
|
|
NetworkMode.RemoteClient => "CLIENT",
|
|
_ => "SOLO"
|
|
};
|
|
_netModeBadge.Modulate = net.Mode == NetworkMode.Solo ? OliveCol : CyanCol;
|
|
|
|
string? err = _uiNetError ?? net.LastError;
|
|
if (!string.IsNullOrWhiteSpace(err))
|
|
{
|
|
_netPanelStatus.Text = $"ERROR: {err}";
|
|
_netPanelStatus.AddThemeColorOverride("font_color", RedCol);
|
|
return;
|
|
}
|
|
|
|
if (net.Mode == NetworkMode.Solo)
|
|
{
|
|
_netPanelStatus.Text = "OFFLINE SOLO — ZERO NETWORK LATENCY";
|
|
_netPanelStatus.AddThemeColorOverride("font_color", TextMuted);
|
|
}
|
|
else if (net.Mode == NetworkMode.ListenHost)
|
|
{
|
|
_netPanelStatus.Text = $"{net.StateLabel} • {net.ConnectedHumans}/{net.MaxHumans} HUMANS";
|
|
_netPanelStatus.AddThemeColorOverride("font_color", CyanCol);
|
|
}
|
|
else if (net.Connected)
|
|
{
|
|
_netPanelStatus.Text = $"CONNECTED • PING {net.PingMs} ms • {net.ConnectedHumans}/{net.MaxHumans} HUMANS";
|
|
_netPanelStatus.AddThemeColorOverride("font_color", OliveCol);
|
|
}
|
|
else
|
|
{
|
|
_netPanelStatus.Text = $"STATE: {net.StateLabel}...";
|
|
_netPanelStatus.AddThemeColorOverride("font_color", OrangeCol);
|
|
}
|
|
}
|
|
|
|
private static int ParsePort(string text, int fallback)
|
|
{
|
|
string trimmed = (text ?? string.Empty).Trim();
|
|
int colon = trimmed.LastIndexOf(':');
|
|
if (colon >= 0 && colon + 1 < trimmed.Length &&
|
|
int.TryParse(trimmed[(colon + 1)..], NumberStyles.Integer, CultureInfo.InvariantCulture, out int p) &&
|
|
p is > 0 and <= 65535)
|
|
{
|
|
return p;
|
|
}
|
|
if (int.TryParse(trimmed, NumberStyles.Integer, CultureInfo.InvariantCulture, out int direct) &&
|
|
direct is > 0 and <= 65535)
|
|
{
|
|
return direct;
|
|
}
|
|
return fallback;
|
|
}
|
|
|
|
private ref struct SpanWriter
|
|
{
|
|
private readonly char[] _buf;
|
|
private int _pos;
|
|
|
|
public SpanWriter(char[] buf)
|
|
{
|
|
_buf = buf;
|
|
_pos = 0;
|
|
}
|
|
|
|
public readonly ReadOnlySpan<char> Span => _buf.AsSpan(0, _pos);
|
|
|
|
public void Append(ReadOnlySpan<char> s)
|
|
{
|
|
int copy = Math.Min(s.Length, _buf.Length - _pos);
|
|
if (copy > 0)
|
|
{
|
|
s[..copy].CopyTo(_buf.AsSpan(_pos));
|
|
_pos += copy;
|
|
}
|
|
}
|
|
|
|
public void AppendInt(int val)
|
|
{
|
|
if (val.TryFormat(_buf.AsSpan(_pos), out int written, default, CultureInfo.InvariantCulture))
|
|
{
|
|
_pos += written;
|
|
}
|
|
}
|
|
|
|
public void AppendFloat(float val, ReadOnlySpan<char> fmt)
|
|
{
|
|
if (val.TryFormat(_buf.AsSpan(_pos), out int written, fmt, CultureInfo.InvariantCulture))
|
|
{
|
|
_pos += written;
|
|
}
|
|
}
|
|
}
|
|
}
|