using Godot; using RailEnterprise.Client.App; using RailEnterprise.Client.Tutorial; using static RailEnterprise.Client.App.Localization; namespace RailEnterprise.Client.Screens; /// /// Menu iniziale: partita locale (server figlio), collegamento a un server, tutorial, lingua, uscita. La /// casella «Mostra il tutorial» è attiva alla prima partita; «Tutorial» apre la partita locale con il /// tutorial dal primo passo. /// public partial class MenuScreen : Control { public event Action? LocalGame; public event Action? ConnectToServer; public event Action? LanguageChanged; public event Action? TutorialRequested; private readonly CheckBox _showTutorial = new() { Text = T("Mostra il tutorial") }; /// Casella «Mostra il tutorial» per la partita che si apre. public bool ShowTutorial => _showTutorial.ButtonPressed; private readonly Label _status = UiTheme.Text("", 14, Palette.TextSecondary); public override void _Ready() { // già nell'albero: ancore e margini insieme, altrimenti la schermata resterebbe grande zero SetAnchorsAndOffsetsPreset(LayoutPreset.FullRect); UiTheme.Apply(this); var bg = new ColorRect { Color = Palette.AppBackground }; bg.SetAnchorsPreset(LayoutPreset.FullRect); AddChild(bg); var center = new CenterContainer(); center.SetAnchorsPreset(LayoutPreset.FullRect); AddChild(center); var col = new VBoxContainer { CustomMinimumSize = new Vector2(440, 0) }; col.AddThemeConstantOverride("separation", 14); center.AddChild(col); col.AddChild(UiTheme.TitleLabel("Rail Enterprise", 96)); col.AddChild(UiTheme.Text(T("Gestionale ferroviario dall'alto"), 18, Palette.TextSecondary)); col.AddChild(new Control { CustomMinimumSize = new Vector2(0, 20) }); var local = UiTheme.Primary(T("Partita locale")); local.CustomMinimumSize = new Vector2(0, 48); local.Pressed += () => LocalGame?.Invoke(); col.AddChild(local); _showTutorial.ButtonPressed = !TutorialSettings.Played; _showTutorial.TooltipText = T("Guida passo per passo alla prima linea: si chiude quando vuoi e si riapre con F1"); col.AddChild(_showTutorial); var remote = new Button { Text = T("Collegati a un server"), CustomMinimumSize = new Vector2(0, 48) }; remote.Pressed += () => ConnectToServer?.Invoke(); col.AddChild(remote); var tutorial = new Button { Text = T("Tutorial"), CustomMinimumSize = new Vector2(0, 40) }; tutorial.TooltipText = T("Partita locale con il tutorial dal primo passo"); tutorial.Pressed += () => TutorialRequested?.Invoke(); col.AddChild(tutorial); var lang = new HBoxContainer(); lang.AddThemeConstantOverride("separation", 8); foreach (var (code, label) in new[] { ("it", "Italiano"), ("en", "English") }) { var b = new Button { Text = label, ToggleMode = true, ButtonPressed = TranslationServer.GetLocale().StartsWith(code) }; b.Pressed += () => LanguageChanged?.Invoke(code); lang.AddChild(b); } col.AddChild(lang); var quit = new Button { Text = T("Esci"), CustomMinimumSize = new Vector2(0, 40) }; quit.Pressed += () => GetTree().Quit(); col.AddChild(quit); _status.AutowrapMode = TextServer.AutowrapMode.WordSmart; col.AddChild(_status); } public void SetStatus(string text) => _status.Text = text; }