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

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

160 lines
8.0 KiB
C#

using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Shapes;
using Pokerfreak.Cockpit.Kern;
namespace Pokerfreak.Cockpit.Seiten;
/// <summary>Raumnamen des Clients ("14R NL 0.01-0.02 EV-INRIT-(A) 1845111") in kurz: "#5111" und "NL2".</summary>
public static partial class Raum
{
[GeneratedRegex(@"(?:\d+R )?(?:NL|PL|FL) [\d.]+-[\d.]+ \S+ \d*(\d{4})\b")]
private static partial Regex Name();
[GeneratedRegex(@"(NL|PL|FL) [\d.]+-([\d.]+)")]
private static partial Regex Blinds();
public static string Nummer(string raum)
{
var m = Name().Match(raum);
return m.Success ? "#" + m.Groups[1].Value : raum;
}
/// <summary>"NL2" aus den Blinds; leer, wenn der Name keine traegt.</summary>
public static string Stufe(string raum)
{
var m = Blinds().Match(raum);
return m.Success && double.TryParse(m.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture, out var bb)
? $"{m.Groups[1].Value}{bb * 100:0}" : "";
}
/// <summary>Alle Raumnamen in einem Satz kuerzen.</summary>
public static string Kurz(string satz) => Name().Replace(satz, m => "#" + m.Groups[1].Value);
}
/// <summary>
/// Ein Tisch als Zeile: Zustand, Nummer und Stufe, eigene Karten mit der letzten Aktion, Ergebnis. Antippen klappt
/// die volle Kachel darunter auf (Minitisch, Entscheidung, Gegner) - sie entsteht erst dann.
/// </summary>
public sealed class TischZeile : UserControl
{
private readonly CockpitZustand _z;
private readonly string _raum;
private readonly Ellipse _punkt = Ui.Punkt("grau", 7);
private readonly StackPanel _karten = Ui.Reihe(2);
private readonly TextBlock _was = Ui.Text("", 12, pinsel: Ui.Zweit);
private readonly TextBlock _netto = Ui.Text("", 12.5, fett: true, zahlen: true);
private readonly FontIcon _pfeil = Ui.Zeichen("", 8);
private readonly Border _marke = new() { Width = 3, CornerRadius = new CornerRadius(2), Margin = new Thickness(0, 6, 0, 6) };
private readonly TextBlock _log = new() { FontSize = 11, TextTrimming = TextTrimming.CharacterEllipsis, TextWrapping = TextWrapping.NoWrap };
private readonly Ellipse _logPunkt = Ui.Punkt("grau", 5);
private readonly Grid _logZeile = new() { ColumnSpacing = 6, Padding = new Thickness(21, 0, 10, 6) };
private readonly Border _huelle = new() { Padding = new Thickness(8, 0, 8, 8), Visibility = Visibility.Collapsed };
private readonly Border _linie = Ui.Linie();
private TischKachel? _kachel;
private JsonObject? _daten;
private byte[]? _foto;
private string _abdruck = "";
/// <summary>Aufgeklappt (hoechstens eine Zeile, das regelt die Liste).</summary>
public event Action<TischZeile>? Geoeffnet;
public TischZeile(CockpitZustand z, string raum, string titel)
{
_z = z;
_raum = raum;
_pfeil.Foreground = Ui.Dritt;
var nr = Raum.Nummer(raum);
var name = Ui.Reihe(6, _punkt.Mit(p => p.VerticalAlignment = VerticalAlignment.Center),
Ui.Text(nr == raum ? titel : nr, 12.5, fett: true, zahlen: true).Mit(t => t.MaxWidth = 110),
Ui.Text(Raum.Stufe(raum), 11, pinsel: Ui.Dritt).Mit(t => t.VerticalAlignment = VerticalAlignment.Center));
var g = new Grid { ColumnSpacing = 6, Height = 32, Padding = new Thickness(5, 0, 10, 0) };
foreach (var b in new[] { GridLength.Auto, new GridLength(94), new GridLength(60), new GridLength(1, GridUnitType.Star), GridLength.Auto, GridLength.Auto })
g.ColumnDefinitions.Add(new ColumnDefinition { Width = b });
g.Children.Add(_marke);
g.Children.Add(name.Spalte(1));
g.Children.Add(_karten.Spalte(2));
g.Children.Add(_was.Spalte(3));
g.Children.Add(_netto.Spalte(4));
g.Children.Add(_pfeil.Spalte(5));
foreach (var e in new FrameworkElement[] { name, _karten, _was, _netto, _pfeil }) e.VerticalAlignment = VerticalAlignment.Center;
// darunter die letzte Zeile des Stroms an diesem Tisch (Owner 02.12.: "log line pro tisch")
_logZeile.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
_logZeile.ColumnDefinitions.Add(new ColumnDefinition());
_logZeile.Children.Add(_logPunkt.Mit(p => p.Margin = new Thickness(0, 1, 0, 0)));
_logZeile.Children.Add(_log.Spalte(1));
_logZeile.Visibility = Visibility.Collapsed;
var kopfUndLog = Ui.Spalte(0, g, _logZeile);
var s = Ui.Spalte(0);
s.Children.Add(_linie);
s.Children.Add(kopfUndLog.Tippen(() => Offen = !Offen, 4));
s.Children.Add(_huelle);
Content = s;
Visibility = Visibility.Collapsed;
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(this, raum);
}
public bool Linie { set => _linie.Visibility = value ? Visibility.Visible : Visibility.Collapsed; }
public bool Offen
{
get => _huelle.Visibility == Visibility.Visible;
set
{
if (value == Offen) return;
_pfeil.Glyph = value ? "" : "";
_huelle.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
Visibility = _huelle.Visibility; // zu: nur die Kachel im Raster steht fuer den Tisch
if (!value) return;
_huelle.Child ??= _kachel = new TischKachel(_z, _raum);
if (_daten != null) _kachel!.Setzen(_daten, _foto);
Geoeffnet?.Invoke(this);
}
}
public void Setzen(JsonObject chip, JsonObject? kachel, byte[]? foto)
{
_daten = kachel;
_foto = foto;
if (Offen && kachel != null) _kachel?.Setzen(kachel, foto);
bool zug = chip.Wahr("am_zug");
var karten = kachel.Texte("karten").ToList();
// Sitzt er, sagt die letzte Aktion am meisten; sonst Zustand und Grund
var was = zug ? "am Zug" : kachel.Text("aktion") is { Length: > 0 } a ? a.Replace("Raise auf", "Raise").Replace(" BB", "")
: kachel.Text("zustand") is { Length: > 0 } zu && zu != "gesessen" ? zu : "";
var zeile = chip.T("zeile");
var log = chip.T("log");
var abdruck = $"{chip.T("punkt_ton")}|{zug}|{string.Join(",", karten)}|{was}|{zeile}|{chip.T("zeile_ton")}|{log}|{chip.T("log_ton")}|{chip.T("log_warn")}";
if (abdruck == _abdruck) return;
_abdruck = abdruck;
_punkt.Fill = Ui.Pinsel(chip.T("punkt_ton"));
_marke.Background = zug ? Ui.Pinsel("orange") : null;
_karten.Children.Clear();
foreach (var k in karten.Take(4)) _karten.Children.Add(Ui.Minikarte(k));
_was.Text = was;
_was.Foreground = zug ? Ui.Pinsel("orange") : Ui.Zweit;
_netto.Text = zeile == "gesessen" ? "" : zeile;
_netto.Foreground = chip.T("zeile_ton") is "grau" or "" ? Ui.Dritt : Ui.Pinsel(chip.T("zeile_ton"));
LogSetzen(log, chip.Zahl("log_zeit"), chip.T("log_warn") is { Length: > 0 } w ? w : chip.T("log_ton"), chip.T("log_warn").Length > 0 || chip.T("log_art") == "ergebnis");
ToolTipService.SetToolTip(this, kachel.Text("hinweis") is { Length: > 0 } h ? $"{_raum}\n{h}" : _raum);
}
/// <summary>Die letzte Stromzeile: Uhrzeit leise, Text in Weiss bzw. bei Warnung/Fehler in deren Farbe.</summary>
private void LogSetzen(string text, double? zeit, string ton, bool laut)
{
_logZeile.Visibility = text.Length > 0 ? Visibility.Visible : Visibility.Collapsed;
if (text.Length == 0) return;
text = Raum.Kurz(text);
_log.Inlines.Clear();
if (zeit is double t)
_log.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run { Text = Format.Kurz(t) + " ", Foreground = Ui.Dritt });
_log.Inlines.Add(new Microsoft.UI.Xaml.Documents.Run { Text = text, Foreground = laut ? Ui.Pinsel(ton) : Ui.Zweit });
_logPunkt.Fill = Ui.Pinsel(ton is { Length: > 0 } ? ton : "grau", laut ? 1 : 0.7);
ToolTipService.SetToolTip(_logZeile, (zeit is double z ? Format.Uhr(z) + " " : "") + text);
}
public void Takt() { if (Offen) _kachel?.Takt(); }
}