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

152 lines
7.7 KiB
C#

using Godot;
using ViaFerrea.Client.App;
using ViaFerrea.Client.Net;
using ViaFerrea.Core.Common;
using ViaFerrea.Core.Rail;
using static ViaFerrea.Client.App.Localization;
namespace ViaFerrea.Client.Panels;
/// <summary>Scheda dell'entità selezionata (treno, stazione, industria, città) come nel pannello destro dell'immagine 01.</summary>
public partial class InfoPanel : VBoxContainer
{
public enum Kind { None, Train, Station, Industry, Town }
private readonly GameSession _session;
private Kind _kind;
private int _id = -1;
private double _refresh;
public InfoPanel(GameSession session)
{
_session = session;
AddThemeConstantOverride("separation", 10);
Select(Kind.None, -1);
}
public void Select(Kind kind, int id)
{
_kind = kind;
_id = id;
Rebuild();
}
public override void _Process(double delta)
{
_refresh += delta;
if (_refresh < 0.5) return;
_refresh = 0;
Rebuild();
}
private void Rebuild()
{
foreach (var c in GetChildren()) c.QueueFree();
var w = _session.World;
switch (_kind)
{
case Kind.Train when w.Trains.TryGetValue(_id, out var t):
{
var head = PanelKit.Row();
var title = UiTheme.TitleLabel(t.Name, 38);
title.SizeFlagsHorizontal = SizeFlags.ExpandFill;
head.AddChild(title);
if (t.Line >= 0 && w.Lines.TryGetValue(t.Line, out var line))
{
var badge = new CenterContainer();
var b = UiTheme.LineBadge(line.Name);
badge.AddChild(b);
head.AddChild(badge);
AddChild(head);
string route = string.Join(" → ", line.Stops.Select(s => w.Stations.TryGetValue(s.Station.Value, out var st) ? st.Name : "?"));
AddChild(UiTheme.Text(route, 17, bold: true));
}
else
{
AddChild(head);
}
var loco = t.Vehicles.Select(v => w.Vehicles.GetValueOrDefault(v)).FirstOrDefault(v => v is not null && w.Data.Vehicles.Any(d => d.Id == v.Type && d.Kind == Core.Data.VehicleKind.Locomotive));
var locoDef = loco is null ? null : w.Data.Vehicles.First(d => d.Id == loco.Type);
AddChild(UiTheme.Text($"{T("Locomotiva")} {locoDef?.NameIt ?? "—"} · {TrainsPanel.StateName((TrainState)t.State)}", 14, Palette.TextSecondary));
var stats = PanelKit.Row();
double speed = w.Motions.TryGetValue(t.Id, out var m) ? m.Speed * 3.6 : 0;
double condition = w.Motions.TryGetValue(t.Id, out var m2) ? m2.Condition : t.Vehicles.Select(v => w.Vehicles.GetValueOrDefault(v)?.Condition ?? 100).DefaultIfEmpty(100).Min();
stats.AddChild(PanelKit.Stat(T("Velocità"), PanelKit.Value($"{speed:0} km/h")));
stats.AddChild(PanelKit.Stat(T("Condizione"), PanelKit.Value($"{condition:0}%")));
stats.AddChild(PanelKit.Stat(T("Veicoli"), PanelKit.Value($"{t.Vehicles.Length}")));
AddChild(stats);
AddChild(PanelKit.Pair(T("Carico"), PanelKit.Value($"{t.Load} / {t.Capacity}")));
var bar = new ProgressBar { MaxValue = Math.Max(1, t.Capacity), Value = t.Load, ShowPercentage = false, CustomMinimumSize = new Vector2(0, 10) };
bar.AddThemeStyleboxOverride("fill", UiTheme.Box(Palette.Amber, Palette.Amber, 4, 0));
AddChild(bar);
if (t.Line >= 0 && w.Lines.TryGetValue(t.Line, out var l2))
{
for (int i = 0; i < l2.Stops.Length; i++)
{
var s = l2.Stops[i];
string name = w.Stations.TryGetValue(s.Station.Value, out var st) ? st.Name : "?";
string orders = (s.Load ? T("carica") : "") + (s.Unload ? (s.Load ? ", " : "") + T("scarica") : "")
+ (s.WaitFull ? $", {T("attendi il pieno")} (max {s.MaxWaitDays} {T("giorni")})" : "");
var row = PanelKit.Row();
row.AddChild(UiTheme.Text($"{i + 1}", 14, Palette.TextSecondary, bold: true));
var col = PanelKit.Column(0);
col.AddChild(UiTheme.Text(name, 15, bold: true));
col.AddChild(UiTheme.Text(orders, 13, Palette.TextSecondary));
row.AddChild(col);
AddChild(row);
}
}
break;
}
case Kind.Station when w.Stations.TryGetValue(_id, out var s):
{
AddChild(UiTheme.TitleLabel(s.Name, 38));
AddChild(PanelKit.Pair(T("Binari di stazione"), PanelKit.Value($"{s.Platforms}")));
AddChild(PanelKit.Pair(T("Merci e passeggeri in attesa"), PanelKit.Value($"{s.WaitingUnits}")));
AddChild(UiTheme.Text(T("Nel bacino"), 14, bold: true));
foreach (int i in s.Industries)
if (w.Industries.TryGetValue(i, out var ind)) AddChild(UiTheme.Text($"• {ind.Name}", 13));
foreach (int i in s.Towns)
if (w.Towns.TryGetValue(i, out var town)) AddChild(UiTheme.Text($"• {town.Name}", 13));
break;
}
case Kind.Industry when w.Industries.TryGetValue(_id, out var ind):
{
AddChild(UiTheme.TitleLabel(ind.Name, 38));
var def = w.Data.Industries.FirstOrDefault(d => d.Id == ind.Type);
AddChild(UiTheme.Text(def?.NameIt ?? ind.Type, 14, Palette.TextSecondary));
var stats = PanelKit.Row();
stats.AddChild(PanelKit.Stat(T("Livello"), PanelKit.Value($"{ind.Level}")));
stats.AddChild(PanelKit.Stat(T("Efficienza"), PanelKit.Value($"{ind.Efficiency * 100:0}%")));
stats.AddChild(PanelKit.Stat(T("Impianti"), PanelKit.Value($"{ind.Condition:0}%")));
AddChild(stats);
if (def is not null)
{
string inputs = string.Join(", ", def.Recipe.Inputs.Select(i => w.Data.Goods.First(g => g.Id == i.Good).NameIt));
string outputs = string.Join(", ", def.Recipe.Outputs.Select(o => w.Data.Goods.First(g => g.Id == o.Good).NameIt));
if (inputs.Length > 0) AddChild(PanelKit.Pair(T("Consuma"), PanelKit.Value(inputs)));
AddChild(PanelKit.Pair(T("Produce"), PanelKit.Value(outputs)));
}
if (ind.Closed) AddChild(UiTheme.Notice(T("Chiusa")));
break;
}
case Kind.Town when w.Towns.TryGetValue(_id, out var town):
{
AddChild(UiTheme.TitleLabel(town.Name, 38));
AddChild(PanelKit.Pair(T("Abitanti"), PanelKit.Value(Money.GroupThousands((ulong)town.Population))));
AddChild(PanelKit.Pair(T("Soddisfazione"), PanelKit.Value($"{town.Satisfaction * 100:0}%")));
AddChild(PanelKit.Pair(T("Servizi"), PanelKit.Value($"{town.Services}")));
break;
}
default:
{
AddChild(UiTheme.TitleLabel(T("Via Ferrea"), 38));
var help = UiTheme.Text(T("Scegli uno strumento a sinistra oppure fai clic su un treno, una stazione, un'industria o una città per vederne la scheda."), 14, Palette.TextSecondary);
help.AutowrapMode = TextServer.AutowrapMode.WordSmart;
AddChild(help);
break;
}
}
}
}