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>
176 lines
8.3 KiB
C#
176 lines
8.3 KiB
C#
using Godot;
|
||
|
||
namespace RailEnterprise.Client.App;
|
||
|
||
/// <summary>
|
||
/// Tema dell'interfaccia costruito in codice dalla palette (immagine 05): titoli in Big Shoulders
|
||
/// Display 800, testo e numeri in IBM Plex Sans; raggio 8–12 px, bordi 1 px #2c3a42, nessuna ombra.
|
||
/// </summary>
|
||
public static class UiTheme
|
||
{
|
||
public static Font Body { get; private set; } = ThemeDB.FallbackFont;
|
||
public static Font BodyBold { get; private set; } = ThemeDB.FallbackFont;
|
||
public static Font Title { get; private set; } = ThemeDB.FallbackFont;
|
||
|
||
/// <summary>
|
||
/// Tema costruito da <see cref="Build"/>. Il tema della finestra non attraversa i nodi che non
|
||
/// sono Control (Main, CanvasLayer): ogni radice dell'interfaccia lo riceve con <see cref="Apply"/>.
|
||
/// </summary>
|
||
public static Theme? Current { get; private set; }
|
||
|
||
/// <summary>Assegna il tema a una radice dell'interfaccia (figlia di un nodo che non è un Control).</summary>
|
||
public static void Apply(Control root) => root.Theme = Current;
|
||
|
||
public static Theme Build()
|
||
{
|
||
Body = LoadFont("res://assets/fonts/IBMPlexSans-Regular.ttf");
|
||
BodyBold = LoadFont("res://assets/fonts/IBMPlexSans-SemiBold.ttf");
|
||
Title = LoadFont("res://assets/fonts/BigShouldersDisplay-ExtraBold.ttf");
|
||
|
||
var t = new Theme { DefaultFont = Body, DefaultFontSize = 14 };
|
||
foreach (string type in new[] { "Label", "Button", "LineEdit", "CheckBox", "OptionButton", "SpinBox", "ItemList", "PopupMenu", "TooltipLabel" })
|
||
{
|
||
t.SetColor("font_color", type, Palette.Text);
|
||
}
|
||
t.SetColor("font_color", "TooltipLabel", Palette.Text);
|
||
t.SetStylebox("panel", "TooltipPanel", Box(Palette.Inner, Palette.Border, 8, 8));
|
||
|
||
t.SetStylebox("panel", "PanelContainer", Box(Palette.Panel, Palette.Border, 10, 12));
|
||
t.SetStylebox("panel", "Panel", Box(Palette.Panel, Palette.Border, 0, 0));
|
||
|
||
var normal = Box(Palette.Panel, Palette.Border, 8, 10);
|
||
t.SetStylebox("normal", "Button", normal);
|
||
t.SetStylebox("hover", "Button", Box(Palette.Inner, Palette.TextSecondary, 8, 10));
|
||
t.SetStylebox("pressed", "Button", Box(Palette.Amber, Palette.Amber, 8, 10));
|
||
t.SetStylebox("disabled", "Button", Box(Palette.AppBackground, Palette.Border, 8, 10));
|
||
t.SetStylebox("focus", "Button", Box(new Color(0, 0, 0, 0), Palette.AmberLight, 8, 10));
|
||
// pulsanti in IBM Plex Sans 600 come nell'immagine 05
|
||
t.SetFont("font", "Button", BodyBold);
|
||
t.SetColor("font_pressed_color", "Button", Palette.AppBackground);
|
||
t.SetColor("font_hover_color", "Button", Palette.Text);
|
||
t.SetColor("font_disabled_color", "Button", Palette.TextSecondary);
|
||
t.SetColor("font_hover_pressed_color", "Button", Palette.AppBackground);
|
||
|
||
// caselle e interruttori: niente riquadro da pulsante (altrimenti ereditano quello di Button)
|
||
var plain = new StyleBoxEmpty { ContentMarginLeft = 4, ContentMarginRight = 4, ContentMarginTop = 2, ContentMarginBottom = 2 };
|
||
foreach (string type in new[] { "CheckBox", "CheckButton" })
|
||
{
|
||
foreach (string state in new[] { "normal", "pressed", "hover", "hover_pressed", "disabled", "focus" }) t.SetStylebox(state, type, plain);
|
||
t.SetColor("font_pressed_color", type, Palette.Text);
|
||
t.SetColor("font_hover_color", type, Palette.Text);
|
||
t.SetColor("font_hover_pressed_color", type, Palette.Text);
|
||
t.SetFont("font", type, Body);
|
||
}
|
||
|
||
t.SetStylebox("normal", "LineEdit", Box(Palette.Inner, Palette.Border, 8, 8));
|
||
t.SetStylebox("focus", "LineEdit", Box(Palette.Inner, Palette.Amber, 8, 8));
|
||
t.SetColor("caret_color", "LineEdit", Palette.Amber);
|
||
t.SetStylebox("panel", "ItemList", Box(Palette.Inner, Palette.Border, 8, 6));
|
||
// selezione su ambra scuro: restano leggibili anche le voci colorate (condizione, proprietario)
|
||
t.SetColor("font_selected_color", "ItemList", Palette.AmberLight);
|
||
t.SetStylebox("selected", "ItemList", Box(Palette.AmberDark, Palette.Amber, 4, 4));
|
||
t.SetStylebox("selected_focus", "ItemList", Box(Palette.AmberDark, Palette.Amber, 4, 4));
|
||
|
||
// cursori: binario vuoto e parte piena in ambra
|
||
var track = Box(Palette.Border, Palette.Border, 3, 0);
|
||
track.ContentMarginTop = track.ContentMarginBottom = 3;
|
||
t.SetStylebox("slider", "HSlider", track);
|
||
t.SetStylebox("grabber_area", "HSlider", Box(Palette.Amber, Palette.Amber, 3, 0));
|
||
t.SetStylebox("grabber_area_highlight", "HSlider", Box(Palette.AmberLight, Palette.AmberLight, 3, 0));
|
||
|
||
t.SetStylebox("background", "ProgressBar", Box(Palette.Border, Palette.Border, 4, 0));
|
||
t.SetStylebox("fill", "ProgressBar", Box(Palette.Workers, Palette.Workers, 4, 0));
|
||
t.SetColor("font_color", "ProgressBar", Palette.Text);
|
||
Current = t;
|
||
return t;
|
||
}
|
||
|
||
/// <summary>Riquadro piatto con bordo di 1 px.</summary>
|
||
public static StyleBoxFlat Box(Color bg, Color border, int radius, int margin)
|
||
{
|
||
var s = new StyleBoxFlat { BgColor = bg, BorderColor = border };
|
||
s.SetBorderWidthAll(1);
|
||
s.SetCornerRadiusAll(radius);
|
||
s.ContentMarginLeft = margin;
|
||
s.ContentMarginRight = margin;
|
||
s.ContentMarginTop = margin * 0.6f;
|
||
s.ContentMarginBottom = margin * 0.6f;
|
||
return s;
|
||
}
|
||
|
||
/// <summary>Carica un font importato dall'editor oppure, in mancanza, direttamente dal file.</summary>
|
||
private static Font LoadFont(string path)
|
||
{
|
||
if (ResourceLoader.Exists(path))
|
||
{
|
||
var imported = ResourceLoader.Load<FontFile>(path);
|
||
if (imported is not null) return imported;
|
||
}
|
||
var font = new FontFile();
|
||
if (font.LoadDynamicFont(path) == Error.Ok) return font;
|
||
GD.PushWarning($"Font non trovato: {path}");
|
||
return ThemeDB.FallbackFont;
|
||
}
|
||
|
||
/// <summary>Etichetta con il font dei titoli.</summary>
|
||
public static Label TitleLabel(string text, int size, Color? color = null)
|
||
{
|
||
var l = new Label { Text = text };
|
||
l.AddThemeFontOverride("font", Title);
|
||
l.AddThemeFontSizeOverride("font_size", size);
|
||
l.AddThemeColorOverride("font_color", color ?? Palette.Text);
|
||
return l;
|
||
}
|
||
|
||
public static Label Text(string text, int size = 14, Color? color = null, bool bold = false)
|
||
{
|
||
var l = new Label { Text = text };
|
||
l.AddThemeFontOverride("font", bold ? BodyBold : Body);
|
||
l.AddThemeFontSizeOverride("font_size", size);
|
||
l.AddThemeColorOverride("font_color", color ?? Palette.Text);
|
||
return l;
|
||
}
|
||
|
||
/// <summary>Pulsante d'azione primaria (ambra).</summary>
|
||
public static Button Primary(string text)
|
||
{
|
||
var b = new Button { Text = text };
|
||
b.AddThemeStyleboxOverride("normal", Box(Palette.Amber, Palette.Amber, 8, 12));
|
||
b.AddThemeStyleboxOverride("hover", Box(Palette.AmberLight, Palette.AmberLight, 8, 12));
|
||
b.AddThemeColorOverride("font_color", Palette.AppBackground);
|
||
b.AddThemeColorOverride("font_hover_color", Palette.AppBackground);
|
||
b.AddThemeFontOverride("font", BodyBold);
|
||
return b;
|
||
}
|
||
|
||
/// <summary>Distintivo ambra (livello della compagnia, linea).</summary>
|
||
public static PanelContainer Badge(string text)
|
||
{
|
||
var p = new PanelContainer();
|
||
p.AddThemeStyleboxOverride("panel", Box(Palette.Amber, Palette.Amber, 4, 6));
|
||
var l = Text(text, 12, Palette.AppBackground, bold: true);
|
||
p.AddChild(l);
|
||
return p;
|
||
}
|
||
|
||
/// <summary>Etichetta di linea: ambra su fondo ambra scuro, su una riga (immagine 01).</summary>
|
||
public static PanelContainer LineBadge(string text)
|
||
{
|
||
var p = new PanelContainer();
|
||
p.AddThemeStyleboxOverride("panel", Box(Palette.AmberDark, Palette.AmberDark, 6, 10));
|
||
p.AddChild(Text(text, 13, Palette.AmberLight, bold: true));
|
||
return p;
|
||
}
|
||
|
||
/// <summary>Riquadro d'avviso ambra scuro (colli di bottiglia e opportunità).</summary>
|
||
public static PanelContainer Notice(string text)
|
||
{
|
||
var p = new PanelContainer();
|
||
p.AddThemeStyleboxOverride("panel", Box(Palette.AmberDark, Palette.AmberDark, 8, 12));
|
||
var l = Text(text, 13, Palette.AmberLight);
|
||
l.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||
p.AddChild(l);
|
||
return p;
|
||
}
|
||
}
|