- 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>
592 lines
31 KiB
C#
592 lines
31 KiB
C#
using System.Text.Json.Nodes;
|
||
using System.Text.RegularExpressions;
|
||
using Microsoft.UI.Text;
|
||
using Microsoft.UI.Xaml;
|
||
using Microsoft.UI.Xaml.Controls;
|
||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||
using Microsoft.UI.Xaml.Documents;
|
||
using Microsoft.UI.Xaml.Input;
|
||
using Microsoft.UI.Xaml.Media;
|
||
using Pokerfreak.Cockpit.Kern;
|
||
using Windows.ApplicationModel.DataTransfer;
|
||
|
||
namespace Pokerfreak.Cockpit.Seiten;
|
||
|
||
/// <summary>
|
||
/// Der Reiter Protokoll (Owner 02.12.: "saubere Farben, Filter, Lesbarkeit, Suche"). Drei Teile:
|
||
/// Gedanken (je eigener Entscheidung eine Zeile), Ereignisse (der Strom des Laeufers) und Geld.
|
||
/// Oben Suche, Pause und Menue; bei den Ereignissen eine Leiste mit Filterchips (Tisch, Probleme, je Art mit Zahl).
|
||
/// Jede Zeile: Zeit links, darueber klein Art und Tisch in der Farbe der Art, darunter der Text; Warnungen und
|
||
/// Fehler mit getoentem Grund und Farbstrich. Suchtreffer sind markiert. Rechtsklick: kopieren, nur dieser Tisch,
|
||
/// Art ausblenden. Strg+F springt in die Suche.
|
||
/// </summary>
|
||
public sealed class ProtokollSeite : UserControl, ISeite
|
||
{
|
||
private static readonly FontFamily Fest = new("Cascadia Mono, Consolas");
|
||
|
||
/// <summary>Die Arten des Stroms (betrieb/strom.py) mit Namen und fester Farbe - gleiche Art, gleiche Farbe.</summary>
|
||
private static readonly (string Art, string Name, string Ton)[] Arten =
|
||
{
|
||
("entscheidung", "Entscheidung", "blau"), ("vorhaben", "Vorhaben", "indigo"), ("ergebnis", "Ergebnis", "gruen"),
|
||
("sitzen", "Sitzen", "teal"), ("ereignis", "Ereignis", "grau"), ("zeitplan", "Zeitplan", "lila"),
|
||
("gegner", "Gegner", "gelb"), ("showdown", "Showdown", "orange"), ("deal", "Deal", "orange"),
|
||
("zeiger", "Zeiger", "grau"), ("technik", "Technik", "grau"),
|
||
};
|
||
|
||
private static (string Name, string Ton) ArtVon(string? art)
|
||
{
|
||
foreach (var a in Arten) if (a.Art == art) return (a.Name, a.Ton);
|
||
return (string.IsNullOrEmpty(art) ? "Sonstiges" : char.ToUpperInvariant(art[0]) + art[1..], "grau");
|
||
}
|
||
|
||
/// <summary>Wie ernst eine Zeile ist: "rot" Fehler, "orange" Warnung, sonst null (wie sicht/abgeleitet.py `log_ton`).</summary>
|
||
internal static string? Ernst(string? art, string? name, string? text)
|
||
{
|
||
var t = (text ?? "").ToLowerInvariant();
|
||
var n = (name ?? "").ToLowerInvariant();
|
||
if (new[] { "absturz", "fehler", "abbruch", "abgebrochen", "not-aus", "timeout" }.Any(w => n.Contains(w) || t.Contains(w))) return "rot";
|
||
if (n.Contains("warn") || t.StartsWith("ereignis warnung") || t.Contains("sitzt aus") || n == "kanal_rueckfall") return "orange";
|
||
return null;
|
||
}
|
||
|
||
private readonly CockpitZustand _z;
|
||
private readonly Segmente _teil = new(new[] { "Gedanken", "Ereignisse", "Geld" }, "protokoll.teil");
|
||
private readonly AutoSuggestBox _suche = new()
|
||
{
|
||
PlaceholderText = "Suchen (Strg+F)",
|
||
QueryIcon = new SymbolIcon(Symbol.Find),
|
||
FontSize = 12,
|
||
VerticalAlignment = VerticalAlignment.Center,
|
||
};
|
||
private readonly ToggleButton _pause = new() { Padding = new Thickness(10, 5, 10, 5), CornerRadius = new CornerRadius(4), MinWidth = 0 };
|
||
private readonly TextBlock _pauseText = Ui.Text("Live", 12);
|
||
private readonly FontIcon _pauseZeichen = Ui.Zeichen("\uE769", 11);
|
||
private readonly Button _menue = new() { Padding = new Thickness(8, 6, 8, 6), CornerRadius = new CornerRadius(4), MinWidth = 0 };
|
||
private readonly ToggleMenuFlyoutItem _nurSitzung = new() { Text = "Nur laufende Sitzung" };
|
||
private readonly StackPanel _chips = Ui.Reihe(6);
|
||
private readonly ScrollViewer _chipLeiste;
|
||
private readonly Auswahl _art = new("Art");
|
||
private readonly Border _uebung = Ui.Abzeichen("ÜBUNG", "blau");
|
||
private readonly TextBlock _stand = Ui.Winzig("", Ui.Dritt);
|
||
private readonly StackPanel _liste = Ui.Spalte(0);
|
||
private readonly ScrollViewer _rollen;
|
||
|
||
private readonly HashSet<string> _aus;
|
||
private bool _nurProbleme;
|
||
private string? _tisch;
|
||
private double _sitzungsStart = double.NegativeInfinity;
|
||
private JsonObject? _angehalten;
|
||
private string _abdruck = "", _chipAbdruck = "";
|
||
private List<string> _sichtbar = new(); // die gezeigten Zeilen als Text (Alles kopieren)
|
||
|
||
public ProtokollSeite(CockpitZustand z)
|
||
{
|
||
_z = z;
|
||
_aus = new HashSet<string>((Merker.Lesen("protokoll.aus") ?? "technik").Split(',', StringSplitOptions.RemoveEmptyEntries));
|
||
_nurProbleme = Merker.Lesen("protokoll.probleme") == "1";
|
||
_nurSitzung.IsChecked = Merker.Lesen("protokoll.sitzung") == "1";
|
||
|
||
_teil.Gewaehlt += _ => Neu();
|
||
_suche.TextChanged += (_, _) => Neu();
|
||
_suche.QuerySubmitted += (_, _) => Neu();
|
||
|
||
_pause.Content = Ui.Reihe(6, _pauseZeichen, _pauseText);
|
||
ToolTipService.SetToolTip(_pause, "Anhalten zum Lesen - neue Zeilen kommen erst nach dem Fortsetzen");
|
||
_pause.Click += (_, _) => { _angehalten = _pause.IsChecked == true ? _z.Ansicht.Ticker : null; Neu(); };
|
||
|
||
var kopieren = new MenuFlyoutItem { Text = "Gezeigte Zeilen kopieren", Icon = new FontIcon { Glyph = "\uE8C8" } };
|
||
kopieren.Click += (_, _) => Kopieren(string.Join("\n", _sichtbar));
|
||
var zuruecksetzen = new MenuFlyoutItem { Text = "Filter zurücksetzen", Icon = new FontIcon { Glyph = "\uE894" } };
|
||
zuruecksetzen.Click += (_, _) => FilterZurueck();
|
||
_nurSitzung.Click += (_, _) => { Merker.Schreiben("protokoll.sitzung", _nurSitzung.IsChecked ? "1" : "0"); Neu(); };
|
||
_menue.Content = Ui.Zeichen("\uE712", 12);
|
||
_menue.Flyout = new MenuFlyout { Items = { _nurSitzung, new MenuFlyoutSeparator(), zuruecksetzen, kopieren } };
|
||
ToolTipService.SetToolTip(_menue, "Mehr");
|
||
_art.Geaendert += Neu;
|
||
|
||
var f = new KeyboardAccelerator { Key = Windows.System.VirtualKey.F, Modifiers = Windows.System.VirtualKeyModifiers.Control };
|
||
f.Invoked += (_, e) => { e.Handled = true; _suche.Focus(FocusState.Keyboard); };
|
||
var esc = new KeyboardAccelerator { Key = Windows.System.VirtualKey.Escape };
|
||
esc.Invoked += (_, e) => { if (_suche.Text.Length > 0) { e.Handled = true; _suche.Text = ""; } };
|
||
// Am Fenster, solange die Seite steht: der Fokus-Anker des Fensters sitzt ausserhalb der Seite, Kuerzel an der
|
||
// Seite selbst kaemen nie an
|
||
Loaded += (_, _) =>
|
||
{
|
||
if (XamlRoot?.Content is UIElement w && !w.KeyboardAccelerators.Contains(f)) { w.KeyboardAccelerators.Add(f); w.KeyboardAccelerators.Add(esc); }
|
||
};
|
||
Unloaded += (_, _) =>
|
||
{
|
||
if (XamlRoot?.Content is UIElement w) { w.KeyboardAccelerators.Remove(f); w.KeyboardAccelerators.Remove(esc); }
|
||
};
|
||
|
||
// Kopf: Teile | Suche, Pause, Menue | Filterchips | Stand
|
||
var werkzeug = new Grid { ColumnSpacing = 6 };
|
||
werkzeug.ColumnDefinitions.Add(new ColumnDefinition());
|
||
werkzeug.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
|
||
werkzeug.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
|
||
werkzeug.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
|
||
werkzeug.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
|
||
werkzeug.Children.Add(_suche);
|
||
werkzeug.Children.Add(_art.Spalte(1).Mit(a => a.VerticalAlignment = VerticalAlignment.Center));
|
||
werkzeug.Children.Add(_uebung.Spalte(2));
|
||
werkzeug.Children.Add(_pause.Spalte(3).Mit(p => p.VerticalAlignment = VerticalAlignment.Center));
|
||
werkzeug.Children.Add(_menue.Spalte(4).Mit(p => p.VerticalAlignment = VerticalAlignment.Center));
|
||
|
||
_chipLeiste = new ScrollViewer
|
||
{
|
||
Content = _chips,
|
||
HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden,
|
||
HorizontalScrollMode = ScrollMode.Enabled,
|
||
VerticalScrollBarVisibility = ScrollBarVisibility.Disabled,
|
||
VerticalScrollMode = ScrollMode.Disabled,
|
||
};
|
||
var kopf = Ui.Spalte(8, _teil, werkzeug, _chipLeiste, _stand);
|
||
kopf.Padding = new Thickness(12, 12, 12, 8);
|
||
|
||
_liste.Padding = new Thickness(6, 4, 10, 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;
|
||
}
|
||
|
||
private void Neu() { _abdruck = ""; Zeichnen(); }
|
||
|
||
private void FilterZurueck()
|
||
{
|
||
_aus.Clear();
|
||
_nurProbleme = false;
|
||
_tisch = null;
|
||
_suche.Text = "";
|
||
_nurSitzung.IsChecked = false;
|
||
Merker.Schreiben("protokoll.aus", "");
|
||
Merker.Schreiben("protokoll.probleme", "0");
|
||
Merker.Schreiben("protokoll.sitzung", "0");
|
||
_chipAbdruck = "";
|
||
Neu();
|
||
}
|
||
|
||
private static void Kopieren(string text)
|
||
{
|
||
if (text.Length == 0) return;
|
||
var p = new DataPackage();
|
||
p.SetText(text);
|
||
try { Clipboard.SetContent(p); } catch { }
|
||
}
|
||
|
||
private string Suche => _suche.Text.Trim();
|
||
|
||
public void Zeichnen()
|
||
{
|
||
int teil = _teil.Index;
|
||
bool geld = teil == 2, ereignisse = teil == 1;
|
||
_pause.Visibility = geld ? Visibility.Collapsed : Visibility.Visible;
|
||
_chipLeiste.Visibility = ereignisse ? Visibility.Visible : Visibility.Collapsed;
|
||
_menue.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;
|
||
_pauseText.Text = _pause.IsChecked == true ? "Angehalten" : "Live";
|
||
_pauseZeichen.Glyph = _pause.IsChecked == true ? "\uE768" : "\uE769";
|
||
_pauseZeichen.Foreground = Ui.Pinsel(_pause.IsChecked == true ? "orange" : "gruen");
|
||
if (geld) GeldZeichnen();
|
||
else if (ereignisse) EreignisseZeichnen();
|
||
else GedankenZeichnen();
|
||
}
|
||
|
||
// ---- Ereignisse ------------------------------------------------------------------------------
|
||
|
||
/// <summary>Beginn der laufenden Sitzung: das letzte `zeitplan`-Ereignis mit phase "spielen".</summary>
|
||
private void SitzungMerken(JsonObject? t)
|
||
{
|
||
_sitzungsStart = double.NegativeInfinity;
|
||
foreach (var z in t.Objekte("zeilen"))
|
||
if (z.Text("art") == "zeitplan" && (z.Text("text") ?? "").Contains("phase=spielen"))
|
||
_sitzungsStart = Math.Max(_sitzungsStart, z.Zahl("zeit") ?? double.NegativeInfinity);
|
||
}
|
||
|
||
private static string? Problem(JsonObject z) => Ernst(z.Text("art"), z.Text("name"), z.Text("text"));
|
||
|
||
/// <summary>Die Gruppe einer Zeile: "technik" (Takt, Kanaele, ...; vom Server) vor der Art.</summary>
|
||
private static string ArtSchluessel(JsonObject z) => z.Text("gruppe") is { Length: > 0 } g ? g : z.T("art");
|
||
|
||
private static string TischVon(JsonObject z) => z.Text("raum") is { Length: > 0 } r ? Raum.Nummer(r) : "";
|
||
|
||
/// <summary>Der Text ohne den angehaengten Raumnamen ("... (14R NL ... 1845111).") - der steht schon als Marke.</summary>
|
||
private static string Klartext(JsonObject z)
|
||
{
|
||
var t = z.T("text");
|
||
if (z.Text("raum") is { Length: > 0 } r) t = t.Replace($" ({r})", "");
|
||
return Raum.Kurz(t);
|
||
}
|
||
|
||
private bool Passt(JsonObject z, bool mitArt = true)
|
||
{
|
||
if (_nurSitzung.IsChecked && (z.Zahl("zeit") ?? double.NegativeInfinity) < _sitzungsStart) return false;
|
||
if (_tisch != null && TischVon(z) != _tisch) return false;
|
||
if (_nurProbleme && Problem(z) == null) return false;
|
||
if (mitArt && _aus.Contains(ArtSchluessel(z))) return false;
|
||
var s = Suche;
|
||
return s.Length == 0 || new[] { z.Text("art"), z.Text("raum"), z.Text("text"), z.Text("kurz"), TischVon(z) }
|
||
.Any(x => x != null && x.Contains(s, StringComparison.OrdinalIgnoreCase));
|
||
}
|
||
|
||
private void EreignisseZeichnen()
|
||
{
|
||
var live = _z.Ansicht.Ticker;
|
||
var t = _angehalten ?? live;
|
||
var alle = t.Objekte("zeilen").ToList();
|
||
SitzungMerken(t);
|
||
int neu = 0;
|
||
if (_angehalten != null)
|
||
{
|
||
var oben = alle.FirstOrDefault()?.Zahl("zeit") ?? double.NegativeInfinity;
|
||
neu = live.Objekte("zeilen").Count(z => (z.Zahl("zeit") ?? 0) > oben);
|
||
}
|
||
Chips(alle);
|
||
var abdruck = "e" + t?["zeilen"].Abdruck() + neu;
|
||
if (abdruck == _abdruck) return;
|
||
_abdruck = abdruck;
|
||
|
||
var zeilen = alle.Where(z => Passt(z)).ToList();
|
||
_stand.Text = $"{zeilen.Count} von {alle.Count} Zeilen" + (_angehalten != null ? $" · angehalten{(neu > 0 ? $", {neu} neu" : "")}" : "");
|
||
_stand.Foreground = _angehalten != null ? Ui.Pinsel("orange") : Ui.Dritt;
|
||
_liste.Children.Clear();
|
||
_sichtbar = new List<string>();
|
||
foreach (var z in zeilen)
|
||
{
|
||
var (name, ton) = ArtVon(ArtSchluessel(z));
|
||
var ernst = Problem(z);
|
||
if (z.Text("art") == "ergebnis" && z.Zahl("netto") is double n) ton = n > 0 ? "gruen" : n < 0 ? "rot" : "grau";
|
||
var tisch = TischVon(z);
|
||
var text = Klartext(z);
|
||
var kurz = z.Text("kurz") is { Length: > 0 } k ? Raum.Kurz(k) : text;
|
||
// Entscheidung: "Turn · K♣Q♣ · Check" vorn, Konfidenz und Grund leise darunter
|
||
var mehr = z.T("art") == "entscheidung" && kurz != text ? Nachsatz(text) : "";
|
||
_sichtbar.Add($"{Format.Uhr(z.Zahl("zeit"))} {name,-12} {tisch,-6} {text}");
|
||
_liste.Children.Add(Zeile(Format.Uhr(z.Zahl("zeit")), name, ernst ?? ton, tisch, z.Text("raum"), kurz, mehr, ernst, ArtSchluessel(z)));
|
||
}
|
||
if (_liste.Children.Count == 0)
|
||
_liste.Children.Add(alle.Count == 0
|
||
? Teile.Leer("Noch nichts", t.Text("leer") ?? "Der Strom läuft, sobald der Läufer arbeitet.", "\uE7C3")
|
||
: LeerMitFilter());
|
||
}
|
||
|
||
/// <summary>Was nach der Aktion im Entscheidungstext steht ("Konfidenz 0,97. Grund: ...").</summary>
|
||
private static string Nachsatz(string text)
|
||
{
|
||
var i = text.IndexOf(". Konfidenz", StringComparison.Ordinal);
|
||
if (i < 0) i = text.IndexOf(". Equity", StringComparison.Ordinal);
|
||
if (i < 0) i = text.IndexOf(". Grund", StringComparison.Ordinal);
|
||
return i < 0 ? "" : text[(i + 2)..];
|
||
}
|
||
|
||
private UIElement LeerMitFilter()
|
||
{
|
||
var s = Teile.Leer("Kein Treffer", "Die Filter verbergen alle Zeilen.", "\uE71C");
|
||
s.Children.Add(Teile.Knopf("Filter zurücksetzen", FilterZurueck).Mit(k => k.HorizontalAlignment = HorizontalAlignment.Center));
|
||
return s;
|
||
}
|
||
|
||
/// <summary>Die Filterleiste: Tisch, Probleme, dann je Art ein Chip mit Zahl (Zahl ohne Art-Filter gezaehlt).</summary>
|
||
private void Chips(List<JsonObject> alle)
|
||
{
|
||
var basis = alle.Where(z => Passt(z, mitArt: false)).ToList();
|
||
var je = basis.GroupBy(ArtSchluessel).ToDictionary(g => g.Key, g => g.Count());
|
||
var arten = alle.Select(ArtSchluessel).Distinct()
|
||
.OrderBy(a => Array.FindIndex(Arten, x => x.Art == a) is var i && i >= 0 ? i : 99).ThenBy(a => a).ToList();
|
||
var tische = alle.Select(TischVon).Where(x => x.Length > 0).Distinct().OrderBy(x => x).ToList();
|
||
int probleme = alle.Count(z => Problem(z) != null);
|
||
var abdruck = string.Join("|", arten.Select(a => $"{a}:{je.GetValueOrDefault(a)}:{_aus.Contains(a)}"))
|
||
+ $"#{string.Join(",", tische)}#{_tisch}#{_nurProbleme}#{probleme}";
|
||
if (abdruck == _chipAbdruck) return;
|
||
_chipAbdruck = abdruck;
|
||
_chips.Children.Clear();
|
||
|
||
// Tisch: Menue mit allen Tischen des Stroms
|
||
var tischMenue = new MenuFlyout();
|
||
var alleT = new ToggleMenuFlyoutItem { Text = "Alle Tische", IsChecked = _tisch == null };
|
||
alleT.Click += (_, _) => { _tisch = null; _chipAbdruck = ""; Neu(); };
|
||
tischMenue.Items.Add(alleT);
|
||
if (tische.Count > 0) tischMenue.Items.Add(new MenuFlyoutSeparator());
|
||
foreach (var x in tische)
|
||
{
|
||
var e = new ToggleMenuFlyoutItem { Text = x, IsChecked = _tisch == x };
|
||
e.Click += (_, _) => { _tisch = x; _chipAbdruck = ""; Neu(); };
|
||
tischMenue.Items.Add(e);
|
||
}
|
||
var tischChip = Chip("\uE8A9", _tisch ?? "Alle Tische", null, _tisch != null, "blau", null, pfeil: true);
|
||
FlyoutBase.SetAttachedFlyout(tischChip, tischMenue);
|
||
tischChip.Getippt += () => FlyoutBase.ShowAttachedFlyout(tischChip);
|
||
_chips.Children.Add(tischChip);
|
||
|
||
_chips.Children.Add(Chip("\uE7BA", "Probleme", probleme, _nurProbleme, "orange", () =>
|
||
{
|
||
_nurProbleme = !_nurProbleme;
|
||
Merker.Schreiben("protokoll.probleme", _nurProbleme ? "1" : "0");
|
||
_chipAbdruck = "";
|
||
Neu();
|
||
}));
|
||
_chips.Children.Add(new Border { Width = 1, Margin = new Thickness(2, 4, 2, 4), Background = Ui.Weiss(0.12) });
|
||
|
||
foreach (var a in arten)
|
||
{
|
||
var (name, ton) = ArtVon(a);
|
||
var art = a;
|
||
_chips.Children.Add(Chip(null, name, je.GetValueOrDefault(a), !_aus.Contains(a), ton, () =>
|
||
{
|
||
if (!_aus.Remove(art)) _aus.Add(art);
|
||
Merker.Schreiben("protokoll.aus", string.Join(",", _aus));
|
||
_chipAbdruck = "";
|
||
Neu();
|
||
}, punkt: true));
|
||
}
|
||
}
|
||
|
||
/// <summary>Ein Filterchip: Kapsel, an = getoent in der Farbe, aus = nur Rand und blasser Text.</summary>
|
||
private static Tippflaeche Chip(string? glyph, string text, int? zahl, bool an, string ton, Action? tun,
|
||
bool punkt = false, bool pfeil = false)
|
||
{
|
||
var inhalt = Ui.Reihe(5);
|
||
if (punkt) inhalt.Children.Add(Ui.Punkt(ton, 6).Mit(p => p.Opacity = an ? 1 : 0.35));
|
||
if (glyph != null) inhalt.Children.Add(Ui.Zeichen(glyph, 10, an ? ton : "grau"));
|
||
inhalt.Children.Add(Ui.Text(text, 11.5, pinsel: an ? Ui.Pinsel("") : Ui.Zweit).Mit(t => t.VerticalAlignment = VerticalAlignment.Center));
|
||
if (zahl is int n)
|
||
inhalt.Children.Add(Ui.Text(Format.Zahl(n), 10.5, pinsel: an ? Ui.Zweit : Ui.Dritt, zahlen: true)
|
||
.Mit(t => t.VerticalAlignment = VerticalAlignment.Center));
|
||
if (pfeil) inhalt.Children.Add(Ui.Zeichen("\uE70D", 8, "grau"));
|
||
var b = new Border
|
||
{
|
||
Height = 26,
|
||
Padding = new Thickness(9, 0, 10, 0),
|
||
CornerRadius = new CornerRadius(13),
|
||
BorderThickness = new Thickness(1),
|
||
Background = an && !punkt ? Ui.Pinsel(ton, 0.16) : an ? Ui.Weiss(0.07) : null,
|
||
BorderBrush = an && !punkt ? Ui.Pinsel(ton, 0.45) : Ui.Weiss(an ? 0.10 : 0.08),
|
||
Child = inhalt.Mit(r => r.VerticalAlignment = VerticalAlignment.Center),
|
||
};
|
||
var t = b.Tippen(tun ?? (() => { }), 13);
|
||
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(t, text);
|
||
return t;
|
||
}
|
||
|
||
/// <summary>Eine Zeile: Zeit | (Art · Tisch) / Text. Probleme mit Farbstrich und getoentem Grund.</summary>
|
||
private Grid Zeile(string zeit, string art, string ton, string tisch, string? raum, string text, string mehr, string? ernst, string artSchluessel)
|
||
{
|
||
var g = new Grid { ColumnSpacing = 8, Padding = new Thickness(6, 5, 6, 6), CornerRadius = new CornerRadius(4) };
|
||
g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(3) });
|
||
g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(52) });
|
||
g.ColumnDefinitions.Add(new ColumnDefinition());
|
||
var normal = ernst != null ? Ui.Pinsel(ernst, 0.08) : Ui.Weiss(0);
|
||
g.Background = normal;
|
||
g.PointerEntered += (_, _) => g.Background = ernst != null ? Ui.Pinsel(ernst, 0.14) : Ui.Weiss(0.04);
|
||
g.PointerExited += (_, _) => g.Background = normal;
|
||
|
||
g.Children.Add(new Border { CornerRadius = new CornerRadius(2), Background = ernst != null ? Ui.Pinsel(ernst) : null });
|
||
g.Children.Add(new TextBlock
|
||
{
|
||
Text = zeit, FontFamily = Fest, FontSize = 11, Foreground = Ui.Dritt,
|
||
Margin = new Thickness(0, 1, 0, 0), IsTextSelectionEnabled = true,
|
||
}.Spalte(1));
|
||
|
||
var oben = Ui.Reihe(6, Ui.Text(art.ToUpperInvariant(), 9.5, ton, fett: true).Mit(t => t.CharacterSpacing = 40));
|
||
if (tisch.Length > 0)
|
||
{
|
||
var marke = new Border
|
||
{
|
||
Background = Ui.Weiss(0.07), CornerRadius = new CornerRadius(3), Padding = new Thickness(5, 0, 5, 1),
|
||
Child = Ui.Text(tisch, 10, pinsel: Ui.Zweit, zahlen: true),
|
||
};
|
||
var t = marke.Tippen(() => { _tisch = _tisch == tisch ? null : tisch; _chipAbdruck = ""; Neu(); }, 3,
|
||
_tisch == tisch ? "Wieder alle Tische" : $"Nur {tisch} zeigen\n{raum}");
|
||
oben.Children.Add(t);
|
||
}
|
||
var haupt = new TextBlock
|
||
{
|
||
Text = text, FontSize = 12.5, TextWrapping = TextWrapping.Wrap, IsTextSelectionEnabled = true,
|
||
Foreground = ernst != null ? Ui.Pinsel(ernst) : Ui.Pinsel(""), LineHeight = 17,
|
||
};
|
||
Markieren(haupt, text);
|
||
var spalte = Ui.Spalte(1, oben, haupt);
|
||
if (mehr.Length > 0)
|
||
{
|
||
var leise = new TextBlock { Text = mehr, FontSize = 11, Foreground = Ui.Zweit, TextWrapping = TextWrapping.Wrap, IsTextSelectionEnabled = true };
|
||
Markieren(leise, mehr);
|
||
spalte.Children.Add(leise);
|
||
}
|
||
g.Children.Add(spalte.Spalte(2));
|
||
|
||
var kopie = new MenuFlyoutItem { Text = "Zeile kopieren", Icon = new FontIcon { Glyph = "\uE8C8" } };
|
||
kopie.Click += (_, _) => Kopieren($"{zeit} {art} {tisch} {text}".Replace(" ", " "));
|
||
var menue = new MenuFlyout { Items = { kopie } };
|
||
if (tisch.Length > 0)
|
||
{
|
||
var nur = new MenuFlyoutItem { Text = _tisch == tisch ? "Wieder alle Tische" : $"Nur {tisch} zeigen", Icon = new FontIcon { Glyph = "\uE71C" } };
|
||
nur.Click += (_, _) => { _tisch = _tisch == tisch ? null : tisch; _chipAbdruck = ""; Neu(); };
|
||
menue.Items.Add(nur);
|
||
}
|
||
if (artSchluessel.Length > 0)
|
||
{
|
||
var weg = new MenuFlyoutItem { Text = $"{art} ausblenden", Icon = new FontIcon { Glyph = "\uED1A" } };
|
||
weg.Click += (_, _) => { _aus.Add(artSchluessel); Merker.Schreiben("protokoll.aus", string.Join(",", _aus)); _chipAbdruck = ""; Neu(); };
|
||
menue.Items.Add(weg);
|
||
}
|
||
g.ContextFlyout = menue;
|
||
return g;
|
||
}
|
||
|
||
/// <summary>Alle Vorkommen der Suche gelb unterlegen.</summary>
|
||
private void Markieren(TextBlock t, string text)
|
||
{
|
||
var s = Suche;
|
||
if (s.Length == 0) return;
|
||
var h = new TextHighlighter
|
||
{
|
||
Background = Ui.Pinsel("gelb", 0.35),
|
||
Foreground = Ui.Pinsel(""),
|
||
};
|
||
for (int i = text.IndexOf(s, StringComparison.OrdinalIgnoreCase); i >= 0; i = text.IndexOf(s, i + s.Length, StringComparison.OrdinalIgnoreCase))
|
||
h.Ranges.Add(new TextRange { StartIndex = i, Length = s.Length });
|
||
if (h.Ranges.Count > 0) t.TextHighlighters.Add(h);
|
||
}
|
||
|
||
// ---- Gedanken --------------------------------------------------------------------------------
|
||
|
||
/// <summary>"12:03:44 Hand 123 Flop: Raise 3 BB | Konfidenz 0,8 | Equity 45 % | Grund: ... | Ergebnis: gewonnen (+3 BB)"</summary>
|
||
private static readonly Regex Gedanke = new(@"^(\d\d:\d\d:\d\d)\s+(.*?):\s(.*)$", RegexOptions.Compiled);
|
||
|
||
internal static string AktionTon(string a) =>
|
||
a.StartsWith("Fold") ? "grau" : a.StartsWith("Check") || a.StartsWith("Call") ? "gruen"
|
||
: a.StartsWith("Raise") || a.StartsWith("Bet") || a.StartsWith("All") ? "orange" : "";
|
||
|
||
private void GedankenZeichnen()
|
||
{
|
||
var t = _angehalten ?? _z.Ansicht.Ticker;
|
||
var alle = t.Texte("gedanken").ToList();
|
||
var abdruck = "g" + t?["gedanken"].Abdruck();
|
||
if (abdruck == _abdruck) return;
|
||
_abdruck = abdruck;
|
||
var s = Suche;
|
||
var zeilen = alle.Where(x => s.Length == 0 || x.Contains(s, StringComparison.OrdinalIgnoreCase)).ToList();
|
||
_stand.Text = $"{zeilen.Count} von {alle.Count} Entscheidungen" + (_angehalten != null ? " · angehalten" : "");
|
||
_stand.Foreground = _angehalten != null ? Ui.Pinsel("orange") : Ui.Dritt;
|
||
_liste.Children.Clear();
|
||
_sichtbar = zeilen;
|
||
foreach (var roh in zeilen) _liste.Children.Add(GedankenZeile(roh));
|
||
if (_liste.Children.Count == 0)
|
||
_liste.Children.Add(alle.Count == 0
|
||
? Teile.Leer("Noch nichts", t.Text("leer") ?? "Je eigener Entscheidung erscheint hier eine Zeile.", "\uE7C3")
|
||
: LeerMitFilter());
|
||
}
|
||
|
||
private Grid GedankenZeile(string roh)
|
||
{
|
||
var m = Gedanke.Match(roh);
|
||
var g = new Grid { ColumnSpacing = 8, Padding = new Thickness(6, 6, 6, 7), CornerRadius = new CornerRadius(4) };
|
||
g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(3) });
|
||
g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(52) });
|
||
g.ColumnDefinitions.Add(new ColumnDefinition());
|
||
g.PointerEntered += (_, _) => g.Background = Ui.Weiss(0.04);
|
||
g.PointerExited += (_, _) => g.Background = null;
|
||
var kopie = new MenuFlyoutItem { Text = "Zeile kopieren", Icon = new FontIcon { Glyph = "\uE8C8" } };
|
||
kopie.Click += (_, _) => Kopieren(roh);
|
||
g.ContextFlyout = new MenuFlyout { Items = { kopie } };
|
||
if (!m.Success)
|
||
{
|
||
var t = new TextBlock { Text = roh, FontSize = 12.5, TextWrapping = TextWrapping.Wrap, IsTextSelectionEnabled = true };
|
||
Markieren(t, roh);
|
||
g.Children.Add(t.Spalte(2));
|
||
return g;
|
||
}
|
||
var teile = m.Groups[3].Value.Split(" | ").ToList();
|
||
var aktion = teile.FirstOrDefault() ?? "";
|
||
var ergebnis = teile.FirstOrDefault(x => x.StartsWith("Ergebnis: "))?["Ergebnis: ".Length..] ?? "";
|
||
var grund = teile.FirstOrDefault(x => x.StartsWith("Grund: "))?["Grund: ".Length..] ?? "";
|
||
var werte = teile.Skip(1).Where(x => !x.StartsWith("Ergebnis: ") && !x.StartsWith("Grund: ")).ToList();
|
||
string ergTon = ergebnis.StartsWith("gewonnen") ? "gruen" : ergebnis.StartsWith("verloren") ? "rot" : "grau";
|
||
|
||
g.Children.Add(new Border { CornerRadius = new CornerRadius(2), Background = Ui.Pinsel(AktionTon(aktion) is { Length: > 0 } at ? at : "grau", 0.8) });
|
||
g.Children.Add(new TextBlock { Text = m.Groups[1].Value, FontFamily = Fest, FontSize = 11, Foreground = Ui.Dritt, Margin = new Thickness(0, 1, 0, 0) }.Spalte(1));
|
||
|
||
var kopf = new Grid { ColumnSpacing = 8 };
|
||
kopf.ColumnDefinitions.Add(new ColumnDefinition());
|
||
kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
|
||
var titel = new TextBlock { FontSize = 12.5, TextWrapping = TextWrapping.Wrap, IsTextSelectionEnabled = true };
|
||
titel.Inlines.Add(new Run { Text = m.Groups[2].Value + " ", Foreground = Ui.Zweit });
|
||
titel.Inlines.Add(new Run { Text = aktion, Foreground = Ui.Pinsel(AktionTon(aktion)), FontWeight = FontWeights.SemiBold });
|
||
kopf.Children.Add(titel);
|
||
if (ergebnis.Length > 0)
|
||
kopf.Children.Add(Ui.Text(ergebnis == "offen" ? "offen" : ergebnis, 11, ergTon, fett: ergebnis != "offen", zahlen: true)
|
||
.Mit(t => { t.VerticalAlignment = VerticalAlignment.Top; t.MaxWidth = 150; }).Spalte(1));
|
||
var spalte = Ui.Spalte(2, kopf);
|
||
if (werte.Count > 0) spalte.Children.Add(Ui.Text(string.Join(" · ", werte), 11, pinsel: Ui.Zweit, zahlen: true));
|
||
if (grund.Length > 0)
|
||
{
|
||
var gt = new TextBlock { Text = grund, FontSize = 11.5, Foreground = Ui.Zweit, TextWrapping = TextWrapping.Wrap, IsTextSelectionEnabled = true };
|
||
Markieren(gt, grund);
|
||
spalte.Children.Add(gt);
|
||
}
|
||
g.Children.Add(spalte.Spalte(2));
|
||
return g;
|
||
}
|
||
|
||
// ---- Geld ------------------------------------------------------------------------------------
|
||
|
||
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 + "|" + Suche;
|
||
if (abdruck == _abdruck) return;
|
||
_abdruck = abdruck;
|
||
_liste.Children.Clear();
|
||
var s = Suche;
|
||
var zeilen = alle.Where(z => _art.Wahl == null || z.Text("art") == _art.Wahl)
|
||
.Where(z => s.Length == 0 || new[] { z.Text("art"), z.Text("raum"), z.Text("grund") }
|
||
.Any(x => x != null && x.Contains(s, StringComparison.OrdinalIgnoreCase))).ToList();
|
||
var summe = zeilen.Where(z => z.WahrOderNull("uebung") != true).Sum(z => z.Zahl("betrag") ?? 0);
|
||
_stand.Text = $"{zeilen.Count} von {alle.Count} Bewegungen" + (zeilen.Count > 0 ? $" · Summe {Format.Zahl(summe, 2)}" : "");
|
||
_stand.Foreground = Ui.Dritt;
|
||
_sichtbar = zeilen.Select(z => $"{Format.Uhr(z.Zahl("zeit"))} {z.T("art")} {Format.Zahl(z.Zahl("betrag"), 2)} {z.T("raum")} {z.T("grund")}").ToList();
|
||
if (zeilen.Count == 0)
|
||
{
|
||
_liste.Children.Add(alle.Count == 0
|
||
? Teile.Leer("Keine Geldbewegungen", g.Text("leer") ?? "Buy-in, Nachkauf und Aufstehen erscheinen hier.", "\uE8C7")
|
||
: LeerMitFilter());
|
||
return;
|
||
}
|
||
foreach (var z in zeilen)
|
||
{
|
||
var kopf = new Grid { ColumnSpacing = 6 };
|
||
foreach (var w in new[] { new GridLength(52), GridLength.Auto, GridLength.Auto, new GridLength(1, GridUnitType.Star), GridLength.Auto, GridLength.Auto })
|
||
kopf.ColumnDefinitions.Add(new ColumnDefinition { Width = w });
|
||
kopf.Children.Add(new TextBlock { Text = Format.Uhr(z.Zahl("zeit")), FontFamily = Fest, FontSize = 11, Foreground = Ui.Dritt, VerticalAlignment = VerticalAlignment.Center });
|
||
kopf.Children.Add(Ui.Text(z.Text("art") ?? "–", 13, 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), 13, Teile.Ton(b) ?? "", fett: true, zahlen: true).Spalte(4));
|
||
if (z.Zahl("betrag_bb") is double bb)
|
||
kopf.Children.Add(Ui.Text(Format.Auto(bb) + " bb", 11, pinsel: Ui.Zweit, zahlen: true).Spalte(5).Mit(t => t.VerticalAlignment = VerticalAlignment.Center));
|
||
var unter = new TextBlock
|
||
{
|
||
Text = Raum.Kurz(string.Join(" · ", new[] { z.Text("raum") is { } r ? Raum.Nummer(r) : null, z.Text("grund") }.Where(x => !string.IsNullOrEmpty(x)))),
|
||
FontSize = 11.5,
|
||
Foreground = Ui.Zweit,
|
||
TextWrapping = TextWrapping.Wrap,
|
||
IsTextSelectionEnabled = true,
|
||
Margin = new Thickness(58, 0, 0, 0),
|
||
};
|
||
var zeile = Ui.Spalte(2, kopf, unter);
|
||
zeile.Padding = new Thickness(6, 7, 6, 7);
|
||
zeile.Opacity = z.WahrOderNull("uebung") == true ? 0.7 : 1;
|
||
if (_liste.Children.Count > 0) _liste.Children.Add(Ui.Linie());
|
||
_liste.Children.Add(zeile);
|
||
}
|
||
}
|
||
}
|