1011 lines
38 KiB
C#
1011 lines
38 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Godot;
|
|
using RustToDust.Core;
|
|
using RustToDust.Ymir;
|
|
|
|
namespace RustToDust.Client;
|
|
|
|
/// <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<ArenaSession?> _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 _promptLabel = null!;
|
|
private Label _controlsHint = null!;
|
|
|
|
private RadarWidget _radar = null!;
|
|
private CrosshairOverlay _crosshair = null!;
|
|
private InventoryGridControl _schematic = null!;
|
|
private Button _thermalButton = 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 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 Hud(Func<ArenaSession?> getSession, Action<int, string> onEquipCargo, Func<float>? getCameraYaw = null)
|
|
{
|
|
_getSession = getSession;
|
|
_onEquipCargo = onEquipCargo;
|
|
_getCameraYaw = getCameraYaw ?? (() => 0f);
|
|
Layer = 10;
|
|
}
|
|
|
|
public bool GarageExpanded => _garageExpanded;
|
|
public bool ThermalMode => _schematic.ThermalEnabled;
|
|
public InventoryGridControl Schematic => _schematic;
|
|
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;
|
|
}
|
|
|
|
public void ToggleGarage()
|
|
{
|
|
_garageExpanded = !_garageExpanded;
|
|
_garageDetails.Visible = _garageExpanded;
|
|
_schematic.CustomMinimumSize = _garageExpanded ? new Vector2(198f, 208f) : new Vector2(180f, 188f);
|
|
_schematic.QueueRedraw();
|
|
}
|
|
|
|
public void ToggleThermal() => SetThermalMode(!_schematic.ThermalEnabled);
|
|
|
|
public void SetThermalMode(bool enabled, bool instant = false)
|
|
{
|
|
if (instant)
|
|
{
|
|
_schematic.SetThermalInstant(enabled);
|
|
}
|
|
else
|
|
{
|
|
_schematic.ThermalEnabled = enabled;
|
|
}
|
|
_thermalButton.ButtonPressed = enabled;
|
|
_thermalButton.Modulate = enabled ? CyanCol : TextMuted;
|
|
_thermalButton.Text = enabled ? "[T] CONDUITS: ON" : "[T] CONDUITS";
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
BuildCrosshair();
|
|
BuildTopLeft();
|
|
BuildTopRightRadar();
|
|
BuildBottomLeftSchematic();
|
|
BuildBottomCenterChyron();
|
|
BuildOutcomeBanner();
|
|
}
|
|
|
|
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));
|
|
}
|
|
|
|
public bool HasPanelOverlapOrClip(Vector2 viewportSize)
|
|
{
|
|
var panels = new[] { _topLeftPanel, _topRightPanel, _bottomLeftPanel, _chyronPanel };
|
|
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(ArenaSession session)
|
|
{
|
|
var state = session.State;
|
|
var player = state.Player;
|
|
|
|
// Top-Left Status
|
|
_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;
|
|
|
|
_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}";
|
|
|
|
int aliveCount = 0;
|
|
for (int i = 0; i < state.Contenders.Count; i++)
|
|
{
|
|
if (state.Contenders[i].Alive) aliveCount++;
|
|
}
|
|
_statsLabel.Text = $"SPD {player.Speed:F1} m/s | ALIVE {aliveCount} / {state.Contenders.Count} | KILLS {player.Kills}";
|
|
|
|
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;
|
|
}
|
|
|
|
if (state.PlayerDetectedByCount > 0)
|
|
{
|
|
_detectionLabel.Text = $"DETECTED BY {state.PlayerDetectedByCount}";
|
|
_detectionLabel.Modulate = RedCol;
|
|
}
|
|
else
|
|
{
|
|
_detectionLabel.Text = "CONCEALED (TERRAIN)";
|
|
_detectionLabel.Modulate = OliveCol;
|
|
}
|
|
|
|
_promptLabel.Text = BuildInteractionPrompt(state, player);
|
|
_promptLabel.Visible = !string.IsNullOrEmpty(_promptLabel.Text);
|
|
|
|
// Crosshair + Heat Arc
|
|
_crosshair.SetState(player);
|
|
_crosshair.QueueRedraw();
|
|
|
|
// Radar (heading-up with camera yaw)
|
|
_radar.SetState(state, _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
|
|
if (state.Phase == MatchPhase.Victory)
|
|
{
|
|
_outcomeBanner.Visible = true;
|
|
_outcomeBanner.ChromeMaterial.SetShaderParameter("accent_color", OliveCol);
|
|
_outcomeLabel.Text = "VICTORY — LAST RIG STANDING\n[R] New Drop";
|
|
_outcomeLabel.Modulate = OliveCol;
|
|
}
|
|
else if (state.Phase == MatchPhase.Defeat)
|
|
{
|
|
_outcomeBanner.Visible = true;
|
|
_outcomeBanner.ChromeMaterial.SetShaderParameter("accent_color", RedCol);
|
|
_outcomeLabel.Text = "CHASSIS DESTROYED\n[R] Redeploy";
|
|
_outcomeLabel.Modulate = RedCol;
|
|
}
|
|
else
|
|
{
|
|
_outcomeBanner.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void BuildCrosshair()
|
|
{
|
|
_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);
|
|
|
|
_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 | T Conduits | 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);
|
|
|
|
var title = new Label { Text = "GALLERY & ARENA RADAR", HorizontalAlignment = HorizontalAlignment.Center };
|
|
title.AddThemeColorOverride("font_color", OrangeCol);
|
|
title.AddThemeFontSizeOverride("font_size", 12);
|
|
vbox.AddChild(title);
|
|
|
|
_radar = new RadarWidget
|
|
{
|
|
CustomMinimumSize = new Vector2(214f, 214f)
|
|
};
|
|
vbox.AddChild(_radar);
|
|
}
|
|
|
|
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);
|
|
|
|
_thermalButton = new Button
|
|
{
|
|
Text = "[T] CONDUITS",
|
|
ToggleMode = true,
|
|
FocusMode = Control.FocusModeEnum.None,
|
|
Modulate = TextMuted
|
|
};
|
|
_thermalButton.AddThemeFontSizeOverride("font_size", 10);
|
|
_thermalButton.Pressed += () => SetThermalMode(_thermalButton.ButtonPressed);
|
|
headRow.AddChild(_thermalButton);
|
|
|
|
_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 OnHardpointClicked(string hardpointId)
|
|
{
|
|
var session = _getSession();
|
|
if (session is null) return;
|
|
var cargo = session.State.Player.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);
|
|
_hoverLabel.Text = mounted is not null
|
|
? $"{hp.Kind.ToString().ToUpperInvariant()}: {mounted.Spec.Name} {mounted.CurrentTemp:F0}°C ({mounted.CurrentPerformance * 100f:F0}%)"
|
|
: $"{hp.Kind.ToString().ToUpperInvariant()} SLOT [{hp.Width}x{hp.Height}] EMPTY";
|
|
_hoverLabel.AddThemeColorOverride("font_color", arm <= 0.01f ? 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 = grid.Cargo.Count * 97 + (_selectedCargoIndex + 10);
|
|
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 = null;
|
|
float bestD2 = MatchState.PickupRadius * MatchState.PickupRadius;
|
|
for (int i = 0; i < state.GroundDrops.Count; i++)
|
|
{
|
|
var d = state.GroundDrops[i];
|
|
if (d.PickedUp) continue;
|
|
float dx = d.X - player.X;
|
|
float dz = d.Z - player.Z;
|
|
float d2 = dx * dx + dz * dz;
|
|
if (d2 <= bestD2)
|
|
{
|
|
bestD2 = d2;
|
|
nearest = d;
|
|
}
|
|
}
|
|
|
|
if (nearest is null) return "";
|
|
if (nearest.Module is { } mod)
|
|
{
|
|
return $"[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];
|
|
lines.Add($"• {m.HardpointId}: {m.Spec.Name} {m.CurrentTemp:F0}°C ({(m.CurrentPerformance * 100f):F0}%)");
|
|
}
|
|
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 ContenderState? _player;
|
|
|
|
public void SetState(ContenderState player) => _player = player;
|
|
|
|
public override void _Draw()
|
|
{
|
|
Vector2 center = Size * 0.5f;
|
|
float gap = 6f;
|
|
float tick = 10f;
|
|
Color retCol = 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);
|
|
|
|
if (_player is null || !_player.Alive)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
private sealed partial class RadarWidget : Control
|
|
{
|
|
private MatchState? _state;
|
|
private float _cameraYaw;
|
|
|
|
public void SetState(MatchState state, float cameraYaw)
|
|
{
|
|
_state = state;
|
|
_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);
|
|
float scale = radius / MatchState.ArenaHalfExtent;
|
|
|
|
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 (_state is null) return;
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
// Spectator Wall (LOS / Tourist horizon rule / 5s ghost memory; hidden Exemplars vanish!)
|
|
var specs = _state.Spectators.Spectators;
|
|
for (int i = 0; i < specs.Count; i++)
|
|
{
|
|
var s = specs[i];
|
|
if (!s.Alive) continue;
|
|
|
|
_state.SpectatorContacts.TryGetValue(s.Id, out var mem);
|
|
if (!MatchState.IsContactOnRadar(mem))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
bool live = mem!.VisibleToPlayer;
|
|
float drawX = live || mem.FaintHorizonPing ? s.X : mem.LastSeenX;
|
|
float drawZ = live || mem.FaintHorizonPing ? 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.IsPlayer ||
|
|
(_state.ContenderContacts.TryGetValue(tgt.Id, out var tgtMem) && tgtMem.VisibleToPlayer);
|
|
if (targetVisible)
|
|
{
|
|
float tgtClampR = MathF.Max(4f, radius - (tgt.IsPlayer ? 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.Alive) continue;
|
|
|
|
if (c.IsPlayer)
|
|
{
|
|
float playerClampR = MathF.Max(4f, radius - 6.5f - 1f);
|
|
var p = ClampToRadarDisc(center, playerClampR, WorldToRadar(center, scale, c.X, c.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;
|
|
}
|
|
|
|
_state.ContenderContacts.TryGetValue(c.Id, out var mem);
|
|
if (!MatchState.IsContactOnRadar(mem))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (mem!.VisibleToPlayer)
|
|
{
|
|
float rivalClampR = MathF.Max(4f, radius - 3.3f - 1f);
|
|
var p = ClampToRadarDisc(center, rivalClampR, WorldToRadar(center, scale, c.X, c.Z, _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");
|
|
}
|
|
}
|