Files
Rail_Enterprise/client/ViaFerrea.Client/scripts/Panels/TrackPanel.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

125 lines
5.7 KiB
C#

using Godot;
using ViaFerrea.Client.App;
using ViaFerrea.Core.Data;
using ViaFerrea.Core.Rail;
using ViaFerrea.Protocol.Client;
using static ViaFerrea.Client.App.Localization;
namespace ViaFerrea.Client.Panels;
/// <summary>
/// Strumento binari: classe, ponti, gallerie, doppio binario, elettrificazione e quota; anteprima
/// del profilo con opere, costo e giorni (calcolata con Core come farà il server).
/// </summary>
public partial class TrackPanel : VBoxContainer
{
private readonly ClientWorld _world;
private readonly OptionButton _class = new();
private readonly CheckBox _bridges = new() { Text = T("Ponti"), ButtonPressed = true };
private readonly CheckBox _tunnels = new() { Text = T("Gallerie"), ButtonPressed = true };
private readonly CheckBox _double = new() { Text = T("Doppio binario") };
private readonly CheckBox _electric = new() { Text = T("Elettrificato") };
private readonly HSlider _height = new() { SizeFlagsHorizontal = SizeFlags.ExpandFill, Step = 0.5 };
private readonly Label _heightValue = PanelKit.Value("0 m");
private readonly ProfileChart _chart = new();
private readonly VBoxContainer _summary = PanelKit.Column(4);
private readonly Label _status = UiTheme.Text("", 13, Palette.TextSecondary);
public Button Build { get; } = UiTheme.Primary(T("Costruisci"));
public Button Cancel { get; } = new() { Text = T("Annulla") };
public event Action? OptionsChanged;
public TrackPanel(ClientWorld world)
{
_world = world;
AddThemeConstantOverride("separation", 10);
AddChild(UiTheme.TitleLabel(T("Binari"), 34));
AddChild(UiTheme.Text(T("Clic sulla mappa per i punti del tracciato (Maiusc: senza scatto a 45°), Invio per costruire, tasto destro per annullare."), 13, Palette.TextSecondary));
foreach (var cls in world.Data.Eras.TrackClasses)
{
_class.AddItem($"{cls.NameIt}", cls.Index);
_class.SetItemDisabled(_class.ItemCount - 1, cls.From > world.Year);
}
_class.Selected = 0;
AddChild(PanelKit.Pair(T("Classe"), new Label()));
AddChild(_class);
var flags = new GridContainer { Columns = 2 };
flags.AddChild(_bridges);
flags.AddChild(_tunnels);
flags.AddChild(_double);
flags.AddChild(_electric);
AddChild(flags);
double range = world.Data.Construction.Profile.HeightOffsetRangeM;
_height.MinValue = -range;
_height.MaxValue = range;
AddChild(PanelKit.Pair(T("Quota rispetto al terreno"), _heightValue));
AddChild(_height);
var buttons = PanelKit.Row();
Build.SizeFlagsHorizontal = SizeFlags.ExpandFill;
Cancel.SizeFlagsHorizontal = SizeFlags.ExpandFill;
buttons.AddChild(Build);
buttons.AddChild(Cancel);
AddChild(buttons);
_status.AutowrapMode = TextServer.AutowrapMode.WordSmart;
AddChild(_status);
AddChild(_chart);
AddChild(_summary);
_class.ItemSelected += _ => OptionsChanged?.Invoke();
foreach (var c in new[] { _bridges, _tunnels, _double, _electric }) c.Toggled += _ => OptionsChanged?.Invoke();
_height.ValueChanged += v =>
{
_heightValue.Text = $"{v:+0.0;-0.0;0} m";
OptionsChanged?.Invoke();
};
Show(null);
}
public string TrackClass => _world.Data.Eras.TrackClasses[Math.Max(0, _class.Selected)].Id;
public bool AllowBridges => _bridges.ButtonPressed;
public bool AllowTunnels => _tunnels.ButtonPressed;
public bool DoubleTrack => _double.ButtonPressed;
public bool Electrified => _electric.ButtonPressed;
public double HeightOffset => _height.Value;
public void SetStatus(string text, bool error = false)
{
_status.Text = text;
_status.AddThemeColorOverride("font_color", error ? Palette.Danger : Palette.TextSecondary);
}
public void Show(TrackPlan? plan)
{
_chart.Show(plan);
foreach (var child in _summary.GetChildren()) child.QueueFree();
Build.Disabled = plan is not { Valid: true };
if (plan is null)
{
_summary.AddChild(UiTheme.Text(T("Nessun tracciato"), 13, Palette.TextSecondary));
return;
}
_summary.AddChild(PanelKit.Pair(T("Lunghezza"), PanelKit.Value($"{plan.LengthM / 1000:0.00} km")));
_summary.AddChild(PanelKit.Pair(T("Pendenza massima"), PanelKit.Value($"{plan.MaxGradient * 100:0.0} % / {plan.GradientLimit * 100:0.0} %")));
_summary.AddChild(PanelKit.Pair(T("Raggio minimo"), PanelKit.Value(double.IsInfinity(plan.MinRadiusM) ? "—" : $"{plan.MinRadiusM:0} m")));
foreach (var kind in new[] { WorkKind.Embankment, WorkKind.Cutting, WorkKind.Bridge, WorkKind.Tunnel })
{
double len = plan.LengthOf(kind);
if (len <= 0) continue;
string name = kind switch
{
WorkKind.Embankment => T("Rilevato"),
WorkKind.Cutting => T("Trincea"),
WorkKind.Bridge => T("Ponte") + (plan.BridgeType is { } b ? $" ({b})" : ""),
_ => T("Galleria"),
};
_summary.AddChild(PanelKit.Pair(name, PanelKit.Value($"{len:0} m")));
}
var cost = PanelKit.Value(plan.TotalCost.ToString());
cost.AddThemeColorOverride("font_color", Palette.AmberLight);
_summary.AddChild(PanelKit.Pair(T("Costo"), cost));
_summary.AddChild(PanelKit.Pair(T("Cantiere"), PanelKit.Value($"{plan.Days} {T("giorni")}")));
foreach (var e in plan.Errors.Take(3)) _summary.AddChild(UiTheme.Notice(e.Message));
foreach (var e in plan.Warnings.Take(2)) _summary.AddChild(UiTheme.Text(e.Message, 12, Palette.AmberLight));
}
}