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>
199 lines
7.9 KiB
C#
199 lines
7.9 KiB
C#
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:
|
||
// 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.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,
|
||
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));
|
||
}
|
||
|
||
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;
|
||
foreach (var (rect, node) in _hits)
|
||
{
|
||
if (!rect.HasPoint(click.Position)) continue;
|
||
IndustryClicked?.Invoke(node.Industry);
|
||
AcceptEvent();
|
||
return;
|
||
}
|
||
}
|
||
}
|