- Einstellungen: Lehrer & Stimme (Anbieter-Formulare), Plan-Editor Zeiten & Geld (Vorlagen, Feineinstellung, Geld-Stopps), Streamer (Twitch/Chat/Moderation); Plan-Kachel oeffnet ihn - Absturz beim Klick auf eine Vorlage behoben (Json.ZahlVon las selbst gesetzte long nicht) - Leiste wie das Mac-Panel: volle Hoehe am Rand, ueber allem, schnappt nach dem Ziehen an den naechsten Rand, Restbreite neben den Kacheln (cockpit_ziel.json), Ausweichen fuer Laeufer-Klicks; Cockpit-Seite in Allgemein; cockpit.json mit form leiste/seite/mindestbreite/zeit - Tisch-Desktop an: das Cockpit zieht mit hinueber und dockt nur dort (statt an alle Desktops) - Zahnrad als vierte Systemtaste buendig vor Minimieren/Maximieren/Schliessen - --nur-spiel / POKERFREAK_NUR_SPIEL=1: nur Cash Game und Turnier (ohne Zuschauer, Sonderformate, Lehrer & Stimme, Streamer, Maus-Schalter, Klon-Abzeichen) - Stimme: unter Windows "Windows" (System.Speech) statt macOS, MP3 ueber MediaPlayer; Specs plattformneutral (anbieter, anbieter_knoepfe, sprecher gruen) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
341 lines
13 KiB
C#
341 lines
13 KiB
C#
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;
|
|
}
|
|
|
|
/// <summary>Den Grund eines Absturzes neben die Merkdatei schreiben (absturz.txt).</summary>
|
|
public static void Absturz(Exception e)
|
|
{
|
|
try
|
|
{
|
|
var pfad = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Datei)!, "absturz.txt");
|
|
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(pfad)!);
|
|
File.WriteAllText(pfad, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}\n{e}\n");
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
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 > 0, rot < 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));
|
|
}
|
|
}
|
|
}
|