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>
732 lines
40 KiB
C#
732 lines
40 KiB
C#
using Godot;
|
||
using RailEnterprise.Client.App;
|
||
using RailEnterprise.Client.Net;
|
||
using RailEnterprise.Core.Commands;
|
||
using RailEnterprise.Core.Common;
|
||
using RailEnterprise.Core.Economy;
|
||
using RailEnterprise.Protocol.Client;
|
||
using RailEnterprise.Protocol.Messages;
|
||
using static RailEnterprise.Client.App.Localization;
|
||
|
||
namespace RailEnterprise.Client.Panels;
|
||
|
||
/// <summary>
|
||
/// 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 OptionButton _chooser = new() { CustomMinimumSize = new Vector2(320, 44), FitToLongestItem = false };
|
||
private readonly List<int> _ids = [];
|
||
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 _history = PanelKit.Column(4);
|
||
private readonly Label _status = UiTheme.Text("", 13, Palette.TextSecondary);
|
||
/// <summary>Esito dell'offerta di acquisto, accanto al pulsante (la scheda è a tutto schermo e la mappa è nascosta).</summary>
|
||
private readonly Label _buyStatus = UiTheme.Text("", 13, Palette.TextSecondary);
|
||
private Button? _overhaul, _upgrade;
|
||
private readonly List<Button> _budgetButtons = [];
|
||
private SpinBox? _partsOrder;
|
||
private int _industry = -1;
|
||
private (int Industry, int Owner) _controlsKey = (-2, -2);
|
||
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", 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);
|
||
// tooltip «perché» dell'efficienza con i termini dell'ultima produzione (ADR 0024)
|
||
WhyTooltip.Attach(_ring, () => _industry >= 0 ? new ExplainTarget(ExplainSubject.IndustryEfficiency, _industry) : null);
|
||
_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);
|
||
_buyStatus.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||
chain.AddChild(_buyStatus);
|
||
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;
|
||
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;
|
||
|
||
public void Select(int id)
|
||
{
|
||
if (id == _industry) return;
|
||
_industry = id;
|
||
_status.Text = "";
|
||
_buyStatus.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 });
|
||
}
|
||
|
||
public override void _Process(double delta)
|
||
{
|
||
// la scheda aperta si aggiorna una volta al secondo; il pannello al massimo quattro volte
|
||
_request += delta;
|
||
_sinceRefresh += delta;
|
||
if (_request >= 1)
|
||
{
|
||
_request = 0;
|
||
Request();
|
||
}
|
||
var w = _session.World;
|
||
if ((w.EntityVersion != _entityVersion || w.DetailVersion != _detailVersion) && _sinceRefresh >= 0.25) Refresh();
|
||
}
|
||
|
||
private void Result(CommandResultMessage r) => Show(_status, r);
|
||
|
||
private void Show(Label label, CommandResultMessage r)
|
||
{
|
||
label.Text = r.Message;
|
||
label.AddThemeColorOverride("font_color", r.Ok ? Palette.TextSecondary : Palette.Danger);
|
||
Request();
|
||
}
|
||
|
||
private void Refresh()
|
||
{
|
||
var w = _session.World;
|
||
_sinceRefresh = 0;
|
||
if (w.EntityVersion != _entityVersion) RefreshList();
|
||
_entityVersion = w.EntityVersion;
|
||
_detailVersion = w.DetailVersion;
|
||
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;
|
||
}
|
||
var card = w.IndustryCards.GetValueOrDefault(_industry);
|
||
BuildHeader(w, ind, card);
|
||
BuildControls(ind);
|
||
UpdateControls(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>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;
|
||
int me = w.Summary?.CompanyId ?? 0;
|
||
long today = Fmt.Today(w);
|
||
var ordered = w.Industries.Values.Where(i => !i.Closed)
|
||
.OrderBy(i => i.Owner == me ? 0 : i.Owner < 0 ? 1 : 2).ThenBy(i => i.Name, StringComparer.Ordinal).ThenBy(i => i.Id).ToList();
|
||
bool same = ordered.Count == _ids.Count && ordered.Select(i => i.Id).SequenceEqual(_ids);
|
||
if (!same)
|
||
{
|
||
_ids.Clear();
|
||
_chooser.Clear();
|
||
}
|
||
for (int n = 0; n < ordered.Count; n++)
|
||
{
|
||
var ind = ordered[n];
|
||
string owner = ind.Owner == me ? T("tua") : ind.Owner < 0 ? T("privati") : Fmt.Company(w, ind.Owner);
|
||
string stop = ind.StoppedUntilDay >= today ? " · " + T("ferma") : "";
|
||
string text = $"{ind.Name} · {Fmt.Number(ind.Condition, 0)}% · {owner}{stop}";
|
||
if (!same)
|
||
{
|
||
_ids.Add(ind.Id);
|
||
_chooser.AddItem(text, n);
|
||
}
|
||
else if (_chooser.GetItemText(n) != text)
|
||
{
|
||
_chooser.SetItemText(n, text);
|
||
}
|
||
}
|
||
if (!same) SyncSelection();
|
||
}
|
||
|
||
private void SyncSelection()
|
||
{
|
||
int index = _ids.IndexOf(_industry);
|
||
if (index >= 0 && _chooser.Selected != index) _chooser.Select(index);
|
||
if (index < 0) _chooser.Select(-1);
|
||
}
|
||
|
||
// ------------------------------------------------------------------ intestazione
|
||
|
||
private void BuildHeader(ClientWorld w, IndustryInfo ind, IndustryCard? card)
|
||
{
|
||
int me = w.Summary?.CompanyId ?? 0;
|
||
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)
|
||
_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)
|
||
_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)
|
||
_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));
|
||
}
|
||
|
||
// ------------------------------------------------------------------ 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(Wrapped($"{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, f.Good, 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";
|
||
// OnSite sono i posti coperti da chi vive negli alloggi dell'industria, non i presenti
|
||
_workforce.AddChild(Wrapped($"{T("copertura")} {window} {T("giorni")} {Fmt.Pct(coverage30, 0)} · {T("in sede")} {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(Wrapped($"{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(Wrapped($"{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, f.Good, 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")}")));
|
||
var sale = PanelKit.Pair(T("Prezzo di vendita"), PanelKit.Value(s.SalePrice < 0 ? "—" : Fmt.PricePrecise(s.SalePrice)));
|
||
// le industrie vendono al prezzo globale del giorno (ADR 0004): si spiega quello
|
||
if (s.SalePrice >= 0 && s.Outputs.Count == 1)
|
||
{
|
||
int good = s.Outputs[0].Good;
|
||
WhyTooltip.Attach(sale, () => new ExplainTarget(ExplainSubject.GlobalPrice, good));
|
||
}
|
||
_production.AddChild(sale);
|
||
_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 += () =>
|
||
{
|
||
_buyStatus.Text = T("Offerta inviata…");
|
||
_buyStatus.AddThemeColorOverride("font_color", Palette.TextSecondary);
|
||
_session.Command(new BuyIndustryCommand(new IndustryId(id), card.Valuation), r => Show(_buyStatus, r));
|
||
};
|
||
actions.AddChild(buy);
|
||
}
|
||
_chainFooter.AddChild(actions);
|
||
if (ind.Owner == me)
|
||
_chainFooter.AddChild(Wrapped(T("L'industria è tua: gli utili entrano nel conto economico della compagnia."), 12, Palette.TextSecondary));
|
||
else if (ind.Owner < 0 && !s.ForSale)
|
||
_chainFooter.AddChild(Wrapped(T("Industria inattiva: non è in vendita finché non riprende a produrre."), 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(Wrapped($"{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());
|
||
var scoreHeader = FlowHeader(T("Punteggio di crescita"), $"{Fmt.Number(s.Score, 2)} · {T("giorno")} {s.QuarterDay} {T("di")} {s.QuarterDays}");
|
||
_plants.AddChild(scoreHeader);
|
||
var bar = new ScoreBar();
|
||
bar.Set(s.Score, s.LastScore, s.DowngradeThreshold, s.UpgradeThreshold);
|
||
int scored = _industry;
|
||
WhyTooltip.Attach(scoreHeader, () => new ExplainTarget(ExplainSubject.IndustryGrowth, scored));
|
||
WhyTooltip.Attach(bar, () => new ExplainTarget(ExplainSubject.IndustryGrowth, scored));
|
||
_plants.AddChild(bar);
|
||
_plants.AddChild(Wrapped($"{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(Wrapped($"{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(Wrapped($"{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)
|
||
{
|
||
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;
|
||
_overhaul = _upgrade = null;
|
||
if (ind is null || ind.Owner != me) return;
|
||
var w = _session.World;
|
||
int id = ind.Id;
|
||
_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")) })
|
||
{
|
||
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 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);
|
||
overhaul.SetMeta(BaseTooltip, overhaul.TooltipText);
|
||
actions.AddChild(overhaul);
|
||
_overhaul = 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);
|
||
upgrade.SetMeta(BaseTooltip, upgrade.TooltipText);
|
||
actions.AddChild(upgrade);
|
||
_upgrade = 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);
|
||
|
||
// revisione e ammodernamento: il server li rifiuta durante un fermo, con un lavoro già in
|
||
// programma o (l'ammodernamento) al livello massimo; il pulsante lo dice prima
|
||
string busy = ind.StoppedUntilDay >= Fmt.Today(_session.World) ? T("L'industria è ferma: riprova a fermo finito.")
|
||
: ind.PendingWork != 0 ? T("C'è già un lavoro in programma.") : "";
|
||
var sheet = card?.Sheet;
|
||
string top = sheet is not null && sheet.Level >= sheet.MaxLevel ? T("Livello massimo raggiunto") : "";
|
||
Gate(_overhaul, busy);
|
||
Gate(_upgrade, busy.Length > 0 ? busy : top);
|
||
}
|
||
|
||
private const string BaseTooltip = "base_tooltip";
|
||
|
||
/// <summary>Abilita il pulsante, o lo disabilita con il motivo in testa al suggerimento.</summary>
|
||
private static void Gate(Button? button, string reason)
|
||
{
|
||
if (button is null) return;
|
||
button.Disabled = reason.Length > 0;
|
||
string tip = button.GetMeta(BaseTooltip, "").AsString();
|
||
button.TooltipText = reason.Length > 0 ? reason + "\n" + tip : tip;
|
||
}
|
||
|
||
// ------------------------------------------------------------------ pezzi
|
||
|
||
private static HBoxContainer FlowHeader(string name, string value, Color? color = null)
|
||
{
|
||
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, int good, 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}";
|
||
var label = Wrapped(text, 12, p.Line >= 0 ? Palette.AmberLight : Palette.TextSecondary);
|
||
// prezzo del partner spiegato dal server: locale per le industrie che comprano, globale per chi vende e per
|
||
// le città; quello degli hub è il prezzo mondiale con il dazio, senza spiegazione
|
||
var kind = (ChainPartnerKind)p.Kind;
|
||
int target = p.Target;
|
||
if (kind == ChainPartnerKind.Industry && !supplier) WhyTooltip.Attach(label, () => new ExplainTarget(ExplainSubject.LocalPrice, good, target));
|
||
else if (kind != ChainPartnerKind.Hub) WhyTooltip.Attach(label, () => new ExplainTarget(ExplainSubject.GlobalPrice, good));
|
||
return label;
|
||
}
|
||
|
||
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);
|
||
var name = UiTheme.Text(caption, 13, Palette.TextSecondary);
|
||
name.CustomMinimumSize = new Vector2(96, 0);
|
||
row.AddChild(name);
|
||
var bar = new ProgressBar { MaxValue = Math.Max(1, Math.Max(have, target)), Value = have, ShowPercentage = false, CustomMinimumSize = new Vector2(0, 10), SizeFlagsHorizontal = SizeFlags.ExpandFill, SizeFlagsVertical = SizeFlags.ShrinkCenter };
|
||
bar.AddThemeStyleboxOverride("fill", UiTheme.Box(color, color, 3, 0));
|
||
row.AddChild(bar);
|
||
row.AddChild(UiTheme.Text($"{have} / {target}", 13, bold: true));
|
||
return row;
|
||
}
|
||
|
||
// ------------------------------------------------------------------ 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"),
|
||
2 => T("Incidente grave"),
|
||
3 => T("Revisione"),
|
||
4 => T("Ammodernamento"),
|
||
_ => T("Fermo"),
|
||
};
|
||
|
||
private static string WorkName(byte work) => work switch
|
||
{
|
||
1 => T("Revisione programmata"),
|
||
2 => T("Ammodernamento programmato"),
|
||
_ => "",
|
||
};
|
||
|
||
private static Label ColoredValue(string text, Color color)
|
||
{
|
||
var l = PanelKit.Value(text);
|
||
l.AddThemeColorOverride("font_color", color);
|
||
return l;
|
||
}
|
||
|
||
private static Label Wrapped(string text, int size, Color? color)
|
||
{
|
||
var l = UiTheme.Text(text, size, color);
|
||
l.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||
return l;
|
||
}
|
||
}
|