Files
Rail_Enterprise/client/RailEnterprise.Client/scripts/Map/ToolOverlay.cs
T
Alby96andClaude Opus 5.5 c1a0049bcf
CI / Build e test (pull_request) Successful in 1m20s
CI / Immagine Docker (pull_request) Successful in 37s
Infrastruttura: nome «Rail Enterprise», CI e rilasci su Gitea, documentazione
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>
2026-11-07 11:14:54 +01:00

123 lines
4.5 KiB
C#

using Godot;
using RailEnterprise.Client.App;
using RailEnterprise.Core.Rail;
using RailEnterprise.Protocol.Client;
namespace RailEnterprise.Client.Map;
/// <summary>Sagome degli strumenti: tracciato in corso con l'anteprima delle opere, stazione o deposito da posare, fermate di una linea.</summary>
public partial class ToolOverlay : Node2D
{
public enum Ghost { None, Station, Depot, Demolish }
private ClientWorld? _world;
private float _zoom = 1;
private List<Vector2> _points = [];
private Vector2? _mouse;
private TrackPlan? _plan;
private Ghost _ghost;
private Vector2? _ghostAt;
private List<Vector2> _stops = [];
public void Bind(ClientWorld world) => _world = world;
public void SetZoom(float zoom)
{
_zoom = zoom;
QueueRedraw();
}
public void SetTrack(List<Vector2> points, Vector2? mouse, TrackPlan? plan)
{
_points = points;
_mouse = mouse;
_plan = plan;
QueueRedraw();
}
public void SetGhost(Ghost ghost, Vector2? at)
{
_ghost = ghost;
_ghostAt = at;
QueueRedraw();
}
public void SetStops(List<Vector2> stops)
{
_stops = stops;
QueueRedraw();
}
public void Clear()
{
_points = [];
_mouse = null;
_plan = null;
_ghost = Ghost.None;
_ghostAt = null;
_stops = [];
QueueRedraw();
}
public static Color WorkColor(WorkKind kind) => kind switch
{
WorkKind.Embankment => new Color("e8e0c2"),
WorkKind.Cutting => new Color("8f8a73"),
WorkKind.Bridge => new Color("5b8fb0"),
WorkKind.Tunnel => new Color("4a4740"),
_ => Palette.Ballast,
};
public override void _Draw()
{
float s = MapScale.Symbol(_zoom);
if (_plan is { Samples.Count: > 1 } plan)
{
var color = plan.Valid ? Palette.Ok : Palette.Danger;
for (int i = 0; i < plan.Samples.Count - 1; i++)
{
var a = MapScale.V(plan.Samples[i].Point);
var b = MapScale.V(plan.Samples[i + 1].Point);
DrawLine(a, b, Palette.WithAlpha(color, 0.45f), 14f * s);
if (plan.Samples[i].Kind == WorkKind.Tunnel) DrawDashedLine(a, b, WorkColor(WorkKind.Tunnel), 5f * s, 6f * s);
else DrawLine(a, b, WorkColor(plan.Samples[i].Kind), 7f * s);
}
}
var pts = new List<Vector2>(_points);
if (_mouse is { } m && pts.Count > 0) pts.Add(m);
for (int i = 0; i < pts.Count - 1; i++) DrawDashedLine(pts[i], pts[i + 1], Palette.Amber, 2f * s, 8f * s);
foreach (var p in _points) DrawCircle(p, 4f * s, Palette.Amber);
if (_ghostAt is { } g && _world is not null)
{
switch (_ghost)
{
case Ghost.Station:
float radius = (float)(_world.Data.Construction.Stations.CatchmentKm * 1000);
for (int k = 0; k < 48; k += 2)
{
float a0 = k * MathF.Tau / 48, a1 = (k + 1) * MathF.Tau / 48;
DrawLine(g + new Vector2(MathF.Cos(a0), MathF.Sin(a0)) * radius, g + new Vector2(MathF.Cos(a1), MathF.Sin(a1)) * radius, Palette.Amber, 2.5f * s);
}
DrawCircle(g, radius, Palette.WithAlpha(Palette.Amber, 0.08f));
DrawRect(new Rect2(g - new Vector2(12, 6) * s, new Vector2(24, 12) * s), Palette.WithAlpha(Palette.TileRoof, 0.8f));
break;
case Ghost.Depot:
DrawRect(new Rect2(g - new Vector2(16, 9) * s, new Vector2(32, 18) * s), Palette.WithAlpha(new Color("5a6670"), 0.8f));
break;
case Ghost.Demolish:
DrawCircle(g, 30f * s, Palette.WithAlpha(Palette.Danger, 0.3f));
DrawLine(g - new Vector2(10, 10) * s, g + new Vector2(10, 10) * s, Palette.Danger, 3f * s);
DrawLine(g + new Vector2(-10, 10) * s, g + new Vector2(10, -10) * s, Palette.Danger, 3f * s);
break;
}
}
for (int i = 0; i < _stops.Count; i++)
{
if (i > 0) DrawDashedLine(_stops[i - 1], _stops[i], Palette.Amber, 3f * s, 10f * s);
DrawCircle(_stops[i], 9f * s, Palette.Amber);
DrawString(UiTheme.BodyBold, _stops[i] + new Vector2(-4, 5) * s, (i + 1).ToString(), HorizontalAlignment.Left, -1, (int)Math.Max(8, 12 * s), Palette.AppBackground);
}
}
}