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>
177 lines
8.7 KiB
C#
177 lines
8.7 KiB
C#
using Godot;
|
|
using RailEnterprise.Client.App;
|
|
using static RailEnterprise.Client.App.Localization;
|
|
|
|
namespace RailEnterprise.Client.Hud;
|
|
|
|
/// <summary>Strumenti e pannelli della barra sinistra (immagine 01).</summary>
|
|
public enum Tool { None, Track, Station, Signal, Depot, Trains, Lines, Maintenance, Employment, Industries, Market, Companies, Finance, Demolish }
|
|
|
|
/// <summary>
|
|
/// Barra degli strumenti a sinistra: icone disegnate in codice con l'etichetta sotto. I pulsanti
|
|
/// sono compatti e la colonna scorre con la rotella se la finestra è più bassa della barra.
|
|
/// </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 scroll = new ScrollContainer
|
|
{
|
|
HorizontalScrollMode = ScrollContainer.ScrollMode.Disabled,
|
|
VerticalScrollMode = ScrollContainer.ScrollMode.ShowNever,
|
|
SizeFlagsVertical = SizeFlags.ExpandFill,
|
|
};
|
|
AddChild(scroll);
|
|
var col = new VBoxContainer();
|
|
col.AddThemeConstantOverride("separation", 4);
|
|
scroll.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.Maintenance, "Officine"), (Tool.Employment, "Impieghi"),
|
|
(Tool.Industries, "Industrie"), (Tool.Market, "Mercato"), (Tool.Companies, "Compagnie"), (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, 56);
|
|
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, 20);
|
|
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, 48), _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.Maintenance:
|
|
// chiave inglese
|
|
DrawArc(c + new Vector2(6, -6), 6, MathF.PI * 0.25f, MathF.PI * 1.75f, 16, col, w);
|
|
DrawLine(c + new Vector2(2, -2), c + new Vector2(-10, 10), col, w * 1.6f);
|
|
break;
|
|
case Tool.Employment:
|
|
// due persone
|
|
DrawCircle(c + new Vector2(-6, -6), 3.5f, col, false, w);
|
|
DrawCircle(c + new Vector2(6, -6), 3.5f, col, false, w);
|
|
DrawArc(c + new Vector2(-6, 9), 7, MathF.PI, MathF.Tau, 12, col, w);
|
|
DrawArc(c + new Vector2(6, 9), 7, MathF.PI, MathF.Tau, 12, col, w);
|
|
break;
|
|
case Tool.Industries:
|
|
// fabbrica: tetto a shed e ciminiera
|
|
DrawPolyline([c + new Vector2(-11, 10), c + new Vector2(-11, -2), c + new Vector2(-5, -7), c + new Vector2(-5, -2),
|
|
c + new Vector2(1, -7), c + new Vector2(1, -2), c + new Vector2(7, -7), c + new Vector2(7, 10), c + new Vector2(-11, 10)], col, w);
|
|
DrawLine(c + new Vector2(10, 10), c + new Vector2(10, -11), col, w);
|
|
DrawLine(c + new Vector2(7, -11), c + new Vector2(10, -11), col, w);
|
|
break;
|
|
case Tool.Companies:
|
|
// palazzo della borsa: frontone, colonne e basamento
|
|
DrawPolyline([c + new Vector2(-11, -5), c + new Vector2(0, -11), c + new Vector2(11, -5), c + new Vector2(-11, -5)], col, w);
|
|
for (int i = -1; i <= 1; i++) DrawLine(c + new Vector2(i * 7, -3), c + new Vector2(i * 7, 7), col, w);
|
|
DrawLine(c + new Vector2(-11, 10), c + new Vector2(11, 10), 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;
|
|
}
|
|
}
|
|
}
|
|
}
|