F6: scheda industria e connessione, correzioni della revisione

Correzioni dalla revisione della scheda industria e della schermata di
connessione.

- Dati di altre compagnie: la forza lavoro della scheda mostra solo i
  contratti a piedi, quelli della compagnia della sessione e, se
  l'industria è sua, quelli di tutti i vettori, come il Registro degli
  impieghi. Lo stesso filtro vale per provenienze, conteggio e viaggio
  medio.
- Prezzo: «prezzo medio realizzato» mescolava una media mobile dei
  ricavi con i totali del trimestre in corso. Al suo posto c'è il prezzo
  di vendita, cioè il prezzo globale del giorno (SalePrice).
- Avvisi del server: hanno il giorno −1, così il rifiuto di Load o
  NewGame non si confonde più con gli eventi del mondo che arrivano
  mentre si aspetta il Welcome.
- Schermata di connessione:
  - all'apertura avvia la strada scelta l'ultima volta;
  - cambiando strada chiude la sessione dell'altra;
  - senza sessione «Connetti e riprendi» la apre;
  - il cambio di lingua passa la sessione alla schermata nuova;
  - la scelta del salvataggio si tiene per id;
  - Load e nuova partita chiedono conferma;
  - stato del server su 3×2 con la versione del protocollo, salvataggi
    su tre colonne, «Attivo da» che avanza.
- Scheda dell'industria:
  - collegamenti e nodi non collegati sono leggibili;
  - testo per l'industria inattiva;
  - revisione e ammodernamento disabilitati, con il motivo, quando il
    server li rifiuterebbe;
  - l'esito dell'acquisto compare accanto al pulsante;
  - le righe lunghe vanno a capo;
  - «in sede» al posto di «al lavoro ora».
- Gli avvisi dei comandi compaiono anche sulle schermate a tutto
  schermo.
- Pilota automatico:
  - la schermata 20 sta su un suo CanvasLayer sopra l'interfaccia;
  - 12 e 12b sono ora la scheda a tutto schermo.
- Test: pendolari di altri vettori nascosti, Load rifiutato via
  WebSocket, Welcome senza ServerInfo. 202 test, 183 senza i lenti.

Refs #42.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-08 14:29:14 +01:00
1 parent 45462bf9ec
commit 0667a4a544
17 files changed
+514 -156

No files matched your search

@@ -41,6 +41,9 @@ public partial class IndustryPanel : VBoxContainer
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;
@@ -123,6 +126,8 @@ public partial class IndustryPanel : VBoxContainer
_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);
@@ -156,6 +161,7 @@ public partial class IndustryPanel : VBoxContainer
if (id == _industry) return;
_industry = id;
_status.Text = "";
_buyStatus.Text = "";
_scroll.ScrollVertical = 0;
SyncSelection();
Request();
@@ -188,10 +194,12 @@ public partial class IndustryPanel : VBoxContainer
if ((w.EntityVersion != _entityVersion || w.DetailVersion != _detailVersion) && _sinceRefresh >= 0.25) Refresh();
}
private void Result(CommandResultMessage r)
private void Result(CommandResultMessage r) => Show(_status, r);
private void Show(Label label, CommandResultMessage r)
{
_status.Text = r.Message;
_status.AddThemeColorOverride("font_color", r.Ok ? Palette.TextSecondary : Palette.Danger);
label.Text = r.Message;
label.AddThemeColorOverride("font_color", r.Ok ? Palette.TextSecondary : Palette.Danger);
Request();
}
@@ -327,7 +335,7 @@ public partial class IndustryPanel : VBoxContainer
_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));
_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, unit, supplier: true));
if (f.Partners.Count == 0) _inputs.AddChild(UiTheme.Text(T("Nessun fornitore nella regione"), 12, Palette.TextSecondary));
_inputs.AddChild(PanelKit.Separator());
@@ -361,7 +369,8 @@ public partial class IndustryPanel : VBoxContainer
_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));
// 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);
@@ -375,7 +384,7 @@ public partial class IndustryPanel : VBoxContainer
_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));
_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)
@@ -386,14 +395,14 @@ public partial class IndustryPanel : VBoxContainer
_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));
_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, 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("Prezzo di vendita"), PanelKit.Value(s.SalePrice < 0 ? "—" : Fmt.PricePrecise(s.SalePrice))));
_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)));
}
@@ -430,12 +439,19 @@ public partial class IndustryPanel : VBoxContainer
{
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);
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(UiTheme.Text(T("L'industria è tua: gli utili entrano nel conto economico della compagnia."), 12, Palette.TextSecondary));
_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)
@@ -452,7 +468,7 @@ public partial class IndustryPanel : VBoxContainer
_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(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))));
@@ -466,9 +482,9 @@ public partial class IndustryPanel : VBoxContainer
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));
_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(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));
_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));
@@ -484,7 +500,7 @@ public partial class IndustryPanel : VBoxContainer
_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(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));
}
@@ -505,6 +521,7 @@ public partial class IndustryPanel : VBoxContainer
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;
@@ -540,12 +557,16 @@ public partial class IndustryPanel : VBoxContainer
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);
}
@@ -553,6 +574,26 @@ public partial class IndustryPanel : VBoxContainer
{
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
@@ -148,21 +148,25 @@ public partial class ChainGraph : Control
DrawDashedLine(from, to, Palette.Staff, 2.5f, 3);
break;
default:
DrawDashedLine(from, to, Palette.Border, 2, 8);
// grigio leggibile sul fondo della scheda (il bordo dei pannelli sparirebbe)
DrawDashedLine(from, to, Palette.TextSecondary, 2, 8);
break;
}
}
private void Node(Rect2 rect, ChainNode node, bool center)
{
bool unlinked = !center && node.Edge == ChainEdge.Unlinked;
var border = center ? Palette.Amber : node.Edge switch
{
ChainEdge.Goods => Palette.AmberDark,
ChainEdge.Workers => Palette.Workers,
ChainEdge.Staff => Palette.Staff,
_ => Palette.Border,
_ => Palette.Inner,
};
DrawStyleBox(UiTheme.Box(center ? Palette.AmberDark : Palette.Inner, border, 8, 0), rect);
// partner non collegato: bordo tratteggiato grigio, come «Opportunità non collegata» nell'immagine 07
if (unlinked) DashedRect(rect.Grow(-1), Palette.TextSecondary);
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,
@@ -171,6 +175,15 @@ public partial class ChainGraph : Control
if (node.Industry >= 0) _hits.Add((rect, node));
}
private void DashedRect(Rect2 r, Color color)
{
var (a, b, c, d) = (r.Position, new Vector2(r.End.X, r.Position.Y), r.End, new Vector2(r.Position.X, r.End.Y));
DrawDashedLine(a, b, color, 1.5f, 6);
DrawDashedLine(b, c, color, 1.5f, 6);
DrawDashedLine(c, d, color, 1.5f, 6);
DrawDashedLine(d, a, color, 1.5f, 6);
}
public override void _GuiInput(InputEvent e)
{
if (e is not InputEventMouseButton { Pressed: true, ButtonIndex: MouseButton.Left } click) return;