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 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 21:22:07 +01:00
co-authored by Claude Opus 5.5
parent d369908039
commit 9b33942394
23 changed files with 4664 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
bin/
obj/
*.user
+41
View File
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<Application
x:Class="Pokerfreak.Cockpit.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
RequestedTheme="Dark">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</ResourceDictionary.MergedDictionaries>
<!-- Die Farbnamen der Ansicht ("gruen", "rot", ... sicht/abgeleitet.py). Das Cockpit ist immer
dunkel wie die Mac-App (Leiste: .colorScheme dark); die Toene sind die Systemfarben dort. -->
<SolidColorBrush x:Key="TonGruen" Color="#30D158" />
<SolidColorBrush x:Key="TonRot" Color="#FF453A" />
<SolidColorBrush x:Key="TonOrange" Color="#FF9F0A" />
<SolidColorBrush x:Key="TonGelb" Color="#FFD60A" />
<SolidColorBrush x:Key="TonBlau" Color="#0A84FF" />
<SolidColorBrush x:Key="TonIndigo" Color="#5E5CE6" />
<SolidColorBrush x:Key="TonTeal" Color="#40C8E0" />
<SolidColorBrush x:Key="TonLila" Color="#BF5AF2" />
<!-- Eine Karte wie in den Windows-Einstellungen -->
<Style x:Key="Karte" TargetType="Border">
<Setter Property="Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}" />
<Setter Property="BorderBrush" Value="{ThemeResource CardStrokeColorDefaultBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
<Setter Property="Padding" Value="12" />
</Style>
<Style x:Key="Klein" TargetType="TextBlock" BasedOn="{StaticResource CaptionTextBlockStyle}">
<Setter Property="Foreground" Value="{ThemeResource TextFillColorSecondaryBrush}" />
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
</Style>
<Style x:Key="Abschnitt" TargetType="TextBlock" BasedOn="{StaticResource BodyStrongTextBlockStyle}">
<Setter Property="Margin" Value="2,6,0,2" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
+20
View File
@@ -0,0 +1,20 @@
using Microsoft.UI.Xaml;
namespace Pokerfreak.Cockpit;
/// <summary>Start: ein Fenster, eine Verbindung zum Server (Kern/Verbindung.cs).</summary>
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();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB

