Eine Zeile oben in der Ecke der Leistenseite (380x52): Statuspunkt, ECHTGELD, Satz, darunter was laeuft / die Meldung / die letzte Entscheidung, Zug-Uhr, Hauptknopf, Not-Aus, Ausklappen, Beenden. Doppelklick, der Pfeil oder Strg+Alt+C klappt wieder aus. cockpit.json meldet form "pille" (Kacheln wie am Mac). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
152 lines
6.8 KiB
C#
152 lines
6.8 KiB
C#
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using Microsoft.UI.Xaml.Media;
|
|
using Microsoft.UI.Xaml.Shapes;
|
|
using Pokerfreak.Cockpit.Kern;
|
|
|
|
namespace Pokerfreak.Cockpit.Seiten;
|
|
|
|
/// <summary>
|
|
/// Eingeklappt (Wurzel.swift `Pille`): ein Satz, ein Punkt, der Countdown und der Not-Aus. Das reicht
|
|
/// zum Mitlaufen. Minimieren klappt hierher (wie Gelb am Mac), Doppelklick oder der Pfeil klappt wieder aus.
|
|
/// </summary>
|
|
public sealed class Pille : UserControl
|
|
{
|
|
private readonly CockpitZustand _z;
|
|
private readonly Action _ausklappen, _beenden;
|
|
private readonly Border _flaeche = new() { CornerRadius = new CornerRadius(8), Padding = new Thickness(14, 0, 8, 0) };
|
|
private readonly Ellipse _punkt = Ui.Punkt("grau", 11);
|
|
private readonly Border _echtgeld = Ui.Abzeichen("ECHTGELD", "rot");
|
|
private readonly TextBlock _satz = Ui.Text("", 13, fett: true);
|
|
private readonly TextBlock _unter = Ui.Text("", 11);
|
|
private readonly ZugRing _uhr = new(28);
|
|
private readonly Button _haupt;
|
|
private readonly FontIcon _hauptZeichen = Ui.Zeichen("", 17);
|
|
private readonly Grid _notAus = new() { Width = 28, Height = 28 };
|
|
private readonly NotAusKnopf _notAusKnopf;
|
|
private readonly LoesenKnopf _loesen;
|
|
|
|
public Pille(CockpitZustand z, Action ausklappen, Action beenden)
|
|
{
|
|
_z = z;
|
|
_ausklappen = ausklappen;
|
|
_beenden = beenden;
|
|
foreach (var t in new[] { _satz, _unter })
|
|
{
|
|
t.TextTrimming = TextTrimming.CharacterEllipsis;
|
|
t.TextWrapping = TextWrapping.NoWrap;
|
|
}
|
|
_haupt = new Button
|
|
{
|
|
Content = _hauptZeichen,
|
|
Padding = new Thickness(5),
|
|
MinWidth = 0,
|
|
MinHeight = 0,
|
|
Background = Ui.Weiss(0),
|
|
BorderThickness = new Thickness(0),
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
};
|
|
_haupt.Click += (_, _) => _z.HauptknopfDruecken();
|
|
_notAusKnopf = new NotAusKnopf(28, () => _z.NotAusSetzen());
|
|
_loesen = new LoesenKnopf(28, () => _z.NotAusLoesen());
|
|
_notAus.Children.Add(_notAusKnopf);
|
|
_notAus.Children.Add(_loesen);
|
|
|
|
var texte = Ui.Spalte(1, _satz, _unter);
|
|
texte.VerticalAlignment = VerticalAlignment.Center;
|
|
var zeile = new Grid { ColumnSpacing = 8 };
|
|
foreach (var breite in new[] { GridLength.Auto, GridLength.Auto, new GridLength(1, GridUnitType.Star),
|
|
GridLength.Auto, GridLength.Auto, GridLength.Auto, GridLength.Auto, GridLength.Auto })
|
|
zeile.ColumnDefinitions.Add(new ColumnDefinition { Width = breite });
|
|
_punkt.VerticalAlignment = VerticalAlignment.Center;
|
|
_echtgeld.VerticalAlignment = VerticalAlignment.Center;
|
|
_uhr.VerticalAlignment = VerticalAlignment.Center;
|
|
_notAus.VerticalAlignment = VerticalAlignment.Center;
|
|
var aus = Ui.Symbolknopf("", "Als Leiste ausklappen (Strg+Alt+C)", () => _ausklappen(), 13);
|
|
var zu = Ui.Symbolknopf("", "Cockpit beenden", () => _beenden(), 11);
|
|
aus.VerticalAlignment = zu.VerticalAlignment = VerticalAlignment.Center;
|
|
zeile.Children.Add(_punkt);
|
|
zeile.Children.Add(_echtgeld.Spalte(1));
|
|
zeile.Children.Add(texte.Spalte(2));
|
|
zeile.Children.Add(_uhr.Spalte(3));
|
|
zeile.Children.Add(_haupt.Spalte(4));
|
|
zeile.Children.Add(_notAus.Spalte(5));
|
|
zeile.Children.Add(aus.Spalte(6));
|
|
zeile.Children.Add(zu.Spalte(7));
|
|
_flaeche.Child = zeile;
|
|
_flaeche.DoubleTapped += (_, _) => _ausklappen();
|
|
Content = _flaeche;
|
|
}
|
|
|
|
/// <summary>Aus dem Zustand neu zeichnen (wie die Statuszeile der Cash-Seite).</summary>
|
|
public void Zeichnen()
|
|
{
|
|
var k = _z.Ansicht.Kopf;
|
|
string satz, ton;
|
|
if (!_z.Verbunden) { satz = _z.JemalsVerbunden ? $"Server weg - {_z.Getrennt}" : _z.Getrennt; ton = "grau"; }
|
|
else
|
|
{
|
|
satz = k.Obj("status").Text("satz") ?? k.Text("text") ?? "liest …";
|
|
ton = k.Obj("status").Text("farbe") ?? "grau";
|
|
}
|
|
_punkt.Fill = Ui.Pinsel(ton);
|
|
_satz.Text = satz;
|
|
ToolTipService.SetToolTip(_satz, satz);
|
|
|
|
bool cash = _z.Wahl.Cash && !_z.Ansicht.Zuschauen;
|
|
_echtgeld.Visibility = cash ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
// Darunter: was gerade auf Antwort wartet, sonst die letzte Meldung, sonst die letzte Entscheidung
|
|
string? unter = null, unterTon = "grau";
|
|
if (_z.Laufend.Count > 0)
|
|
{
|
|
unter = "läuft: " + string.Join(", ", _z.Laufend.Select(x => x.Replace('_', ' ')));
|
|
unterTon = "blau";
|
|
}
|
|
else if (_z.Meldung is { } m)
|
|
{
|
|
unter = m.Text;
|
|
unterTon = m.Ok ? "gruen" : "orange";
|
|
}
|
|
else if (_z.Ansicht.Jetzt is { } j && j.Obj("entscheidung") is { } e)
|
|
{
|
|
unter = string.Join(" · ", new[] { e.Text("aktion_text") ?? e.Text("aktion"), j.Text("raum") }
|
|
.Where(s => !string.IsNullOrEmpty(s)));
|
|
}
|
|
_unter.Text = unter ?? "";
|
|
_unter.Foreground = Ui.Pinsel(unterTon);
|
|
_unter.Visibility = string.IsNullOrEmpty(unter) ? Visibility.Collapsed : Visibility.Visible;
|
|
|
|
// Hauptknopf (nur das Zeichen) - Not-Aus loesen geht ueber den Halteknopf daneben
|
|
var knopf = _z.Knopf;
|
|
bool notAus = _z.NotAus;
|
|
_haupt.Visibility = knopf.Wirksam() && knopf != HauptArt.NotAusLoesen && !notAus ? Visibility.Visible : Visibility.Collapsed;
|
|
_hauptZeichen.Glyph = knopf.Zeichen();
|
|
_hauptZeichen.Foreground = Ui.Pinsel(knopf.Ton());
|
|
_haupt.IsEnabled = _z.Laufend.Count == 0;
|
|
ToolTipService.SetToolTip(_haupt, knopf.Titel());
|
|
_notAusKnopf.Visibility = notAus ? Visibility.Collapsed : Visibility.Visible;
|
|
_loesen.Visibility = notAus ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
// Glas wie die Leiste: rot getoent in Echtgeld und bei Not-Aus
|
|
_flaeche.Background = notAus ? Ui.Pinsel("rot", 0.35) : cash ? Ui.Pinsel("rot", 0.18) : Ui.Weiss(0);
|
|
_flaeche.BorderBrush = notAus || cash ? Ui.Pinsel("rot", 0.7) : Ui.Weiss(0.10);
|
|
_flaeche.BorderThickness = new Thickness(notAus || cash ? 1.5 : 0.5);
|
|
Takt();
|
|
}
|
|
|
|
/// <summary>Countdown des offenen Zugs (jede Sekunde); ohne Zug keine Uhr.</summary>
|
|
public void Takt()
|
|
{
|
|
var zug = _z.Ansicht.Jetzt?.Obj("zug");
|
|
if (zug != null && zug.Wahr("offen") && zug.Zahl("bis") is double bis)
|
|
{
|
|
var rest = Math.Max(0, bis - Format.Jetzt());
|
|
var ganz = zug.Zahl("frist_s") is double f && f > 0 ? f : Math.Max(rest, 1);
|
|
_uhr.Setzen(Math.Clamp(rest / ganz, 0, 1), rest);
|
|
_uhr.Visibility = Visibility.Visible;
|
|
}
|
|
else _uhr.Visibility = Visibility.Collapsed;
|
|
}
|
|
}
|