diff --git a/cockpit/src/bruecke.rs b/cockpit/src/bruecke.rs index 7fd1f604..6c707a65 100644 --- a/cockpit/src/bruecke.rs +++ b/cockpit/src/bruecke.rs @@ -115,7 +115,8 @@ fn zeigen(f: &Cockpit) { meldung_ok: a.meldung_ok, }; f.set_lage(z); - f.set_nur_spiel(crate::umfang::nur_spiel()); + // Zuschauer bleibt immer sichtbar (16.11.) - nur-spiel blendet in der Oberflaeche nur ihn aus + f.set_nur_spiel(false); let zeilen: Vec = a .karten .iter() diff --git a/cockpit/src/umfang.rs b/cockpit/src/umfang.rs index 5a49254c..63bf4259 100644 --- a/cockpit/src/umfang.rs +++ b/cockpit/src/umfang.rs @@ -1,6 +1,6 @@ //! Wie viel das Cockpit zeigt. Vorgabe (seit 15.11. 23:30 immer, Owner mehrfach): nur Cash Game //! NLH und Turniere stehen (Owner 15.11.: "alle modi disablen außer cash und turniere, nur noch NLH"): -//! weg sind PLO, die Sonderformate (All-In or Fold, Bomb Pot, K-Poker) und der Zuschauer-Modus. +//! weg sind PLO und die Sonderformate (All-In or Fold, Bomb Pot, K-Poker); der Zuschauer bleibt (16.11.). //! Ausgeblendete Formate fliegen auch aus der Wahl, damit der Laeufer sie nicht mehr spielt. Uebung //! bleibt, damit ein Start nicht nur noch mit Echtgeld geht. (Spiegel: winui/Kern/Umfang.cs.) //! Lehrer & Stimme, Streamer und das Klon-Abzeichen gibt es in diesem Cockpit (noch) nicht. diff --git a/mac/Sources/Cockpit/Spielplan.swift b/mac/Sources/Cockpit/Spielplan.swift index 68188b85..4c66ff6b 100644 --- a/mac/Sources/Cockpit/Spielplan.swift +++ b/mac/Sources/Cockpit/Spielplan.swift @@ -10,7 +10,7 @@ struct ModusSchalter: View { let zuschauen = cockpit.zuschauen let cash = cockpit.wahl.cash && !zuschauen HStack(spacing: 0) { - if !Umfang.nurSpiel { teil("Zuschauer", an: zuschauen, farbe: .teal) { cockpit.zuschauenWaehlen() } } + teil("Zuschauer", an: zuschauen, farbe: .teal) { cockpit.zuschauenWaehlen() } // bleibt immer (16.11.) teil("Übung", an: !cash && !zuschauen, farbe: .blue) { cockpit.modusWaehlen(cash: false) } teil("Echtgeld", an: cash, farbe: .red) { cockpit.modusWaehlen(cash: true) } } @@ -20,7 +20,7 @@ struct ModusSchalter: View { .animation(.snappy, value: zuschauen) .disabled(cockpit.laeuft == true) .help(cockpit.laeuft == true ? "Erst aufhören, dann den Modus wechseln" - : Umfang.nurSpiel ? "Übung: Claim Chips · Cash: Geld" : "Zuschauer: liest nur, klickt nie · Übung: Claim Chips · Cash: Geld") + : "Zuschauer: liest nur, klickt nie · Übung: Claim Chips · Cash: Geld") } private func teil(_ titel: String, an: Bool, farbe: Color, _ tun: @escaping () -> Void) -> some View { diff --git a/mac/Sources/Cockpit/Umfang.swift b/mac/Sources/Cockpit/Umfang.swift index bce3f883..921087e2 100644 --- a/mac/Sources/Cockpit/Umfang.swift +++ b/mac/Sources/Cockpit/Umfang.swift @@ -4,7 +4,7 @@ import Foundation /// Wie viel das Cockpit zeigt (wie winui/Kern/Umfang.cs und das Rust-Cockpit). Vorgabe (seit 15.11. /// 23:30 immer; nur `--alles` oder POKERFREAK_NUR_SPIEL=0 zeigt alles): nur Cash Game NLH und Turniere (Owner 15.11.: "alle modi /// disablen außer cash und turniere, nur noch NLH"): weg sind PLO, die Sonderformate (All-In or Fold, -/// Bomb Pot, K-Poker), der Zuschauer-Modus, Lehrer & Stimme, Streamer (samt Maus-Schalter) und das +/// Bomb Pot, K-Poker), Lehrer & Stimme, Streamer (samt Maus-Schalter) und das /// Klon-Abzeichen. Ausgeblendete Formate fliegen auch aus der Wahl, damit der Laeufer sie nicht mehr /// spielt. Übung bleibt, damit ein Start nicht nur noch mit Echtgeld geht. enum Umfang { diff --git a/winui/Kern/Umfang.cs b/winui/Kern/Umfang.cs index c5d54fd7..9b7f4244 100644 --- a/winui/Kern/Umfang.cs +++ b/winui/Kern/Umfang.cs @@ -3,9 +3,10 @@ namespace Pokerfreak.Cockpit.Kern; /// /// Wie viel das Cockpit zeigt. Vorgabe: nur Cash Game NLH und /// Turniere stehen (Owner 15.11.: "alle modi disablen außer cash und turniere, nur noch NLH"): -/// weg sind PLO, die Sonderformate (All-In or Fold, Bomb Pot, K-Poker), der Zuschauer-Modus, +/// weg sind PLO, die Sonderformate (All-In or Fold, Bomb Pot, K-Poker), /// Lehrer & Stimme, Streamer (samt Maus-Schalter) und das Klon-Abzeichen. Ausgeblendete Formate fliegen -/// auch aus der Wahl, damit der Laeufer sie nicht mehr spielt. Übung bleibt, damit ein Start nicht nur +/// auch aus der Wahl, damit der Laeufer sie nicht mehr spielt. Der Zuschauer bleibt (16.11.: er spielt +/// nicht, er liest nur mit). Übung bleibt, damit ein Start nicht nur /// noch mit Echtgeld geht. (Spiegel: mac/Sources/Cockpit/Umfang.swift, cockpit/src/umfang.rs.) /// Seit 15.11. 23:30 IMMER so (Owner, mehrfach: das Cockpit lief einmal ohne `--nur-spiel` aus der /// Taskleiste und zeigte alles wieder). Nur `--alles` oder POKERFREAK_NUR_SPIEL=0 zeigt alles. diff --git a/winui/Seiten/CashSeite.cs b/winui/Seiten/CashSeite.cs index a5e05938..46f1697f 100644 --- a/winui/Seiten/CashSeite.cs +++ b/winui/Seiten/CashSeite.cs @@ -1,724 +1,719 @@ -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; - -/// -/// 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. -/// -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 }; - - // Turniere (TurnierBereich: Plan aus der Wahl, Anmeldungen aus dem Kopf) - private readonly Border _turnierPlan; - private readonly TextBox _buyinMin = Zahlfeld("ab"), _buyinMax = Zahlfeld("bis"), _fenster = Zahlfeld("alle", 56); - private readonly ComboBox _turnierTyp = new() { FontSize = 12, MinWidth = 0, Width = 118, Padding = new Thickness(8, 2, 4, 2) }; - private readonly ToggleSwitch _nurLaufend = new() { OnContent = "", OffContent = "", MinWidth = 0, Width = 44 }; - private readonly Border _anmeldungen = Ui.Flaeche(null, 10, 0.06, 10); - - // 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; - private readonly ZuschauerTeil _zuschauer; - - public CashSeite(CockpitZustand z) - { - _z = z; - _live = new LiveTeil(z); - _zuschauer = new ZuschauerTeil(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)); - } - // --nur-spiel: ohne Zuschauer, nur Übung | Echtgeld - if (Umfang.NurSpiel) - { - modus.ColumnDefinitions[0].Width = new GridLength(0); - _modusTipp[0].Visibility = Visibility.Collapsed; - } - var modusKapsel = new Border { Background = Ui.Weiss(0.07), CornerRadius = new CornerRadius(19), Padding = new Thickness(3), Child = modus }; - ToolTipService.SetToolTip(modusKapsel, Umfang.NurSpiel ? "Übung: Claim Chips · Echtgeld: Geld" - : "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)); - // Die Plan-Kachel oeffnet den Plan-Editor (PlanEditor.swift `PlanKachel`) - var planKachel = Kachel(Ui.Winzig("Plan"), _planWert, _planFuss); - kacheln.Children.Add(planKachel.Tippen(() => _z.EinstellungenOeffnen(EinstellungenSeite.ZeitenUndGeld), 14, - "Wie lange, wie oft, zu welchen Uhrzeiten, welches Geld – öffnet die Einstellungen").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); - - // ---- Turniere (TurnierBereich.swift, cockpit/ui/cash.slint) --------------------------------- - foreach (var (n, _) in Turnierplan.Typen) _turnierTyp.Items.Add(n); - _turnierTyp.SelectionChanged += (_, _) => - { - if (_zeichnet || _turnierTyp.SelectedIndex < 0) return; - TurnierAendern(t => t.TypSetzen(_turnierTyp.SelectedIndex)); - }; - _nurLaufend.Toggled += (_, _) => { if (!_zeichnet) TurnierAendern(t => t.NurLaufend = _nurLaufend.IsOn); }; - ToolTipService.SetToolTip(_nurLaufend, "Nur Turniere, die schon laufen (Late-Reg offen)"); - Uebernehmen(_buyinMin, x => TurnierAendern(t => t.BuyinMin = Turnierplan.BetragLesen(x))); - Uebernehmen(_buyinMax, x => TurnierAendern(t => t.BuyinMax = Turnierplan.BetragLesen(x))); - Uebernehmen(_fenster, x => TurnierAendern(t => t.FensterMin = Turnierplan.MinutenLesen(x))); - TextBlock Fett(string t) => Ui.Text(t, 12, fett: true).Mit(x => x.VerticalAlignment = VerticalAlignment.Center); - TextBlock Leise(string t) => Ui.Winzig(t).Mit(x => x.VerticalAlignment = VerticalAlignment.Center); - _turnierPlan = Ui.Flaeche(Ui.Spalte(8, - Ui.Zeile(Ui.Reihe(6, Ui.Zeichen("\uE7C1", 12), Fett("Turniere")), Leise("höchstes Preisgeld zuerst")), - Ui.Reihe(8, Fett("Buy-in"), _buyinMin, Leise("–"), _buyinMax), - Ui.Klein("Das Buy-in-Band gilt nur für bezahlte Turniere – Freerolls sind frei und immer dabei.", true), - Ui.Zeile(Ui.Reihe(8, Fett("Typ"), _turnierTyp), Ui.Reihe(6, Leise("nur laufende"), _nurLaufend)), - Ui.Reihe(8, Fett("Startet in"), _fenster, Leise("Min oder weniger")), - Ui.Klein("Anmeldung wird noch gemessen - Auswahl und Band greifen, der Live-Beitritt ist in Erprobung.", true)), - 10, 0.06, 10); - - // ---- 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, _turnierPlan, _anmeldungen, - _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 = Ui.Spalte(0, _live, _zuschauer), - 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; - } - - /// Eine Instrument-Kachel (Spielplan.swift `Kachel`): Titel klein, Inhalt 30 hoch, Fuss klein. - 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); - } - - /// Ein Stepper wie am Mac: zwei kleine Knoepfe in einer Kapsel. - 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 static TextBox Zahlfeld(string platzhalter, double breite = 66) => new() - { - PlaceholderText = platzhalter, - FontSize = 12, - Width = breite, - MinWidth = 0, - MinHeight = 0, - Padding = new Thickness(8, 3, 6, 3), - }; - - /// Ein Feld uebernimmt bei Enter oder beim Verlassen (nicht bei jedem Tastendruck). - private void Uebernehmen(TextBox feld, Action tun) - { - string? zuletzt = null; - void Los() - { - if (_zeichnet || feld.Text == zuletzt) return; - zuletzt = feld.Text; - tun(feld.Text); - } - feld.KeyDown += (_, e) => { if (e.Key == Windows.System.VirtualKey.Enter) Los(); }; - feld.LostFocus += (_, _) => Los(); - feld.GotFocus += (_, _) => zuletzt = feld.Text; - } - - /// Eine Aenderung am Turnierplan: in die Wahl schreiben (nur wenn gesetzt), dann wie jede Eingabe. - private void TurnierAendern(Action tun) => _z.Eingabe(w => - { - var t = Turnierplan.Aus(w.Turnier); - tun(t); - w.Turnier = t.Daten(); - }); - - 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; } - // Solange der Zuschauer laeuft, steht seine Sicht an Stelle der Live-Ansicht (Wurzel.swift) - var zuschauen = _z.Ansicht.Zuschauen; - _live.Visibility = zuschauen ? Visibility.Collapsed : Visibility.Visible; - _zuschauer.Visibility = zuschauen ? Visibility.Visible : Visibility.Collapsed; - if (zuschauen) _zuschauer.Zeichnen(); - else _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. "Micro only": nur die - // Stakes-Kappe und die Tischzahl zaehlen - das Budget ist aus (betrieb/spielplan.wirksames_guthaben). - bool budgetAus = w.Cash && w.MicroOnly; - _geldTitel.Text = w.Cash ? "Budget" : "Geld"; - _budget.Visibility = Sichtbar(w.Cash && !budgetAus); - _geldWert.Visibility = Sichtbar(!w.Cash || budgetAus); - _geldWert.Text = budgetAus ? "aus" : "Chips"; - _geldFuss.Text = budgetAus ? "Micro only: ganzes Guthaben" - : w.Cash ? $"{w.ReserveBuyins} Buy-ins/Tisch" : $"Buy-in {(w.KaufMax ? "Max" : "Min")}"; - if (w.Cash && !budgetAus && _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); - Turniere(w, k, zuschauen); - - // 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; - } - - /// Der Turnier-Bereich: der Plan nur mit Turnier-Tischen in der Wahl, die eigenen - /// Anmeldungen (vom Server fertig) mit "Abmelden", sobald es welche gibt. - private void Turniere(Spielplan w, System.Text.Json.Nodes.JsonObject? k, bool zuschauen) - { - var t = Turnierplan.Aus(w.Turnier); - _turnierPlan.Visibility = Sichtbar(!zuschauen && w.Anzahl(SpielFormat.Turnier) > 0); - if (_buyinMin.FocusState == FocusState.Unfocused) _buyinMin.Text = Turnierplan.BetragText(t.BuyinMin); - if (_buyinMax.FocusState == FocusState.Unfocused) _buyinMax.Text = Turnierplan.BetragText(t.BuyinMax); - if (_fenster.FocusState == FocusState.Unfocused) _fenster.Text = t.FensterMin?.ToString() ?? ""; - _turnierTyp.SelectedIndex = t.TypIndex; - _nurLaufend.IsOn = t.NurLaufend; - - var liste = k.Objekte("turnier_anmeldungen").Where(a => a.Text("raum") != null).ToList(); - var abdruck = string.Join("|", liste.Select(a => $"{a.Text("raum")}:{a.Text("name")}:{a.Text("status")}")); - if ((string?)_anmeldungen.Tag != abdruck) - { - _anmeldungen.Tag = abdruck; - var s = Ui.Spalte(6, Ui.Text($"Angemeldet ({liste.Count})", 12, fett: true)); - foreach (var a in liste) - { - var raum = a.Text("raum")!; - var name = Ui.Spalte(0, Ui.Text(a.Text("name") ?? raum, 12).Mit(x => x.TextTrimming = TextTrimming.CharacterEllipsis)); - if (a.Text("status") is string st) name.Children.Add(Ui.Winzig(st)); - name.VerticalAlignment = VerticalAlignment.Center; - var ab = new Button { Content = "Abmelden", FontSize = 11, Padding = new Thickness(8, 2, 8, 3), MinHeight = 0 }; - ab.Click += async (_, _) => await _z.SendenRaum(raum, ("turnier_abmelden", null)); - ToolTipService.SetToolTip(ab, "Vom Turnier abmelden (solange es noch nicht begonnen hat)"); - s.Children.Add(Ui.Zeile(name, ab)); - } - _anmeldungen.Child = s; - } - _anmeldungen.Visibility = Sichtbar(liste.Count > 0); - } - - /// "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. - 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); - // --nur-spiel: nur Cash NLH und Turnier - reihe.RemoveAll(f => !Umfang.Erlaubt(f)); - 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; - } -} - -/// Not-Aus (Wurzel.swift `NotAusKnopf`): runder roter Knopf, ein Klick haelt sofort an. -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"); - } -} - -/// 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. -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", - _ => "", - }; -} +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; + +/// +/// 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. +/// +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 }; + + // Turniere (TurnierBereich: Plan aus der Wahl, Anmeldungen aus dem Kopf) + private readonly Border _turnierPlan; + private readonly TextBox _buyinMin = Zahlfeld("ab"), _buyinMax = Zahlfeld("bis"), _fenster = Zahlfeld("alle", 56); + private readonly ComboBox _turnierTyp = new() { FontSize = 12, MinWidth = 0, Width = 118, Padding = new Thickness(8, 2, 4, 2) }; + private readonly ToggleSwitch _nurLaufend = new() { OnContent = "", OffContent = "", MinWidth = 0, Width = 44 }; + private readonly Border _anmeldungen = Ui.Flaeche(null, 10, 0.06, 10); + + // 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; + private readonly ZuschauerTeil _zuschauer; + + public CashSeite(CockpitZustand z) + { + _z = z; + _live = new LiveTeil(z); + _zuschauer = new ZuschauerTeil(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)); + } + // Zuschauer bleibt immer (Owner 16.11.: "in swift gibts einen spectator mode") - er spielt nicht, + // er liest nur mit; nur die Spielformate schraenkt Umfang ein. + 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)); + // Die Plan-Kachel oeffnet den Plan-Editor (PlanEditor.swift `PlanKachel`) + var planKachel = Kachel(Ui.Winzig("Plan"), _planWert, _planFuss); + kacheln.Children.Add(planKachel.Tippen(() => _z.EinstellungenOeffnen(EinstellungenSeite.ZeitenUndGeld), 14, + "Wie lange, wie oft, zu welchen Uhrzeiten, welches Geld – öffnet die Einstellungen").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); + + // ---- Turniere (TurnierBereich.swift, cockpit/ui/cash.slint) --------------------------------- + foreach (var (n, _) in Turnierplan.Typen) _turnierTyp.Items.Add(n); + _turnierTyp.SelectionChanged += (_, _) => + { + if (_zeichnet || _turnierTyp.SelectedIndex < 0) return; + TurnierAendern(t => t.TypSetzen(_turnierTyp.SelectedIndex)); + }; + _nurLaufend.Toggled += (_, _) => { if (!_zeichnet) TurnierAendern(t => t.NurLaufend = _nurLaufend.IsOn); }; + ToolTipService.SetToolTip(_nurLaufend, "Nur Turniere, die schon laufen (Late-Reg offen)"); + Uebernehmen(_buyinMin, x => TurnierAendern(t => t.BuyinMin = Turnierplan.BetragLesen(x))); + Uebernehmen(_buyinMax, x => TurnierAendern(t => t.BuyinMax = Turnierplan.BetragLesen(x))); + Uebernehmen(_fenster, x => TurnierAendern(t => t.FensterMin = Turnierplan.MinutenLesen(x))); + TextBlock Fett(string t) => Ui.Text(t, 12, fett: true).Mit(x => x.VerticalAlignment = VerticalAlignment.Center); + TextBlock Leise(string t) => Ui.Winzig(t).Mit(x => x.VerticalAlignment = VerticalAlignment.Center); + _turnierPlan = Ui.Flaeche(Ui.Spalte(8, + Ui.Zeile(Ui.Reihe(6, Ui.Zeichen("\uE7C1", 12), Fett("Turniere")), Leise("höchstes Preisgeld zuerst")), + Ui.Reihe(8, Fett("Buy-in"), _buyinMin, Leise("–"), _buyinMax), + Ui.Klein("Das Buy-in-Band gilt nur für bezahlte Turniere – Freerolls sind frei und immer dabei.", true), + Ui.Zeile(Ui.Reihe(8, Fett("Typ"), _turnierTyp), Ui.Reihe(6, Leise("nur laufende"), _nurLaufend)), + Ui.Reihe(8, Fett("Startet in"), _fenster, Leise("Min oder weniger")), + Ui.Klein("Anmeldung wird noch gemessen - Auswahl und Band greifen, der Live-Beitritt ist in Erprobung.", true)), + 10, 0.06, 10); + + // ---- 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, _turnierPlan, _anmeldungen, + _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 = Ui.Spalte(0, _live, _zuschauer), + 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; + } + + /// Eine Instrument-Kachel (Spielplan.swift `Kachel`): Titel klein, Inhalt 30 hoch, Fuss klein. + 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); + } + + /// Ein Stepper wie am Mac: zwei kleine Knoepfe in einer Kapsel. + 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 static TextBox Zahlfeld(string platzhalter, double breite = 66) => new() + { + PlaceholderText = platzhalter, + FontSize = 12, + Width = breite, + MinWidth = 0, + MinHeight = 0, + Padding = new Thickness(8, 3, 6, 3), + }; + + /// Ein Feld uebernimmt bei Enter oder beim Verlassen (nicht bei jedem Tastendruck). + private void Uebernehmen(TextBox feld, Action tun) + { + string? zuletzt = null; + void Los() + { + if (_zeichnet || feld.Text == zuletzt) return; + zuletzt = feld.Text; + tun(feld.Text); + } + feld.KeyDown += (_, e) => { if (e.Key == Windows.System.VirtualKey.Enter) Los(); }; + feld.LostFocus += (_, _) => Los(); + feld.GotFocus += (_, _) => zuletzt = feld.Text; + } + + /// Eine Aenderung am Turnierplan: in die Wahl schreiben (nur wenn gesetzt), dann wie jede Eingabe. + private void TurnierAendern(Action tun) => _z.Eingabe(w => + { + var t = Turnierplan.Aus(w.Turnier); + tun(t); + w.Turnier = t.Daten(); + }); + + 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; } + // Solange der Zuschauer laeuft, steht seine Sicht an Stelle der Live-Ansicht (Wurzel.swift) + var zuschauen = _z.Ansicht.Zuschauen; + _live.Visibility = zuschauen ? Visibility.Collapsed : Visibility.Visible; + _zuschauer.Visibility = zuschauen ? Visibility.Visible : Visibility.Collapsed; + if (zuschauen) _zuschauer.Zeichnen(); + else _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. "Micro only": nur die + // Stakes-Kappe und die Tischzahl zaehlen - das Budget ist aus (betrieb/spielplan.wirksames_guthaben). + bool budgetAus = w.Cash && w.MicroOnly; + _geldTitel.Text = w.Cash ? "Budget" : "Geld"; + _budget.Visibility = Sichtbar(w.Cash && !budgetAus); + _geldWert.Visibility = Sichtbar(!w.Cash || budgetAus); + _geldWert.Text = budgetAus ? "aus" : "Chips"; + _geldFuss.Text = budgetAus ? "Micro only: ganzes Guthaben" + : w.Cash ? $"{w.ReserveBuyins} Buy-ins/Tisch" : $"Buy-in {(w.KaufMax ? "Max" : "Min")}"; + if (w.Cash && !budgetAus && _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); + Turniere(w, k, zuschauen); + + // 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; + } + + /// Der Turnier-Bereich: der Plan nur mit Turnier-Tischen in der Wahl, die eigenen + /// Anmeldungen (vom Server fertig) mit "Abmelden", sobald es welche gibt. + private void Turniere(Spielplan w, System.Text.Json.Nodes.JsonObject? k, bool zuschauen) + { + var t = Turnierplan.Aus(w.Turnier); + _turnierPlan.Visibility = Sichtbar(!zuschauen && w.Anzahl(SpielFormat.Turnier) > 0); + if (_buyinMin.FocusState == FocusState.Unfocused) _buyinMin.Text = Turnierplan.BetragText(t.BuyinMin); + if (_buyinMax.FocusState == FocusState.Unfocused) _buyinMax.Text = Turnierplan.BetragText(t.BuyinMax); + if (_fenster.FocusState == FocusState.Unfocused) _fenster.Text = t.FensterMin?.ToString() ?? ""; + _turnierTyp.SelectedIndex = t.TypIndex; + _nurLaufend.IsOn = t.NurLaufend; + + var liste = k.Objekte("turnier_anmeldungen").Where(a => a.Text("raum") != null).ToList(); + var abdruck = string.Join("|", liste.Select(a => $"{a.Text("raum")}:{a.Text("name")}:{a.Text("status")}")); + if ((string?)_anmeldungen.Tag != abdruck) + { + _anmeldungen.Tag = abdruck; + var s = Ui.Spalte(6, Ui.Text($"Angemeldet ({liste.Count})", 12, fett: true)); + foreach (var a in liste) + { + var raum = a.Text("raum")!; + var name = Ui.Spalte(0, Ui.Text(a.Text("name") ?? raum, 12).Mit(x => x.TextTrimming = TextTrimming.CharacterEllipsis)); + if (a.Text("status") is string st) name.Children.Add(Ui.Winzig(st)); + name.VerticalAlignment = VerticalAlignment.Center; + var ab = new Button { Content = "Abmelden", FontSize = 11, Padding = new Thickness(8, 2, 8, 3), MinHeight = 0 }; + ab.Click += async (_, _) => await _z.SendenRaum(raum, ("turnier_abmelden", null)); + ToolTipService.SetToolTip(ab, "Vom Turnier abmelden (solange es noch nicht begonnen hat)"); + s.Children.Add(Ui.Zeile(name, ab)); + } + _anmeldungen.Child = s; + } + _anmeldungen.Visibility = Sichtbar(liste.Count > 0); + } + + /// "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. + 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); + // --nur-spiel: nur Cash NLH und Turnier + reihe.RemoveAll(f => !Umfang.Erlaubt(f)); + 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; + } +} + +/// Not-Aus (Wurzel.swift `NotAusKnopf`): runder roter Knopf, ein Klick haelt sofort an. +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"); + } +} + +/// 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. +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", + _ => "", + }; +}