F6: scheda industria e schermata di connessione definitive
La scheda dell'industria e la schermata di connessione si allineano alle
immagini di riferimento 07 e 09. I dati che mancavano li calcola il Core
con una funzione pura, e viaggiano in blocchi compatibili del protocollo.
Il formato dei salvataggi non cambia (ADR 0021).
- IndustryOutlook calcola la scheda in sola lettura:
- fattori dell'efficienza e quello che la limita;
- ingressi e uscite al mese, con giorni di scorta o di magazzino;
- fornitori e clienti con prezzo, distanza e linea che li collega;
- forza lavoro dai contratti dei pendolari;
- punteggio di crescita del trimestre con le soglie;
- prezzo medio, utile annuo, stazioni che la servono, sblocco
dell'acquisto.
IndustryMath.GrowthScore è ora l'unica formula del punteggio e la usa
anche IndustrySystem: gli hash non cambiano. Nuovi parametri in
balance.json, industry.outlook.
- Protocollo:
- IndustryCard: blocco 1 IndustrySheetInfo;
- Welcome: blocco 1 ServerInfo (versione, sistema, Docker, tempo di
attività, passo del ciclo, client collegati);
- ClientWorld conserva lo stato del server e l'elenco dei salvataggi.
- Client:
- IndustryPanel a tutto schermo, con tre schede, il grafo della
catena, impianti e crescita, e i comandi del proprietario;
- ConnectScreen sostituisce MenuScreen: server locale o in rete,
stato del server, partite salvate, «Connetti e riprendi» e «Nuova
partita sul server» su una sessione di prova;
- testi in strings.csv;
- pilota automatico: schermate 19_scheda_industria e 20_connessione.
- Test:
- IndustryOutlookTests;
- scheda e stato del server via WebSocket;
- campioni del protocollo con i blocchi nuovi.
200 test, 181 senza i lenti.
Refs #42.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7eec322202
commit
45462bf9ec
28 files changed
+2810
-329
No files matched your search
@@ -11,20 +11,35 @@ using static RailEnterprise.Client.App.Localization;
|
||||
namespace RailEnterprise.Client.Panels;
|
||||
|
||||
/// <summary>
|
||||
/// Industrie (sezione 11): elenco delle industrie della regione e pannello del proprietario
|
||||
/// dell'industria scelta: condizione degli impianti con il moltiplicatore di efficienza, budget di
|
||||
/// manutenzione, scorta di ricambi e macchinari, storico dei fermi, «Fermo programmato»,
|
||||
/// «Ammoderna», «Ordina ricambi»; per le industrie dei privati il prezzo chiesto e «Acquista».
|
||||
/// La scheda del proprietario arriva su richiesta dal server (IndustryCard).
|
||||
/// Scheda dell'industria a tutto schermo (immagine di riferimento 07, sezione 11): in alto nome,
|
||||
/// livello, proprietà, stazione che la serve, valore stimato e l'anello dell'efficienza con il
|
||||
/// fattore che la limita; sotto tre schede (materie prime in ingresso, forza lavoro, produzione), il
|
||||
/// grafo della catena produttiva con fornitori, città dei pendolari e clienti, e la scheda «Impianti
|
||||
/// e crescita» con condizione, punteggio trimestrale e soglie, comandi del proprietario e storico dei
|
||||
/// fermi. Tutti i numeri arrivano dal server nella scheda (IndustryCard, blocco 1: ADR 0021); il
|
||||
/// pannello li chiede una volta al secondo e li mostra com'è.
|
||||
/// </summary>
|
||||
public partial class IndustryPanel : VBoxContainer
|
||||
{
|
||||
private readonly GameSession _session;
|
||||
private readonly ItemList _list = new() { CustomMinimumSize = new Vector2(0, 150) };
|
||||
private readonly OptionButton _chooser = new() { CustomMinimumSize = new Vector2(320, 44), FitToLongestItem = false };
|
||||
private readonly List<int> _ids = [];
|
||||
private readonly VBoxContainer _header = PanelKit.Column(8);
|
||||
private readonly Label _title = UiTheme.TitleLabel("", 44);
|
||||
private readonly Label _subtitle = UiTheme.Text("", 15, Palette.TextSecondary);
|
||||
private readonly Label _ownerLine = UiTheme.Text("", 14, Palette.TextSecondary);
|
||||
private readonly Label _valuation = UiTheme.Text("", 26, Palette.AmberLight, bold: true);
|
||||
private readonly EfficiencyRing _ring = new();
|
||||
private readonly Label _limit = UiTheme.Text("", 13, Palette.TextSecondary);
|
||||
private readonly VBoxContainer _notices = PanelKit.Column(6);
|
||||
private readonly ScrollContainer _scroll = new() { HorizontalScrollMode = ScrollContainer.ScrollMode.Disabled, SizeFlagsVertical = SizeFlags.ExpandFill };
|
||||
private readonly VBoxContainer _inputs = PanelKit.Column(8);
|
||||
private readonly VBoxContainer _workforce = PanelKit.Column(8);
|
||||
private readonly VBoxContainer _production = PanelKit.Column(8);
|
||||
private readonly ChainGraph _graph = new();
|
||||
private readonly VBoxContainer _chainFooter = PanelKit.Column(8);
|
||||
private readonly VBoxContainer _plants = PanelKit.Column(8);
|
||||
private readonly VBoxContainer _controls = PanelKit.Column(8);
|
||||
private readonly VBoxContainer _details = PanelKit.Column(6);
|
||||
private readonly VBoxContainer _history = PanelKit.Column(4);
|
||||
private readonly Label _status = UiTheme.Text("", 13, Palette.TextSecondary);
|
||||
private readonly List<Button> _budgetButtons = [];
|
||||
private SpinBox? _partsOrder;
|
||||
@@ -33,25 +48,106 @@ public partial class IndustryPanel : VBoxContainer
|
||||
private int _entityVersion = -1, _detailVersion = -1;
|
||||
private double _request, _sinceRefresh;
|
||||
|
||||
/// <summary>«Torna alla mappa».</summary>
|
||||
public event Action? CloseRequested;
|
||||
|
||||
/// <summary>«Crea una linea verso questa industria»: strumento binari centrato sull'industria.</summary>
|
||||
public event Action<int>? PlanLineRequested;
|
||||
|
||||
public IndustryPanel(GameSession session)
|
||||
{
|
||||
_session = session;
|
||||
AddThemeConstantOverride("separation", 10);
|
||||
AddChild(UiTheme.TitleLabel(T("Industrie"), 34));
|
||||
var help = UiTheme.Text(T("Scegli un'industria nell'elenco o sulla mappa. Gli impianti si consumano con l'uso: il budget di manutenzione, i ricambi e i macchinari portati in treno li tengono in salute."), 13, Palette.TextSecondary);
|
||||
help.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
AddChild(help);
|
||||
AddChild(_list);
|
||||
AddChild(PanelKit.Separator());
|
||||
AddChild(_header);
|
||||
AddChild(_controls);
|
||||
AddChild(_details);
|
||||
AddThemeConstantOverride("separation", 14);
|
||||
SizeFlagsVertical = SizeFlags.ExpandFill;
|
||||
|
||||
// barra di navigazione: ritorno alla mappa e scelta dell'industria
|
||||
var nav = PanelKit.Row(12);
|
||||
var back = new Button { Text = "‹ " + T("Mappa"), CustomMinimumSize = new Vector2(120, 44) };
|
||||
back.Pressed += () => CloseRequested?.Invoke();
|
||||
nav.AddChild(back);
|
||||
nav.AddChild(_chooser);
|
||||
_chooser.ItemSelected += i => Select(_ids[(int)i]);
|
||||
var hint = UiTheme.Text(T("Scheda dell'industria"), 13, Palette.TextSecondary);
|
||||
hint.SizeFlagsVertical = SizeFlags.ShrinkCenter;
|
||||
nav.AddChild(hint);
|
||||
AddChild(nav);
|
||||
|
||||
// intestazione: nome, livello, proprietà, valore ed efficienza
|
||||
var header = PanelKit.Row(24);
|
||||
var titles = PanelKit.Column(2);
|
||||
titles.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||||
_title.TextOverrunBehavior = TextServer.OverrunBehavior.TrimEllipsis;
|
||||
titles.AddChild(_title);
|
||||
titles.AddChild(_subtitle);
|
||||
_ownerLine.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
titles.AddChild(_ownerLine);
|
||||
header.AddChild(titles);
|
||||
var value = PanelKit.Column(0);
|
||||
value.SizeFlagsVertical = SizeFlags.ShrinkCenter;
|
||||
var valueCaption = UiTheme.Text(T("Valore stimato"), 13, Palette.TextSecondary);
|
||||
valueCaption.HorizontalAlignment = HorizontalAlignment.Right;
|
||||
_valuation.HorizontalAlignment = HorizontalAlignment.Right;
|
||||
value.AddChild(valueCaption);
|
||||
value.AddChild(_valuation);
|
||||
header.AddChild(value);
|
||||
var ring = PanelKit.Column(2);
|
||||
ring.AddChild(_ring);
|
||||
_limit.HorizontalAlignment = HorizontalAlignment.Center;
|
||||
_limit.CustomMinimumSize = new Vector2(150, 0);
|
||||
_limit.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
ring.AddChild(_limit);
|
||||
header.AddChild(ring);
|
||||
AddChild(header);
|
||||
AddChild(_notices);
|
||||
|
||||
// corpo scorrevole: tre schede, poi catena produttiva e impianti
|
||||
AddChild(_scroll);
|
||||
var margin = new MarginContainer { SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||
margin.AddThemeConstantOverride("margin_right", 10);
|
||||
_scroll.AddChild(margin);
|
||||
var body = PanelKit.Column(18);
|
||||
margin.AddChild(body);
|
||||
|
||||
var cards = PanelKit.Row(18);
|
||||
cards.AddChild(Card(T("Materie prime in ingresso"), _inputs, 1));
|
||||
cards.AddChild(Card(T("Forza lavoro"), _workforce, 1));
|
||||
cards.AddChild(Card(T("Produzione"), _production, 1));
|
||||
body.AddChild(cards);
|
||||
|
||||
var lower = PanelKit.Row(18);
|
||||
var chain = PanelKit.Column(10);
|
||||
var legend = PanelKit.Row(16);
|
||||
foreach (var (text, color) in new[] { (T("merci su linea"), Palette.Amber), (T("lavoratori"), Palette.Workers), (T("personale"), Palette.Staff), (T("non collegato"), Palette.TextSecondary) })
|
||||
legend.AddChild(UiTheme.Text("— " + text, 12, color));
|
||||
chain.AddChild(legend);
|
||||
_graph.IndustryClicked += Select;
|
||||
chain.AddChild(_graph);
|
||||
chain.AddChild(_chainFooter);
|
||||
lower.AddChild(Card(T("Catena produttiva"), chain, 1.6f));
|
||||
var plants = PanelKit.Column(10);
|
||||
plants.AddChild(_plants);
|
||||
plants.AddChild(_controls);
|
||||
plants.AddChild(_history);
|
||||
_status.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
AddChild(_status);
|
||||
_list.ItemSelected += i => Select(_ids[(int)i]);
|
||||
plants.AddChild(_status);
|
||||
lower.AddChild(Card(T("Impianti e crescita"), plants, 1));
|
||||
body.AddChild(lower);
|
||||
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
/// <summary>Scheda con titolo e contenuto, larga in proporzione al rapporto dato.</summary>
|
||||
private static PanelContainer Card(string title, Control content, float ratio)
|
||||
{
|
||||
var card = new PanelContainer { SizeFlagsHorizontal = SizeFlags.ExpandFill, SizeFlagsStretchRatio = ratio };
|
||||
card.AddThemeStyleboxOverride("panel", UiTheme.Box(Palette.Panel, Palette.Border, 12, 22));
|
||||
var col = PanelKit.Column(12);
|
||||
col.AddChild(UiTheme.Text(title, 19, bold: true));
|
||||
col.AddChild(content);
|
||||
card.AddChild(col);
|
||||
return card;
|
||||
}
|
||||
|
||||
/// <summary>Industria mostrata (−1 se nessuna).</summary>
|
||||
public int Industry => _industry;
|
||||
|
||||
@@ -60,11 +156,19 @@ public partial class IndustryPanel : VBoxContainer
|
||||
if (id == _industry) return;
|
||||
_industry = id;
|
||||
_status.Text = "";
|
||||
_scroll.ScrollVertical = 0;
|
||||
SyncSelection();
|
||||
Request();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
/// <summary>Scorre il corpo della scheda (0 in cima, 1 in fondo).</summary>
|
||||
public void ScrollTo(double fraction)
|
||||
{
|
||||
var bar = _scroll.GetVScrollBar();
|
||||
_scroll.ScrollVertical = (int)Math.Round((bar.MaxValue - bar.Page) * Math.Clamp(fraction, 0, 1));
|
||||
}
|
||||
|
||||
private void Request()
|
||||
{
|
||||
if (_industry >= 0) _session.Send(new RequestDetail { Kind = DetailKind.Industry, Target = _industry });
|
||||
@@ -98,10 +202,17 @@ public partial class IndustryPanel : VBoxContainer
|
||||
if (w.EntityVersion != _entityVersion) RefreshList();
|
||||
_entityVersion = w.EntityVersion;
|
||||
_detailVersion = w.DetailVersion;
|
||||
foreach (var c in _header.GetChildren()) c.QueueFree();
|
||||
foreach (var c in _details.GetChildren()) c.QueueFree();
|
||||
foreach (var box in new[] { _notices, _inputs, _workforce, _production, _chainFooter, _plants, _history })
|
||||
foreach (var c in box.GetChildren()) c.QueueFree();
|
||||
if (_industry < 0 || !w.Industries.TryGetValue(_industry, out var ind))
|
||||
{
|
||||
_title.Text = T("Industrie");
|
||||
_subtitle.Text = T("Scegli un'industria nell'elenco in alto.");
|
||||
_ownerLine.Text = "";
|
||||
_valuation.Text = "";
|
||||
_limit.Text = "";
|
||||
_ring.Set(0, Palette.Amber);
|
||||
_graph.Visible = false;
|
||||
BuildControls(null);
|
||||
return;
|
||||
}
|
||||
@@ -109,12 +220,24 @@ public partial class IndustryPanel : VBoxContainer
|
||||
BuildHeader(w, ind, card);
|
||||
BuildControls(ind);
|
||||
UpdateControls(ind, card);
|
||||
BuildDetails(w, ind, card);
|
||||
var sheet = card?.Sheet;
|
||||
if (card is null || sheet is null)
|
||||
{
|
||||
_graph.Visible = false;
|
||||
foreach (var box in new[] { _inputs, _workforce, _production, _plants })
|
||||
box.AddChild(UiTheme.Text(T("Scheda in arrivo dal server…"), 13, Palette.TextSecondary));
|
||||
return;
|
||||
}
|
||||
BuildInputs(w, sheet);
|
||||
BuildWorkforce(w, sheet);
|
||||
BuildProduction(w, card, sheet);
|
||||
BuildChain(w, ind, card, sheet);
|
||||
BuildPlants(w, ind, card, sheet);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ elenco
|
||||
|
||||
/// <summary>Elenco: si ricostruisce solo se cambiano le industrie o il loro ordine, altrimenti si aggiornano i testi.</summary>
|
||||
/// <summary>Selettore: si ricostruisce solo se cambiano le industrie o il loro ordine, altrimenti si aggiornano i testi.</summary>
|
||||
private void RefreshList()
|
||||
{
|
||||
var w = _session.World;
|
||||
@@ -126,7 +249,7 @@ public partial class IndustryPanel : VBoxContainer
|
||||
if (!same)
|
||||
{
|
||||
_ids.Clear();
|
||||
_list.Clear();
|
||||
_chooser.Clear();
|
||||
}
|
||||
for (int n = 0; n < ordered.Count; n++)
|
||||
{
|
||||
@@ -137,13 +260,12 @@ public partial class IndustryPanel : VBoxContainer
|
||||
if (!same)
|
||||
{
|
||||
_ids.Add(ind.Id);
|
||||
_list.AddItem(text);
|
||||
_chooser.AddItem(text, n);
|
||||
}
|
||||
else if (_list.GetItemText(n) != text)
|
||||
else if (_chooser.GetItemText(n) != text)
|
||||
{
|
||||
_list.SetItemText(n, text);
|
||||
_chooser.SetItemText(n, text);
|
||||
}
|
||||
_list.SetItemCustomFgColor(n, ind.Owner == me ? Palette.AmberLight : MaintenancePanel.ConditionColor((int)ind.Condition));
|
||||
}
|
||||
if (!same) SyncSelection();
|
||||
}
|
||||
@@ -151,175 +273,341 @@ public partial class IndustryPanel : VBoxContainer
|
||||
private void SyncSelection()
|
||||
{
|
||||
int index = _ids.IndexOf(_industry);
|
||||
if (index < 0)
|
||||
{
|
||||
_list.DeselectAll();
|
||||
return;
|
||||
}
|
||||
if (!_list.IsSelected(index)) _list.Select(index);
|
||||
_list.EnsureCurrentIsVisible();
|
||||
if (index >= 0 && _chooser.Selected != index) _chooser.Select(index);
|
||||
if (index < 0) _chooser.Select(-1);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ scheda
|
||||
// ------------------------------------------------------------------ intestazione
|
||||
|
||||
private void BuildHeader(ClientWorld w, IndustryInfo ind, IndustryCard? card)
|
||||
{
|
||||
int me = w.Summary?.CompanyId ?? 0;
|
||||
var title = UiTheme.TitleLabel(ind.Name, 30);
|
||||
title.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
_header.AddChild(title);
|
||||
var def = w.Data.Industries.FirstOrDefault(d => d.Id == ind.Type);
|
||||
_header.AddChild(UiTheme.Text($"{def?.NameIt ?? ind.Type} · {T("livello")} {ind.Level}", 14, Palette.TextSecondary));
|
||||
string owner = ind.Owner == me ? T("La tua compagnia") : ind.Owner < 0 ? T("Proprietari privati") : Fmt.Company(w, ind.Owner);
|
||||
_header.AddChild(PanelKit.Pair(T("Proprietà"), PanelKit.Value(owner)));
|
||||
var sheet = card?.Sheet;
|
||||
_title.Text = ind.Name;
|
||||
string level = sheet is null ? $"{T("Livello")} {ind.Level}" : $"{T("Livello")} {sheet.Level} {T("di")} {sheet.MaxLevel}";
|
||||
_subtitle.Text = $"{TypeName(w, ind.Type)} · {level}";
|
||||
string owner = ind.Owner == me ? T("la tua compagnia") : ind.Owner < 0 ? T("proprietari privati") : Fmt.Company(w, ind.Owner);
|
||||
string served = "";
|
||||
if (sheet is not null)
|
||||
{
|
||||
var names = sheet.ServingStations.Select(s => w.Stations.TryGetValue(s, out var st) ? st.Name : $"#{s}").Take(3).ToList();
|
||||
served = names.Count == 0
|
||||
? " · " + T("nessuna stazione la serve")
|
||||
: $" · {T("servita dalla stazione")} {string.Join(", ", names)}" +
|
||||
(sheet.ServingLine >= 0 && w.Lines.TryGetValue(sheet.ServingLine, out var line) ? $" ({T("linea")} {line.Name})" : "");
|
||||
}
|
||||
_ownerLine.Text = $"{T("Proprietà")}: {owner}{served}";
|
||||
_valuation.Text = card?.Valuation.ToString() ?? "—";
|
||||
float e = sheet?.Efficiency ?? ind.Efficiency;
|
||||
var limit = sheet is null ? IndustryLimit.None : (IndustryLimit)sheet.Limit;
|
||||
_ring.Set(e, limit is IndustryLimit.None ? Palette.Ok : e < 0.35f ? Palette.Danger : Palette.Amber);
|
||||
_limit.Text = sheet is null ? T("Efficienza") : $"{T("Efficienza")} · {LimitText(limit)}";
|
||||
|
||||
long today = Fmt.Today(w);
|
||||
if (ind.StoppedUntilDay >= today)
|
||||
_header.AddChild(UiTheme.Notice($"{StopName(ind.StopKind)}: {T("ferma fino al")} {Fmt.Date(w, ind.StoppedUntilDay)} ({ind.StoppedUntilDay - today + 1} {T("giorni")})"));
|
||||
_notices.AddChild(UiTheme.Notice($"{StopName(ind.StopKind)}: {T("ferma fino al")} {Fmt.Date(w, ind.StoppedUntilDay)} ({ind.StoppedUntilDay - today + 1} {T("giorni")})"));
|
||||
else if (ind.PendingWork != 0)
|
||||
_header.AddChild(UiTheme.Notice($"{WorkName(ind.PendingWork)}: {T("attende")} {card?.MachineryRequired ?? 0} {T("macchinari")} ({T("in scorta")} {ind.Machinery})" +
|
||||
_notices.AddChild(UiTheme.Notice($"{WorkName(ind.PendingWork)}: {T("attende")} {card?.MachineryRequired ?? 0} {T("macchinari")} ({T("in scorta")} {ind.Machinery})" +
|
||||
(ind.PendingWork == 1 ? " " + T("e personale sufficiente") : "")));
|
||||
if (ind.PartsShort)
|
||||
_header.AddChild(Wrapped(T("⚠ Ricambi esauriti: il recupero degli impianti si dimezza. Portali in treno da una fabbrica di macchinari o da un porto."), 13, Palette.Danger));
|
||||
|
||||
var stats = PanelKit.Row(8);
|
||||
stats.AddChild(PanelKit.Stat(T("Condizione"), ColoredValue($"{Fmt.Number(ind.Condition, 0)}%", MaintenancePanel.ConditionColor((int)ind.Condition))));
|
||||
stats.AddChild(PanelKit.Stat(T("Resa impianti"), PanelKit.Value(card is null ? "—" : "×" + Fmt.Number(card.ConditionMultiplier, 2))));
|
||||
stats.AddChild(PanelKit.Stat(T("Efficienza"), PanelKit.Value(Fmt.Pct(ind.Efficiency, 0))));
|
||||
_header.AddChild(stats);
|
||||
var bar = new ProgressBar { MaxValue = 100, Value = ind.Condition, ShowPercentage = false, CustomMinimumSize = new Vector2(0, 10) };
|
||||
var color = MaintenancePanel.ConditionColor((int)ind.Condition);
|
||||
bar.AddThemeStyleboxOverride("fill", UiTheme.Box(color, color, 4, 0));
|
||||
_header.AddChild(bar);
|
||||
var m = w.Data.Balance.IndustryMaintenance;
|
||||
_header.AddChild(Wrapped($"{T("Sopra il")} {Fmt.Number(m.EfficiencyFullAbove, 0)}% {T("gli impianti rendono pieno; sotto calano fino a")} ×{Fmt.Number(m.EfficiencyAt20, 1)} {T("al 20% e si fermano più spesso.")}", 12, Palette.TextSecondary));
|
||||
_notices.AddChild(Wrapped(T("⚠ Ricambi esauriti: il recupero degli impianti si dimezza. Portali in treno da una fabbrica di macchinari o da un porto."), 13, Palette.Danger));
|
||||
}
|
||||
|
||||
/// <summary>Comandi del proprietario o dell'acquirente: si ricostruiscono solo se cambia l'industria o il proprietario.</summary>
|
||||
// ------------------------------------------------------------------ tre schede
|
||||
|
||||
private void BuildInputs(ClientWorld w, IndustrySheetInfo s)
|
||||
{
|
||||
if (s.Inputs.Count == 0)
|
||||
{
|
||||
_inputs.AddChild(Wrapped(T("Non consuma materie prime: estrae, coltiva o raccoglie da sé."), 13, Palette.TextSecondary));
|
||||
}
|
||||
foreach (var f in s.Inputs)
|
||||
{
|
||||
string unit = Unit(w, f.Good);
|
||||
_inputs.AddChild(FlowHeader(GoodName(w, f.Good), $"{Fmt.Number(f.CurrentMonth, 0)} / {Fmt.Number(f.FullMonth, 0)} {unit} {T("al mese")}"));
|
||||
_inputs.AddChild(Bar(f.FullMonth <= 0 ? 0 : f.CurrentMonth / f.FullMonth, f.Limiting ? Palette.Danger : Palette.Amber));
|
||||
string days = f.Days < 0 ? "" : $" · {T("bastano per")} {Fmt.Number(f.Days, 0)} {T("giorni")}";
|
||||
_inputs.AddChild(UiTheme.Text($"{T("scorta")} {f.Stock} / {f.Storage} {unit}{days}", 12, f.Limiting ? Palette.Danger : Palette.TextSecondary));
|
||||
foreach (var p in f.Partners) _inputs.AddChild(PartnerLine(w, p, unit, supplier: true));
|
||||
if (f.Partners.Count == 0) _inputs.AddChild(UiTheme.Text(T("Nessun fornitore nella regione"), 12, Palette.TextSecondary));
|
||||
_inputs.AddChild(PanelKit.Separator());
|
||||
}
|
||||
if (s.Inputs.Count > 0)
|
||||
_inputs.AddChild(PanelKit.Pair($"{T("Copertura degli ingressi")} ({s.CoverageWindowDays} {T("giorni")})", ColoredValue(Fmt.Pct(s.CovInput, 0), CoverageColor(s.CovInput))));
|
||||
}
|
||||
|
||||
private void BuildWorkforce(ClientWorld w, IndustrySheetInfo s)
|
||||
{
|
||||
WorkforceBlock(w, s.Workers, s.CovWorkers, s.CoverageWindowDays, staff: false);
|
||||
_workforce.AddChild(PanelKit.Separator());
|
||||
WorkforceBlock(w, s.Staff, s.CovStaff, s.CoverageWindowDays, staff: true);
|
||||
var limit = (IndustryLimit)s.Limit;
|
||||
if (limit is IndustryLimit.Workers or IndustryLimit.Staff)
|
||||
{
|
||||
var wf = limit == IndustryLimit.Staff ? s.Staff : s.Workers;
|
||||
string who = limit == IndustryLimit.Staff ? T("il personale qualificato") : T("i lavoratori");
|
||||
_workforce.AddChild(UiTheme.Notice($"{T("Collo di bottiglia")}: {who}. {T("Mancano")} {wf.Missing} {T("persone: portale in treno dalle città vicine.")}"));
|
||||
}
|
||||
}
|
||||
|
||||
private void WorkforceBlock(ClientWorld w, WorkforceInfo f, float coverage30, int window, bool staff)
|
||||
{
|
||||
var color = staff ? Palette.Staff : Palette.Workers;
|
||||
if (f.Jobs <= 0)
|
||||
{
|
||||
_workforce.AddChild(UiTheme.Text(staff ? T("Nessun posto per il personale") : T("Nessun posto per i lavoratori"), 13, Palette.TextSecondary));
|
||||
return;
|
||||
}
|
||||
_workforce.AddChild(FlowHeader(staff ? T("Personale qualificato") : T("Lavoratori"), $"{Fmt.Number(f.Present, 0)} / {f.Jobs} {T("presenti")}", color));
|
||||
_workforce.AddChild(Bar(f.Jobs <= 0 ? 0 : f.Present / f.Jobs, color));
|
||||
string minutes = f.AverageMinutes < 0 ? "" : $" · {T("viaggio medio")} {Fmt.Number(f.AverageMinutes, 0)} min";
|
||||
_workforce.AddChild(UiTheme.Text($"{T("copertura")} {window} {T("giorni")} {Fmt.Pct(coverage30, 0)} · {T("al lavoro ora")} {Fmt.Number(f.OnSite, 0)}{minutes}", 12, Palette.TextSecondary));
|
||||
if (f.Missing > 0)
|
||||
{
|
||||
string reason = EmploymentPanel.ReasonText(w, f.Reason, f.ReasonLine, staff);
|
||||
_workforce.AddChild(Wrapped($"{T("Mancano")} {f.Missing}" + (reason.Length > 0 ? " · " + reason : ""), 12, Palette.Amber));
|
||||
}
|
||||
foreach (var src in f.Sources)
|
||||
{
|
||||
string town = w.Towns.TryGetValue(src.Town, out var t) ? t.Name : $"#{src.Town}";
|
||||
string via = src.Walking ? T("a piedi") : src.Line >= 0 && w.Lines.TryGetValue(src.Line, out var line) ? line.Name : Fmt.Company(w, src.Carrier);
|
||||
string time = src.Walking || src.Minutes <= 0 ? "" : $" · {Fmt.Number(src.Minutes, 0)} min";
|
||||
_workforce.AddChild(Wrapped($"• {src.Headcount} {T("da")} {town} · {via}{time} · {Fmt.Pct(src.Coverage, 0)}", 12, color));
|
||||
}
|
||||
if (f.SourceCount > f.Sources.Count)
|
||||
_workforce.AddChild(UiTheme.Text($"{T("e altre")} {f.SourceCount - f.Sources.Count} {T("provenienze")}", 12, Palette.TextSecondary));
|
||||
}
|
||||
|
||||
private void BuildProduction(ClientWorld w, IndustryCard card, IndustrySheetInfo s)
|
||||
{
|
||||
foreach (var f in s.Outputs)
|
||||
{
|
||||
string unit = Unit(w, f.Good);
|
||||
_production.AddChild(FlowHeader(GoodName(w, f.Good), $"{Fmt.Number(f.CurrentMonth, 0)} / {Fmt.Number(f.FullMonth, 0)} {unit} {T("al mese")}"));
|
||||
_production.AddChild(Bar(f.FullMonth <= 0 ? 0 : f.CurrentMonth / f.FullMonth, Palette.Amber));
|
||||
string full = f.Days < 0 ? "" : f.Days <= 0 ? " · " + T("magazzino pieno") : $" · {T("pieno tra")} {Fmt.Number(f.Days, 0)} {T("giorni")}";
|
||||
_production.AddChild(UiTheme.Text($"{T("magazzino")} {f.Stock} / {f.Storage} {unit}{full}", 12, f.Days == 0 ? Palette.Danger : Palette.TextSecondary));
|
||||
foreach (var p in f.Partners) _production.AddChild(PartnerLine(w, p, unit, supplier: false));
|
||||
if (f.Partners.Count == 0) _production.AddChild(UiTheme.Text(T("Nessun cliente nella regione"), 12, Palette.TextSecondary));
|
||||
_production.AddChild(PanelKit.Separator());
|
||||
}
|
||||
if (s.Outputs.Count == 0) _production.AddChild(UiTheme.Text(T("Nessuna produzione"), 13, Palette.TextSecondary));
|
||||
_production.AddChild(PanelKit.Pair(T("Magazzino"), PanelKit.Value($"{s.StorageDays} {T("giorni di produzione")}")));
|
||||
_production.AddChild(PanelKit.Pair(T("Prezzo medio realizzato"), PanelKit.Value(s.AveragePrice < 0 ? "—" : Fmt.PricePrecise(s.AveragePrice))));
|
||||
_production.AddChild(PanelKit.Pair(T("Utile annuo stimato"), ColoredValue(s.AnnualProfit.ToString(), s.AnnualProfit.Cents < 0 ? Palette.Danger : Palette.Text)));
|
||||
_production.AddChild(PanelKit.Pair(T("Margine"), ColoredValue(Fmt.Pct(card.Margin, 0), card.Margin < 0 ? Palette.Danger : Palette.Text)));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ catena produttiva
|
||||
|
||||
private void BuildChain(ClientWorld w, IndustryInfo ind, IndustryCard card, IndustrySheetInfo s)
|
||||
{
|
||||
var left = new List<ChainNode>();
|
||||
foreach (var f in s.Inputs)
|
||||
foreach (var p in f.Partners.Take(2))
|
||||
left.Add(new ChainNode(PartnerName(w, p), $"{GoodName(w, f.Good)} · {Fmt.Number(p.MonthlyUnits, 0)} {Unit(w, f.Good)}/{T("mese")}", p.Line >= 0 ? ChainEdge.Goods : ChainEdge.Unlinked, PartnerIndustry(p)));
|
||||
foreach (var (wf, staff) in new[] { (s.Workers, false), (s.Staff, true) })
|
||||
foreach (var src in wf.Sources.Take(staff ? 1 : 2))
|
||||
left.Add(new ChainNode(w.Towns.TryGetValue(src.Town, out var t) ? t.Name : $"#{src.Town}",
|
||||
$"{src.Headcount} {(staff ? T("tecnici") : T("lavoratori"))}", staff ? ChainEdge.Staff : ChainEdge.Workers));
|
||||
var right = new List<ChainNode>();
|
||||
foreach (var f in s.Outputs)
|
||||
foreach (var p in f.Partners.Take(3))
|
||||
right.Add(new ChainNode(PartnerName(w, p), $"{GoodName(w, f.Good)} · {Fmt.PricePrecise(p.Price)}", p.Line >= 0 ? ChainEdge.Goods : ChainEdge.Unlinked, PartnerIndustry(p)));
|
||||
string outputs = string.Join(", ", s.Outputs.Select(f => GoodName(w, f.Good)));
|
||||
_graph.Set(left, new ChainNode(ind.Name, $"{T("Livello")} {s.Level} · {outputs}", ChainEdge.Goods), right);
|
||||
_graph.Visible = true;
|
||||
|
||||
// azioni della catena: linea verso l'industria e offerta di acquisto
|
||||
var actions = PanelKit.Row(10);
|
||||
var plan = UiTheme.Primary(T("Crea una linea verso questa industria"));
|
||||
plan.CustomMinimumSize = new Vector2(0, 44);
|
||||
int id = ind.Id;
|
||||
plan.Pressed += () => PlanLineRequested?.Invoke(id);
|
||||
actions.AddChild(plan);
|
||||
int me = w.Summary?.CompanyId ?? 0;
|
||||
if (ind.Owner != me)
|
||||
{
|
||||
var buy = new Button { Text = T("Fai un'offerta di acquisto"), CustomMinimumSize = new Vector2(0, 44) };
|
||||
buy.Disabled = !(s.ForSale && s.BuyUnlocked);
|
||||
buy.Pressed += () => _session.Command(new BuyIndustryCommand(new IndustryId(id), card.Valuation), Result);
|
||||
actions.AddChild(buy);
|
||||
}
|
||||
_chainFooter.AddChild(actions);
|
||||
if (ind.Owner == me)
|
||||
_chainFooter.AddChild(UiTheme.Text(T("L'industria è tua: gli utili entrano nel conto economico della compagnia."), 12, Palette.TextSecondary));
|
||||
else if (!s.ForSale)
|
||||
_chainFooter.AddChild(UiTheme.Text($"{T("Appartiene a")} {Fmt.Company(w, ind.Owner)}: {T("non è in vendita.")}", 12, Palette.TextSecondary));
|
||||
else if (!s.BuyUnlocked)
|
||||
_chainFooter.AddChild(UiTheme.Text($"{T("Disponibile al livello")} «{Fmt.Tier(w, s.BuyTier)}» ({T("avanzamento")} {Fmt.Progress(s.BuyProgress)})", 12, Palette.TextSecondary));
|
||||
else
|
||||
_chainFooter.AddChild(UiTheme.Text($"{T("Prezzo chiesto dai proprietari")}: {card.Valuation}", 12, Palette.TextSecondary));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ impianti e crescita
|
||||
|
||||
private void BuildPlants(ClientWorld w, IndustryInfo ind, IndustryCard card, IndustrySheetInfo s)
|
||||
{
|
||||
var condColor = MaintenancePanel.ConditionColor((int)ind.Condition);
|
||||
_plants.AddChild(PanelKit.Pair(T("Condizione degli impianti"), ColoredValue($"{Fmt.Number(ind.Condition, 0)}%", condColor)));
|
||||
_plants.AddChild(Bar(ind.Condition / 100f, condColor));
|
||||
_plants.AddChild(PanelKit.Pair(T("Moltiplicatore di resa"), PanelKit.Value("×" + Fmt.Number(card.ConditionMultiplier, 2))));
|
||||
_plants.AddChild(UiTheme.Text($"{T("usura")} −{Fmt.Number(card.WearPerDay, 3)} · {T("recupero")} +{Fmt.Number(card.RecoveryPerDay, 3)} {T("al giorno")}", 12, Palette.TextSecondary));
|
||||
_plants.AddChild(PanelKit.Pair(T("Rischio di fermo in un anno"), ColoredValue(Fmt.Pct(card.BreakdownChancePerYear, 0),
|
||||
card.BreakdownChancePerYear > 0.5f ? Palette.Danger : card.BreakdownChancePerYear > 0.1f ? Palette.Amber : Palette.Text)));
|
||||
if (s.ProfitFactor < 1) _plants.AddChild(PanelKit.Pair(T("Fattore di redditività"), PanelKit.Value("×" + Fmt.Number(s.ProfitFactor, 2))));
|
||||
if (s.ReserveFraction >= 0)
|
||||
_plants.AddChild(PanelKit.Pair(T("Giacimento residuo"), ColoredValue(Fmt.Pct(s.ReserveFraction, 0), s.Depletion < 1 ? Palette.Amber : Palette.Text)));
|
||||
if (s.EventCapacity < 1) _plants.AddChild(PanelKit.Pair(T("Capacità ridotta da un evento"), ColoredValue("×" + Fmt.Number(s.EventCapacity, 2), Palette.Amber)));
|
||||
|
||||
// crescita trimestrale: punteggio in corso, soglie, componenti
|
||||
_plants.AddChild(PanelKit.Separator());
|
||||
_plants.AddChild(FlowHeader(T("Punteggio di crescita"), $"{Fmt.Number(s.Score, 2)} · {T("giorno")} {s.QuarterDay} {T("di")} {s.QuarterDays}"));
|
||||
var bar = new ScoreBar();
|
||||
bar.Set(s.Score, s.LastScore, s.DowngradeThreshold, s.UpgradeThreshold);
|
||||
_plants.AddChild(bar);
|
||||
_plants.AddChild(UiTheme.Text($"{T("sotto")} {Fmt.Number(s.DowngradeThreshold, 2)} {T("perde un livello")} · {T("sopra")} {Fmt.Number(s.UpgradeThreshold, 2)} {T("per")} {s.UpgradeQuarters} {T("trimestri sale")} ({s.QuartersAbove}/{s.UpgradeQuarters})", 12, Palette.TextSecondary));
|
||||
var g = w.Data.Balance.Growth;
|
||||
_plants.AddChild(UiTheme.Text($"{T("spedito")} {Fmt.Pct(s.Shipped, 0)} ×{Fmt.Number(g.WeightShipped, 1)} · {T("copertura")} {Fmt.Pct(s.Coverage, 0)} ×{Fmt.Number(g.WeightCoverage, 1)} · {T("utile")} {Fmt.Pct(s.Profit, 0)} ×{Fmt.Number(g.WeightProfit, 1)}", 12, Palette.TextSecondary));
|
||||
if (s.LastScore >= 0) _plants.AddChild(UiTheme.Text($"{T("ultimo trimestre")} {Fmt.Number(s.LastScore, 2)}", 12, Palette.TextSecondary));
|
||||
if (!s.Served)
|
||||
_plants.AddChild(Wrapped(T("Nessun vettore la serve: il livello resta fermo finché una linea non la collega."), 12, Palette.Amber));
|
||||
else if (s.Level >= s.MaxLevel)
|
||||
_plants.AddChild(UiTheme.Text(T("Livello massimo raggiunto"), 12, Palette.Ok));
|
||||
|
||||
int me = w.Summary?.CompanyId ?? 0;
|
||||
if (ind.Owner == me)
|
||||
{
|
||||
_plants.AddChild(PanelKit.Separator());
|
||||
_plants.AddChild(PanelKit.Pair(T("Manutenzione al giorno"), PanelKit.Value(card.MaintenanceCostPerDay.ToString())));
|
||||
_plants.AddChild(PanelKit.Pair(T("Spesa di manutenzione nell'anno"), PanelKit.Value(card.MaintenanceSpentYear.ToString())));
|
||||
_plants.AddChild(PanelKit.Pair(T("Cassa dell'industria"), PanelKit.Value(card.Cash.ToString())));
|
||||
_plants.AddChild(PanelKit.Pair(T("Costo dell'ammodernamento"), PanelKit.Value(card.UpgradeCost.ToString())));
|
||||
_plants.AddChild(StockRow(T("Ricambi"), ind.SpareParts, card.PartsTarget + card.PartsOrdered, ind.PartsShort ? Palette.Danger : Palette.Amber));
|
||||
_plants.AddChild(UiTheme.Text($"{T("scorta della politica")} {card.PartsTarget} · {T("ordinati in più")} {card.PartsOrdered} · {T("consumo")} {card.PartsPerMonth} {T("al mese")}", 12, Palette.TextSecondary));
|
||||
_plants.AddChild(StockRow(T("Macchinari"), ind.Machinery, card.MachineryRequired, Palette.Workers));
|
||||
}
|
||||
|
||||
_history.AddChild(PanelKit.Separator());
|
||||
_history.AddChild(UiTheme.Text(T("Storico dei fermi"), 14, bold: true));
|
||||
if (card.Stops.Count == 0) _history.AddChild(UiTheme.Text(T("Nessun fermo finora"), 13, Palette.TextSecondary));
|
||||
foreach (var stop in Enumerable.Reverse(card.Stops).Take(6))
|
||||
_history.AddChild(UiTheme.Text($"{Fmt.Date(w, stop.Day)} · {StopName(stop.Kind)} · {stop.Days} {T("giorni")}", 13, stop.Kind is 1 or 2 ? Palette.Amber : Palette.TextSecondary));
|
||||
}
|
||||
|
||||
/// <summary>Comandi del proprietario: si ricostruiscono solo se cambia l'industria o il proprietario.</summary>
|
||||
private void BuildControls(IndustryInfo? ind)
|
||||
{
|
||||
var key = ind is null ? (-1, -1) : (ind.Id, ind.Owner);
|
||||
int me = _session.World.Summary?.CompanyId ?? 0;
|
||||
var key = ind is null || ind.Owner != me ? (-1, -1) : (ind.Id, ind.Owner);
|
||||
if (key == _controlsKey) return;
|
||||
_controlsKey = key;
|
||||
foreach (var c in _controls.GetChildren()) c.QueueFree();
|
||||
_budgetButtons.Clear();
|
||||
_partsOrder = null;
|
||||
if (ind is null) return;
|
||||
if (ind is null || ind.Owner != me) return;
|
||||
var w = _session.World;
|
||||
int me = w.Summary?.CompanyId ?? 0;
|
||||
int id = ind.Id;
|
||||
if (ind.Owner == me)
|
||||
_controls.AddChild(PanelKit.Separator());
|
||||
_controls.AddChild(UiTheme.Text(T("Budget di manutenzione"), 14, bold: true));
|
||||
var row = PanelKit.Row(6);
|
||||
var group = new ButtonGroup();
|
||||
foreach (var (budget, label) in new[] { (IndustryBudget.None, T("Nessuno")), (IndustryBudget.Base, T("Base")), (IndustryBudget.High, T("Alto")) })
|
||||
{
|
||||
_controls.AddChild(UiTheme.Text(T("Budget di manutenzione"), 14, bold: true));
|
||||
var row = PanelKit.Row(6);
|
||||
var group = new ButtonGroup();
|
||||
foreach (var (budget, label) in new[] { (IndustryBudget.None, T("Nessuno")), (IndustryBudget.Base, T("Base")), (IndustryBudget.High, T("Alto")) })
|
||||
{
|
||||
var p = w.Data.Balance.IndustryMaintenance.For(budget);
|
||||
var b = new Button { Text = label, ToggleMode = true, ButtonGroup = group, SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||
b.TooltipText = $"{T("Recupero")} {Fmt.Number(p.RecoveryPerDay, 2)} {T("punti al giorno")} · {Fmt.Pct(p.CostShareOfRevenue, 0)} {T("dei ricavi")} · {p.SparePartsPerLevelPerMonth} {T("ricambi al mese per livello")}";
|
||||
b.Pressed += () => _session.Command(new SetIndustryPolicyCommand(new IndustryId(id), budget), Result);
|
||||
_budgetButtons.Add(b);
|
||||
row.AddChild(b);
|
||||
}
|
||||
_controls.AddChild(row);
|
||||
var p = w.Data.Balance.IndustryMaintenance.For(budget);
|
||||
var b = new Button { Text = label, ToggleMode = true, ButtonGroup = group, SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||
b.TooltipText = $"{T("Recupero")} {Fmt.Number(p.RecoveryPerDay, 2)} {T("punti al giorno")} · {Fmt.Pct(p.CostShareOfRevenue, 0)} {T("dei ricavi")} · {p.SparePartsPerLevelPerMonth} {T("ricambi al mese per livello")}";
|
||||
b.Pressed += () => _session.Command(new SetIndustryPolicyCommand(new IndustryId(id), budget), Result);
|
||||
_budgetButtons.Add(b);
|
||||
row.AddChild(b);
|
||||
}
|
||||
_controls.AddChild(row);
|
||||
|
||||
var order = PanelKit.Row(6);
|
||||
var caption = UiTheme.Text(T("Ricambi extra"), 13, Palette.TextSecondary);
|
||||
caption.TooltipText = T("Ricambi da ordinare oltre la scorta della politica: diventano domanda esplicita sulle tue linee.");
|
||||
caption.MouseFilter = MouseFilterEnum.Pass;
|
||||
order.AddChild(caption);
|
||||
_partsOrder = new SpinBox { MinValue = 0, MaxValue = w.Data.Balance.IndustryMaintenance.MaxOrderedParts, SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||
order.AddChild(_partsOrder);
|
||||
var orderButton = new Button { Text = T("Ordina ricambi") };
|
||||
orderButton.Pressed += () => _session.Command(new OrderPartsCommand(DepotId.None, (int)(_partsOrder?.Value ?? 0)) { Industry = new IndustryId(id) }, Result);
|
||||
order.AddChild(orderButton);
|
||||
_controls.AddChild(order);
|
||||
var order = PanelKit.Row(6);
|
||||
var caption = UiTheme.Text(T("Ricambi extra"), 13, Palette.TextSecondary);
|
||||
caption.TooltipText = T("Ricambi da ordinare oltre la scorta della politica: diventano domanda esplicita sulle tue linee.");
|
||||
caption.MouseFilter = MouseFilterEnum.Pass;
|
||||
order.AddChild(caption);
|
||||
_partsOrder = new SpinBox { MinValue = 0, MaxValue = w.Data.Balance.IndustryMaintenance.MaxOrderedParts, SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||
order.AddChild(_partsOrder);
|
||||
var orderButton = new Button { Text = T("Ordina ricambi") };
|
||||
orderButton.Pressed += () => _session.Command(new OrderPartsCommand(DepotId.None, (int)(_partsOrder?.Value ?? 0)) { Industry = new IndustryId(id) }, Result);
|
||||
order.AddChild(orderButton);
|
||||
_controls.AddChild(order);
|
||||
|
||||
var actions = PanelKit.Row(6);
|
||||
var m = w.Data.Balance.IndustryMaintenance;
|
||||
var overhaul = new Button { Text = T("Fermo programmato"), SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||
overhaul.TooltipText = $"{T("Revisione")}: {m.OverhaulDays} {T("giorni di fermo")}, {m.OverhaulMachineryPerLevel} {T("macchinari per livello")}, {T("personale almeno al")} {Fmt.Pct(m.OverhaulMinStaffCoverage, 0)}; {T("riporta la condizione a 100.")}";
|
||||
overhaul.Pressed += () => _session.Command(new OverhaulIndustryCommand(new IndustryId(id)), Result);
|
||||
actions.AddChild(overhaul);
|
||||
var upgrade = UiTheme.Primary(T("Ammoderna"));
|
||||
upgrade.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||||
upgrade.TooltipText = $"{T("Ammodernamento di livello")}: {m.UpgradeDays} {T("giorni di fermo")}, {m.UpgradeMachineryPerLevel} {T("macchinari per livello")}";
|
||||
upgrade.Pressed += () => _session.Command(new UpgradeIndustryCommand(new IndustryId(id)), Result);
|
||||
actions.AddChild(upgrade);
|
||||
_controls.AddChild(actions);
|
||||
}
|
||||
else if (ind.Owner < 0)
|
||||
{
|
||||
_controls.AddChild(UiTheme.Text(T("In vendita"), 14, bold: true));
|
||||
var price = PanelKit.Value("—");
|
||||
price.Name = "Price";
|
||||
_controls.AddChild(PanelKit.Pair(T("Prezzo chiesto dai proprietari"), price));
|
||||
var buy = UiTheme.Primary(T("Acquista"));
|
||||
buy.Pressed += () =>
|
||||
{
|
||||
if (_session.World.IndustryCards.TryGetValue(id, out var c))
|
||||
_session.Command(new BuyIndustryCommand(new IndustryId(id), c.Valuation), Result);
|
||||
else
|
||||
Request();
|
||||
};
|
||||
_controls.AddChild(buy);
|
||||
if (Fmt.UnlockTier(w, u => u.BuyIndustry) is { } tier)
|
||||
_controls.AddChild(Wrapped($"{T("L'acquisto di industrie si sblocca al livello")} «{Fmt.Tier(w, tier)}».", 12, Palette.TextSecondary));
|
||||
}
|
||||
else
|
||||
{
|
||||
_controls.AddChild(Wrapped($"{T("Appartiene a")} {Fmt.Company(w, ind.Owner)}: {T("non è in vendita.")}", 13, Palette.TextSecondary));
|
||||
}
|
||||
var actions = PanelKit.Row(6);
|
||||
var m = w.Data.Balance.IndustryMaintenance;
|
||||
var overhaul = new Button { Text = T("Fermo programmato"), SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||
overhaul.TooltipText = $"{T("Revisione")}: {m.OverhaulDays} {T("giorni di fermo")}, {m.OverhaulMachineryPerLevel} {T("macchinari per livello")}, {T("personale almeno al")} {Fmt.Pct(m.OverhaulMinStaffCoverage, 0)}; {T("riporta la condizione a 100.")}";
|
||||
overhaul.Pressed += () => _session.Command(new OverhaulIndustryCommand(new IndustryId(id)), Result);
|
||||
actions.AddChild(overhaul);
|
||||
var upgrade = UiTheme.Primary(T("Ammoderna"));
|
||||
upgrade.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||||
upgrade.TooltipText = $"{T("Ammodernamento di livello")}: {m.UpgradeDays} {T("giorni di fermo")}, {m.UpgradeMachineryPerLevel} {T("macchinari per livello")}";
|
||||
upgrade.Pressed += () => _session.Command(new UpgradeIndustryCommand(new IndustryId(id)), Result);
|
||||
actions.AddChild(upgrade);
|
||||
_controls.AddChild(actions);
|
||||
}
|
||||
|
||||
private void UpdateControls(IndustryInfo ind, IndustryCard? card)
|
||||
{
|
||||
for (int i = 0; i < _budgetButtons.Count; i++) _budgetButtons[i].SetPressedNoSignal(i == ind.Budget);
|
||||
if (_partsOrder is not null && card is not null && !_partsOrder.GetLineEdit().HasFocus()) _partsOrder.SetValueNoSignal(card.PartsOrdered);
|
||||
if (_controls.FindChild("Price", true, false) is Label price) price.Text = card?.Valuation.ToString() ?? "—";
|
||||
}
|
||||
|
||||
private void BuildDetails(ClientWorld w, IndustryInfo ind, IndustryCard? card)
|
||||
// ------------------------------------------------------------------ pezzi
|
||||
|
||||
private static HBoxContainer FlowHeader(string name, string value, Color? color = null)
|
||||
{
|
||||
if (card is null)
|
||||
{
|
||||
_details.AddChild(UiTheme.Text(T("Scheda in arrivo dal server…"), 13, Palette.TextSecondary));
|
||||
return;
|
||||
}
|
||||
int me = w.Summary?.CompanyId ?? 0;
|
||||
_details.AddChild(UiTheme.Text(T("Impianti"), 14, bold: true));
|
||||
_details.AddChild(PanelKit.Pair(T("Usura al giorno"), PanelKit.Value("−" + Fmt.Number(card.WearPerDay, 3))));
|
||||
_details.AddChild(PanelKit.Pair(T("Recupero al giorno"), PanelKit.Value("+" + Fmt.Number(card.RecoveryPerDay, 3))));
|
||||
_details.AddChild(PanelKit.Pair(T("Rischio di fermo in un anno"), ColoredValue(Fmt.Pct(card.BreakdownChancePerYear, 0),
|
||||
card.BreakdownChancePerYear > 0.5f ? Palette.Danger : card.BreakdownChancePerYear > 0.1f ? Palette.Amber : Palette.Text)));
|
||||
_details.AddChild(PanelKit.Pair(T("Margine"), ColoredValue(Fmt.Pct(card.Margin, 0), card.Margin < 0 ? Palette.Danger : Palette.Text)));
|
||||
|
||||
if (ind.Owner == me)
|
||||
{
|
||||
_details.AddChild(PanelKit.Pair(T("Manutenzione al giorno"), PanelKit.Value(card.MaintenanceCostPerDay.ToString())));
|
||||
_details.AddChild(PanelKit.Pair(T("Spesa di manutenzione nell'anno"), PanelKit.Value(card.MaintenanceSpentYear.ToString())));
|
||||
_details.AddChild(PanelKit.Pair(T("Cassa dell'industria"), PanelKit.Value(card.Cash.ToString())));
|
||||
_details.AddChild(PanelKit.Pair(T("Costo dell'ammodernamento"), PanelKit.Value(card.UpgradeCost.ToString())));
|
||||
}
|
||||
|
||||
_details.AddChild(PanelKit.Separator());
|
||||
_details.AddChild(UiTheme.Text(T("Scorte"), 14, bold: true));
|
||||
_details.AddChild(StockRow(T("Ricambi"), ind.SpareParts, card.PartsTarget + card.PartsOrdered, ind.PartsShort ? Palette.Danger : Palette.Amber));
|
||||
_details.AddChild(UiTheme.Text($"{T("scorta della politica")} {card.PartsTarget} · {T("ordinati in più")} {card.PartsOrdered} · {T("consumo")} {card.PartsPerMonth} {T("al mese")}", 12, Palette.TextSecondary));
|
||||
_details.AddChild(StockRow(T("Macchinari"), ind.Machinery, card.MachineryRequired, Palette.Workers));
|
||||
_details.AddChild(UiTheme.Text($"{T("servono")} {card.MachineryRequired} {T("macchinari per il prossimo lavoro")}", 12, Palette.TextSecondary));
|
||||
|
||||
_details.AddChild(PanelKit.Separator());
|
||||
_details.AddChild(UiTheme.Text(T("Storico dei fermi"), 14, bold: true));
|
||||
if (card.Stops.Count == 0) _details.AddChild(UiTheme.Text(T("Nessun fermo finora"), 13, Palette.TextSecondary));
|
||||
foreach (var s in Enumerable.Reverse(card.Stops).Take(8))
|
||||
{
|
||||
var l = UiTheme.Text($"{Fmt.Date(w, s.Day)} · {StopName(s.Kind)} · {s.Days} {T("giorni")}", 13, s.Kind is 1 or 2 ? Palette.Amber : Palette.TextSecondary);
|
||||
_details.AddChild(l);
|
||||
}
|
||||
var row = PanelKit.Row(8);
|
||||
var l = UiTheme.Text(name, 15, color, bold: true);
|
||||
l.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||||
row.AddChild(l);
|
||||
row.AddChild(UiTheme.Text(value, 14, bold: true));
|
||||
return row;
|
||||
}
|
||||
|
||||
private static ProgressBar Bar(float fraction, Color color)
|
||||
{
|
||||
var bar = new ProgressBar { MaxValue = 1, Step = 0.001, Value = Math.Clamp(fraction, 0, 1), ShowPercentage = false, CustomMinimumSize = new Vector2(0, 10) };
|
||||
bar.AddThemeStyleboxOverride("fill", UiTheme.Box(color, color, 4, 0));
|
||||
return bar;
|
||||
}
|
||||
|
||||
private static Control PartnerLine(ClientWorld w, ChainPartnerInfo p, string unit, bool supplier)
|
||||
{
|
||||
string link = p.Line >= 0 && w.Lines.TryGetValue(p.Line, out var line)
|
||||
? $"{T("linea")} {line.Name}"
|
||||
: $"{T("non collegata")} · {Fmt.Number(p.DistanceKm, 1)} km";
|
||||
string amount = (ChainPartnerKind)p.Kind == ChainPartnerKind.Hub ? "" : $" · {Fmt.Number(p.MonthlyUnits, 0)} {unit}/{T("mese")}";
|
||||
string text = $"{(supplier ? "←" : "→")} {PartnerName(w, p)}{amount} · {Fmt.PricePrecise(p.Price)} · {link}";
|
||||
return Wrapped(text, 12, p.Line >= 0 ? Palette.AmberLight : Palette.TextSecondary);
|
||||
}
|
||||
|
||||
private static string PartnerName(ClientWorld w, ChainPartnerInfo p) => (ChainPartnerKind)p.Kind switch
|
||||
{
|
||||
ChainPartnerKind.Industry => w.Industries.TryGetValue(p.Target, out var i) ? i.Name : $"#{p.Target}",
|
||||
ChainPartnerKind.Hub => w.Hubs.TryGetValue(p.Target, out var h) ? h.Name : $"#{p.Target}",
|
||||
_ => w.Towns.TryGetValue(p.Target, out var t) ? t.Name : $"#{p.Target}",
|
||||
};
|
||||
|
||||
private static int PartnerIndustry(ChainPartnerInfo p) => (ChainPartnerKind)p.Kind == ChainPartnerKind.Industry ? p.Target : -1;
|
||||
|
||||
private static bool English => TranslationServer.GetLocale().StartsWith("en");
|
||||
|
||||
private static string GoodName(ClientWorld w, int good) =>
|
||||
good >= 0 && good < w.Data.Goods.Count ? (English ? w.Data.Goods[good].NameEn : w.Data.Goods[good].NameIt) : $"#{good}";
|
||||
|
||||
private static string Unit(ClientWorld w, int good) => good >= 0 && good < w.Data.Goods.Count ? w.Data.Goods[good].Unit : "";
|
||||
|
||||
private static string TypeName(ClientWorld w, string type)
|
||||
{
|
||||
var def = w.Data.Industries.FirstOrDefault(d => d.Id == type);
|
||||
return def is null ? type : English ? def.NameEn : def.NameIt;
|
||||
}
|
||||
|
||||
private static Color CoverageColor(float coverage) => coverage >= 0.9f ? Palette.Ok : coverage >= 0.5f ? Palette.Amber : Palette.Danger;
|
||||
|
||||
private static Control StockRow(string caption, int have, int target, Color color)
|
||||
{
|
||||
var row = PanelKit.Row(8);
|
||||
@@ -335,6 +623,21 @@ public partial class IndustryPanel : VBoxContainer
|
||||
|
||||
// ------------------------------------------------------------------ testi
|
||||
|
||||
/// <summary>Fattore che limita l'efficienza (IndustryLimit) nella lingua dell'interfaccia.</summary>
|
||||
public static string LimitText(IndustryLimit limit) => limit switch
|
||||
{
|
||||
IndustryLimit.None => T("a piena capacità"),
|
||||
IndustryLimit.Inputs => T("limitata dalle materie prime"),
|
||||
IndustryLimit.Workers => T("limitata dai lavoratori"),
|
||||
IndustryLimit.Staff => T("limitata dal personale"),
|
||||
IndustryLimit.Profit => T("limitata dalla redditività"),
|
||||
IndustryLimit.Condition => T("limitata dagli impianti"),
|
||||
IndustryLimit.Depletion => T("limitata dal giacimento"),
|
||||
IndustryLimit.Event => T("limitata da un evento"),
|
||||
IndustryLimit.Stopped => T("ferma"),
|
||||
_ => T("inattiva"),
|
||||
};
|
||||
|
||||
public static string StopName(byte kind) => kind switch
|
||||
{
|
||||
1 => T("Guasto"),
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
using Godot;
|
||||
using RailEnterprise.Client.App;
|
||||
|
||||
namespace RailEnterprise.Client.Panels;
|
||||
|
||||
/// <summary>Anello dell'efficienza (immagine 07, in alto a destra): arco ambra sulla percentuale.</summary>
|
||||
public partial class EfficiencyRing : Control
|
||||
{
|
||||
private float _value;
|
||||
private Color _color = Palette.Amber;
|
||||
|
||||
public EfficiencyRing() => CustomMinimumSize = new Vector2(112, 112);
|
||||
|
||||
public void Set(float value, Color color)
|
||||
{
|
||||
_value = Math.Clamp(value, 0, 1);
|
||||
_color = color;
|
||||
QueueRedraw();
|
||||
}
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
var c = Size / 2;
|
||||
float r = Math.Min(Size.X, Size.Y) / 2 - 8;
|
||||
DrawArc(c, r, 0, Mathf.Tau, 64, Palette.Inner, 10, true);
|
||||
if (_value > 0) DrawArc(c, r, -Mathf.Pi / 2, -Mathf.Pi / 2 + Mathf.Tau * _value, 64, _color, 10, true);
|
||||
string text = Fmt.Pct(_value, 0);
|
||||
var font = UiTheme.BodyBold;
|
||||
const int size = 24;
|
||||
var s = font.GetStringSize(text, HorizontalAlignment.Left, -1, size);
|
||||
DrawString(font, new Vector2(c.X - s.X / 2, c.Y + s.Y / 4), text, HorizontalAlignment.Left, -1, size, Palette.Text);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Barra del punteggio di crescita: il riempimento è il punteggio del trimestre in corso, le tacche
|
||||
/// sono le soglie di declassamento (rossa) e di promozione (verde), la lineetta l'ultimo trimestre.
|
||||
/// </summary>
|
||||
public partial class ScoreBar : Control
|
||||
{
|
||||
private float _score, _last = -1, _down, _up;
|
||||
|
||||
public ScoreBar() => CustomMinimumSize = new Vector2(0, 26);
|
||||
|
||||
public void Set(float score, float last, float down, float up)
|
||||
{
|
||||
(_score, _last, _down, _up) = (Math.Clamp(score, 0, 1), last, down, up);
|
||||
QueueRedraw();
|
||||
}
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
float h = 12, y = 7, w = Size.X;
|
||||
DrawRect(new Rect2(0, y, w, h), Palette.Inner);
|
||||
var fill = _score >= _up ? Palette.Ok : _score < _down ? Palette.Danger : Palette.Amber;
|
||||
DrawRect(new Rect2(0, y, w * _score, h), fill);
|
||||
DrawLine(new Vector2(w * _down, 2), new Vector2(w * _down, y + h + 5), Palette.Danger, 2);
|
||||
DrawLine(new Vector2(w * _up, 2), new Vector2(w * _up, y + h + 5), Palette.Ok, 2);
|
||||
if (_last >= 0) DrawLine(new Vector2(w * Math.Clamp(_last, 0, 1), y - 3), new Vector2(w * Math.Clamp(_last, 0, 1), y + h + 3), Palette.Text, 2);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Come si disegna un collegamento della catena produttiva (legenda dell'immagine 07).</summary>
|
||||
public enum ChainEdge
|
||||
{
|
||||
/// <summary>Merci su una linea della compagnia: linea piena ambra.</summary>
|
||||
Goods,
|
||||
/// <summary>Lavoratori pendolari: tratteggio blu.</summary>
|
||||
Workers,
|
||||
/// <summary>Personale qualificato: puntinato azzurro.</summary>
|
||||
Staff,
|
||||
/// <summary>Partner possibile ma non collegato: tratteggio grigio.</summary>
|
||||
Unlinked,
|
||||
}
|
||||
|
||||
/// <summary>Nodo del grafo: titolo, riga secondaria, stile del collegamento, industria da aprire (−1 se nessuna).</summary>
|
||||
public sealed record ChainNode(string Title, string Subtitle, ChainEdge Edge, int Industry = -1);
|
||||
|
||||
/// <summary>
|
||||
/// Grafo della catena produttiva: fornitori e città dei pendolari a sinistra, l'industria al centro,
|
||||
/// clienti a destra. I nodi delle industrie si aprono con un clic.
|
||||
/// </summary>
|
||||
public partial class ChainGraph : Control
|
||||
{
|
||||
private const float NodeW = 210, NodeH = 50, Gap = 10;
|
||||
private readonly List<(Rect2 Rect, ChainNode Node)> _hits = [];
|
||||
private List<ChainNode> _left = [], _right = [];
|
||||
private ChainNode? _center;
|
||||
|
||||
public event Action<int>? IndustryClicked;
|
||||
|
||||
public ChainGraph()
|
||||
{
|
||||
CustomMinimumSize = new Vector2(0, 260);
|
||||
MouseFilter = MouseFilterEnum.Stop;
|
||||
}
|
||||
|
||||
public void Set(List<ChainNode> left, ChainNode center, List<ChainNode> right)
|
||||
{
|
||||
(_left, _center, _right) = (left, center, right);
|
||||
int rows = Math.Max(3, Math.Max(left.Count, right.Count));
|
||||
CustomMinimumSize = new Vector2(0, rows * (NodeH + Gap) + 10);
|
||||
QueueRedraw();
|
||||
}
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
_hits.Clear();
|
||||
if (_center is null) return;
|
||||
float w = Size.X, h = Size.Y;
|
||||
float nodeW = Math.Min(NodeW, (w - 80) / 3);
|
||||
var centerRect = new Rect2(w / 2 - nodeW / 2, h / 2 - NodeH * 0.7f, nodeW, NodeH * 1.4f);
|
||||
var leftRects = Column(_left, 0, nodeW, h);
|
||||
var rightRects = Column(_right, w - nodeW, nodeW, h);
|
||||
for (int i = 0; i < _left.Count; i++)
|
||||
Edge(new Vector2(leftRects[i].End.X, leftRects[i].GetCenter().Y), new Vector2(centerRect.Position.X, centerRect.GetCenter().Y), _left[i].Edge);
|
||||
for (int i = 0; i < _right.Count; i++)
|
||||
Edge(new Vector2(centerRect.End.X, centerRect.GetCenter().Y), new Vector2(rightRects[i].Position.X, rightRects[i].GetCenter().Y), _right[i].Edge);
|
||||
for (int i = 0; i < _left.Count; i++) Node(leftRects[i], _left[i], false);
|
||||
for (int i = 0; i < _right.Count; i++) Node(rightRects[i], _right[i], false);
|
||||
Node(centerRect, _center, true);
|
||||
}
|
||||
|
||||
private static List<Rect2> Column(List<ChainNode> nodes, float x, float width, float height)
|
||||
{
|
||||
float total = nodes.Count * NodeH + Math.Max(0, nodes.Count - 1) * Gap;
|
||||
float y = (height - total) / 2;
|
||||
var rects = new List<Rect2>(nodes.Count);
|
||||
foreach (var _ in nodes)
|
||||
{
|
||||
rects.Add(new Rect2(x, y, width, NodeH));
|
||||
y += NodeH + Gap;
|
||||
}
|
||||
return rects;
|
||||
}
|
||||
|
||||
private void Edge(Vector2 from, Vector2 to, ChainEdge edge)
|
||||
{
|
||||
switch (edge)
|
||||
{
|
||||
case ChainEdge.Goods:
|
||||
DrawLine(from, to, Palette.Amber, 3, true);
|
||||
break;
|
||||
case ChainEdge.Workers:
|
||||
DrawDashedLine(from, to, Palette.Workers, 2.5f, 10);
|
||||
break;
|
||||
case ChainEdge.Staff:
|
||||
DrawDashedLine(from, to, Palette.Staff, 2.5f, 3);
|
||||
break;
|
||||
default:
|
||||
DrawDashedLine(from, to, Palette.Border, 2, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void Node(Rect2 rect, ChainNode node, bool center)
|
||||
{
|
||||
var border = center ? Palette.Amber : node.Edge switch
|
||||
{
|
||||
ChainEdge.Goods => Palette.AmberDark,
|
||||
ChainEdge.Workers => Palette.Workers,
|
||||
ChainEdge.Staff => Palette.Staff,
|
||||
_ => Palette.Border,
|
||||
};
|
||||
DrawStyleBox(UiTheme.Box(center ? Palette.AmberDark : Palette.Inner, border, 8, 0), rect);
|
||||
var font = UiTheme.BodyBold;
|
||||
float width = rect.Size.X - 16;
|
||||
DrawString(font, rect.Position + new Vector2(8, center ? 26 : 20), node.Title, HorizontalAlignment.Left, width, center ? 16 : 14,
|
||||
center ? Palette.AmberLight : Palette.Text);
|
||||
DrawString(UiTheme.Body, rect.Position + new Vector2(8, center ? 48 : 39), node.Subtitle, HorizontalAlignment.Left, width, 12, Palette.TextSecondary);
|
||||
if (node.Industry >= 0) _hits.Add((rect, node));
|
||||
}
|
||||
|
||||
public override void _GuiInput(InputEvent e)
|
||||
{
|
||||
if (e is not InputEventMouseButton { Pressed: true, ButtonIndex: MouseButton.Left } click) return;
|
||||
foreach (var (rect, node) in _hits)
|
||||
{
|
||||
if (!rect.HasPoint(click.Position)) continue;
|
||||
IndustryClicked?.Invoke(node.Industry);
|
||||
AcceptEvent();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user