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 00000000..b0e0ffd6
Binary files /dev/null and b/winui/Assets/cockpit.ico differ
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