Files
pokerfreak/mac/Sources/Cockpit/TurnierBereich.swift
T
mmintelandClaude Opus 5.5 383f125769 Mac cockpit: catch up with WinUI (server-built live views, stakes, limits, sammler, statistik)
WinUI is ahead; the Swift app now draws what sicht/ precomputes instead of
computing its own views:
- Spielen page: live tables from sitzen.live (raster, kacheln, bereit, search,
  close question), "Gerade eben" from entscheidungen.feed, money from geld.anzeige
- Stakes priority with tables per stake (spielplan.stufen/stufen_tische);
  micro_only is gone
- Loss limits (deckel_einstellen), sammler in Zuschauer mode (main button
  becomes Sammeln starten/stoppen), "Nur offene Tische spielen", queue
- Statistik: full auswertung (key figures, EV/SD curve, bb/100 by ...,
  history, best times, play/opponent picture, tournaments)
- Small items: Spickzettel, streamer toggle, sendung_lesen, daily limits editor

Intentional deviations: "highest first" compares instead of 1e15 + bb (WinUI
cannot separate NL2 and NL5 there), a single table shows its tile, narrow
segment pickers fall back to menus. Plan: plans/2026-11-30_swift-winui-abgleich.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 09:55:51 +01:00

138 lines
7.5 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
import CockpitKern
import SwiftUI
/// Eigener Steuerbereich für Turniere (Owner 7.11.: "eigener UI-Bereich, mehr Buy-in-Kontrolle").
/// Erscheint, sobald ein Turnierformat (Turnier/Freerolls/VIP) im Plan Tische hat. Setzt das
/// Buy-in-Band, den Typ-Filter (die CoinPoker-Kategorie Daily/Satellite/PGT/Freeroll/VIP) und
/// Late-Reg - gebunden an cockpit.wahl.turnier (CockpitKern.Turnierplan), gelesen vom Selektor
/// lesen/turnier_anmeldung.waehle (Kategorie über ist_kategorie). EHRLICH: der Live-Anmelde-
/// Transport ist noch nicht bestätigt.
struct TurnierBereich: View {
@Environment(Cockpit.self) private var cockpit
/// Es gibt EINE Turnier-Kachel; Freerolls/VIP sind Typen darunter (Owner 9.11.), keine eigenen
/// Kacheln mehr. Der Bereich erscheint, sobald die Turnier-Kachel Tische hat.
private static let turnierFormate: [SpielFormat] = [.turnier]
/// Typ-Filter: die CoinPoker-Kategorien (nil = alle). Der Selektor erkennt sie über
/// lesen/turnier_anmeldung.ist_kategorie - zuverlässiger als ein roher Namensteil.
private static let typen: [(String, String?)] =
[("Alle", nil), ("Daily", "Daily"), ("Satellite", "Satellite"), ("PGT", "PGT"),
("Freerolls", "Freeroll"), ("VIP", "VIP")]
/// Welcher Teil: der Plan (in "Was spielen") oder die Anmeldungen (oben auf der Spielseite, wie WinUI).
enum Teil { case plan, anmeldungen }
var teil: Teil
var body: some View {
let aktiv = Self.turnierFormate.contains { cockpit.wahl.anzahl($0) > 0 }
let anmeldungen = cockpit.ansicht.kopf?.turnierAnmeldungen ?? []
return VStack(alignment: .leading, spacing: 8) {
if teil == .plan, aktiv, !cockpit.zuschauen { planEditor }
if teil == .anmeldungen, !anmeldungen.isEmpty { anmeldungenListe(anmeldungen) }
}
}
/// Die eigenen Anmeldungen (lesen/turnier_verwaltung.uebersicht) mit Abmelden-Knopf je Zeile.
/// Abmelden sendet die Steuer-Aktion turnier_abmelden -> ta.anmelden_connector(raum, to_register=False).
private func anmeldungenListe(_ liste: [TurnierAnmeldung]) -> some View {
VStack(alignment: .leading, spacing: 6) {
Label("Angemeldet (\(liste.count))", systemImage: "checkmark.seal")
.font(.caption.weight(.semibold))
ForEach(liste) { a in
HStack(spacing: 8) {
VStack(alignment: .leading, spacing: 1) {
Text(a.name ?? a.raum).font(.caption.weight(.medium)).lineLimit(1)
if let s = a.status, !s.isEmpty {
Text(s).font(.caption2).foregroundStyle(.secondary)
}
}
Spacer(minLength: 0)
Button("Abmelden") { cockpit.steuern("turnier_abmelden", raum: a.raum) }
.buttonStyle(.bordered).controlSize(.small)
}
}
}
.padding(10)
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 14))
}
/// Der Plan-Editor (Buy-in-Band, Typ, Late-Reg) - sichtbar, sobald ein Turnierformat Tische hat.
private var planEditor: some View {
VStack(alignment: .leading, spacing: 8) {
HStack(alignment: .firstTextBaseline) {
Label("Turniere", systemImage: "trophy").font(.caption.weight(.semibold))
Spacer()
Text("höchstes Preisgeld zuerst").font(.caption2).foregroundStyle(.secondary)
}
HStack(spacing: 8) {
Text("Buy-in").font(.caption.weight(.medium))
feld("ab", wert: bindung(\.buyinMin))
Text("–").foregroundStyle(.secondary)
feld("bis", wert: bindung(\.buyinMax))
Spacer(minLength: 0)
}
.font(.caption)
Text("Das Buy-in-Band gilt nur für bezahlte Turniere – Freerolls sind frei und immer dabei.")
.font(.caption2).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
HStack(spacing: 8) {
Text("Typ").font(.caption.weight(.medium))
Picker("", selection: typWahl) {
ForEach(Self.typen, id: \.0) { Text($0.0).tag($0.1 as String?) }
}
.pickerStyle(.menu).labelsHidden().fixedSize()
Spacer(minLength: 0)
Toggle(isOn: Binding(get: { cockpit.wahl.turnier.nurLaufend },
set: { cockpit.wahl.turnier.nurLaufend = $0 })) {
Text("nur laufende").font(.caption)
}
.toggleStyle(.switch).controlSize(.mini).fixedSize()
.help("Nur Late-Reg/laufende Turniere wählen - dann sitzt der Läufer sofort, statt auf den Start zu warten.")
}
HStack(spacing: 8) {
Text("Startet in").font(.caption.weight(.medium))
TextField("alle", text: fensterBindung)
.textFieldStyle(.roundedBorder).frame(width: 52).monospacedDigit()
Text("Min oder weniger").font(.caption).foregroundStyle(.secondary)
Spacer(minLength: 0)
}
.help("Nur Turniere anmelden, die in den nächsten N Minuten starten (leer = alle; z. B. 60 für die nächste Stunde).")
Label("Anmeldung wird noch gemessen - Auswahl & Band greifen, der Live-Beitritt ist in Erprobung.",
systemImage: "info.circle")
.font(.caption2).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
}
.padding(10)
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 14))
}
/// Binding auf ein Double?-Feld des Turnierplans (ab/bis).
private func bindung(_ pfad: WritableKeyPath<Turnierplan, Double?>) -> Binding<Double?> {
Binding(get: { cockpit.wahl.turnier[keyPath: pfad] },
set: { cockpit.wahl.turnier[keyPath: pfad] = $0 })
}
private var typWahl: Binding<String?> {
Binding(get: { cockpit.wahl.turnier.kategorie }, set: { cockpit.wahl.turnier.kategorie = $0 })
}
/// Zeitfenster in Minuten (leer = kein Fenster): nur Turniere, die in den nächsten N Minuten starten.
private var fensterBindung: Binding<String> {
Binding(get: { cockpit.wahl.turnier.fensterMin.map(String.init) ?? "" },
set: { roh in
let n = Int(roh.trimmingCharacters(in: .whitespaces))
cockpit.wahl.turnier.fensterMin = (n ?? 0) > 0 ? n : nil
})
}
/// Schmales Zahlenfeld; leer = offenes Ende (nil).
private func feld(_ platzhalter: String, wert: Binding<Double?>) -> some View {
TextField(platzhalter, text: Binding(
get: { wert.wrappedValue.map { Format.zahl($0, stellen: 2) } ?? "" },
set: { roh in
let s = roh.replacingOccurrences(of: ",", with: ".").trimmingCharacters(in: .whitespaces)
wert.wrappedValue = Double(s).flatMap { $0 > 0 ? $0 : nil }
}))
.textFieldStyle(.roundedBorder).frame(width: 64).monospacedDigit()
}
}