Files
Rail_Enterprise/client/ViaFerrea.Client/scripts/Hud/TopBar.cs
T
Claude 9a4ada6d9d F3: client Godot minimo, replay dei comandi e collaudi automatici
- Client Godot 4.7 .NET (Godot.NET.Sdk 4.7.2): menu, collegamento, partita
  locale con server figlio; mappa con terreno (fasce, ombreggiatura, rive
  curve con shader, curve di livello), opere, entità, alberi, treni
  interpolati con fumo; strumenti binari con profilo, stazione, deposito,
  segnali, demolizione; pannelli treni, linee, mercato, finanze, schede;
  barra superiore, minimappa, notiziario; italiano e inglese.
- Pilota automatico del client e scripts/client-autopilot.sh: partita locale,
  linea con ponte, treni in moto e schermate (docs/screenshots).
- Registro dei comandi del server (--record) e viaferrea-tools replay.
- PROTOCOL.md normativo, ADR 0009, ARCHITECTURE, STATE e README aggiornati.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
2026-10-02 00:47:42 +00:00

112 lines
5.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Godot;
using ViaFerrea.Client.App;
using ViaFerrea.Client.Net;
using static ViaFerrea.Client.App.Localization;
namespace ViaFerrea.Client.Hud;
/// <summary>Barra superiore (immagine 01): compagnia e livello, data, velocità, cassa, patrimonio, rating, stato del server.</summary>
public partial class TopBar : PanelContainer
{
private GameSession? _session;
private readonly Label _company = UiTheme.TitleLabel("", 30);
private readonly PanelContainer _tier = UiTheme.Badge("");
private readonly Label _date = UiTheme.Text("", 17, bold: true);
private readonly Label _cash = UiTheme.Text("", 20, Palette.AmberLight, bold: true);
private readonly Label _worth = UiTheme.Text("", 20, bold: true);
private readonly Label _rating = UiTheme.Text("", 20, bold: true);
private readonly Label _server = UiTheme.Text("", 14);
private readonly ColorRect _serverDot = new() { CustomMinimumSize = new Vector2(10, 10) };
private readonly List<Button> _speeds = [];
public override void _Ready()
{
AddThemeStyleboxOverride("panel", UiTheme.Box(Palette.Panel, Palette.Border, 0, 14));
CustomMinimumSize = new Vector2(0, 68);
var row = new HBoxContainer();
row.AddThemeConstantOverride("separation", 18);
AddChild(row);
row.AddChild(new Logo { CustomMinimumSize = new Vector2(40, 40) });
row.AddChild(_company);
var tierBox = new CenterContainer();
tierBox.AddChild(_tier);
row.AddChild(tierBox);
row.AddChild(new Control { SizeFlagsHorizontal = SizeFlags.ExpandFill });
row.AddChild(_date);
var speeds = new HBoxContainer();
speeds.AddThemeConstantOverride("separation", 4);
foreach (byte speed in new byte[] { 0, 1, 2, 4, 8 })
{
var b = new Button { Text = speed == 0 ? "II" : $"{speed}×", ToggleMode = true, CustomMinimumSize = new Vector2(46, 40) };
b.Pressed += () => _session?.SetSpeed(speed);
b.TooltipText = speed == 0 ? T("Pausa") : T("Velocità");
_speeds.Add(b);
speeds.AddChild(b);
}
row.AddChild(speeds);
row.AddChild(new Control { SizeFlagsHorizontal = SizeFlags.ExpandFill });
row.AddChild(Stat(T("Cassa"), _cash));
row.AddChild(Stat(T("Patrimonio netto"), _worth));
row.AddChild(Stat(T("Rating"), _rating));
var chip = new PanelContainer();
chip.AddThemeStyleboxOverride("panel", UiTheme.Box(Palette.Inner, Palette.Border, 16, 12));
var chipRow = new HBoxContainer();
chipRow.AddThemeConstantOverride("separation", 8);
var dotBox = new CenterContainer();
dotBox.AddChild(_serverDot);
chipRow.AddChild(dotBox);
chipRow.AddChild(_server);
chip.AddChild(chipRow);
var chipCenter = new CenterContainer();
chipCenter.AddChild(chip);
row.AddChild(chipCenter);
}
private static VBoxContainer Stat(string caption, Label value)
{
var box = new VBoxContainer();
box.AddThemeConstantOverride("separation", -2);
var c = UiTheme.Text(caption, 12, Palette.TextSecondary);
c.HorizontalAlignment = HorizontalAlignment.Right;
value.HorizontalAlignment = HorizontalAlignment.Right;
box.AddChild(c);
box.AddChild(value);
return box;
}
public void Bind(GameSession session) => _session = session;
public override void _Process(double delta)
{
var w = _session?.World;
if (w?.Summary is null) return;
var me = w.Companies.GetValueOrDefault(w.Summary.CompanyId);
_company.Text = me?.Name ?? w.Summary.CompanyName;
int tier = Math.Clamp(me?.Tier ?? 1, 1, w.Data.Tiers.Tiers.Count);
((Label)_tier.GetChild(0)).Text = TranslationServer.GetLocale().StartsWith("en") ? w.Data.Tiers.Tiers[tier - 1].NameEn : w.Data.Tiers.Tiers[tier - 1].NameIt;
_date.Text = w.LastDigest?.Date ?? w.Summary.Date;
_cash.Text = (w.LastDigest?.Cash ?? me?.Cash ?? default).ToString();
_worth.Text = (w.LastDigest?.NetWorth ?? me?.NetWorth ?? default).ToString("short");
_rating.Text = w.LastDigest?.Rating ?? me?.Rating ?? "—";
byte speed = _session!.RequestedSpeed ?? w.LastDigest?.Speed ?? w.Speed;
for (int i = 0; i < _speeds.Count; i++) _speeds[i].SetPressedNoSignal(new byte[] { 0, 1, 2, 4, 8 }[i] == speed);
bool open = _session!.IsOpen;
_serverDot.Color = !open ? Palette.Danger : w.LastDigest?.Slow == true ? Palette.Amber : Palette.Ok;
_server.Text = open ? $"{_session.ServerLabel} {_session.LatencyMs:0} ms" : T("Disconnesso");
}
/// <summary>Marchio: ruota stilizzata ambra (immagine 01).</summary>
private sealed partial class Logo : Control
{
public override void _Draw()
{
var c = Size / 2;
float r = Math.Min(Size.X, Size.Y) / 2 - 3;
DrawArc(c, r, 0, MathF.Tau, 48, Palette.Amber, 3, true);
DrawLine(c - new Vector2(r, 0), c + new Vector2(r, 0), Palette.Amber, 3);
DrawLine(c - new Vector2(0, r), c + new Vector2(0, r), Palette.Amber, 3);
DrawCircle(c, r * 0.28f, Palette.Amber);
}
}
}