1782 lines
70 KiB
C#
1782 lines
70 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using Godot;
|
|
using RustToDust.Core;
|
|
|
|
namespace RustToDust.Client;
|
|
|
|
public enum HitMarkerKind
|
|
{
|
|
None = 0,
|
|
Armor = 1,
|
|
Core = 2,
|
|
Kill = 3
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rust to Dust industrial HUD:
|
|
/// - Top-Left: Chassis badge (DORSAL/CORONAL), Core HP, Speed, Contenders Alive, Safe Circle status, Pickup 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-Center: Imperial Broadcast Chyron (Weksa commentary).
|
|
/// </summary>
|
|
public partial class Hud : CanvasLayer
|
|
{
|
|
private static readonly Color BgDark = Color.FromHtml("#131613");
|
|
private static readonly Color BgInner = Color.FromHtml("#1b1f1b");
|
|
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 GoldCol = Color.FromHtml("#e6b838");
|
|
private static readonly Color RedCol = Color.FromHtml("#d93829");
|
|
|
|
private readonly Func<IClientArenaSession?> _getSession;
|
|
private readonly Action<int, string> _onEquipCargo;
|
|
private readonly Func<float> _getCameraYaw;
|
|
|
|
private Label _chassisHeader = null!;
|
|
private Label _planeBadge = null!;
|
|
private ProgressBar _coreHpBar = null!;
|
|
private Label _coreHpLabel = null!;
|
|
private Label _statsLabel = null!;
|
|
private Label _safeLabel = null!;
|
|
private Label _detectionLabel = null!;
|
|
private Label _waveLabel = null!;
|
|
private Label _netStatusLabel = null!;
|
|
private Label _promptLabel = null!;
|
|
private Label _controlsHint = null!;
|
|
|
|
private RadarWidget _radar = null!;
|
|
private Label _radarTitle = null!;
|
|
private Label _mapAttribLabel = null!;
|
|
private ColorRect _vignetteRect = null!;
|
|
private ShaderMaterial _vignetteMat = null!;
|
|
private CrosshairOverlay _crosshair = null!;
|
|
private float _damagePulse;
|
|
private float _lowCoreRatio;
|
|
private float _overheatPulse;
|
|
private float _vignetteTime;
|
|
private InventoryGridControl _schematic = null!;
|
|
private Label _hoverLabel = null!;
|
|
private VBoxContainer _cargoList = null!;
|
|
private Label _cargoHeader = null!;
|
|
private Label _garageDetails = null!;
|
|
private ChromePanel _topLeftPanel = null!;
|
|
private ChromePanel _topRightPanel = null!;
|
|
private ChromePanel _bottomLeftPanel = null!;
|
|
private ChromePanel _chyronPanel = null!;
|
|
|
|
private ChromePanel _netPanel = null!;
|
|
private Label _netModeBadge = null!;
|
|
private Label _netPanelStatus = null!;
|
|
private LineEdit _callsignEdit = null!;
|
|
private LineEdit _endpointEdit = null!;
|
|
private string? _uiNetError;
|
|
|
|
private VBoxContainer _chyronBox = null!;
|
|
private readonly Label[] _chyronLabels = new Label[3];
|
|
private BroadcastFeed? _lastBroadcastFeed;
|
|
private long _lastChyronVersion = -1;
|
|
private ChromePanel _outcomeBanner = null!;
|
|
private Label _outcomeLabel = null!;
|
|
|
|
private int _selectedCargoIndex = -1;
|
|
private int _lastCargoHash = -1;
|
|
private bool _garageExpanded;
|
|
|
|
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)
|
|
{
|
|
_getSession = getSession;
|
|
_onEquipCargo = onEquipCargo;
|
|
_getCameraYaw = getCameraYaw ?? (() => 0f);
|
|
Layer = 10;
|
|
}
|
|
|
|
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 => _crosshair.ActiveHitArcCount;
|
|
internal bool HasActiveHitMarker => _crosshair.HasActiveHitMarker;
|
|
internal HitMarkerKind ActiveHitMarkerKind => _crosshair.ActiveHitMarkerKind;
|
|
internal bool IsVignetteVisible => _vignetteRect is not null && _vignetteRect.Visible;
|
|
internal void PushTestHitArc(float sourceX, float sourceZ, WeaponVisualClass weaponClass) =>
|
|
_crosshair.PushTestHitArc(sourceX, sourceZ, weaponClass);
|
|
internal void ResetFeedback()
|
|
{
|
|
_damagePulse = 0f;
|
|
_lowCoreRatio = 0f;
|
|
_overheatPulse = 0f;
|
|
_vignetteTime = 0f;
|
|
if (_vignetteRect is not null)
|
|
{
|
|
_vignetteRect.Visible = false;
|
|
}
|
|
_crosshair?.ResetFeedback();
|
|
}
|
|
internal Rect2 BottomLeftPanelRect => _bottomLeftPanel.GetGlobalRect();
|
|
internal Rect2 ChyronPanelRect => _chyronPanel.GetGlobalRect();
|
|
|
|
public IEnumerable<ShaderMaterial> GetChromeMaterials()
|
|
{
|
|
yield return _topLeftPanel.ChromeMaterial;
|
|
yield return _topRightPanel.ChromeMaterial;
|
|
yield return _bottomLeftPanel.ChromeMaterial;
|
|
yield return _chyronPanel.ChromeMaterial;
|
|
yield return _outcomeBanner.ChromeMaterial;
|
|
yield return _netPanel.ChromeMaterial;
|
|
}
|
|
|
|
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;
|
|
_garageDetails.Visible = _garageExpanded;
|
|
_schematic.CustomMinimumSize = _garageExpanded ? new Vector2(198f, 208f) : new Vector2(180f, 188f);
|
|
_schematic.QueueRedraw();
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
float dt = (float)delta;
|
|
_crosshair?.Advance(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);
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
_crosshair?.PushTestHitArc(hit.SourceX, hit.SourceZ, (WeaponVisualClass)hit.WeaponClass);
|
|
float pulse = (WeaponVisualClass)hit.WeaponClass == WeaponVisualClass.Explosive ? 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)
|
|
{
|
|
_crosshair?.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);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
BuildCrosshair();
|
|
BuildTopLeft();
|
|
BuildTopRightRadar();
|
|
BuildBottomLeftSchematic();
|
|
BuildBottomCenterChyron();
|
|
BuildOutcomeBanner();
|
|
BuildNetworkPanel();
|
|
}
|
|
|
|
public bool IsPointerOverInteractiveHud(Vector2 screenPos)
|
|
{
|
|
return (_topLeftPanel.Visible && _topLeftPanel.GetGlobalRect().HasPoint(screenPos))
|
|
|| (_topRightPanel.Visible && _topRightPanel.GetGlobalRect().HasPoint(screenPos))
|
|
|| (_bottomLeftPanel.Visible && _bottomLeftPanel.GetGlobalRect().HasPoint(screenPos))
|
|
|| (_chyronPanel.Visible && _chyronPanel.GetGlobalRect().HasPoint(screenPos))
|
|
|| (_chyronBox.Visible && _chyronBox.GetGlobalRect().HasPoint(screenPos))
|
|
|| (_outcomeBanner.Visible && _outcomeBanner.GetGlobalRect().HasPoint(screenPos))
|
|
|| (_netPanel.Visible && _netPanel.GetGlobalRect().HasPoint(screenPos));
|
|
}
|
|
|
|
public bool HasPanelOverlapOrClip(Vector2 viewportSize)
|
|
{
|
|
var panels = new[] { _topLeftPanel, _topRightPanel, _bottomLeftPanel, _chyronPanel, _netPanel };
|
|
var bounds = new Rect2(Vector2.Zero, viewportSize + new Vector2(1f, 1f));
|
|
for (int i = 0; i < panels.Length; i++)
|
|
{
|
|
if (!panels[i].Visible) continue;
|
|
var ri = panels[i].GetGlobalRect();
|
|
if (!bounds.Encloses(ri))
|
|
{
|
|
return true;
|
|
}
|
|
for (int j = i + 1; j < panels.Length; j++)
|
|
{
|
|
if (!panels[j].Visible) continue;
|
|
if (ri.Intersects(panels[j].GetGlobalRect()))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void Sync(IClientArenaSession session)
|
|
{
|
|
var state = session.ViewState;
|
|
var player = session.LocalContender;
|
|
var net = session.ConnectionStatus;
|
|
|
|
// Top-Left Status
|
|
OrbitalPod? localPod = null;
|
|
if (player.IsInDropPod)
|
|
{
|
|
var pods = session.ActivePods;
|
|
for (int i = 0; i < pods.Count; i++)
|
|
{
|
|
if (pods[i].PodKind == OrbitalPodKind.Contender && pods[i].ContenderId == player.Id)
|
|
{
|
|
localPod = pods[i];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
int aliveCount = 0;
|
|
for (int i = 0; i < state.Contenders.Count; i++)
|
|
{
|
|
if (state.Contenders[i].Alive) aliveCount++;
|
|
}
|
|
|
|
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);
|
|
bool burning = localPod?.Phase == OrbitalPodPhase.RetroBurn;
|
|
_chassisHeader.Text = "ORBITAL DROP POD";
|
|
_planeBadge.Text = burning ? "RETRO BURN" : "FREEFALL";
|
|
_planeBadge.Modulate = burning ? OrangeCol : CyanCol;
|
|
_statsLabel.Text = $"ALT {agl:F0}m | VEL {velDown:F0} m/s | ALIVE {aliveCount} / {state.Contenders.Count}";
|
|
_controlsHint.Text = "WASD Steer Pod | Mouse Look | Retro-Burn Auto | Wheel Zoom";
|
|
}
|
|
else
|
|
{
|
|
_chassisHeader.Text = player.Grid.Spec.Name.ToUpperInvariant();
|
|
bool isCoronal = player.Grid.Spec.Plane == GridPlane.Coronal;
|
|
_planeBadge.Text = isCoronal ? "CORONAL" : "DORSAL";
|
|
_planeBadge.Modulate = isCoronal ? CyanCol : OliveCol;
|
|
|
|
if (player.Grid.Spec.IsVtol)
|
|
{
|
|
float agl = MathF.Max(0f, player.Y - player.Grid.Spec.HalfHeight - state.Terrain.SampleHeight(player.X, player.Z));
|
|
_statsLabel.Text = $"SPD {player.Speed:F1} m/s | ALT {agl:F1}m | ALIVE {aliveCount} / {state.Contenders.Count} | KILLS {player.Kills}";
|
|
_controlsHint.Text = "WASD Fly | Space/C Alt | Mouse Aim | LMB Fire | E Bolt | Tab Garage | M Map | F9 Net";
|
|
}
|
|
else
|
|
{
|
|
_statsLabel.Text = $"SPD {player.Speed:F1} m/s | ALIVE {aliveCount} / {state.Contenders.Count} | KILLS {player.Kills}";
|
|
_controlsHint.Text = "WASD Drive | Mouse Aim | LMB Fire | E Bolt | Tab Garage | M Map | F9 Net | Wheel Zoom";
|
|
}
|
|
}
|
|
|
|
_coreHpBar.MaxValue = Math.Max(1f, player.Grid.MaxCoreHp);
|
|
_coreHpBar.Value = Math.Max(0f, player.Grid.CoreHp);
|
|
_coreHpLabel.Text = $"CORE {player.Grid.CoreHp:F0} / {player.Grid.MaxCoreHp:F0}";
|
|
|
|
_radarTitle.Text = state.MapKind == ArenaMapKind.Sion
|
|
? "SION 3KM • RADAR"
|
|
: "DESERT RING • RADAR";
|
|
_mapAttribLabel.Text = state.MapKind == ArenaMapKind.Sion
|
|
? "Data: swisstopo | [M] Switch Map"
|
|
: "[M] Switch to Sion 3 km";
|
|
|
|
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);
|
|
|
|
if (outside <= 0f)
|
|
{
|
|
_safeLabel.Text = $"RING SAFE ({-outside:F0}m margin)" + (provoked > 0 ? $" • {provoked} PROVOKED!" : "");
|
|
_safeLabel.Modulate = provoked > 0 ? OrangeCol : OliveCol;
|
|
}
|
|
else
|
|
{
|
|
_safeLabel.Text = $"OUTSIDE +{outside:F0}m — {cleared} CLEARED" + (provoked > 0 ? $" / {provoked} PROVOKED!" : "!");
|
|
_safeLabel.Modulate = RedCol;
|
|
}
|
|
|
|
int detectedBy = session.LocalDetectedByCount;
|
|
if (detectedBy > 0)
|
|
{
|
|
_detectionLabel.Text = $"DETECTED BY {detectedBy}";
|
|
_detectionLabel.Modulate = RedCol;
|
|
}
|
|
else
|
|
{
|
|
_detectionLabel.Text = "CONCEALED (TERRAIN)";
|
|
_detectionLabel.Modulate = OliveCol;
|
|
}
|
|
|
|
var wave = session.DropWaveState;
|
|
if (wave.RespawnCutoffReached)
|
|
{
|
|
_waveLabel.Text = "FINAL RING — RESPAWNS CLOSED";
|
|
_waveLabel.Modulate = RedCol;
|
|
}
|
|
else if (wave.NextWaveAtSec is float nextWaveAt)
|
|
{
|
|
float eta = MathF.Max(0f, nextWaveAt - state.Time);
|
|
_waveLabel.Text = $"PATRON WAVE {wave.NextWaveIndex} IN {eta:F0}s • RESP {player.RespawnsRemaining}";
|
|
_waveLabel.Modulate = eta <= 10f ? GoldCol : CyanCol;
|
|
}
|
|
else
|
|
{
|
|
_waveLabel.Text = $"WAVE {wave.CurrentWaveIndex} ACTIVE • RESP {player.RespawnsRemaining}";
|
|
_waveLabel.Modulate = OliveCol;
|
|
}
|
|
|
|
if (net.Mode == NetworkMode.Solo)
|
|
{
|
|
_netStatusLabel.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
_netStatusLabel.Visible = true;
|
|
if (net.Mode == NetworkMode.ListenHost)
|
|
{
|
|
_netStatusLabel.Text = $"{net.StateLabel} • HUMANS {net.ConnectedHumans}/{net.MaxHumans} • [F9] NET";
|
|
_netStatusLabel.Modulate = CyanCol;
|
|
}
|
|
else if (net.Connected)
|
|
{
|
|
_netStatusLabel.Text = $"PING {net.PingMs} ms • HUMANS {net.ConnectedHumans}/{net.MaxHumans} • [F9] NET";
|
|
_netStatusLabel.Modulate = net.PingMs > 120 ? OrangeCol : CyanCol;
|
|
}
|
|
else
|
|
{
|
|
_netStatusLabel.Text = $"{net.StateLabel} • [F9] NET";
|
|
_netStatusLabel.Modulate = net.LastError is not null ? RedCol : OrangeCol;
|
|
}
|
|
}
|
|
|
|
if (_netPanel.Visible)
|
|
{
|
|
SyncNetworkPanel(net);
|
|
}
|
|
|
|
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);
|
|
_promptLabel.Text = $"ORBITAL INSERTION — ALT {agl:F0}m | VEL {velDown:F0}m/s | [WASD] STEER"
|
|
+ (localPod?.Phase == OrbitalPodPhase.RetroBurn ? " [RETRO BURN]" : "");
|
|
_promptLabel.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
_promptLabel.Text = BuildInteractionPrompt(state, player);
|
|
_promptLabel.Visible = !string.IsNullOrEmpty(_promptLabel.Text);
|
|
}
|
|
|
|
// Crosshair + Heat Arc / Orbital Altimeter + Directional Incoming Hit Arcs
|
|
_crosshair.SetState(state, player, _getCameraYaw(), localPod);
|
|
_crosshair.QueueRedraw();
|
|
|
|
// Radar (heading-up with camera yaw)
|
|
_radar.SetState(session, _getCameraYaw());
|
|
_radar.QueueRedraw();
|
|
|
|
// Schematic + Cargo
|
|
_schematic.SetGrid(player.Grid, _selectedCargoIndex);
|
|
SyncCargoButtons(player.Grid);
|
|
|
|
if (_garageExpanded)
|
|
{
|
|
_garageDetails.Text = BuildGarageDetails(player.Grid);
|
|
}
|
|
|
|
// Broadcast Chyron
|
|
SyncBroadcastChyron(state.Broadcast);
|
|
|
|
// Outcome / WaitingForRespawnWave Banner
|
|
var outcome = session.LocalOutcome;
|
|
if (outcome == ClientMatchOutcome.Victory)
|
|
{
|
|
_outcomeBanner.Visible = true;
|
|
_outcomeBanner.ChromeMaterial.SetShaderParameter("accent_color", OliveCol);
|
|
_outcomeLabel.Text = net.Mode == NetworkMode.RemoteClient
|
|
? "VICTORY — LAST RIG STANDING\nNext round starting soon..."
|
|
: "VICTORY — LAST RIG STANDING\n[R] New Drop";
|
|
_outcomeLabel.Modulate = OliveCol;
|
|
}
|
|
else if (outcome == ClientMatchOutcome.Defeat)
|
|
{
|
|
_outcomeBanner.Visible = true;
|
|
_outcomeBanner.ChromeMaterial.SetShaderParameter("accent_color", RedCol);
|
|
string title = !player.Alive ? "CHASSIS DESTROYED" : "MATCH COMPLETED — DEFEAT";
|
|
string sub = net.Mode == NetworkMode.RemoteClient
|
|
? (state.Phase == MatchPhase.Completed ? "Waiting for server next round..." : "Spectating live match...")
|
|
: "[R] Redeploy";
|
|
_outcomeLabel.Text = $"{title}\n{sub}";
|
|
_outcomeLabel.Modulate = RedCol;
|
|
}
|
|
else if (player.WaitingForRespawn)
|
|
{
|
|
_outcomeBanner.Visible = true;
|
|
_outcomeBanner.ChromeMaterial.SetShaderParameter("accent_color", CyanCol);
|
|
float eta = wave.NextWaveAtSec is float nxt ? MathF.Max(0f, nxt - state.Time) : 0f;
|
|
_outcomeLabel.Text = $"AWAITING PATRON WAVE {wave.NextWaveIndex}\nRESPAWN IN {eta:F1}s (RESP: {player.RespawnsRemaining} LEFT)";
|
|
_outcomeLabel.Modulate = CyanCol;
|
|
}
|
|
else
|
|
{
|
|
_outcomeBanner.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void BuildCrosshair()
|
|
{
|
|
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);
|
|
|
|
_crosshair = new CrosshairOverlay { Name = "Crosshair" };
|
|
_crosshair.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
|
_crosshair.MouseFilter = Control.MouseFilterEnum.Ignore;
|
|
AddChild(_crosshair);
|
|
}
|
|
|
|
private void BuildTopLeft()
|
|
{
|
|
var panel = CreateStyledPanel(OliveCol);
|
|
_topLeftPanel = panel;
|
|
panel.AnchorLeft = 0f;
|
|
panel.AnchorTop = 0f;
|
|
panel.OffsetLeft = 14f;
|
|
panel.OffsetTop = 14f;
|
|
panel.CustomMinimumSize = new Vector2(360f, 0f);
|
|
AddChild(panel);
|
|
|
|
var vbox = new VBoxContainer { Theme = null };
|
|
vbox.AddThemeConstantOverride("separation", 5);
|
|
panel.AddChild(vbox);
|
|
|
|
var headRow = new HBoxContainer();
|
|
headRow.AddThemeConstantOverride("separation", 10);
|
|
vbox.AddChild(headRow);
|
|
|
|
_chassisHeader = new Label { Text = "DUNE BUGGY", SizeFlagsHorizontal = Control.SizeFlags.ExpandFill };
|
|
_chassisHeader.AddThemeColorOverride("font_color", TextLight);
|
|
_chassisHeader.AddThemeFontSizeOverride("font_size", 17);
|
|
headRow.AddChild(_chassisHeader);
|
|
|
|
_planeBadge = new Label { Text = "DORSAL" };
|
|
_planeBadge.AddThemeFontSizeOverride("font_size", 13);
|
|
headRow.AddChild(_planeBadge);
|
|
|
|
var hpRow = new HBoxContainer();
|
|
hpRow.AddThemeConstantOverride("separation", 8);
|
|
vbox.AddChild(hpRow);
|
|
|
|
_coreHpBar = new ProgressBar
|
|
{
|
|
ShowPercentage = false,
|
|
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
|
|
CustomMinimumSize = new Vector2(180f, 16f)
|
|
};
|
|
var barBg = new StyleBoxFlat { BgColor = BgInner, BorderColor = BorderCol };
|
|
barBg.SetBorderWidthAll(1);
|
|
var barFill = new StyleBoxFlat { BgColor = OliveCol };
|
|
_coreHpBar.AddThemeStyleboxOverride("background", barBg);
|
|
_coreHpBar.AddThemeStyleboxOverride("fill", barFill);
|
|
hpRow.AddChild(_coreHpBar);
|
|
|
|
_coreHpLabel = new Label { Text = "CORE 100 / 100" };
|
|
_coreHpLabel.AddThemeColorOverride("font_color", TextLight);
|
|
_coreHpLabel.AddThemeFontSizeOverride("font_size", 13);
|
|
hpRow.AddChild(_coreHpLabel);
|
|
|
|
_statsLabel = new Label { Text = "SPD 0.0 m/s" };
|
|
_statsLabel.AddThemeColorOverride("font_color", TextMuted);
|
|
_statsLabel.AddThemeFontSizeOverride("font_size", 13);
|
|
vbox.AddChild(_statsLabel);
|
|
|
|
_safeLabel = new Label { Text = "RING SAFE" };
|
|
_safeLabel.AddThemeFontSizeOverride("font_size", 13);
|
|
vbox.AddChild(_safeLabel);
|
|
|
|
_detectionLabel = new Label { Text = "CONCEALED (TERRAIN)" };
|
|
_detectionLabel.AddThemeFontSizeOverride("font_size", 13);
|
|
vbox.AddChild(_detectionLabel);
|
|
|
|
_waveLabel = new Label { Text = "WAVE 0" };
|
|
_waveLabel.AddThemeFontSizeOverride("font_size", 12);
|
|
_waveLabel.AddThemeColorOverride("font_color", CyanCol);
|
|
vbox.AddChild(_waveLabel);
|
|
|
|
_netStatusLabel = new Label { Text = "", Visible = false };
|
|
_netStatusLabel.AddThemeFontSizeOverride("font_size", 12);
|
|
vbox.AddChild(_netStatusLabel);
|
|
|
|
_promptLabel = new Label { Text = "", Visible = false };
|
|
_promptLabel.AddThemeColorOverride("font_color", CyanCol);
|
|
_promptLabel.AddThemeFontSizeOverride("font_size", 14);
|
|
vbox.AddChild(_promptLabel);
|
|
|
|
_controlsHint = new Label { Text = "WASD Drive | Mouse Aim | LMB Fire | E Loot/Swap | Tab Garage | Wheel Zoom" };
|
|
_controlsHint.AddThemeColorOverride("font_color", TextMuted);
|
|
_controlsHint.AddThemeFontSizeOverride("font_size", 11);
|
|
vbox.AddChild(_controlsHint);
|
|
}
|
|
|
|
private void BuildTopRightRadar()
|
|
{
|
|
var panel = CreateStyledPanel(OrangeCol);
|
|
_topRightPanel = panel;
|
|
panel.AnchorLeft = 1f;
|
|
panel.AnchorRight = 1f;
|
|
panel.AnchorTop = 0f;
|
|
panel.OffsetLeft = -246f;
|
|
panel.OffsetRight = -14f;
|
|
panel.OffsetTop = 14f;
|
|
AddChild(panel);
|
|
|
|
var vbox = new VBoxContainer();
|
|
vbox.AddThemeConstantOverride("separation", 4);
|
|
panel.AddChild(vbox);
|
|
|
|
_radarTitle = new Label { Text = "SION 3KM • RADAR", HorizontalAlignment = HorizontalAlignment.Center };
|
|
_radarTitle.AddThemeColorOverride("font_color", OrangeCol);
|
|
_radarTitle.AddThemeFontSizeOverride("font_size", 12);
|
|
vbox.AddChild(_radarTitle);
|
|
|
|
_radar = new RadarWidget
|
|
{
|
|
CustomMinimumSize = new Vector2(214f, 214f)
|
|
};
|
|
vbox.AddChild(_radar);
|
|
|
|
_mapAttribLabel = new Label { Text = "Data: swisstopo | [M] Switch Map", HorizontalAlignment = HorizontalAlignment.Center };
|
|
_mapAttribLabel.AddThemeColorOverride("font_color", TextMuted);
|
|
_mapAttribLabel.AddThemeFontSizeOverride("font_size", 10);
|
|
vbox.AddChild(_mapAttribLabel);
|
|
}
|
|
|
|
private void BuildBottomLeftSchematic()
|
|
{
|
|
_bottomLeftPanel = CreateStyledPanel(OrangeCol);
|
|
_bottomLeftPanel.AnchorLeft = 0f;
|
|
_bottomLeftPanel.AnchorTop = 1f;
|
|
_bottomLeftPanel.AnchorBottom = 1f;
|
|
_bottomLeftPanel.GrowVertical = Control.GrowDirection.Begin;
|
|
_bottomLeftPanel.OffsetLeft = 14f;
|
|
_bottomLeftPanel.OffsetTop = -248f;
|
|
_bottomLeftPanel.OffsetBottom = -14f;
|
|
AddChild(_bottomLeftPanel);
|
|
|
|
var hbox = new HBoxContainer();
|
|
hbox.AddThemeConstantOverride("separation", 8);
|
|
_bottomLeftPanel.AddChild(hbox);
|
|
|
|
var leftCol = new VBoxContainer();
|
|
leftCol.AddThemeConstantOverride("separation", 4);
|
|
hbox.AddChild(leftCol);
|
|
|
|
var headRow = new HBoxContainer();
|
|
headRow.AddThemeConstantOverride("separation", 6);
|
|
leftCol.AddChild(headRow);
|
|
|
|
var title = new Label
|
|
{
|
|
Text = "HARDPOINTS & HEAT",
|
|
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
|
|
};
|
|
title.AddThemeColorOverride("font_color", OrangeCol);
|
|
title.AddThemeFontSizeOverride("font_size", 12);
|
|
headRow.AddChild(title);
|
|
|
|
_schematic = new InventoryGridControl
|
|
{
|
|
CustomMinimumSize = new Vector2(180f, 188f)
|
|
};
|
|
_schematic.HardpointClicked += OnHardpointClicked;
|
|
_schematic.HoverChanged += OnSchematicHoverChanged;
|
|
leftCol.AddChild(_schematic);
|
|
|
|
_hoverLabel = new Label
|
|
{
|
|
Text = "HOVER CELL FOR TELEMETRY",
|
|
ClipText = true,
|
|
CustomMinimumSize = new Vector2(180f, 15f)
|
|
};
|
|
_hoverLabel.AddThemeColorOverride("font_color", TextMuted);
|
|
_hoverLabel.AddThemeFontSizeOverride("font_size", 10);
|
|
leftCol.AddChild(_hoverLabel);
|
|
|
|
var rightCol = new VBoxContainer { CustomMinimumSize = new Vector2(156f, 0f) };
|
|
rightCol.AddThemeConstantOverride("separation", 3);
|
|
hbox.AddChild(rightCol);
|
|
|
|
_cargoHeader = new Label { Text = "SALVAGE CARGO (0/4)" };
|
|
_cargoHeader.AddThemeColorOverride("font_color", OliveCol);
|
|
_cargoHeader.AddThemeFontSizeOverride("font_size", 11);
|
|
rightCol.AddChild(_cargoHeader);
|
|
|
|
_cargoList = new VBoxContainer();
|
|
_cargoList.AddThemeConstantOverride("separation", 2);
|
|
rightCol.AddChild(_cargoList);
|
|
|
|
_garageDetails = new Label { Visible = false, AutowrapMode = TextServer.AutowrapMode.Word };
|
|
_garageDetails.AddThemeColorOverride("font_color", TextMuted);
|
|
_garageDetails.AddThemeFontSizeOverride("font_size", 10);
|
|
_garageDetails.CustomMinimumSize = new Vector2(178f, 0f);
|
|
hbox.AddChild(_garageDetails);
|
|
}
|
|
|
|
private void BuildBottomCenterChyron()
|
|
{
|
|
_chyronPanel = CreateStyledPanel(GoldCol);
|
|
var panel = _chyronPanel;
|
|
panel.AnchorLeft = 1f;
|
|
panel.AnchorRight = 1f;
|
|
panel.AnchorTop = 1f;
|
|
panel.AnchorBottom = 1f;
|
|
panel.GrowHorizontal = Control.GrowDirection.Begin;
|
|
panel.GrowVertical = Control.GrowDirection.Begin;
|
|
panel.OffsetLeft = -584f;
|
|
panel.OffsetRight = -14f;
|
|
panel.OffsetTop = -104f;
|
|
panel.OffsetBottom = -14f;
|
|
AddChild(panel);
|
|
|
|
var vbox = new VBoxContainer();
|
|
vbox.AddThemeConstantOverride("separation", 3);
|
|
panel.AddChild(vbox);
|
|
|
|
var header = new Label { Text = "IMPERIAL BROADCAST FEED" };
|
|
header.AddThemeColorOverride("font_color", GoldCol);
|
|
header.AddThemeFontSizeOverride("font_size", 11);
|
|
vbox.AddChild(header);
|
|
|
|
_chyronBox = new VBoxContainer();
|
|
_chyronBox.AddThemeConstantOverride("separation", 2);
|
|
vbox.AddChild(_chyronBox);
|
|
|
|
for (int i = 0; i < _chyronLabels.Length; i++)
|
|
{
|
|
var lbl = new Label
|
|
{
|
|
Visible = false,
|
|
AutowrapMode = TextServer.AutowrapMode.Word
|
|
};
|
|
lbl.AddThemeFontSizeOverride("font_size", 11);
|
|
lbl.AddThemeColorOverride("font_color", TextMuted);
|
|
_chyronBox.AddChild(lbl);
|
|
_chyronLabels[i] = lbl;
|
|
}
|
|
}
|
|
|
|
private void BuildOutcomeBanner()
|
|
{
|
|
_outcomeBanner = CreateStyledPanel(OliveCol, cornerLen: 16f, borderPx: 2f);
|
|
_outcomeBanner.AnchorLeft = 0.5f;
|
|
_outcomeBanner.AnchorRight = 0.5f;
|
|
_outcomeBanner.AnchorTop = 0.28f;
|
|
_outcomeBanner.AnchorBottom = 0.28f;
|
|
_outcomeBanner.OffsetLeft = -210f;
|
|
_outcomeBanner.OffsetRight = 210f;
|
|
_outcomeBanner.OffsetTop = -40f;
|
|
_outcomeBanner.OffsetBottom = 40f;
|
|
_outcomeBanner.Visible = false;
|
|
AddChild(_outcomeBanner);
|
|
|
|
_outcomeLabel = new Label
|
|
{
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
VerticalAlignment = VerticalAlignment.Center
|
|
};
|
|
_outcomeLabel.AddThemeFontSizeOverride("font_size", 22);
|
|
_outcomeBanner.AddChild(_outcomeLabel);
|
|
}
|
|
|
|
private void BuildNetworkPanel()
|
|
{
|
|
_netPanel = CreateStyledPanel(CyanCol, cornerLen: 14f, borderPx: 1.5f);
|
|
_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;
|
|
_netPanel.Visible = false;
|
|
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 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;
|
|
_lastCargoHash = -1;
|
|
}
|
|
}
|
|
|
|
private void OnSchematicHoverChanged(Vector2I? cell, HardpointSpec? hp)
|
|
{
|
|
var grid = _schematic.Grid;
|
|
if (cell is null || grid is null)
|
|
{
|
|
_hoverLabel.Text = "HOVER CELL FOR TELEMETRY";
|
|
_hoverLabel.AddThemeColorOverride("font_color", 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]" : "";
|
|
_hoverLabel.Text = 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}";
|
|
_hoverLabel.AddThemeColorOverride("font_color", (arm <= 0.01f || strippedHp) ? RedCol : TextLight);
|
|
}
|
|
else
|
|
{
|
|
_hoverLabel.Text = 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";
|
|
_hoverLabel.AddThemeColorOverride("font_color", arm <= 0.01f ? RedCol : TextMuted);
|
|
}
|
|
}
|
|
|
|
private void SyncCargoButtons(ChassisGrid grid)
|
|
{
|
|
int hash = HashCode.Combine(grid.Cargo.Count, grid.Spec.CargoCapacity, _selectedCargoIndex);
|
|
for (int i = 0; i < grid.Cargo.Count; i++)
|
|
{
|
|
hash = HashCode.Combine(hash, grid.Cargo[i].Id);
|
|
}
|
|
if (hash == _lastCargoHash) return;
|
|
_lastCargoHash = hash;
|
|
|
|
_cargoHeader.Text = $"SALVAGE CARGO ({grid.Cargo.Count}/{grid.Spec.CargoCapacity})";
|
|
for (int i = _cargoList.GetChildCount() - 1; i >= 0; i--)
|
|
{
|
|
var c = _cargoList.GetChild(i);
|
|
_cargoList.RemoveChild(c);
|
|
c.QueueFree();
|
|
}
|
|
|
|
if (grid.Cargo.Count == 0)
|
|
{
|
|
var empty = new Label { Text = "No modules in rack.\nPress [E] near crates." };
|
|
empty.AddThemeColorOverride("font_color", TextMuted);
|
|
empty.AddThemeFontSizeOverride("font_size", 11);
|
|
_cargoList.AddChild(empty);
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < grid.Cargo.Count; i++)
|
|
{
|
|
int idx = i;
|
|
var mod = grid.Cargo[i];
|
|
var row = new HBoxContainer();
|
|
row.AddThemeConstantOverride("separation", 4);
|
|
|
|
var selectBtn = new Button
|
|
{
|
|
Text = $"{(mod.IsImperial ? "★ " : "")}{mod.Name}",
|
|
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
|
|
Alignment = HorizontalAlignment.Left,
|
|
FocusMode = Control.FocusModeEnum.None,
|
|
ClipText = true,
|
|
CustomMinimumSize = new Vector2(114f, 0f)
|
|
};
|
|
selectBtn.AddThemeFontSizeOverride("font_size", 10);
|
|
if (_selectedCargoIndex == idx)
|
|
{
|
|
selectBtn.Modulate = OrangeCol;
|
|
}
|
|
else if (mod.IsImperial)
|
|
{
|
|
selectBtn.Modulate = GoldCol;
|
|
}
|
|
selectBtn.Pressed += () =>
|
|
{
|
|
_selectedCargoIndex = (_selectedCargoIndex == idx) ? -1 : idx;
|
|
_lastCargoHash = -1;
|
|
};
|
|
row.AddChild(selectBtn);
|
|
|
|
var fitBtn = new Button { Text = "FIT", FocusMode = Control.FocusModeEnum.None };
|
|
fitBtn.AddThemeFontSizeOverride("font_size", 10);
|
|
fitBtn.Pressed += () => AutoFitCargo(grid, idx);
|
|
row.AddChild(fitBtn);
|
|
|
|
_cargoList.AddChild(row);
|
|
}
|
|
}
|
|
|
|
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;
|
|
_lastCargoHash = -1;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SyncBroadcastChyron(BroadcastFeed broadcast)
|
|
{
|
|
var lines = broadcast.Lines;
|
|
if (ReferenceEquals(_lastBroadcastFeed, broadcast) && broadcast.Version == _lastChyronVersion)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_lastBroadcastFeed = broadcast;
|
|
_lastChyronVersion = broadcast.Version;
|
|
|
|
int start = Math.Max(0, lines.Count - _chyronLabels.Length);
|
|
int visibleCount = lines.Count - start;
|
|
for (int slot = 0; slot < _chyronLabels.Length; slot++)
|
|
{
|
|
var lbl = _chyronLabels[slot];
|
|
if (slot < visibleCount)
|
|
{
|
|
int lineIdx = start + slot;
|
|
var line = lines[lineIdx];
|
|
bool isLatest = lineIdx == lines.Count - 1;
|
|
lbl.Visible = true;
|
|
lbl.Text = $"[{line.Timestamp:00.0}s] {line.Text}";
|
|
lbl.AddThemeFontSizeOverride("font_size", isLatest ? 12 : 11);
|
|
lbl.AddThemeColorOverride("font_color", isLatest ? TextLight : TextMuted);
|
|
}
|
|
else
|
|
{
|
|
lbl.Visible = false;
|
|
lbl.Text = "";
|
|
}
|
|
}
|
|
}
|
|
|
|
private static string BuildInteractionPrompt(MatchState state, ContenderState player)
|
|
{
|
|
GroundDrop? nearest = state.FindNearestInteractableDrop(player.Id);
|
|
if (nearest is null) return "";
|
|
if (nearest.Module is { } mod)
|
|
{
|
|
var freeHp = player.Grid.FindFirstEmptyCompatibleHardpoint(mod);
|
|
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 "";
|
|
}
|
|
|
|
private static string BuildGarageDetails(ChassisGrid grid)
|
|
{
|
|
var lines = new List<string>
|
|
{
|
|
$"COND {grid.Spec.HullConductivity:F1} | THRUST {grid.ComputeDriveThrust():F0} N",
|
|
"MOUNTED:"
|
|
};
|
|
for (int i = 0; i < grid.Mounted.Count; i++)
|
|
{
|
|
var m = grid.Mounted[i];
|
|
string stateTag = grid.IsHardpointOperational(m.HardpointId) ? "" : " [STRIPPED]";
|
|
lines.Add($"• {m.HardpointId}: {m.Spec.Name} {m.CurrentTemp:F0}°C ({(m.CurrentPerformance * 100f):F0}%){stateTag}");
|
|
}
|
|
return string.Join("\n", lines);
|
|
}
|
|
|
|
private static ChromePanel CreateStyledPanel(Color accentColor, float cornerLen = 12f, float borderPx = 1.5f)
|
|
{
|
|
return new ChromePanel(accentColor, cornerLen, borderPx);
|
|
}
|
|
|
|
private sealed partial class ChromePanel : PanelContainer
|
|
{
|
|
private static Shader? _sharedChromeShader;
|
|
private static ImageTexture? _sharedWhiteTex;
|
|
private readonly ShaderMaterial _material;
|
|
|
|
public ChromePanel(Color accentColor, float cornerLen, float borderPx)
|
|
{
|
|
_sharedChromeShader ??= GD.Load<Shader>("res://panel_chrome.gdshader");
|
|
if (_sharedWhiteTex is null)
|
|
{
|
|
var img = Image.CreateEmpty(1, 1, false, Image.Format.Rgba8);
|
|
img.SetPixel(0, 0, Colors.White);
|
|
_sharedWhiteTex = ImageTexture.CreateFromImage(img);
|
|
}
|
|
|
|
_material = new ShaderMaterial { Shader = _sharedChromeShader };
|
|
_material.SetShaderParameter("bg_color", new Color(BgDark.R, BgDark.G, BgDark.B, 0.88f));
|
|
_material.SetShaderParameter("border_color", BorderCol);
|
|
_material.SetShaderParameter("accent_color", accentColor);
|
|
_material.SetShaderParameter("corner_len", cornerLen);
|
|
_material.SetShaderParameter("border_px", borderPx);
|
|
Material = _material;
|
|
|
|
var empty = new StyleBoxEmpty
|
|
{
|
|
ContentMarginLeft = 10,
|
|
ContentMarginRight = 10,
|
|
ContentMarginTop = 8,
|
|
ContentMarginBottom = 8
|
|
};
|
|
AddThemeStyleboxOverride("panel", empty);
|
|
}
|
|
|
|
public ShaderMaterial ChromeMaterial => _material;
|
|
|
|
public override void _Notification(int what)
|
|
{
|
|
if (what == NotificationResized)
|
|
{
|
|
_material.SetShaderParameter("rect_size", Size);
|
|
QueueRedraw();
|
|
}
|
|
}
|
|
|
|
public override void _Draw()
|
|
{
|
|
if (Size.X < 2f || Size.Y < 2f || _sharedWhiteTex is null) return;
|
|
_material.SetShaderParameter("rect_size", Size);
|
|
DrawTextureRect(_sharedWhiteTex, new Rect2(Vector2.Zero, Size), false, Colors.White);
|
|
}
|
|
}
|
|
|
|
private sealed partial class CrosshairOverlay : Control
|
|
{
|
|
private const float HitArcDuration = 0.65f;
|
|
|
|
private sealed class IncomingHitArc
|
|
{
|
|
public float SourceX;
|
|
public float SourceZ;
|
|
public WeaponVisualClass WeaponClass;
|
|
public float Age;
|
|
}
|
|
|
|
private ContenderState? _player;
|
|
private OrbitalPod? _localPod;
|
|
private float _cameraYaw;
|
|
private MatchState? _lastState;
|
|
private readonly List<IncomingHitArc> _incomingArcs = new();
|
|
private HitMarkerKind _hitMarkerKind;
|
|
private float _hitMarkerRemaining;
|
|
private float _hitMarkerDuration;
|
|
|
|
public void SetState(MatchState state, ContenderState player, float cameraYaw, OrbitalPod? localPod = null)
|
|
{
|
|
if (!ReferenceEquals(_lastState, state))
|
|
{
|
|
_lastState = state;
|
|
ResetFeedback();
|
|
}
|
|
|
|
_player = player;
|
|
_localPod = localPod;
|
|
_cameraYaw = cameraYaw;
|
|
}
|
|
|
|
public void ResetFeedback()
|
|
{
|
|
_incomingArcs.Clear();
|
|
_hitMarkerKind = HitMarkerKind.None;
|
|
_hitMarkerRemaining = 0f;
|
|
_hitMarkerDuration = 0f;
|
|
QueueRedraw();
|
|
}
|
|
|
|
public void TriggerHitMarker(bool coreHit, bool killed)
|
|
{
|
|
HitMarkerKind nextKind = killed
|
|
? HitMarkerKind.Kill
|
|
: (coreHit ? HitMarkerKind.Core : HitMarkerKind.Armor);
|
|
// Preserve stronger hit-marker kind while active (Kill > Core > 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;
|
|
QueueRedraw();
|
|
}
|
|
|
|
public void Advance(float dt)
|
|
{
|
|
bool dirty = false;
|
|
if (_incomingArcs.Count > 0 && dt > 0f)
|
|
{
|
|
for (int i = _incomingArcs.Count - 1; i >= 0; i--)
|
|
{
|
|
_incomingArcs[i].Age += dt;
|
|
if (_incomingArcs[i].Age >= HitArcDuration)
|
|
{
|
|
_incomingArcs.RemoveAt(i);
|
|
}
|
|
}
|
|
dirty = true;
|
|
}
|
|
|
|
if (_hitMarkerRemaining > 0f && dt > 0f)
|
|
{
|
|
_hitMarkerRemaining = MathF.Max(0f, _hitMarkerRemaining - dt);
|
|
if (_hitMarkerRemaining <= 0.001f)
|
|
{
|
|
_hitMarkerRemaining = 0f;
|
|
_hitMarkerKind = HitMarkerKind.None;
|
|
}
|
|
dirty = true;
|
|
}
|
|
|
|
if (dirty)
|
|
{
|
|
QueueRedraw();
|
|
}
|
|
}
|
|
|
|
public void PushTestHitArc(float sourceX, float sourceZ, WeaponVisualClass weaponClass)
|
|
{
|
|
if (_incomingArcs.Count >= 8) _incomingArcs.RemoveAt(0);
|
|
_incomingArcs.Add(new IncomingHitArc
|
|
{
|
|
SourceX = sourceX,
|
|
SourceZ = sourceZ,
|
|
WeaponClass = weaponClass,
|
|
Age = 0f
|
|
});
|
|
QueueRedraw();
|
|
}
|
|
|
|
public int ActiveHitArcCount => _incomingArcs.Count;
|
|
public bool HasActiveHitMarker => _hitMarkerRemaining > 0f && _hitMarkerKind != HitMarkerKind.None;
|
|
public HitMarkerKind ActiveHitMarkerKind => HasActiveHitMarker ? _hitMarkerKind : HitMarkerKind.None;
|
|
|
|
public override void _Draw()
|
|
{
|
|
Vector2 center = Size * 0.5f;
|
|
float gap = 6f;
|
|
float tick = 10f;
|
|
bool allDisabled = _player is not null && _player.Alive &&
|
|
_player.InArcWeaponCount == 0 && _player.OutOfArcWeaponCount == 0 && _player.DisabledWeaponCount > 0;
|
|
bool outOfArc = _player is not null && _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);
|
|
|
|
// Clean 4-tick center crosshair + center pip
|
|
DrawCircle(center, 1.8f, retCol);
|
|
DrawLine(center + new Vector2(-gap - tick, 0f), center + new Vector2(-gap, 0f), retCol, 1.6f);
|
|
DrawLine(center + new Vector2(gap, 0f), center + new Vector2(gap + tick, 0f), retCol, 1.6f);
|
|
DrawLine(center + new Vector2(0f, -gap - tick), center + new Vector2(0f, -gap), retCol, 1.6f);
|
|
DrawLine(center + new Vector2(0f, gap), center + new Vector2(0f, gap + tick), retCol, 1.6f);
|
|
|
|
// Outgoing reticle hit-marker X-flash (white/gold armor, crimson core, crimson double-X kill)
|
|
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);
|
|
DrawLine(center + dir * rIn, center + dir * rOut, xCol, xWidth);
|
|
if (_hitMarkerKind == HitMarkerKind.Kill)
|
|
{
|
|
DrawLine(center + dir * (rOut + 4f), center + dir * (rOut + 10.5f), new Color(GoldCol.R, GoldCol.G, GoldCol.B, frac * 0.95f), 2.2f);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (allDisabled)
|
|
{
|
|
DrawString(
|
|
ThemeDB.FallbackFont,
|
|
center + new Vector2(-52f, 36f),
|
|
"WEAPONS STRIPPED",
|
|
HorizontalAlignment.Left,
|
|
-1,
|
|
11,
|
|
RedCol);
|
|
}
|
|
else if (outOfArc)
|
|
{
|
|
DrawString(
|
|
ThemeDB.FallbackFont,
|
|
center + new Vector2(-34f, 36f),
|
|
"OUT OF ARC",
|
|
HorizontalAlignment.Left,
|
|
-1,
|
|
11,
|
|
RedCol);
|
|
}
|
|
|
|
if (_player is null || !_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;
|
|
bool burning = _localPod?.Phase == OrbitalPodPhase.RetroBurn;
|
|
Color bracketCol = burning ? OrangeCol : CyanCol;
|
|
|
|
float altFrac = Math.Clamp(agl / 410f, 0f, 1f);
|
|
const float barX = 72f;
|
|
const float barH = 76f;
|
|
Vector2 topL = center + new Vector2(-barX, -barH * 0.5f);
|
|
Vector2 topR = center + new Vector2(barX, -barH * 0.5f);
|
|
DrawLine(topL, topL + new Vector2(0f, barH), new Color(BorderCol.R, BorderCol.G, BorderCol.B, 0.55f), 2.0f);
|
|
DrawLine(topR, topR + new Vector2(0f, barH), new Color(BorderCol.R, BorderCol.G, BorderCol.B, 0.55f), 2.0f);
|
|
|
|
float fillH = barH * altFrac;
|
|
DrawLine(topL + new Vector2(0f, barH - fillH), topL + new Vector2(0f, barH), bracketCol, 3.0f);
|
|
DrawLine(topR + new Vector2(0f, barH - fillH), topR + new Vector2(0f, barH), bracketCol, 3.0f);
|
|
|
|
DrawString(
|
|
ThemeDB.FallbackFont,
|
|
center + new Vector2(-46f, 54f),
|
|
$"ALT {agl:F0}m | {vel:F0}m/s",
|
|
HorizontalAlignment.Left,
|
|
-1,
|
|
11,
|
|
bracketCol);
|
|
if (burning)
|
|
{
|
|
DrawString(
|
|
ThemeDB.FallbackFont,
|
|
center + new Vector2(-46f, -52f),
|
|
"RETRO BURN ACTIVE",
|
|
HorizontalAlignment.Left,
|
|
-1,
|
|
11,
|
|
OrangeCol);
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
float arcRadius = 21f;
|
|
float startAngle = -MathF.PI * 0.75f;
|
|
float maxSweep = MathF.PI * 1.5f;
|
|
DrawArc(center, arcRadius, startAngle, startAngle + maxSweep, 24, new Color(BorderCol.R, BorderCol.G, BorderCol.B, 0.4f), 2.0f);
|
|
|
|
if (heatRatio > 0.01f)
|
|
{
|
|
Color heatCol = overPlateau
|
|
? RedCol
|
|
: (heatRatio > 0.65f ? OrangeCol : OliveCol);
|
|
DrawArc(center, arcRadius, startAngle, startAngle + maxSweep * heatRatio, 24, heatCol, 2.4f);
|
|
}
|
|
|
|
// Directional incoming-hit indicator arcs (fade over 0.65s)
|
|
if (_incomingArcs.Count > 0)
|
|
{
|
|
float sinY = MathF.Sin(_cameraYaw);
|
|
float cosY = MathF.Cos(_cameraYaw);
|
|
for (int i = 0; i < _incomingArcs.Count; 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.ThermalBeam => new Color(0.30f, 0.90f, 1.0f, alpha * 0.96f),
|
|
_ => new Color(0.96f, 0.72f, 0.22f, alpha * 0.94f)
|
|
};
|
|
|
|
const float hitR = 39f;
|
|
const float halfSpan = 0.34f;
|
|
DrawArc(center, hitR, angle - halfSpan, angle + halfSpan, 14, arcCol, 4.2f);
|
|
if (arc.WeaponClass == WeaponVisualClass.ThermalBeam)
|
|
{
|
|
DrawArc(center, hitR - 3.5f, angle - halfSpan * 0.75f, angle + halfSpan * 0.75f, 10,
|
|
new Color(GoldCol.R, GoldCol.G, GoldCol.B, alpha * 0.90f), 2.0f);
|
|
}
|
|
|
|
Vector2 dirVec = new(MathF.Cos(angle), MathF.Sin(angle));
|
|
Vector2 perp = new(-dirVec.Y, dirVec.X);
|
|
Vector2 tip = center + dirVec * (hitR + 9f);
|
|
Vector2 baseL = center + dirVec * (hitR + 1.5f) - perp * 4.5f;
|
|
Vector2 baseR = center + dirVec * (hitR + 1.5f) + perp * 4.5f;
|
|
DrawColoredPolygon(new[] { tip, baseL, baseR }, arcCol);
|
|
}
|
|
|
|
var latest = _incomingArcs[^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.ThermalBeam => ("THERMAL HIT", new Color(0.36f, 0.92f, 1.0f, tagAlpha)),
|
|
_ => ("KINETIC HIT", new Color(0.96f, 0.78f, 0.28f, tagAlpha))
|
|
};
|
|
DrawString(
|
|
ThemeDB.FallbackFont,
|
|
center + new Vector2(-36f, 54f),
|
|
tagText,
|
|
HorizontalAlignment.Left,
|
|
-1,
|
|
10,
|
|
tagCol);
|
|
}
|
|
}
|
|
}
|
|
|
|
private sealed partial class RadarWidget : Control
|
|
{
|
|
private IClientArenaSession? _session;
|
|
private float _cameraYaw;
|
|
|
|
public void SetState(IClientArenaSession session, float cameraYaw)
|
|
{
|
|
_session = session;
|
|
_cameraYaw = cameraYaw;
|
|
}
|
|
|
|
private static Vector2 WorldToRadar(Vector2 center, float scale, float wx, float wz, float camYaw)
|
|
{
|
|
// Heading-up 3P radar: camera forward (sinY, cosY) is always UP (-screenY), camera right (-cosY, sinY) is RIGHT (+screenX).
|
|
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;
|
|
}
|
|
|
|
public override void _Draw()
|
|
{
|
|
Vector2 center = Size * 0.5f;
|
|
float radius = MathF.Min(Size.X, Size.Y) * 0.47f;
|
|
float maxBlipRadius = MathF.Max(4f, radius - 3f);
|
|
var state = _session?.ViewState;
|
|
float arenaHalf = MathF.Max(1f, state?.Terrain.MapHalfExtent ?? MatchState.ArenaHalfExtent);
|
|
float scale = radius / arenaHalf;
|
|
|
|
DrawCircle(center, radius, BgInner);
|
|
DrawArc(center, radius, 0f, MathF.Tau, 48, BorderCol, 1.5f);
|
|
// Forward-up indicator tick at top of radar
|
|
DrawLine(center + new Vector2(0f, -radius), center + new Vector2(0f, -radius + 6f), CyanCol, 2.0f);
|
|
|
|
if (_session is null || state is null) return;
|
|
|
|
int localId = _session.LocalContenderId;
|
|
|
|
// Safe Circle
|
|
float safePx = MathF.Min(state.Spectators.SafeRadius * scale, maxBlipRadius);
|
|
DrawArc(center, safePx, 0f, MathF.Tau, 64, OrangeCol, 1.6f);
|
|
|
|
// 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)
|
|
{
|
|
DrawRect(new Rect2(p - new Vector2(2.5f, 2.5f), new Vector2(5f, 5f)), CyanCol);
|
|
}
|
|
else if (d.Module is { IsImperial: true })
|
|
{
|
|
DrawCircle(p, 3.0f, GoldCol);
|
|
}
|
|
}
|
|
|
|
// Active descending Orbital Pods (cyan/gold diamonds for gear, chevrons for contenders)
|
|
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;
|
|
Color pCol = isLocalPod ? OliveCol : OrangeCol;
|
|
float sz = isLocalPod ? 5.5f : 3.6f;
|
|
var pts = new[]
|
|
{
|
|
pp + new Vector2(0f, -sz),
|
|
pp + new Vector2(-sz * 0.8f, sz * 0.7f),
|
|
pp + new Vector2(sz * 0.8f, sz * 0.7f)
|
|
};
|
|
DrawColoredPolygon(pts, pCol);
|
|
}
|
|
else
|
|
{
|
|
bool isImp = pod.WaveIndex > 0 || pod.Module?.IsImperial == true;
|
|
Color gCol = isImp ? GoldCol : CyanCol;
|
|
const float d = 3.2f;
|
|
var pts = new[]
|
|
{
|
|
pp + new Vector2(0f, -d),
|
|
pp + new Vector2(d, 0f),
|
|
pp + new Vector2(0f, d),
|
|
pp + new Vector2(-d, 0f)
|
|
};
|
|
DrawColoredPolygon(pts, gCol);
|
|
}
|
|
}
|
|
|
|
// Spectator Wall (LOS / Tourist horizon rule / 5s ghost memory; hidden Exemplars vanish!)
|
|
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));
|
|
DrawLine(p, tp, new Color(RedCol.R, RedCol.G, RedCol.B, 0.65f), 1.3f);
|
|
}
|
|
}
|
|
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;
|
|
DrawCircle(p, blipR, new Color(ghostCol.R, ghostCol.G, ghostCol.B, alpha));
|
|
}
|
|
else
|
|
{
|
|
DrawCircle(p, blipR, col);
|
|
}
|
|
}
|
|
|
|
// Contenders (player always live; rivals obey 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));
|
|
var perp = new Vector2(-dir.Y, dir.X);
|
|
var pts = new[]
|
|
{
|
|
p + dir * 6.5f,
|
|
p - dir * 4.5f + perp * 4.2f,
|
|
p - dir * 4.5f - perp * 4.2f
|
|
};
|
|
DrawColoredPolygon(pts, OliveCol);
|
|
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));
|
|
DrawCircle(p, 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);
|
|
DrawCircle(p, 2.8f, new Color(OrangeCol.R, OrangeCol.G, OrangeCol.B, alpha));
|
|
}
|
|
}
|
|
}
|
|
|
|
private static readonly Color PatronColor = Color.FromHtml("#4ba8a5");
|
|
}
|
|
}
|