F6: ere e obsolescenza dei veicoli
La tecnologia avanzava solo come filtro d'acquisto: nessuna notizia del cambio d'era, nessun modello «superato», due formule diverse per valore di libro e rivendita e nessun modo di sostituire i veicoli di un treno. Ora rinnovare la flotta è una scelta con costi e benefici visibili. - vehicles.json: successore per modello (validato: stessa categoria, introdotto dopo) e parametri di obsolescenza; Obsolescence, senza stato, ricava produzione, superato, successore consigliato, curva del valore (gradino all'arrivo del successore, poi ammortamento più rapido) e fattore di manutenzione: una sola fonte per patrimonio, SellVehicle, rinnovo e quadri. - Rinnovo come intervento «renewal» di maintenance.json prenotato con ScheduleService: in officina i veicoli superati si vendono e il successore prende il loro posto. Nessun comando nuovo. - EraSystem: il 1° gennaio la notizia dell'era e delle novità dell'anno lette dai dati, annotata nella Cronaca, una volta sola anche attraverso un salvataggio. - Nessuno stato nuovo, quindi il salvataggio resta alla versione 7. - IA: modelli dei progetti aggiornati quando escono di produzione e rinnovo mensile con una regola in ai.json. - Protocollo: DetailKind.Fleet (10) e FleetReport (136); client: catalogo senza i fuori produzione e con i superati segnati, rivendita, Vendi e Rinnova nel pannello Treni, sezione «Rinnovo della flotta» in Officine. - ADR 0020, STATE, ARCHITECTURE e PROTOCOL aggiornati; ErasTests (11). Accettazione F4 e F5 invariate. Refs #41. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b3a9bdb9c
commit
f7c286bf1d
39 files changed
+1648
-53
No files matched your search
@@ -677,3 +677,27 @@ una leva non oltre {0} (rimborsando {1}),,leverage no higher than {0} (by repayi
|
||||
Per il gradino {0} serve un punteggio di {1}: {2}.,,To reach {0} you need a score of {1}: {2}.
|
||||
In bancarotta non si possono chiedere prestiti,,Loans cannot be requested while bankrupt
|
||||
Fido disponibile {0} su {1}. Tasso di un nuovo prestito: {2} fisso (base {3} + rating {4} {5}) per {6} anni.,,Available credit {0} of {1}. Rate of a new loan: {2} fixed (base {3} + rating {4} {5}) for {6} years.
|
||||
Rinnovo della flotta,,Fleet renewal
|
||||
Rinnova i veicoli superati,,Renew superseded vehicles
|
||||
Rinnova,,Renew
|
||||
Era,,Era
|
||||
Prossima era,,Next era
|
||||
Valore della flotta,,Fleet value
|
||||
Nessun veicolo superato,,No superseded vehicles
|
||||
Quadro della flotta in arrivo dal server…,,Fleet overview coming from the server…
|
||||
Cassa insufficiente.,,Not enough cash.
|
||||
In produzione fino al {0}.,,In production until {0}.
|
||||
"Rinnovo: {0} veicoli superati, spesa netta {1} dopo le rivendite.",,"Renewal: {0} superseded vehicles, net cost {1} after resale."
|
||||
Seleziona i veicoli da vendere,,Select the vehicles to sell
|
||||
Superato dal {0}.,,Superseded since {0}.
|
||||
"Superato dal {0}: successore {1} ({2} kW, {3} km/h, {4}).",,"Superseded since {0}: successor {1} ({2} kW, {3} km/h, {4})."
|
||||
da rinnovare,,to renew
|
||||
e altri {0} veicoli superati,,and {0} more superseded vehicles
|
||||
fuori produzione,,out of production
|
||||
manutenzione ×{0:0.##},,maintenance ×{0:0.##}
|
||||
rivendita {0},,resale {0}
|
||||
"successore {0} ({1} kW, {2} km/h, {3})",,"successor {0} ({1} kW, {2} km/h, {3})"
|
||||
superato,,superseded
|
||||
superato dal {0},,superseded since {0}
|
||||
valore {0},,value {0}
|
||||
"{0}: {1} veicoli da rinnovare, spesa netta {2}",,"{0}: {1} vehicles to renew, net cost {2}"
|
||||
|
@@ -3,6 +3,7 @@ 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;
|
||||
|
||||
@@ -11,7 +12,8 @@ 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. Le cartelle e i registri arrivano su richiesta dal server.
|
||||
/// 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
|
||||
{
|
||||
@@ -29,12 +31,15 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
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;
|
||||
private bool _updating;
|
||||
|
||||
public event Action<bool>? HeatMapToggled;
|
||||
@@ -69,6 +74,9 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
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);
|
||||
|
||||
@@ -113,10 +121,26 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
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 Result(CommandResultMessage r) => _status.Text = r.Message;
|
||||
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()
|
||||
{
|
||||
@@ -160,6 +184,7 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
|
||||
BuildCard();
|
||||
BuildWorkshop();
|
||||
BuildFleet();
|
||||
}
|
||||
|
||||
private string DueText(TrainInfo t)
|
||||
@@ -212,6 +237,12 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
{
|
||||
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);
|
||||
@@ -261,6 +292,82 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
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;
|
||||
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(report.Era)));
|
||||
if (report.NextEra.Length > 0)
|
||||
_fleet.AddChild(PanelKit.Pair(T("Prossima era"), PanelKit.Value($"{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);
|
||||
int train = r.Train;
|
||||
var button = new Button { Text = T("Rinnova") };
|
||||
button.Pressed += () => _session.Command(new ScheduleServiceCommand(new TrainId(train), report.RenewalIntervention), Result);
|
||||
row.AddChild(button);
|
||||
_fleet.AddChild(row);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ registro officina
|
||||
|
||||
@@ -11,8 +11,11 @@ using static RailEnterprise.Client.App.Localization;
|
||||
namespace RailEnterprise.Client.Panels;
|
||||
|
||||
/// <summary>
|
||||
/// Treni: acquisto dei veicoli in un deposito, composizione, assegnazione alle linee, rientro.
|
||||
/// Ogni azione è un comando; la lista si aggiorna con i delta del server.
|
||||
/// Treni: acquisto dei veicoli in un deposito, composizione, assegnazione alle linee, rientro, vendita
|
||||
/// dei veicoli liberi e rinnovo dei treni con veicoli superati. Ogni azione è un comando; la lista si
|
||||
/// aggiorna con i delta del server. Catalogo, obsolescenza, successori e valori di rivendita vengono dal
|
||||
/// quadro della flotta (FleetReport, ADR 0020), chiesto all'apertura, a ogni nuovo giorno e dopo i comandi:
|
||||
/// il pannello non calcola nulla.
|
||||
/// </summary>
|
||||
public partial class TrainsPanel : VBoxContainer
|
||||
{
|
||||
@@ -20,10 +23,12 @@ public partial class TrainsPanel : VBoxContainer
|
||||
private readonly OptionButton _depot = new();
|
||||
private readonly OptionButton _vehicle = new();
|
||||
private readonly SpinBox _count = new() { MinValue = 1, MaxValue = 12, Value = 1 };
|
||||
private readonly Label _modelInfo = UiTheme.Text("", 13, Palette.TextSecondary);
|
||||
private readonly ItemList _inDepot = new() { SelectMode = ItemList.SelectModeEnum.Multi, CustomMinimumSize = new Vector2(0, 120) };
|
||||
private readonly LineEdit _name = new() { PlaceholderText = T("Nome del treno") };
|
||||
private readonly ItemList _trains = new() { CustomMinimumSize = new Vector2(0, 140) };
|
||||
private readonly OptionButton _line = new();
|
||||
private readonly Label _renewInfo = UiTheme.Text("", 13, Palette.TextSecondary);
|
||||
private readonly Label _status = UiTheme.Text("", 13, Palette.TextSecondary);
|
||||
private readonly List<int> _depotIds = [];
|
||||
private readonly List<VehicleDef> _catalog = [];
|
||||
@@ -31,6 +36,9 @@ public partial class TrainsPanel : VBoxContainer
|
||||
private readonly List<int> _trainIds = [];
|
||||
private readonly List<int> _lineIds = [];
|
||||
private int _version = -1;
|
||||
private FleetReport? _fleetShown;
|
||||
private long _requestedDay = long.MinValue;
|
||||
private double _sinceRequest = double.MaxValue;
|
||||
|
||||
public event Action<int>? TrainSelected;
|
||||
|
||||
@@ -46,6 +54,8 @@ public partial class TrainsPanel : VBoxContainer
|
||||
buy.AddChild(_vehicle);
|
||||
buy.AddChild(_count);
|
||||
AddChild(buy);
|
||||
_modelInfo.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
AddChild(_modelInfo);
|
||||
var buyButton = UiTheme.Primary(T("Compra veicoli"));
|
||||
buyButton.Pressed += Buy;
|
||||
AddChild(buyButton);
|
||||
@@ -57,6 +67,9 @@ public partial class TrainsPanel : VBoxContainer
|
||||
var composeButton = new Button { Text = T("Componi") };
|
||||
composeButton.Pressed += Compose;
|
||||
compose.AddChild(composeButton);
|
||||
var sellButton = new Button { Text = T("Vendi") };
|
||||
sellButton.Pressed += Sell;
|
||||
compose.AddChild(sellButton);
|
||||
AddChild(compose);
|
||||
AddChild(PanelKit.Separator());
|
||||
AddChild(UiTheme.Text(T("Treni della compagnia"), 14, bold: true));
|
||||
@@ -71,15 +84,38 @@ public partial class TrainsPanel : VBoxContainer
|
||||
var home = new Button { Text = T("Manda al deposito") };
|
||||
home.Pressed += SendHome;
|
||||
AddChild(home);
|
||||
var renew = new Button { Text = T("Rinnova i veicoli superati") };
|
||||
renew.Pressed += Renew;
|
||||
AddChild(renew);
|
||||
_renewInfo.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
AddChild(_renewInfo);
|
||||
_status.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
AddChild(_status);
|
||||
_depot.ItemSelected += _ => Refresh(force: true);
|
||||
_trains.ItemSelected += i => TrainSelected?.Invoke(_trainIds[(int)i]);
|
||||
_vehicle.ItemSelected += _ => ShowModel();
|
||||
_trains.ItemSelected += i =>
|
||||
{
|
||||
TrainSelected?.Invoke(_trainIds[(int)i]);
|
||||
ShowRenewal();
|
||||
};
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_session.World.EntityVersion != _version) Refresh(force: false);
|
||||
var w = _session.World;
|
||||
_sinceRequest += delta;
|
||||
// quadro della flotta: all'apertura e a ogni nuovo giorno; di nuovo dopo 5 s se non arriva
|
||||
long today = Fmt.Today(w);
|
||||
if (today != _requestedDay || (w.Fleet is null && _sinceRequest > 5)) RequestFleet(today);
|
||||
bool fleetChanged = !ReferenceEquals(w.Fleet, _fleetShown);
|
||||
if (w.EntityVersion != _version || fleetChanged) Refresh(force: fleetChanged);
|
||||
}
|
||||
|
||||
private void RequestFleet(long day)
|
||||
{
|
||||
_requestedDay = day;
|
||||
_sinceRequest = 0;
|
||||
_session.Send(new RequestDetail { Kind = DetailKind.Fleet, Target = 0 });
|
||||
}
|
||||
|
||||
private int Company => _session.World.Summary?.CompanyId ?? 0;
|
||||
@@ -87,7 +123,9 @@ public partial class TrainsPanel : VBoxContainer
|
||||
private void Refresh(bool force)
|
||||
{
|
||||
var w = _session.World;
|
||||
var fleet = w.Fleet;
|
||||
_version = w.EntityVersion;
|
||||
_fleetShown = fleet;
|
||||
int selectedDepot = _depot.Selected >= 0 && _depot.Selected < _depotIds.Count ? _depotIds[_depot.Selected] : -1;
|
||||
_depotIds.Clear();
|
||||
_depot.Clear();
|
||||
@@ -101,16 +139,33 @@ public partial class TrainsPanel : VBoxContainer
|
||||
|
||||
if (_catalog.Count == 0 || force)
|
||||
{
|
||||
int keep = _vehicle.Selected;
|
||||
string? keep = _vehicle.Selected >= 0 && _vehicle.Selected < _catalog.Count ? _catalog[_vehicle.Selected].Id : null;
|
||||
_catalog.Clear();
|
||||
_vehicle.Clear();
|
||||
foreach (var def in w.Data.Vehicles.Where(v => v.EraFrom <= w.Year && (v.EraTo is null || v.EraTo >= w.Year)))
|
||||
if (fleet is not null)
|
||||
{
|
||||
_catalog.Add(def);
|
||||
_vehicle.AddItem($"{def.NameIt} — {new Money(def.Price)}");
|
||||
// catalogo del server: solo i modelli in produzione, i superati segnati con il successore
|
||||
foreach (var m in fleet.Models)
|
||||
{
|
||||
if (Def(m.Type) is not { } def) continue;
|
||||
_catalog.Add(def);
|
||||
string mark = m.Superseded ? $" · {T("superato")}" + (m.Successor.Length > 0 ? $" → {Def(m.Successor)?.NameIt ?? m.Successor}" : "") : "";
|
||||
_vehicle.AddItem($"{def.NameIt} — {new Money(def.Price)}{mark}");
|
||||
}
|
||||
}
|
||||
_vehicle.Selected = keep >= 0 && keep < _catalog.Count ? keep : 0;
|
||||
else
|
||||
{
|
||||
// in attesa del quadro del server: i modelli dell'anno, senza segni
|
||||
foreach (var def in w.Data.Vehicles.Where(v => v.EraFrom <= w.Year && (v.EraTo is null || v.EraTo >= w.Year)))
|
||||
{
|
||||
_catalog.Add(def);
|
||||
_vehicle.AddItem($"{def.NameIt} — {new Money(def.Price)}");
|
||||
}
|
||||
}
|
||||
int index = keep is null ? -1 : _catalog.FindIndex(d => d.Id == keep);
|
||||
_vehicle.Selected = index >= 0 ? index : _catalog.Count > 0 ? 0 : -1;
|
||||
}
|
||||
ShowModel();
|
||||
|
||||
int depot = _depot.Selected >= 0 ? _depotIds[_depot.Selected] : -1;
|
||||
_vehicleIds.Clear();
|
||||
@@ -118,18 +173,24 @@ public partial class TrainsPanel : VBoxContainer
|
||||
foreach (var v in w.Vehicles.Values.Where(v => v.Owner == Company && v.Depot == depot && v.Train < 0).OrderBy(v => v.Id))
|
||||
{
|
||||
_vehicleIds.Add(v.Id);
|
||||
var def = w.Data.Vehicles.FirstOrDefault(d => d.Id == v.Type);
|
||||
_inDepot.AddItem($"{def?.NameIt ?? v.Type} #{v.Id}");
|
||||
var info = fleet?.Vehicles.FirstOrDefault(x => x.Vehicle == v.Id);
|
||||
string extra = info is null
|
||||
? ""
|
||||
: (info.Superseded ? $" · {T("superato")}" : "") + " · " + string.Format(T("rivendita {0}"), info.Resale);
|
||||
_inDepot.AddItem($"{Def(v.Type)?.NameIt ?? v.Type} #{v.Id}{extra}");
|
||||
if (info is { Superseded: true }) _inDepot.SetItemCustomFgColor(_inDepot.ItemCount - 1, Palette.Amber);
|
||||
}
|
||||
|
||||
var selectedTrain = _trains.GetSelectedItems() is { Length: > 0 } sel ? _trainIds[sel[0]] : -1;
|
||||
var selectedTrain = SelectedTrain;
|
||||
_trainIds.Clear();
|
||||
_trains.Clear();
|
||||
foreach (var t in w.Trains.Values.Where(t => t.Owner == Company).OrderBy(t => t.Id))
|
||||
{
|
||||
_trainIds.Add(t.Id);
|
||||
string line = t.Line >= 0 && w.Lines.TryGetValue(t.Line, out var l) ? l.Name : T("senza linea");
|
||||
_trains.AddItem($"{t.Name} · {StateName((TrainState)t.State)} · {line}");
|
||||
bool renew = fleet?.Trains.Any(r => r.Train == t.Id) == true;
|
||||
_trains.AddItem($"{t.Name} · {StateName((TrainState)t.State)} · {line}{(renew ? " · " + T("da rinnovare") : "")}");
|
||||
if (renew) _trains.SetItemCustomFgColor(_trains.ItemCount - 1, Palette.Amber);
|
||||
}
|
||||
int ti = _trainIds.IndexOf(selectedTrain);
|
||||
if (ti >= 0) _trains.Select(ti);
|
||||
@@ -146,6 +207,40 @@ public partial class TrainsPanel : VBoxContainer
|
||||
}
|
||||
int li = _lineIds.IndexOf(selectedLine);
|
||||
_line.Selected = li >= 0 ? li : Math.Min(1, _lineIds.Count - 1);
|
||||
ShowRenewal();
|
||||
}
|
||||
|
||||
private VehicleDef? Def(string id) => _session.World.Data.Vehicles.FirstOrDefault(v => v.Id == id);
|
||||
|
||||
/// <summary>Modello scelto nel catalogo: superato o no, successore con prestazioni e prezzo, ultimo anno di produzione.</summary>
|
||||
private void ShowModel()
|
||||
{
|
||||
var fleet = _session.World.Fleet;
|
||||
if (fleet is null || _vehicle.Selected < 0 || _vehicle.Selected >= _catalog.Count) { _modelInfo.Text = ""; return; }
|
||||
var model = fleet.Models.FirstOrDefault(m => m.Type == _catalog[_vehicle.Selected].Id);
|
||||
if (model is null) { _modelInfo.Text = ""; return; }
|
||||
var parts = new List<string>();
|
||||
if (model.Superseded)
|
||||
{
|
||||
var next = Def(model.Successor);
|
||||
parts.Add(next is null
|
||||
? string.Format(T("Superato dal {0}."), model.SupersededYear)
|
||||
: string.Format(T("Superato dal {0}: successore {1} ({2} kW, {3} km/h, {4})."),
|
||||
model.SupersededYear, next.NameIt, next.PowerKw, next.MaxSpeedKmh, new Money(next.Price)));
|
||||
}
|
||||
if (model.LastYear > 0) parts.Add(string.Format(T("In produzione fino al {0}."), model.LastYear));
|
||||
_modelInfo.Text = string.Join(" ", parts);
|
||||
}
|
||||
|
||||
/// <summary>Rinnovo del treno scelto: veicoli superati e spesa netta calcolati dal server.</summary>
|
||||
private void ShowRenewal()
|
||||
{
|
||||
int train = SelectedTrain;
|
||||
var renewal = train >= 0 ? _session.World.Fleet?.Trains.FirstOrDefault(r => r.Train == train) : null;
|
||||
_renewInfo.Text = renewal is null
|
||||
? ""
|
||||
: string.Format(T("Rinnovo: {0} veicoli superati, spesa netta {1} dopo le rivendite."), renewal.Vehicles, renewal.NetCost)
|
||||
+ (renewal.Affordable ? "" : " " + T("Cassa insufficiente."));
|
||||
}
|
||||
|
||||
public static string StateName(TrainState s) => s switch
|
||||
@@ -160,7 +255,12 @@ public partial class TrainsPanel : VBoxContainer
|
||||
_ => s.ToString(),
|
||||
};
|
||||
|
||||
private void Result(CommandResultMessage r) => _status.Text = r.Message;
|
||||
private void Result(CommandResultMessage r)
|
||||
{
|
||||
_status.Text = r.Message;
|
||||
// acquisti, vendite e rinnovi cambiano il quadro della flotta
|
||||
RequestFleet(Fmt.Today(_session.World));
|
||||
}
|
||||
|
||||
private void Buy()
|
||||
{
|
||||
@@ -177,7 +277,14 @@ public partial class TrainsPanel : VBoxContainer
|
||||
_session.Command(new ComposeTrainCommand(new DepotId(_depotIds[_depot.Selected]), selected, name), Result);
|
||||
}
|
||||
|
||||
private int SelectedTrain => _trains.GetSelectedItems() is { Length: > 0 } sel ? _trainIds[sel[0]] : -1;
|
||||
private void Sell()
|
||||
{
|
||||
var selected = _inDepot.GetSelectedItems().OrderBy(i => i).Select(i => _vehicleIds[i]).ToList();
|
||||
if (selected.Count == 0) { _status.Text = T("Seleziona i veicoli da vendere"); return; }
|
||||
foreach (int id in selected) _session.Command(new SellVehicleCommand(new VehicleId(id)), Result);
|
||||
}
|
||||
|
||||
private int SelectedTrain => _trains.GetSelectedItems() is { Length: > 0 } sel && sel[0] < _trainIds.Count ? _trainIds[sel[0]] : -1;
|
||||
|
||||
private void Assign()
|
||||
{
|
||||
@@ -192,4 +299,13 @@ public partial class TrainsPanel : VBoxContainer
|
||||
if (train < 0 || _depot.Selected < 0) { _status.Text = T("Seleziona un treno e un deposito"); return; }
|
||||
_session.Command(new SendToDepotCommand(new TrainId(train), new DepotId(_depotIds[_depot.Selected])), Result);
|
||||
}
|
||||
|
||||
private void Renew()
|
||||
{
|
||||
int train = SelectedTrain;
|
||||
if (train < 0) { _status.Text = T("Seleziona un treno"); return; }
|
||||
string intervention = _session.World.Fleet?.RenewalIntervention ?? "";
|
||||
if (intervention.Length == 0) { _status.Text = T("Quadro della flotta in arrivo dal server…"); return; }
|
||||
_session.Command(new ScheduleServiceCommand(new TrainId(train), intervention), Result);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user