From 9b339423946fb0664c82e3f402d1620e2c707f89 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Sat, 14 Nov 2026 21:22:07 +0100 Subject: [PATCH] Cockpit als native Windows-11-App (WinUI 3, winui/), Optik nach der Mac-App WinUI 3 / Windows App SDK 1.8, C#/.NET 8, unpackaged. Nur Anzeige und Knoepfe: Daten ueber /ws (ansicht), Befehle ueber POST /api/steuern; abgeleitete Anzeige kommt aus sicht/abgeleitet.py. Optisch nach mac/Sources/Cockpit (dunkles Glas, Kapseln, Apple-Systemfarben, Reiterleiste unten). Reiter: Cash (Modus-Kapsel mit Echtgeld-Rueckfrage, Instrument-Kacheln, Tische/Form/Formate, Hauptknopf, Not-Aus mit Halten-zum-Loesen, Sitzungsleiste, Werkzeuge, Bereit-Schritte, Tischkacheln mit Minitisch, Geld, Gerade eben), Haende (Suche, Filter, aufklappbare Zeilen), Statistik (Ergebnis Uebung/Cash/Archiv mit Kurve/Verteilung/Stakes/Stunden/Stapel/Sitzungen, Formatvergleich; Stil Anteile/Verlauf/Groessen/Denkzeit), Protokoll (Gedanken, Ereignisse, Geld), Einstellungen (Allgemein, Humanisierung, Sicherheit; Stimme, Plan-Editor, Streamer folgen). Co-Authored-By: Claude Opus 5.5 --- winui/.gitignore | 3 + winui/App.xaml | 41 ++ winui/App.xaml.cs | 20 + winui/Assets/cockpit.ico | Bin 0 -> 304886 bytes winui/Kern/Ansicht.cs | 140 +++++ winui/Kern/Cockpit.cs | 232 +++++++ winui/Kern/Hauptknopf.cs | 88 +++ winui/Kern/Spielplan.cs | 297 +++++++++ winui/Kern/Verbindung.cs | 176 ++++++ winui/Kern/Wurzel.cs | 83 +++ winui/MainWindow.xaml | 57 ++ winui/MainWindow.xaml.cs | 143 +++++ winui/Pokerfreak.Cockpit.csproj | 30 + winui/Seiten/Bausteine.cs | 328 ++++++++++ winui/Seiten/CashSeite.cs | 603 ++++++++++++++++++ winui/Seiten/EinstellungenSeite.cs | 279 +++++++++ winui/Seiten/HaendeSeite.cs | 258 ++++++++ winui/Seiten/LiveTeil.cs | 955 +++++++++++++++++++++++++++++ winui/Seiten/ProtokollSeite.cs | 154 +++++ winui/Seiten/StatistikSeite.cs | 467 ++++++++++++++ winui/Seiten/Ui.cs | 289 +++++++++ winui/app.manifest | 14 + winui/nuget.config | 7 + 23 files changed, 4664 insertions(+) create mode 100644 winui/.gitignore create mode 100644 winui/App.xaml create mode 100644 winui/App.xaml.cs create mode 100644 winui/Assets/cockpit.ico create mode 100644 winui/Kern/Ansicht.cs create mode 100644 winui/Kern/Cockpit.cs create mode 100644 winui/Kern/Hauptknopf.cs create mode 100644 winui/Kern/Spielplan.cs create mode 100644 winui/Kern/Verbindung.cs create mode 100644 winui/Kern/Wurzel.cs create mode 100644 winui/MainWindow.xaml create mode 100644 winui/MainWindow.xaml.cs create mode 100644 winui/Pokerfreak.Cockpit.csproj create mode 100644 winui/Seiten/Bausteine.cs create mode 100644 winui/Seiten/CashSeite.cs create mode 100644 winui/Seiten/EinstellungenSeite.cs create mode 100644 winui/Seiten/HaendeSeite.cs create mode 100644 winui/Seiten/LiveTeil.cs create mode 100644 winui/Seiten/ProtokollSeite.cs create mode 100644 winui/Seiten/StatistikSeite.cs create mode 100644 winui/Seiten/Ui.cs create mode 100644 winui/app.manifest create mode 100644 winui/nuget.config diff --git a/winui/.gitignore b/winui/.gitignore new file mode 100644 index 00000000..ac8d21bd --- /dev/null +++ b/winui/.gitignore @@ -0,0 +1,3 @@ +bin/ +obj/ +*.user diff --git a/winui/App.xaml b/winui/App.xaml new file mode 100644 index 00000000..e010ac2b --- /dev/null +++ b/winui/App.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/winui/App.xaml.cs b/winui/App.xaml.cs new file mode 100644 index 00000000..c9154f5e --- /dev/null +++ b/winui/App.xaml.cs @@ -0,0 +1,20 @@ +using Microsoft.UI.Xaml; + +namespace Pokerfreak.Cockpit; + +/// Start: ein Fenster, eine Verbindung zum Server (Kern/Verbindung.cs). +public partial class App : Application +{ + private MainWindow? _fenster; + + public App() + { + InitializeComponent(); + } + + protected override void OnLaunched(LaunchActivatedEventArgs args) + { + _fenster = new MainWindow(Kern.Adresse.AusBefehlszeile(Environment.GetCommandLineArgs())); + _fenster.Activate(); + } +} diff --git a/winui/Assets/cockpit.ico b/winui/Assets/cockpit.ico new file mode 100644 index 0000000000000000000000000000000000000000..b0e0ffd6c7d8b88def1d1997b94f724a7594622c GIT binary patch literal 304886 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 J2FB08{{ts|$9@0+ literal 0 HcmV?d00001 diff --git a/winui/Kern/Ansicht.cs b/winui/Kern/Ansicht.cs new file mode 100644 index 00000000..ad4f780c --- /dev/null +++ b/winui/Kern/Ansicht.cs @@ -0,0 +1,140 @@ +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Nodes; + +namespace Pokerfreak.Cockpit.Kern; + +/// +/// Die Ansicht des Servers (sicht/ANSICHT.md), nachsichtig gelesen: fehlt ein Feld oder hat es den +/// falschen Typ, ist es leer - nie ein Fehler. Die Bereiche bleiben JSON; die App liest, was sie zeigt. +/// +public sealed class Ansicht +{ + public JsonObject Teile { get; } + + public Ansicht(JsonObject teile) => Teile = teile; + + public static Ansicht Leer { get; } = new(new JsonObject()); + + public JsonObject? Kopf => Teile.Obj("kopf"); + public JsonObject? Jetzt => Teile.Obj("jetzt"); + public JsonObject? Wachstum => Teile.Obj("wachstum"); + public JsonObject? Entscheidungen => Teile.Obj("entscheidungen"); + public JsonObject? Geld => Teile.Obj("geld"); + public JsonObject? Sitzen => Teile.Obj("sitzen"); + public JsonObject? Stil => Teile.Obj("stil"); + public JsonObject? Ticker => Teile.Obj("ticker"); + public JsonObject? Zuschauer => Teile.Obj("zuschauer"); + + public bool Laeuft => Kopf.Wahr("laeuft"); + public bool Zuschauen => Zuschauer.Wahr("laeuft"); +} + +public static class Json +{ + public static JsonObject? Obj(this JsonObject? o, string k) => o?[k] as JsonObject; + + public static JsonArray Liste(this JsonObject? o, string k) => o?[k] as JsonArray ?? new JsonArray(); + + public static IEnumerable Objekte(this JsonObject? o, string k) => + o.Liste(k).OfType(); + + public static IEnumerable Texte(this JsonObject? o, string k) => + o.Liste(k).Select(TextVon).Where(t => t != null)!; + + public static string? Text(this JsonObject? o, string k) => TextVon(o?[k]); + + public static string T(this JsonObject? o, string k) => o.Text(k) ?? ""; + + public static string? TextVon(JsonNode? n) => n is JsonValue v + ? v.GetValueKind() switch + { + JsonValueKind.String => v.GetValue(), + JsonValueKind.Number => v.GetValue().ToString(CultureInfo.InvariantCulture), + JsonValueKind.True => "true", + JsonValueKind.False => "false", + _ => null, + } + : null; + + public static double? Zahl(this JsonObject? o, string k) => + o?[k] is JsonValue v && v.GetValueKind() == JsonValueKind.Number ? v.GetValue() : null; + + public static bool Wahr(this JsonObject? o, string k) => + o?[k] is JsonValue v && v.GetValueKind() == JsonValueKind.True; + + /// true/false, null wenn das Feld fehlt oder kein Wahrheitswert ist. + public static bool? WahrOderNull(this JsonObject? o, string k) => + o?[k] is JsonValue v ? v.GetValueKind() switch + { + JsonValueKind.True => true, + JsonValueKind.False => false, + _ => null, + } : null; + + /// Gleicher Inhalt? (Kacheln nur neu bauen, wenn sich ihr JSON aendert.) + public static string Abdruck(this JsonNode? n) => n?.ToJsonString() ?? "null"; +} + +/// Zahlen und Zeiten, wie die App sie zeigt: deutsch, Strich fuer unbekannt (format.rs). +public static class Format +{ + private static readonly CultureInfo De = CultureInfo.GetCultureInfo("de-DE"); + + public static string Zahl(double? x, int stellen = 0) + { + if (x is not double v || !double.IsFinite(v)) return "–"; + var s = Math.Round(v, stellen, MidpointRounding.AwayFromZero).ToString("#,0." + new string('#', stellen), De); + return s == "-0" ? "0" : s; + } + + public static string Auto(double? x) => x is double v + ? Zahl(v, Math.Abs(v) >= 100 ? 0 : Math.Abs(v) >= 10 ? 1 : 2) + : "–"; + + /// Achsenzahl: 1200 -> "1,2k", sonst bis eine Nachkommastelle. + public static string Kurzzahl(double v) => Math.Abs(v) >= 1000 + ? Zahl(v / 1000, 1) + "k" + : Zahl(v, Math.Abs(v) >= 10 ? 0 : 1); + + public static string Prozent(double? x) => x is double v ? $"{Zahl(v * 100)} %" : "–"; + + public static string Vorzeichen(double? x, int stellen = 1) + { + if (x is not double v) return "–"; + var t = Zahl(Math.Abs(v), stellen); + return v > 0 ? "+" + t : v < 0 ? "−" + t : t; + } + + public static string Dauer(double s) + { + var g = (long)Math.Max(0, s); + return g >= 3600 ? $"{g / 3600} h {g % 3600 / 60} min" : g >= 60 ? $"{g / 60} min" : $"{g} s"; + } + + public static DateTime Ortszeit(double epoche) => + DateTimeOffset.FromUnixTimeMilliseconds((long)(epoche * 1000)).LocalDateTime; + + public static string Uhr(double? t) => t is double v ? Ortszeit(v).ToString("HH:mm:ss") : "–"; + + public static string Kurz(double? t) => t is double v ? Ortszeit(v).ToString("HH:mm") : ""; + + public static double Jetzt() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() / 1000.0; + + /// "Qh" -> ("Q♥", rot); "Th" -> "10♥". Unlesbares: null. + public static (string Text, bool Rot)? Karte(string? s) + { + if (s is not { Length: 2 }) return null; + var (symbol, rot) = char.ToLowerInvariant(s[1]) switch + { + 'h' => ("♥", true), + 'd' => ("♦", true), + 's' => ("♠", false), + 'c' => ("♣", false), + _ => ("", false), + }; + var r = char.ToUpperInvariant(s[0]); + if (symbol == "" || !"23456789TJQKA".Contains(r)) return null; + return ((r == 'T' ? "10" : r.ToString()) + symbol, rot); + } +} diff --git a/winui/Kern/Cockpit.cs b/winui/Kern/Cockpit.cs new file mode 100644 index 00000000..a82007fc --- /dev/null +++ b/winui/Kern/Cockpit.cs @@ -0,0 +1,232 @@ +using System.Text.Json.Nodes; +using Microsoft.UI.Dispatching; + +namespace Pokerfreak.Cockpit.Kern; + +/// +/// Der Zustand des Fensters: die Ansicht vom Server und was nur im Fenster lebt (die Wahl, Rueckfragen, +/// laufende Knoepfe, die letzte Meldung). Alles hier laeuft auf dem UI-Thread; `Geaendert` sagt den +/// Seiten, dass sie neu zeichnen. Entspricht `Bedienung` + bruecke.rs der Rust-App. +/// +public sealed class CockpitZustand +{ + /// So lange fuehrt der optimistische Not-Aus (Cockpit.swift `notAusGnade`). + public static readonly TimeSpan NotAusGnade = TimeSpan.FromSeconds(6); + private static readonly TimeSpan PlanVerzug = TimeSpan.FromMilliseconds(800); + + private readonly DispatcherQueue _ui; + private readonly DispatcherQueueTimer _planTimer; + private readonly DispatcherQueueTimer _meldungTimer; + + public Verbindung Verbindung { get; } + public Ansicht Ansicht { get; private set; } = Ansicht.Leer; + public bool Verbunden { get; private set; } + public string Getrennt { get; private set; } = "verbindet mit dem Cockpit-Server …"; + public bool JemalsVerbunden { get; private set; } + + public Spielplan Wahl { get; private set; } = Spielplan.Neu(Wurzel.ModusLesen(), 1); + /// Bis zur ersten eigenen Eingabe folgt die Wahl dem Plan des Servers. + public bool Geimpft { get; private set; } + public bool CashFragen { get; set; } + public HashSet Laufend { get; } = new(); + public DateTime? NotAusGewollt { get; private set; } + public Rueckmeldung? Meldung { get; private set; } + public bool Pausiert { get; private set; } = Wurzel.Pausiert(); + /// Fotos je Raum (PNG-Bytes vom Server). + public Dictionary Fotos { get; } = new(); + + public event Action? Geaendert; + + public CockpitZustand(Adresse adresse, DispatcherQueue ui) + { + _ui = ui; + Verbindung = new Verbindung(adresse); + _planTimer = ui.CreateTimer(); + _planTimer.IsRepeating = false; + _planTimer.Interval = PlanVerzug; + _planTimer.Tick += (_, _) => _ = Senden(("spielplan_setzen", Wahl.Daten())); + _meldungTimer = ui.CreateTimer(); + _meldungTimer.IsRepeating = false; + _meldungTimer.Interval = TimeSpan.FromSeconds(8); + _meldungTimer.Tick += (_, _) => { Meldung = null; Melden(); }; + + Verbindung.Aktualisiert += a => _ui.TryEnqueue(() => { Ansicht = a; Abgleichen(); Melden(); }); + Verbindung.Zustand += (ok, grund) => _ui.TryEnqueue(() => + { + Verbunden = ok; + JemalsVerbunden |= ok; + Getrennt = ok ? "" : grund; + Melden(); + }); + Verbindung.Gemeldet += r => _ui.TryEnqueue(() => Rueckmelden(r)); + Verbindung.Starten(); + } + + public void Melden() => Geaendert?.Invoke(); + + /// Ungeimpft uebernimmt die Wahl den Plan des Servers - im zuletzt gewaehlten Modus + /// (Owner 14.11.: "wenn ich in Echtgeld war, soll er nicht in Übung switchen"). Gestartet wird damit nichts. + private void Abgleichen() + { + var p = Spielplan.Aus(Ansicht.Kopf.Obj("spielplan")); + if (p == null) return; + if (!Geimpft) + { + var modus = Wahl.Modus; + Wahl = p; + Wahl.Modus = modus; + } + else + { + Wahl.Gemessen = p.Gemessen; + Wahl.Spielbar = p.Spielbar; + } + } + + public bool NotAus => Ansicht.Kopf.Wahr("not_aus") + || (NotAusGewollt is DateTime t && DateTime.Now - t < NotAusGnade); + + public HauptArt Knopf => Verbunden + ? Hauptknopf.Waehlen(Ansicht.Kopf, true, Wahl, Ansicht.Zuschauen) + : HauptArt.Unbekannt; + + /// Eine Eingabe an der Wahl: aendern, zeigen; laeuft der Laeufer, geht der Plan bald hinaus. + public void Eingabe(Action tun) + { + tun(Wahl); + Geimpft = true; + var k = Ansicht.Kopf; + if (k.Wahr("laeuft") || k.Zahl("pid") != null) + { + _planTimer.Stop(); + _planTimer.Start(); + } + Melden(); + } + + /// Knoepfe nacheinander an den Server; scheitert einer, folgt keiner mehr. + public async Task Senden(params (string Aktion, JsonNode? Daten)[] schritte) => + await SendenRaum(null, schritte); + + public async Task SendenRaum(string? raum, params (string Aktion, JsonNode? Daten)[] schritte) + { + if (schritte.Length == 0) return; + foreach (var (a, _) in schritte) Laufend.Add(a); + Melden(); + try + { + foreach (var (a, d) in schritte) + { + var r = await Verbindung.Senden(a, raum, d); + Rueckmelden(r); + if (!r.Ok) break; + } + } + finally + { + foreach (var (a, _) in schritte) Laufend.Remove(a); + Melden(); + } + } + + public void Rueckmelden(Rueckmeldung r) + { + Meldung = r; + _meldungTimer.Stop(); + _meldungTimer.Start(); + if (r.Bild is string bild && r.Raum is string raum && FotoName(bild) is string name) + _ = FotoLaden(raum, name); + Melden(); + } + + /// "/foto/foto-123.png" -> "foto-123.png"; nur harmlose Namen. + public static string? FotoName(string pfad) + { + if (!pfad.StartsWith("/foto/")) return null; + var n = pfad["/foto/".Length..]; + return n.StartsWith("foto-") && n.EndsWith(".png") && !n.Contains("..") + && n.All(c => char.IsAsciiLetterOrDigit(c) || c is '-' or '_' or '.') + ? n : null; + } + + private async Task FotoLaden(string raum, string name) + { + var b = await Verbindung.Laden("foto/" + name); + if (b == null) return; + _ui.TryEnqueue(() => { Fotos[raum] = b; Melden(); }); + } + + // ---- Knoepfe der Oberflaeche -------------------------------------------------------------- + + public void ModusWaehlen(int i) + { + switch (i) + { + case 0: + CashFragen = false; + Eingabe(w => w.Modus = Modus.Uebung); + if (!Ansicht.Zuschauen) _ = Senden(("zuschauer_starten", null)); + break; + case 1: + CashFragen = false; + Eingabe(w => w.Modus = Modus.Uebung); + Wurzel.ModusMerken(Modus.Uebung); + if (Ansicht.Zuschauen) _ = Senden(("zuschauer_stoppen", null)); + break; + default: + if (!Wahl.Cash) { CashFragen = true; Melden(); } // Echtgeld nur bewusst: erst die Rueckfrage + break; + } + } + + public void CashBestaetigen() + { + CashFragen = false; + Eingabe(w => w.Modus = Modus.Echt); + Wurzel.ModusMerken(Modus.Echt); + if (Ansicht.Zuschauen) _ = Senden(("zuschauer_stoppen", null)); + } + + public void CashAbbrechen() + { + CashFragen = false; + Melden(); + } + + public void HauptknopfDruecken() + { + if (Laufend.Count > 0) return; + var schritte = Knopf.Schritte() + .Select(a => (a, a == "spielplan_setzen" ? (JsonNode?)Wahl.Daten() : null)).ToArray(); + _ = Senden(schritte); + } + + /// Not-Aus: ein Klick haelt sofort an (optimistisch, bis der Server ihn zeigt). + public void NotAusSetzen() + { + NotAusGewollt = DateTime.Now; + _ = Senden(("not_aus_setzen", null)); + Melden(); + } + + /// Loesen nur bewusst (Gedrueckthalten am Knopf) - nie aus Versehen wieder scharf. + public void NotAusLoesen() + { + NotAusGewollt = null; + _ = Senden(("not_aus_loeschen", null)); + Melden(); + } + + public void MeldungWeg() + { + Meldung = null; + _meldungTimer.Stop(); + Melden(); + } + + public void PauseUmschalten() + { + Pausiert = !Pausiert; + Rueckmelden(Wurzel.PauseSetzen(Pausiert)); + } +} diff --git a/winui/Kern/Hauptknopf.cs b/winui/Kern/Hauptknopf.cs new file mode 100644 index 00000000..3a21a029 --- /dev/null +++ b/winui/Kern/Hauptknopf.cs @@ -0,0 +1,88 @@ +using System.Text.Json.Nodes; + +namespace Pokerfreak.Cockpit.Kern; + +/// +/// Der eine grosse Knopf: immer der naechste sinnvolle Schritt (cockpit/src/hauptknopf.rs, +/// Hauptknopf.swift). Die Fallreihenfolge ist Teil des Vertrags: +/// Not-Aus aktiv -> loesen; Laeufer hoert auf -> nichts (ein zweiter Stopp braeche das Auslaufen ab); +/// Laeufer laeuft -> Aufhoeren; Zuschauer laeuft -> Zuschauen beenden; CoinPoker zu -> starten; +/// ohne Debug-Port -> neu starten bzw. Port fehlt; ohne Guthaben/Budget -> Budget fehlt; sonst Starten. +/// Bleibt in der App, weil er von der Wahl im Fenster abhaengt (nicht nur vom Server). +/// +public enum HauptArt +{ + Unbekannt, NotAusLoesen, HoertAuf, Aufhoeren, ZuschauenBeenden, FreigabeFehlt, ClientStarten, + BudgetFehlt, ClientNeuStarten, PortFehlt, UebungStarten, EchtgeldStarten, +} + +public static class Hauptknopf +{ + public static HauptArt Waehlen(JsonObject? k, bool fensterLesbar, Spielplan wahl, bool zuschauen) + { + if (k == null) return HauptArt.Unbekannt; + if (k.Wahr("not_aus")) return HauptArt.NotAusLoesen; + if (k.Wahr("laeuft") || k.Zahl("pid") != null) + return k.Wahr("hoert_auf") ? HauptArt.HoertAuf : HauptArt.Aufhoeren; + if (zuschauen) return HauptArt.ZuschauenBeenden; + if (!fensterLesbar) return HauptArt.FreigabeFehlt; + if (k.WahrOderNull("client") == false) return HauptArt.ClientStarten; + if (k.WahrOderNull("client_port") == false) + return (k.Zahl("tische_offen") ?? 0) > 0 ? HauptArt.PortFehlt : HauptArt.ClientNeuStarten; + // Mit "Micro only" ist das Budget aus - dann kann es auch nicht fehlen. + if (wahl.Cash && !wahl.MicroOnly && k.Zahl("guthaben") == null && wahl.Budget == null) + return HauptArt.BudgetFehlt; + return wahl.Cash ? HauptArt.EchtgeldStarten : HauptArt.UebungStarten; + } + + /// Die Knoepfe von sicht/steuern.py, nacheinander; bricht einer ab, folgt keiner mehr. + public static string[] Schritte(this HauptArt a) => a switch + { + HauptArt.NotAusLoesen => new[] { "not_aus_loeschen" }, + HauptArt.Aufhoeren => new[] { "laeufer_stoppen" }, + HauptArt.ZuschauenBeenden => new[] { "zuschauer_stoppen" }, + HauptArt.UebungStarten or HauptArt.EchtgeldStarten => new[] { "spielplan_setzen", "laeufer_starten" }, + HauptArt.ClientStarten => new[] { "client_starten" }, + HauptArt.ClientNeuStarten => new[] { "client_neu_starten" }, + _ => Array.Empty(), + }; + + public static string Titel(this HauptArt a) => a switch + { + HauptArt.Unbekannt => "…", + HauptArt.NotAusLoesen => "Not-Aus lösen", + HauptArt.HoertAuf => "Hört auf …", + HauptArt.Aufhoeren => "Aufhören", + HauptArt.ZuschauenBeenden => "Zuschauen beenden", + HauptArt.FreigabeFehlt => "Freigabe fehlt", + HauptArt.ClientStarten => "CoinPoker starten", + HauptArt.BudgetFehlt => "Budget angeben", + HauptArt.ClientNeuStarten => "CoinPoker neu starten", + HauptArt.PortFehlt => "Debug-Port fehlt", + HauptArt.EchtgeldStarten => "Echtgeld starten", + _ => "Übung starten", + }; + + /// Segoe Fluent Icons. + public static string Zeichen(this HauptArt a) => a switch + { + HauptArt.Unbekannt => "", + HauptArt.NotAusLoesen or HauptArt.UebungStarten => "", + HauptArt.HoertAuf => "", + HauptArt.Aufhoeren => "", + HauptArt.EchtgeldStarten or HauptArt.ClientStarten or HauptArt.ClientNeuStarten => "", + _ => "", + }; + + /// Farbname (Ton) des Zeichens. + public static string Ton(this HauptArt a) => a switch + { + HauptArt.Aufhoeren or HauptArt.HoertAuf => "orange", + HauptArt.ZuschauenBeenden => "teal", + HauptArt.EchtgeldStarten => "rot", + HauptArt.UebungStarten or HauptArt.NotAusLoesen or HauptArt.ClientStarten or HauptArt.ClientNeuStarten => "gruen", + _ => "grau", + }; + + public static bool Wirksam(this HauptArt a) => a.Schritte().Length > 0; +} diff --git a/winui/Kern/Spielplan.cs b/winui/Kern/Spielplan.cs new file mode 100644 index 00000000..899354be --- /dev/null +++ b/winui/Kern/Spielplan.cs @@ -0,0 +1,297 @@ +using System.Text.Json.Nodes; + +namespace Pokerfreak.Cockpit.Kern; + +/// Was an einem Tisch gespielt wird (lesen/formate.py) - nicht der Modus (Uebung/Cash). +public enum SpielFormat { Cash, CashPlo, Aof, Bombpot, Turnier, Kpoker, Vip, Freeroll } + +public static class Formate +{ + public static readonly SpielFormat[] Alle = Enum.GetValues(); + + public static string Roh(this SpielFormat f) => f switch + { + SpielFormat.Cash => "cash", + SpielFormat.CashPlo => "cash_plo", + SpielFormat.Aof => "aof", + SpielFormat.Bombpot => "bombpot", + SpielFormat.Turnier => "turnier", + SpielFormat.Kpoker => "kpoker", + SpielFormat.Vip => "vip", + _ => "freeroll", + }; + + public static SpielFormat? AusRoh(string? s) => Alle.Cast().FirstOrDefault(f => f!.Value.Roh() == s); + + public static string Name(this SpielFormat f) => f switch + { + SpielFormat.Cash => "Cash NLH", + SpielFormat.CashPlo => "Cash PLO", + SpielFormat.Aof => "All-In or Fold", + SpielFormat.Bombpot => "Bomb Pot", + SpielFormat.Turnier => "Turnier", + SpielFormat.Kpoker => "K-Poker", + SpielFormat.Vip => "VIP Arena", + _ => "Freerolls", + }; + + /// Segoe Fluent Icons je Format. + public static string Zeichen(this SpielFormat f) => f switch + { + SpielFormat.Cash => "", // Kreis + SpielFormat.CashPlo => "", // Liste + SpielFormat.Aof => "", // Blitz + SpielFormat.Bombpot => "", // Energie + SpielFormat.Turnier => "", // Fahne + SpielFormat.Kpoker => "", // Tastatur + SpielFormat.Vip => "", // Stern + _ => "", // Geschenk + }; +} + +public enum Modus { Uebung, Echt } + +public enum Tischform { Multiway, Hu, Beide } + +/// +/// Der Spielplan, wie das Cockpit ihn einstellt und vom Server liest (cockpit/src/spielplan.rs, +/// betrieb/spielplan.py): Uebung oder Cash, Tische je Format, Budget, Ziel (Ausweichen), Fuellfolge. +/// Zeit-, Geld- und Turnierplan gehen unveraendert zurueck (der Plan-Editor ist ein Folgeschritt). +/// +public sealed class Spielplan +{ + public const int Hoechstens = 12; + + public Modus Modus = Modus.Uebung; + private readonly SortedDictionary _formate = new() { [SpielFormat.Cash] = 1 }; + public HashSet Gemessen = new() { SpielFormat.Cash }; + public HashSet Spielbar = new() { SpielFormat.Cash, SpielFormat.Aof }; + private int? _ziel; + private List _reihenfolge = new(); + public double? Budget; + private int? _tischeBis; + public bool Zeiger, Lehrer, MicroOnly; + public Tischform Tischform = Tischform.Multiway; + public JsonObject? Zeitplan, Geld, Turnier; + + public static Spielplan Neu(Modus m, int tische, double? budget = null) + { + var p = new Spielplan { Modus = m, Budget = budget > 0 ? budget : null }; + p._formate[SpielFormat.Cash] = Klemmen(tische); + return p; + } + + public Spielplan Kopie() => Aus(Daten(), mitListe: false) is { } p + ? p.Mit(x => { x.Modus = Modus; x.Gemessen = new(Gemessen); x.Spielbar = new(Spielbar); x.Budget = Budget; }) + : Neu(Modus, 1); + + private Spielplan Mit(Action a) { a(this); return this; } + + private static int Klemmen(int n) => Math.Clamp(n, 1, Hoechstens); + + public bool Cash => Modus == Modus.Echt; + + public int Anzahl(SpielFormat f) => _formate.TryGetValue(f, out var n) ? n : 0; + + public int Tische + { + get + { + var summe = _formate.Values.Sum(); + return _ziel is int z ? Math.Min(z, summe) : summe; + } + } + + public void TischeSetzen(int n) + { + if (_ziel != null) { ZielSetzen(n); return; } + var rest = Tische - Anzahl(SpielFormat.Cash); + Setzen(SpielFormat.Cash, n - rest); + } + + public int? Ziel => _ziel; + + public void ZielSetzen(int? z) + { + _ziel = z is int v ? Klemmen(v) : null; + _tischeBis = Spanne(Tische, _tischeBis); + } + + public int? TischeBis => _tischeBis; + + public void TischeBisSetzen(int? bis) => _tischeBis = Spanne(Tische, bis); + + private static int? Spanne(int von, int? bis) => bis is int b && b > von ? Math.Min(b, Hoechstens) : null; + + /// Die Fuellfolge: genannte zuerst, dann der Rest in fester Reihenfolge. + public List Folge() + { + var genannt = _reihenfolge.Where(f => Anzahl(f) > 0).ToList(); + var folge = new List(genannt); + folge.AddRange(Formate.Alle.Where(f => Anzahl(f) > 0 && !genannt.Contains(f))); + return folge; + } + + public void Setzen(SpielFormat f, int n) + { + var grenze = _ziel != null ? Hoechstens : Hoechstens - (Tische - Anzahl(f)); + var neu = Math.Max(0, Math.Min(n, grenze)); + var davor = Folge(); + if (neu > 0) _formate[f] = neu; else _formate.Remove(f); + var reihe = davor.Where(x => Anzahl(x) > 0).ToList(); + reihe.AddRange(Folge().Where(x => !davor.Contains(x))); + Ordnen(reihe); + _tischeBis = Spanne(Tische, _tischeBis); + } + + public void Ausweichen(bool an) + { + if (an) { ZielSetzen(Math.Max(1, Tische)); return; } + var reihe = Folge(); + _ziel = null; + var rest = Hoechstens; + foreach (var f in reihe) + { + var n = Math.Min(Anzahl(f), rest); + if (n > 0) _formate[f] = n; else _formate.Remove(f); + rest -= n; + } + _tischeBis = Spanne(Tische, _tischeBis); + } + + public void Vorziehen(SpielFormat f) + { + var reihe = Folge(); + var i = reihe.IndexOf(f); + if (i <= 0) return; + (reihe[i], reihe[i - 1]) = (reihe[i - 1], reihe[i]); + Ordnen(reihe); + } + + private void Ordnen(List reihe) + { + var vorgabe = Formate.Alle.Where(reihe.Contains).ToList(); + _reihenfolge = reihe.SequenceEqual(vorgabe) ? new() : reihe; + } + + /// kopf.spielplan des Servers -> Spielplan; null, wenn unlesbar. + public static Spielplan? Aus(JsonObject? o, bool mitListe = true) + { + if (o == null) return null; + var modus = o.Text("modus") switch { "uebung" => Modus.Uebung, "cash" => Modus.Echt, _ => (Modus?)null }; + if (modus == null || o.Zahl("tische") is not double tische) return null; + var p = Neu(modus.Value, (int)tische, o.Zahl("budget")); + p.ZielSetzen(o.Zahl("ziel") is double z ? (int)z : null); + p.TischeBisSetzen(o.Zahl("tische_bis") is double b ? (int)b : null); + p.Zeiger = o.Wahr("zeiger"); + p.Lehrer = o.Wahr("lehrer"); + p.MicroOnly = o.Wahr("micro_only"); + p.Tischform = o.Text("tischform") switch + { + "hu" => Tischform.Hu, + "beide" => Tischform.Beide, + _ => Tischform.Multiway, + }; + p.Zeitplan = o.Obj("zeitplan")?.DeepClone() as JsonObject; + p.Geld = o.Obj("geld")?.DeepClone() as JsonObject; + p.Turnier = o.Obj("turnier")?.DeepClone() as JsonObject; + if (o.Obj("formate") is JsonObject roh) + { + p._formate.Clear(); + foreach (var f in Formate.Alle) + if (roh.Zahl(f.Roh()) is double n) p.Setzen(f, (int)n); + // Alt-Plaene mit freeroll/vip: EINE Turnier-Kachel, der Typ steckt in turnier.kategorie + var extra = p.Anzahl(SpielFormat.Freeroll) + p.Anzahl(SpielFormat.Vip); + if (extra > 0) + { + var neu = p.Anzahl(SpielFormat.Turnier) > 0 ? p.Anzahl(SpielFormat.Turnier) : extra; + p._formate.Remove(SpielFormat.Freeroll); + p._formate.Remove(SpielFormat.Vip); + if (neu > 0) p._formate[SpielFormat.Turnier] = neu; + } + p._tischeBis = Spanne(p.Tische, o.Zahl("tische_bis") is double b2 ? (int)b2 : null); + } + if (o["reihenfolge"] is JsonArray namen) + { + var genannt = namen.Select(Json.TextVon).Select(Formate.AusRoh).Where(f => f != null).Select(f => f!.Value).ToList(); + var reihe = genannt.Where(x => p.Anzahl(x) > 0).ToList(); + reihe.AddRange(p.Folge().Where(x => !genannt.Contains(x))); + p.Ordnen(reihe); + } + if (mitListe && o["formate_liste"] is JsonArray liste) + { + var eintraege = liste.OfType() + .Select(e => (F: Formate.AusRoh(e.Text("format")), G: e.WahrOderNull("gemessen"), S: e.WahrOderNull("spielbar"))) + .Where(e => e.F != null && e.G != null).ToList(); + p.Gemessen = eintraege.Where(e => e.G == true).Select(e => e.F!.Value).ToHashSet(); + if (eintraege.Any(e => e.S != null)) + p.Spielbar = eintraege.Where(e => e.S == true).Select(e => e.F!.Value).ToHashSet(); + } + return p; + } + + /// Die Daten fuer spielplan_setzen (betrieb/spielplan.py). + public JsonObject Daten() + { + var d = new JsonObject + { + ["modus"] = Cash ? "cash" : "uebung", + ["tische"] = Math.Max(1, Tische), + }; + if (!(_formate.Count == 1 && _formate.ContainsKey(SpielFormat.Cash))) + { + var m = new JsonObject(); + foreach (var (k, v) in _formate) m[k.Roh()] = v; + d["formate"] = m; + } + if (_ziel is int z) d["ziel"] = z; + if (_reihenfolge.Count > 0) d["reihenfolge"] = new JsonArray(_reihenfolge.Select(f => (JsonNode)f.Roh()).ToArray()); + if (Cash && Budget is double b) d["budget"] = b == Math.Truncate(b) ? (JsonNode)(long)b : b; + if (_tischeBis is int bis) d["tische_bis"] = bis; + if (Zeiger) d["zeiger"] = true; + if (Lehrer) d["lehrer"] = true; + if (MicroOnly) d["micro_only"] = true; + if (Turnier != null) d["turnier"] = Turnier.DeepClone(); + d["tischform"] = Tischform switch { Tischform.Hu => "hu", Tischform.Beide => "beide", _ => "multiway" }; + if (Zeitplan is { Count: > 0 }) d["zeitplan"] = Zeitplan.DeepClone(); + if (Geld is { Count: > 0 }) d["geld"] = Geld.DeepClone(); + return d; + } + + /// Titel und Fuss der Plan-Kachel: eine Vorlage oder "Eigener" mit der Kurzform des Zeitplans. + /// Erkennt die Vorlagen am Zeitplan (plankarte.rs prueft zusaetzlich den Geldplan). + public (string Titel, string Fuss) PlanText() + { + var z = Zeitplan; + var sitzung = Paar(z, "sitzung"); + var pause = Paar(z, "pause"); + var n = z.Zahl("sitzungen"); + var fenster = z?["fenster"] as JsonArray; + if (sitzung == null && (pause == null || pause.Value.B <= 0) && n == null && fenster == null) + return ("Dauerlauf", "bis du stoppst · −250 BB"); + if (sitzung == (60, 90) && pause == (10, 20) && n == 3 && fenster == null) + return ("Feierabend", "3 × 60–90 min · Pausen"); + if (sitzung == (30, 45) && (pause == null || pause.Value.B <= 0) && n == 1 && fenster == null) + return ("Kurz & sicher", "30–45 min · ±100 BB"); + var teile = new List { sitzung is { } s ? $"{Minuten(s)} min" : "ohne Ende" }; + if (pause is { B: > 0 } p) teile.Add($"Pause {Minuten(p)}"); + if (n is double sn) teile.Add($"{sn}×"); + if (fenster is { Count: 2 }) teile.Add($"{Json.TextVon(fenster[0])}–{Json.TextVon(fenster[1])}"); + return ("Eigener", string.Join(" · ", teile)); + } + + public bool Unendlich => Paar(Zeitplan, "sitzung") == null; + + private static (double A, double B)? Paar(JsonObject? z, string k) => + z?[k] is JsonArray { Count: 2 } a && a[0] is JsonValue x && a[1] is JsonValue y + && x.TryGetValue(out var va) && y.TryGetValue(out var vb) + ? (va, vb) + : null; + + private static string Minuten((double A, double B) s) => + s.A == s.B ? $"{s.A}" : $"{s.A}–{s.B}"; + + public int ReserveBuyins => (int)(Geld.Zahl("reserve_buyins") ?? 20); + + public bool KaufMax => Geld.Text("kauf") == "max"; +} diff --git a/winui/Kern/Verbindung.cs b/winui/Kern/Verbindung.cs new file mode 100644 index 00000000..923a4321 --- /dev/null +++ b/winui/Kern/Verbindung.cs @@ -0,0 +1,176 @@ +using System.Net.Http; +using System.Net.WebSockets; +using System.Text; +using System.Text.Json; +using System.Text.Json.Nodes; + +namespace Pokerfreak.Cockpit.Kern; + +/// Wo der Server steht: 127.0.0.1:8787, sonst --adresse host:port oder POKERFREAK_ADRESSE. +public sealed record Adresse(string Host, int Port) +{ + public Uri Ws => new($"ws://{Host}:{Port}/ws"); + public Uri Steuern => new($"http://{Host}:{Port}/api/steuern"); + public Uri Basis => new($"http://{Host}:{Port}/"); + + public static Adresse AusBefehlszeile(string[] argv) + { + string? roh = Environment.GetEnvironmentVariable("POKERFREAK_ADRESSE"); + for (int i = 0; i < argv.Length - 1; i++) + if (argv[i] == "--adresse") roh = argv[i + 1]; + return Lesen(roh); + } + + public static Adresse Lesen(string? roh) + { + var a = new Adresse("127.0.0.1", 8787); + if (string.IsNullOrWhiteSpace(roh)) return a; + roh = roh.Trim(); + foreach (var p in new[] { "ws://", "http://" }) + if (roh.StartsWith(p)) roh = roh[p.Length..]; + roh = roh.Split('/')[0]; + var teile = roh.Split(':'); + return teile.Length == 2 && int.TryParse(teile[1], out var port) + ? new Adresse(teile[0], port) + : new Adresse(roh, 8787); + } +} + +/// Was ein Knopf des Servers zurueckmeldet ({ok, text}, auch ueber den WebSocket). +public sealed record Rueckmeldung(string Aktion, bool Ok, string Text, string? Raum = null, string? Bild = null, + JsonObject? Roh = null); + +/// +/// Die eine WebSocket-Verbindung zum Server (sicht/ws.py): beim Verbinden alle Bereiche, danach nur +/// geaenderte. Haelt die zusammengefuehrte Ansicht und meldet jede Aenderung; verbindet von selbst neu. +/// Ereignisse kommen auf einem Hintergrund-Thread - die Oberflaeche wechselt selbst auf ihren. +/// +public sealed class Verbindung : IDisposable +{ + private readonly Adresse _adresse; + private readonly CancellationTokenSource _ende = new(); + private readonly HttpClient _http = new() { Timeout = TimeSpan.FromSeconds(20) }; + private readonly object _sperre = new(); + private JsonObject _teile = new(); + + public event Action? Aktualisiert; + public event Action? Zustand; // verbunden?, Grund + public event Action? Gemeldet; + + public Verbindung(Adresse adresse) => _adresse = adresse; + + public Adresse Adresse => _adresse; + + public void Starten() => _ = Task.Run(Schleife); + + private async Task Schleife() + { + var warte = TimeSpan.FromMilliseconds(500); + while (!_ende.IsCancellationRequested) + { + string grund; + try + { + using var ws = new ClientWebSocket(); + ws.Options.KeepAliveInterval = TimeSpan.FromSeconds(15); + using (var frist = CancellationTokenSource.CreateLinkedTokenSource(_ende.Token)) + { + frist.CancelAfter(TimeSpan.FromSeconds(5)); + await ws.ConnectAsync(_adresse.Ws, frist.Token); + } + Zustand?.Invoke(true, ""); + warte = TimeSpan.FromMilliseconds(500); + await Lesen(ws); + grund = "Verbindung geschlossen"; + } + catch (OperationCanceledException) when (_ende.IsCancellationRequested) { return; } + catch (Exception e) + { + grund = e is WebSocketException or HttpRequestException or OperationCanceledException + ? $"kein Cockpit-Server auf {_adresse.Host}:{_adresse.Port}" + : e.Message; + } + Zustand?.Invoke(false, grund); + try { await Task.Delay(warte, _ende.Token); } catch (OperationCanceledException) { return; } + warte = TimeSpan.FromMilliseconds(Math.Min(4000, warte.TotalMilliseconds * 2)); + } + } + + private async Task Lesen(ClientWebSocket ws) + { + var puffer = new byte[1 << 16]; + var text = new MemoryStream(); + while (ws.State == WebSocketState.Open && !_ende.IsCancellationRequested) + { + var r = await ws.ReceiveAsync(puffer, _ende.Token); + if (r.MessageType == WebSocketMessageType.Close) return; + text.Write(puffer, 0, r.Count); + if (!r.EndOfMessage) continue; + var json = Encoding.UTF8.GetString(text.GetBuffer(), 0, (int)text.Length); + text.SetLength(0); + Verarbeiten(json); + } + } + + private void Verarbeiten(string json) + { + JsonNode? n; + try { n = JsonNode.Parse(json); } catch (JsonException) { return; } + if (n is not JsonObject o) return; + var typ = o["typ"]?.GetValue(); + if (typ == "ansicht" && o["teile"] is JsonObject neu) + { + Ansicht a; + lock (_sperre) + { + var kopie = (JsonObject)_teile.DeepClone(); + foreach (var (k, v) in neu) kopie[k] = v?.DeepClone(); + _teile = kopie; + a = new Ansicht(kopie); + } + Aktualisiert?.Invoke(a); + } + else if (typ == "rueckmeldung") + { + Gemeldet?.Invoke(RueckmeldungAus(o)); + } + } + + private static Rueckmeldung RueckmeldungAus(JsonObject o) => new( + o.Text("aktion") ?? "", o.Wahr("ok"), o.Text("text") ?? "", o.Text("raum"), o.Text("bild")); + + /// Ein Knopf des Servers (POST /api/steuern {aktion, raum?, daten?}); wirft nie. + public async Task Senden(string aktion, string? raum = null, JsonNode? daten = null) + { + var koerper = new JsonObject { ["aktion"] = aktion }; + if (raum != null) koerper["raum"] = raum; + if (daten != null) koerper["daten"] = daten.DeepClone(); + try + { + using var inhalt = new StringContent(koerper.ToJsonString(), Encoding.UTF8, "application/json"); + using var antwort = await _http.PostAsync(_adresse.Steuern, inhalt, _ende.Token); + var text = await antwort.Content.ReadAsStringAsync(_ende.Token); + var o = JsonNode.Parse(text) as JsonObject; + return o == null + ? new Rueckmeldung(aktion, false, $"Antwort unlesbar ({(int)antwort.StatusCode})") + : new Rueckmeldung(aktion, o.Wahr("ok"), o.Text("text") ?? "", o.Text("raum") ?? raum, o.Text("bild"), o); + } + catch (Exception e) + { + return new Rueckmeldung(aktion, false, $"Server nicht erreicht: {e.Message}"); + } + } + + /// Ein Bild vom Server (/foto/<name>.png) als Bytes; null bei Fehler. + public async Task Laden(string pfad) + { + try { return await _http.GetByteArrayAsync(new Uri(_adresse.Basis, pfad.TrimStart('/')), _ende.Token); } + catch { return null; } + } + + public void Dispose() + { + _ende.Cancel(); + _http.Dispose(); + } +} diff --git a/winui/Kern/Wurzel.cs b/winui/Kern/Wurzel.cs new file mode 100644 index 00000000..a95c99fa --- /dev/null +++ b/winui/Kern/Wurzel.cs @@ -0,0 +1,83 @@ +namespace Pokerfreak.Cockpit.Kern; + +/// +/// Was die App selbst auf der Platte tut - so wenig wie moeglich: die Pausendateien (wie Mac- und +/// Rust-App, bruecke_live.rs) und der zuletzt gewaehlte Modus (geteilt mit dem Rust-Cockpit). +/// +public static class Wurzel +{ + /// Der Projektordner: POKERFREAK_WURZEL, sonst aufwaerts vom Programm bis zu einem Ordner mit lesen/ und sicht/. + public static string? Finden() + { + var env = Environment.GetEnvironmentVariable("POKERFREAK_WURZEL"); + if (!string.IsNullOrEmpty(env) && Directory.Exists(env)) return env; + var d = new DirectoryInfo(AppContext.BaseDirectory); + while (d != null) + { + if (Directory.Exists(Path.Combine(d.FullName, "lesen")) && Directory.Exists(Path.Combine(d.FullName, "sicht"))) + return d.FullName; + d = d.Parent; + } + return null; + } + + private static IEnumerable PausePfade() + { + var w = Finden(); + if (w == null) yield break; + foreach (var p in new[] { "scratch/pause", "hand/scratch/pause", "betrieb/scratch/pause" }) + yield return Path.Combine(w, p); + } + + public static bool Pausiert() => PausePfade().Any(File.Exists); + + /// Pause setzen oder loesen; die Rueckmeldung sagt, ob es geklappt hat. + public static Rueckmeldung PauseSetzen(bool an) + { + var pfade = PausePfade().ToList(); + var fehler = new List(); + foreach (var p in pfade) + { + try + { + if (an) + { + Directory.CreateDirectory(Path.GetDirectoryName(p)!); + File.WriteAllText(p, "pause"); + } + else if (File.Exists(p)) File.Delete(p); + } + catch (Exception) { fehler.Add(p); } + } + var ok = fehler.Count == 0 && pfade.Count > 0; + var text = (an, ok) switch + { + (true, true) => "Pause - der Läufer klickt nicht mehr, Tische und Sitz bleiben", + (false, true) => "Fortgesetzt - der Läufer spielt weiter", + _ when pfade.Count == 0 => "Projektordner nicht gefunden - Pause nicht gesetzt", + _ => $"Pause nicht {(an ? "gesetzt" : "gelöst")}: {string.Join(", ", fehler)}", + }; + return new Rueckmeldung(an ? "pausieren" : "fortsetzen", ok, text); + } + + // %APPDATA%\Pokerfreak\modus.txt ("echt" | "uebung") - dieselbe Datei wie das Rust-Cockpit. + private static string ModusDatei() => + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Pokerfreak", "modus.txt"); + + /// Nur ein ausdrueckliches "echt" gibt Echtgeld, alles andere Uebung. + public static Modus ModusLesen() + { + try { return File.ReadAllText(ModusDatei()).Trim() == "echt" ? Modus.Echt : Modus.Uebung; } + catch { return Modus.Uebung; } + } + + public static void ModusMerken(Modus m) + { + try + { + Directory.CreateDirectory(Path.GetDirectoryName(ModusDatei())!); + File.WriteAllText(ModusDatei(), m == Modus.Echt ? "echt" : "uebung"); + } + catch { } + } +} diff --git a/winui/MainWindow.xaml b/winui/MainWindow.xaml new file mode 100644 index 00000000..a49ee772 --- /dev/null +++ b/winui/MainWindow.xaml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/winui/MainWindow.xaml.cs b/winui/MainWindow.xaml.cs new file mode 100644 index 00000000..4ef3b407 --- /dev/null +++ b/winui/MainWindow.xaml.cs @@ -0,0 +1,143 @@ +using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using Pokerfreak.Cockpit.Kern; +using Pokerfreak.Cockpit.Seiten; +using Windows.Graphics; +using Windows.UI; + +namespace Pokerfreak.Cockpit; + +/// +/// Das Cockpit-Fenster nach der Leiste der Mac-App (Wurzel.swift `Leiste`): schmal und hoch (440 x 900), +/// tiefes Glas mit Gluehen (blau in Uebung, rot in Echtgeld, roter Rand bei Echtgeld/Not-Aus), oben +/// Verbindung/Klon/Laufzeit/Zahnrad, unten die Reiter mit Symbol und Namen. Die Seiten bleiben am Leben. +/// +public sealed partial class MainWindow : Window +{ + private static readonly (string Tag, string Titel, string Glyph)[] Reiter = + { + ("cash", "Cash", ""), ("haende", "Hände", ""), + ("statistik", "Statistik", ""), ("protokoll", "Protokoll", ""), + }; + + private readonly CockpitZustand _z; + private readonly Dictionary _seiten = new(); + private readonly Dictionary _reiterKnoepfe = new(); + private string _tag = "cash"; + private ISeite? _sichtbar; + private readonly Border _klon = Ui.Abzeichen("Klon", "lila"); + private readonly StackPanel _laufzeit = Ui.Reihe(4); + private readonly TextBlock _laufzeitText = Ui.Winzig(""); + private readonly Button _zahnrad; + + public MainWindow(Adresse adresse) + { + InitializeComponent(); + ExtendsContentIntoTitleBar = true; + SetTitleBar(Titelleiste); + AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Standard; + AppWindow.SetIcon("Assets/cockpit.ico"); + + var skala = DpiSkala(); + AppWindow.Resize(new SizeInt32((int)(440 * skala), (int)(900 * skala))); + if (AppWindow.Presenter is OverlappedPresenter p) p.PreferredMinimumWidth = (int)(380 * skala); + + _z = new CockpitZustand(adresse, DispatcherQueue); + _seiten["cash"] = new CashSeite(_z); + _seiten["haende"] = new HaendeSeite(_z); + _seiten["statistik"] = new StatistikSeite(_z); + _seiten["protokoll"] = new ProtokollSeite(_z); + _seiten["einstellungen"] = new EinstellungenSeite(_z); + + for (int i = 0; i < Reiter.Length; i++) + { + var (tag, titel, glyph) = Reiter[i]; + var zeichen = Ui.Zeichen(glyph, 15); + var text = Ui.Text(titel, 10.5); + text.HorizontalAlignment = HorizontalAlignment.Center; + var inhalt = Ui.Spalte(2, zeichen, text); + inhalt.HorizontalAlignment = HorizontalAlignment.Stretch; + inhalt.Padding = new Thickness(0, 4, 0, 4); + var knopf = inhalt.Tippen(() => Zeigen(tag), 8, $"{titel} (Strg+{i + 1})"); + Reiterleiste.ColumnDefinitions.Add(new ColumnDefinition()); + Reiterleiste.Children.Add(knopf.Spalte(i)); + _reiterKnoepfe[tag] = (zeichen, text); + var taste = new Microsoft.UI.Xaml.Input.KeyboardAccelerator + { + Key = Windows.System.VirtualKey.Number1 + i, + Modifiers = Windows.System.VirtualKeyModifiers.Control, + }; + taste.Invoked += (_, e) => { e.Handled = true; Zeigen(tag); }; + Wurzel.KeyboardAccelerators.Add(taste); + } + + _laufzeit.Children.Add(Ui.Zeichen("", 10, "grau")); + _laufzeit.Children.Add(_laufzeitText); + _zahnrad = Ui.Symbolknopf("", "Einstellungen", () => Zeigen(_tag == "einstellungen" ? "cash" : "einstellungen"), 14); + KopfRechts.Children.Add(_klon); + KopfRechts.Children.Add(_laufzeit); + KopfRechts.Children.Add(_zahnrad); + + _z.Geaendert += Zeichnen; + Zeigen("cash"); + Closed += (_, _) => _z.Verbindung.Dispose(); + + // Laufende Zeit (Countdown, Dauer) tickt ohne neue Daten weiter + var takt = DispatcherQueue.CreateTimer(); + takt.Interval = TimeSpan.FromSeconds(1); + takt.Tick += (_, _) => _sichtbar?.Takt(); + takt.Start(); + } + + private static double DpiSkala() + { + try { return GetDpiForSystem() / 96.0; } catch { return 1.0; } + } + + [System.Runtime.InteropServices.DllImport("user32.dll")] + private static extern uint GetDpiForSystem(); + + private void Zeigen(string tag) + { + _tag = tag; + _sichtbar = _seiten[tag]; + Inhalt.Content = _sichtbar; + foreach (var (t, (zeichen, text)) in _reiterKnoepfe) + { + var pinsel = t == tag ? Ui.Akzent : Ui.Zweit; + zeichen.Foreground = pinsel; + text.Foreground = pinsel; + } + _zahnrad.Content = Ui.Zeichen("", 14, tag == "einstellungen" ? "blau" : "grau"); + _sichtbar.Zeichnen(); + } + + private void Zeichnen() + { + var k = _z.Ansicht.Kopf; + VerbindungPunkt.Fill = Ui.Pinsel(_z.Verbunden ? "gruen" : _z.JemalsVerbunden ? "rot" : "grau"); + VerbindungText.Text = _z.Verbunden ? "" : _z.Getrennt; + ToolTipService.SetToolTip(VerbindungPunkt, $"{_z.Verbindung.Adresse.Host}:{_z.Verbindung.Adresse.Port}"); + _klon.Visibility = k.Wahr("klon") ? Visibility.Visible : Visibility.Collapsed; + var lz = k.Zahl("laufzeit_s"); + _laufzeit.Visibility = k.Wahr("laeuft") && lz != null ? Visibility.Visible : Visibility.Collapsed; + _laufzeitText.Text = lz is double s ? Format.Dauer(s) : ""; + + // Hintergrund: Echtgeld glueht rot, sonst ein Hauch Blau; Rand rot bei Echtgeld und Not-Aus + bool cash = _z.Wahl.Cash && !_z.Ansicht.Zuschauen; + GluehenFarbe.Color = cash ? Color.FromArgb(0x47, 0xFF, 0x45, 0x3A) : Color.FromArgb(0x24, 0x0A, 0x84, 0xFF); + GluehenRand.Color = cash ? Color.FromArgb(0, 0xFF, 0x45, 0x3A) : Color.FromArgb(0, 0x0A, 0x84, 0xFF); + Wurzel.BorderBrush = _z.NotAus ? Ui.Pinsel("rot") : cash ? Ui.Pinsel("rot", 0.7) : Ui.Weiss(0.10); + Wurzel.BorderThickness = new Thickness(_z.NotAus || cash ? 1.5 : 0.5); + _sichtbar?.Zeichnen(); + } +} + +/// Ein Reiter: zeichnet sich aus dem Zustand neu; `Takt` jede Sekunde fuer laufende Zeit. +public interface ISeite +{ + void Zeichnen(); + void Takt() { } +} diff --git a/winui/Pokerfreak.Cockpit.csproj b/winui/Pokerfreak.Cockpit.csproj new file mode 100644 index 00000000..93610b0f --- /dev/null +++ b/winui/Pokerfreak.Cockpit.csproj @@ -0,0 +1,30 @@ + + + + WinExe + net8.0-windows10.0.22621.0 + 10.0.19041.0 + Pokerfreak.Cockpit + Pokerfreak.Cockpit + app.manifest + x64 + x64 + win-x64 + true + None + true + true + enable + enable + latest + true + Assets/cockpit.ico + + + + + + + + diff --git a/winui/Seiten/Bausteine.cs b/winui/Seiten/Bausteine.cs new file mode 100644 index 00000000..12f5cf0f --- /dev/null +++ b/winui/Seiten/Bausteine.cs @@ -0,0 +1,328 @@ +using Microsoft.UI.Xaml; +using Pokerfreak.Cockpit.Kern; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Shapes; +using Windows.Foundation; + +namespace Pokerfreak.Cockpit.Seiten; + +/// Kleine Merkzettel des Fensters (gewaehlte Reiterteile, Filter): eine Zeile je Schluessel in +/// %APPDATA%\Pokerfreak\cockpit-winui.txt - wie `@AppStorage` der Mac-App. +public static class Merker +{ + private static string Datei => System.IO.Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Pokerfreak", "cockpit-winui.txt"); + + public static string? Lesen(string k) + { + try + { + foreach (var z in File.ReadAllLines(Datei)) + if (z.StartsWith(k + "=")) return z[(k.Length + 1)..]; + } + catch { } + return null; + } + + public static void Schreiben(string k, string v) + { + try + { + var zeilen = File.Exists(Datei) ? File.ReadAllLines(Datei).Where(z => !z.StartsWith(k + "=")).ToList() : new List(); + zeilen.Add($"{k}={v}"); + Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Datei)!); + File.WriteAllLines(Datei, zeilen); + } + catch { } + } +} + +/// +/// Segmentierte Wahl wie `.pickerStyle(.segmented)` im Stil der Mac-App: eine Kapsel aus Weiss 6 %, +/// das gewaehlte Teil gefuellt. Merkt sich die Wahl unter `schluessel` (falls gegeben). +/// +public sealed class Segmente : UserControl +{ + private readonly Border[] _teile; + private readonly TextBlock[] _texte; + private readonly string? _schluessel; + private readonly string _ton; + private int _index; + public event Action? Gewaehlt; + + public Segmente(string[] namen, string? schluessel = null, int vorgabe = 0, string ton = "blau", double hoehe = 28) + { + _schluessel = schluessel; + _ton = ton; + _index = vorgabe; + if (schluessel != null && int.TryParse(Merker.Lesen(schluessel), out var g) && g >= 0 && g < namen.Length) _index = g; + var raster = new Grid { ColumnSpacing = 2 }; + _teile = new Border[namen.Length]; + _texte = new TextBlock[namen.Length]; + for (var i = 0; i < namen.Length; i++) + { + raster.ColumnDefinitions.Add(new ColumnDefinition()); + _texte[i] = Ui.Text(namen[i], 12, fett: true); + _texte[i].HorizontalAlignment = HorizontalAlignment.Center; + _texte[i].VerticalAlignment = VerticalAlignment.Center; + _teile[i] = new Border { CornerRadius = new CornerRadius(hoehe / 2), Height = hoehe - 4, Child = _texte[i] }; + var n = i; + raster.Children.Add(_teile[i].Tippen(() => Waehlen(n, true), hoehe / 2).Spalte(i)); + } + Content = new Border + { + Background = Ui.Weiss(0.06), + CornerRadius = new CornerRadius(hoehe / 2), + Padding = new Thickness(2), + Child = raster, + }; + Zeigen(); + } + + public int Index + { + get => _index; + set { if (value != _index) { _index = value; Zeigen(); } } + } + + private void Waehlen(int i, bool melden) + { + _index = i; + if (_schluessel != null) Merker.Schreiben(_schluessel, i.ToString()); + Zeigen(); + if (melden) Gewaehlt?.Invoke(i); + } + + private void Zeigen() + { + for (var i = 0; i < _teile.Length; i++) + { + var an = i == _index; + _teile[i].Background = an ? Ui.Pinsel(_ton) : null; + _texte[i].Foreground = an ? Ui.Pinsel(null) : Ui.Zweit; + } + } +} + +/// Ein Menue wie SwiftUI `Menu(titel)`: kleine Kapsel mit Pfeil, "alle" setzt zurueck. +public sealed class Auswahl : UserControl +{ + private readonly string _titel; + private readonly DropDownButton _knopf = new() + { + FontSize = 12, + Padding = new Thickness(10, 3, 8, 4), + CornerRadius = new CornerRadius(12), + Background = Ui.Weiss(0.06), + BorderThickness = new Thickness(0), + }; + private string _abdruck = ""; + public string? Wahl { get; private set; } + public event Action? Geaendert; + + public Auswahl(string titel) + { + _titel = titel; + Content = _knopf; + Werte(Array.Empty()); + } + + public void Setzen(string? w) + { + Wahl = w; + _knopf.Content = w ?? _titel; + _knopf.Foreground = w == null ? Ui.Zweit : Ui.Akzent; + } + + public void Werte(IEnumerable werte) + { + var liste = werte.ToList(); + var abdruck = string.Join("|", liste); + if (abdruck == _abdruck && _knopf.Flyout != null) return; + _abdruck = abdruck; + var menue = new MenuFlyout(); + var alle = new MenuFlyoutItem { Text = "alle" }; + alle.Click += (_, _) => { Setzen(null); Geaendert?.Invoke(); }; + menue.Items.Add(alle); + foreach (var w in liste) + { + var e = new MenuFlyoutItem { Text = w }; + e.Click += (_, _) => { Setzen(w); Geaendert?.Invoke(); }; + menue.Items.Add(e); + } + _knopf.Flyout = menue; + _knopf.IsEnabled = liste.Count > 0; + Setzen(Wahl); + } +} + +/// Bausteine der Auswertungsseiten (Bausteine.swift `Kennzahl`, `Leer`). +public static class Teile +{ + /// Eine Kennzahl: Titel klein, Wert gross, auf heller Flaeche. + public static Border Kennzahl(string titel, string wert, string? ton = null) + { + var s = Ui.Spalte(2, Ui.Winzig(titel), Ui.Gross(wert, 18, ton)); + return Ui.Flaeche(s, 12, 0.06, 10).Mit(b => b.HorizontalAlignment = HorizontalAlignment.Stretch); + } + + /// Platzhalter mittig: Symbol, Titel, Satz. + public static StackPanel Leer(string titel, string text, string glyph = "") + { + var s = Ui.Spalte(6, + Ui.Zeichen(glyph, 28, "grau").Mit(z => z.HorizontalAlignment = HorizontalAlignment.Center), + Ui.Text(titel, 15, fett: true).Mit(t => t.HorizontalAlignment = HorizontalAlignment.Center), + Ui.Klein(text, true).Mit(t => { t.TextAlignment = TextAlignment.Center; t.HorizontalAlignment = HorizontalAlignment.Center; })); + s.HorizontalAlignment = HorizontalAlignment.Center; + s.VerticalAlignment = VerticalAlignment.Center; + s.Margin = new Thickness(24, 40, 24, 40); + s.MaxWidth = 320; + return s; + } + + /// Ergebnisfarbe wie `Farben.ergebnis`: gruen > 0, rot < 0, sonst Text. + public static string? Ton(double? x) => x is double v ? (v > 0 ? "gruen" : v < 0 ? "rot" : null) : null; + + /// Kleine Textknopf-Kapsel (`.buttonStyle(.borderless)` bzw. `.borderedProminent`). + public static Tippflaeche Knopf(string text, Action tun, string? ton = null, bool voll = false) + { + var b = new Border + { + CornerRadius = new CornerRadius(11), + Padding = new Thickness(10, 3, 10, 4), + Background = voll ? Ui.Pinsel(ton ?? "blau") : Ui.Weiss(0.08), + Child = Ui.Text(text, 12, fett: true, pinsel: voll ? Ui.Pinsel(null) : ton != null ? Ui.Pinsel(ton) : Ui.Akzent), + }; + return b.Tippen(tun, 11); + } +} + +/// +/// Ein Diagramm auf einer Leinwand, das bei jeder Groessenaenderung neu zeichnet. Die Zeichenfunktion +/// bekommt Leinwand, Breite und Hoehe; die Helfer unten zeichnen Linien, Saeulen und Punkte wie Swift Charts +/// in schlicht: leise Gitterlinien, Achsenbeschriftung klein in .tertiary. +/// +public sealed class Diagramm : Grid +{ + private readonly Canvas _leinwand = new(); + private Action? _zeichnen; + + public Diagramm(double hoehe = 220) + { + Height = hoehe; + Children.Add(_leinwand); + SizeChanged += (_, _) => Neu(); + } + + public Action? Zeichnen + { + set { _zeichnen = value; Neu(); } + } + + private void Neu() + { + _leinwand.Children.Clear(); + if (_zeichnen != null && ActualWidth > 20) _zeichnen(_leinwand, ActualWidth, ActualHeight); + } + + public const double Links = 40, Unten = 18; + + /// Achse y mit 4 Gitterlinien von lo bis hi; gibt die Abbildung Wert -> y zurueck. + public static Func AchseY(Canvas c, double b, double h, double lo, double hi, string einheit = "") + { + if (hi - lo < 1e-9) { lo -= 1; hi += 1; } + var oben = 6.0; + double Y(double v) => oben + (h - Unten - oben) * (1 - (v - lo) / (hi - lo)); + for (var i = 0; i <= 4; i++) + { + var v = lo + (hi - lo) * i / 4; + var y = Y(v); + c.Children.Add(new Line { X1 = Links, X2 = b, Y1 = y, Y2 = y, Stroke = Ui.Weiss(0.07), StrokeThickness = 1 }); + var t = Ui.Text(Format.Kurzzahl(v) + einheit, 10, pinsel: Ui.Dritt); + t.Width = Links - 6; + t.TextAlignment = TextAlignment.Right; + Canvas.SetLeft(t, 0); + Canvas.SetTop(t, y - 7); + c.Children.Add(t); + } + if (lo < 0 && hi > 0) + c.Children.Add(new Line { X1 = Links, X2 = b, Y1 = Y(0), Y2 = Y(0), Stroke = Ui.Weiss(0.25), StrokeThickness = 1 }); + return Y; + } + + public static void Beschriftung(Canvas c, string text, double x, double y, double breite = 60) + { + var t = Ui.Text(text, 10, pinsel: Ui.Dritt); + t.Width = breite; + t.TextAlignment = TextAlignment.Center; + Canvas.SetLeft(t, x - breite / 2); + Canvas.SetTop(t, y); + c.Children.Add(t); + } + + /// Linie mit Flaeche darunter (LineMark + AreaMark in Tint 12 %). + public static void Linie(Canvas c, double b, double h, IList<(double X, double Y)> punkte, string ton = "blau", + Func? xText = null, bool flaeche = true, double? lo = null, double? hi = null) + { + if (punkte.Count == 0) return; + var ylo = lo ?? Math.Min(0, punkte.Min(p => p.Y)); + var yhi = hi ?? Math.Max(0, punkte.Max(p => p.Y)); + var Y = AchseY(c, b, h, ylo, yhi); + double x0 = punkte[0].X, x1 = punkte[^1].X; + if (x1 - x0 < 1e-9) x1 = x0 + 1; + double X(double v) => Links + 4 + (b - Links - 8) * (v - x0) / (x1 - x0); + var linie = new Polyline { Stroke = Ui.Pinsel(ton), StrokeThickness = 2, StrokeLineJoin = PenLineJoin.Round }; + foreach (var p in punkte) linie.Points.Add(new Point(X(p.X), Y(p.Y))); + if (flaeche) + { + var f = new Polygon { Fill = Ui.Pinsel(ton, 0.12) }; + var basis = Y(Math.Max(ylo, Math.Min(yhi, 0))); + f.Points.Add(new Point(X(punkte[0].X), basis)); + foreach (var p in punkte) f.Points.Add(new Point(X(p.X), Y(p.Y))); + f.Points.Add(new Point(X(punkte[^1].X), basis)); + c.Children.Add(f); + } + c.Children.Add(linie); + if (punkte.Count <= 40) + foreach (var p in punkte) + { + var e = new Ellipse { Width = 5, Height = 5, Fill = Ui.Pinsel(ton) }; + Canvas.SetLeft(e, X(p.X) - 2.5); + Canvas.SetTop(e, Y(p.Y) - 2.5); + c.Children.Add(e); + } + if (xText != null) + { + Beschriftung(c, xText(x0), Links + 30, h - Unten + 3); + Beschriftung(c, xText(x1), b - 30, h - Unten + 3); + } + } + + /// Saeulen (BarMark): Werte mit Farbe und Beschriftung unten. + public static void Saeulen(Canvas c, double b, double h, IList<(string Name, double Wert, string Ton)> saeulen, + int beschriftungJede = 1) + { + if (saeulen.Count == 0) return; + var Y = AchseY(c, b, h, 0, Math.Max(1, saeulen.Max(s => s.Wert))); + var breite = (b - Links - 4) / saeulen.Count; + for (var i = 0; i < saeulen.Count; i++) + { + var (name, wert, ton) = saeulen[i]; + var x = Links + 4 + i * breite; + var r = new Rectangle + { + Width = Math.Max(1, breite - 3), + Height = Math.Max(0, Y(0) - Y(wert)), + Fill = Ui.Pinsel(ton, 0.7), + RadiusX = 2, + RadiusY = 2, + }; + Canvas.SetLeft(r, x + 1); + Canvas.SetTop(r, Y(wert)); + c.Children.Add(r); + if (i % beschriftungJede == 0) Beschriftung(c, name, x + breite / 2, h - Unten + 3, Math.Max(breite * beschriftungJede, 30)); + } + } +} diff --git a/winui/Seiten/CashSeite.cs b/winui/Seiten/CashSeite.cs new file mode 100644 index 00000000..c7ffc5d8 --- /dev/null +++ b/winui/Seiten/CashSeite.cs @@ -0,0 +1,603 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Shapes; +using Pokerfreak.Cockpit.Kern; +using Windows.UI; + +namespace Pokerfreak.Cockpit.Seiten; + +/// +/// Der Reiter "Cash" nach der Mac-App (Wurzel.swift `Kopfzeile` + Tische.swift `LiveAnsicht`): oben der +/// Kopf (Modus als Kapsel, Instrument-Kacheln, Tischzahl/-form, "Was spielen", Status, Hauptknopf mit +/// rundem Not-Aus), darunter die Rueckmeldungen, dann die Live-Ansicht zum Scrollen. +/// Die Steuerelemente bleiben stehen; `Zeichnen` setzt ihre Werte, Listen bauen nur bei neuem Abdruck. +/// +public sealed class CashSeite : UserControl, ISeite +{ + private readonly CockpitZustand _z; + private bool _zeichnet; + + // Modus + private readonly Border[] _modusTeil = new Border[3]; + private readonly TextBlock[] _modusText = new TextBlock[3]; + private readonly Tippflaeche[] _modusTipp = new Tippflaeche[3]; + private static readonly string[] ModusTon = { "teal", "blau", "rot" }; + private readonly Border _cashFrage; + + // Kacheln + private readonly TextBlock _tischeWert = Ui.Gross("", 24), _tischeFuss = Ui.Winzig(""); + private readonly TextBlock _geldTitel = Ui.Winzig(""), _geldWert = Ui.Gross("Chips", 20, "grau"), _geldFuss = Ui.Winzig(""); + private readonly TextBox _budget = new() + { + PlaceholderText = "alles", + FontSize = 20, + FontWeight = Microsoft.UI.Text.FontWeights.SemiBold, + BorderThickness = new Thickness(0), + Padding = new Thickness(0), + MinHeight = 0, + Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), + }; + private readonly TextBlock _planWert = Ui.Text("", 14, fett: true), _planFuss = Ui.Winzig(""); + private readonly UIElement[] _nurLaeufer; + + // Zeilen + private readonly ComboBox _sitzungArt = new() { FontSize = 12, MinWidth = 0, Padding = new Thickness(8, 2, 4, 2) }; + private readonly TextBlock _stepperText = Ui.Text("", 12); + private readonly Tippflaeche _minus, _plus; + private readonly ComboBox _form = new() { FontSize = 12, MinWidth = 0, Padding = new Thickness(8, 2, 4, 2) }; + private readonly ToggleSwitch _micro = new() { OnContent = "", OffContent = "", MinWidth = 0, Width = 44 }; + + // Was spielen + private readonly TextBlock _zusammen = Ui.Winzig(""); + private readonly ToggleButton _ausweichen = new() { Content = "Ausweichen", FontSize = 11, Padding = new Thickness(8, 1, 8, 2), MinHeight = 0 }; + private readonly StackPanel _zielZeile = Ui.Reihe(6); + private readonly TextBlock _zielText = Ui.Winzig(""); + private readonly Grid _formate = new() { ColumnSpacing = 6, RowSpacing = 6 }; + + // Status und Knoepfe + private readonly Border _phase = Ui.Flaeche(null, 10, 0.06, 0); + private readonly Ellipse _statusPunkt = Ui.Punkt("grau", 10); + private readonly TextBlock _statusSatz = Ui.Text("", 14, fett: true, umbruch: true); + private readonly Grid _statusZeile; + private readonly StackPanel _konto = Ui.Spalte(4); + private readonly Grid _knoepfe = new() { ColumnSpacing = 10 }; + private readonly Border _hauptknopf = new() { CornerRadius = new CornerRadius(22), Height = 44 }; + private readonly Tippflaeche _hauptTipp; + private readonly FontIcon _hauptZeichen = Ui.Zeichen("", 15, ""); + private readonly ProgressRing _hauptRing = new() { Width = 16, Height = 16, IsActive = false, Foreground = Ui.Pinsel("") }; + private readonly TextBlock _hauptTitel = Ui.Text("…", 15, "", fett: true); + private readonly Grid _notAusBand; + private readonly TextBlock _portWarnung; + + // Rueckmeldungen + private readonly Border _wartet, _meldung; + private readonly TextBlock _wartetText = Ui.Text("", 13, umbruch: true), _meldungText = Ui.Text("", 13, umbruch: true); + private readonly FontIcon _meldungZeichen = Ui.Zeichen("", 14); + + private readonly LiveTeil _live; + + public CashSeite(CockpitZustand z) + { + _z = z; + _live = new LiveTeil(z); + + // ---- Modus: Zuschauer | Übung | Echtgeld als Kapsel --------------------------------------- + var modus = new Grid(); + string[] titel = { "Zuschauer", "Übung", "Echtgeld" }; + for (int i = 0; i < 3; i++) + { + int n = i; + modus.ColumnDefinitions.Add(new ColumnDefinition()); + _modusText[i] = Ui.Text(titel[i], 14, fett: true); + _modusText[i].HorizontalAlignment = HorizontalAlignment.Center; + _modusTeil[i] = new Border { CornerRadius = new CornerRadius(16), Padding = new Thickness(0, 6, 0, 7), Child = _modusText[i] }; + _modusTipp[i] = _modusTeil[i].Tippen(() => _z.ModusWaehlen(n), 16); + modus.Children.Add(_modusTipp[i].Spalte(i)); + } + var modusKapsel = new Border { Background = Ui.Weiss(0.07), CornerRadius = new CornerRadius(19), Padding = new Thickness(3), Child = modus }; + ToolTipService.SetToolTip(modusKapsel, "Zuschauer: liest nur, klickt nie · Übung: Claim Chips · Echtgeld: Geld"); + + var abbrechen = new Button { Content = "Abbrechen", FontSize = 12 }; + abbrechen.Click += (_, _) => _z.CashAbbrechen(); + var einschalten = new Button { Content = "Echtgeld einschalten", FontSize = 12, Background = Ui.Pinsel("rot"), Foreground = Ui.Pinsel("") }; + einschalten.Click += (_, _) => _z.CashBestaetigen(); + _cashFrage = Ui.Getoent(Ui.Spalte(8, + Ui.Reihe(6, Ui.Zeichen("", 13, "rot"), Ui.Text("Echtgeld heißt echtes Geld", 14, "rot", fett: true)), + Ui.Klein("Der Läufer öffnet selbst Tische und setzt Geld.", true), + Ui.Zeile(abbrechen, einschalten)), "rot", 0.12, 12); + + // ---- Kacheln: Tische | Budget/Geld | Plan -------------------------------------------------- + _budget.KeyDown += (_, e) => { if (e.Key == Windows.System.VirtualKey.Enter) BudgetUebernehmen(); }; + _budget.LostFocus += (_, _) => BudgetUebernehmen(); + var budgetFeld = new Grid(); + budgetFeld.Children.Add(_geldWert); + budgetFeld.Children.Add(_budget); + var kacheln = new Grid { ColumnSpacing = 8 }; + for (int i = 0; i < 3; i++) kacheln.ColumnDefinitions.Add(new ColumnDefinition()); + kacheln.Children.Add(Kachel(Ui.Winzig("Tische"), _tischeWert, _tischeFuss)); + kacheln.Children.Add(Kachel(_geldTitel, budgetFeld, _geldFuss).Spalte(1)); + kacheln.Children.Add(Kachel(Ui.Winzig("Plan"), _planWert, _planFuss).Spalte(2)); + + // ---- Tische je Sitzung, Tischform, Micro only ---------------------------------------------- + _sitzungArt.Items.Add("immer 1"); + _sitzungArt.Items.Add("ausgelost"); + _sitzungArt.SelectionChanged += (_, _) => + { + if (_zeichnet || _sitzungArt.SelectedIndex < 0) return; + _z.Eingabe(w => w.TischeBisSetzen(_sitzungArt.SelectedIndex == 1 ? Math.Min(Spielplan.Hoechstens, w.Tische + 2) : null)); + }; + _minus = Stufe("", () => _z.Eingabe(w => { if (w.TischeBis is int b) w.TischeBisSetzen(b - 1); else w.TischeSetzen(w.Tische - 1); })); + _plus = Stufe("", () => _z.Eingabe(w => { if (w.TischeBis is int b) w.TischeBisSetzen(b + 1); else w.TischeSetzen(w.Tische + 1); })); + var stepper = Ui.Reihe(6, _stepperText.Mit(t => t.VerticalAlignment = VerticalAlignment.Center), Stepper(_minus, _plus)); + var zahlZeile = Ui.Reihe(8, Ui.Text("Tische je Sitzung", 12, fett: true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center), _sitzungArt, stepper); + + foreach (var f in new[] { "Multiway", "Heads-Up", "Beide" }) _form.Items.Add(f); + _form.SelectionChanged += (_, _) => + { + if (_zeichnet || _form.SelectedIndex < 0) return; + _z.Eingabe(w => w.Tischform = (Tischform)_form.SelectedIndex); + }; + ToolTipService.SetToolTip(_form, "Multiway = Ring-Tische (Engine-Stärke). Heads-Up = nur 2-Platz-Tische. Beide = egal."); + _micro.Toggled += (_, _) => { if (!_zeichnet) _z.Eingabe(w => w.MicroOnly = _micro.IsOn); }; + ToolTipService.SetToolTip(_micro, "Nur die kleinsten Stakes (Big Blind ≤ 0.10) - schnelles Testen. Kappt das Einsatz-Band nach oben."); + var formZeile = Ui.Zeile( + Ui.Reihe(8, Ui.Text("Tischform", 12, fett: true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center), _form), + Ui.Reihe(6, Ui.Text("Micro only", 12).Mit(t => t.VerticalAlignment = VerticalAlignment.Center), _micro)); + + // ---- Was spielen --------------------------------------------------------------------------- + _ausweichen.Click += (_, _) => _z.Eingabe(w => w.Ausweichen(_ausweichen.IsChecked == true)); + ToolTipService.SetToolTip(_ausweichen, "Ein Tischziel: gibt es von einem Format zu wenig freie Tische, nimmt er das nächste"); + var wasKopf = Ui.Zeile(Ui.Winzig("Was spielen", fett: true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center), + Ui.Reihe(8, _zusammen.Mit(t => t.VerticalAlignment = VerticalAlignment.Center), _ausweichen)); + _zielZeile.Children.Add(_zielText.Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + _zielZeile.Children.Add(Stepper(Stufe("", () => _z.Eingabe(w => w.ZielSetzen((w.Ziel ?? 1) - 1))), + Stufe("", () => _z.Eingabe(w => w.ZielSetzen((w.Ziel ?? 1) + 1))))); + _formate.ColumnDefinitions.Add(new ColumnDefinition()); + _formate.ColumnDefinitions.Add(new ColumnDefinition()); + var wasSpielen = Ui.Spalte(6, wasKopf, _zielZeile, _formate); + + // ---- Status, Konto, Hauptknopf + Not-Aus --------------------------------------------------- + _statusZeile = new Grid { ColumnSpacing = 8 }; + _statusZeile.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + _statusZeile.ColumnDefinitions.Add(new ColumnDefinition()); + _statusPunkt.VerticalAlignment = VerticalAlignment.Top; + _statusPunkt.Margin = new Thickness(0, 5, 0, 0); + _statusZeile.Children.Add(_statusPunkt); + _statusZeile.Children.Add(_statusSatz.Spalte(1)); + + var hauptInhalt = Ui.Reihe(7, _hauptZeichen, _hauptRing, _hauptTitel); + hauptInhalt.HorizontalAlignment = HorizontalAlignment.Center; + hauptInhalt.VerticalAlignment = VerticalAlignment.Center; + _hauptknopf.Child = hauptInhalt; + _hauptTipp = _hauptknopf.Tippen(() => _z.HauptknopfDruecken(), 22); + var notAus = new NotAusKnopf(44, () => _z.NotAusSetzen()); + _knoepfe.ColumnDefinitions.Add(new ColumnDefinition()); + _knoepfe.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + _knoepfe.Children.Add(_hauptTipp); + _knoepfe.Children.Add(notAus.Spalte(1)); + + var loesen = new LoesenKnopf(44, () => _z.NotAusLoesen()); + _notAusBand = new Grid { ColumnSpacing = 10, Padding = new Thickness(10), CornerRadius = new CornerRadius(14) }; + _notAusBand.Background = new LinearGradientBrush + { + StartPoint = new Windows.Foundation.Point(0, 0.5), + EndPoint = new Windows.Foundation.Point(1, 0.5), + GradientStops = + { + new GradientStop { Color = Color.FromArgb(255, 0xD9, 0x1F, 0x24), Offset = 0 }, + new GradientStop { Color = Color.FromArgb(255, 0x8C, 0x0D, 0x14), Offset = 1 }, + }, + }; + _notAusBand.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + _notAusBand.ColumnDefinitions.Add(new ColumnDefinition()); + _notAusBand.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + _notAusBand.Children.Add(Ui.Zeichen(NotAusKnopf.Hand, 18, "").Mit(f => f.VerticalAlignment = VerticalAlignment.Center)); + _notAusBand.Children.Add(Ui.Spalte(1, Ui.Text("Not-Aus aktiv", 14, "", fett: true), + Ui.Text("Es wird nichts geklickt. Zum Lösen den grünen Knopf gedrückt halten.", 11, pinsel: Ui.Weiss(0.85), umbruch: true)) + .Mit(s => s.VerticalAlignment = VerticalAlignment.Center).Spalte(1)); + _notAusBand.Children.Add(loesen.Spalte(2)); + + _portWarnung = Ui.Text("CoinPoker läuft ohne Debug-Port: Tische öffnen und Selbstheilen gehen nicht. Aufhören, dann neu starten.", + 12, "orange", umbruch: true); + + // ---- Rueckmeldungen ------------------------------------------------------------------------ + var wartetRing = new ProgressRing { IsActive = true, Width = 14, Height = 14 }; + _wartet = Ui.Getoent(Ui.Reihe(8, wartetRing, _wartetText), "blau", 0.12, 10); + var weg = Ui.Symbolknopf("", "Ausblenden", () => _z.MeldungWeg(), 10); + var meldungInhalt = new Grid { ColumnSpacing = 8 }; + meldungInhalt.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + meldungInhalt.ColumnDefinitions.Add(new ColumnDefinition()); + meldungInhalt.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + meldungInhalt.Children.Add(_meldungZeichen); + meldungInhalt.Children.Add(_meldungText.Mit(t => t.IsTextSelectionEnabled = true).Spalte(1)); + meldungInhalt.Children.Add(weg.Spalte(2)); + _meldung = Ui.Getoent(meldungInhalt, "gruen", 0.14, 10); + + // ---- Aufbau -------------------------------------------------------------------------------- + _nurLaeufer = new UIElement[] { kacheln, zahlZeile, formZeile, wasSpielen }; + var kopf = Ui.Spalte(10, modusKapsel, _cashFrage, kacheln, zahlZeile, formZeile, wasSpielen, + _phase, _statusZeile, _konto, _knoepfe, _notAusBand, _portWarnung); + kopf.Padding = new Thickness(12, 6, 12, 10); + var rueck = Ui.Spalte(6, _wartet, _meldung); + rueck.Padding = new Thickness(12, 0, 12, 0); + + var scroll = new ScrollViewer + { + Content = _live, + HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled, + Padding = new Thickness(12, 10, 12, 12), + }; + var seite = new Grid(); + seite.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + seite.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + seite.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + seite.RowDefinitions.Add(new RowDefinition()); + seite.Children.Add(kopf); + seite.Children.Add(rueck.Zeile(1)); + seite.Children.Add(new Rectangle { Height = 1, Fill = Ui.Weiss(0.12), Margin = new Thickness(0, 8, 0, 0) }.Zeile(2)); + seite.Children.Add(scroll.Zeile(3)); + Content = seite; + } + + /// Eine Instrument-Kachel (Spielplan.swift `Kachel`): Titel klein, Inhalt 30 hoch, Fuss klein. + private static Border Kachel(TextBlock titel, FrameworkElement inhalt, TextBlock fuss) + { + inhalt.Height = 30; + inhalt.VerticalAlignment = VerticalAlignment.Center; + return Ui.Flaeche(Ui.Spalte(2, titel, inhalt, fuss), 14, 0.06, 10); + } + + private static Tippflaeche Stufe(string glyph, Action tun) + { + var z = Ui.Zeichen(glyph, 9, ""); + z.HorizontalAlignment = HorizontalAlignment.Center; + z.VerticalAlignment = VerticalAlignment.Center; + var b = new Border { Width = 24, Height = 22, Child = z, Background = Ui.Weiss(0) }; + return b.Tippen(tun, 6); + } + + /// Ein Stepper wie am Mac: zwei kleine Knoepfe in einer Kapsel. + private static Border Stepper(Tippflaeche minus, Tippflaeche plus) => new() + { + Background = Ui.Weiss(0.12), + CornerRadius = new CornerRadius(6), + Child = Ui.Reihe(0, minus, new Rectangle { Width = 1, Fill = Ui.Weiss(0.15), Margin = new Thickness(0, 4, 0, 4) }, plus), + VerticalAlignment = VerticalAlignment.Center, + }; + + private void BudgetUebernehmen() + { + if (_zeichnet) return; + var roh = _budget.Text.Replace(".", "").Replace(",", ".").Trim(); + double? neu = double.TryParse(roh, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var v) && v > 0 ? v : null; + if (neu == _z.Wahl.Budget) { _budget.Text = neu is double n ? Format.Zahl(n) : ""; return; } + _z.Eingabe(w => w.Budget = neu); + } + + // ---- Zeichnen ------------------------------------------------------------------------------- + + public void Takt() => _live.Takt(); + + public void Zeichnen() + { + _zeichnet = true; + try { Werte(); } + finally { _zeichnet = false; } + _live.Zeichnen(); + } + + private static Visibility Sichtbar(bool b) => b ? Visibility.Visible : Visibility.Collapsed; + + private void Werte() + { + var a = _z.Ansicht; + var w = _z.Wahl; + var k = a.Kopf; + bool laeuft = a.Laeuft, zuschauen = a.Zuschauen, cash = w.Cash && !zuschauen; + + // Modus + int an = zuschauen ? 0 : cash ? 2 : 1; + for (int i = 0; i < 3; i++) + { + _modusTeil[i].Background = i == an ? Ui.Pinsel(ModusTon[i]) : null; + _modusText[i].Foreground = i == an ? Ui.Pinsel("") : Ui.Zweit; + _modusTipp[i].An = !laeuft && _z.Verbunden; + _modusTipp[i].Opacity = 1; + } + _cashFrage.Visibility = Sichtbar(_z.CashFragen); + + // Der Spielplan gilt nur fuer den Laeufer + foreach (var e in _nurLaeufer) e.Visibility = Sichtbar(!zuschauen); + + // Tische-Kachel: die Summe (die Zahl je Format steht unter "Was spielen") + int tische = w.Tische; + _tischeWert.Text = w.TischeBis is int b ? $"{tische}–{b}" : $"{tische}"; + _tischeWert.FontSize = w.TischeBis == null ? 24 : 20; + var offen = (int?)k.Zahl("tische_offen") ?? 0; + _tischeFuss.Text = laeuft ? $"{offen} von {tische} offen" : "füllt der Läufer auf"; + + // Geld-Kachel: Echtgeld = Budget (eintippbar), sonst Chips mit dem Buy-in + _geldTitel.Text = w.Cash ? "Budget" : "Geld"; + _budget.Visibility = Sichtbar(w.Cash); + _geldWert.Visibility = Sichtbar(!w.Cash); + _geldFuss.Text = w.Cash ? $"{w.ReserveBuyins} Buy-ins/Tisch" : $"Buy-in {(w.KaufMax ? "Max" : "Min")}"; + if (w.Cash && _budget.FocusState == FocusState.Unfocused) + _budget.Text = w.Budget is double bu ? Format.Zahl(bu) : ""; + + var (pt, pf) = w.PlanText(); + _planWert.Text = pt; + _planFuss.Text = pf; + + // Tische je Sitzung + _sitzungArt.Items[0] = $"immer {tische}"; + _sitzungArt.SelectedIndex = w.TischeBis != null ? 1 : 0; + _stepperText.Text = w.TischeBis is int bis ? $"{tische} bis {bis}" : $"{tische} {(tische == 1 ? "Tisch" : "Tische")}"; + _minus.An = w.TischeBis is int b2 ? b2 > tische + 1 : tische > 1; + _plus.An = (w.TischeBis ?? tische) < Spielplan.Hoechstens; + _form.SelectedIndex = (int)w.Tischform; + _micro.IsOn = w.MicroOnly; + + // Was spielen + _zusammen.Text = tische == 0 ? "nichts gewählt" : $"{tische} Tisch{(tische == 1 ? "" : "e")} zusammen"; + _ausweichen.IsChecked = w.Ziel != null; + _zielZeile.Visibility = Sichtbar(w.Ziel != null); + if (w.Ziel is int zz) _zielText.Text = $"Ziel: {zz} Tisch{(zz == 1 ? "" : "e")} · Zahlen unten sind Obergrenzen"; + FormatKarten(w); + + // Phase des Zeitplans + if (laeuft && k.Obj("phase") is { } ph) + { + var art = ph.Text("art"); + string glyph = art switch { "pause" => "", "ausserhalb" => "", "fertig" => "", "spielen" => "", _ => "" }; + string? ton = art == "spielen" ? null : "orange"; + _phase.Child = Ui.Reihe(8, Ui.Zeichen(glyph, 12, ton), Ui.Text(ph.T("text"), 12, ton, fett: true, umbruch: true)) + .Mit(r => r.Margin = new Thickness(10, 6, 10, 6)); + _phase.Visibility = Visibility.Visible; + } + else _phase.Visibility = Visibility.Collapsed; + + // Status: was gerade passiert (ohne Verbindung steht dort, was los ist) + string satz, ton2; + if (!_z.Verbunden) { satz = _z.JemalsVerbunden ? $"Server weg - {_z.Getrennt}" : _z.Getrennt; ton2 = "grau"; } + else + { + satz = k.Obj("status").Text("satz") ?? k.Text("text") ?? "liest …"; + ton2 = k.Obj("status").Text("farbe") ?? "grau"; + } + _statusPunkt.Fill = Ui.Pinsel(ton2); + _statusSatz.Text = satz; + bool notAus = _z.NotAus; + _statusZeile.Visibility = Sichtbar(!(notAus && _z.Verbunden)); + + // Konto-Alarme: Verdacht, Sperre, laufende Ruhezeit + var alarme = k.Obj("konto").Texte("felder") + .Where(f => f.StartsWith("Verdacht: ja") || f.StartsWith("Gesperrt: ja") || f.Contains("(JETZT)")).ToList(); + var abdruck = string.Join("|", alarme); + if ((string?)_konto.Tag != abdruck) + { + _konto.Tag = abdruck; + _konto.Children.Clear(); + foreach (var f in alarme) + { + var t = f.Contains("(JETZT)") ? "orange" : "rot"; + _konto.Children.Add(Ui.Getoent(Ui.Text(f, 11, t, umbruch: true), t, 0.12, 9, 4) + .Mit(x => x.HorizontalAlignment = HorizontalAlignment.Left)); + } + } + _konto.Visibility = Sichtbar(alarme.Count > 0); + + // Hauptknopf oder Not-Aus-Band + _knoepfe.Visibility = Sichtbar(!notAus); + _notAusBand.Visibility = Sichtbar(notAus); + var knopf = _z.Knopf; + bool beschaeftigt = _z.Laufend.Count > 0; + _hauptTitel.Text = knopf.Titel(); + _hauptZeichen.Glyph = knopf.Zeichen(); + _hauptZeichen.Visibility = Sichtbar(!beschaeftigt); + _hauptRing.IsActive = beschaeftigt; + _hauptRing.Visibility = Sichtbar(beschaeftigt); + var farbe = Ui.Farbe(knopf.Ton()); + _hauptknopf.Background = knopf.Ton() == "grau" ? Ui.Weiss(0.14) : new LinearGradientBrush + { + StartPoint = new Windows.Foundation.Point(0, 0), + EndPoint = new Windows.Foundation.Point(0, 1), + GradientStops = + { + new GradientStop { Color = farbe, Offset = 0 }, + new GradientStop { Color = Color.FromArgb(255, (byte)(farbe.R * 0.8), (byte)(farbe.G * 0.8), (byte)(farbe.B * 0.8)), Offset = 1 }, + }, + }; + _hauptTipp.An = knopf.Wirksam() && !beschaeftigt; + ToolTipService.SetToolTip(_hauptTipp, knopf.Hilfe()); + + _portWarnung.Visibility = Sichtbar(laeuft && k.WahrOderNull("client_port") == false); + + // Rueckmeldungen + _wartet.Visibility = Sichtbar(beschaeftigt); + _wartetText.Text = "läuft: " + string.Join(", ", _z.Laufend.Select(x => x.Replace('_', ' '))); + if (_z.Meldung is { } m) + { + _meldung.Visibility = Visibility.Visible; + _meldung.Background = Ui.Pinsel(m.Ok ? "gruen" : "orange", 0.14); + _meldungZeichen.Glyph = m.Ok ? "" : ""; + _meldungZeichen.Foreground = Ui.Pinsel(m.Ok ? "gruen" : "orange"); + _meldungText.Text = m.Text; + } + else _meldung.Visibility = Visibility.Collapsed; + } + + /// "Was spielen" (FormatWahl.swift): je Format eine Karte im Zweierraster. In Uebung nur + /// Gemessenes (oder schon Gewaehltes); Freeroll und VIP stecken im Turnier-Typ. Mit Ausweichen in + /// Fuellfolge, mit Pfeil nach vorn. + private void FormatKarten(Spielplan w) + { + var folge = w.Folge(); + var reihe = (w.Ziel == null ? Formate.Alle.ToList() : folge.Concat(Formate.Alle.Where(f => !folge.Contains(f))).ToList()) + .Where(f => f is not (SpielFormat.Freeroll or SpielFormat.Vip)).ToList(); + if (!w.Cash) reihe.RemoveAll(f => !w.Gemessen.Contains(f) && w.Anzahl(f) == 0); + var abdruck = string.Join(",", reihe.Select(f => $"{f}:{w.Anzahl(f)}:{folge.IndexOf(f)}:{w.Gemessen.Contains(f)}:{w.Spielbar.Contains(f)}")) + $"|{w.Tische}|{w.Ziel}"; + if ((string?)_formate.Tag == abdruck) return; + _formate.Tag = abdruck; + _formate.Children.Clear(); + _formate.RowDefinitions.Clear(); + for (int i = 0; i < reihe.Count; i++) + { + if (i % 2 == 0) _formate.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + var karte = FormatKarte(w, reihe[i], w.Ziel == null ? -1 : folge.IndexOf(reihe[i])); + Grid.SetRow(karte, i / 2); + Grid.SetColumn(karte, i % 2); + _formate.Children.Add(karte); + } + } + + private Border FormatKarte(Spielplan w, SpielFormat f, int rang) + { + int anzahl = w.Anzahl(f); + bool an = anzahl > 0; + bool voll = w.Ziel == null ? w.Tische >= Spielplan.Hoechstens : anzahl >= Spielplan.Hoechstens; + string? hinweis = !w.Gemessen.Contains(f) ? "ungemessen" + : !w.Spielbar.Contains(f) ? "Menü nicht gemessen" + : f == SpielFormat.Bombpot ? "PLO5 · Engine schwächer" : null; + + var g = new Grid { ColumnSpacing = 4, Height = 38, Padding = new Thickness(8, 0, 2, 0) }; + g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(20) }); + g.ColumnDefinitions.Add(new ColumnDefinition()); + g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + g.Children.Add(Ui.Zeichen(f.Zeichen(), 13, an ? "blau" : "grau").Mit(z => z.VerticalAlignment = VerticalAlignment.Center)); + var namen = Ui.Spalte(0, Ui.Text(f.Name(), 12, fett: true)); + if (hinweis != null) namen.Children.Add(Ui.Text(hinweis, 9.5, "orange")); + namen.VerticalAlignment = VerticalAlignment.Center; + g.Children.Add(namen.Spalte(1)); + var rechts = Ui.Reihe(0); + rechts.VerticalAlignment = VerticalAlignment.Center; + if (rang > 0) rechts.Children.Add(Ui.Symbolknopf("", $"In der Füllfolge nach vorn (jetzt Platz {rang + 1})", () => _z.Eingabe(p => p.Vorziehen(f)), 10, "")); + if (an) + { + rechts.Children.Add(Ui.Symbolknopf("", "eins weniger", () => _z.Eingabe(p => p.Setzen(f, anzahl - 1)), 10, "")); + rechts.Children.Add(Ui.Gross($"{anzahl}", 14).Mit(t => { t.MinWidth = 12; t.TextAlignment = TextAlignment.Center; t.VerticalAlignment = VerticalAlignment.Center; })); + } + var plus = Ui.Symbolknopf("", "eins mehr", () => _z.Eingabe(p => p.Setzen(f, anzahl + 1)), 10, ""); + plus.IsEnabled = !voll; + rechts.Children.Add(plus); + g.Children.Add(rechts.Spalte(2)); + + var karte = new Border + { + Background = an ? Ui.Pinsel("blau", 0.14) : Ui.Weiss(0.05), + BorderBrush = an ? Ui.Pinsel("blau", 0.5) : null, + BorderThickness = new Thickness(an ? 1 : 0), + CornerRadius = new CornerRadius(10), + Child = g, + }; + ToolTipService.SetToolTip(karte, !w.Gemessen.Contains(f) + ? $"{f.Name()}: der Weg in der Lobby ist noch nicht gemessen - der Läufer öffnet hier nichts" + : !w.Spielbar.Contains(f) + ? $"{f.Name()}: gelistet, aber das Einsatz-Menü ist noch nicht gemessen - der Läufer kann dort nicht klicken" + : $"{f.Name()}: {anzahl} Tisch{(anzahl == 1 ? "" : "e")}"); + return karte; + } +} + +/// Not-Aus (Wurzel.swift `NotAusKnopf`): runder roter Knopf, ein Klick haelt sofort an. +public sealed class NotAusKnopf : Grid +{ + public const string Hand = ""; + + public NotAusKnopf(double d, Action tun) + { + Width = d; + Height = d; + var kreis = new Ellipse + { + Fill = new LinearGradientBrush + { + StartPoint = new Windows.Foundation.Point(0, 0), + EndPoint = new Windows.Foundation.Point(0, 1), + GradientStops = + { + new GradientStop { Color = Color.FromArgb(255, 255, 82, 77), Offset = 0 }, + new GradientStop { Color = Color.FromArgb(255, 191, 20, 26), Offset = 1 }, + }, + }, + Stroke = Ui.Weiss(0.35), + StrokeThickness = 1, + }; + var schein = new Ellipse { Fill = Ui.Pinsel("rot", 0.30), Margin = new Thickness(-4) }; + Children.Add(schein); + Children.Add(kreis); + Children.Add(Ui.Zeichen(Hand, d * 0.38, "").Mit(z => { z.HorizontalAlignment = HorizontalAlignment.Center; z.VerticalAlignment = VerticalAlignment.Center; })); + Background = Ui.Weiss(0); + CenterPoint = new System.Numerics.Vector3((float)d / 2, (float)d / 2, 0); + PointerPressed += (_, _) => { Scale = new System.Numerics.Vector3(0.92f); schein.Margin = new Thickness(-1); }; + PointerReleased += (_, _) => { Scale = new System.Numerics.Vector3(1); schein.Margin = new Thickness(-4); }; + PointerExited += (_, _) => { Scale = new System.Numerics.Vector3(1); schein.Margin = new Thickness(-4); }; + Tapped += (_, _) => tun(); + ToolTipService.SetToolTip(this, "Not-Aus - sofort anhalten"); + Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(this, "Not-Aus"); + } +} + +/// Gedrueckt halten (1 s) loest den Not-Aus - der Ring fuellt sich dabei (Wurzel.swift `LoesenKnopf`). +/// So wird der Laeufer nie aus Versehen wieder scharf. +public sealed class LoesenKnopf : Grid +{ + private static readonly TimeSpan Dauer = TimeSpan.FromSeconds(1); + private readonly ProgressRing _ring = new() { IsIndeterminate = false, Minimum = 0, Maximum = 1, Value = 0, Foreground = Ui.Pinsel("gruen") }; + private readonly Microsoft.UI.Dispatching.DispatcherQueueTimer _uhr; + private DateTime? _seit; + + public LoesenKnopf(double d, Action tun) + { + Width = d; + Height = d; + Children.Add(new Ellipse { Fill = Ui.Weiss(0.10) }); + _ring.Width = d; + _ring.Height = d; + Children.Add(_ring); + Children.Add(Ui.Zeichen("", d * 0.34, "gruen").Mit(z => { z.HorizontalAlignment = HorizontalAlignment.Center; z.VerticalAlignment = VerticalAlignment.Center; })); + Background = Ui.Weiss(0); + _uhr = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread().CreateTimer(); + _uhr.Interval = TimeSpan.FromMilliseconds(30); + _uhr.Tick += (_, _) => + { + if (_seit is not DateTime s) return; + var anteil = (DateTime.Now - s) / Dauer; + _ring.Value = Math.Min(1, anteil); + if (anteil >= 1) { Ende(); tun(); } + }; + PointerPressed += (_, e) => { _seit = DateTime.Now; CapturePointer(e.Pointer); _uhr.Start(); }; + PointerReleased += (_, _) => Ende(); + PointerCaptureLost += (_, _) => Ende(); + ToolTipService.SetToolTip(this, "Gedrückt halten, um den Not-Aus zu lösen"); + Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(this, "Not-Aus lösen, gedrückt halten"); + } + + private void Ende() + { + _seit = null; + _uhr.Stop(); + _ring.Value = 0; + } +} + +public static class HauptknopfHilfe +{ + public static string Hilfe(this HauptArt a) => a switch + { + HauptArt.Unbekannt => "wartet auf den Server", + HauptArt.NotAusLoesen => "Not-Aus lösen - der Läufer darf wieder klicken", + HauptArt.HoertAuf => "Er spielt die laufenden Hände zu Ende und schließt dann die Tische - sofort: Not-Aus", + HauptArt.Aufhoeren => "Bei nächster Gelegenheit: ab der nächsten Hand aussetzen, laufende Hände zu Ende spielen, dann Tische zu - sofort: Not-Aus", + HauptArt.ZuschauenBeenden => "Zuschauer stoppen - danach wählst du Übung oder Echtgeld", + HauptArt.EchtgeldStarten => "Spielplan auf Echtgeld setzen und den Läufer starten - er öffnet selbst Tische bis zur Tischzahl", + HauptArt.UebungStarten => "Spielplan Übung setzen und den Läufer starten - er öffnet selbst Übungstische bis zur Tischzahl", + HauptArt.BudgetFehlt => "Echtgeld braucht ein Guthaben: Budget eintragen, sonst wählte die Lobby blind", + HauptArt.FreigabeFehlt => "Das Cockpit kann die Tischfenster nicht lesen - ein Läufer von hier wäre blind", + HauptArt.ClientStarten => "CoinPoker mit Debug-Port starten - danach anmelden", + HauptArt.ClientNeuStarten => "CoinPoker läuft ohne Debug-Port - beenden und mit Port neu starten, danach anmelden", + HauptArt.PortFehlt => "CoinPoker läuft ohne Debug-Port, aber Tische sind offen - erst die Tische schließen, dann neu starten", + _ => "", + }; +} diff --git a/winui/Seiten/EinstellungenSeite.cs b/winui/Seiten/EinstellungenSeite.cs new file mode 100644 index 00000000..3b2d29bd --- /dev/null +++ b/winui/Seiten/EinstellungenSeite.cs @@ -0,0 +1,279 @@ +using System.Text.Json.Nodes; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Pokerfreak.Cockpit.Kern; + +namespace Pokerfreak.Cockpit.Seiten; + +/// +/// Die Einstellungen (Einstellungen.swift): oben die Bereiche als Kapseln, darunter der gewaehlte. +/// Allgemein (Maus fuer den Stream, Lehrer live), Humanisierung (humanisierung_lesen/_setzen) und +/// Sicherheit (Konto-Ampel) sind da; Stimme, Streamer und der Plan-Editor (Zeiten/Geld) folgen. +/// +public sealed class EinstellungenSeite : UserControl, ISeite +{ + private static readonly (string Titel, string Glyph)[] Bereiche = + { + ("Allgemein", ""), ("Humanisierung", ""), ("Sicherheit", ""), + ("Lehrer & Stimme", ""), ("Zeiten & Geld", ""), ("Streamer", ""), + }; + + private readonly CockpitZustand _z; + private readonly Tippflaeche[] _knoepfe = new Tippflaeche[Bereiche.Length]; + private readonly Border[] _kapseln = new Border[Bereiche.Length]; + private readonly ContentControl _inhalt = new() { HorizontalContentAlignment = HorizontalAlignment.Stretch }; + private readonly TextBlock _ueberschrift = Ui.Gross("", 20); + private readonly FontIcon _symbol = Ui.Zeichen("", 18); + private int _bereich; + private string _abdruck = ""; + + // Humanisierung: die Werte des Servers, bis "Sichern" + private JsonObject? _human; + private string[] _stufen = { "knapp", "normal", "ausfuehrlich" }; + private bool _humanLaedt; + + public EinstellungenSeite(CockpitZustand z) + { + _z = z; + _bereich = int.TryParse(Merker.Lesen("einstellungen.bereich"), out var b) && b >= 0 && b < Bereiche.Length ? b : 0; + var leiste = new Grid { ColumnSpacing = 6, RowSpacing = 6 }; + for (var i = 0; i < 3; i++) leiste.ColumnDefinitions.Add(new ColumnDefinition()); + leiste.RowDefinitions.Add(new RowDefinition()); + leiste.RowDefinitions.Add(new RowDefinition()); + for (var i = 0; i < Bereiche.Length; i++) + { + var n = i; + _kapseln[i] = new Border + { + CornerRadius = new CornerRadius(14), + Padding = new Thickness(6, 6, 6, 7), + Child = Ui.Reihe(6, Ui.Zeichen(Bereiche[i].Glyph, 12), Ui.Text(Bereiche[i].Titel, 12, fett: true)).Mit(r => r.HorizontalAlignment = HorizontalAlignment.Center), + }; + _knoepfe[i] = _kapseln[i].Tippen(() => + { + _bereich = n; + Merker.Schreiben("einstellungen.bereich", n.ToString()); + _abdruck = ""; + Zeichnen(); + }, 14); + Grid.SetColumn(_knoepfe[i], i % 3); + Grid.SetRow(_knoepfe[i], i / 3); + leiste.Children.Add(_knoepfe[i]); + } + var s = Ui.Spalte(14, leiste, Ui.Reihe(8, _symbol, _ueberschrift), _inhalt); + s.Padding = new Thickness(14); + Content = new ScrollViewer { Content = s, HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled }; + } + + public void Zeichnen() + { + for (var i = 0; i < Bereiche.Length; i++) + { + var an = i == _bereich; + _kapseln[i].Background = an ? Ui.Pinsel("blau", 0.22) : Ui.Weiss(0.05); + foreach (var kind in ((StackPanel)_kapseln[i].Child).Children) + { + if (kind is TextBlock t) t.Foreground = an ? Ui.Pinsel(null) : Ui.Zweit; + if (kind is FontIcon f) f.Foreground = an ? Ui.Pinsel(null) : Ui.Zweit; + } + } + _ueberschrift.Text = Bereiche[_bereich].Titel; + _symbol.Glyph = Bereiche[_bereich].Glyph; + + var k = _z.Ansicht.Kopf; + var abdruck = _bereich + "|" + _z.Verbunden + "|" + k.Wahr("maus") + "|" + _z.Wahl.Lehrer + "|" + + k.Obj("konto").Abdruck() + "|" + (_human != null); + if (abdruck == _abdruck) return; + _abdruck = abdruck; + _inhalt.Content = _bereich switch + { + 0 => Allgemein(), + 1 => Humanisierung(), + 2 => Sicherheit(), + 3 => Folgt("Der Lehrer erklärt jeden Zug mit Stimme – ohne Twitch. Die Stimme (Anbieter, Schlüssel) " + + "richtest du vorerst in der Mac-App ein; der Schalter „Lehrer live“ steht unter Allgemein."), + 4 => Folgt("Der Plan-Editor für Zeiten (Sitzungslänge, Pausen, Ruhezeiten) und Geld (Budget, Stop-Loss, " + + "Nachkauf) kommt als Nächstes. Bis dahin gilt der Plan, den der Server hält."), + _ => Folgt("Twitch, Chat und OBS sind nur für den Stream. Der Läufer und der Lehrer laufen auch ohne."), + }; + } + + // ---- Bereiche -------------------------------------------------------------------------------- + + private UIElement Allgemein() + { + var maus = new ToggleSwitch { IsOn = _z.Ansicht.Kopf.Wahr("maus"), IsEnabled = _z.Verbunden, OnContent = "", OffContent = "", MinWidth = 0 }; + maus.Toggled += (_, _) => + { + if (maus.IsOn == _z.Ansicht.Kopf.Wahr("maus")) return; + _ = _z.Senden(("maus_setzen", new JsonObject { ["an"] = maus.IsOn })); + }; + var lehrer = new ToggleSwitch { IsOn = _z.Wahl.Lehrer, OnContent = "", OffContent = "", MinWidth = 0 }; + lehrer.Toggled += (_, _) => { if (lehrer.IsOn != _z.Wahl.Lehrer) _z.Eingabe(w => w.Lehrer = lehrer.IsOn); }; + return Ui.Spalte(10, + Schalter("Streamer-Modus: Maus sichtbar steuern", "Nur für den Stream – sonst spielt er über den Kanal, ohne Maus.", maus), + Schalter("Lehrer live mitlaufen lassen", "Erklärt die Züge am Fokustisch laut, während er spielt. Geht mit dem nächsten Plan an den Läufer.", lehrer), + Ui.Flaeche(Ui.Spalte(2, Ui.Winzig("Server"), Ui.Text($"{_z.Verbindung.Adresse.Host}:{_z.Verbindung.Adresse.Port}", 13, zahlen: true)), 12, 0.05, 12)); + } + + private static Border Schalter(string titel, string hinweis, ToggleSwitch schalter) + { + var g = new Grid { ColumnSpacing = 10 }; + g.ColumnDefinitions.Add(new ColumnDefinition()); + g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + g.Children.Add(Ui.Spalte(1, Ui.Text(titel, 14), Ui.Klein(hinweis, true))); + g.Children.Add(schalter.Spalte(1).Mit(s => s.VerticalAlignment = VerticalAlignment.Center)); + return Ui.Flaeche(g, 12, 0.05, 12); + } + + private UIElement Sicherheit() + { + var konto = _z.Ansicht.Kopf.Obj("konto"); + if (konto == null) return Ui.Klein("Noch keine Kontodaten – sobald der Läufer verbunden ist.", true); + var schwarz = konto.Wahr("schwarz_jetzt"); + var ampeln = Ui.Reihe(6, + Ampel("Verdacht", "", konto.WahrOderNull("verdacht") == true, "rot"), + Ampel("Sperre", "", konto.WahrOderNull("gesperrt") == true, "rot"), + Ampel("Ruhezeit", "", schwarz, "orange")); + var s = Ui.Spalte(8, ampeln); + if (schwarz) s.Children.Add(Ui.Text("Ruhezeit läuft – der Läufer öffnet jetzt keinen neuen Tisch", 11, "orange", umbruch: true)); + foreach (var f in konto.Texte("felder")) + s.Children.Add(Ui.Reihe(6, Ui.Punkt("grau", 6).Mit(p => p.Margin = new Thickness(0, 5, 0, 0)), Ui.Winzig(f).Mit(t => t.TextWrapping = TextWrapping.Wrap))); + return Ui.Flaeche(s, 12, 0.05, 12); + } + + /// Eine Ampel-Pille: gruen = sauber, sonst die Warnfarbe; das Symbol traegt die Bedeutung. + private static Border Ampel(string titel, string glyph, bool an, string anTon) + { + var b = Ui.Abzeichen(titel, an ? anTon : "gruen", an ? glyph : ""); + ToolTipService.SetToolTip(b, an ? $"{titel}: Achtung" : $"{titel}: sauber"); + return b; + } + + private static UIElement Folgt(string text) => Ui.Flaeche(Ui.Spalte(8, + Ui.Abzeichen("folgt", "orange", ""), Ui.Text(text, 13, pinsel: Ui.Zweit, umbruch: true)), 12, 0.05, 12); + + // ---- Humanisierung --------------------------------------------------------------------------- + + private static readonly string[] SitzungFolge = { "auto_post_bb", "straddle", "rabbit_run" }; + private static readonly string[] AnlassFolge = { "karten_zeigen", "karten_zeigen_satt", "nachkauf", "zeitbank", "rabbit_run", "buyout", "tisch_warten" }; + + private static string Beschriftung(string k, bool sitzung) => k == "rabbit_run" + ? (sitzung ? "Rabbit Run (Sitzung)" : "Rabbit Run") + : k switch + { + "auto_post_bb" => "Blind von selbst (Sitzung)", + "straddle" => "Straddle (Sitzung)", + "karten_zeigen" => "Karten zeigen nach Bluff", + "karten_zeigen_satt" => "… wenn schon viel gezeigt", + "nachkauf" => "Nachkauf bei kurzem Stapel", + "zeitbank" => "Zeitbank bei knapper Zeit", + "buyout" => "Rückkauf am Handende", + "tisch_warten" => "Auf den guten Platz warten", + _ => k, + }; + + private async void HumanLaden() + { + if (_humanLaedt) return; + _humanLaedt = true; + var r = await _z.Verbindung.Senden("humanisierung_lesen"); + _humanLaedt = false; + if (r.Roh.Obj("humanisierung") is JsonObject h && h.Obj("werte") is JsonObject w) + { + _human = (JsonObject)w.DeepClone(); + if (h.Texte("stufen").ToArray() is { Length: > 0 } st) _stufen = st; + } + else _z.Rueckmelden(r); + _abdruck = ""; + Zeichnen(); + } + + private UIElement Humanisierung() + { + if (_human == null) + { + if (_z.Verbunden) HumanLaden(); + return Ui.Klein(_z.Verbunden ? "lädt …" : "Ohne Server keine Werte."); + } + var w = _human; + var s = Ui.Spalte(12, Ui.Text("Diese Werte lassen den Bot menschlich wirken. Die Vorgaben entsprechen genau dem heutigen " + + "Verhalten – ändere sie nur bewusst.", 13, pinsel: Ui.Zweit, umbruch: true)); + s.Children.Add(Abschnitt("Denkzeit", "Wie lange ein Zug auf sich warten lässt (Millisekunden).", + Ms("Untergrenze", w, "denk_min_ms"), Ms("Median", w, "denk_median_ms"), Ms("Obergrenze", w, "denk_max_ms"), + Regler("Streuung", w, "timing_streuung", 2, false))); + s.Children.Add(Abschnitt("Timing-Gewohnheiten", "Gelegentliche menschliche Züge – nie bei jedem Zug.", + Regler("Lange Pause (Tank)", w, "tank_rate"), Regler("Zeitbank bei schwerer Lage", w, "zeitbank_rate"), + Regler("Zeit von der Handstärke lösen", w, "entkoppel_rate"))); + s.Children.Add(Abschnitt("Sizing-Jitter", "Raise-Größen leicht krumm machen statt glatt.", + Regler("Weite", w, "sizing_jitter_weite"), Regler("Wie oft", w, "sizing_jitter_rate"))); + var raten = new List(); + if (w.Obj("sitzung_raten") is JsonObject sr) raten.AddRange(SitzungFolge.Select(k => Regler(Beschriftung(k, true), sr, k))); + if (w.Obj("anlass_raten") is JsonObject ar) raten.AddRange(AnlassFolge.Select(k => Regler(Beschriftung(k, false), ar, k))); + s.Children.Add(Abschnitt("Gewohnheits-Raten", "Wie oft eine Gewohnheit bei gegebenem Anlass wirklich fällt.", raten.ToArray())); + + var stufe = new Segmente(_stufen.Select(x => char.ToUpper(x[0]) + x[1..]).ToArray(), + vorgabe: Math.Max(0, Array.IndexOf(_stufen, w.T("lehrer_ausfuehrlichkeit")))); + stufe.Gewaehlt += i => w["lehrer_ausfuehrlichkeit"] = _stufen[i]; + var fokus = new ToggleSwitch { IsOn = w.Wahr("lehrer_fokusansage"), OnContent = "", OffContent = "", MinWidth = 0 }; + fokus.Toggled += (_, _) => w["lehrer_fokusansage"] = fokus.IsOn; + s.Children.Add(Abschnitt("Lehrer", "Wie der Lehrer spricht.", + Ui.Spalte(4, Ui.Text("Ausführlichkeit", 13), stufe), + Ui.Zeile(Ui.Text("Fokuswechsel ansagen („Ich schaue jetzt auf …“)", 13, umbruch: true), fokus))); + + var knoepfe = new Grid(); + knoepfe.ColumnDefinitions.Add(new ColumnDefinition()); + knoepfe.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + knoepfe.Children.Add(Teile.Knopf("Neu laden", () => { _human = null; _abdruck = ""; Zeichnen(); })); + knoepfe.Children.Add(Teile.Knopf("Sichern", () => _ = _z.Senden(("humanisierung_setzen", new JsonObject { ["werte"] = w.DeepClone() })), "blau", true).Spalte(1)); + s.Children.Add(knoepfe); + return s; + } + + private static Border Abschnitt(string titel, string hinweis, params UIElement[] zeilen) + { + var s = Ui.Spalte(8, Ui.Text(titel, 15, fett: true), Ui.Winzig(hinweis).Mit(t => t.TextWrapping = TextWrapping.Wrap)); + foreach (var z in zeilen) s.Children.Add(z); + return Ui.Flaeche(s, 12, 0.05, 12); + } + + private static Grid Ms(string titel, JsonObject w, string k) + { + var box = new NumberBox + { + Value = w.Zahl(k) ?? 0, + Minimum = 0, + Maximum = 60000, + SmallChange = 50, + Width = 110, + SpinButtonPlacementMode = NumberBoxSpinButtonPlacementMode.Hidden, + }; + box.ValueChanged += (_, e) => { if (!double.IsNaN(e.NewValue)) w[k] = e.NewValue; }; + var g = new Grid { ColumnSpacing = 8 }; + g.ColumnDefinitions.Add(new ColumnDefinition()); + g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(24) }); + g.Children.Add(Ui.Text(titel, 13).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + g.Children.Add(box.Spalte(1)); + g.Children.Add(Ui.Klein("ms").Spalte(2).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + return g; + } + + /// Ein Regler 0..max in Schritten zu 0,05; Raten als Prozent, Faktoren mit zwei Stellen. + private static Grid Regler(string titel, JsonObject w, string k, double max = 1, bool prozent = true) + { + var wert = Ui.Text("", 12, zahlen: true).Mit(t => { t.TextAlignment = TextAlignment.Right; t.VerticalAlignment = VerticalAlignment.Center; }); + void Text(double v) => wert.Text = prozent ? $"{Math.Round(v * 100):0} %" : Format.Zahl(v, 2); + var r = new Slider { Minimum = 0, Maximum = max, StepFrequency = 0.05, Value = w.Zahl(k) ?? 0 }; + r.ValueChanged += (_, e) => { w[k] = Math.Round(e.NewValue, 2); Text(e.NewValue); }; + Text(r.Value); + var g = new Grid { ColumnSpacing = 8 }; + g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); + g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1.1, GridUnitType.Star) }); + g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(44) }); + g.Children.Add(Ui.Text(titel, 13, umbruch: true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + g.Children.Add(r.Spalte(1)); + g.Children.Add(wert.Spalte(2)); + return g; + } +} diff --git a/winui/Seiten/HaendeSeite.cs b/winui/Seiten/HaendeSeite.cs new file mode 100644 index 00000000..0581006d --- /dev/null +++ b/winui/Seiten/HaendeSeite.cs @@ -0,0 +1,258 @@ +using System.Text.Json.Nodes; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using Pokerfreak.Cockpit.Kern; + +namespace Pokerfreak.Cockpit.Seiten; + +/// +/// Der Reiter Haende: die Entscheidungen des Kerns, neueste oben (EntscheidungenGeld.swift +/// `EntscheidungenAnsicht`). Suche und Filter wie `filtern()` in sicht/ansicht.py; ein Tipp klappt eine +/// Zeile auf (Tisch, Hand, Stake, Equity, Confidence, Gedenkzeit, Ergebnis, Klick, Beleg, Grund). +/// +public sealed class HaendeSeite : UserControl, ISeite +{ + private const int Seite = 150; + + private readonly CockpitZustand _z; + private readonly TextBox _suche = new() + { + PlaceholderText = "Suchen: Grund, Karten, Hand, Tisch", + FontSize = 13, + CornerRadius = new CornerRadius(8), + }; + private readonly Auswahl _aktion = new("Aktion"), _stake = new("Stake"), _spiel = new("Spiel"), _ergebnis = new("Ergebnis"); + private readonly Tippflaeche _zurueck; + private readonly TextBlock _zaehler = Ui.Winzig(""); + private readonly StackPanel _liste = Ui.Spalte(0); + private readonly ContentControl _leer = new() { HorizontalContentAlignment = HorizontalAlignment.Stretch }; + private readonly ScrollViewer _rollen; + private readonly Dictionary _zeilen = new(); + private string? _offen; + private int _zeigen = Seite; + private string _abdruck = ""; + + public HaendeSeite(CockpitZustand z) + { + _z = z; + _ergebnis.Werte(new[] { "gewonnen", "verloren", "null", "offen" }); + foreach (var a in new[] { _aktion, _stake, _spiel, _ergebnis }) a.Geaendert += () => Neu(true); + _suche.TextChanged += (_, _) => Neu(true); + _zurueck = Teile.Knopf("Zurücksetzen", () => + { + _suche.Text = ""; + foreach (var a in new[] { _aktion, _stake, _spiel, _ergebnis }) a.Setzen(null); + Neu(true); + }); + + var filter = Ui.Reihe(6, _aktion, _stake, _spiel, _ergebnis, _zurueck); + var kopf = Ui.Spalte(8, _suche, filter, _zaehler); + kopf.Padding = new Thickness(12, 12, 12, 10); + + _rollen = new ScrollViewer + { + Content = new StackPanel { Children = { _leer, _liste }, Padding = new Thickness(12, 4, 12, 12) }, + HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled, + }; + var g = new Grid(); + g.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + g.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + g.RowDefinitions.Add(new RowDefinition()); + g.Children.Add(kopf); + g.Children.Add(new Border { Height = 1, Background = Ui.Weiss(0.08) }.Zeile(1)); + g.Children.Add(_rollen.Zeile(2)); + Content = g; + } + + public void Zeichnen() + { + var e = _z.Ansicht.Entscheidungen; + var abdruck = e.Abdruck(); + if (abdruck == _abdruck) return; + _abdruck = abdruck; + var f = e.Obj("facetten"); + _aktion.Werte(f.Texte("aktion")); + _stake.Werte(f.Texte("stake")); + _spiel.Werte(f.Texte("spielart")); + Neu(false); + } + + private bool FilterLeer => string.IsNullOrWhiteSpace(_suche.Text) && _aktion.Wahl == null && _stake.Wahl == null + && _spiel.Wahl == null && _ergebnis.Wahl == null; + + /// Die Filterregel von `filtern()` (sicht/ansicht.py). + private bool Passt(JsonObject z) + { + if (_aktion.Wahl is string a && z.Text("aktion") != a) return false; + if (_stake.Wahl is string s && z.Text("stake") != s) return false; + if (_spiel.Wahl is string sp && z.Text("spielart") != sp) return false; + var x = z.Zahl("ergebnis_bb"); + var ok = _ergebnis.Wahl switch + { + "gewonnen" => x > 0, + "verloren" => x < 0, + "null" => x == 0, + "offen" => x == null, + _ => true, + }; + if (!ok) return false; + var such = _suche.Text.Trim().ToLowerInvariant(); + if (such.Length == 0) return true; + foreach (var k in new[] { "grund", "klartext", "karten", "hand", "raum" }) + { + var t = z[k] is JsonArray l ? string.Join(" ", l.Select(Json.TextVon)) : z.T(k); + if (t.ToLowerInvariant().Contains(such)) return true; + } + return false; + } + + private void Neu(bool filterNeu) + { + if (filterNeu) _zeigen = Seite; + _zurueck.Visibility = FilterLeer ? Visibility.Collapsed : Visibility.Visible; + var e = _z.Ansicht.Entscheidungen; + var alle = e.Objekte("zeilen").ToList(); + var treffer = alle.Where(Passt).ToList(); + var zaehler = treffer.Count == alle.Count ? $"{alle.Count} Entscheidungen" : $"{treffer.Count} von {alle.Count} passen"; + if (e.Text("hinweis") is string h) zaehler += " · " + h; + _zaehler.Text = zaehler; + + _leer.Content = alle.Count == 0 + ? Teile.Leer("Noch keine Entscheidungen", e.Text("leer") ?? "Sobald der Kern entscheidet, steht es hier.", "") + : treffer.Count == 0 ? Teile.Leer("Nichts passt", "Filter lockern oder zurücksetzen.", "") : null; + + _liste.Children.Clear(); + var behalten = new HashSet(); + foreach (var z in treffer.Take(_zeigen)) + { + var schluessel = $"{z.T("zeit")}|{z.T("raum")}|{z.T("hand")}|{z.T("strasse")}"; + behalten.Add(schluessel); + var offen = _offen == schluessel; + var ab = z.Abdruck() + (offen ? "+" : ""); + if (!_zeilen.TryGetValue(schluessel, out var alt) || alt.Abdruck != ab) + _zeilen[schluessel] = alt = (ab, ZeileBauen(z, schluessel, offen)); + if (_liste.Children.Count > 0) _liste.Children.Add(new Border { Height = 1, Background = Ui.Weiss(0.06) }); + _liste.Children.Add(alt.Zeile); + } + foreach (var k in _zeilen.Keys.Where(k => !behalten.Contains(k)).ToList()) _zeilen.Remove(k); + if (treffer.Count > _zeigen) + { + var mehr = Teile.Knopf($"Weitere {Math.Min(Seite, treffer.Count - _zeigen)} zeigen", () => { _zeigen += Seite; Neu(false); }); + mehr.HorizontalAlignment = HorizontalAlignment.Center; + mehr.Margin = new Thickness(0, 10, 0, 0); + _liste.Children.Add(mehr); + } + } + + private UIElement ZeileBauen(JsonObject z, string schluessel, bool offen) + { + // Zeile 1: Uhr, Strasse, Aktion mit Betrag, Ergebnis, Klick + var kopf = new Grid { ColumnSpacing = 6 }; + foreach (var w in new[] { GridLength.Auto, GridLength.Auto, new GridLength(1, GridUnitType.Star), GridLength.Auto, GridLength.Auto }) + kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = w }); + kopf.Children.Add(Ui.Text(Format.Uhr(z.Zahl("zeit")), 12, pinsel: Ui.Zweit, zahlen: true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + kopf.Children.Add(Ui.Text(z.T("strasse"), 12, pinsel: Ui.Zweit).Spalte(1).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + kopf.Children.Add(Ui.Text(MitBetrag(z.Text("aktion_text") ?? z.Text("aktion"), z.Zahl("betrag_bb")), 14, fett: true).Spalte(2)); + if (z.Zahl("ergebnis_bb") is double x) + kopf.Children.Add(Ui.Text(Format.Vorzeichen(x) + " bb", 12, Teile.Ton(x), zahlen: true).Spalte(3).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + kopf.Children.Add(KlickSymbol(z.Text("klick"), z.Text("klick_warum")).Spalte(4)); + + // Zeile 2: Karten, Board, Klartext + var zwei = new Grid { ColumnSpacing = 8 }; + zwei.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + zwei.ColumnDefinitions.Add(new ColumnDefinition()); + var karten = z.Texte("karten").ToList(); + if (karten.Count > 0) zwei.Children.Add(Kartenzeile(karten, z.Texte("board").ToList())); + var satz = Ui.Klein(z.Text("klartext") ?? z.T("grund"), true); + satz.MaxLines = offen ? 0 : 2; + satz.TextTrimming = TextTrimming.CharacterEllipsis; + satz.VerticalAlignment = VerticalAlignment.Center; + zwei.Children.Add(satz.Spalte(karten.Count > 0 ? 1 : 0).Mit(t => { if (karten.Count == 0) Grid.SetColumnSpan(t, 2); })); + + var spalte = Ui.Spalte(5, kopf, zwei); + spalte.Padding = new Thickness(4, 8, 4, 8); + if (offen) spalte.Children.Add(Einzelheiten(z)); + return spalte.Tippen(() => + { + _offen = _offen == schluessel ? null : schluessel; + Neu(false); + }, 8); + } + + private static UIElement Einzelheiten(JsonObject z) + { + var g = new Grid { ColumnSpacing = 10, RowSpacing = 3, Margin = new Thickness(0, 4, 0, 0) }; + g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + g.ColumnDefinitions.Add(new ColumnDefinition()); + var reihen = new List<(string, string)> + { + ("Tisch", z.Text("raum") ?? "–"), + ("Hand", z.Text("hand") ?? "–"), + ("Stake", string.Join(" · ", new[] { z.Text("stake"), z.Text("spielart") }.Where(s => !string.IsNullOrEmpty(s)))), + ("Equity", Format.Prozent(z.Zahl("equity"))), + ("Confidence", Format.Zahl(z.Zahl("confidence"), 2)), + ("Gedenkzeit", z.Zahl("gedenkzeit_s") is double s ? Format.Zahl(s, 1) + " s" : "–"), + ("Ergebnis", z.Text("ergebnis_text") ?? "–"), + ("Klick", string.Join(" - ", new[] { z.Text("klick"), z.Text("klick_warum") }.Where(s => !string.IsNullOrEmpty(s)))), + }; + if (z.Text("beleg") is { Length: > 0 } b) reihen.Add(("Beleg", b)); + if (z.Text("grund") is { Length: > 0 } gr && gr != z.Text("klartext")) reihen.Add(("Grund", gr)); + if (z.Obj("modus") is JsonObject m && m.Text("art") is string art && art != "cash") + reihen.Insert(0, ("Modus", string.Join(" · ", new[] { m.Text("text"), m.Text("lage") }.Where(t => !string.IsNullOrEmpty(t))) is { Length: > 0 } mt ? mt : art)); + for (var i = 0; i < reihen.Count; i++) + { + g.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + g.Children.Add(Ui.Text(reihen[i].Item1, 12, pinsel: Ui.Zweit).Zeile(i)); + var wert = new TextBlock + { + Text = string.IsNullOrEmpty(reihen[i].Item2) ? "–" : reihen[i].Item2, + FontSize = 12, + TextWrapping = TextWrapping.Wrap, + IsTextSelectionEnabled = true, + }; + g.Children.Add(wert.Zeile(i).Spalte(1)); + } + return g; + } + + /// Aktionstext.mitBetrag: "Raise" + " 3 bb". + public static string MitBetrag(string? aktion, double? bb) + { + var a = aktion ?? "–"; + if (a.Length > 1 && a.All(c => !char.IsLower(c))) a = a[0] + a[1..].ToLowerInvariant().Replace('_', '-'); + // aktion_text traegt den Betrag oft schon ("Raise auf 11,83 BB") - dann nicht doppelt + return bb is double b && b > 0 && !a.Any(char.IsDigit) ? $"{a} {Format.Auto(b)} bb" : a; + } + + /// Kleine Karten, dann das Board etwas abgesetzt (Kartenzeile in Bausteine.swift). + public static StackPanel Kartenzeile(IList karten, IList board) + { + var r = Ui.Reihe(2); + foreach (var k in karten) r.Children.Add(Ui.Spielkarte(k)); + if (board.Count > 0) + { + r.Children.Add(new Border { Width = 6 }); + foreach (var k in board) r.Children.Add(Ui.Spielkarte(k).Mit(b => b.Opacity = 0.85)); + } + r.VerticalAlignment = VerticalAlignment.Center; + return r; + } + + /// Der Klick einer Entscheidung als Zeichen (bestaetigt, unbestaetigt, ausgesetzt, gestoppt, Schatten). + public static FontIcon KlickSymbol(string? status, string? warum) + { + var (glyph, ton) = status switch + { + "bestätigt" => ("", "gruen"), + "unbestätigt" => ("", "orange"), + "gestoppt" => ("", "rot"), + "ausgesetzt" => ("", "grau"), + _ => ("", "grau"), + }; + var z = Ui.Zeichen(glyph, 12, ton); + z.VerticalAlignment = VerticalAlignment.Center; + ToolTipService.SetToolTip(z, string.Join(" - ", new[] { status, warum }.Where(s => !string.IsNullOrEmpty(s))) is { Length: > 0 } t ? t : "Klick"); + return z; + } +} diff --git a/winui/Seiten/LiveTeil.cs b/winui/Seiten/LiveTeil.cs new file mode 100644 index 00000000..f5b6790c --- /dev/null +++ b/winui/Seiten/LiveTeil.cs @@ -0,0 +1,955 @@ +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, Ui.Dritt) : 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}"; + } + } +} diff --git a/winui/Seiten/ProtokollSeite.cs b/winui/Seiten/ProtokollSeite.cs new file mode 100644 index 00000000..7a7eab72 --- /dev/null +++ b/winui/Seiten/ProtokollSeite.cs @@ -0,0 +1,154 @@ +using System.Text.Json.Nodes; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Media; +using Pokerfreak.Cockpit.Kern; + +namespace Pokerfreak.Cockpit.Seiten; + +/// +/// Der Reiter Protokoll (EntscheidungenGeld.swift `ProtokollAnsicht`): Gedanken und Ereignisse als +/// Strom in Festbreitenschrift, anhaltbar zum Lesen; Geld als Liste der Geldbewegungen mit Art-Filter. +/// +public sealed class ProtokollSeite : UserControl, ISeite +{ + private static readonly FontFamily Fest = new("Cascadia Mono, Consolas"); + + private readonly CockpitZustand _z; + private readonly Segmente _teil = new(new[] { "Gedanken", "Ereignisse", "Geld" }, "protokoll.teil"); + private readonly ToggleButton _pause = new() + { + Content = Ui.Zeichen("", 12), + Padding = new Thickness(8, 5, 8, 5), + CornerRadius = new CornerRadius(8), + }; + private readonly Auswahl _art = new("Art"); + private readonly Border _uebung = Ui.Abzeichen("ÜBUNG", "blau"); + private readonly StackPanel _liste = Ui.Spalte(6); + private readonly ScrollViewer _rollen; + private JsonObject? _angehalten; + private string _abdruck = ""; + + public ProtokollSeite(CockpitZustand z) + { + _z = z; + ToolTipService.SetToolTip(_pause, "Anhalten zum Lesen"); + _teil.Gewaehlt += _ => { _abdruck = ""; Zeichnen(); }; + _pause.Click += (_, _) => { _angehalten = _pause.IsChecked == true ? _z.Ansicht.Ticker : null; _abdruck = ""; Zeichnen(); }; + _art.Geaendert += () => { _abdruck = ""; Zeichnen(); }; + + var kopf = new Grid { ColumnSpacing = 8, Padding = new Thickness(12) }; + kopf.ColumnDefinitions.Add(new ColumnDefinition()); + kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + kopf.Children.Add(_teil); + kopf.Children.Add(_pause.Spalte(1).Mit(p => p.VerticalAlignment = VerticalAlignment.Center)); + kopf.Children.Add(_art.Spalte(2).Mit(a => a.VerticalAlignment = VerticalAlignment.Center)); + kopf.Children.Add(_uebung.Spalte(3)); + + _liste.Padding = new Thickness(12); + _rollen = new ScrollViewer { Content = _liste, HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled }; + var g = new Grid(); + g.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + g.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + g.RowDefinitions.Add(new RowDefinition()); + g.Children.Add(kopf); + g.Children.Add(new Border { Height = 1, Background = Ui.Weiss(0.08) }.Zeile(1)); + g.Children.Add(_rollen.Zeile(2)); + Content = g; + } + + public void Zeichnen() + { + var geld = _teil.Index == 2; + _pause.Visibility = geld ? Visibility.Collapsed : Visibility.Visible; + _art.Visibility = geld ? Visibility.Visible : Visibility.Collapsed; + _uebung.Visibility = geld && _z.Ansicht.Geld.Wahr("uebung") ? Visibility.Visible : Visibility.Collapsed; + if (geld) GeldZeichnen(); + else StromZeichnen(_teil.Index == 0); + } + + private void StromZeichnen(bool gedanken) + { + var t = _angehalten ?? _z.Ansicht.Ticker; + var abdruck = (gedanken ? "g" : "e") + (gedanken ? t?["gedanken"] : t?["zeilen"]).Abdruck(); + if (abdruck == _abdruck) return; + _abdruck = abdruck; + _liste.Children.Clear(); + if (gedanken) + { + foreach (var g in t.Texte("gedanken")) + _liste.Children.Add(FestText(g)); + } + else + { + foreach (var z in t.Objekte("zeilen")) + { + var tb = FestText(""); + tb.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run { Text = Format.Uhr(z.Zahl("zeit")) + " ", Foreground = Ui.Zweit }); + if (z.Text("art") is string art) + tb.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run { Text = art + " ", Foreground = Ui.Akzent }); + tb.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run + { + Text = string.Join(" · ", new[] { z.Text("raum"), z.Text("text") }.Where(s => !string.IsNullOrEmpty(s))), + }); + _liste.Children.Add(tb); + } + } + if (_liste.Children.Count == 0) + _liste.Children.Add(Teile.Leer("Noch nichts", t.Text("leer") ?? "Der Strom läuft, sobald der Läufer arbeitet.", "")); + } + + private static TextBlock FestText(string text) => new() + { + Text = text, + FontFamily = Fest, + FontSize = 11.5, + TextWrapping = TextWrapping.Wrap, + IsTextSelectionEnabled = true, + }; + + private void GeldZeichnen() + { + var g = _z.Ansicht.Geld; + var alle = g.Objekte("zeilen").ToList(); + _art.Werte(alle.Select(z => z.Text("art")).OfType().Distinct().OrderBy(a => a)); + var abdruck = "geld" + g?["zeilen"].Abdruck() + _art.Wahl; + if (abdruck == _abdruck) return; + _abdruck = abdruck; + _liste.Children.Clear(); + var zeilen = alle.Where(z => _art.Wahl == null || z.Text("art") == _art.Wahl).ToList(); + if (zeilen.Count == 0) + { + _liste.Children.Add(Teile.Leer("Keine Geldbewegungen", g.Text("leer") ?? "Buy-in, Nachkauf und Aufstehen erscheinen hier.", "")); + return; + } + foreach (var z in zeilen) + { + var kopf = new Grid { ColumnSpacing = 6 }; + foreach (var w in new[] { GridLength.Auto, GridLength.Auto, GridLength.Auto, new GridLength(1, GridUnitType.Star), GridLength.Auto, GridLength.Auto }) + kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = w }); + kopf.Children.Add(Ui.Text(Format.Uhr(z.Zahl("zeit")), 12, pinsel: Ui.Zweit, zahlen: true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + kopf.Children.Add(Ui.Text(z.Text("art") ?? "–", 14, fett: true).Spalte(1)); + if (z.WahrOderNull("uebung") == true) kopf.Children.Add(Ui.Abzeichen("Übung", "blau").Spalte(2)); + if (z.Zahl("betrag") is double b) kopf.Children.Add(Ui.Text(Format.Zahl(b, 2), 14, zahlen: true).Spalte(4)); + if (z.Zahl("betrag_bb") is double bb) + kopf.Children.Add(Ui.Text(Format.Auto(bb) + " bb", 12, pinsel: Ui.Zweit).Spalte(5).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + var unter = new TextBlock + { + Text = string.Join(" · ", new[] { z.Text("raum"), z.Text("grund") }.Where(s => !string.IsNullOrEmpty(s))), + FontSize = 12, + Foreground = Ui.Zweit, + TextWrapping = TextWrapping.Wrap, + IsTextSelectionEnabled = true, + }; + var s = Ui.Spalte(3, kopf, unter); + s.Padding = new Thickness(4, 6, 4, 6); + s.Opacity = z.WahrOderNull("uebung") == true ? 0.75 : 1; + if (_liste.Children.Count > 0) _liste.Children.Add(new Border { Height = 1, Background = Ui.Weiss(0.06) }); + _liste.Children.Add(s); + } + } +} diff --git a/winui/Seiten/StatistikSeite.cs b/winui/Seiten/StatistikSeite.cs new file mode 100644 index 00000000..4f5c10a0 --- /dev/null +++ b/winui/Seiten/StatistikSeite.cs @@ -0,0 +1,467 @@ +using System.Text.Json.Nodes; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Shapes; +using Pokerfreak.Cockpit.Kern; + +namespace Pokerfreak.Cockpit.Seiten; + +/// +/// Der Reiter Statistik (Diagramme.swift): Ergebnis und Stil. Ergebnis zeigt Übung, Cash (je ab ihrem +/// Nullpunkt) oder das Archiv mit Kennzahlen, Formatvergleich und einem Diagramm zur Wahl; Stil die +/// Anteile der Aktionen, ihren Verlauf, die Einsatzgroessen und die Gedenkzeiten. +/// +public sealed class StatistikSeite : UserControl, ISeite +{ + private static readonly string[] ErgebnisTeile = { "Kurve", "Verteilung", "Stakes", "Stunden", "Stapel", "Sitzungen" }; + private static readonly (string Name, string Schluessel, string Ton)[] Aktionen = + { ("Fold", "fold", "grau"), ("Check", "check", "teal"), ("Call", "call", "blau"), ("Raise", "raise", "orange"), ("All-in", "allin", "rot") }; + + private readonly CockpitZustand _z; + private readonly Segmente _teil = new(new[] { "Ergebnis", "Stil" }, "statistik.teil"); + private readonly Segmente _grundlage = new(new[] { "Übung", "Cash", "Archiv" }); + private readonly Segmente _stilTeil = new(new[] { "Anteile", "Verlauf", "Größen", "Denkzeit" }, "stil.teil"); + private readonly ComboBox _diagrammWahl = new() { FontSize = 12, MinWidth = 130, CornerRadius = new CornerRadius(8) }; + private readonly StackPanel _ergebnis = Ui.Spalte(12), _stil = Ui.Spalte(12); + private readonly ContentControl _ergebnisInhalt = new() { HorizontalContentAlignment = HorizontalAlignment.Stretch }; + private readonly ContentControl _stilInhalt = new() { HorizontalContentAlignment = HorizontalAlignment.Stretch }; + private bool _grundlageGewaehlt, _fragtReset; + private string _abdruck = ""; + + public StatistikSeite(CockpitZustand z) + { + _z = z; + foreach (var t in ErgebnisTeile) _diagrammWahl.Items.Add(t); + _diagrammWahl.SelectedIndex = int.TryParse(Merker.Lesen("ergebnis.teil"), out var d) && d is >= 0 and < 6 ? d : 0; + _diagrammWahl.SelectionChanged += (_, _) => + { + if (_diagrammWahl.SelectedIndex >= 0) Merker.Schreiben("ergebnis.teil", _diagrammWahl.SelectedIndex.ToString()); + Neu(); + }; + _teil.Gewaehlt += _ => Neu(); + _grundlage.Gewaehlt += _ => { _grundlageGewaehlt = true; _fragtReset = false; Neu(); }; + _stilTeil.Gewaehlt += _ => Neu(); + + _ergebnis.Children.Add(_grundlage); + _ergebnis.Children.Add(_ergebnisInhalt); + _stil.Children.Add(_stilTeil); + _stil.Children.Add(_stilInhalt); + + var oben = new Border { Padding = new Thickness(12, 10, 12, 0), Child = _teil }; + var rollen = new ScrollViewer + { + Content = new Grid { Children = { _ergebnis, _stil }, Padding = new Thickness(12) }, + HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled, + }; + var g = new Grid(); + g.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + g.RowDefinitions.Add(new RowDefinition()); + g.Children.Add(oben); + g.Children.Add(rollen.Zeile(1)); + Content = g; + } + + public void Zeichnen() + { + var a = _z.Ansicht; + var abdruck = a.Wachstum.Abdruck() + a.Stil.Abdruck() + _z.Wahl.Cash; + if (abdruck == _abdruck) return; + _abdruck = abdruck; + Neu(); + } + + private void Neu() + { + if (!_grundlageGewaehlt) _grundlage.Index = _z.Wahl.Cash ? 1 : 0; + var ergebnis = _teil.Index == 0; + _ergebnis.Visibility = ergebnis ? Visibility.Visible : Visibility.Collapsed; + _stil.Visibility = ergebnis ? Visibility.Collapsed : Visibility.Visible; + if (ergebnis) ErgebnisBauen(); + else StilBauen(); + } + + // ---- Ergebnis -------------------------------------------------------------------------------- + + private void ErgebnisBauen() + { + var w = _z.Ansicht.Wachstum; + var archiv = _grundlage.Index == 2; + var cash = _grundlage.Index == 1; + var k = archiv ? w.Obj("bestand") : w.Obj("je_modus").Obj(cash ? "cash" : "uebung"); + var s = Ui.Spalte(12); + + var kopf = new Grid(); + kopf.ColumnDefinitions.Add(new ColumnDefinition()); + kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + if (k.Text("grundlage") is string g) kopf.Children.Add(Ui.Klein(g, true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + if (!archiv) + { + var knoepfe = Ui.Reihe(6); + if (k.Zahl("nullpunkt") != null) knoepfe.Children.Add(Teile.Knopf("Ab Anfang", () => Zuruecksetzen(true))); + knoepfe.Children.Add(Teile.Knopf("Zurücksetzen", () => { _fragtReset = true; Neu(); })); + kopf.Children.Add(knoepfe.Spalte(1)); + } + s.Children.Add(kopf); + if (_fragtReset && !archiv) s.Children.Add(ResetFrage(cash)); + if (archiv) s.Children.Add(Ui.Winzig("Summe über alle Sitze im Archiv, nicht der eigene Verlauf.", Ui.Dritt)); + if (!archiv && w.Zahl("unklar") is double u && u > 0) + s.Children.Add(Ui.Winzig($"{u:0} Hände ohne bekannten Modus zählen hier nicht mit.", Ui.Dritt)); + + var summe = k.Obj("summe"); + if (k == null || (summe.Zahl("haende") ?? 0) == 0) + { + s.Children.Add(Teile.Leer(k.Wahr("rechnet") ? "Wird gerechnet" : "Noch keine Hände", + k.Text("leer") ?? w.Text("leer") ?? "Kurven erscheinen mit den ersten eigenen Händen.", "")); + _ergebnisInhalt.Content = s; + return; + } + + s.Children.Add(Kennzahlen(k)); + if (!archiv && FormatVergleich(k) is UIElement fv) s.Children.Add(fv); + if (archiv && _diagrammWahl.SelectedIndex >= 4) _diagrammWahl.SelectedIndex = 0; + s.Children.Add(_diagrammWahl.Parent is Panel p ? Loesen(p) : _diagrammWahl); + s.Children.Add(DiagrammBauen(k, w, archiv)); + _ergebnisInhalt.Content = s; + } + + private UIElement Loesen(Panel p) + { + p.Children.Remove(_diagrammWahl); + return _diagrammWahl; + } + + private void Zuruecksetzen(bool abAnfang) + { + _fragtReset = false; + // steuern.py nimmt "uebung" oder "echt" (je_modus heisst den Cash-Teil "cash") + var daten = new JsonObject { ["modus"] = _grundlage.Index == 1 ? "echt" : "uebung" }; + _ = _z.Senden((abAnfang ? "statistik_ab_anfang" : "statistik_zuruecksetzen", daten)); + Neu(); + } + + private Border ResetFrage(bool cash) + { + var g = new Grid { ColumnSpacing = 8 }; + g.ColumnDefinitions.Add(new ColumnDefinition()); + g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + g.Children.Add(Ui.Text($"Statistik {(cash ? "Cash" : "Übung")} ab jetzt neu zählen? Das Archiv bleibt.", 12, umbruch: true)); + g.Children.Add(Ui.Reihe(6, + Teile.Knopf("Abbrechen", () => { _fragtReset = false; Neu(); }), + Teile.Knopf("Zurücksetzen", () => Zuruecksetzen(false), "orange", true)).Spalte(1)); + return Ui.Getoent(g, "orange", 0.12, 10, 8); + } + + private static Grid Kennzahlen(JsonObject? k) + { + var s = k.Obj("summe"); + var bb100 = Gesamt(k.Objekte("bb100")); + var g = new Grid { ColumnSpacing = 8, RowSpacing = 8 }; + g.ColumnDefinitions.Add(new ColumnDefinition()); + g.ColumnDefinitions.Add(new ColumnDefinition()); + g.RowDefinitions.Add(new RowDefinition()); + g.RowDefinitions.Add(new RowDefinition()); + g.Children.Add(Teile.Kennzahl("Hände", Format.Zahl(s.Zahl("haende")))); + g.Children.Add(Teile.Kennzahl("Netto", Format.Vorzeichen(s.Zahl("netto_bb")) + " bb", Teile.Ton(s.Zahl("netto_bb"))).Spalte(1)); + g.Children.Add(Teile.Kennzahl("bb/100", Format.Vorzeichen(bb100), Teile.Ton(bb100)).Zeile(1)); + g.Children.Add(Teile.Kennzahl("Gewonnen / verloren", $"{s.Zahl("gewonnen") ?? 0:0} / {s.Zahl("verloren") ?? 0:0}").Zeile(1).Spalte(1)); + return g; + } + + /// bb/100 ueber alle Stakes, gewichtet nach Haenden (Diagramme.swift `BB100.gesamt`). + private static double? Gesamt(IEnumerable zeilen) + { + var l = zeilen.ToList(); + var n = l.Sum(z => z.Zahl("haende") ?? 0); + return n > 0 ? l.Sum(z => (z.Zahl("bb100") ?? 0) * (z.Zahl("haende") ?? 0)) / n : null; + } + + /// Formate im Vergleich (FormatVergleich.swift): bb/100 mit 95-%-Spanne auf gemeinsamer Achse. + private static UIElement? FormatVergleich(JsonObject? k) + { + var zeilen = k.Objekte("je_format").ToList(); + if (zeilen.Count == 0) return null; + var s = Ui.Spalte(8); + s.Children.Add(Ui.Zeile(Ui.Text("Formate im Vergleich", 12, pinsel: Ui.Zweit, fett: true), Ui.Winzig("bb/100 · 95 %", Ui.Dritt))); + if (k.Obj("bestes_format") is JsonObject u) + { + var sieger = Formate.AusRoh(u.Text("format")); + var titel = Ui.Reihe(6, + Ui.Zeichen(sieger == null ? "" : "", 13, sieger == null ? "grau" : "gruen"), + Ui.Text(sieger is SpielFormat f ? $"{f.Name()} liegt vorn" : "Noch kein Urteil", 14, sieger == null ? "grau" : "gruen", fett: true)); + s.Children.Add(Ui.Spalte(1, titel, Ui.Text(u.T("grund"), 11, pinsel: Ui.Dritt, umbruch: true))); + } + var werte = zeilen.SelectMany(z => new[] { z.Zahl("unten"), z.Zahl("oben"), z.Zahl("bb100") }).OfType().Append(0.0).ToList(); + double lo = werte.Min(), hi = werte.Max(); + if (hi - lo < 1e-9) { lo -= 1; hi += 1; } + foreach (var z in zeilen) + { + var fmt = Formate.AusRoh(z.Text("format")); + var b = z.Zahl("bb100"); + var kopf = new Grid { ColumnSpacing = 6 }; + foreach (var w in new[] { GridLength.Auto, GridLength.Auto, GridLength.Auto, new GridLength(1, GridUnitType.Star), GridLength.Auto }) + kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = w }); + kopf.Children.Add(Ui.Zeichen(fmt?.Zeichen() ?? "", 11, "grau")); + kopf.Children.Add(Ui.Text(z.T("name"), 12, fett: true).Spalte(1)); + kopf.Children.Add(Ui.Winzig($"{z.Zahl("haende") ?? 0:0} Hände", Ui.Dritt).Spalte(2).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + kopf.Children.Add(Ui.Text(Format.Vorzeichen(b), 12, Teile.Ton(b), fett: true, zahlen: true).Spalte(4)); + var balken = new Diagramm(12) + { + Zeichnen = (c, br, _) => + { + double X(double v) => br * (v - lo) / (hi - lo); + c.Children.Add(Ort(new Rectangle { Width = br, Height = 4, RadiusX = 2, RadiusY = 2, Fill = Ui.Weiss(0.1) }, 0, 4)); + c.Children.Add(Ort(new Rectangle { Width = 1, Height = 12, Fill = Ui.Weiss(0.4) }, X(0), 0)); + if (z.Zahl("unten") is double un && z.Zahl("oben") is double ob) + c.Children.Add(Ort(new Rectangle { Width = Math.Max(2, X(ob) - X(un)), Height = 8, RadiusX = 4, RadiusY = 4, Fill = Ui.Pinsel(Teile.Ton(b) ?? "grau", 0.35) }, X(un), 2)); + if (b is double bv) + c.Children.Add(Ort(new Ellipse { Width = 8, Height = 8, Fill = Ui.Pinsel(Teile.Ton(bv)) }, X(bv) - 4, 2)); + }, + }; + ToolTipService.SetToolTip(balken, z.Zahl("unten") is double uu + ? $"95 %: {Format.Zahl(uu)} bis {Format.Zahl(z.Zahl("oben"))} bb/100" : "zu wenig Hände für eine Spanne"); + s.Children.Add(Ui.Spalte(3, kopf, balken)); + } + return Ui.Flaeche(s, 14, 0.05, 10); + } + + private static T Ort(T e, double x, double y) where T : UIElement + { + Canvas.SetLeft(e, x); + Canvas.SetTop(e, y); + return e; + } + + private UIElement DiagrammBauen(JsonObject? k, JsonObject? w, bool archiv) + { + var d = new Diagramm(220); + switch (_diagrammWahl.SelectedIndex) + { + case 0: + { + var p = k.Objekte("ergebnis_kurve") + .Where(x => x.Zahl("t") != null && x.Zahl("bb") != null) + .Select(x => (x.Zahl("t")!.Value, x.Zahl("bb")!.Value)).ToList(); + d.Zeichnen = (c, b, h) => Diagramm.Linie(c, b, h, p, "blau", t => Format.Ortszeit(t).ToString("dd.MM. HH:mm")); + break; + } + case 1: + { + var v = k.Objekte("verteilung").Select(x => + { + var von = x.Zahl("von"); + var bis = x.Zahl("bis"); + var name = von == null ? $"<{Format.Auto(bis)}" : bis == null ? $"≥{Format.Auto(von)}" : $"{Format.Auto(von)}"; + return (name, x.Zahl("anzahl") ?? 0, (bis ?? 1) <= 0 ? "rot" : "gruen"); + }).ToList(); + d.Zeichnen = (c, b, h) => Diagramm.Saeulen(c, b, h, v, b < 420 ? 2 : 1); + break; + } + case 2: + return Stakes(k); + case 3: + { + var v = k.Objekte("je_stunde").Select(x => (Format.Kurz(x.Zahl("stunde")), x.Zahl("haende") ?? 0, "blau")).ToList(); + d.Zeichnen = (c, b, h) => Diagramm.Saeulen(c, b, h, v, Math.Max(1, v.Count / 6)); + break; + } + case 4: + return Stapel(w); + default: + return Sitzungen(w); + } + return d; + } + + /// bb/100 je Stake mit 95-%-Intervall: Punkt und Spanne je Zeile. + private static UIElement Stakes(JsonObject? k) + { + var zeilen = k.Objekte("bb100").ToList(); + var s = Ui.Spalte(10); + var werte = zeilen.SelectMany(z => new[] { z.Zahl("unten"), z.Zahl("oben"), z.Zahl("bb100") }).OfType().Append(0.0).ToList(); + double lo = werte.Min(), hi = werte.Max(); + if (hi - lo < 1e-9) { lo -= 1; hi += 1; } + foreach (var z in zeilen) + { + var b = z.Zahl("bb100"); + var kopf = Ui.Zeile(Ui.Reihe(6, Ui.Text(z.T("stake"), 13, fett: true), Ui.Winzig($"{z.Zahl("haende") ?? 0:0} Hände", Ui.Dritt)), + Ui.Text(Format.Vorzeichen(b), 13, Teile.Ton(b), true, zahlen: true)); + var balken = new Diagramm(12) + { + Zeichnen = (c, br, _) => + { + double X(double v) => br * (v - lo) / (hi - lo); + c.Children.Add(Ort(new Rectangle { Width = br, Height = 4, RadiusX = 2, RadiusY = 2, Fill = Ui.Weiss(0.1) }, 0, 4)); + c.Children.Add(Ort(new Rectangle { Width = 1, Height = 12, Fill = Ui.Weiss(0.4) }, X(0), 0)); + if (z.Zahl("unten") is double un && z.Zahl("oben") is double ob) + c.Children.Add(Ort(new Rectangle { Width = Math.Max(2, X(ob) - X(un)), Height = 8, RadiusX = 4, RadiusY = 4, Fill = Ui.Weiss(0.25) }, X(un), 2)); + if (b is double bv) + c.Children.Add(Ort(new Ellipse { Width = 9, Height = 9, Fill = Ui.Pinsel(Teile.Ton(bv)) }, X(bv) - 4.5, 1.5)); + }, + }; + s.Children.Add(Ui.Spalte(4, kopf, balken)); + } + s.Children.Add(Ui.Winzig("bb/100 mit 95 %-Intervall", Ui.Dritt)); + return Ui.Flaeche(s, 14, 0.05, 12); + } + + /// Stapel je Tisch ueber die Zeit, eine Linie je Tisch mit Legende. + private static UIElement Stapel(JsonObject? w) + { + var toene = new[] { "blau", "orange", "gruen", "lila", "teal", "gelb", "rot", "indigo" }; + var reihen = w.Objekte("stapel").Select((r, i) => (Raum: r.T("raum"), Ton: toene[i % toene.Length], + Punkte: r.Objekte("punkte").Where(p => p.Zahl("t") != null && p.Zahl("stack") != null) + .Select(p => (p.Zahl("t")!.Value, p.Zahl("stack")!.Value)).ToList())).Where(r => r.Punkte.Count > 0).ToList(); + if (reihen.Count == 0) return Ui.Klein("Noch keine Stapel."); + double x0 = reihen.Min(r => r.Punkte.Min(p => p.Item1)), x1 = reihen.Max(r => r.Punkte.Max(p => p.Item1)); + double lo = reihen.Min(r => r.Punkte.Min(p => p.Item2)), hi = reihen.Max(r => r.Punkte.Max(p => p.Item2)); + var d = new Diagramm(220) + { + Zeichnen = (c, b, h) => + { + var Y = Diagramm.AchseY(c, b, h, lo, hi); + var spanne = Math.Max(1e-9, x1 - x0); + foreach (var r in reihen) + { + var linie = new Polyline { Stroke = Ui.Pinsel(r.Ton), StrokeThickness = 1.6 }; + foreach (var (t, st) in r.Punkte) + linie.Points.Add(new Windows.Foundation.Point(Diagramm.Links + 4 + (b - Diagramm.Links - 8) * (t - x0) / spanne, Y(st))); + c.Children.Add(linie); + } + Diagramm.Beschriftung(c, Format.Kurz(x0), Diagramm.Links + 30, h - Diagramm.Unten + 3); + Diagramm.Beschriftung(c, Format.Kurz(x1), b - 30, h - Diagramm.Unten + 3); + }, + }; + var legende = new VariableSizedWrapGrid { Orientation = Orientation.Horizontal, ItemHeight = 18, ItemWidth = 130 }; + foreach (var r in reihen) legende.Children.Add(Ui.Reihe(4, Ui.Punkt(r.Ton, 7), Ui.Winzig(r.Raum))); + return Ui.Spalte(6, d, legende); + } + + private static UIElement Sitzungen(JsonObject? w) + { + var s = Ui.Spalte(0); + foreach (var x in w.Objekte("sitzungen").Reverse()) + { + var n = x.Zahl("netto_bb"); + var links = Ui.Spalte(1, Ui.Text(x.Text("raum") ?? "–", 14, fett: true), + Ui.Klein($"{Format.Kurz(x.Zahl("von"))}–{(x.Zahl("bis") is double b ? Format.Kurz(b) : "läuft")} · {x.Zahl("haende") ?? 0:0} Hände")); + var z = Ui.Zeile(links, Ui.Text(Format.Vorzeichen(n) + " bb", 14, Teile.Ton(n), zahlen: true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)); + z.Padding = new Thickness(0, 6, 0, 6); + if (s.Children.Count > 0) s.Children.Add(new Border { Height = 1, Background = Ui.Weiss(0.06) }); + s.Children.Add(z); + } + return s.Children.Count == 0 ? Ui.Klein("Noch keine Sitzungen.") : s; + } + + // ---- Stil ------------------------------------------------------------------------------------ + + private void StilBauen() + { + var st = _z.Ansicht.Stil; + var a = st.Obj("anteile"); + if ((a.Zahl("n") ?? 0) == 0) + { + _stilInhalt.Content = Teile.Leer("Noch kein Stil", st.Text("leer") ?? "Erst nach den ersten Entscheidungen.", ""); + return; + } + _stilInhalt.Content = _stilTeil.Index switch + { + 0 => Anteile(a), + 1 => Verlauf(st.Objekte("verlauf").ToList()), + 2 => Groessen(st.Objekte("groessen").ToList()), + _ => Denkzeit(st), + }; + } + + private static UIElement Anteile(JsonObject? a) + { + var s = Ui.Spalte(8); + foreach (var (name, k, ton) in Aktionen) + { + var v = a.Zahl(k) ?? 0; + var g = new Grid { ColumnSpacing = 8 }; + g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(52) }); + g.ColumnDefinitions.Add(new ColumnDefinition()); + g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(44) }); + g.Children.Add(Ui.Text(name, 13)); + g.Children.Add(LiveTeil.Balken(v, ton, 8, false).Spalte(1).Mit(b => b.VerticalAlignment = VerticalAlignment.Center)); + g.Children.Add(Ui.Text(Format.Prozent(v), 12, zahlen: true).Spalte(2).Mit(t => t.TextAlignment = TextAlignment.Right)); + s.Children.Add(g); + } + s.Children.Add(Ui.Klein($"aus {a.Zahl("n") ?? 0:0} Entscheidungen")); + return s; + } + + /// Gestapelte Flaechen je Block zu 20 Entscheidungen (AreaMark, stacking: .normalized). + private static UIElement Verlauf(List bloecke) + { + var d = new Diagramm(240) + { + Zeichnen = (c, b, h) => + { + var Y = Diagramm.AchseY(c, b, h, 0, 1); + var n = bloecke.Count; + double X(int i) => Diagramm.Links + 4 + (b - Diagramm.Links - 8) * (n <= 1 ? 0.5 : i / (double)(n - 1)); + var unten = new double[n]; + foreach (var (_, k, ton) in Aktionen) + { + var f = new Polygon { Fill = Ui.Pinsel(ton, 0.75) }; + var oben = new double[n]; + for (var i = 0; i < n; i++) + { + var summe = Aktionen.Sum(x => bloecke[i].Zahl(x.Schluessel) ?? 0); + oben[i] = unten[i] + (summe > 0 ? (bloecke[i].Zahl(k) ?? 0) / summe : 0); + f.Points.Add(new Windows.Foundation.Point(X(i), Y(oben[i]))); + } + for (var i = n - 1; i >= 0; i--) f.Points.Add(new Windows.Foundation.Point(X(i), Y(unten[i]))); + if (n == 1) { f.Points.Clear(); f.Points.Add(new(Diagramm.Links + 4, Y(oben[0]))); f.Points.Add(new(b - 4, Y(oben[0]))); f.Points.Add(new(b - 4, Y(unten[0]))); f.Points.Add(new(Diagramm.Links + 4, Y(unten[0]))); } + c.Children.Add(f); + unten = oben; + } + }, + }; + var legende = Ui.Reihe(10); + foreach (var (name, _, ton) in Aktionen) legende.Children.Add(Ui.Reihe(4, Ui.Punkt(ton, 7), Ui.Winzig(name))); + return Ui.Spalte(6, d, legende, Ui.Winzig("Blöcke zu 20 Entscheidungen", Ui.Dritt)); + } + + private static UIElement Groessen(List g) + { + var p = g.Where(x => x.Zahl("topf_anteil") != null && x.Zahl("betrag_bb") != null) + .Select(x => (x.Zahl("topf_anteil")!.Value, x.Zahl("betrag_bb")!.Value)).ToList(); + if (p.Count == 0) return Ui.Klein("Noch keine Einsätze mit Topfgröße."); + double x0 = Math.Min(0, p.Min(q => q.Item1)), x1 = p.Max(q => q.Item1); + var d = new Diagramm(240) + { + Zeichnen = (c, b, h) => + { + var Y = Diagramm.AchseY(c, b, h, 0, p.Max(q => q.Item2), " bb"); + var spanne = Math.Max(1e-9, x1 - x0); + foreach (var (a, bb) in p) + c.Children.Add(Ort(new Ellipse { Width = 6, Height = 6, Fill = Ui.Pinsel("blau", 0.7) }, + Diagramm.Links + 4 + (b - Diagramm.Links - 8) * (a - x0) / spanne - 3, Y(bb) - 3)); + Diagramm.Beschriftung(c, Format.Prozent(x0), Diagramm.Links + 20, h - Diagramm.Unten + 3); + Diagramm.Beschriftung(c, Format.Prozent(x1), b - 20, h - Diagramm.Unten + 3); + }, + }; + return Ui.Spalte(6, d, Ui.Winzig("x: Anteil am Topf · y: Einsatz in bb", Ui.Dritt)); + } + + private static UIElement Denkzeit(JsonObject? st) + { + var dz = st.Obj("denkzeit"); + var g = new Grid { ColumnSpacing = 8 }; + for (var i = 0; i < 3; i++) g.ColumnDefinitions.Add(new ColumnDefinition()); + g.Children.Add(Teile.Kennzahl("Median", dz.Zahl("median") is double m ? Format.Zahl(m, 1) + " s" : "–")); + g.Children.Add(Teile.Kennzahl("Streuung", dz.Zahl("streuung") is double s ? Format.Zahl(s, 1) + " s" : "–").Spalte(1)); + g.Children.Add(Teile.Kennzahl("VK", Format.Zahl(dz.Zahl("vk"), 2)).Spalte(2)); + var sekunden = st.Objekte("denkzeiten").Select(x => x.Zahl("s")).OfType() + .GroupBy(x => (int)Math.Floor(x)).OrderBy(x => x.Key).ToList(); + var saeulen = new List<(string, double, string)>(); + if (sekunden.Count > 0) + for (var sek = sekunden[0].Key; sek <= sekunden[^1].Key; sek++) + saeulen.Add((sek.ToString(), sekunden.FirstOrDefault(x => x.Key == sek)?.Count() ?? 0, "blau")); + var d = new Diagramm(200) { Zeichnen = (c, b, h) => Diagramm.Saeulen(c, b, h, saeulen, Math.Max(1, saeulen.Count / 10)) }; + return Ui.Spalte(10, g, d, Ui.Winzig("Gedenkzeit, volle Sekunden", Ui.Dritt), + Ui.Klein("Ein VK deutlich über 0 heißt: nicht maschinell gleichmäßig.", true)); + } +} diff --git a/winui/Seiten/Ui.cs b/winui/Seiten/Ui.cs new file mode 100644 index 00000000..185eb0f5 --- /dev/null +++ b/winui/Seiten/Ui.cs @@ -0,0 +1,289 @@ +using Microsoft.UI.Input; +using Microsoft.UI.Text; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Windows.UI; +using Windows.UI.Text; + +namespace Pokerfreak.Cockpit.Seiten; + +/// +/// Bausteine fuer Oberflaeche aus Code, optisch nach der Mac-App (mac/Sources/Cockpit/Bausteine.swift): +/// dunkles Glas, Flaechen in Weiss mit wenig Deckkraft, Kapseln, abgerundete Kacheln, Systemfarben. +/// +public static class Ui +{ + private static Brush Res(string k) => (Brush)Application.Current.Resources[k]; + + /// Farbname der Ansicht ("gruen", "rot", ...; "" = Text) -> Farbe. + public static Color Farbe(string? ton) => ton switch + { + "gruen" => Color.FromArgb(255, 0x30, 0xD1, 0x58), + "rot" => Color.FromArgb(255, 0xFF, 0x45, 0x3A), + "orange" => Color.FromArgb(255, 0xFF, 0x9F, 0x0A), + "gelb" => Color.FromArgb(255, 0xFF, 0xD6, 0x0A), + "blau" => Color.FromArgb(255, 0x0A, 0x84, 0xFF), + "indigo" => Color.FromArgb(255, 0x5E, 0x5C, 0xE6), + "teal" => Color.FromArgb(255, 0x40, 0xC8, 0xE0), + "lila" => Color.FromArgb(255, 0xBF, 0x5A, 0xF2), + "grau" => Color.FromArgb(0x99, 0xEB, 0xEB, 0xF5), // .secondary auf dunkel + _ => Color.FromArgb(255, 0xFF, 0xFF, 0xFF), + }; + + public static Brush Pinsel(string? ton) => new SolidColorBrush(Farbe(ton)); + + /// Die Farbe mit Deckkraft (wie `.opacity(0.14)`). + public static Brush Pinsel(string? ton, double deckkraft) + { + var c = Farbe(ton); + return new SolidColorBrush(Color.FromArgb((byte)(c.A * deckkraft), c.R, c.G, c.B)); + } + + public static Brush Weiss(double deckkraft) => new SolidColorBrush(Color.FromArgb((byte)(255 * deckkraft), 255, 255, 255)); + public static Brush Schwarz(double deckkraft) => new SolidColorBrush(Color.FromArgb((byte)(255 * deckkraft), 0, 0, 0)); + public static Brush Zweit => Pinsel("grau"); + public static Brush Dritt => new SolidColorBrush(Color.FromArgb(0x4D, 0xEB, 0xEB, 0xF5)); // .tertiary + public static Brush Akzent => Pinsel("blau"); + + public static TextBlock Text(string text, double groesse = 14, string? ton = null, bool fett = false, + bool umbruch = false, Brush? pinsel = null, bool zahlen = false) + { + var t = new TextBlock + { + Text = text, + FontSize = groesse, + FontWeight = fett ? FontWeights.SemiBold : FontWeights.Normal, + TextWrapping = umbruch ? TextWrapping.WrapWholeWords : TextWrapping.NoWrap, + TextTrimming = umbruch ? TextTrimming.None : TextTrimming.CharacterEllipsis, + }; + if (zahlen) Microsoft.UI.Xaml.Documents.Typography.SetNumeralAlignment(t, FontNumeralAlignment.Tabular); + if (pinsel != null) t.Foreground = pinsel; + else if (ton != null) t.Foreground = Pinsel(ton); + return t; + } + + /// .caption in .secondary + public static TextBlock Klein(string text, bool umbruch = false) => + Text(text, 12, pinsel: Zweit, umbruch: umbruch); + + /// .caption2 + public static TextBlock Winzig(string text, Brush? pinsel = null, bool fett = false) => + Text(text, 11, pinsel: pinsel ?? Zweit, fett: fett); + + /// Gerundete Zahlenschrift wie `.design(.rounded)` - unter Windows die Variable-Schrift. + public static TextBlock Gross(string text, double groesse, string? ton = null, bool fett = true) + { + var t = Text(text, groesse, ton, fett, zahlen: true); + t.FontFamily = new FontFamily("Segoe UI Variable Display"); + return t; + } + + /// Ein Symbol; ohne Ton erbt es die Textfarbe (kein gesetztes null). + public static FontIcon Zeichen(string glyph, double groesse = 16, string? ton = null) + { + var z = new FontIcon { Glyph = glyph, FontSize = groesse }; + if (ton != null) z.Foreground = Pinsel(ton); + return z; + } + + /// Eine Flaeche wie `.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 14))`. + public static Border Flaeche(UIElement? inhalt, double radius = 14, double weiss = 0.06, double polster = 10) => new() + { + Background = Weiss(weiss), + CornerRadius = new CornerRadius(radius), + Padding = new Thickness(polster), + Child = inhalt, + }; + + /// Eine getoente Flaeche: `.background(farbe.opacity(0.12), in: RoundedRectangle(10))`. + public static Border Getoent(UIElement? inhalt, string ton, double deckkraft = 0.12, double radius = 10, double polster = 10) => new() + { + Background = Pinsel(ton, deckkraft), + CornerRadius = new CornerRadius(radius), + Padding = new Thickness(polster), + Child = inhalt, + }; + + /// Abzeichen: kleiner Text in einer getoenten Kapsel. + public static Border Abzeichen(string text, string ton, string? glyph = null) + { + var inhalt = Reihe(4); + if (glyph != null) inhalt.Children.Add(Zeichen(glyph, 9, ton)); + inhalt.Children.Add(Text(text, 11, ton, fett: true)); + return new Border + { + Background = Pinsel(ton, 0.14), + CornerRadius = new CornerRadius(10), + Padding = new Thickness(7, 1, 7, 2), + VerticalAlignment = VerticalAlignment.Center, + Child = inhalt, + }; + } + + /// Abschnittskopf: "Tische" halbfett in .secondary, daneben ein leiser Hinweis. + public static Grid Abschnitt(string titel, string? hinweis = null, UIElement? rechts = null) + { + var g = new Grid { ColumnSpacing = 6, Margin = new Thickness(0, 4, 0, 0) }; + g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + g.ColumnDefinitions.Add(new ColumnDefinition()); + g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + g.Children.Add(Text(titel, 12, pinsel: Zweit, fett: true)); + if (hinweis != null) g.Children.Add(Winzig(hinweis, Dritt).Spalte(1).Mit(t => t.VerticalAlignment = VerticalAlignment.Bottom)); + if (rechts is FrameworkElement r) g.Children.Add(r.Spalte(2)); + return g; + } + + /// Eine Spielkarte: Rang und Farbe, rot oder hell, auf dunklem Grund mit Rand (KarteAnsicht). + public static Border Spielkarte(string? roh, bool gross = false) + { + var k = Kern.Format.Karte(roh); + var t = new TextBlock + { + Text = k?.Text ?? "?", + FontSize = gross ? 17 : 13, + FontWeight = FontWeights.Bold, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + Foreground = k?.Rot == true ? Pinsel("rot") : Pinsel(""), + }; + return new Border + { + MinWidth = gross ? 34 : 26, + Height = gross ? 44 : 32, + Padding = new Thickness(2, 0, 2, 0), + CornerRadius = new CornerRadius(5), + BorderThickness = new Thickness(1), + BorderBrush = Weiss(0.18), + Background = new SolidColorBrush(Color.FromArgb(255, 0x1C, 0x1C, 0x1E)), + Child = t, + }; + } + + /// Ein leerer Kartenplatz (gestrichelt wie im Minitisch). + public static Border Kartenplatz(double b = 24, double h = 29) => new() + { + Width = b, + Height = h, + CornerRadius = new CornerRadius(5), + BorderThickness = new Thickness(1), + BorderBrush = Weiss(0.18), + }; + + public static StackPanel Reihe(double abstand = 8, params UIElement[] kinder) + { + var s = new StackPanel { Orientation = Orientation.Horizontal, Spacing = abstand }; + foreach (var k in kinder) s.Children.Add(k); + return s; + } + + public static StackPanel Spalte(double abstand = 4, params UIElement[] kinder) + { + var s = new StackPanel { Spacing = abstand }; + foreach (var k in kinder) s.Children.Add(k); + return s; + } + + /// Links etwas, rechts etwas, dazwischen Platz (HStack mit Spacer). + public static Grid Zeile(UIElement links, UIElement? rechts, double abstand = 8) + { + var g = new Grid { ColumnSpacing = abstand }; + g.ColumnDefinitions.Add(new ColumnDefinition()); + g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + g.Children.Add(links); + if (rechts is FrameworkElement r) g.Children.Add(r.Spalte(1)); + return g; + } + + public static Microsoft.UI.Xaml.Shapes.Ellipse Punkt(string ton, double d = 8) => new() + { + Width = d, + Height = d, + Fill = Pinsel(ton), + VerticalAlignment = VerticalAlignment.Center, + }; + + /// Ein schlichter Symbolknopf ohne Rahmen (`.buttonStyle(.borderless)`). + public static Button Symbolknopf(string glyph, string hilfe, Action tun, double groesse = 12, string? ton = "grau") + { + var b = new Button + { + Content = Zeichen(glyph, groesse, ton), + Padding = new Thickness(5), + MinWidth = 0, + MinHeight = 0, + Background = new SolidColorBrush(Colors.Transparent), + BorderThickness = new Thickness(0), + }; + ToolTipService.SetToolTip(b, hilfe); + b.Click += (_, _) => tun(); + return b; + } + + private static class Colors + { + public static Color Transparent => Color.FromArgb(0, 0, 0, 0); + } +} + +/// +/// Eine Flaeche, die man antippen kann: Hover hellt auf, Druck gibt nach (KartenDruck), deaktiviert +/// halb durchsichtig. Ohne die Knopf-Optik von WinUI - so sehen Kacheln und Kapseln aus wie am Mac. +/// +public sealed class Tippflaeche : Grid +{ + private readonly Border _schleier = new() { IsHitTestVisible = false }; + private bool _an = true; + public event Action? Getippt; + + public Tippflaeche(UIElement inhalt, double radius = 10) + { + Children.Add(inhalt); + _schleier.CornerRadius = new CornerRadius(radius); + Children.Add(_schleier); + Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); + PointerEntered += (_, _) => { if (_an) _schleier.Background = Ui.Weiss(0.05); ProtectedCursor = InputSystemCursor.Create(InputSystemCursorShape.Hand); }; + PointerExited += (_, _) => { _schleier.Background = null; Scale = new System.Numerics.Vector3(1); }; + PointerPressed += (_, _) => { if (_an) { _schleier.Background = Ui.Weiss(0.10); Scale = new System.Numerics.Vector3(0.98f); } }; + PointerReleased += (_, _) => { _schleier.Background = _an ? Ui.Weiss(0.05) : null; Scale = new System.Numerics.Vector3(1); }; + Loaded += (_, _) => CenterPoint = new System.Numerics.Vector3((float)ActualWidth / 2, (float)ActualHeight / 2, 0); + SizeChanged += (_, _) => CenterPoint = new System.Numerics.Vector3((float)ActualWidth / 2, (float)ActualHeight / 2, 0); + Tapped += (_, e) => { if (_an) { e.Handled = true; Getippt?.Invoke(); } }; + } + + public bool An + { + get => _an; + set { _an = value; Opacity = value ? 1 : 0.4; } + } +} + +public static class UiErweiterung +{ + public static T Spalte(this T e, int spalte) where T : FrameworkElement + { + Grid.SetColumn(e, spalte); + return e; + } + + public static T Zeile(this T e, int zeile) where T : FrameworkElement + { + Grid.SetRow(e, zeile); + return e; + } + + public static T Mit(this T e, Action tun) + { + tun(e); + return e; + } + + public static Tippflaeche Tippen(this UIElement e, Action tun, double radius = 10, string? hilfe = null) + { + var t = new Tippflaeche(e, radius); + t.Getippt += tun; + if (hilfe != null) ToolTipService.SetToolTip(t, hilfe); + return t; + } +} diff --git a/winui/app.manifest b/winui/app.manifest new file mode 100644 index 00000000..1f71d65d --- /dev/null +++ b/winui/app.manifest @@ -0,0 +1,14 @@ + + + + + + + + + + + PerMonitorV2 + + + diff --git a/winui/nuget.config b/winui/nuget.config new file mode 100644 index 00000000..7440ab84 --- /dev/null +++ b/winui/nuget.config @@ -0,0 +1,7 @@ + + + + + + +