F4: protocollo e client per manutenzione e impieghi, ADR 0010, stato dei lavori
- Protocollo: riepilogo di manutenzione nei record (blocco 1), RequestDetail, MaintenanceCard, WorkshopRegister, EmploymentReport con depositi, motivi e convenzioni, MaintenanceAlert. - Server: dettagli su richiesta, avvisi dalla manutenzione, registro dopo le convenzioni. - Client: pannelli Officine (cartella di manutenzione, Registro officina, scorta di ricambi, avvisi, mappa di calore) e Impieghi (Registro degli impieghi con convenzioni); schede di treno, industria e città aggiornate; pilota automatico con le nuove schermate. - ADR 0010, PROTOCOL, ARCHITECTURE e STATE aggiornati; 102 test verdi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
This commit is contained in:
28 files changed
+1618
-64
No files matched your search
@@ -0,0 +1,156 @@
|
||||
using Godot;
|
||||
using ViaFerrea.Client.App;
|
||||
using ViaFerrea.Client.Net;
|
||||
using ViaFerrea.Core.Commands;
|
||||
using ViaFerrea.Core.Common;
|
||||
using ViaFerrea.Protocol.Client;
|
||||
using ViaFerrea.Protocol.Messages;
|
||||
using static ViaFerrea.Client.App.Localization;
|
||||
|
||||
namespace ViaFerrea.Client.Panels;
|
||||
|
||||
/// <summary>
|
||||
/// Registro degli impieghi (sezione 9): convenzioni proposte dalle industrie (accetta o rifiuta),
|
||||
/// posti di lavoro serviti dai treni della compagnia e suoi depositi, con provenienza dei
|
||||
/// pendolari per città e linea, posti scoperti e motivo.
|
||||
/// </summary>
|
||||
public partial class EmploymentPanel : VBoxContainer
|
||||
{
|
||||
private readonly GameSession _session;
|
||||
private readonly VBoxContainer _agreements = PanelKit.Column(8);
|
||||
private readonly VBoxContainer _rows = PanelKit.Column(10);
|
||||
private readonly Label _status = UiTheme.Text("", 13, Palette.TextSecondary);
|
||||
private int _version = -1;
|
||||
|
||||
public EmploymentPanel(GameSession session)
|
||||
{
|
||||
_session = session;
|
||||
AddThemeConstantOverride("separation", 10);
|
||||
AddChild(UiTheme.TitleLabel(T("Registro degli impieghi"), 30));
|
||||
var help = UiTheme.Text(T("Ogni mese le città mandano i loro lavoratori alle industrie e ai depositi raggiungibili con i tuoi treni entro 60 minuti (personale: 90). Qui vedi da dove arrivano, quanti posti restano scoperti e perché."), 13, Palette.TextSecondary);
|
||||
help.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
AddChild(help);
|
||||
var refresh = new Button { Text = T("Aggiorna") };
|
||||
refresh.Pressed += Request;
|
||||
AddChild(refresh);
|
||||
AddChild(UiTheme.Text(T("Convenzioni"), 16, bold: true));
|
||||
AddChild(_agreements);
|
||||
AddChild(PanelKit.Separator());
|
||||
AddChild(UiTheme.Text(T("Posti di lavoro"), 16, bold: true));
|
||||
AddChild(_rows);
|
||||
_status.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
AddChild(_status);
|
||||
Request();
|
||||
}
|
||||
|
||||
private void Request() => _session.Send(new RequestDetail { Kind = DetailKind.Employment, Target = 0 });
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_session.World.DetailVersion != _version) Refresh();
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
var w = _session.World;
|
||||
_version = w.DetailVersion;
|
||||
foreach (var c in _agreements.GetChildren()) c.QueueFree();
|
||||
foreach (var c in _rows.GetChildren()) c.QueueFree();
|
||||
var report = w.Employment;
|
||||
if (report is null)
|
||||
{
|
||||
_rows.AddChild(UiTheme.Text(T("Registro in arrivo dal server…"), 13, Palette.TextSecondary));
|
||||
return;
|
||||
}
|
||||
|
||||
var open = report.Agreements.Where(a => a.State <= 1).ToList();
|
||||
if (open.Count == 0) _agreements.AddChild(Wrapped(T("Nessuna convenzione: le industrie la propongono quando i tuoi treni portano almeno 20 pendolari al giorno."), 13, Palette.TextSecondary));
|
||||
foreach (var a in open) _agreements.AddChild(AgreementRow(w, a));
|
||||
|
||||
foreach (var row in report.Rows.OrderBy(r => r.Kind).ThenBy(r => r.Industry)) _rows.AddChild(WorkplaceRow(w, row));
|
||||
if (report.Rows.Count == 0) _rows.AddChild(Wrapped(T("Nessun posto di lavoro servito dai tuoi treni."), 13, Palette.TextSecondary));
|
||||
}
|
||||
|
||||
private Control AgreementRow(ClientWorld w, AgreementInfo a)
|
||||
{
|
||||
var box = new PanelContainer();
|
||||
box.AddThemeStyleboxOverride("panel", UiTheme.Box(Palette.Inner, a.State == 0 ? Palette.Amber : Palette.Border, 8, 10));
|
||||
var col = PanelKit.Column(6);
|
||||
box.AddChild(col);
|
||||
string industry = w.Industries.TryGetValue(a.Industry, out var ind) ? ind.Name : $"#{a.Industry}";
|
||||
col.AddChild(UiTheme.Text(industry, 15, bold: true));
|
||||
col.AddChild(Wrapped($"{a.SeatsPerDay} {T("posti al giorno garantiti")} · {a.MonthlyFee} {T("al mese")}", 13, null));
|
||||
if (a.State == 0)
|
||||
{
|
||||
var buttons = PanelKit.Row(6);
|
||||
var accept = UiTheme.Primary(T("Accetta"));
|
||||
accept.Pressed += () => _session.Command(new AcceptAgreementCommand(new AgreementId(a.Id)), r => _status.Text = r.Message);
|
||||
var reject = new Button { Text = T("Rifiuta") };
|
||||
reject.Pressed += () => _session.Command(new RejectAgreementCommand(new AgreementId(a.Id)), r => _status.Text = r.Message);
|
||||
buttons.AddChild(accept);
|
||||
buttons.AddChild(reject);
|
||||
col.AddChild(buttons);
|
||||
var risk = UiTheme.Text(T("Se la capacità manca per 30 giorni la convenzione salta con una penale."), 12, Palette.TextSecondary);
|
||||
risk.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
col.AddChild(risk);
|
||||
}
|
||||
else
|
||||
{
|
||||
col.AddChild(UiTheme.Text($"{T("Attiva")} · {T("copertura")} {a.Coverage * 100:0}%" +
|
||||
(a.ShortDays > 0 ? $" · {T("capacità mancante da")} {a.ShortDays} {T("giorni")}" : ""), 13, a.ShortDays > 0 ? Palette.Danger : Palette.Ok));
|
||||
}
|
||||
return box;
|
||||
}
|
||||
|
||||
private Control WorkplaceRow(ClientWorld w, EmploymentRow row)
|
||||
{
|
||||
var col = PanelKit.Column(4);
|
||||
string name = row.Kind == 1
|
||||
? (w.Depots.TryGetValue(row.Industry, out var d) ? d.Name : $"#{row.Industry}")
|
||||
: (w.Industries.TryGetValue(row.Industry, out var ind) ? ind.Name : $"#{row.Industry}");
|
||||
col.AddChild(UiTheme.Text(name, 15, bold: true));
|
||||
var stats = PanelKit.Row();
|
||||
stats.AddChild(PanelKit.Stat(T("Lavoratori"), PanelKit.Value($"{row.WorkersPresent:0} / {row.JobsWorkers}")));
|
||||
stats.AddChild(PanelKit.Stat(T("Personale"), PanelKit.Value($"{row.StaffPresent:0} / {row.JobsStaff}")));
|
||||
col.AddChild(stats);
|
||||
foreach (string reason in new[] { ReasonText(w, row.WorkersReason, row.WorkersReasonLine, staff: false), ReasonText(w, row.StaffReason, row.StaffReasonLine, staff: true) })
|
||||
{
|
||||
if (reason.Length == 0) continue;
|
||||
var l = UiTheme.Text("⚠ " + reason, 13, Palette.Amber);
|
||||
l.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
col.AddChild(l);
|
||||
}
|
||||
foreach (var s in row.Sources.OrderByDescending(s => s.Headcount))
|
||||
{
|
||||
string town = w.Towns.TryGetValue(s.Town, out var t) ? t.Name : $"#{s.Town}";
|
||||
string via = s.Line >= 0 && w.Lines.TryGetValue(s.Line, out var line) ? line.Name : T("a piedi");
|
||||
string who = s.Category == 1 ? T("tecnici") : T("lavoratori");
|
||||
col.AddChild(Wrapped($"• {s.Headcount} {who} {T("da")} {town} · {via} · {T("copertura")} {s.Coverage * 100:0}%", 13,
|
||||
s.Category == 1 ? Palette.Staff : Palette.Workers));
|
||||
}
|
||||
return col;
|
||||
}
|
||||
|
||||
private static Label Wrapped(string text, int size, Color? color)
|
||||
{
|
||||
var l = UiTheme.Text(text, size, color);
|
||||
l.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
return l;
|
||||
}
|
||||
|
||||
/// <summary>Motivo dei posti scoperti nella lingua dell'interfaccia (codici UncoveredReason).</summary>
|
||||
public static string ReasonText(ClientWorld w, byte reason, int line, bool staff)
|
||||
{
|
||||
string who = staff ? T("Personale") : T("Lavoratori");
|
||||
string minutes = staff ? $"{w.Data.Balance.Employment.StaffMaxMinutes:0}" : $"{w.Data.Balance.Employment.WorkerMaxMinutes:0}";
|
||||
return reason switch
|
||||
{
|
||||
1 => $"{who}: {T("nessuna stazione serve il posto di lavoro")}",
|
||||
2 => $"{who}: {T("nessuna città raggiungibile entro")} {minutes} min",
|
||||
3 => $"{who}: {T("le città raggiungibili non hanno lavoratori liberi")}",
|
||||
4 => $"{who}: {T("città senza servizi per il personale")}",
|
||||
5 => $"{who}: {T("capacità delle carrozze insufficiente sulla")} {(w.Lines.TryGetValue(line, out var l) ? l.Name : T("linea"))}",
|
||||
_ => "",
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user