- 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
92 lines
3.5 KiB
C#
92 lines
3.5 KiB
C#
using Godot;
|
|
using ViaFerrea.Client.App;
|
|
using static ViaFerrea.Client.App.Localization;
|
|
|
|
namespace ViaFerrea.Client.Screens;
|
|
|
|
/// <summary>
|
|
/// Collegamento a un server (immagine 09 non fornita: palette e componenti dell'immagine 05).
|
|
/// Ricorda indirizzo e token in user://settings.cfg.
|
|
/// </summary>
|
|
public partial class ConnectScreen : Control
|
|
{
|
|
private const string SettingsPath = "user://settings.cfg";
|
|
private readonly LineEdit _address = new() { PlaceholderText = "unraid.lan:7400" };
|
|
private readonly LineEdit _token = new() { Secret = true, PlaceholderText = T("Token del server") };
|
|
private readonly Label _status = UiTheme.Text("", 14, Palette.TextSecondary);
|
|
private readonly Button _connect = UiTheme.Primary(T("Collegati"));
|
|
|
|
public event Action<Uri, string, string>? ConnectRequested;
|
|
public event Action? Back;
|
|
|
|
public override void _Ready()
|
|
{
|
|
SetAnchorsPreset(LayoutPreset.FullRect);
|
|
var bg = new ColorRect { Color = Palette.AppBackground };
|
|
bg.SetAnchorsPreset(LayoutPreset.FullRect);
|
|
AddChild(bg);
|
|
var center = new CenterContainer();
|
|
center.SetAnchorsPreset(LayoutPreset.FullRect);
|
|
AddChild(center);
|
|
var panel = new PanelContainer { CustomMinimumSize = new Vector2(480, 0) };
|
|
center.AddChild(panel);
|
|
var col = new VBoxContainer();
|
|
col.AddThemeConstantOverride("separation", 12);
|
|
panel.AddChild(col);
|
|
col.AddChild(UiTheme.TitleLabel(T("Collegati a un server"), 40));
|
|
col.AddChild(UiTheme.Text(T("Indirizzo (host:porta)"), 13, Palette.TextSecondary));
|
|
col.AddChild(_address);
|
|
col.AddChild(UiTheme.Text(T("Token"), 13, Palette.TextSecondary));
|
|
col.AddChild(_token);
|
|
var row = new HBoxContainer();
|
|
row.AddThemeConstantOverride("separation", 10);
|
|
_connect.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
|
_connect.Pressed += Submit;
|
|
row.AddChild(_connect);
|
|
var back = new Button { Text = T("Indietro") };
|
|
back.Pressed += () => Back?.Invoke();
|
|
row.AddChild(back);
|
|
col.AddChild(row);
|
|
_status.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
|
col.AddChild(_status);
|
|
col.AddChild(UiTheme.Notice(T("La connessione non è cifrata: per Internet usa un reverse proxy con TLS (wss://).")));
|
|
|
|
var cfg = new ConfigFile();
|
|
if (cfg.Load(SettingsPath) == Error.Ok)
|
|
{
|
|
_address.Text = (string)cfg.GetValue("server", "address", "");
|
|
_token.Text = (string)cfg.GetValue("server", "token", "");
|
|
}
|
|
_token.TextSubmitted += _ => Submit();
|
|
}
|
|
|
|
public void SetStatus(string text, bool busy)
|
|
{
|
|
_status.Text = text;
|
|
_connect.Disabled = busy;
|
|
}
|
|
|
|
private void Submit()
|
|
{
|
|
string address = _address.Text.Trim();
|
|
if (address.Length == 0)
|
|
{
|
|
SetStatus(T("Indica l'indirizzo del server"), false);
|
|
return;
|
|
}
|
|
string url = address.Contains("://") ? address : $"ws://{address}";
|
|
if (!url.EndsWith("/ws", StringComparison.Ordinal)) url = url.TrimEnd('/') + "/ws";
|
|
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri))
|
|
{
|
|
SetStatus(T("Indirizzo non valido"), false);
|
|
return;
|
|
}
|
|
var cfg = new ConfigFile();
|
|
cfg.Load(SettingsPath);
|
|
cfg.SetValue("server", "address", address);
|
|
cfg.SetValue("server", "token", _token.Text);
|
|
cfg.Save(SettingsPath);
|
|
ConnectRequested?.Invoke(uri, _token.Text, uri.Host);
|
|
}
|
|
}
|