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,104 @@
|
||||
using Godot;
|
||||
using ViaFerrea.Client.App;
|
||||
using ViaFerrea.Client.Map;
|
||||
using ViaFerrea.Core.Map;
|
||||
using ViaFerrea.Protocol.Client;
|
||||
|
||||
namespace ViaFerrea.Client.Hud;
|
||||
|
||||
/// <summary>Minimappa: terreno ridotto, linee, città e rettangolo della vista; un clic centra la mappa.</summary>
|
||||
public partial class Minimap : Control
|
||||
{
|
||||
private ClientWorld? _world;
|
||||
private MapView? _map;
|
||||
private ImageTexture? _texture;
|
||||
private int _terrainVersion = -1;
|
||||
|
||||
public void Bind(ClientWorld world, MapView map)
|
||||
{
|
||||
_world = world;
|
||||
_map = map;
|
||||
_terrainVersion = -1;
|
||||
CustomMinimumSize = new Vector2(0, 220);
|
||||
MouseFilter = MouseFilterEnum.Stop;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_world?.Terrain is { } t && _world.TerrainVersion != _terrainVersion && Engine.GetProcessFrames() % 30 == 0)
|
||||
{
|
||||
_terrainVersion = _world.TerrainVersion;
|
||||
int step = Math.Max(1, t.Width / 256);
|
||||
int w = t.Width / step, h = t.Height / step;
|
||||
var data = new byte[w * h * 4];
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
var type = (CellType)t.Types[y * step * t.Width + x * step];
|
||||
var c = type switch
|
||||
{
|
||||
CellType.Sea => Palette.Sea,
|
||||
CellType.Water => Palette.Water,
|
||||
CellType.Forest => Palette.Undergrowth,
|
||||
CellType.Town => Palette.TileRoof.Lightened(0.3f),
|
||||
CellType.Mountain or CellType.Rock => Palette.Highland,
|
||||
CellType.Hill => Palette.Hill,
|
||||
_ => Palette.Plain,
|
||||
};
|
||||
int i = (y * w + x) * 4;
|
||||
data[i] = (byte)(c.R * 255);
|
||||
data[i + 1] = (byte)(c.G * 255);
|
||||
data[i + 2] = (byte)(c.B * 255);
|
||||
data[i + 3] = 255;
|
||||
}
|
||||
}
|
||||
_texture = ImageTexture.CreateFromImage(Image.CreateFromData(w, h, false, Image.Format.Rgba8, data));
|
||||
}
|
||||
QueueRedraw();
|
||||
}
|
||||
|
||||
private Rect2 MapRect()
|
||||
{
|
||||
var t = _world!.Terrain!;
|
||||
float aspect = (float)t.Width / t.Height;
|
||||
float w = Size.X, h = Size.X / aspect;
|
||||
if (h > Size.Y)
|
||||
{
|
||||
h = Size.Y;
|
||||
w = h * aspect;
|
||||
}
|
||||
return new Rect2((Size.X - w) / 2, (Size.Y - h) / 2, w, h);
|
||||
}
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
DrawStyleBox(UiTheme.Box(Palette.Inner, Palette.Border, 8, 0), new Rect2(Vector2.Zero, Size));
|
||||
if (_world?.Terrain is not { } t || _texture is null || _map is null) return;
|
||||
var r = MapRect();
|
||||
DrawTextureRect(_texture, r, false);
|
||||
float k = r.Size.X / (float)(t.Width * t.CellSizeM);
|
||||
Vector2 P(Vector2 world) => r.Position + world * k;
|
||||
foreach (var e in _world.Edges.Values)
|
||||
{
|
||||
if (e.S.Length < 2) continue;
|
||||
DrawLine(P(MapScale.V(e.X[0], e.Y[0])), P(MapScale.V(e.X[^1], e.Y[^1])), new Color("2a2f2c"), 2);
|
||||
}
|
||||
foreach (var town in _world.Towns.Values) DrawCircle(P(MapScale.V(town.Position)), 3.5f, new Color("8a6a55"));
|
||||
var view = _map.VisibleRect();
|
||||
DrawRect(new Rect2(P(view.Position), view.Size * k), Palette.Amber, false, 2);
|
||||
}
|
||||
|
||||
public override void _GuiInput(InputEvent e)
|
||||
{
|
||||
if (_world?.Terrain is not { } t || _map is null) return;
|
||||
if (e is InputEventMouseButton { ButtonIndex: MouseButton.Left, Pressed: true } b || e is InputEventMouseMotion { ButtonMask: MouseButtonMask.Left })
|
||||
{
|
||||
var pos = e is InputEventMouse m ? m.Position : Vector2.Zero;
|
||||
var r = MapRect();
|
||||
float k = r.Size.X / (float)(t.Width * t.CellSizeM);
|
||||
_map.CenterOn((pos - r.Position) / k);
|
||||
AcceptEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://ci04fqk4we7bk
|
||||
@@ -0,0 +1,42 @@
|
||||
using Godot;
|
||||
using ViaFerrea.Client.App;
|
||||
using ViaFerrea.Protocol.Messages;
|
||||
using static ViaFerrea.Client.App.Localization;
|
||||
|
||||
namespace ViaFerrea.Client.Hud;
|
||||
|
||||
/// <summary>Notiziario in basso (immagine 01): «Notizie» e gli ultimi eventi che scorrono.</summary>
|
||||
public partial class Ticker : PanelContainer
|
||||
{
|
||||
private readonly List<string> _items = [];
|
||||
private readonly Label _text = UiTheme.Text("", 14);
|
||||
private readonly Control _clip = new() { ClipContents = true, SizeFlagsHorizontal = SizeFlags.ExpandFill, CustomMinimumSize = new Vector2(0, 22) };
|
||||
private float _offset;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
AddThemeStyleboxOverride("panel", UiTheme.Box(Palette.Panel, Palette.Border, 0, 14));
|
||||
var row = new HBoxContainer();
|
||||
row.AddThemeConstantOverride("separation", 18);
|
||||
AddChild(row);
|
||||
row.AddChild(UiTheme.Text(T("Notizie"), 14, Palette.Amber, bold: true));
|
||||
row.AddChild(_clip);
|
||||
_clip.AddChild(_text);
|
||||
}
|
||||
|
||||
public void Add(EventInfo e)
|
||||
{
|
||||
_items.Insert(0, e.Text);
|
||||
if (_items.Count > 8) _items.RemoveAt(_items.Count - 1);
|
||||
_text.Text = string.Join(" | ", _items);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_items.Count == 0) return;
|
||||
_offset += (float)delta * 40f;
|
||||
float width = _text.GetMinimumSize().X;
|
||||
if (_offset > width) _offset = -_clip.Size.X;
|
||||
_text.Position = new Vector2(-_offset, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://c57cbfp1dm0qo
|
||||
@@ -0,0 +1,139 @@
|
||||
using Godot;
|
||||
using ViaFerrea.Client.App;
|
||||
using static ViaFerrea.Client.App.Localization;
|
||||
|
||||
namespace ViaFerrea.Client.Hud;
|
||||
|
||||
/// <summary>Strumenti e pannelli della barra sinistra (immagine 01).</summary>
|
||||
public enum Tool { None, Track, Station, Signal, Depot, Trains, Lines, Market, Finance, Demolish }
|
||||
|
||||
/// <summary>Barra degli strumenti a sinistra: icone disegnate in codice con l'etichetta sotto.</summary>
|
||||
public partial class Toolbar : PanelContainer
|
||||
{
|
||||
private readonly Dictionary<Tool, ToolButton> _buttons = [];
|
||||
|
||||
public event Action<Tool>? Selected;
|
||||
|
||||
public Tool Current { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
AddThemeStyleboxOverride("panel", UiTheme.Box(Palette.Panel, Palette.Border, 0, 6));
|
||||
CustomMinimumSize = new Vector2(88, 0);
|
||||
var col = new VBoxContainer();
|
||||
col.AddThemeConstantOverride("separation", 6);
|
||||
AddChild(col);
|
||||
foreach (var (tool, label) in new[]
|
||||
{
|
||||
(Tool.Track, "Binari"), (Tool.Station, "Stazione"), (Tool.Signal, "Segnali"), (Tool.Depot, "Deposito"),
|
||||
(Tool.Trains, "Treni"), (Tool.Lines, "Linee"), (Tool.Market, "Mercato"), (Tool.Finance, "Finanze"), (Tool.Demolish, "Demolisci"),
|
||||
})
|
||||
{
|
||||
var b = new ToolButton(tool, T(label));
|
||||
b.Pressed += () => Select(Current == tool ? Tool.None : tool);
|
||||
_buttons[tool] = b;
|
||||
col.AddChild(b);
|
||||
}
|
||||
}
|
||||
|
||||
public void Select(Tool tool)
|
||||
{
|
||||
Current = tool;
|
||||
foreach (var (t, b) in _buttons) b.Active = t == tool;
|
||||
Selected?.Invoke(tool);
|
||||
}
|
||||
|
||||
/// <summary>Pulsante con icona vettoriale.</summary>
|
||||
private sealed partial class ToolButton : Button
|
||||
{
|
||||
private readonly Tool _tool;
|
||||
private readonly string _label;
|
||||
private bool _active;
|
||||
|
||||
public ToolButton(Tool tool, string label)
|
||||
{
|
||||
_tool = tool;
|
||||
_label = label;
|
||||
CustomMinimumSize = new Vector2(76, 72);
|
||||
Flat = true;
|
||||
TooltipText = label;
|
||||
MouseEntered += QueueRedraw;
|
||||
MouseExited += QueueRedraw;
|
||||
}
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get => _active;
|
||||
set
|
||||
{
|
||||
_active = value;
|
||||
QueueRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
if (_active) DrawStyleBox(UiTheme.Box(Palette.Inner, Palette.Inner, 8, 0), new Rect2(Vector2.Zero, Size));
|
||||
else if (IsHovered()) DrawStyleBox(UiTheme.Box(Palette.Inner, Palette.Border, 8, 0), new Rect2(Vector2.Zero, Size));
|
||||
var color = _active ? Palette.Amber : Palette.Text;
|
||||
var c = new Vector2(Size.X / 2, 26);
|
||||
DrawGlyph(c, color);
|
||||
var font = _active ? UiTheme.BodyBold : UiTheme.Body;
|
||||
var dims = font.GetStringSize(_label, HorizontalAlignment.Left, -1, 13);
|
||||
DrawString(font, new Vector2((Size.X - dims.X) / 2, 60), _label, HorizontalAlignment.Left, -1, 13, color);
|
||||
}
|
||||
|
||||
private void DrawGlyph(Vector2 c, Color col)
|
||||
{
|
||||
const float w = 2.2f;
|
||||
switch (_tool)
|
||||
{
|
||||
case Tool.Track:
|
||||
DrawLine(c + new Vector2(-5, -11), c + new Vector2(-5, 11), col, w);
|
||||
DrawLine(c + new Vector2(5, -11), c + new Vector2(5, 11), col, w);
|
||||
for (int i = -1; i <= 1; i++) DrawLine(c + new Vector2(-10, i * 7), c + new Vector2(10, i * 7), col, w);
|
||||
break;
|
||||
case Tool.Station:
|
||||
DrawPolyline([c + new Vector2(-11, -1), c + new Vector2(0, -11), c + new Vector2(11, -1)], col, w);
|
||||
DrawRect(new Rect2(c + new Vector2(-8, -1), new Vector2(16, 12)), col, false, w);
|
||||
DrawRect(new Rect2(c + new Vector2(-2, 4), new Vector2(4, 7)), col, false, w);
|
||||
break;
|
||||
case Tool.Signal:
|
||||
DrawCircle(c + new Vector2(0, -6), 5, col, false, w);
|
||||
DrawLine(c + new Vector2(0, -1), c + new Vector2(0, 11), col, w);
|
||||
DrawLine(c + new Vector2(-5, 11), c + new Vector2(5, 11), col, w);
|
||||
break;
|
||||
case Tool.Depot:
|
||||
DrawPolyline([c + new Vector2(-11, 11), c + new Vector2(-11, -3), c + new Vector2(0, -11), c + new Vector2(11, -3), c + new Vector2(11, 11)], col, w);
|
||||
DrawRect(new Rect2(c + new Vector2(-6, 1), new Vector2(12, 10)), col, false, w);
|
||||
break;
|
||||
case Tool.Trains:
|
||||
DrawRect(new Rect2(c + new Vector2(-8, -11), new Vector2(16, 17)), col, false, w);
|
||||
DrawLine(c + new Vector2(-8, -2), c + new Vector2(8, -2), col, w);
|
||||
DrawLine(c + new Vector2(-5, 6), c + new Vector2(-8, 12), col, w);
|
||||
DrawLine(c + new Vector2(5, 6), c + new Vector2(8, 12), col, w);
|
||||
break;
|
||||
case Tool.Lines:
|
||||
DrawCircle(c + new Vector2(-8, -8), 3.5f, col, false, w);
|
||||
DrawCircle(c + new Vector2(8, 8), 3.5f, col, false, w);
|
||||
DrawPolyline([c + new Vector2(-4, -8), c + new Vector2(8, -8), c + new Vector2(8, -2), c + new Vector2(-8, 2), c + new Vector2(-8, 8), c + new Vector2(4, 8)], col, w);
|
||||
break;
|
||||
case Tool.Market:
|
||||
DrawPolyline([c + new Vector2(-11, 8), c + new Vector2(-4, 0), c + new Vector2(2, 5), c + new Vector2(11, -7)], col, w);
|
||||
DrawLine(c + new Vector2(-11, 11), c + new Vector2(11, 11), col, w);
|
||||
break;
|
||||
case Tool.Finance:
|
||||
DrawArc(c + new Vector2(0, -7), 9, 0, MathF.Tau, 24, col, w);
|
||||
DrawLine(c + new Vector2(-9, -7), c + new Vector2(-9, 7), col, w);
|
||||
DrawLine(c + new Vector2(9, -7), c + new Vector2(9, 7), col, w);
|
||||
DrawArc(c + new Vector2(0, 7), 9, 0, MathF.PI, 16, col, w);
|
||||
break;
|
||||
case Tool.Demolish:
|
||||
DrawLine(c + new Vector2(-10, -8), c + new Vector2(10, -8), col, w);
|
||||
DrawLine(c + new Vector2(-4, -11), c + new Vector2(4, -11), col, w);
|
||||
DrawPolyline([c + new Vector2(-7, -8), c + new Vector2(-5, 11), c + new Vector2(5, 11), c + new Vector2(7, -8)], col, w);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bngg3p5mnbnru
|
||||
@@ -0,0 +1,111 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dgi7tae6dnp32
|
||||
Reference in new issue
Block a user