using System.Runtime.InteropServices.WindowsRuntime; using System.Text.Json.Nodes; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Imaging; using Microsoft.UI.Xaml.Shapes; using Pokerfreak.Cockpit.Kern; using Windows.UI; namespace Pokerfreak.Cockpit.Seiten; /// /// Die Live-Ansicht unter dem Cash-Kopf nach Tische.swift `LiveAnsicht`: die Sitzungsleiste, die /// Werkzeug-Kacheln fuer alle Tische, "Alle Tische (n)" als Chips, dann je Tisch eine Kachel (sonst /// "Bis zum Spielen"), Such-Kacheln, und eingeklappt "Geld" und "Gerade eben". Fertig gerechnet vom /// Server (sicht/abgeleitet.py) - hier wird nur gezeichnet. Ein Block baut nur bei neuem Abdruck neu. /// public sealed class LiveTeil : UserControl { private readonly CockpitZustand _z; private readonly ContentControl _leiste = Breit(), _chips = Breit(), _such = Breit(), _bereit = Breit(); private readonly StackPanel _kacheln = new() { Spacing = 10 }; private readonly Grid _kachelKopf = Ui.Abschnitt("Tische", "Klick holt nach vorn"); private readonly Einklappen _geld = new("Geld", "", "ein.geld", true), _feed = new("Gerade eben", "", "ein.feed", false); private readonly Border _schliessenFrage; private readonly TextBlock _schliessenText = Ui.Text("", 12, umbruch: true); private readonly Werkzeug _pause, _vorn, _anordnen, _foto, _schliessen; private readonly Dictionary _kachelVon = new(); private readonly Dictionary _abdruck = new(); private string _kachelFolge = "", _geldAbdruck = "", _feedAbdruck = ""; public LiveTeil(CockpitZustand z) { _z = z; _pause = new Werkzeug("Pause", "", false, () => _z.PauseUmschalten()); _vorn = new Werkzeug("Nach vorn", "", false, () => _ = _z.Senden(("tische_vorn", null))); _anordnen = new Werkzeug("Anordnen", "", false, () => _ = _z.Senden(("tische_anordnen", null))); _foto = new Werkzeug("Foto", "", false, () => _ = _z.Senden(("foto", null))); _schliessen = new Werkzeug("Schließen", "", true, () => _schliessenFrage!.Visibility = Visibility.Visible); var leiste = new Grid { ColumnSpacing = 6 }; var alle = new[] { _pause, _vorn, _anordnen, _foto, _schliessen }; for (int i = 0; i < alle.Length; i++) { leiste.ColumnDefinitions.Add(new ColumnDefinition()); leiste.Children.Add(alle[i].Spalte(i)); } var nein = new Button { Content = "Abbrechen", FontSize = 12 }; nein.Click += (_, _) => _schliessenFrage!.Visibility = Visibility.Collapsed; var ja = new Button { Content = "Schließen", FontSize = 12, Background = Ui.Pinsel("rot"), Foreground = Ui.Pinsel("") }; ja.Click += (_, _) => { _schliessenFrage!.Visibility = Visibility.Collapsed; _ = _z.Senden(("tische_schliessen", null)); }; var frage = new Grid { ColumnSpacing = 8 }; frage.ColumnDefinitions.Add(new ColumnDefinition()); frage.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); frage.Children.Add(_schliessenText); frage.Children.Add(Ui.Reihe(6, nein, ja).Mit(r => r.VerticalAlignment = VerticalAlignment.Center).Spalte(1)); _schliessenFrage = Ui.Getoent(frage, "rot", 0.12, 10, 8); _schliessenFrage.Visibility = Visibility.Collapsed; Content = Ui.Spalte(10, _leiste, leiste, _schliessenFrage, _chips, _bereit, _kachelKopf, _kacheln, _such, _geld, _feed); } private static ContentControl Breit() => new() { HorizontalContentAlignment = HorizontalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, }; public void Takt() { foreach (var k in _kachelVon.Values) k.Takt(); } /// Setzt den Inhalt nur, wenn sich der Abdruck geaendert hat. private void Block(ContentControl c, JsonNode? daten, Func bauen) { var a = daten.Abdruck(); if (_abdruck.TryGetValue(c, out var alt) && alt == a) return; _abdruck[c] = a; var e = bauen(); c.Content = e; c.Visibility = e == null ? Visibility.Collapsed : Visibility.Visible; } public void Zeichnen() { var a = _z.Ansicht; var live = a.Sitzen.Obj("live"); int anzahl = (int)(live.Zahl("anzahl") ?? 0); _pause.Setzen(_z.Pausiert ? "Fortsetzen" : "Pause", _z.Pausiert ? "" : "", _z.Verbunden); ToolTipService.SetToolTip(_pause, _z.Pausiert ? "Fortsetzen - der Läufer spielt weiter" : "Pause - der Läufer klickt nicht mehr, Tische und Sitz bleiben (du kannst manuell spielen). Kein Schließen, umkehrbar."); foreach (var w in new[] { _vorn, _anordnen, _foto, _schliessen }) w.An = _z.Verbunden && anzahl > 0; foreach (var w in new[] { _vorn, _anordnen, _foto }) w.Laeuft = _z.Laufend.Contains(w == _vorn ? "tische_vorn" : w == _anordnen ? "tische_anordnen" : "foto"); _schliessenText.Text = live.Text("schliessen_frage") ?? "Alle Tische schließen?"; Block(_leiste, a.Kopf.Obj("sitzungsleiste"), () => Sitzungsleiste(a.Kopf.Obj("sitzungsleiste"))); Block(_chips, live?["chips"], () => Chips(live.Objekte("chips").ToList())); Block(_such, live == null ? null : new JsonArray(live["such"]?.DeepClone(), live["such_titel"]?.DeepClone()), () => Such(live)); Block(_bereit, live?["bereit"], () => Bereit(live.Obj("bereit"))); var kacheln = live.Objekte("kacheln").ToList(); _kachelKopf.Visibility = kacheln.Count > 0 ? Visibility.Visible : Visibility.Collapsed; Kacheln(kacheln); _geld.Hinweis = _z.Wahl.Cash ? "Echtgeld" : "Übung"; Geld(a.Geld.Obj("anzeige")); Feed(a.Entscheidungen.Liste("feed")); } // ---- Sitzungsleiste ------------------------------------------------------------------------ /// Das Ergebnis der laufenden (sonst letzten) Sitzung gross, neun Kennzahlen, Abstand zum Stop. private static UIElement? Sitzungsleiste(JsonObject? s) { if (s == null || !s.Wahr("da")) return null; var kopf = Ui.Zeile(Ui.Reihe(6, Ui.Punkt(s.Wahr("laeuft") ? "gruen" : "grau", 7), Ui.Text(s.T("titel"), 12, pinsel: Ui.Zweit, fett: true)), s.Text("ende") is { Length: > 0 } ende ? Ui.Winzig(ende, s.Wahr("warn") ? Ui.Pinsel("orange") : Ui.Dritt, fett: s.Wahr("warn")) : null); var gross = Ui.Reihe(8, Ui.Gross(s.T("geld"), 30, s.T("ton"))); if (s.Text("bb") is { Length: > 0 } bb) gross.Children.Add(Ui.Text(bb, 13, s.T("ton"), fett: true).Mit(t => { t.VerticalAlignment = VerticalAlignment.Bottom; t.Margin = new Thickness(0, 0, 0, 6); })); var zellen = new Grid { ColumnSpacing = 6, RowSpacing = 6 }; for (int i = 0; i < 3; i++) zellen.ColumnDefinitions.Add(new ColumnDefinition()); int n = 0; foreach (var z in s.Objekte("zellen")) { if (n % 3 == 0) zellen.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); var c = Ui.Flaeche(Ui.Spalte(1, Ui.Winzig(z.T("titel")), Ui.Gross(z.T("wert"), 15, z.Text("ton") is { Length: > 0 } t ? t : null)), 10, 0.05, 8); Grid.SetRow(c, n / 3); Grid.SetColumn(c, n % 3); zellen.Children.Add(c); n++; } var teile = Ui.Spalte(8, kopf, gross, zellen); if (s.Zahl("stopp_anteil") is double anteil) teile.Children.Add(Ui.Spalte(3, Balken(anteil, s.T("stopp_ton"), 5), Ui.Winzig(s.T("stopp_text")))); return Ui.Flaeche(teile, 14, 0.05, 12); } /// Ein Balken wie `ProgressView(value:)`: Kapsel in .quaternary, gefuellt in Farbe. internal static Grid Balken(double anteil, string ton, double hoehe = 6, bool vonRechts = false) { var g = new Grid { Height = hoehe }; g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(Math.Clamp(anteil, 0, 1), GridUnitType.Star) }); g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1 - Math.Clamp(anteil, 0, 1), GridUnitType.Star) }); g.Children.Add(new Border { Background = Ui.Weiss(0.10), CornerRadius = new CornerRadius(hoehe / 2) }.Mit(b => Grid.SetColumnSpan(b, 2))); var fuell = new Border { Background = Ui.Pinsel(ton, 0.85), CornerRadius = new CornerRadius(hoehe / 2) }; if (vonRechts) { g.FlowDirection = FlowDirection.RightToLeft; } g.Children.Add(fuell); return g; } // ---- Alle Tische (Chips) -------------------------------------------------------------------- private UIElement? Chips(List chips) { if (chips.Count == 0) return null; var reihe = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, Padding = new Thickness(0, 0, 0, 2) }; foreach (var c in chips) { var raum = c.T("raum"); var inhalt = Ui.Spalte(3, Ui.Reihe(4, Ui.Punkt(c.T("punkt_ton"), 6), Ui.Text(c.T("titel"), 10.5, fett: true)), Ui.Text(c.T("zeile"), 10.5, c.T("zeile_ton"), fett: c.T("zeile_ton") != "grau", zahlen: true)); var karte = new Border { Width = 104, Padding = new Thickness(8, 6, 8, 6), CornerRadius = new CornerRadius(10), Background = Ui.Weiss(0.06), BorderBrush = c.Wahr("am_zug") ? Ui.Pinsel("orange") : null, BorderThickness = new Thickness(c.Wahr("am_zug") ? 1.5 : 0), Child = inhalt, }; reihe.Children.Add(karte.Tippen(() => _ = _z.SendenRaum(raum, ("tische_vorn", null)), 10, $"{raum} nach vorn holen")); } return Ui.Spalte(4, Ui.Winzig($"Alle Tische ({chips.Count})", fett: true), new ScrollViewer { Content = reihe, HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden, VerticalScrollBarVisibility = ScrollBarVisibility.Disabled, HorizontalScrollMode = ScrollMode.Enabled, VerticalScrollMode = ScrollMode.Disabled, }); } // ---- Kacheln ------------------------------------------------------------------------------- private void Kacheln(List kacheln) { var folge = string.Join("|", kacheln.Select(k => k.T("raum"))); if (folge != _kachelFolge) { _kachelFolge = folge; var neu = new Dictionary(); _kacheln.Children.Clear(); foreach (var k in kacheln) { var raum = k.T("raum"); var kachel = _kachelVon.TryGetValue(raum, out var alt) ? alt : new TischKachel(_z, raum); neu[raum] = kachel; _kacheln.Children.Add(kachel); } _kachelVon.Clear(); foreach (var (r, k) in neu) _kachelVon[r] = k; } foreach (var k in kacheln) if (_kachelVon.TryGetValue(k.T("raum"), out var kachel)) kachel.Setzen(k, _z.Fotos.GetValueOrDefault(k.T("raum"))); _kacheln.Visibility = kacheln.Count > 0 ? Visibility.Visible : Visibility.Collapsed; } // ---- Suche / Bereit ------------------------------------------------------------------------ /// Je fehlenden Tisch eine gestrichelte Such-Kachel: die Luecke ist Absicht, kein Haenger. private static UIElement? Such(JsonObject? live) { int n = (int)(live.Zahl("such") ?? 0); if (live == null || n <= 0) return null; var spalte = Ui.Spalte(10); for (int i = 0; i < n; i++) { var kopf = Ui.Zeile(Ui.Reihe(6, Ui.Zeichen(live.T("such_titel").StartsWith("Warte") ? "" : "", 13, "grau"), Ui.Text(live.T("such_titel"), 13, fett: true)), new ProgressRing { IsActive = true, Width = 14, Height = 14 }); var rahmen = new Grid(); rahmen.Children.Add(new Rectangle { RadiusX = 10, RadiusY = 10, Stroke = Ui.Pinsel("grau", 0.5), StrokeThickness = 1, StrokeDashArray = new DoubleCollection { 5, 4 }, }); rahmen.Children.Add(Ui.Spalte(6, kopf, Ui.Klein(live.T("such_text"), true)).Mit(s => s.Margin = new Thickness(10))); spalte.Children.Add(rahmen); } return spalte; } private static readonly string[] SchrittZeichen = { "", "", "", "", "" }; /// Sitzt der Laeufer nirgends: fuenf Schritte als Leiste, "Als Naechstes", die letzte Sitzung. private static UIElement? Bereit(JsonObject? b) { if (b == null) return null; var schritte = b.Objekte("schritte").ToList(); var leiste = new Grid(); for (int i = 0; i < schritte.Count; i++) { if (i > 0) leiste.ColumnDefinitions.Add(new ColumnDefinition()); leiste.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); } for (int i = 0; i < schritte.Count; i++) { var s = schritte[i]; bool erledigt = s.Wahr("erledigt"), aktuell = s.Wahr("aktuell"); string ton = erledigt ? "gruen" : aktuell ? "blau" : "grau"; if (i > 0) leiste.Children.Add(new Border { Height = 2, CornerRadius = new CornerRadius(1), VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, 15, 0, 0), Background = erledigt ? Ui.Pinsel("gruen", 0.6) : Ui.Weiss(0.12), }.Spalte(2 * i - 1)); var kreis = new Grid { Width = 32, Height = 32, HorizontalAlignment = HorizontalAlignment.Center }; kreis.Children.Add(new Ellipse { Fill = erledigt ? Ui.Pinsel("gruen", 0.18) : aktuell ? Ui.Pinsel("blau", 0.2) : Ui.Weiss(0.06), Stroke = Ui.Pinsel(ton, erledigt || aktuell ? 0.9 : 0.3), StrokeThickness = aktuell ? 2 : 1, }); kreis.Children.Add(Ui.Zeichen(erledigt ? "" : SchrittZeichen[Math.Min(i, 4)], 12, ton) .Mit(z => { z.HorizontalAlignment = HorizontalAlignment.Center; z.VerticalAlignment = VerticalAlignment.Center; })); var knoten = Ui.Spalte(5, kreis, Ui.Text(s.T("kurz"), 9.5, pinsel: aktuell ? Ui.Pinsel("") : Ui.Zweit, fett: aktuell) .Mit(t => t.HorizontalAlignment = HorizontalAlignment.Center)); leiste.Children.Add(knoten.Spalte(2 * i)); } UIElement weiter; if (b.Text("naechst") is { Length: > 0 } n) { var g = new Grid { ColumnSpacing = 8 }; g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); g.ColumnDefinitions.Add(new ColumnDefinition()); g.Children.Add(Ui.Zeichen("", 14, "blau").Mit(z => z.VerticalAlignment = VerticalAlignment.Top)); g.Children.Add(Ui.Spalte(2, Ui.Text(n, 13, fett: true), Ui.Klein(b.T("tun"), true)).Spalte(1)); weiter = Ui.Getoent(g, "blau", 0.12, 10); } else weiter = Ui.Reihe(6, Ui.Zeichen("", 14, "gruen"), Ui.Text("Alles bereit", 13, "gruen", fett: true)); var spalte = Ui.Spalte(10, Ui.Abschnitt("Bis zum Spielen"), Ui.Flaeche(Ui.Spalte(12, leiste, weiter), 14, 0.05, 12)); if (b.Obj("sitzung") is { } s2) { spalte.Children.Add(Ui.Abschnitt("Letzte Sitzung", s2.T("wann"))); spalte.Children.Add(SitzungsKarte(s2)); } return spalte; } /// Die letzte Sitzung (Ueberblick.swift `SitzungsKarte`): Ergebnis gross, daneben Tisch/Haende/Dauer, rechts warum sie endete. private static Border SitzungsKarte(JsonObject s) { var g = new Grid { ColumnSpacing = 14 }; g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); g.ColumnDefinitions.Add(new ColumnDefinition()); g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); if (s.Wahr("hat_zahl")) { g.Children.Add(Ui.Spalte(0, Ui.Gross(s.T("netto"), 30, s.T("netto_ton")), Ui.Text("bb", 12, pinsel: Ui.Zweit, fett: true))); var info = Ui.Spalte(4); info.Children.Add(Ui.Reihe(5, Ui.Zeichen("", 10, "grau"), Ui.Klein(s.T("raum")))); info.Children.Add(Ui.Reihe(5, Ui.Zeichen("", 10, "grau"), Ui.Klein(s.T("haende")))); if (s.Text("dauer") is { Length: > 0 } d) info.Children.Add(Ui.Reihe(5, Ui.Zeichen("", 10, "grau"), Ui.Klein(d))); info.VerticalAlignment = VerticalAlignment.Center; g.Children.Add(info.Spalte(1)); } if (s.Text("ende") is { Length: > 0 } e) { bool abbruch = s.Wahr("ende_abbruch"); string glyph = abbruch ? "" : e.StartsWith("Not-Aus") ? "" : e.StartsWith("Zeitplan") ? "" : e.StartsWith("Stopp") ? "" : e.StartsWith("von dir") ? "" : ""; var ende = Ui.Spalte(4, Ui.Zeichen(glyph, 16, abbruch ? "rot" : "grau").Mit(z => z.HorizontalAlignment = HorizontalAlignment.Center), Ui.Text(e, 10, abbruch ? "rot" : "grau", umbruch: true).Mit(t => { t.TextAlignment = TextAlignment.Center; t.HorizontalAlignment = HorizontalAlignment.Center; })); var box = new Border { Width = 92, Padding = new Thickness(4, 8, 4, 8), CornerRadius = new CornerRadius(10), Background = abbruch ? Ui.Pinsel("rot", 0.12) : Ui.Weiss(0.05), Child = ende, VerticalAlignment = VerticalAlignment.Center, }; g.Children.Add(box.Spalte(2)); } return Ui.Flaeche(g, 14, 0.05, 12); } // ---- Geld gegen die Stops ------------------------------------------------------------------ private void Geld(JsonObject? g) { var a = g.Abdruck(); if (a == _geldAbdruck) return; _geldAbdruck = a; _geld.Visibility = g == null ? Visibility.Collapsed : Visibility.Visible; var inhalt = Ui.Spalte(12); if (g.Text("hinweis") is { Length: > 0 } h) inhalt.Children.Add(Ui.Klein(h, true)); foreach (var s in g.Objekte("skalen")) { bool gross = s.Wahr("gross"); var kopf = Ui.Zeile(Ui.Text(s.T("titel"), gross ? 13 : 12, fett: gross), Ui.Text(s.T("netto"), gross ? 13 : 12, s.T("netto_ton"), fett: true, zahlen: true)); // Mitte = 0; Minus waechst nach links zum Stopp, Plus nach rechts var spur = new Grid { ColumnSpacing = 2 }; spur.ColumnDefinitions.Add(new ColumnDefinition()); spur.ColumnDefinitions.Add(new ColumnDefinition()); double anteil = s.Zahl("anteil") ?? 0; spur.Children.Add(Balken(s.Wahr("minus") ? anteil : 0, s.T("ton"), gross ? 8 : 5, vonRechts: true)); spur.Children.Add(Balken(s.Wahr("minus") ? 0 : anteil, s.T("ton"), gross ? 8 : 5).Spalte(1)); var fuss = new Grid(); fuss.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); fuss.ColumnDefinitions.Add(new ColumnDefinition()); fuss.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); fuss.Children.Add(Ui.Winzig(s.T("stopp"), Ui.Pinsel("rot", 0.8))); fuss.Children.Add(Ui.Winzig(s.T("mitte")).Mit(t => t.HorizontalAlignment = HorizontalAlignment.Center).Spalte(1)); fuss.Children.Add(Ui.Winzig(s.T("plus"), Ui.Dritt).Spalte(2)); inhalt.Children.Add(Ui.Spalte(4, kopf, spur, fuss)); } foreach (var r in g.Texte("regeln")) inhalt.Children.Add(Ui.Winzig("· " + r).Mit(t => t.TextWrapping = TextWrapping.WrapWholeWords)); _geld.Inhalt = Ui.Flaeche(inhalt, 14, 0.05, 12); } // ---- Gerade eben --------------------------------------------------------------------------- private void Feed(JsonArray bloecke) { var a = bloecke.Abdruck(); if (a == _feedAbdruck) return; _feedAbdruck = a; var inhalt = Ui.Spalte(10); foreach (var b in bloecke.OfType()) { var block = Ui.Spalte(5, Ui.Zeile(Ui.Winzig(b.T("beginn"), fett: true), Ui.Text(b.T("summe"), 11, b.T("summe_ton"), fett: true, zahlen: true))); foreach (var z in b.Objekte("zeilen")) { var g = new Grid { ColumnSpacing = 8 }; g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(34) }); g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); g.ColumnDefinitions.Add(new ColumnDefinition()); g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); g.Children.Add(Ui.Winzig(z.T("zeit"), Ui.Dritt).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); var karten = Ui.Reihe(2); foreach (var k in z.Texte("karten")) karten.Children.Add(Ui.Spielkarte(k).Mit(c => { c.MinWidth = 20; c.Height = 24; ((TextBlock)c.Child).FontSize = 10.5; })); g.Children.Add(karten.Spalte(1)); var schritte = new TextBlock { FontSize = 11.5, TextTrimming = TextTrimming.CharacterEllipsis, VerticalAlignment = VerticalAlignment.Center }; bool erst = true; foreach (var s in z.Objekte("schritte")) { if (!erst) schritte.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run { Text = " › ", Foreground = Ui.Dritt }); erst = false; schritte.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run { Text = s.T("text"), Foreground = Ui.Pinsel(s.T("ton")) }); } g.Children.Add(schritte.Spalte(2)); g.Children.Add(Ui.Text(z.T("ergebnis"), 11.5, z.T("ton"), fett: true, zahlen: true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center).Spalte(3)); ToolTipService.SetToolTip(g, z.T("raum")); block.Children.Add(g); } inhalt.Children.Add(block); } if (bloecke.Count == 0) inhalt.Children.Add(Ui.Klein("Noch keine Hand in diesem Lauf.")); _feed.Inhalt = Ui.Flaeche(inhalt, 14, 0.05, 12); } } /// Eine Werkzeug-Kachel (Tische.swift `TischLeiste`): Symbol ueber kleinem Namen, 44 hoch. public sealed class Werkzeug : UserControl { private readonly FontIcon _zeichen; private readonly TextBlock _titel; private readonly ProgressRing _ring = new() { Width = 14, Height = 14, IsActive = false, Visibility = Visibility.Collapsed }; private readonly Tippflaeche _tipp; public Werkzeug(string titel, string glyph, bool rot, Action tun) { _zeichen = Ui.Zeichen(glyph, 14, rot ? "rot" : ""); _titel = Ui.Text(titel, 9.5, rot ? "rot" : "", fett: true); _titel.HorizontalAlignment = HorizontalAlignment.Center; var oben = new Grid { HorizontalAlignment = HorizontalAlignment.Center }; oben.Children.Add(_zeichen); oben.Children.Add(_ring); var inhalt = Ui.Spalte(3, oben, _titel); inhalt.VerticalAlignment = VerticalAlignment.Center; var flaeche = new Border { Background = Ui.Weiss(0.06), CornerRadius = new CornerRadius(10), MinHeight = 44, Child = inhalt }; _tipp = flaeche.Tippen(tun, 10, titel); Content = _tipp; } public bool An { get => _tipp.An; set => _tipp.An = value; } public bool Laeuft { set { _ring.IsActive = value; _ring.Visibility = value ? Visibility.Visible : Visibility.Collapsed; _zeichen.Visibility = value ? Visibility.Collapsed : Visibility.Visible; } } public void Setzen(string titel, string glyph, bool an) { _titel.Text = titel; _zeichen.Glyph = glyph; An = an; } } /// Ein einklappbarer Abschnitt (Tische.swift `EinklappAbschnitt`): Symbol, Titel, Hinweis, Chevron; /// der Zustand bleibt je Schluessel ueber Neustarts (lokale Einstellungen). public sealed class Einklappen : UserControl { private readonly ContentControl _inhalt = new() { HorizontalContentAlignment = HorizontalAlignment.Stretch }; private readonly FontIcon _chevron = Ui.Zeichen("", 9); private readonly TextBlock _hinweis = Ui.Winzig("", Ui.Dritt); private readonly string _schluessel; private bool _offen; public Einklappen(string titel, string glyph, string schluessel, bool vorgabe) { _schluessel = schluessel; _offen = Gemerkt(schluessel) ?? vorgabe; _chevron.Foreground = Ui.Dritt; var kopf = new Grid { ColumnSpacing = 6, Padding = new Thickness(0, 4, 0, 2) }; kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(14) }); kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); kopf.ColumnDefinitions.Add(new ColumnDefinition()); kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); kopf.Children.Add(Ui.Zeichen(glyph, 10, "grau")); kopf.Children.Add(Ui.Text(titel, 12, pinsel: Ui.Zweit, fett: true).Spalte(1)); kopf.Children.Add(_hinweis.Spalte(2).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); kopf.Children.Add(_chevron.Spalte(3)); var tipp = kopf.Tippen(() => { _offen = !_offen; Merken(_schluessel, _offen); Zeigen(); }, 6); Content = Ui.Spalte(8, tipp, _inhalt); Zeigen(); } public string Hinweis { set => _hinweis.Text = value; } public UIElement? Inhalt { set => _inhalt.Content = value; } private void Zeigen() { _chevron.Glyph = _offen ? "" : ""; _inhalt.Visibility = _offen ? Visibility.Visible : Visibility.Collapsed; } private static string Datei => System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Pokerfreak", "cockpit-winui.txt"); private static bool? Gemerkt(string k) { try { foreach (var z in File.ReadAllLines(Datei)) if (z.StartsWith(k + "=")) return z.EndsWith("=1"); } catch { } return null; } private static void Merken(string k, bool an) { try { var zeilen = File.Exists(Datei) ? File.ReadAllLines(Datei).Where(z => !z.StartsWith(k + "=")).ToList() : new List(); zeilen.Add($"{k}={(an ? 1 : 0)}"); Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Datei)!); File.WriteAllLines(Datei, zeilen); } catch { } } } /// /// Eine Tischkachel (Tische.swift `KachelAnsicht`): Klick holt den Tisch nach vorn. Kopf mit Name, /// Zustand, Netto, Foto und Schliessen; Modus; Minitisch; deine Karten gross mit der Entscheidung; /// Urteil und Gegner; Platzzeile; Foto. Orange umrandet, solange ein Zug offen ist. /// public sealed class TischKachel : UserControl { private readonly CockpitZustand _z; private readonly string _raum; private readonly ContentControl _inhalt = new() { HorizontalContentAlignment = HorizontalAlignment.Stretch }; private readonly Image _foto = new() { MaxHeight = 260, Stretch = Stretch.Uniform, Visibility = Visibility.Collapsed }; private readonly Border _rahmen; private readonly List _ringe = new(); private readonly HashSet _gegnerOffen = new(); private string _abdruck = ""; private byte[]? _fotoDa; private JsonObject? _zug, _letzt; public TischKachel(CockpitZustand z, string raum) { _z = z; _raum = raum; _rahmen = new Border { Background = Ui.Weiss(0.05), CornerRadius = new CornerRadius(16), BorderThickness = new Thickness(1.5), Padding = new Thickness(10), Child = Ui.Spalte(7, _inhalt, new Border { CornerRadius = new CornerRadius(8), Child = _foto }), }; Content = _rahmen.Tippen(() => _ = _z.SendenRaum(_raum, ("tische_vorn", null)), 16, $"Klick: {raum} nach vorn holen"); } public void Setzen(JsonObject k, byte[]? foto) { if (!ReferenceEquals(foto, _fotoDa)) { _fotoDa = foto; if (foto != null) _ = FotoZeigen(foto); } var a = k.Abdruck(); if (a == _abdruck) return; _abdruck = a; _letzt = k; _zug = k.Obj("zug"); _rahmen.BorderBrush = k.Wahr("zug_offen") ? Ui.Pinsel("orange") : null; _ringe.Clear(); _inhalt.Content = Bauen(k); Takt(); } private async Task FotoZeigen(byte[] png) { var bild = new BitmapImage(); using var strom = new Windows.Storage.Streams.InMemoryRandomAccessStream(); await strom.WriteAsync(png.AsBuffer()); strom.Seek(0); await bild.SetSourceAsync(strom); _foto.Source = bild; _foto.Visibility = Visibility.Visible; } /// Countdown des offenen Zugs (der Server schickt nur `bis` und `frist_s`). public void Takt() { double? anteil = null, rest = null; if (_zug.Wahr("offen") && _zug.Zahl("bis") is double bis) { rest = Math.Max(0, bis - Format.Jetzt()); var ganz = _zug.Zahl("frist_s") is double f && f > 0 ? f : Math.Max(rest.Value, 1); anteil = Math.Clamp(rest.Value / ganz, 0, 1); } foreach (var r in _ringe) r.Setzen(anteil, rest); } private UIElement Bauen(JsonObject k) { var teile = Ui.Spalte(7); // Kopf: Name, Zustand, Netto, Foto, Schliessen var kopf = new Grid { ColumnSpacing = 6 }; kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); kopf.ColumnDefinitions.Add(new ColumnDefinition()); kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); var name = Ui.Reihe(6, Ui.Text(k.T("titel"), 13, fett: true).Mit(t => t.MaxWidth = 170)); if (k.Text("zustand") is { Length: > 0 } zu) name.Children.Add(Ui.Abzeichen(zu, k.T("zustand_ton"))); kopf.Children.Add(name); var rechts = Ui.Reihe(2); if (k.Text("netto") is { Length: > 0 } netto) { var ton = k.T("netto_ton"); rechts.Children.Add(new Border { Background = Ui.Pinsel(ton, 0.15), CornerRadius = new CornerRadius(10), Padding = new Thickness(7, 2, 7, 2), VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 4, 0), Child = Ui.Reihe(3, Ui.Zeichen(netto.StartsWith("-") || netto.StartsWith("−") ? "" : "", 8, ton), Ui.Text(netto, 11.5, ton, fett: true, zahlen: true)), }); } rechts.Children.Add(Ui.Symbolknopf("", "Foto", () => _ = _z.SendenRaum(_raum, ("foto", null)), 11)); rechts.Children.Add(Ui.Symbolknopf("", "Tisch schließen", () => _ = _z.SendenRaum(_raum, ("tische_schliessen", null)), 11)); kopf.Children.Add(rechts.Spalte(2)); teile.Children.Add(kopf); if (k.Obj("modus") is { } m) teile.Children.Add(Modus(m)); teile.Children.Add(Minitisch(k)); // Deine Karten gross, daneben was der Laeufer damit tut var unten = new Grid { ColumnSpacing = 10 }; unten.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); unten.ColumnDefinitions.Add(new ColumnDefinition()); var karten = Ui.Reihe(4); foreach (var c in k.Texte("karten")) karten.Children.Add(Ui.Spielkarte(c, true)); if (karten.Children.Count > 0) unten.Children.Add(karten); var was = Ui.Spalte(3); if (k.Text("aktion") is { Length: > 0 } aktion) { var zeile = Ui.Reihe(6, Ui.Text(aktion, 14, fett: true)); if (k.Text("equity") is { Length: > 0 } eq) zeile.Children.Add(Ui.Klein(eq).Mit(t => t.VerticalAlignment = VerticalAlignment.Bottom)); var klick = Ui.Text(k.T("klick"), 14, k.T("klick_ton"), fett: true); ToolTipService.SetToolTip(klick, "Klick: " + (k.Text("klick_warum") is { Length: > 0 } w ? w : "kein Klick")); was.Children.Add(Ui.Zeile(zeile, klick)); if (k.Text("klartext") is { Length: > 0 } kl) was.Children.Add(Ui.Klein(kl, true).Mit(t => t.MaxLines = 3)); } else was.Children.Add(Ui.Klein(k.T("hinweis"), true)); unten.Children.Add(was.Spalte(karten.Children.Count > 0 ? 1 : 0).Mit(s => { if (karten.Children.Count == 0) Grid.SetColumnSpan(s, 2); })); teile.Children.Add(unten); // Urteil und Gegner var gegner = k.Objekte("gegner").ToList(); if (gegner.Count > 0) { if (k.Obj("urteil") is { } u) teile.Children.Add(Urteil(u)); teile.Children.Add(Ui.Zeile(Ui.Winzig("Was ich über die Gegner denke", fett: true), Ui.Text("antippen: alle Werte", 9, pinsel: Ui.Dritt))); foreach (var s in gegner) teile.Children.Add(Gegner(s)); } if (k.Text("platz") is { Length: > 0 } platz) teile.Children.Add(Ui.Winzig(platz, Ui.Dritt)); return teile; } private static UIElement Urteil(JsonObject u) { var ton = u.T("ton"); var g = new Grid { ColumnSpacing = 8 }; g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); g.ColumnDefinitions.Add(new ColumnDefinition()); g.Children.Add(Ui.Zeichen(u.Wahr("setzen") ? "" : "", 14, ton).Mit(z => z.VerticalAlignment = VerticalAlignment.Center)); g.Children.Add(Ui.Spalte(1, Ui.Text(u.T("titel"), 12, ton, fett: true), Ui.Winzig(u.T("grund")).Mit(t => { t.TextWrapping = TextWrapping.WrapWholeWords; t.MaxLines = 2; })).Spalte(1)); return Ui.Getoent(g, ton, 0.12, 10, 7); } /// Der Modus des Tisches (ModusLeiste.swift): Chip als Kapsel, Text, Lage, Spur zum Geld. private static UIElement Modus(JsonObject m) { string ton = m.T("chip_ton"); string art = m.T("art"); string glyph = art switch { "turnier" => "", "kpoker" => "", _ => "" }; var chip = Ui.Abzeichen(m.T("chip"), ton, glyph); if (art == "kpoker") { var zeile = Ui.Reihe(6, chip); foreach (var t in m.Texte("tasten")) zeile.Children.Add(new Border { Padding = new Thickness(6, 1, 6, 2), CornerRadius = new CornerRadius(5), BorderThickness = new Thickness(1), BorderBrush = Ui.Weiss(0.15), Background = Ui.Weiss(0.08), Child = Ui.Text(t, 11, fett: true), VerticalAlignment = VerticalAlignment.Center, }); return Ui.Zeile(zeile, Ui.Reihe(4, Ui.Zeichen("", 10, "grau"), Ui.Text(m.T("uhr"), 11, "grau", fett: true, zahlen: true))); } var oben = Ui.Zeile(Ui.Reihe(6, chip, Ui.Klein(m.T("text")).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)), m.Text("lage") is { Length: > 0 } lage ? Ui.Abzeichen(lage, m.T("lage_ton"), "") : null); if (m.Obj("spur") is not { } spur) return oben; string spurTon = m.T("lage_ton") == "gruen" ? "gruen" : "indigo"; UIElement band; if (spur["striche"] is JsonArray striche) { var g = new Grid { ColumnSpacing = 2, Height = 6 }; int i = 0; foreach (var s in striche) { g.ColumnDefinitions.Add(new ColumnDefinition()); bool voll = s is JsonValue v && v.TryGetValue(out var b) && b; g.Children.Add(new Border { CornerRadius = new CornerRadius(3), Background = voll ? Ui.Pinsel(spurTon, 0.75) : null, BorderBrush = voll ? null : m.T("lage_ton") == "orange" ? Ui.Pinsel("orange") : Ui.Zweit, BorderThickness = new Thickness(voll ? 0 : 1), }.Spalte(i++)); } band = g; } else band = LiveTeil.Balken(spur.Zahl("anteil") ?? 0, spurTon, 6); var unten = Ui.Zeile(band, Ui.Winzig(spur.T("text"))); ((FrameworkElement)band).VerticalAlignment = VerticalAlignment.Center; return Ui.Spalte(5, oben, unten); } /// Der Minitisch (Tischbild.swift `MiniTisch`): Filz-Oval mit Bande, Board in fuenf Plaetzen und /// Topf in der Mitte, die Plaetze an (ux, uy) - dein Platz unten mit dem Countdown-Ring. private UIElement Minitisch(JsonObject k) { bool mitTisch = k.Wahr("mit_tisch"); double B = 380, H = mitTisch ? 220 : 130; double rx = B / 2 - (mitTisch ? 40 : 22), ry = H / 2 - (mitTisch ? 26 : 20); double mx = B / 2, my = H / 2 - 6; var flaeche = new Canvas { Width = B, Height = H }; var filz = new Ellipse { Width = rx * 2 + 16, Height = ry * 2 + 14, Fill = new RadialGradientBrush { GradientStops = { new GradientStop { Color = Color.FromArgb(255, 20, 115, 77), Offset = 0 }, new GradientStop { Color = Color.FromArgb(255, 8, 64, 43), Offset = 1 }, }, }, Stroke = new SolidColorBrush(Color.FromArgb(255, 92, 61, 33)), StrokeThickness = 5, }; Canvas.SetLeft(filz, mx - filz.Width / 2); Canvas.SetTop(filz, my - filz.Height / 2); flaeche.Children.Add(filz); var mitte = Ui.Spalte(5); var board = Ui.Reihe(3); var karten = k.Texte("board").Take(5).ToList(); for (int i = 0; i < 5; i++) board.Children.Add(i < karten.Count ? Ui.Spielkarte(karten[i]).Mit(c => { c.MinWidth = 24; c.Width = 24; c.Height = 29; ((TextBlock)c.Child).FontSize = 11.5; }) : Ui.Kartenplatz()); board.HorizontalAlignment = HorizontalAlignment.Center; mitte.Children.Add(board); if (k.Text("topf") is { Length: > 0 } t) mitte.Children.Add(new Border { Background = Ui.Schwarz(0.35), CornerRadius = new CornerRadius(10), Padding = new Thickness(8, 2, 8, 2), HorizontalAlignment = HorizontalAlignment.Center, Child = Ui.Text(t, 11.5, "", fett: true, zahlen: true), }); Mittig(flaeche, mitte, mx, my, 200); foreach (var s in k.Objekte("sitze")) { double x = mx + (s.Zahl("ux") ?? 0) * rx, y = my + (s.Zahl("uy") ?? 0) * ry; FrameworkElement platz; if (s.Wahr("frei")) { if (s.Wahr("ich")) platz = EigenerPlatz(); else platz = new Ellipse { Width = mitTisch ? 12 : 16, Height = mitTisch ? 12 : 16, Fill = new SolidColorBrush(Color.FromArgb(mitTisch ? (byte)128 : (byte)255, 36, 48, 64)), Stroke = mitTisch ? null : Ui.Weiss(0.12), }; } else platz = Schild(s); Mittig(flaeche, platz, x, y, 80); } return new Viewbox { Child = flaeche, Stretch = Stretch.Uniform, StretchDirection = StretchDirection.Both }; } private ZugRing EigenerPlatz(double d = 26) { var r = new ZugRing(d); _ringe.Add(r); return r; } /// Ein Platz wie am Tisch (SitzSchild): Rolle, Name, Stack gelb, BB klein, letzte Aktion; der Rand /// in der Farbe des Stils; wer aussitzt, ist blass; dein Platz blau mit Countdown-Ring. private FrameworkElement Schild(JsonObject s) { bool ich = s.Wahr("ich"); var name = Ui.Reihe(2); if (ich) name.Children.Add(EigenerPlatz(16)); if (s.Text("rolle") is { Length: > 0 } r) { bool d = r == "D"; name.Children.Add(new Border { Background = d ? Ui.Pinsel("") : Ui.Pinsel("blau", 0.8), CornerRadius = new CornerRadius(5), Padding = new Thickness(3, 0, 3, 1), VerticalAlignment = VerticalAlignment.Center, Child = Ui.Text(r, 7.5, pinsel: d ? Ui.Schwarz(1) : Ui.Pinsel(""), fett: true), }); } name.Children.Add(Ui.Text(s.T("name"), 9, fett: true).Mit(t => t.MaxWidth = 56)); var spalte = Ui.Spalte(0, name, Ui.Text(s.T("stack"), 10, pinsel: Ui.Pinsel("gelb", 0.9), fett: true, zahlen: true).Mit(t => t.HorizontalAlignment = HorizontalAlignment.Center)); if (s.Text("stack_bb") is { Length: > 0 } sb) spalte.Children.Add(Ui.Text(sb, 7.5, pinsel: Ui.Weiss(0.55), zahlen: true).Mit(t => t.HorizontalAlignment = HorizontalAlignment.Center)); if (s.Text("aktion") is { Length: > 0 } a) spalte.Children.Add(Ui.Text(a, 8, s.T("aktion_ton"), fett: true).Mit(t => t.HorizontalAlignment = HorizontalAlignment.Center)); name.HorizontalAlignment = HorizontalAlignment.Center; string stil = s.T("stil_ton"); var schild = new Border { Background = ich ? Ui.Pinsel("blau", 0.35) : Ui.Schwarz(0.5), BorderBrush = stil != "" ? Ui.Pinsel(stil, 0.9) : null, BorderThickness = new Thickness(stil != "" ? 1.5 : 0), CornerRadius = new CornerRadius(6), Padding = new Thickness(4, 2, 4, 2), MaxWidth = 80, Opacity = s.Wahr("draussen") ? 0.45 : 1, Child = spalte, }; if (s.Text("stil_kuerzel") is not { Length: > 0 } kz) return schild; var huelle = new Grid(); huelle.Children.Add(schild); huelle.Children.Add(new Border { Background = Ui.Pinsel(stil), CornerRadius = new CornerRadius(4), Padding = new Thickness(2, 0, 2, 0), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, -4, -4, 0), Child = Ui.Text(kz, 6.5, pinsel: Ui.Schwarz(1), fett: true), }); return huelle; } /// Legt ein Element mit seiner Mitte auf (x, y). private static void Mittig(Canvas c, FrameworkElement e, double x, double y, double breite) { e.Measure(new Windows.Foundation.Size(breite, 200)); var g = e.DesiredSize; Canvas.SetLeft(e, x - g.Width / 2); Canvas.SetTop(e, y - g.Height / 2); c.Children.Add(e); } /// Ein Gegner als Karte (Gegner.swift `GegnerKarte`): Name, Stack, Stil-Abzeichen, Fold-Chance, /// Vertrauen, der Satz des Kerns; angetippt alle Werte und die Stichprobe. private UIElement Gegner(JsonObject s) { string name = s.T("name"); bool offen = _gegnerOffen.Contains(name); var kopfZeile = Ui.Reihe(6); if (s.Text("rolle") is { Length: > 0 } r) kopfZeile.Children.Add(new Border { Background = r == "D" ? Ui.Pinsel("") : Ui.Pinsel("blau", 0.8), CornerRadius = new CornerRadius(5), Padding = new Thickness(3, 0, 3, 1), VerticalAlignment = VerticalAlignment.Center, Child = Ui.Text(r, 8, pinsel: r == "D" ? Ui.Schwarz(1) : Ui.Pinsel(""), fett: true), }); kopfZeile.Children.Add(Ui.Text(name, 12, fett: true)); var kopf = Ui.Zeile(kopfZeile, Ui.Reihe(6, Ui.Text(s.T("stack"), 12, pinsel: Ui.Pinsel("gelb", 0.9), fett: true, zahlen: true), Ui.Zeichen(offen ? "" : "", 9).Mit(z => z.Foreground = Ui.Dritt))); var teile = Ui.Spalte(4, kopf); if (s.Wahr("geschaetzt")) { var vt = s.T("vertrauen_ton"); var vertrauen = Ui.Reihe(3, new Grid { Width = 22, Height = 4, VerticalAlignment = VerticalAlignment.Center }.Mit(g => { g.Children.Add(new Border { Background = Ui.Weiss(0.12), CornerRadius = new CornerRadius(2) }); g.Children.Add(new Border { Background = Ui.Pinsel(vt), CornerRadius = new CornerRadius(2), Width = 22 * (s.Zahl("vertrauen") ?? 0), HorizontalAlignment = HorizontalAlignment.Left }); }), Ui.Text(s.T("vertrauen_text"), 9, vt, fett: true)); var zeile = Ui.Reihe(8, Ui.Abzeichen(s.T("stil"), s.T("stil_ton"))); if (s.Text("fold") is { Length: > 0 } f) zeile.Children.Add(Ui.Reihe(3, Ui.Zeichen("", 9, "grau"), Ui.Winzig(f)).Mit(x => x.VerticalAlignment = VerticalAlignment.Center)); teile.Children.Add(Ui.Zeile(zeile, vertrauen.Mit(v => v.VerticalAlignment = VerticalAlignment.Center))); } teile.Children.Add(Ui.Text(s.T("satz"), 11, pinsel: s.Wahr("satz_leise") ? Ui.Dritt : Ui.Weiss(0.85), umbruch: true)); var werte = s.Objekte("werte").ToList(); if (offen && werte.Count > 0) { var g = new Grid { ColumnSpacing = 6, RowSpacing = 4 }; for (int i = 0; i < 4; i++) g.ColumnDefinitions.Add(new ColumnDefinition()); int n = 0; foreach (var w in werte) { if (n % 4 == 0) g.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); var c = Ui.Spalte(0, Ui.Text(w.T("name"), 9, "grau"), Ui.Text(w.T("wert"), 11, fett: true, zahlen: true)); Grid.SetRow(c, n / 4); Grid.SetColumn(c, n % 4); g.Children.Add(c); n++; } teile.Children.Add(g); teile.Children.Add(Ui.Text(s.T("stichprobe"), 9, pinsel: Ui.Dritt, umbruch: true)); } var karte = new Border { Background = Ui.Weiss(0.05), CornerRadius = new CornerRadius(10), Padding = new Thickness(8), BorderBrush = s.Wahr("geschaetzt") ? Ui.Pinsel(s.T("stil_ton"), 0.35) : null, BorderThickness = new Thickness(1), Opacity = s.Wahr("draussen") ? 0.55 : 1, Child = teile, }; return karte.Tippen(() => { if (!_gegnerOffen.Remove(name)) _gegnerOffen.Add(name); if (_letzt == null) return; _ringe.Clear(); _inhalt.Content = Bauen(_letzt); Takt(); }, 10); } } /// Der eigene Platz (Tischbild.swift `EigenerPlatz`): ohne Zug ein Kreis mit Person, mit Zug ein Ring /// mit der Restzeit - gruen, unter der Haelfte orange, unter einem Viertel rot. public sealed class ZugRing : Grid { private readonly ProgressRing _ring = new() { IsIndeterminate = false, Minimum = 0, Maximum = 1 }; private readonly TextBlock _zahl = Ui.Text("", 10, "", fett: true, zahlen: true); private readonly FontIcon _person = Ui.Zeichen("", 9); private readonly Ellipse _rand = new() { Stroke = Ui.Weiss(0.35), StrokeThickness = 1.5 }; public ZugRing(double d) { Width = d; Height = d; Children.Add(new Ellipse { Fill = new SolidColorBrush(Color.FromArgb(255, 26, 33, 46)) }); Children.Add(_rand); _ring.Width = d; _ring.Height = d; Children.Add(_ring); _person.Foreground = Ui.Weiss(0.7); _zahl.FontSize = d * 0.4; foreach (var e in new FrameworkElement[] { _person, _zahl }) { e.HorizontalAlignment = HorizontalAlignment.Center; e.VerticalAlignment = VerticalAlignment.Center; Children.Add(e); } Setzen(null, null); } public void Setzen(double? anteil, double? rest) { bool zug = anteil != null; _ring.Visibility = zug ? Visibility.Visible : Visibility.Collapsed; _rand.Visibility = zug ? Visibility.Collapsed : Visibility.Visible; _person.Visibility = zug ? Visibility.Collapsed : Visibility.Visible; _zahl.Visibility = zug ? Visibility.Visible : Visibility.Collapsed; if (anteil is double a) { _ring.Value = a; _ring.Foreground = Ui.Pinsel(a < 0.25 ? "rot" : a < 0.5 ? "orange" : "gruen"); _zahl.Text = $"{Math.Ceiling(rest ?? 0):0}"; } } }