diff --git a/winui/Seiten/LiveTeil.cs b/winui/Seiten/LiveTeil.cs index 58206c2c..e4a9562c 100644 --- a/winui/Seiten/LiveTeil.cs +++ b/winui/Seiten/LiveTeil.cs @@ -81,6 +81,7 @@ public sealed class LiveTeil : UserControl public void Takt() { foreach (var k in _zeileVon.Values) k.Takt(); + foreach (var u in _uhren) UhrStellen(u); } /// Setzt den Inhalt nur, wenn sich der Abdruck geaendert hat. @@ -201,18 +202,31 @@ public sealed class LiveTeil : UserControl foreach (var c in chips) if (_zeileVon.TryGetValue(c.T("raum"), out var z)) z.Setzen(c, kacheln.GetValueOrDefault(c.T("raum")), _z.Fotos.GetValueOrDefault(c.T("raum"))); - Raster(chips); + Raster(chips, kacheln); _tische.Visibility = chips.Count > 0 ? Visibility.Visible : Visibility.Collapsed; } - /// Die Tische wie die Fenster auf dem Schirm; antippen klappt den Tisch darunter auf. - private void Raster(List chips) + /// Was aus einer Kachel im Raster zu sehen ist (nur das bestimmt den Neubau). + private static string KachelAbdruck(JsonObject? k) => k == null ? "" : + $"{string.Join(",", k.Texte("karten"))}/{string.Join(",", k.Texte("board"))}/{k.T("topf")}/{IchAktion(k)}/{k.Obj("zug")?.ToJsonString()}"; + + /// Die letzte eigene Aktion dieser Hand aus den Plaetzen ("Fold", "Raise 0,06", ...). + private static string IchAktion(JsonObject k) => k.Objekte("sitze").FirstOrDefault(x => x.Wahr("ich")).T("aktion"); + + /// Laufende Zug-Uhren der Kacheln: (Balken, bis, frist) - `Takt` schiebt sie jede Sekunde. + private readonly List<(Grid Balken, double Bis, double Frist)> _uhren = new(); + + /// Die Tische wie die Fenster auf dem Schirm; antippen klappt den Tisch darunter auf. Jede Kachel ist ein + /// kleiner Tisch (Owner 30.11.: "informativer und geiler"): Filzgrund, eigene Karten, Netto, Board mit Farben, Topf, + /// letzte eigene Aktion; am Zug orange mit ablaufender Uhr. Nach dem Fold sind die Karten blass. + private void Raster(List chips, Dictionary kacheln) { var auf = _zeileVon.FirstOrDefault(p => p.Value.Offen).Key ?? ""; - var abdruck = auf + "|" + string.Join("|", chips.Select(c => c.ToJsonString())); + var abdruck = auf + "|" + string.Join("|", chips.Select(c => c.ToJsonString() + "#" + KachelAbdruck(kacheln.GetValueOrDefault(c.T("raum"))))); if (abdruck == _rasterAbdruck) return; _rasterAbdruck = abdruck; _raster.Children.Clear(); + _uhren.Clear(); _raster.RowDefinitions.Clear(); _raster.ColumnDefinitions.Clear(); if (chips.Count == 0) return; @@ -237,15 +251,18 @@ public sealed class LiveTeil : UserControl if (!string.IsNullOrEmpty(c.T("stufe"))) kopf.Children.Add(Ui.Text(c.T("stufe"), 9.5, pinsel: Ui.Dritt).Mit(t => { t.VerticalAlignment = VerticalAlignment.Center; t.TextTrimming = TextTrimming.CharacterEllipsis; }).Spalte(2)); + var k = kacheln.GetValueOrDefault(raum); + var inhalt = Ui.Spalte(2, kopf, Ui.Text(c.T("zeile"), 12, c.T("zeile_ton"), fett: true, zahlen: true) + .Mit(t => t.TextTrimming = TextTrimming.CharacterEllipsis)); + if (k != null) Minitisch(inhalt, k, zug); var kachel = new Border { Padding = new Thickness(7, 5, 7, 6), - CornerRadius = new CornerRadius(5), - Background = zug ? Ui.Pinsel("orange", 0.22) : Ui.Weiss(raum == auf ? 0.14 : 0.06), + CornerRadius = new CornerRadius(6), + Background = zug ? Ui.Pinsel("orange", 0.22) : Filz(raum == auf), BorderThickness = new Thickness(1), - BorderBrush = zug ? Ui.Pinsel("orange", 0.9) : Ui.Weiss(raum == auf ? 0.35 : 0), - Child = Ui.Spalte(1, kopf, Ui.Text(c.T("zeile"), 12, c.T("zeile_ton"), fett: true, zahlen: true) - .Mit(t => t.TextTrimming = TextTrimming.CharacterEllipsis)), + BorderBrush = zug ? Ui.Pinsel("orange", 0.9) : Ui.Weiss(raum == auf ? 0.35 : 0.07), + Child = inhalt, MinWidth = 0, }; ToolTipService.SetToolTip(kachel, c.T("titel")); @@ -255,7 +272,7 @@ public sealed class LiveTeil : UserControl if (!_zeileVon.TryGetValue(raum, out var z)) return; z.Offen = !z.Offen; _rasterAbdruck = ""; - Raster(chips); + Raster(chips, kacheln); }; Grid.SetRow(kachel, (int)(c.Zahl("zeile_nr") ?? 0)); Grid.SetColumn(kachel, (int)(c.Zahl("spalte_nr") ?? 0)); @@ -263,6 +280,91 @@ public sealed class LiveTeil : UserControl } } + /// Filzgrund: dunkles Tischgruen von oben nach unten (aufgeklappt etwas heller). + private static Brush Filz(bool hell) => new LinearGradientBrush + { + StartPoint = new Windows.Foundation.Point(0, 0), + EndPoint = new Windows.Foundation.Point(0, 1), + GradientStops = + { + new GradientStop { Color = Color.FromArgb(hell ? (byte)110 : (byte)70, 20, 115, 77), Offset = 0 }, + new GradientStop { Color = Color.FromArgb(hell ? (byte)70 : (byte)38, 8, 64, 43), Offset = 1 }, + }, + }; + + /// Unter Kopf und Netto: eigene Karten mit Topf, darunter Board in Farbe oder die letzte eigene Aktion, + /// am Zug eine ablaufende Uhr als Balken. + private void Minitisch(StackPanel inhalt, JsonObject k, bool zug) + { + var aktion = IchAktion(k); + bool raus = aktion.StartsWith("Fold"); + var karten = k.Texte("karten").Take(4).ToList(); + var reihe = new Grid { ColumnSpacing = 3 }; + reihe.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + reihe.ColumnDefinitions.Add(new ColumnDefinition()); + var hand = Ui.Reihe(1); + foreach (var x in karten) hand.Children.Add(Mikrokarte(x).Mit(b => b.Opacity = raus ? 0.35 : 1)); + if (karten.Count == 0) hand.Children.Add(Ui.Text("–", 10, pinsel: Ui.Dritt)); + reihe.Children.Add(hand); + if (k.Text("topf") is { Length: > 0 } topf) + reihe.Children.Add(Ui.Text(topf.Replace("Topf ", ""), 9.5, pinsel: Ui.Pinsel("gelb", 0.85), zahlen: true) + .Mit(t => { t.HorizontalAlignment = HorizontalAlignment.Right; t.VerticalAlignment = VerticalAlignment.Center; t.TextTrimming = TextTrimming.CharacterEllipsis; }) + .Spalte(1)); + inhalt.Children.Add(reihe); + + var board = k.Texte("board").Take(5).ToList(); + if (board.Count > 0) + { + var t = new TextBlock { FontSize = 10, FontWeight = Microsoft.UI.Text.FontWeights.SemiBold, TextTrimming = TextTrimming.Clip }; + foreach (var roh in board) + { + var kk = Kern.Format.Karte(roh); + t.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run { Text = kk?.Text ?? "?", Foreground = kk?.Rot == true ? Ui.Pinsel("rot") : Ui.Pinsel("") }); + } + ToolTipService.SetToolTip(t, string.Join(" ", board.Select(b => Kern.Format.Karte(b)?.Text ?? b))); + inhalt.Children.Add(t); + } + else if (aktion.Length > 0) + inhalt.Children.Add(Ui.Text(aktion, 9.5, AktionTon(aktion), fett: true).Mit(t => t.TextTrimming = TextTrimming.CharacterEllipsis)); + + var z = k.Obj("zug"); + if (zug && z != null && z.Wahr("offen") && z.Zahl("bis") is double bis) + { + var balken = Balken(1, "gruen", 3); + balken.Margin = new Thickness(0, 2, 0, 0); + _uhren.Add((balken, bis, z.Zahl("frist_s") is double f && f > 0 ? f : 0)); + inhalt.Children.Add(balken); + UhrStellen(_uhren[^1]); + } + } + + private static string AktionTon(string a) => + a.StartsWith("Fold") ? "grau" : a.StartsWith("Call") || a.StartsWith("Check") ? "gruen" + : a.StartsWith("Raise") || a.StartsWith("Bet") || a.StartsWith("All") ? "orange" : ""; + + /// Eine winzige Karte fuer die Kachel (Rang und Farbe, rot oder hell). + private static Border Mikrokarte(string roh) + { + var b = Ui.Spielkarte(roh); + b.MinWidth = 17; + b.Height = 17; + b.Padding = new Thickness(1, 0, 1, 0); + b.CornerRadius = new CornerRadius(3); + ((TextBlock)b.Child).FontSize = 9.5; + return b; + } + + private static void UhrStellen((Grid Balken, double Bis, double Frist) u) + { + var rest = Math.Max(0, u.Bis - Format.Jetzt()); + var ganz = u.Frist > 0 ? u.Frist : Math.Max(rest, 1); + var a = Math.Clamp(rest / ganz, 0, 1); + u.Balken.ColumnDefinitions[0].Width = new GridLength(a, GridUnitType.Star); + u.Balken.ColumnDefinitions[1].Width = new GridLength(1 - a, GridUnitType.Star); + if (u.Balken.Children.Count > 1 && u.Balken.Children[1] is Border b) + b.Background = Ui.Pinsel(a < 0.25 ? "rot" : a < 0.5 ? "orange" : "gruen", 0.9); + } + // ---- Suche / Bereit ------------------------------------------------------------------------ /// Fuer die fehlenden Tische eine gestrichelte Such-Kachel: die Luecke ist Absicht, kein Haenger.