Files
pokerfreak/winui/Seiten/LiveTeil.cs
T
mmintelandClaude Opus 5.5 ab2e36fa4c WinUI: Protokoll mit Suche, Filterchips, Farben; Logzeile je Tisch; Tisch im Status
- Protokoll: Suche (Strg+F) mit Markierung, Chips je Art mit Zahl, Tisch-Filter, Probleme,
  Technik-Gruppe (Standard aus), Rechtsklick kopieren/filtern, Gedanken aufgeteilt und farbig
- Server: ticker liefert name/hand/netto/gruppe/kurz; Chips tragen die letzte Stromzeile
  des Tisches (log, log_zeit, log_art, log_ton, log_warn); status.raum bei denkt/klickt
- Live-Ansicht: unter dem Raster je Tisch eine Zeile mit der letzten Logzeile

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 10:23:49 +01:00

1098 lines
58 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
/// <summary>
/// Die Live-Ansicht unter dem Cash-Kopf nach Tische.swift `LiveAnsicht`: die Sitzungsleiste, die
/// Tische als Liste (antippen klappt die volle Kachel auf; sonst "Bis zum Spielen"), die Suche, "Gerade eben"
/// und eingeklappt "Geld". Fertig gerechnet vom
/// Server (sicht/abgeleitet.py) - hier wird nur gezeichnet. Ein Block baut nur bei neuem Abdruck neu.
/// </summary>
public sealed class LiveTeil : UserControl
{
private readonly CockpitZustand _z;
private readonly ContentControl _leiste = Breit(), _such = Breit(), _bereit = Breit();
private readonly StackPanel _zeilen = Ui.Spalte(0);
private readonly Grid _raster = new() { ColumnSpacing = 4, RowSpacing = 4 };
private string _rasterAbdruck = "", _logAbdruck = "";
/// <summary>Je Tisch eine Zeile mit der letzten Zeile des Stroms (Owner 02.12.: "log line pro tisch").</summary>
private readonly StackPanel _logs = Ui.Spalte(0);
private readonly TextBlock _tischText = Ui.Text("", 12, pinsel: Ui.Zweit);
private readonly StackPanel _tische;
/// <summary>Platz zwischen Tischliste und Verlauf: im Lauf die Einstellungen der Spielseite.</summary>
public Border Einschub { get; } = new();
private readonly Einklappen _geld = new("Geld", "", "ein.geld", false), _feed = new("Gerade eben", "", "ein.gerade", true);
private readonly Border _schliessenFrage;
private readonly TextBlock _schliessenText = Ui.Text("", 12, umbruch: true);
private readonly Button _vorn, _anordnen, _mehr;
private readonly Dictionary<string, TischZeile> _zeileVon = new();
private readonly Dictionary<ContentControl, string> _abdruck = new();
private string _folge = "", _geldAbdruck = "", _feedAbdruck = "";
public LiveTeil(CockpitZustand z)
{
_z = z;
_vorn = Ui.Symbolknopf("\uE8A7", "Alle Tische nach vorn", () => _ = _z.Senden(("tische_vorn", null)), 13);
_anordnen = Ui.Symbolknopf("\uF0E2", "Tische anordnen", () => _ = _z.Senden(("tische_anordnen", null)), 13);
_mehr = Ui.Symbolknopf("\uE712", "Mehr", () => { }, 13);
var foto = new MenuFlyoutItem { Text = "Fotos machen", Icon = new FontIcon { Glyph = "\uE722" } };
foto.Click += (_, _) => _ = _z.Senden(("foto", null));
var zu = new MenuFlyoutItem { Text = "Alle Tische schließen …", Icon = new FontIcon { Glyph = "\uE711", Foreground = Ui.Pinsel("rot") }, Foreground = Ui.Pinsel("rot") };
zu.Click += (_, _) => _schliessenFrage!.Visibility = Visibility.Visible;
_mehr.Flyout = new MenuFlyout { Items = { foto, new MenuFlyoutSeparator(), zu } };
foreach (var b in new[] { _vorn, _anordnen, _mehr }) { b.Padding = new Thickness(8, 6, 8, 6); b.CornerRadius = new CornerRadius(4); }
var kopf = new Grid { ColumnSpacing = 8, Margin = new Thickness(2, 2, 0, 0) };
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.Text("Tische", 13, fett: true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center));
kopf.Children.Add(_tischText.Mit(t => t.VerticalAlignment = VerticalAlignment.Center).Spalte(1));
kopf.Children.Add(Ui.Reihe(2, _vorn, _anordnen, _mehr).Spalte(2));
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; // Sammelt er, schliesst er beim Stoppen selbst - sonst fuellte er gleich wieder auf
_ = _z.Senden((_z.Ansicht.Sammelt ? "sammler_stoppen" : "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;
var logFlaeche = Ui.Flaeche(_logs, 8, 0.05, 0);
logFlaeche.Padding = new Thickness(0, 2, 0, 2);
_tische = Ui.Spalte(6, kopf, _schliessenFrage, _raster, logFlaeche, Ui.Flaeche(_zeilen, 8, 0.05, 0));
Content = Ui.Spalte(12, _leiste, _bereit, _tische, _such, Einschub, _feed, _geld);
}
private static ContentControl Breit() => new()
{
HorizontalContentAlignment = HorizontalAlignment.Stretch,
HorizontalAlignment = HorizontalAlignment.Stretch,
};
public void Takt()
{
foreach (var k in _zeileVon.Values) k.Takt();
foreach (var u in _uhren) UhrStellen(u);
}
/// <summary>Setzt den Inhalt nur, wenn sich der Abdruck geaendert hat.</summary>
private void Block(ContentControl c, JsonNode? daten, Func<UIElement?> 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);
bool zuschauen = _z.Zuschauen, an = _z.Verbunden && anzahl > 0;
_vorn.IsEnabled = an && !_z.Laufend.Contains("tische_vorn");
_anordnen.IsEnabled = an && !_z.Laufend.Contains("tische_anordnen");
_mehr.IsEnabled = an;
_schliessenText.Text = live.Text("schliessen_frage") ?? "Alle Tische schließen?";
Block(_leiste, zuschauen ? null : a.Kopf.Obj("sitzungsleiste"), () => zuschauen ? null : Sitzungsleiste(a.Kopf.Obj("sitzungsleiste")));
Block(_such, live == null ? null : new JsonArray(live["such"]?.DeepClone(), live["such_titel"]?.DeepClone()), () => Such(live));
Block(_bereit, zuschauen ? null : live?["bereit"], () => zuschauen ? null : Bereit(live.Obj("bereit")));
Zeilen(live.Objekte("chips").ToList(), live.Objekte("kacheln").GroupBy(k => k.T("raum")).ToDictionary(g => g.Key, g => g.First()));
var neben = a.Kopf.Obj("sitzungsleiste").Objekte("zellen").FirstOrDefault(x => x.T("titel") == "Tische").T("wert");
_tischText.Text = zuschauen ? $"{anzahl}" : anzahl == 0 ? "" : neben.Length > 0 ? neben : $"{anzahl} offen";
_geld.Hinweis = _z.Wahl.Cash ? "Echtgeld" : "Übung";
Geld(a.Geld.Obj("anzeige"));
Feed(a.Entscheidungen.Liste("feed"));
_geld.Visibility = !zuschauen && a.Geld.Obj("anzeige") != null ? Visibility.Visible : Visibility.Collapsed;
_feed.Visibility = zuschauen ? Visibility.Collapsed : Visibility.Visible;
}
// ---- Sitzungsleiste ------------------------------------------------------------------------
/// <summary>Nebenwerte stehen im Tooltip ihrer Hauptzahl, nicht als eigene Zelle.</summary>
private static readonly Dictionary<string, string> Neben = new()
{
["Tische"] = "Hände",
};
/// <summary>Das Ergebnis der laufenden (sonst letzten) Sitzung gross, sechs Kennzahlen, Abstand zum Stop.</summary>
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)
.Mit(t => t.VerticalAlignment = VerticalAlignment.Center)), new Ui.Info(s.T("ende"), s.Wahr("warn")));
var gross = Ui.Reihe(8, Ui.Gross(s.T("geld"), 34, 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, 8); }));
var zellen = new Grid { ColumnSpacing = 6, RowSpacing = 8 };
for (int i = 0; i < 5; i++) zellen.ColumnDefinitions.Add(new ColumnDefinition());
int n = 0;
var alle = s.Objekte("zellen").ToList();
foreach (var z in alle.Where(z => !Neben.ContainsKey(z.T("titel"))))
{
if (n % 5 == 0) zellen.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
var c = Ui.Spalte(0, Ui.Text(z.T("titel"), 10.5, pinsel: Ui.Zweit),
Ui.Gross(z.T("wert"), 13, z.Text("ton") is { Length: > 0 } t ? t : null));
c.Background = Ui.Weiss(0);
var mehr = alle.Where(x => Neben.GetValueOrDefault(x.T("titel")) == z.T("titel")).Select(x => $"{x.T("titel")}: {x.T("wert")}").ToList();
ToolTipService.SetToolTip(c, string.Join("\n", mehr.Prepend($"{z.T("titel")}: {z.T("wert")}")));
Grid.SetRow(c, n / 5);
Grid.SetColumn(c, n % 5);
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, 8, 0.05, 14);
}
/// <summary>Ein Balken wie `ProgressView(value:)`: Kapsel in .quaternary, gefuellt in Farbe.</summary>
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 void Zeilen(List<JsonObject> chips, Dictionary<string, JsonObject> kacheln)
{
var folge = string.Join("|", chips.Select(c => c.T("raum")));
if (folge != _folge)
{
_folge = folge;
_zeilen.Children.Clear();
var alt = new Dictionary<string, TischZeile>(_zeileVon);
_zeileVon.Clear();
foreach (var c in chips)
{
var raum = c.T("raum");
if (_zeileVon.ContainsKey(raum)) continue;
if (!alt.TryGetValue(raum, out var z))
{
z = new TischZeile(_z, raum, c.T("titel"));
z.Geoeffnet += offen => { foreach (var x in _zeileVon.Values) if (x != offen) x.Offen = false; };
}
z.Linie = _zeileVon.Count > 0;
_zeileVon[raum] = z;
_zeilen.Children.Add(z);
}
}
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, kacheln);
Logs(chips);
_tische.Visibility = chips.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
}
/// <summary>Was aus einer Kachel im Raster zu sehen ist (nur das bestimmt den Neubau).</summary>
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()}";
/// <summary>Die letzte eigene Aktion dieser Hand aus den Plaetzen ("Fold", "Raise 0,06", ...).</summary>
private static string IchAktion(JsonObject k) => k.Objekte("sitze").FirstOrDefault(x => x.Wahr("ich")).T("aktion");
/// <summary>Laufende Zug-Uhren der Kacheln: (Balken, bis, frist) - `Takt` schiebt sie jede Sekunde.</summary>
private readonly List<(Grid Balken, double Bis, double Frist)> _uhren = new();
/// <summary>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.</summary>
private void Raster(List<JsonObject> chips, Dictionary<string, JsonObject> kacheln)
{
var auf = _zeileVon.FirstOrDefault(p => p.Value.Offen).Key ?? "";
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;
for (int i = 0; i <= chips.Max(c => (int)(c.Zahl("spalte_nr") ?? 0)); i++) _raster.ColumnDefinitions.Add(new ColumnDefinition());
for (int i = 0; i <= chips.Max(c => (int)(c.Zahl("zeile_nr") ?? 0)); i++) _raster.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
foreach (var c in chips)
{
var raum = c.T("raum");
var nr = Raum.Nummer(raum);
bool zug = c.Wahr("am_zug");
// Kopf als Grid mit kuerzendem Text: eine horizontale Reihe kuerzt nie, vier Kacheln wurden mit dem
// Limit breiter als die Leiste und schoben die ganze Seite nach rechts - das X der Stufen-Prioritaet
// lag dann ausserhalb (Owner 27.11.: "kann bei den prioritaeten das x nicht klicken")
var kopf = new Grid { ColumnSpacing = 4 };
kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
kopf.ColumnDefinitions.Add(new ColumnDefinition());
kopf.Children.Add(Ui.Punkt(c.T("punkt_ton"), 6).Mit(p => p.VerticalAlignment = VerticalAlignment.Center));
kopf.Children.Add(Ui.Text(nr == raum ? c.T("titel") : "#" + (nr.Length > 4 ? nr[^4..] : nr), 10.5, pinsel: Ui.Zweit, zahlen: true)
.Mit(t => t.TextTrimming = TextTrimming.CharacterEllipsis).Spalte(1));
// klein das Limit bzw. Freeroll/Turnier (Owner 26.11.); ein aelterer Server schickt es nicht
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(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.07),
Child = inhalt,
MinWidth = 0,
};
ToolTipService.SetToolTip(kachel, c.T("log") is { Length: > 0 } lg
? $"{c.T("titel")}\n{(c.Zahl("log_zeit") is double lz ? Format.Uhr(lz) + " " : "")}{Raum.Kurz(lg)}" : c.T("titel"));
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(kachel, raum);
kachel.Tapped += (_, _) =>
{
if (!_zeileVon.TryGetValue(raum, out var z)) return;
z.Offen = !z.Offen;
_rasterAbdruck = "";
Raster(chips, kacheln);
};
Grid.SetRow(kachel, (int)(c.Zahl("zeile_nr") ?? 0));
Grid.SetColumn(kachel, (int)(c.Zahl("spalte_nr") ?? 0));
_raster.Children.Add(kachel);
}
}
/// <summary>Unter dem Raster je Tisch eine Zeile: Punkt, Nummer, Limit, dann was zuletzt an diesem Tisch geschah
/// (am Zug: orange "am Zug"). So steht jede Logzeile bei ihrem Tisch. Antippen klappt den Tisch auf.</summary>
private void Logs(List<JsonObject> chips)
{
var auf = _zeileVon.FirstOrDefault(p => p.Value.Offen).Key ?? "";
var folge = chips.OrderBy(c => c.Zahl("zeile_nr") ?? 0).ThenBy(c => c.Zahl("spalte_nr") ?? 0).ToList();
var abdruck = auf + "|" + string.Join("|", folge.Select(c =>
$"{c.T("raum")}:{c.T("punkt_ton")}:{c.Wahr("am_zug")}:{c.T("log")}:{c.T("log_ton")}:{c.T("log_warn")}:{c.Text("log_zeit")}:{c.T("zeile")}:{c.T("zeile_ton")}"));
if (abdruck == _logAbdruck) return;
_logAbdruck = abdruck;
_logs.Children.Clear();
foreach (var c in folge)
{
var raum = c.T("raum");
bool zug = c.Wahr("am_zug");
var nr = Raum.Nummer(raum);
var g = new Grid { ColumnSpacing = 6, Padding = new Thickness(8, 4, 10, 4), MinHeight = 26 };
g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(44) });
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.Punkt(c.T("punkt_ton"), 6));
g.Children.Add(Ui.Text(nr == raum ? c.T("titel") : nr, 11.5, fett: true, zahlen: true,
pinsel: raum == auf ? Ui.Akzent : null).Mit(t => t.VerticalAlignment = VerticalAlignment.Center).Spalte(1));
var log = Raum.Kurz(c.T("log"));
var ton = c.T("log_ton");
var warn = c.T("log_warn");
bool laut = warn.Length > 0;
if (laut) ton = warn;
var text = new TextBlock { FontSize = 11.5, TextTrimming = TextTrimming.CharacterEllipsis, VerticalAlignment = VerticalAlignment.Center };
if (zug)
text.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run { Text = "am Zug ", Foreground = Ui.Pinsel("orange"), FontWeight = Microsoft.UI.Text.FontWeights.SemiBold });
if (c.Zahl("log_zeit") is double lz)
text.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run { Text = Format.Kurz(lz) + " ", Foreground = Ui.Dritt });
text.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run
{
Text = log.Length > 0 ? log : "noch nichts an diesem Tisch",
Foreground = log.Length == 0 ? Ui.Dritt : laut || c.T("log_art") == "ergebnis" ? Ui.Pinsel(ton) : Ui.Zweit,
});
if (!laut && log.Length > 0 && ton is { Length: > 0 } && ton != "grau")
g.Children.Add(new Border { Width = 3, Height = 12, CornerRadius = new CornerRadius(1.5), Background = Ui.Pinsel(ton, 0.8), VerticalAlignment = VerticalAlignment.Center }.Spalte(2));
else if (laut)
g.Children.Add(Ui.Zeichen("\uE7BA", 10, ton).Mit(z => z.VerticalAlignment = VerticalAlignment.Center).Spalte(2));
g.Children.Add(text.Spalte(3));
g.Children.Add(Ui.Text(c.T("zeile") == "gesessen" ? "" : c.T("zeile"), 11.5, c.T("zeile_ton") is "grau" or "" ? null : c.T("zeile_ton"),
fett: true, zahlen: true, pinsel: c.T("zeile_ton") is "grau" or "" ? Ui.Dritt : null).Mit(t => t.VerticalAlignment = VerticalAlignment.Center).Spalte(4));
ToolTipService.SetToolTip(g, $"{raum}\n{(c.Zahl("log_zeit") is double z2 ? Format.Uhr(z2) + " " : "")}{(log.Length > 0 ? log : "noch keine Zeile")}");
var flaeche = g.Tippen(() =>
{
if (!_zeileVon.TryGetValue(raum, out var zz)) return;
zz.Offen = !zz.Offen;
_rasterAbdruck = _logAbdruck = "";
Zeichnen();
}, 6);
if (_logs.Children.Count > 0) _logs.Children.Add(Ui.Linie().Mit(l => l.Margin = new Thickness(8, 0, 8, 0)));
if (zug) g.Background = Ui.Pinsel("orange", 0.10);
_logs.Children.Add(flaeche);
}
}
/// <summary>Filzgrund: dunkles Tischgruen von oben nach unten (aufgeklappt etwas heller).</summary>
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 },
},
};
/// <summary>Unter Kopf und Netto: eigene Karten mit Topf, darunter Board in Farbe oder die letzte eigene Aktion,
/// am Zug eine ablaufende Uhr als Balken.</summary>
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" : "";
/// <summary>Eine winzige Karte fuer die Kachel (Rang und Farbe, rot oder hell).</summary>
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 ------------------------------------------------------------------------
/// <summary>Fuer die fehlenden Tische eine gestrichelte Such-Kachel: die Luecke ist Absicht, kein Haenger.</summary>
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);
{ // eine Zeile fuer alle: 16 leere Kacheln untereinander sagten auch nicht mehr
var kopf = Ui.Zeile(Ui.Reihe(6, Ui.Zeichen(live.T("such_titel").StartsWith("Warte") ? "" : "", 13, "grau"),
Ui.Text(live.T("such_titel") + (n > 1 ? $" · {n} Tische" : ""), 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).Mit(s => s.Margin = new Thickness(10)));
ToolTipService.SetToolTip(rahmen, live.T("such_text"));
spalte.Children.Add(rahmen);
}
return spalte;
}
private static readonly string[] SchrittZeichen = { "", "", "", "", "" };
/// <summary>Sitzt der Laeufer nirgends: fuenf Schritte als Leiste, "Als Naechstes", die letzte Sitzung.</summary>
private static UIElement? Bereit(JsonObject? b)
{
if (b == null) return null;
var schritte = b.Objekte("schritte").ToList();
// Fehlt nur noch der Tisch, sagt das der Startknopf; die letzte Sitzung steht schon oben
if (schritte.FindIndex(x => !x.Wahr("erledigt")) is < 0 or >= 3) return null;
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));
return spalte;
}
// ---- Geld gegen die Stops ------------------------------------------------------------------
private void Geld(JsonObject? g)
{
var a = g.Abdruck();
if (a == _geldAbdruck) return;
_geldAbdruck = a;
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<JsonObject>())
{
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);
}
}
/// <summary>Ein einklappbarer Abschnitt (Tische.swift `EinklappAbschnitt`): Symbol, Titel, Hinweis, Chevron;
/// der Zustand bleibt je Schluessel ueber Neustarts (lokale Einstellungen).</summary>
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<string>();
zeilen.Add($"{k}={(an ? 1 : 0)}");
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Datei)!);
File.WriteAllLines(Datei, zeilen);
}
catch { }
}
}
/// <summary>
/// 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.
/// </summary>
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<ZugRing> _ringe = new();
private readonly HashSet<string> _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;
}
/// <summary>Countdown des offenen Zugs (der Server schickt nur `bis` und `frist_s`).</summary>
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(Raum.Kurz(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 if (k.T("hinweis") is { Length: > 0 } hinweis) was.Children.Add(Ui.Klein(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);
}
/// <summary>Der Modus des Tisches (ModusLeiste.swift): Chip als Kapsel, Text, Lage, Spur zum Geld.</summary>
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<bool>(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);
}
/// <summary>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.</summary>
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;
}
/// <summary>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.</summary>
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;
}
/// <summary>Legt ein Element mit seiner Mitte auf (x, y).</summary>
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);
}
/// <summary>Ein Gegner als Karte (Gegner.swift `GegnerKarte`): Name, Stack, Stil-Abzeichen, Fold-Chance,
/// Vertrauen, der Satz des Kerns; angetippt alle Werte und die Stichprobe.</summary>
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);
}
}
/// <summary>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.</summary>
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}";
}
}
}