Ogni valore importante dei pannelli spiega al passaggio del mouse da dove viene: formula, termini con i valori di oggi e note, calcolati dal Core e mandati dal server, perché il client non deve rifare né ricomporre formule. - Core: modello comune Explanation ed Explanations, pure funzioni che chiamano le stesse funzioni del motore; estratte senza cambiare l'aritmetica (hash invariati) Market.NextPrice e LocalPriceTerms, Tariffs.FreightTerms e PassengerTerms, TownSystem.GrowthOf, Fleet.DailyHazard, GameClock.YearsAt; Industry.LastEfficiency transitorio (né salvato né nell'hash). - Protocollo: RequestDetail kind 11 con un blocco 1 (subject, arg) ed ExplanationReport 137; il server risponde sempre, anche con available falso. Nessun campo nei delta, formato dei salvataggi invariato. - Client: WhyTooltip comune (palette 05, apertura dopo 0,45 s, «in arrivo…» finché la spiegazione manca) su barra superiore, Mercato, Scalata, Finanze, scheda industria, Treni e Officine; testi in strings.csv. - ADR 0024, PROTOCOL.md, ARCHITECTURE.md, STATE.md; 10 test nuovi in Economy/ExplanationTests.cs con uguaglianza esatta ai valori del motore. Refs #44. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
485 lines
24 KiB
C#
485 lines
24 KiB
C#
using Godot;
|
||
using RailEnterprise.Client.App;
|
||
using RailEnterprise.Client.Net;
|
||
using RailEnterprise.Core.Commands;
|
||
using RailEnterprise.Core.Common;
|
||
using RailEnterprise.Core.Data;
|
||
using RailEnterprise.Protocol.Messages;
|
||
using static RailEnterprise.Client.App.Localization;
|
||
using ExplainSubject = RailEnterprise.Core.Economy.ExplainSubject;
|
||
using ExplainTarget = RailEnterprise.Core.Economy.ExplainTarget;
|
||
|
||
namespace RailEnterprise.Client.Panels;
|
||
|
||
/// <summary>
|
||
/// Officine (sezione 10.3): politica della flotta, avvisi, flotta ordinata per condizione con la
|
||
/// mappa di calore, cartella di manutenzione del treno scelto, depositi con il Registro officina e
|
||
/// la scorta di ricambi, rinnovo della flotta (ere e obsolescenza, ADR 0020). Le cartelle, i registri
|
||
/// e il quadro della flotta arrivano su richiesta dal server: età, successori e valori non si calcolano qui.
|
||
/// </summary>
|
||
public partial class MaintenancePanel : VBoxContainer
|
||
{
|
||
private static readonly string[] PolicyIds = ["economy", "standard", "thorough"];
|
||
|
||
private readonly GameSession _session;
|
||
private readonly OptionButton _fleetPolicy = new();
|
||
private readonly CheckButton _heat = new() { Text = T("Mappa di calore della condizione") };
|
||
private readonly VBoxContainer _alerts = PanelKit.Column(4);
|
||
private readonly ItemList _trains = new() { CustomMinimumSize = new Vector2(0, 150) };
|
||
private readonly VBoxContainer _card = PanelKit.Column(8);
|
||
private readonly VBoxContainer _cardControls = PanelKit.Column(8);
|
||
private readonly VBoxContainer _cardDetails = PanelKit.Column(6);
|
||
private readonly ItemList _depots = new() { CustomMinimumSize = new Vector2(0, 80) };
|
||
private readonly VBoxContainer _workshop = PanelKit.Column(8);
|
||
private readonly VBoxContainer _workshopDetails = PanelKit.Column(6);
|
||
private readonly HBoxContainer _orderRow = PanelKit.Row();
|
||
private readonly VBoxContainer _fleet = PanelKit.Column(6);
|
||
private readonly Label _status = UiTheme.Text("", 13, Palette.TextSecondary);
|
||
private readonly List<int> _trainIds = [];
|
||
private readonly List<int> _depotIds = [];
|
||
private int _train = -1, _depot = -1;
|
||
private int _entityVersion = -1, _detailVersion = -1;
|
||
private double _request;
|
||
private long _fleetDay = long.MinValue;
|
||
private double _sinceFleet = double.MaxValue;
|
||
// quadro della flotta mostrato: la sezione si ricostruisce solo quando ne arriva uno nuovo, così i
|
||
// pulsanti «Rinnova» non si ricreano sotto il cursore a ogni aggiornamento della cartella
|
||
private FleetReport? _fleetShown;
|
||
private bool _fleetBuilt;
|
||
private bool _updating;
|
||
|
||
public event Action<bool>? HeatMapToggled;
|
||
public event Action<int>? TrainSelected;
|
||
|
||
public MaintenancePanel(GameSession session, bool heatMap)
|
||
{
|
||
_session = session;
|
||
AddThemeConstantOverride("separation", 10);
|
||
AddChild(UiTheme.TitleLabel(T("Officine"), 34));
|
||
var policyRow = PanelKit.Row();
|
||
var caption = UiTheme.Text(T("Politica della flotta"), 14, Palette.TextSecondary);
|
||
caption.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||
policyRow.AddChild(caption);
|
||
foreach (var p in session.World.Data.Maintenance.Policies) _fleetPolicy.AddItem(p.NameIt);
|
||
policyRow.AddChild(_fleetPolicy);
|
||
AddChild(policyRow);
|
||
_heat.ButtonPressed = heatMap;
|
||
_heat.Toggled += on => HeatMapToggled?.Invoke(on);
|
||
AddChild(_heat);
|
||
AddChild(_alerts);
|
||
|
||
AddChild(PanelKit.Separator());
|
||
AddChild(UiTheme.Text(T("Flotta, dal treno più usurato"), 14, bold: true));
|
||
AddChild(_trains);
|
||
AddChild(_card);
|
||
AddChild(_cardControls);
|
||
AddChild(_cardDetails);
|
||
AddChild(PanelKit.Separator());
|
||
AddChild(UiTheme.Text(T("Depositi e officine"), 14, bold: true));
|
||
AddChild(_depots);
|
||
AddChild(_workshop);
|
||
AddChild(_workshopDetails);
|
||
AddChild(_orderRow);
|
||
AddChild(PanelKit.Separator());
|
||
AddChild(UiTheme.Text(T("Rinnovo della flotta"), 14, bold: true));
|
||
AddChild(_fleet);
|
||
_status.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||
AddChild(_status);
|
||
|
||
_fleetPolicy.ItemSelected += i =>
|
||
{
|
||
if (!_updating) _session.Command(new SetMaintenancePolicyCommand(MaintenanceScope.Company, 0, PolicyIds[i]), Result);
|
||
};
|
||
_trains.ItemSelected += i => SelectTrain(_trainIds[(int)i]);
|
||
_depots.ItemSelected += i => SelectDepot(_depotIds[(int)i]);
|
||
}
|
||
|
||
/// <summary>Allinea l'interruttore della mappa di calore senza rilanciare l'evento.</summary>
|
||
public void SetHeatMap(bool on) => _heat.SetPressedNoSignal(on);
|
||
|
||
public void SelectTrain(int id)
|
||
{
|
||
_train = id;
|
||
_detailVersion = -1;
|
||
_session.Send(new RequestDetail { Kind = DetailKind.TrainCard, Target = id });
|
||
TrainSelected?.Invoke(id);
|
||
BuildCardControls();
|
||
Refresh();
|
||
}
|
||
|
||
public void SelectDepot(int id)
|
||
{
|
||
_depot = id;
|
||
_detailVersion = -1;
|
||
_session.Send(new RequestDetail { Kind = DetailKind.Workshop, Target = id });
|
||
BuildOrderRow();
|
||
Refresh();
|
||
}
|
||
|
||
public override void _Process(double delta)
|
||
{
|
||
// cartella e registro aperti si aggiornano una volta al secondo
|
||
_request += delta;
|
||
if (_request >= 1)
|
||
{
|
||
_request = 0;
|
||
if (_train >= 0) _session.Send(new RequestDetail { Kind = DetailKind.TrainCard, Target = _train });
|
||
if (_depot >= 0) _session.Send(new RequestDetail { Kind = DetailKind.Workshop, Target = _depot });
|
||
}
|
||
var w = _session.World;
|
||
// quadro della flotta: all'apertura e a ogni nuovo giorno; di nuovo dopo 5 s se non arriva
|
||
_sinceFleet += delta;
|
||
long today = Fmt.Today(w);
|
||
if (today != _fleetDay || (w.Fleet is null && _sinceFleet > 5)) RequestFleet(today);
|
||
if (w.EntityVersion != _entityVersion || w.DetailVersion != _detailVersion) Refresh();
|
||
}
|
||
|
||
private void RequestFleet(long day)
|
||
{
|
||
_fleetDay = day;
|
||
_sinceFleet = 0;
|
||
_session.Send(new RequestDetail { Kind = DetailKind.Fleet, Target = 0 });
|
||
}
|
||
|
||
private void Result(CommandResultMessage r)
|
||
{
|
||
_status.Text = r.Message;
|
||
// un rinnovo prenotato o completato cambia il quadro della flotta
|
||
RequestFleet(Fmt.Today(_session.World));
|
||
}
|
||
|
||
private void Refresh()
|
||
{
|
||
var w = _session.World;
|
||
_entityVersion = w.EntityVersion;
|
||
_detailVersion = w.DetailVersion;
|
||
int company = w.Summary?.CompanyId ?? 0;
|
||
_updating = true;
|
||
if (w.Companies.TryGetValue(company, out var me)) _fleetPolicy.Selected = Math.Clamp(me.MaintenancePolicy, 0, PolicyIds.Length - 1);
|
||
_updating = false;
|
||
|
||
foreach (var c in _alerts.GetChildren()) c.QueueFree();
|
||
foreach (var a in w.Alerts.Take(4))
|
||
{
|
||
var l = UiTheme.Text("⚠ " + a.Text, 13, a.Condition < w.Data.Maintenance.Planner.CriticalCondition ? Palette.Danger : Palette.Amber);
|
||
l.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||
_alerts.AddChild(l);
|
||
}
|
||
|
||
_trainIds.Clear();
|
||
_trains.Clear();
|
||
foreach (var t in w.Trains.Values.Where(t => t.Owner == company).OrderBy(t => t.Condition).ThenBy(t => t.Id))
|
||
{
|
||
_trainIds.Add(t.Id);
|
||
_trains.AddItem($"{t.Name} · {t.Condition}% · {StatusName(t.Maintenance)}{(t.Reserve ? " · " + T("riserva") : "")}{DueText(t)}");
|
||
_trains.SetItemCustomFgColor(_trains.ItemCount - 1, ConditionColor(t.Condition));
|
||
}
|
||
int ti = _trainIds.IndexOf(_train);
|
||
if (ti >= 0) _trains.Select(ti);
|
||
|
||
_depotIds.Clear();
|
||
_depots.Clear();
|
||
foreach (var d in w.Depots.Values.Where(d => d.Owner == company).OrderBy(d => d.Id))
|
||
{
|
||
_depotIds.Add(d.Id);
|
||
_depots.AddItem($"{d.Name} · {T("ricambi")} {d.SpareParts}/{d.PartsTarget} · {T("personale")} {d.StaffPercent}% · {d.Jobs} {T("lavori")}");
|
||
if (d.WaitingParts) _depots.SetItemCustomFgColor(_depots.ItemCount - 1, Palette.Danger);
|
||
}
|
||
int di = _depotIds.IndexOf(_depot);
|
||
if (di >= 0) _depots.Select(di);
|
||
|
||
BuildCard();
|
||
BuildWorkshop();
|
||
if (!_fleetBuilt || !ReferenceEquals(w.Fleet, _fleetShown)) BuildFleet();
|
||
}
|
||
|
||
private string DueText(TrainInfo t)
|
||
{
|
||
if (t.NextIntervention.Length == 0 || t.Maintenance != TrainMaintenanceStatus.InService) return "";
|
||
return t.NextDueDays <= 0
|
||
? $" · {InterventionName(t.NextIntervention)} {T("scaduta")}"
|
||
: $" · {InterventionName(t.NextIntervention)} {T("tra")} {t.NextDueDays} {T("g")}";
|
||
}
|
||
|
||
// ------------------------------------------------------------------ cartella di manutenzione
|
||
|
||
private void BuildCard()
|
||
{
|
||
foreach (var c in _card.GetChildren()) c.QueueFree();
|
||
foreach (var c in _cardDetails.GetChildren()) c.QueueFree();
|
||
var w = _session.World;
|
||
if (_train < 0 || !w.Trains.TryGetValue(_train, out var t)) return;
|
||
_card.AddChild(UiTheme.TitleLabel(T("Cartella di manutenzione") + " · " + t.Name, 22));
|
||
var card = w.Cards.GetValueOrDefault(_train);
|
||
var stats = PanelKit.Row();
|
||
var condition = PanelKit.Stat(T("Condizione"), PanelKit.Value($"{Math.Floor(card?.Condition ?? t.Condition):0}%"));
|
||
int trainId = _train;
|
||
WhyTooltip.Attach(condition, () => new ExplainTarget(ExplainSubject.TrainCondition, trainId));
|
||
stats.AddChild(condition);
|
||
stats.AddChild(PanelKit.Stat(T("Guasti nell'anno"), PanelKit.Value($"{card?.FailuresThisYear ?? 0}")));
|
||
stats.AddChild(PanelKit.Stat(T("Costi dell'anno"), PanelKit.Value((card?.CostThisYear ?? Money.Zero).ToString())));
|
||
_card.AddChild(stats);
|
||
_card.AddChild(PanelKit.Pair(T("Stato"), PanelKit.Value(StatusName(t.Maintenance))));
|
||
if (card is not null)
|
||
{
|
||
if (card.Failure != 0)
|
||
_card.AddChild(UiTheme.Notice($"{FailureName(card.Failure)}: {ComponentName(card.FailedComponent)}" +
|
||
(card.RescueHours >= 0 ? $" · {T("soccorso tra")} {card.RescueHours:0.0} {T("ore")}" : "")));
|
||
if (card.PlannedIntervention.Length > 0 && card.MaintenanceDepot >= 0 && w.Depots.TryGetValue(card.MaintenanceDepot, out var md))
|
||
_card.AddChild(PanelKit.Pair(T("Prenotato"), PanelKit.Value($"{InterventionName(card.PlannedIntervention)} · {md.Name}")));
|
||
if (card.NextIntervention.Length > 0)
|
||
_card.AddChild(PanelKit.Pair(T("Prossimo intervento"), PanelKit.Value(card.NextDueDays <= 0
|
||
? $"{InterventionName(card.NextIntervention)} · {T("scaduto")}"
|
||
: $"{InterventionName(card.NextIntervention)} · {T("tra")} {Math.Ceiling(card.NextDueDays):0} {T("giorni")}")));
|
||
_card.AddChild(PanelKit.Pair(T("Km di servizio al giorno"), PanelKit.Value($"{card.ServiceKmPerDay:0}")));
|
||
if (card.CoveredBy >= 0 && w.Trains.TryGetValue(card.CoveredBy, out var cover))
|
||
_card.AddChild(PanelKit.Pair(T("Coperto dalla riserva"), PanelKit.Value(cover.Name)));
|
||
}
|
||
|
||
if (card is null)
|
||
{
|
||
_cardDetails.AddChild(UiTheme.Text(T("Cartella in arrivo dal server…"), 13, Palette.TextSecondary));
|
||
return;
|
||
}
|
||
|
||
foreach (var v in card.Vehicles)
|
||
{
|
||
var def = w.Data.Vehicles.FirstOrDefault(d => d.Id == v.Type);
|
||
_cardDetails.AddChild(UiTheme.Text($"{def?.NameIt ?? v.Type} #{v.Vehicle} · {v.OdometerKm / 1000:0.#} {T("mila km")} · {v.AgeYears:0.#} {T("anni")}", 13, bold: true));
|
||
if (w.Fleet?.Vehicles.FirstOrDefault(f => f.Vehicle == v.Vehicle) is { } info)
|
||
{
|
||
var value = UiTheme.Text(VehicleOutlook(info), 12, info.Superseded ? Palette.Amber : Palette.TextSecondary);
|
||
value.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||
_cardDetails.AddChild(value);
|
||
}
|
||
foreach (var c in v.Components)
|
||
{
|
||
var row = PanelKit.Row(6);
|
||
var name = UiTheme.Text(ComponentName(c.Component), 12, Palette.TextSecondary);
|
||
name.CustomMinimumSize = new Vector2(150, 0);
|
||
row.AddChild(name);
|
||
var bar = new ProgressBar { MaxValue = 100, Value = c.Condition, ShowPercentage = false, CustomMinimumSize = new Vector2(0, 10), SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||
bar.AddThemeStyleboxOverride("fill", UiTheme.Box(ConditionColor((int)c.Condition), ConditionColor((int)c.Condition), 3, 0));
|
||
row.AddChild(bar);
|
||
row.AddChild(UiTheme.Text($"{c.Condition:0}%", 12, bold: true));
|
||
_cardDetails.AddChild(row);
|
||
}
|
||
}
|
||
if (card.History.Count > 0)
|
||
{
|
||
_cardDetails.AddChild(UiTheme.Text(T("Storico"), 14, bold: true));
|
||
foreach (var h in Enumerable.Reverse(card.History).Take(6))
|
||
{
|
||
string depot = w.Depots.TryGetValue(h.Depot, out var dd) ? dd.Name : "";
|
||
_cardDetails.AddChild(UiTheme.Text($"{T("giorno")} {h.Day} · {InterventionName(h.Intervention)} · {h.Cost} · {depot}", 12, Palette.TextSecondary));
|
||
}
|
||
}
|
||
}
|
||
|
||
// controlli della cartella: costruiti alla selezione, non a ogni aggiornamento
|
||
private void BuildCardControls()
|
||
{
|
||
foreach (var c in _cardControls.GetChildren()) c.QueueFree();
|
||
var w = _session.World;
|
||
if (_train < 0 || !w.Trains.TryGetValue(_train, out var t)) return;
|
||
// politica propria del treno e riserva
|
||
var policy = new OptionButton();
|
||
policy.AddItem(T("Come la linea o la flotta"));
|
||
foreach (var p in w.Data.Maintenance.Policies) policy.AddItem(p.NameIt);
|
||
policy.Selected = t.Policy == byte.MaxValue ? 0 : t.Policy + 1;
|
||
policy.ItemSelected += i => _session.Command(new SetMaintenancePolicyCommand(MaintenanceScope.Train, _train, i == 0 ? "inherit" : PolicyIds[i - 1]), Result);
|
||
_cardControls.AddChild(PanelKit.Pair(T("Politica del treno"), new Label()));
|
||
_cardControls.AddChild(policy);
|
||
var reserve = new CheckBox { Text = T("Treno di riserva in deposito"), ButtonPressed = t.Reserve };
|
||
reserve.Toggled += on => _session.Command(new SetReserveCommand(new TrainId(_train), on), Result);
|
||
_cardControls.AddChild(reserve);
|
||
var actions = PanelKit.Row(6);
|
||
foreach (string id in new[] { "inspection", "service", "overhaul" })
|
||
{
|
||
var b = new Button { Text = InterventionName(id), SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||
b.Pressed += () => _session.Command(new ScheduleServiceCommand(new TrainId(_train), id), Result);
|
||
actions.AddChild(b);
|
||
}
|
||
_cardControls.AddChild(actions);
|
||
// rinnovo: l'intervento con effetto «renew» dei dati, vende i veicoli superati e compra i successori
|
||
if (w.Data.Maintenance.Interventions.FirstOrDefault(i => i.Effect == InterventionEffect.Renew) is { } renewal)
|
||
{
|
||
var renew = new Button { Text = renewal.NameIt };
|
||
renew.Pressed += () => _session.Command(new ScheduleServiceCommand(new TrainId(_train), renewal.Id), Result);
|
||
_cardControls.AddChild(renew);
|
||
}
|
||
}
|
||
|
||
// ------------------------------------------------------------------ rinnovo della flotta
|
||
|
||
/// <summary>Riga di obsolescenza di un veicolo: superato, successore con prestazioni e prezzo, valori, costo di manutenzione.</summary>
|
||
private string VehicleOutlook(FleetVehicleInfo v)
|
||
{
|
||
var parts = new List<string>();
|
||
if (v.Superseded)
|
||
{
|
||
parts.Add(string.Format(T("superato dal {0}"), v.SupersededYear));
|
||
var next = _session.World.Data.Vehicles.FirstOrDefault(d => d.Id == v.Successor);
|
||
if (next is not null)
|
||
parts.Add(string.Format(T("successore {0} ({1} kW, {2} km/h, {3})"), next.NameIt, next.PowerKw, next.MaxSpeedKmh, new Money(next.Price)));
|
||
}
|
||
if (!v.InProduction) parts.Add(T("fuori produzione"));
|
||
parts.Add(string.Format(T("valore {0}"), v.BookValue));
|
||
parts.Add(string.Format(T("rivendita {0}"), v.Resale));
|
||
if (v.MaintenanceFactor > 1.001f) parts.Add(string.Format(T("manutenzione ×{0:0.##}"), v.MaintenanceFactor));
|
||
return string.Join(" · ", parts);
|
||
}
|
||
|
||
private void BuildFleet()
|
||
{
|
||
foreach (var c in _fleet.GetChildren()) c.QueueFree();
|
||
var w = _session.World;
|
||
var report = w.Fleet;
|
||
_fleetShown = report;
|
||
_fleetBuilt = true;
|
||
if (report is null)
|
||
{
|
||
_fleet.AddChild(UiTheme.Text(T("Quadro della flotta in arrivo dal server…"), 13, Palette.TextSecondary));
|
||
return;
|
||
}
|
||
_fleet.AddChild(PanelKit.Pair(T("Era"), PanelKit.Value(EraName(report.Era))));
|
||
if (report.NextEra.Length > 0)
|
||
_fleet.AddChild(PanelKit.Pair(T("Prossima era"), PanelKit.Value($"{EraName(report.NextEra)} · {report.NextEraYear}")));
|
||
_fleet.AddChild(PanelKit.Pair(T("Valore della flotta"), PanelKit.Value(report.BookValueTotal.ToString())));
|
||
var superseded = report.Vehicles.Where(v => v.Superseded).ToList();
|
||
if (superseded.Count == 0)
|
||
{
|
||
_fleet.AddChild(UiTheme.Text(T("Nessun veicolo superato"), 13, Palette.TextSecondary));
|
||
return;
|
||
}
|
||
foreach (var v in superseded.Take(8))
|
||
{
|
||
var def = w.Data.Vehicles.FirstOrDefault(d => d.Id == v.Type);
|
||
string where = v.Train >= 0 && w.Trains.TryGetValue(v.Train, out var t) ? t.Name
|
||
: v.Depot >= 0 && w.Depots.TryGetValue(v.Depot, out var d) ? d.Name : "";
|
||
_fleet.AddChild(UiTheme.Text($"{def?.NameIt ?? v.Type} #{v.Vehicle} · {where} · {v.AgeYears:0.#}/{v.LifeYears} {T("anni")}", 13, bold: true));
|
||
var line = UiTheme.Text(VehicleOutlook(v), 12, Palette.Amber);
|
||
line.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||
_fleet.AddChild(line);
|
||
}
|
||
if (superseded.Count > 8)
|
||
_fleet.AddChild(UiTheme.Text(string.Format(T("e altri {0} veicoli superati"), superseded.Count - 8), 12, Palette.TextSecondary));
|
||
foreach (var r in report.Trains)
|
||
{
|
||
string name = w.Trains.TryGetValue(r.Train, out var t) ? t.Name : $"#{r.Train}";
|
||
var row = PanelKit.Row(6);
|
||
var text = UiTheme.Text(string.Format(T("{0}: {1} veicoli da rinnovare, spesa netta {2}"), name, r.Vehicles, r.NetCost), 13,
|
||
r.Affordable ? Palette.Text : Palette.Danger);
|
||
text.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||
text.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||
row.AddChild(text);
|
||
if (r.Booked)
|
||
{
|
||
// rinnovo già prenotato: niente pulsante, ripremerlo rifarebbe la prenotazione
|
||
row.AddChild(UiTheme.Text(T("rinnovo prenotato"), 13, Palette.TextSecondary));
|
||
}
|
||
else
|
||
{
|
||
int train = r.Train;
|
||
string intervention = report.RenewalIntervention;
|
||
var button = new Button { Text = T("Rinnova") };
|
||
button.Pressed += () => _session.Command(new ScheduleServiceCommand(new TrainId(train), intervention), Result);
|
||
row.AddChild(button);
|
||
}
|
||
_fleet.AddChild(row);
|
||
}
|
||
}
|
||
|
||
/// <summary>Nome italiano dell'era dal suo id in eras.json (il quadro della flotta manda l'id).</summary>
|
||
private string EraName(string id) => _session.World.Data.Eras.Eras.FirstOrDefault(e => e.Id == id)?.NameIt ?? id;
|
||
|
||
// ------------------------------------------------------------------ registro officina
|
||
|
||
private void BuildWorkshop()
|
||
{
|
||
foreach (var c in _workshop.GetChildren()) c.QueueFree();
|
||
foreach (var c in _workshopDetails.GetChildren()) c.QueueFree();
|
||
var w = _session.World;
|
||
if (_depot < 0 || !w.Depots.TryGetValue(_depot, out var d)) return;
|
||
_workshop.AddChild(UiTheme.TitleLabel(T("Registro officina") + " · " + d.Name, 22));
|
||
var reg = w.Workshops.GetValueOrDefault(_depot);
|
||
var stats = PanelKit.Row();
|
||
stats.AddChild(PanelKit.Stat(T("Stalli"), PanelKit.Value($"{d.Stalls}")));
|
||
stats.AddChild(PanelKit.Stat(T("Personale"), PanelKit.Value($"{d.StaffPercent}%")));
|
||
stats.AddChild(PanelKit.Stat(T("Ricambi"), PanelKit.Value($"{d.SpareParts}")));
|
||
_workshop.AddChild(stats);
|
||
if (d.WaitingParts) _workshop.AddChild(UiTheme.Notice(T("Ricambi esauriti: gli interventi aspettano. Porta i ricambi in treno da una fabbrica di macchinari o da un porto.")));
|
||
// sciopero del personale del deposito (ADR 0017)
|
||
WorldEventText.AddNotices(w, _workshop, WorldEventText.Depot, _depot);
|
||
if (reg is not null)
|
||
{
|
||
if (reg.WorkRate < 0.999f)
|
||
_workshopDetails.AddChild(PanelKit.Pair(T("Ritmo di lavoro (manca personale)"), PanelKit.Value($"{reg.WorkRate * 100:0}%")));
|
||
_workshopDetails.AddChild(PanelKit.Pair(T("Ricambi già destinati"), PanelKit.Value($"{reg.PartsReserved}")));
|
||
int stall = 0;
|
||
foreach (var j in reg.Jobs)
|
||
{
|
||
string train = w.Trains.TryGetValue(j.Train, out var t) ? t.Name : $"#{j.Train}";
|
||
string where = j.InStall ? $"{T("stallo")} {++stall}" : T("in coda");
|
||
string what = j.Started ? $"{j.Progress:0.0}/{j.Days:0} {T("giorni")}" : j.InStall ? T("attende i ricambi") : T("in attesa");
|
||
var line = UiTheme.Text($"{where} · {train} · {InterventionName(j.Intervention)} · {what}", 13);
|
||
line.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||
_workshopDetails.AddChild(line);
|
||
}
|
||
foreach (var j in reg.Booked)
|
||
{
|
||
string train = w.Trains.TryGetValue(j.Train, out var t) ? t.Name : $"#{j.Train}";
|
||
_workshopDetails.AddChild(UiTheme.Text($"{T("in arrivo")} · {train} · {InterventionName(j.Intervention)} · {j.Parts} {T("ricambi")}", 13, Palette.TextSecondary));
|
||
}
|
||
if (reg.Jobs.Count == 0 && reg.Booked.Count == 0) _workshopDetails.AddChild(UiTheme.Text(T("Nessun treno in officina"), 13, Palette.TextSecondary));
|
||
}
|
||
}
|
||
|
||
// scorta desiderata: costruita alla selezione del deposito
|
||
private void BuildOrderRow()
|
||
{
|
||
foreach (var c in _orderRow.GetChildren()) c.QueueFree();
|
||
var w = _session.World;
|
||
if (_depot < 0 || !w.Depots.TryGetValue(_depot, out var d)) return;
|
||
var target = new SpinBox { MinValue = 0, MaxValue = w.Data.Maintenance.Depots.MaxSpareParts, Value = d.PartsTarget, SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||
_orderRow.AddChild(UiTheme.Text(T("Scorta desiderata"), 13, Palette.TextSecondary));
|
||
_orderRow.AddChild(target);
|
||
var button = new Button { Text = T("Ordina") };
|
||
button.Pressed += () => _session.Command(new OrderPartsCommand(new DepotId(_depot), (int)target.Value), Result);
|
||
_orderRow.AddChild(button);
|
||
}
|
||
|
||
// ------------------------------------------------------------------ testi
|
||
|
||
public static string StatusName(TrainMaintenanceStatus s) => s switch
|
||
{
|
||
TrainMaintenanceStatus.Booked => T("intervento prenotato"),
|
||
TrainMaintenanceStatus.InWorkshop => T("in officina"),
|
||
TrainMaintenanceStatus.MinorFailure => T("guasto lieve"),
|
||
TrainMaintenanceStatus.Stranded => T("fermo in linea"),
|
||
TrainMaintenanceStatus.Towed => T("rimorchiato"),
|
||
_ => T("in servizio"),
|
||
};
|
||
|
||
private static string FailureName(byte f) => f switch
|
||
{
|
||
1 => T("Guasto lieve"),
|
||
2 => T("Guasto grave"),
|
||
3 => T("Deragliamento"),
|
||
_ => "",
|
||
};
|
||
|
||
public string InterventionName(string id) =>
|
||
_session.World.Data.Maintenance.Interventions.FirstOrDefault(i => i.Id == id)?.NameIt ?? id;
|
||
|
||
private string ComponentName(string id)
|
||
{
|
||
var m = _session.World.Data.Maintenance.Components;
|
||
return m.Locomotive.Concat(m.Car).FirstOrDefault(c => c.Id == id)?.NameIt ?? id;
|
||
}
|
||
|
||
/// <summary>Colore della condizione: verde sopra 70, ambra fino a 40, rosso sotto.</summary>
|
||
public static Color ConditionColor(int condition) =>
|
||
condition >= 70 ? Palette.Ok : condition >= 40 ? Palette.Amber : Palette.Danger;
|
||
}
|