120 lines
6.0 KiB
C#
120 lines
6.0 KiB
C#
using System.Text.Json.Nodes;
|
||
using Microsoft.UI.Xaml;
|
||
using Microsoft.UI.Xaml.Controls;
|
||
using Pokerfreak.Cockpit.Kern;
|
||
|
||
namespace Pokerfreak.Cockpit.Seiten;
|
||
|
||
/// <summary>
|
||
/// Die Verlustlimits (Verlustdeckel Sitzung und Tag) direkt im Cash-Reiter einstellen - Owner 17.11.:
|
||
/// "ich muss da zahlen raten". Eingeklappt eine Zeile (verbraucht/Deckel), aufgeklappt je Deckel eine
|
||
/// Auswahl fertiger Stufen (Buy-ins · BB · USDT der laufenden Stake) mit der Empfehlung und einem Knopf,
|
||
/// der sie uebernimmt. Alle Zahlen kommen vom Server (sicht/ansicht.deckel_ "einstellen", gerechnet in
|
||
/// betrieb/verlustdeckel.einstellen) - die App rechnet nichts. Gewaehlt wird ueber "deckel_einstellen";
|
||
/// ein laufender Laeufer laedt die Regeldatei nach. Eine schon gesetzte Sperre bleibt (Halteknopf).
|
||
/// </summary>
|
||
public sealed class LimitTeil : UserControl
|
||
{
|
||
private readonly CockpitZustand _z;
|
||
/// <summary>Kurz fuer die Falte.</summary>
|
||
public string Kurz { get; private set; } = "";
|
||
private readonly Zeile[] _zeilen;
|
||
private bool _zeichnet;
|
||
|
||
private sealed class Zeile
|
||
{
|
||
public string Was = "";
|
||
public readonly TextBlock Name = Ui.Text("", 13);
|
||
public readonly TextBlock Stand = Ui.Winzig("");
|
||
public readonly ProgressBar Balken = new() { Minimum = 0, Maximum = 1, Height = 3, MinHeight = 3 };
|
||
public readonly ComboBox Wahl = new() { FontSize = 12, MinWidth = 0, HorizontalAlignment = HorizontalAlignment.Stretch, Padding = new Thickness(8, 2, 4, 2) };
|
||
public readonly Ui.Info Empfehlung = new();
|
||
public readonly Button Uebernehmen = new() { Content = "Empfehlung nehmen", FontSize = 11, Padding = new Thickness(8, 1, 8, 2), MinHeight = 0 };
|
||
public readonly List<double> Werte = new();
|
||
public double? EmpfohlenBB;
|
||
public string Abdruck = "";
|
||
public StackPanel Block = null!;
|
||
}
|
||
|
||
public LimitTeil(CockpitZustand z)
|
||
{
|
||
_z = z;
|
||
_zeilen = new[] { new Zeile(), new Zeile() };
|
||
var inhalt = Ui.Spalte(14);
|
||
inhalt.Padding = new Thickness(12);
|
||
foreach (var zl in _zeilen)
|
||
{
|
||
var r = zl;
|
||
r.Wahl.SelectionChanged += (_, _) =>
|
||
{
|
||
if (_zeichnet || r.Wahl.SelectedIndex < 0 || r.Wahl.SelectedIndex >= r.Werte.Count) return;
|
||
_z.DeckelEinstellen(r.Was, r.Werte[r.Wahl.SelectedIndex]);
|
||
};
|
||
r.Uebernehmen.Click += (_, _) => { if (r.EmpfohlenBB is double bb) _z.DeckelEinstellen(r.Was, bb); };
|
||
ToolTipService.SetToolTip(r.Wahl, "Ab diesem Verlust stoppt der Läufer (Hand zu Ende, aufstehen) - zählt über Neustarts. Niedriger greift sofort; höher hebt eine schon gesetzte Sperre nicht auf - dafür den Halteknopf.");
|
||
var oben = new Grid { ColumnSpacing = 10 };
|
||
oben.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(62) });
|
||
oben.ColumnDefinitions.Add(new ColumnDefinition());
|
||
oben.Children.Add(r.Name.Mit(t => t.VerticalAlignment = VerticalAlignment.Center));
|
||
oben.Children.Add(r.Wahl.Spalte(1));
|
||
r.Stand.VerticalAlignment = VerticalAlignment.Center;
|
||
r.Block = Ui.Spalte(6, oben, r.Balken, Ui.Zeile(Ui.Reihe(0, r.Stand, r.Empfehlung), r.Uebernehmen));
|
||
inhalt.Children.Add(r.Block);
|
||
}
|
||
Content = inhalt;
|
||
}
|
||
|
||
/// <summary>`deckel`: a.Geld.deckel vom Server; ohne "einstellen" (noch keine Echtgeld-Hand) unsichtbar.</summary>
|
||
public void Zeichnen(JsonObject? deckel, bool sichtbar)
|
||
{
|
||
var ein = deckel?["einstellen"] as JsonArray;
|
||
Visibility = sichtbar && ein is { Count: > 0 } ? Visibility.Visible : Visibility.Collapsed;
|
||
if (Visibility != Visibility.Visible) return;
|
||
_zeichnet = true;
|
||
try
|
||
{
|
||
var kacheln = deckel.Objekte("kacheln").ToList();
|
||
var kurz = new List<string>();
|
||
for (int i = 0; i < _zeilen.Length; i++)
|
||
{
|
||
var r = _zeilen[i];
|
||
var e = i < ein!.Count ? ein[i] as JsonObject : null;
|
||
r.Block.Visibility = e is null ? Visibility.Collapsed : Visibility.Visible;
|
||
if (e is null) continue;
|
||
r.Was = e.T("was");
|
||
var name = e.T("name");
|
||
var deckelBB = e.Zahl("bb") ?? 0;
|
||
var k = i < kacheln.Count ? kacheln[i] : null;
|
||
var verlust = Math.Max(0, -(k.Zahl("bb") ?? 0));
|
||
var anteil = k.Zahl("anteil") ?? 0;
|
||
r.Name.Text = name;
|
||
r.Stand.Text = verlust < 0.5 ? $"noch nichts verloren · Deckel {Format.Zahl(deckelBB)} BB" : $"−{Format.Zahl(verlust)} von {Format.Zahl(deckelBB)} BB";
|
||
r.Balken.Value = Math.Clamp(anteil, 0, 1);
|
||
r.Balken.Foreground = Ui.Pinsel(k.Text("ton") ?? "gruen");
|
||
kurz.Add($"{name} {Format.Zahl(deckelBB)} BB");
|
||
|
||
var optionen = e.Objekte("optionen").ToList();
|
||
var abdruck = string.Join("|", optionen.Select(o => $"{o.T("text")}{o.Wahr("empfohlen")}{o.Wahr("gewaehlt")}"));
|
||
if (abdruck != r.Abdruck)
|
||
{
|
||
r.Abdruck = abdruck;
|
||
r.Wahl.Items.Clear();
|
||
r.Werte.Clear();
|
||
foreach (var o in optionen)
|
||
{
|
||
r.Wahl.Items.Add(o.T("text") + (o.Wahr("empfohlen") ? " ★" : ""));
|
||
r.Werte.Add(o.Zahl("bb") ?? 0);
|
||
}
|
||
r.Wahl.SelectedIndex = optionen.FindIndex(o => o.Wahr("gewaehlt"));
|
||
}
|
||
r.EmpfohlenBB = e.Zahl("empfohlen_bb");
|
||
var aufEmpfehlung = r.EmpfohlenBB is double eb && Math.Abs(eb - deckelBB) < 1e-6;
|
||
r.Empfehlung.Setzen(e.T("empfehlung"));
|
||
r.Uebernehmen.Visibility = aufEmpfehlung ? Visibility.Collapsed : Visibility.Visible;
|
||
}
|
||
Kurz = string.Join(" · ", kurz);
|
||
}
|
||
finally { _zeichnet = false; }
|
||
}
|
||
}
|