+140
View File
@@ -0,0 +1,140 @@
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Nodes;
namespace Pokerfreak.Cockpit.Kern;
/// <summary>
/// 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.
/// </summary>
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<JsonObject> Objekte(this JsonObject? o, string k) =>
o.Liste(k).OfType<JsonObject>();
public static IEnumerable<string> 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<string>(),
JsonValueKind.Number => v.GetValue<double>().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<double>() : null;
public static bool Wahr(this JsonObject? o, string k) =>
o?[k] is JsonValue v && v.GetValueKind() == JsonValueKind.True;
/// <summary>true/false, null wenn das Feld fehlt oder kein Wahrheitswert ist.</summary>
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;
/// <summary>Gleicher Inhalt? (Kacheln nur neu bauen, wenn sich ihr JSON aendert.)</summary>
public static string Abdruck(this JsonNode? n) => n?.ToJsonString() ?? "null";
}
/// <summary>Zahlen und Zeiten, wie die App sie zeigt: deutsch, Strich fuer unbekannt (format.rs).</summary>
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)
: "–";
/// <summary>Achsenzahl: 1200 -> "1,2k", sonst bis eine Nachkommastelle.</summary>
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;
/// <summary>"Qh" -> ("Q♥", rot); "Th" -> "10♥". Unlesbares: null.</summary>
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);
}
}
+232
View File
@@ -0,0 +1,232 @@
using System.Text.Json.Nodes;
using Microsoft.UI.Dispatching;
namespace Pokerfreak.Cockpit.Kern;
/// <summary>
/// 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.
/// </summary>
public sealed class CockpitZustand
{
/// <summary>So lange fuehrt der optimistische Not-Aus (Cockpit.swift `notAusGnade`).</summary>
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);
/// <summary>Bis zur ersten eigenen Eingabe folgt die Wahl dem Plan des Servers.</summary>
public bool Geimpft { get; private set; }
public bool CashFragen { get; set; }
public HashSet<string> Laufend { get; } = new();
public DateTime? NotAusGewollt { get; private set; }
public Rueckmeldung? Meldung { get; private set; }
public bool Pausiert { get; private set; } = Wurzel.Pausiert();
/// <summary>Fotos je Raum (PNG-Bytes vom Server).</summary>
public Dictionary<string, byte[]> 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();
/// <summary>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.</summary>
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;
/// <summary>Eine Eingabe an der Wahl: aendern, zeigen; laeuft der Laeufer, geht der Plan bald hinaus.</summary>
public void Eingabe(Action<Spielplan> tun)
{
tun(Wahl);
Geimpft = true;
var k = Ansicht.Kopf;
if (k.Wahr("laeuft") || k.Zahl("pid") != null)
{
_planTimer.Stop();
_planTimer.Start();
}
Melden();
}
/// <summary>Knoepfe nacheinander an den Server; scheitert einer, folgt keiner mehr.</summary>
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();
}
/// <summary>"/foto/foto-123.png" -> "foto-123.png"; nur harmlose Namen.</summary>
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);
}
/// <summary>Not-Aus: ein Klick haelt sofort an (optimistisch, bis der Server ihn zeigt).</summary>
public void NotAusSetzen()
{
NotAusGewollt = DateTime.Now;
_ = Senden(("not_aus_setzen", null));
Melden();
}
/// <summary>Loesen nur bewusst (Gedrueckthalten am Knopf) - nie aus Versehen wieder scharf.</summary>
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));
}
}
+88
View File
@@ -0,0 +1,88 @@
using System.Text.Json.Nodes;
namespace Pokerfreak.Cockpit.Kern;
/// <summary>
/// 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).
/// </summary>
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;
}
/// <summary>Die Knoepfe von sicht/steuern.py, nacheinander; bricht einer ab, folgt keiner mehr.</summary>
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<string>(),
};
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",
};
/// <summary>Segoe Fluent Icons.</summary>
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 => "",
_ => "",
};
/// <summary>Farbname (Ton) des Zeichens.</summary>
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;
}
+297
View File
@@ -0,0 +1,297 @@
using System.Text.Json.Nodes;
namespace Pokerfreak.Cockpit.Kern;
/// <summary>Was an einem Tisch gespielt wird (lesen/formate.py) - nicht der Modus (Uebung/Cash).</summary>
public enum SpielFormat { Cash, CashPlo, Aof, Bombpot, Turnier, Kpoker, Vip, Freeroll }
public static class Formate
{
public static readonly SpielFormat[] Alle = Enum.GetValues<SpielFormat>();
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<SpielFormat?>().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",
};
/// <summary>Segoe Fluent Icons je Format.</summary>
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 }
/// <summary>
/// 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).
/// </summary>
public sealed class Spielplan
{
public const int Hoechstens = 12;
public Modus Modus = Modus.Uebung;
private readonly SortedDictionary<SpielFormat, int> _formate = new() { [SpielFormat.Cash] = 1 };
public HashSet<SpielFormat> Gemessen = new() { SpielFormat.Cash };
public HashSet<SpielFormat> Spielbar = new() { SpielFormat.Cash, SpielFormat.Aof };
private int? _ziel;
private List<SpielFormat> _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<Spielplan> 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;
/// <summary>Die Fuellfolge: genannte zuerst, dann der Rest in fester Reihenfolge.</summary>
public List<SpielFormat> Folge()
{
var genannt = _reihenfolge.Where(f => Anzahl(f) > 0).ToList();
var folge = new List<SpielFormat>(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<SpielFormat> reihe)
{
var vorgabe = Formate.Alle.Where(reihe.Contains).ToList();
_reihenfolge = reihe.SequenceEqual(vorgabe) ? new() : reihe;
}
/// <summary>kopf.spielplan des Servers -> Spielplan; null, wenn unlesbar.</summary>
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<JsonObject>()
.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;
}
/// <summary>Die Daten fuer spielplan_setzen (betrieb/spielplan.py).</summary>
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;
}
/// <summary>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).</summary>
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<string> { 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<double>(out var va) && y.TryGetValue<double>(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";
}
+176
View File
@@ -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;
/// <summary>Wo der Server steht: 127.0.0.1:8787, sonst --adresse host:port oder POKERFREAK_ADRESSE.</summary>
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);
}
}
/// <summary>Was ein Knopf des Servers zurueckmeldet ({ok, text}, auch ueber den WebSocket).</summary>
public sealed record Rueckmeldung(string Aktion, bool Ok, string Text, string? Raum = null, string? Bild = null,
JsonObject? Roh = null);
/// <summary>
/// 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.
/// </summary>
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<Ansicht>? Aktualisiert;
public event Action<bool, string>? Zustand; // verbunden?, Grund
public event Action<Rueckmeldung>? 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<string>();
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"));
/// <summary>Ein Knopf des Servers (POST /api/steuern {aktion, raum?, daten?}); wirft nie.</summary>
public async Task<Rueckmeldung> 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}");
}
}
/// <summary>Ein Bild vom Server (/foto/&lt;name&gt;.png) als Bytes; null bei Fehler.</summary>
public async Task<byte[]?> 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();
}
}
+83
View File
@@ -0,0 +1,83 @@
namespace Pokerfreak.Cockpit.Kern;
/// <summary>
/// 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).
/// </summary>
public static class Wurzel
{
/// <summary>Der Projektordner: POKERFREAK_WURZEL, sonst aufwaerts vom Programm bis zu einem Ordner mit lesen/ und sicht/.</summary>
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<string> 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);
/// <summary>Pause setzen oder loesen; die Rueckmeldung sagt, ob es geklappt hat.</summary>
public static Rueckmeldung PauseSetzen(bool an)
{
var pfade = PausePfade().ToList();
var fehler = new List<string>();
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");
/// <summary>Nur ein ausdrueckliches "echt" gibt Echtgeld, alles andere Uebung.</summary>
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 { }
}
}
+57
View File
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="Pokerfreak.Cockpit.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Pokerfreak Cockpit">
<Window.SystemBackdrop>
<DesktopAcrylicBackdrop />
</Window.SystemBackdrop>
<!-- Wie die Leiste der Mac-App (Wurzel.swift): tiefes Glas mit einem Hauch Farbe - blau in Uebung,
rot in Echtgeld -, Kopf oben, eine Ansicht, unten die Reiter. -->
<Grid x:Name="Wurzel" BorderThickness="1">
<Grid.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#EB1A2130" Offset="0" />
<GradientStop Color="#F50D121A" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Das Gluehen oben (RadialGradient im Hintergrund der Mac-Leiste) -->
<Rectangle Grid.RowSpan="4" IsHitTestVisible="False">
<Rectangle.Fill>
<RadialGradientBrush Center="0.5,0" GradientOrigin="0.5,0" RadiusX="0.75" RadiusY="0.38">
<GradientStop x:Name="GluehenFarbe" Color="#240A84FF" Offset="0" />
<GradientStop x:Name="GluehenRand" Color="#000A84FF" Offset="1" />
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<!-- Eigene Titelleiste: Verbindung, rechts Klon, Laufzeit, Zahnrad; daneben die Systemtasten -->
<Grid x:Name="Titelleiste" Height="40" Padding="14,0,138,0" ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Spacing="7" VerticalAlignment="Center">
<Ellipse x:Name="VerbindungPunkt" Width="7" Height="7" Fill="#99EBEBF5" />
<TextBlock Text="Cockpit" FontSize="12" FontWeight="SemiBold" Foreground="#99EBEBF5" />
<TextBlock x:Name="VerbindungText" FontSize="11" Foreground="#4DEBEBF5"
TextTrimming="CharacterEllipsis" VerticalAlignment="Center" />
</StackPanel>
<StackPanel x:Name="KopfRechts" Grid.Column="1" Orientation="Horizontal" Spacing="8" VerticalAlignment="Center" />
</Grid>
<ContentControl x:Name="Inhalt" Grid.Row="1" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />
<Rectangle Grid.Row="2" Height="1" Fill="#1FFFFFFF" />
<Grid x:Name="Reiterleiste" Grid.Row="3" Padding="6,4,6,4" ColumnSpacing="2" />
</Grid>
</Window>
+143
View File
@@ -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;
/// <summary>
/// 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.
/// </summary>
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<string, ISeite> _seiten = new();
private readonly Dictionary<string, (FontIcon Zeichen, TextBlock Text)> _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();
}
}
/// <summary>Ein Reiter: zeichnet sich aus dem Zustand neu; `Takt` jede Sekunde fuer laufende Zeit.</summary>
public interface ISeite
{
void Zeichnen();
void Takt() { }
}
+30
View File
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- Das native Windows-Cockpit (WinUI 3, Windows App SDK, unpaketiert). Nur Anzeige und Befehle:
die Daten kommen vom Python-Server sicht/start.py (WebSocket /ws, POST /api/steuern). -->
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<RootNamespace>Pokerfreak.Cockpit</RootNamespace>
<AssemblyName>Pokerfreak.Cockpit</AssemblyName>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x64</Platforms>
<PlatformTarget>x64</PlatformTarget>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<UseWinUI>true</UseWinUI>
<WindowsPackageType>None</WindowsPackageType>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<SelfContained>true</SelfContained>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<EnableMsixTooling>true</EnableMsixTooling>
<ApplicationIcon>Assets/cockpit.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.8.260921001" />
</ItemGroup>
<ItemGroup>
<Content Update="Assets/cockpit.ico" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
+328
View File
@@ -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;
/// <summary>Kleine Merkzettel des Fensters (gewaehlte Reiterteile, Filter): eine Zeile je Schluessel in
/// %APPDATA%\Pokerfreak\cockpit-winui.txt - wie `@AppStorage` der Mac-App.</summary>
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<string>();
zeilen.Add($"{k}={v}");
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Datei)!);
File.WriteAllLines(Datei, zeilen);
}
catch { }
}
}
/// <summary>
/// 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).
/// </summary>
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<int>? 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;
}
}
}
/// <summary>Ein Menue wie SwiftUI `Menu(titel)`: kleine Kapsel mit Pfeil, "alle" setzt zurueck.</summary>
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<string>());
}
public void Setzen(string? w)
{
Wahl = w;
_knopf.Content = w ?? _titel;
_knopf.Foreground = w == null ? Ui.Zweit : Ui.Akzent;
}
public void Werte(IEnumerable<string> 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);
}
}
/// <summary>Bausteine der Auswertungsseiten (Bausteine.swift `Kennzahl`, `Leer`).</summary>
public static class Teile
{
/// <summary>Eine Kennzahl: Titel klein, Wert gross, auf heller Flaeche.</summary>
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);
}
/// <summary>Platzhalter mittig: Symbol, Titel, Satz.</summary>
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;
}
/// <summary>Ergebnisfarbe wie `Farben.ergebnis`: gruen &gt; 0, rot &lt; 0, sonst Text.</summary>
public static string? Ton(double? x) => x is double v ? (v > 0 ? "gruen" : v < 0 ? "rot" : null) : null;
/// <summary>Kleine Textknopf-Kapsel (`.buttonStyle(.borderless)` bzw. `.borderedProminent`).</summary>
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);
}
}
/// <summary>
/// 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.
/// </summary>
public sealed class Diagramm : Grid
{
private readonly Canvas _leinwand = new();
private Action<Canvas, double, double>? _zeichnen;
public Diagramm(double hoehe = 220)
{
Height = hoehe;
Children.Add(_leinwand);
SizeChanged += (_, _) => Neu();
}
public Action<Canvas, double, double>? 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;
/// <summary>Achse y mit 4 Gitterlinien von lo bis hi; gibt die Abbildung Wert -> y zurueck.</summary>
public static Func<double, double> 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);
}
/// <summary>Linie mit Flaeche darunter (LineMark + AreaMark in Tint 12 %).</summary>
public static void Linie(Canvas c, double b, double h, IList<(double X, double Y)> punkte, string ton = "blau",
Func<double, string>? 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);
}
}
/// <summary>Saeulen (BarMark): Werte mit Farbe und Beschriftung unten.</summary>
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));
}
}
}
+603
View File
@@ -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;
/// <summary>
/// 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.
/// </summary>
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;
}
/// <summary>Eine Instrument-Kachel (Spielplan.swift `Kachel`): Titel klein, Inhalt 30 hoch, Fuss klein.</summary>
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);
}
/// <summary>Ein Stepper wie am Mac: zwei kleine Knoepfe in einer Kapsel.</summary>
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;
}
/// <summary>"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.</summary>
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;
}
}
/// <summary>Not-Aus (Wurzel.swift `NotAusKnopf`): runder roter Knopf, ein Klick haelt sofort an.</summary>
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");
}
}
/// <summary>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.</summary>
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",
_ => "",
};
}
+279
View File
@@ -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;
/// <summary>
/// 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.
/// </summary>
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);
}
/// <summary>Eine Ampel-Pille: gruen = sauber, sonst die Warnfarbe; das Symbol traegt die Bedeutung.</summary>
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<UIElement>();
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;
}
/// <summary>Ein Regler 0..max in Schritten zu 0,05; Raten als Prozent, Faktoren mit zwei Stellen.</summary>
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;
}
}
+258
View File
@@ -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;
/// <summary>
/// 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).
/// </summary>
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<string, (string Abdruck, UIElement Zeile)> _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;
/// <summary>Die Filterregel von `filtern()` (sicht/ansicht.py).</summary>
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<string>();
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;
}
/// <summary>Aktionstext.mitBetrag: "Raise" + " 3 bb".</summary>
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;
}
/// <summary>Kleine Karten, dann das Board etwas abgesetzt (Kartenzeile in Bausteine.swift).</summary>
public static StackPanel Kartenzeile(IList<string> karten, IList<string> 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;
}
/// <summary>Der Klick einer Entscheidung als Zeichen (bestaetigt, unbestaetigt, ausgesetzt, gestoppt, Schatten).</summary>
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;
}
}
+955
View File
@@ -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;
/// <summary>
/// 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.
/// </summary>
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<string, TischKachel> _kachelVon = new();
private readonly Dictionary<ContentControl, string> _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();
}
/// <summary>Setzt den Inhalt nur, wenn sich der Abdruck geaendert hat.</summary>
private void Block(ContentControl c, JsonNode? daten, Func<UIElement?> bauen)
{
var a = daten.Abdruck();
if (_abdruck.TryGetValue(c, out var alt) && alt == a) return;
_abdruck[c] = a;
var e = bauen();
c.Content = e;
c.Visibility = e == null ? Visibility.Collapsed : Visibility.Visible;
}
public void Zeichnen()
{
var a = _z.Ansicht;
var live = a.Sitzen.Obj("live");
int anzahl = (int)(live.Zahl("anzahl") ?? 0);
_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 ------------------------------------------------------------------------
/// <summary>Das Ergebnis der laufenden (sonst letzten) Sitzung gross, neun Kennzahlen, Abstand zum Stop.</summary>
private static UIElement? Sitzungsleiste(JsonObject? s)
{
if (s == null || !s.Wahr("da")) return null;
var kopf = Ui.Zeile(Ui.Reihe(6, Ui.Punkt(s.Wahr("laeuft") ? "gruen" : "grau", 7), Ui.Text(s.T("titel"), 12, pinsel: Ui.Zweit, fett: true)),
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);
}
/// <summary>Ein Balken wie `ProgressView(value:)`: Kapsel in .quaternary, gefuellt in Farbe.</summary>
internal static Grid Balken(double anteil, string ton, double hoehe = 6, bool vonRechts = false)
{
var g = new Grid { Height = hoehe };
g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(Math.Clamp(anteil, 0, 1), GridUnitType.Star) });
g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1 - Math.Clamp(anteil, 0, 1), GridUnitType.Star) });
g.Children.Add(new Border { Background = Ui.Weiss(0.10), CornerRadius = new CornerRadius(hoehe / 2) }.Mit(b => Grid.SetColumnSpan(b, 2)));
var fuell = new Border { Background = Ui.Pinsel(ton, 0.85), CornerRadius = new CornerRadius(hoehe / 2) };
if (vonRechts) { g.FlowDirection = FlowDirection.RightToLeft; }
g.Children.Add(fuell);
return g;
}
// ---- Alle Tische (Chips) --------------------------------------------------------------------
private UIElement? Chips(List<JsonObject> 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<JsonObject> kacheln)
{
var folge = string.Join("|", kacheln.Select(k => k.T("raum")));
if (folge != _kachelFolge)
{
_kachelFolge = folge;
var neu = new Dictionary<string, TischKachel>();
_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 ------------------------------------------------------------------------
/// <summary>Je fehlenden Tisch eine gestrichelte Such-Kachel: die Luecke ist Absicht, kein Haenger.</summary>
private static UIElement? Such(JsonObject? live)
{
int n = (int)(live.Zahl("such") ?? 0);
if (live == null || n <= 0) return null;
var spalte = Ui.Spalte(10);
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 = { "", "", "", "", "" };
/// <summary>Sitzt der Laeufer nirgends: fuenf Schritte als Leiste, "Als Naechstes", die letzte Sitzung.</summary>
private static UIElement? Bereit(JsonObject? b)
{
if (b == null) return null;
var schritte = b.Objekte("schritte").ToList();
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;
}
/// <summary>Die letzte Sitzung (Ueberblick.swift `SitzungsKarte`): Ergebnis gross, daneben Tisch/Haende/Dauer, rechts warum sie endete.</summary>
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<JsonObject>())
{
var block = Ui.Spalte(5, Ui.Zeile(Ui.Winzig(b.T("beginn"), fett: true), Ui.Text(b.T("summe"), 11, b.T("summe_ton"), fett: true, zahlen: true)));
foreach (var z in b.Objekte("zeilen"))
{
var g = new Grid { ColumnSpacing = 8 };
g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(34) });
g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
g.ColumnDefinitions.Add(new ColumnDefinition());
g.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
g.Children.Add(Ui.Winzig(z.T("zeit"), Ui.Dritt).Mit(t => t.VerticalAlignment = VerticalAlignment.Center));
var karten = Ui.Reihe(2);
foreach (var k in z.Texte("karten")) karten.Children.Add(Ui.Spielkarte(k).Mit(c => { c.MinWidth = 20; c.Height = 24; ((TextBlock)c.Child).FontSize = 10.5; }));
g.Children.Add(karten.Spalte(1));
var schritte = new TextBlock { FontSize = 11.5, TextTrimming = TextTrimming.CharacterEllipsis, VerticalAlignment = VerticalAlignment.Center };
bool erst = true;
foreach (var s in z.Objekte("schritte"))
{
if (!erst) schritte.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run { Text = " › ", Foreground = Ui.Dritt });
erst = false;
schritte.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run { Text = s.T("text"), Foreground = Ui.Pinsel(s.T("ton")) });
}
g.Children.Add(schritte.Spalte(2));
g.Children.Add(Ui.Text(z.T("ergebnis"), 11.5, z.T("ton"), fett: true, zahlen: true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center).Spalte(3));
ToolTipService.SetToolTip(g, z.T("raum"));
block.Children.Add(g);
}
inhalt.Children.Add(block);
}
if (bloecke.Count == 0) inhalt.Children.Add(Ui.Klein("Noch keine Hand in diesem Lauf."));
_feed.Inhalt = Ui.Flaeche(inhalt, 14, 0.05, 12);
}
}
/// <summary>Eine Werkzeug-Kachel (Tische.swift `TischLeiste`): Symbol ueber kleinem Namen, 44 hoch.</summary>
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;
}
}
/// <summary>Ein einklappbarer Abschnitt (Tische.swift `EinklappAbschnitt`): Symbol, Titel, Hinweis, Chevron;
/// der Zustand bleibt je Schluessel ueber Neustarts (lokale Einstellungen).</summary>
public sealed class Einklappen : UserControl
{
private readonly ContentControl _inhalt = new() { HorizontalContentAlignment = HorizontalAlignment.Stretch };
private readonly FontIcon _chevron = Ui.Zeichen("", 9);
private readonly TextBlock _hinweis = Ui.Winzig("", Ui.Dritt);
private readonly string _schluessel;
private bool _offen;
public Einklappen(string titel, string glyph, string schluessel, bool vorgabe)
{
_schluessel = schluessel;
_offen = Gemerkt(schluessel) ?? vorgabe;
_chevron.Foreground = Ui.Dritt;
var kopf = new Grid { ColumnSpacing = 6, Padding = new Thickness(0, 4, 0, 2) };
kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(14) });
kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
kopf.ColumnDefinitions.Add(new ColumnDefinition());
kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
kopf.Children.Add(Ui.Zeichen(glyph, 10, "grau"));
kopf.Children.Add(Ui.Text(titel, 12, pinsel: Ui.Zweit, fett: true).Spalte(1));
kopf.Children.Add(_hinweis.Spalte(2).Mit(t => t.VerticalAlignment = VerticalAlignment.Center));
kopf.Children.Add(_chevron.Spalte(3));
var tipp = kopf.Tippen(() =>
{
_offen = !_offen;
Merken(_schluessel, _offen);
Zeigen();
}, 6);
Content = Ui.Spalte(8, tipp, _inhalt);
Zeigen();
}
public string Hinweis { set => _hinweis.Text = value; }
public UIElement? Inhalt { set => _inhalt.Content = value; }
private void Zeigen()
{
_chevron.Glyph = _offen ? "" : "";
_inhalt.Visibility = _offen ? Visibility.Visible : Visibility.Collapsed;
}
private static string Datei => System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Pokerfreak", "cockpit-winui.txt");
private static bool? Gemerkt(string k)
{
try
{
foreach (var z in File.ReadAllLines(Datei))
if (z.StartsWith(k + "=")) return z.EndsWith("=1");
}
catch { }
return null;
}
private static void Merken(string k, bool an)
{
try
{
var zeilen = File.Exists(Datei) ? File.ReadAllLines(Datei).Where(z => !z.StartsWith(k + "=")).ToList() : new List<string>();
zeilen.Add($"{k}={(an ? 1 : 0)}");
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Datei)!);
File.WriteAllLines(Datei, zeilen);
}
catch { }
}
}
/// <summary>
/// Eine Tischkachel (Tische.swift `KachelAnsicht`): Klick holt den Tisch nach vorn. Kopf mit Name,
/// Zustand, Netto, Foto und Schliessen; Modus; Minitisch; deine Karten gross mit der Entscheidung;
/// Urteil und Gegner; Platzzeile; Foto. Orange umrandet, solange ein Zug offen ist.
/// </summary>
public sealed class TischKachel : UserControl
{
private readonly CockpitZustand _z;
private readonly string _raum;
private readonly ContentControl _inhalt = new() { HorizontalContentAlignment = HorizontalAlignment.Stretch };
private readonly Image _foto = new() { MaxHeight = 260, Stretch = Stretch.Uniform, Visibility = Visibility.Collapsed };
private readonly Border _rahmen;
private readonly List<ZugRing> _ringe = new();
private readonly HashSet<string> _gegnerOffen = new();
private string _abdruck = "";
private byte[]? _fotoDa;
private JsonObject? _zug, _letzt;
public TischKachel(CockpitZustand z, string raum)
{
_z = z;
_raum = raum;
_rahmen = new Border
{
Background = Ui.Weiss(0.05),
CornerRadius = new CornerRadius(16),
BorderThickness = new Thickness(1.5),
Padding = new Thickness(10),
Child = Ui.Spalte(7, _inhalt, new Border { CornerRadius = new CornerRadius(8), Child = _foto }),
};
Content = _rahmen.Tippen(() => _ = _z.SendenRaum(_raum, ("tische_vorn", null)), 16, $"Klick: {raum} nach vorn holen");
}
public void Setzen(JsonObject k, byte[]? foto)
{
if (!ReferenceEquals(foto, _fotoDa))
{
_fotoDa = foto;
if (foto != null) _ = FotoZeigen(foto);
}
var a = k.Abdruck();
if (a == _abdruck) return;
_abdruck = a;
_letzt = k;
_zug = k.Obj("zug");
_rahmen.BorderBrush = k.Wahr("zug_offen") ? Ui.Pinsel("orange") : null;
_ringe.Clear();
_inhalt.Content = Bauen(k);
Takt();
}
private async Task FotoZeigen(byte[] png)
{
var bild = new BitmapImage();
using var strom = new Windows.Storage.Streams.InMemoryRandomAccessStream();
await strom.WriteAsync(png.AsBuffer());
strom.Seek(0);
await bild.SetSourceAsync(strom);
_foto.Source = bild;
_foto.Visibility = Visibility.Visible;
}
/// <summary>Countdown des offenen Zugs (der Server schickt nur `bis` und `frist_s`).</summary>
public void Takt()
{
double? anteil = null, rest = null;
if (_zug.Wahr("offen") && _zug.Zahl("bis") is double bis)
{
rest = Math.Max(0, bis - Format.Jetzt());
var ganz = _zug.Zahl("frist_s") is double f && f > 0 ? f : Math.Max(rest.Value, 1);
anteil = Math.Clamp(rest.Value / ganz, 0, 1);
}
foreach (var r in _ringe) r.Setzen(anteil, rest);
}
private UIElement Bauen(JsonObject k)
{
var teile = Ui.Spalte(7);
// Kopf: Name, Zustand, Netto, Foto, Schliessen
var kopf = new Grid { ColumnSpacing = 6 };
kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
kopf.ColumnDefinitions.Add(new ColumnDefinition());
kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
var name = Ui.Reihe(6, Ui.Text(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);
}
/// <summary>Der Modus des Tisches (ModusLeiste.swift): Chip als Kapsel, Text, Lage, Spur zum Geld.</summary>
private static UIElement Modus(JsonObject m)
{
string ton = m.T("chip_ton");
string art = m.T("art");
string glyph = art switch { "turnier" => "", "kpoker" => "", _ => "" };
var chip = Ui.Abzeichen(m.T("chip"), ton, glyph);
if (art == "kpoker")
{
var zeile = Ui.Reihe(6, chip);
foreach (var t in m.Texte("tasten"))
zeile.Children.Add(new Border
{
Padding = new Thickness(6, 1, 6, 2), CornerRadius = new CornerRadius(5), BorderThickness = new Thickness(1),
BorderBrush = Ui.Weiss(0.15), Background = Ui.Weiss(0.08), Child = Ui.Text(t, 11, fett: true), VerticalAlignment = VerticalAlignment.Center,
});
return Ui.Zeile(zeile, Ui.Reihe(4, Ui.Zeichen("", 10, "grau"), Ui.Text(m.T("uhr"), 11, "grau", fett: true, zahlen: true)));
}
var oben = Ui.Zeile(Ui.Reihe(6, chip, Ui.Klein(m.T("text")).Mit(t => t.VerticalAlignment = VerticalAlignment.Center)),
m.Text("lage") is { Length: > 0 } lage ? Ui.Abzeichen(lage, m.T("lage_ton"), "") : null);
if (m.Obj("spur") is not { } spur) return oben;
string spurTon = m.T("lage_ton") == "gruen" ? "gruen" : "indigo";
UIElement band;
if (spur["striche"] is JsonArray striche)
{
var g = new Grid { ColumnSpacing = 2, Height = 6 };
int i = 0;
foreach (var s in striche)
{
g.ColumnDefinitions.Add(new ColumnDefinition());
bool voll = s is JsonValue v && v.TryGetValue<bool>(out var b) && b;
g.Children.Add(new Border
{
CornerRadius = new CornerRadius(3),
Background = voll ? Ui.Pinsel(spurTon, 0.75) : null,
BorderBrush = voll ? null : m.T("lage_ton") == "orange" ? Ui.Pinsel("orange") : Ui.Zweit,
BorderThickness = new Thickness(voll ? 0 : 1),
}.Spalte(i++));
}
band = g;
}
else band = LiveTeil.Balken(spur.Zahl("anteil") ?? 0, spurTon, 6);
var unten = Ui.Zeile(band, Ui.Winzig(spur.T("text")));
((FrameworkElement)band).VerticalAlignment = VerticalAlignment.Center;
return Ui.Spalte(5, oben, unten);
}
/// <summary>Der Minitisch (Tischbild.swift `MiniTisch`): Filz-Oval mit Bande, Board in fuenf Plaetzen und
/// Topf in der Mitte, die Plaetze an (ux, uy) - dein Platz unten mit dem Countdown-Ring.</summary>
private UIElement Minitisch(JsonObject k)
{
bool mitTisch = k.Wahr("mit_tisch");
double B = 380, H = mitTisch ? 220 : 130;
double rx = B / 2 - (mitTisch ? 40 : 22), ry = H / 2 - (mitTisch ? 26 : 20);
double mx = B / 2, my = H / 2 - 6;
var flaeche = new Canvas { Width = B, Height = H };
var filz = new Ellipse
{
Width = rx * 2 + 16, Height = ry * 2 + 14,
Fill = new RadialGradientBrush
{
GradientStops =
{
new GradientStop { Color = Color.FromArgb(255, 20, 115, 77), Offset = 0 },
new GradientStop { Color = Color.FromArgb(255, 8, 64, 43), Offset = 1 },
},
},
Stroke = new SolidColorBrush(Color.FromArgb(255, 92, 61, 33)),
StrokeThickness = 5,
};
Canvas.SetLeft(filz, mx - filz.Width / 2);
Canvas.SetTop(filz, my - filz.Height / 2);
flaeche.Children.Add(filz);
var mitte = Ui.Spalte(5);
var board = Ui.Reihe(3);
var karten = k.Texte("board").Take(5).ToList();
for (int i = 0; i < 5; i++)
board.Children.Add(i < karten.Count
? Ui.Spielkarte(karten[i]).Mit(c => { c.MinWidth = 24; c.Width = 24; c.Height = 29; ((TextBlock)c.Child).FontSize = 11.5; })
: Ui.Kartenplatz());
board.HorizontalAlignment = HorizontalAlignment.Center;
mitte.Children.Add(board);
if (k.Text("topf") is { Length: > 0 } t)
mitte.Children.Add(new Border
{
Background = Ui.Schwarz(0.35), CornerRadius = new CornerRadius(10), Padding = new Thickness(8, 2, 8, 2),
HorizontalAlignment = HorizontalAlignment.Center,
Child = Ui.Text(t, 11.5, "", fett: true, zahlen: true),
});
Mittig(flaeche, mitte, mx, my, 200);
foreach (var s in k.Objekte("sitze"))
{
double x = mx + (s.Zahl("ux") ?? 0) * rx, y = my + (s.Zahl("uy") ?? 0) * ry;
FrameworkElement platz;
if (s.Wahr("frei"))
{
if (s.Wahr("ich")) platz = EigenerPlatz();
else platz = new Ellipse
{
Width = mitTisch ? 12 : 16, Height = mitTisch ? 12 : 16,
Fill = new SolidColorBrush(Color.FromArgb(mitTisch ? (byte)128 : (byte)255, 36, 48, 64)),
Stroke = mitTisch ? null : Ui.Weiss(0.12),
};
}
else platz = Schild(s);
Mittig(flaeche, platz, x, y, 80);
}
return new Viewbox { Child = flaeche, Stretch = Stretch.Uniform, StretchDirection = StretchDirection.Both };
}
private ZugRing EigenerPlatz(double d = 26)
{
var r = new ZugRing(d);
_ringe.Add(r);
return r;
}
/// <summary>Ein Platz wie am Tisch (SitzSchild): Rolle, Name, Stack gelb, BB klein, letzte Aktion; der Rand
/// in der Farbe des Stils; wer aussitzt, ist blass; dein Platz blau mit Countdown-Ring.</summary>
private FrameworkElement Schild(JsonObject s)
{
bool ich = s.Wahr("ich");
var name = Ui.Reihe(2);
if (ich) name.Children.Add(EigenerPlatz(16));
if (s.Text("rolle") is { Length: > 0 } r)
{
bool d = r == "D";
name.Children.Add(new Border
{
Background = d ? Ui.Pinsel("") : Ui.Pinsel("blau", 0.8), CornerRadius = new CornerRadius(5), Padding = new Thickness(3, 0, 3, 1),
VerticalAlignment = VerticalAlignment.Center,
Child = Ui.Text(r, 7.5, pinsel: d ? Ui.Schwarz(1) : Ui.Pinsel(""), fett: true),
});
}
name.Children.Add(Ui.Text(s.T("name"), 9, fett: true).Mit(t => t.MaxWidth = 56));
var spalte = Ui.Spalte(0, name,
Ui.Text(s.T("stack"), 10, pinsel: Ui.Pinsel("gelb", 0.9), fett: true, zahlen: true).Mit(t => t.HorizontalAlignment = HorizontalAlignment.Center));
if (s.Text("stack_bb") is { Length: > 0 } sb)
spalte.Children.Add(Ui.Text(sb, 7.5, pinsel: Ui.Weiss(0.55), zahlen: true).Mit(t => t.HorizontalAlignment = HorizontalAlignment.Center));
if (s.Text("aktion") is { Length: > 0 } a)
spalte.Children.Add(Ui.Text(a, 8, s.T("aktion_ton"), fett: true).Mit(t => t.HorizontalAlignment = HorizontalAlignment.Center));
name.HorizontalAlignment = HorizontalAlignment.Center;
string stil = s.T("stil_ton");
var schild = new Border
{
Background = ich ? Ui.Pinsel("blau", 0.35) : Ui.Schwarz(0.5),
BorderBrush = stil != "" ? Ui.Pinsel(stil, 0.9) : null,
BorderThickness = new Thickness(stil != "" ? 1.5 : 0),
CornerRadius = new CornerRadius(6),
Padding = new Thickness(4, 2, 4, 2),
MaxWidth = 80,
Opacity = s.Wahr("draussen") ? 0.45 : 1,
Child = spalte,
};
if (s.Text("stil_kuerzel") is not { Length: > 0 } kz) return schild;
var huelle = new Grid();
huelle.Children.Add(schild);
huelle.Children.Add(new Border
{
Background = Ui.Pinsel(stil), CornerRadius = new CornerRadius(4), Padding = new Thickness(2, 0, 2, 0),
HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(0, -4, -4, 0),
Child = Ui.Text(kz, 6.5, pinsel: Ui.Schwarz(1), fett: true),
});
return huelle;
}
/// <summary>Legt ein Element mit seiner Mitte auf (x, y).</summary>
private static void Mittig(Canvas c, FrameworkElement e, double x, double y, double breite)
{
e.Measure(new Windows.Foundation.Size(breite, 200));
var g = e.DesiredSize;
Canvas.SetLeft(e, x - g.Width / 2);
Canvas.SetTop(e, y - g.Height / 2);
c.Children.Add(e);
}
/// <summary>Ein Gegner als Karte (Gegner.swift `GegnerKarte`): Name, Stack, Stil-Abzeichen, Fold-Chance,
/// Vertrauen, der Satz des Kerns; angetippt alle Werte und die Stichprobe.</summary>
private UIElement Gegner(JsonObject s)
{
string name = s.T("name");
bool offen = _gegnerOffen.Contains(name);
var kopfZeile = Ui.Reihe(6);
if (s.Text("rolle") is { Length: > 0 } r)
kopfZeile.Children.Add(new Border
{
Background = r == "D" ? Ui.Pinsel("") : Ui.Pinsel("blau", 0.8), CornerRadius = new CornerRadius(5), Padding = new Thickness(3, 0, 3, 1),
VerticalAlignment = VerticalAlignment.Center, Child = Ui.Text(r, 8, pinsel: r == "D" ? Ui.Schwarz(1) : Ui.Pinsel(""), fett: true),
});
kopfZeile.Children.Add(Ui.Text(name, 12, fett: true));
var kopf = Ui.Zeile(kopfZeile, Ui.Reihe(6, Ui.Text(s.T("stack"), 12, pinsel: Ui.Pinsel("gelb", 0.9), fett: true, zahlen: true),
Ui.Zeichen(offen ? "" : "", 9).Mit(z => z.Foreground = Ui.Dritt)));
var teile = Ui.Spalte(4, kopf);
if (s.Wahr("geschaetzt"))
{
var vt = s.T("vertrauen_ton");
var vertrauen = Ui.Reihe(3,
new Grid { Width = 22, Height = 4, VerticalAlignment = VerticalAlignment.Center }.Mit(g =>
{
g.Children.Add(new Border { Background = Ui.Weiss(0.12), CornerRadius = new CornerRadius(2) });
g.Children.Add(new Border { Background = Ui.Pinsel(vt), CornerRadius = new CornerRadius(2), Width = 22 * (s.Zahl("vertrauen") ?? 0), HorizontalAlignment = HorizontalAlignment.Left });
}),
Ui.Text(s.T("vertrauen_text"), 9, vt, fett: true));
var zeile = Ui.Reihe(8, Ui.Abzeichen(s.T("stil"), s.T("stil_ton")));
if (s.Text("fold") is { Length: > 0 } f)
zeile.Children.Add(Ui.Reihe(3, Ui.Zeichen("", 9, "grau"), Ui.Winzig(f)).Mit(x => x.VerticalAlignment = VerticalAlignment.Center));
teile.Children.Add(Ui.Zeile(zeile, vertrauen.Mit(v => v.VerticalAlignment = VerticalAlignment.Center)));
}
teile.Children.Add(Ui.Text(s.T("satz"), 11, pinsel: s.Wahr("satz_leise") ? Ui.Dritt : Ui.Weiss(0.85), umbruch: true));
var werte = s.Objekte("werte").ToList();
if (offen && werte.Count > 0)
{
var g = new Grid { ColumnSpacing = 6, RowSpacing = 4 };
for (int i = 0; i < 4; i++) g.ColumnDefinitions.Add(new ColumnDefinition());
int n = 0;
foreach (var w in werte)
{
if (n % 4 == 0) g.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
var c = Ui.Spalte(0, Ui.Text(w.T("name"), 9, "grau"), Ui.Text(w.T("wert"), 11, fett: true, zahlen: true));
Grid.SetRow(c, n / 4);
Grid.SetColumn(c, n % 4);
g.Children.Add(c);
n++;
}
teile.Children.Add(g);
teile.Children.Add(Ui.Text(s.T("stichprobe"), 9, pinsel: Ui.Dritt, umbruch: true));
}
var karte = new Border
{
Background = Ui.Weiss(0.05), CornerRadius = new CornerRadius(10), Padding = new Thickness(8),
BorderBrush = s.Wahr("geschaetzt") ? Ui.Pinsel(s.T("stil_ton"), 0.35) : null, BorderThickness = new Thickness(1),
Opacity = s.Wahr("draussen") ? 0.55 : 1, Child = teile,
};
return karte.Tippen(() =>
{
if (!_gegnerOffen.Remove(name)) _gegnerOffen.Add(name);
if (_letzt == null) return;
_ringe.Clear();
_inhalt.Content = Bauen(_letzt);
Takt();
}, 10);
}
}
/// <summary>Der eigene Platz (Tischbild.swift `EigenerPlatz`): ohne Zug ein Kreis mit Person, mit Zug ein Ring
/// mit der Restzeit - gruen, unter der Haelfte orange, unter einem Viertel rot.</summary>
public sealed class ZugRing : Grid
{
private readonly ProgressRing _ring = new() { IsIndeterminate = false, Minimum = 0, Maximum = 1 };
private readonly TextBlock _zahl = Ui.Text("", 10, "", fett: true, zahlen: true);
private readonly FontIcon _person = Ui.Zeichen("", 9);
private readonly Ellipse _rand = new() { Stroke = Ui.Weiss(0.35), StrokeThickness = 1.5 };
public ZugRing(double d)
{
Width = d;
Height = d;
Children.Add(new Ellipse { Fill = new SolidColorBrush(Color.FromArgb(255, 26, 33, 46)) });
Children.Add(_rand);
_ring.Width = d;
_ring.Height = d;
Children.Add(_ring);
_person.Foreground = Ui.Weiss(0.7);
_zahl.FontSize = d * 0.4;
foreach (var e in new FrameworkElement[] { _person, _zahl }) { e.HorizontalAlignment = HorizontalAlignment.Center; e.VerticalAlignment = VerticalAlignment.Center; Children.Add(e); }
Setzen(null, null);
}
public void Setzen(double? anteil, double? rest)
{
bool zug = anteil != null;
_ring.Visibility = zug ? Visibility.Visible : Visibility.Collapsed;
_rand.Visibility = zug ? Visibility.Collapsed : Visibility.Visible;
_person.Visibility = zug ? Visibility.Collapsed : Visibility.Visible;
_zahl.Visibility = zug ? Visibility.Visible : Visibility.Collapsed;
if (anteil is double a)
{
_ring.Value = a;
_ring.Foreground = Ui.Pinsel(a < 0.25 ? "rot" : a < 0.5 ? "orange" : "gruen");
_zahl.Text = $"{Math.Ceiling(rest ?? 0):0}";
}
}
}
+154
View File
@@ -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;
/// <summary>
/// Der Reiter Protokoll (EntscheidungenGeld.swift `ProtokollAnsicht`): Gedanken und Ereignisse als
/// Strom in Festbreitenschrift, anhaltbar zum Lesen; Geld als Liste der Geldbewegungen mit Art-Filter.
/// </summary>
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<string>().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);
}
}
}
+467
View File
@@ -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;
/// <summary>
/// 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.
/// </summary>
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;
}
/// <summary>bb/100 ueber alle Stakes, gewichtet nach Haenden (Diagramme.swift `BB100.gesamt`).</summary>
private static double? Gesamt(IEnumerable<JsonObject> 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;
}
/// <summary>Formate im Vergleich (FormatVergleich.swift): bb/100 mit 95-%-Spanne auf gemeinsamer Achse.</summary>
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<double>().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>(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;
}
/// <summary>bb/100 je Stake mit 95-%-Intervall: Punkt und Spanne je Zeile.</summary>
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<double>().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);
}
/// <summary>Stapel je Tisch ueber die Zeit, eine Linie je Tisch mit Legende.</summary>
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;
}
/// <summary>Gestapelte Flaechen je Block zu 20 Entscheidungen (AreaMark, stacking: .normalized).</summary>
private static UIElement Verlauf(List<JsonObject> 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<JsonObject> 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<double>()
.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));
}
}
+289
View File
@@ -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;
/// <summary>
/// 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.
/// </summary>
public static class Ui
{
private static Brush Res(string k) => (Brush)Application.Current.Resources[k];
/// <summary>Farbname der Ansicht ("gruen", "rot", ...; "" = Text) -> Farbe.</summary>
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));
/// <summary>Die Farbe mit Deckkraft (wie `.opacity(0.14)`).</summary>
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;
}
/// <summary>.caption in .secondary</summary>
public static TextBlock Klein(string text, bool umbruch = false) =>
Text(text, 12, pinsel: Zweit, umbruch: umbruch);
/// <summary>.caption2</summary>
public static TextBlock Winzig(string text, Brush? pinsel = null, bool fett = false) =>
Text(text, 11, pinsel: pinsel ?? Zweit, fett: fett);
/// <summary>Gerundete Zahlenschrift wie `.design(.rounded)` - unter Windows die Variable-Schrift.</summary>
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;
}
/// <summary>Ein Symbol; ohne Ton erbt es die Textfarbe (kein gesetztes null).</summary>
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;
}
/// <summary>Eine Flaeche wie `.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 14))`.</summary>
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,
};
/// <summary>Eine getoente Flaeche: `.background(farbe.opacity(0.12), in: RoundedRectangle(10))`.</summary>
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,
};
/// <summary>Abzeichen: kleiner Text in einer getoenten Kapsel.</summary>
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,
};
}
/// <summary>Abschnittskopf: "Tische" halbfett in .secondary, daneben ein leiser Hinweis.</summary>
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;
}
/// <summary>Eine Spielkarte: Rang und Farbe, rot oder hell, auf dunklem Grund mit Rand (KarteAnsicht).</summary>
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,
};
}
/// <summary>Ein leerer Kartenplatz (gestrichelt wie im Minitisch).</summary>
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;
}
/// <summary>Links etwas, rechts etwas, dazwischen Platz (HStack mit Spacer).</summary>
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,
};
/// <summary>Ein schlichter Symbolknopf ohne Rahmen (`.buttonStyle(.borderless)`).</summary>
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);
}
}
/// <summary>
/// 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.
/// </summary>
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<T>(this T e, int spalte) where T : FrameworkElement
{
Grid.SetColumn(e, spalte);
return e;
}
public static T Zeile<T>(this T e, int zeile) where T : FrameworkElement
{
Grid.SetRow(e, zeile);
return e;
}
public static T Mit<T>(this T e, Action<T> 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;
}
}
+14
View File
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="Pokerfreak.Cockpit.app"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</windowsSettings>
</application>
</assembly>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>