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
This commit is contained in:
97 files changed
+5151
-96
No files matched your search
@@ -0,0 +1,195 @@
|
||||
using Godot;
|
||||
using ViaFerrea.Client.App;
|
||||
using ViaFerrea.Client.Net;
|
||||
using ViaFerrea.Core.Commands;
|
||||
using ViaFerrea.Core.Common;
|
||||
using ViaFerrea.Core.Data;
|
||||
using ViaFerrea.Core.Rail;
|
||||
using ViaFerrea.Protocol.Messages;
|
||||
using static ViaFerrea.Client.App.Localization;
|
||||
|
||||
namespace ViaFerrea.Client.Panels;
|
||||
|
||||
/// <summary>
|
||||
/// Treni: acquisto dei veicoli in un deposito, composizione, assegnazione alle linee, rientro.
|
||||
/// Ogni azione è un comando; la lista si aggiorna con i delta del server.
|
||||
/// </summary>
|
||||
public partial class TrainsPanel : VBoxContainer
|
||||
{
|
||||
private readonly GameSession _session;
|
||||
private readonly OptionButton _depot = new();
|
||||
private readonly OptionButton _vehicle = new();
|
||||
private readonly SpinBox _count = new() { MinValue = 1, MaxValue = 12, Value = 1 };
|
||||
private readonly ItemList _inDepot = new() { SelectMode = ItemList.SelectModeEnum.Multi, CustomMinimumSize = new Vector2(0, 120) };
|
||||
private readonly LineEdit _name = new() { PlaceholderText = T("Nome del treno") };
|
||||
private readonly ItemList _trains = new() { CustomMinimumSize = new Vector2(0, 140) };
|
||||
private readonly OptionButton _line = new();
|
||||
private readonly Label _status = UiTheme.Text("", 13, Palette.TextSecondary);
|
||||
private readonly List<int> _depotIds = [];
|
||||
private readonly List<VehicleDef> _catalog = [];
|
||||
private readonly List<int> _vehicleIds = [];
|
||||
private readonly List<int> _trainIds = [];
|
||||
private readonly List<int> _lineIds = [];
|
||||
private int _version = -1;
|
||||
|
||||
public event Action<int>? TrainSelected;
|
||||
|
||||
public TrainsPanel(GameSession session)
|
||||
{
|
||||
_session = session;
|
||||
AddThemeConstantOverride("separation", 8);
|
||||
AddChild(UiTheme.TitleLabel(T("Treni"), 34));
|
||||
AddChild(PanelKit.Pair(T("Deposito"), new Label()));
|
||||
AddChild(_depot);
|
||||
var buy = PanelKit.Row();
|
||||
_vehicle.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||||
buy.AddChild(_vehicle);
|
||||
buy.AddChild(_count);
|
||||
AddChild(buy);
|
||||
var buyButton = UiTheme.Primary(T("Compra veicoli"));
|
||||
buyButton.Pressed += Buy;
|
||||
AddChild(buyButton);
|
||||
AddChild(UiTheme.Text(T("Veicoli liberi nel deposito (selezione multipla, in ordine)"), 13, Palette.TextSecondary));
|
||||
AddChild(_inDepot);
|
||||
var compose = PanelKit.Row();
|
||||
_name.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||||
compose.AddChild(_name);
|
||||
var composeButton = new Button { Text = T("Componi") };
|
||||
composeButton.Pressed += Compose;
|
||||
compose.AddChild(composeButton);
|
||||
AddChild(compose);
|
||||
AddChild(PanelKit.Separator());
|
||||
AddChild(UiTheme.Text(T("Treni della compagnia"), 14, bold: true));
|
||||
AddChild(_trains);
|
||||
var assign = PanelKit.Row();
|
||||
_line.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||||
assign.AddChild(_line);
|
||||
var assignButton = new Button { Text = T("Assegna") };
|
||||
assignButton.Pressed += Assign;
|
||||
assign.AddChild(assignButton);
|
||||
AddChild(assign);
|
||||
var home = new Button { Text = T("Manda al deposito") };
|
||||
home.Pressed += SendHome;
|
||||
AddChild(home);
|
||||
_status.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
AddChild(_status);
|
||||
_depot.ItemSelected += _ => Refresh(force: true);
|
||||
_trains.ItemSelected += i => TrainSelected?.Invoke(_trainIds[(int)i]);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_session.World.EntityVersion != _version) Refresh(force: false);
|
||||
}
|
||||
|
||||
private int Company => _session.World.Summary?.CompanyId ?? 0;
|
||||
|
||||
private void Refresh(bool force)
|
||||
{
|
||||
var w = _session.World;
|
||||
_version = w.EntityVersion;
|
||||
int selectedDepot = _depot.Selected >= 0 && _depot.Selected < _depotIds.Count ? _depotIds[_depot.Selected] : -1;
|
||||
_depotIds.Clear();
|
||||
_depot.Clear();
|
||||
foreach (var d in w.Depots.Values.Where(d => d.Owner == Company).OrderBy(d => d.Id))
|
||||
{
|
||||
_depotIds.Add(d.Id);
|
||||
_depot.AddItem(d.Name);
|
||||
}
|
||||
int di = _depotIds.IndexOf(selectedDepot);
|
||||
_depot.Selected = di >= 0 ? di : _depotIds.Count > 0 ? 0 : -1;
|
||||
|
||||
if (_catalog.Count == 0 || force)
|
||||
{
|
||||
int keep = _vehicle.Selected;
|
||||
_catalog.Clear();
|
||||
_vehicle.Clear();
|
||||
foreach (var def in w.Data.Vehicles.Where(v => v.EraFrom <= w.Year && (v.EraTo is null || v.EraTo >= w.Year)))
|
||||
{
|
||||
_catalog.Add(def);
|
||||
_vehicle.AddItem($"{def.NameIt} — {new Money(def.Price)}");
|
||||
}
|
||||
_vehicle.Selected = keep >= 0 && keep < _catalog.Count ? keep : 0;
|
||||
}
|
||||
|
||||
int depot = _depot.Selected >= 0 ? _depotIds[_depot.Selected] : -1;
|
||||
_vehicleIds.Clear();
|
||||
_inDepot.Clear();
|
||||
foreach (var v in w.Vehicles.Values.Where(v => v.Owner == Company && v.Depot == depot && v.Train < 0).OrderBy(v => v.Id))
|
||||
{
|
||||
_vehicleIds.Add(v.Id);
|
||||
var def = w.Data.Vehicles.FirstOrDefault(d => d.Id == v.Type);
|
||||
_inDepot.AddItem($"{def?.NameIt ?? v.Type} #{v.Id}");
|
||||
}
|
||||
|
||||
var selectedTrain = _trains.GetSelectedItems() is { Length: > 0 } sel ? _trainIds[sel[0]] : -1;
|
||||
_trainIds.Clear();
|
||||
_trains.Clear();
|
||||
foreach (var t in w.Trains.Values.Where(t => t.Owner == Company).OrderBy(t => t.Id))
|
||||
{
|
||||
_trainIds.Add(t.Id);
|
||||
string line = t.Line >= 0 && w.Lines.TryGetValue(t.Line, out var l) ? l.Name : T("senza linea");
|
||||
_trains.AddItem($"{t.Name} · {StateName((TrainState)t.State)} · {line}");
|
||||
}
|
||||
int ti = _trainIds.IndexOf(selectedTrain);
|
||||
if (ti >= 0) _trains.Select(ti);
|
||||
|
||||
int selectedLine = _line.Selected >= 0 && _line.Selected < _lineIds.Count ? _lineIds[_line.Selected] : -1;
|
||||
_lineIds.Clear();
|
||||
_line.Clear();
|
||||
_lineIds.Add(-1);
|
||||
_line.AddItem(T("Nessuna linea"));
|
||||
foreach (var l in w.Lines.Values.Where(l => l.Owner == Company).OrderBy(l => l.Id))
|
||||
{
|
||||
_lineIds.Add(l.Id);
|
||||
_line.AddItem(l.Name);
|
||||
}
|
||||
int li = _lineIds.IndexOf(selectedLine);
|
||||
_line.Selected = li >= 0 ? li : Math.Min(1, _lineIds.Count - 1);
|
||||
}
|
||||
|
||||
public static string StateName(TrainState s) => s switch
|
||||
{
|
||||
TrainState.InDepot => T("in deposito"),
|
||||
TrainState.Moving => T("in marcia"),
|
||||
TrainState.Waiting => T("in attesa di via libera"),
|
||||
TrainState.Loading => T("in stazione"),
|
||||
TrainState.Stalled => T("fermo in salita"),
|
||||
TrainState.Broken => T("guasto"),
|
||||
TrainState.NoRoute => T("senza percorso"),
|
||||
_ => s.ToString(),
|
||||
};
|
||||
|
||||
private void Result(CommandResultMessage r) => _status.Text = r.Message;
|
||||
|
||||
private void Buy()
|
||||
{
|
||||
if (_depot.Selected < 0 || _vehicle.Selected < 0) { _status.Text = T("Serve un deposito"); return; }
|
||||
_session.Command(new BuyVehicleCommand(_catalog[_vehicle.Selected].Id, new DepotId(_depotIds[_depot.Selected]), (int)_count.Value), Result);
|
||||
}
|
||||
|
||||
private void Compose()
|
||||
{
|
||||
if (_depot.Selected < 0) return;
|
||||
var selected = _inDepot.GetSelectedItems().OrderBy(i => i).Select(i => new VehicleId(_vehicleIds[i])).ToList();
|
||||
if (selected.Count == 0) { _status.Text = T("Seleziona i veicoli da comporre"); return; }
|
||||
string? name = string.IsNullOrWhiteSpace(_name.Text) ? null : _name.Text.Trim();
|
||||
_session.Command(new ComposeTrainCommand(new DepotId(_depotIds[_depot.Selected]), selected, name), Result);
|
||||
}
|
||||
|
||||
private int SelectedTrain => _trains.GetSelectedItems() is { Length: > 0 } sel ? _trainIds[sel[0]] : -1;
|
||||
|
||||
private void Assign()
|
||||
{
|
||||
int train = SelectedTrain;
|
||||
if (train < 0 || _line.Selected < 0) { _status.Text = T("Seleziona un treno"); return; }
|
||||
_session.Command(new AssignTrainCommand(new TrainId(train), new LineId(_lineIds[_line.Selected])), Result);
|
||||
}
|
||||
|
||||
private void SendHome()
|
||||
{
|
||||
int train = SelectedTrain;
|
||||
if (train < 0 || _depot.Selected < 0) { _status.Text = T("Seleziona un treno e un deposito"); return; }
|
||||
_session.Command(new SendToDepotCommand(new TrainId(train), new DepotId(_depotIds[_depot.Selected])), Result);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user