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

145 lines
6.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Godot;
namespace ViaFerrea.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;
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));
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);
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));
t.SetColor("font_selected_color", "ItemList", Palette.AppBackground);
t.SetStylebox("selected", "ItemList", Box(Palette.Amber, Palette.Amber, 4, 4));
t.SetStylebox("selected_focus", "ItemList", Box(Palette.Amber, Palette.Amber, 4, 4));
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);
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;
}
}