Il progetto adotta il nome «Rail Enterprise» ovunque (codice RailEnterprise.*, variabili RE_*, intestazioni RESV/RECL, immagine rail-enterprise-server) per allinearsi al repository Gitea. Aggiunge Gitea Actions sul modello di Chronos: CI su PR e main, rilascio da tag con gioco Windows (client Godot + server in server/), server Windows/Linux e immagine Docker nel registro Gitea, nightly. Aggiunge i riferimenti visivi 06–09, i modelli di PR e issue, l'ADR 0014 e aggiorna README (comandi locali), STATE e CLAUDE.md. 120 test verdi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
5.8 KiB
C#
127 lines
5.8 KiB
C#
using Godot;
|
|
using RailEnterprise.Client.App;
|
|
using RailEnterprise.Core.Data;
|
|
using RailEnterprise.Core.Rail;
|
|
using RailEnterprise.Protocol.Client;
|
|
using static RailEnterprise.Client.App.Localization;
|
|
|
|
namespace RailEnterprise.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));
|
|
var help = 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);
|
|
help.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
|
AddChild(help);
|
|
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));
|
|
}
|
|
}
|