Files
pokerfreak/mac/Sources/Cockpit/PlanEditor.swift
mmintel 06f336e730 Bankroll reserve, table shape, Bomb Pot, stakes band, HU fix
- Echtgeld bankroll = conservative N-buy-in reserve per table (configurable,
  default 20), replacing the aggressive 1/5 rule; threaded through table
  selection (auswahl) and the sit gate (sitzen) end to end.
- Table shape selectable (Multiway/Heads-Up/Both); heads-up detected from the
  seat count AND the room name ('NL HU'); an opened wrong-shape table is closed.
- Bomb Pot playable in both modes (PLO5, engine capable); only K-Poker stays
  off (bet menu unmeasured). Drop the 'gambling' framing for an honest
  capability gate (nicht_bespielbar / NICHT_BESPIELBAR).
- Stakes band (min/max BB) added to the money model; 'Echtgeld' mode rename;
  native Preferences window; budget tile shows the reserve, not a percent.
- Fix runner import path so the client auto-config thread finds lobby_adapter.
2026-11-07 23:09:43 +01:00

381 lines
16 KiB
Swift
Raw Permalink 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
/// Die Phase des Zeitplans, solange der Läufer läuft - Sitzung, Pause, Fenster zu, fertig.
struct PhaseBand: View {
@Environment(Cockpit.self) private var cockpit
var body: some View {
if cockpit.laeuft == true, let p = cockpit.ansicht.kopf?.phase {
Label(p.text, systemImage: Self.symbol(p.art))
.font(.caption.weight(.medium)).lineLimit(2)
.foregroundStyle(p.art == .spielen ? Color.primary : Color.orange)
.padding(.horizontal, 10).padding(.vertical, 6)
.frame(maxWidth: .infinity, alignment: .leading)
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 10))
.contentTransition(.numericText())
}
}
static func symbol(_ a: Phase.Art?) -> String {
switch a {
case .spielen: "play.circle.fill"
case .pause: "cup.and.saucer.fill"
case .ausserhalb: "moon.zzz.fill"
case .fertig: "flag.checkered"
case nil: "clock"
}
}
}
/// Der Zeitplan auf einen Blick - antippen klappt ihn auf. Geld ist eine eigene Kachel.
struct PlanKachel: View {
@Environment(Cockpit.self) private var cockpit
var body: some View {
let w = cockpit.wahl
let vorlage = PlanVorlage.erkennen(w)
Button { NotificationCenter.default.post(name: .einstellungenOeffnen, object: "zeiten") } label: {
Kachel(titel: "Plan") {
Label(vorlage?.titel ?? "Eigener", systemImage: vorlage?.symbol ?? "slider.horizontal.3")
.font(.callout.weight(.semibold)).lineLimit(1)
.frame(maxWidth: .infinity, alignment: .leading)
} fuss: {
Text(vorlage?.untertitel ?? w.zeitplan.kurz)
}
.overlay(alignment: .topTrailing) {
Image(systemName: "chevron.right")
.font(.caption2).foregroundStyle(.secondary).padding(8)
}
}
.buttonStyle(.plain)
.help("Wie lange, wie oft, zu welchen Uhrzeiten – öffnet die Einstellungen")
}
}
/// Der Zeitplan: drei Vorlagen als Knöpfe, darunter in einem Satz, was der Läufer damit tut. Die
/// Feineinstellung der Sitzungen bleibt eingeklappt. Geld ist ein eigener Editor (Geld-Kachel).
/// Jede Änderung geht gleich an den Läufer.
struct ZeitenEditor: View {
@Environment(Cockpit.self) private var cockpit
@State private var fein = false
var body: some View {
@Bindable var c = cockpit
let aktiv = PlanVorlage.erkennen(c.wahl)
VStack(alignment: .leading, spacing: 10) {
HStack(spacing: 6) {
ForEach(PlanVorlage.allCases) { v in
VorlageKnopf(vorlage: v, an: aktiv == v) { v.anwenden(auf: &c.wahl) }
}
}
Text(c.wahl.ablauf)
.font(.caption).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
Text("Die Vorlagen stellen auch die Geld-Stopps mit ein; feiner regelst du Geld in der Geld-Kachel.")
.font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
DisclosureGroup(isExpanded: $fein) {
SitzungsEinstellung().padding(.top, 8)
} label: {
Text(aktiv == nil ? "Feineinstellung · eigener Plan" : "Feineinstellung")
.font(.caption.weight(.medium))
}
}
.controlSize(.small)
.padding(10)
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 14))
}
}
/// Alles ums Geld an einem Ort: Stakes, Einkauf, Stopps und die Regeln am einzelnen Tisch - vom
/// Zeitplan getrennt (Eigentümer 6.11.: Geld anfassen, ohne den ganzen Sitzungsplan zu sehen).
struct GeldEditor: View {
@Environment(Cockpit.self) private var cockpit
var body: some View {
VStack(alignment: .leading, spacing: 10) {
GeldEinstellung()
}
.controlSize(.small)
.padding(10)
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 14))
}
}
private struct VorlageKnopf: View {
var vorlage: PlanVorlage
var an: Bool
var tun: () -> Void
var body: some View {
Button(action: tun) {
VStack(spacing: 4) {
Image(systemName: vorlage.symbol).font(.system(size: 20, weight: .semibold))
Text(vorlage.titel).font(.caption.weight(.semibold)).lineLimit(1).minimumScaleFactor(0.8)
Text(vorlage.untertitel).font(.caption2).foregroundStyle(an ? .white.opacity(0.85) : .secondary)
.lineLimit(2).multilineTextAlignment(.center)
}
.frame(maxWidth: .infinity, minHeight: 74)
.padding(.vertical, 6).padding(.horizontal, 4)
.foregroundStyle(an ? Color.white : Color.primary)
.background(an ? AnyShapeStyle(Color.accentColor.gradient) : AnyShapeStyle(.white.opacity(0.07)),
in: RoundedRectangle(cornerRadius: 12))
.contentShape(RoundedRectangle(cornerRadius: 12))
}
.buttonStyle(.plain)
.animation(.snappy, value: an)
}
}
/// Die Sitzungen als Sätze: wie viele Tische, wie lange, Pause danach, wie oft, nur zu Uhrzeiten.
private struct SitzungsEinstellung: View {
@Environment(Cockpit.self) private var cockpit
var body: some View {
@Bindable var c = cockpit
PlanAbschnitt(titel: "Sitzungen", symbol: "calendar.badge.clock") {
Frage("Wie lange dauert eine Sitzung?") {
Wahl(an: c.wahl.zeitplan.sitzung != nil, aus: "ohne Ende", an_: "begrenzt") {
c.wahl.zeitplan.sitzung = $0 ? Spanne(45, 90) : nil
}
if c.wahl.zeitplan.sitzung != nil {
MinutenSpanne(wert: Binding(get: { c.wahl.zeitplan.sitzung ?? Spanne(45, 90) },
set: { c.wahl.zeitplan.sitzung = $0 }), unten: 5)
}
}
if c.wahl.zeitplan.sitzung != nil {
Frage("Und danach?") {
Wahl(an: c.wahl.zeitplan.pause.bis > 0, aus: "Schluss", an_: "Pause, dann weiter") {
c.wahl.zeitplan.pause = $0 ? Spanne(10, 20) : Spanne(0, 0)
}
if c.wahl.zeitplan.pause.bis > 0 {
MinutenSpanne(wert: $c.wahl.zeitplan.pause, unten: 1)
}
}
if c.wahl.zeitplan.pause.bis > 0 {
Frage("Wie oft?") {
Stepper(c.wahl.zeitplan.sitzungen.map { "\($0) Sitzungen, dann Schluss" } ?? "immer wieder",
value: Binding(get: { c.wahl.zeitplan.sitzungen ?? 1 },
set: { c.wahl.zeitplan.sitzungen = $0 > 1 ? $0 : nil }),
in: 1...24)
}
}
}
Frage("Nur zu bestimmten Uhrzeiten?") { uhrzeiten }
Text("Zufall: Dauer und Pause werden je Sitzung neu ausgelost - kein starres Muster. Die Tischzahl stellst du oben bei den Tischen ein.")
.font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
}
}
private var uhrzeiten: some View {
@Bindable var c = cockpit
let f = c.wahl.zeitplan.fenster
let stunde = { (t: String) in Int(t.prefix(2)) ?? 0 }
let setzen = { (start: Int, ende: Int) in
c.wahl.zeitplan.fenster = start == ende ? nil
: .init(start: String(format: "%02d:00", start), ende: String(format: "%02d:00", ende))
}
let uhr = { (wert: Int, neu: @escaping (Int) -> Void) in
Picker("", selection: Binding(get: { wert }, set: neu)) {
ForEach(0..<24, id: \.self) { Text(String(format: "%02d Uhr", $0)).tag($0) }
}
.labelsHidden().frame(width: 84)
}
return HStack(spacing: 6) {
Wahl(an: f != nil, aus: "jederzeit", an_: "nur von–bis") { setzen($0 ? 18 : 0, $0 ? 2 : 0) }
if let f {
uhr(stunde(f.start)) { setzen($0, stunde(f.ende)) }
Text("bis")
uhr(stunde(f.ende)) { setzen(stunde(f.start), $0) }
}
}
}
}
/// Geld als Sätze: Stakes, Einkauf, Stopps je Sitzung und Tag, Regeln am einzelnen Tisch.
private struct GeldEinstellung: View {
@Environment(Cockpit.self) private var cockpit
@State private var stakesText = ""
@State private var stakesMaxText = ""
var body: some View {
@Bindable var c = cockpit
PlanAbschnitt(titel: "Geld", symbol: "banknote") {
Frage("Welche Stakes?") { stakes }
Frage("Wie viel kaufen?") {
Picker("", selection: $c.wahl.geld.kauf) {
Text("Max (tief)").tag(Geldplan.Kauf.max)
Text("Min").tag(Geldplan.Kauf.min)
}
.pickerStyle(.segmented).labelsHidden()
}
Frage("Wann ist eine Sitzung vorbei?") {
VStack(alignment: .leading, spacing: 4) {
GrenzeZeile(titel: "Verlust", grenze: $c.wahl.geld.sitzungVerlust, vorgabe: Grenze(250))
GrenzeZeile(titel: "Gewinn", grenze: $c.wahl.geld.sitzungGewinn, vorgabe: Grenze(150))
}
}
Frage("Wann ist der Tag vorbei?") {
VStack(alignment: .leading, spacing: 4) {
GrenzeZeile(titel: "Verlust", grenze: $c.wahl.geld.tagVerlust, vorgabe: Grenze(500))
GrenzeZeile(titel: "Gewinn", grenze: $c.wahl.geld.tagGewinn, vorgabe: Grenze(300))
}
}
Frage("Am einzelnen Tisch") {
VStack(alignment: .leading, spacing: 2) {
Stepper("aufstehen nach \(Format.zahl(c.wahl.geld.tischVerlustBB, stellen: 0)) BB Verlust",
value: $c.wahl.geld.tischVerlustBB, in: 10...1000, step: 10)
Stepper("nachkaufen unter \(Format.zahl(c.wahl.geld.nachkaufUnterBB, stellen: 0)) BB",
value: $c.wahl.geld.nachkaufUnterBB, in: 10...100, step: 5)
Stepper("aufstehen unter \(Format.zahl(c.wahl.geld.aufstehenUnterBB, stellen: 0)) BB Stack",
value: $c.wahl.geld.aufstehenUnterBB, in: 5...max(5, c.wahl.geld.nachkaufUnterBB - 5), step: 5)
}
}
Frage("Bankroll (nur Echtgeld)") {
VStack(alignment: .leading, spacing: 2) {
Stepper("\(c.wahl.geld.reserveBuyins) volle Buy-ins Reserve je Tisch",
value: $c.wahl.geld.reserveBuyins, in: 1...100)
Text("Best Practice: 20–30. Je höher, desto weniger Tische bei kleiner Bankroll (mehr Reserve).")
.font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
}
}
Text("% heißt: Anteil der Bankroll beim Sitzungsstart (nur Cash).")
.font(.caption2).foregroundStyle(.tertiary)
}
.onAppear {
stakesText = c.wahl.geld.stakesBB.map { Format.zahl($0, stellen: 2) } ?? ""
stakesMaxText = c.wahl.geld.stakesMaxBB.map { Format.zahl($0, stellen: 2) } ?? ""
}
}
private var stakes: some View {
@Bindable var c = cockpit
return VStack(alignment: .leading, spacing: 6) {
Picker("", selection: $c.wahl.geld.modell) {
Text("nach Guthaben").tag(Geldplan.Modell.leiter)
Text("fest").tag(Geldplan.Modell.fest)
Text("Band").tag(Geldplan.Modell.band)
}
.pickerStyle(.segmented).labelsHidden()
.help("nach Guthaben: Stufe hoch bei doppeltem, runter bei halbem Guthaben · fest: genau dieser Big Blind · Band: nur Big Blinds zwischen min und max (ein Feld leer = offenes Ende, z. B. nur 'max bis')")
if c.wahl.geld.modell == .fest {
TextField("Big Blind", text: $stakesText)
.textFieldStyle(.roundedBorder).frame(width: 74).onSubmit { setzeStakesMin() }
} else if c.wahl.geld.modell == .band {
HStack(spacing: 6) {
TextField("min BB", text: $stakesText)
.textFieldStyle(.roundedBorder).frame(width: 74).onSubmit { setzeStakesMin() }
Text("bis").foregroundStyle(.secondary)
TextField("max BB", text: $stakesMaxText)
.textFieldStyle(.roundedBorder).frame(width: 74).onSubmit { setzeStakesMax() }
}
}
}
}
/// Big Blind in Chips (Spielgeld) bzw. in der Währung (Echtgeld, z. B. 0.02). Leer = Grenze offen.
private func setzeStakesMin() {
let roh = stakesText.replacingOccurrences(of: ",", with: ".").trimmingCharacters(in: .whitespaces)
cockpit.wahl.geld.stakesBB = Double(roh).flatMap { $0 > 0 ? $0 : nil }
stakesText = cockpit.wahl.geld.stakesBB.map { Format.zahl($0, stellen: 2) } ?? ""
}
private func setzeStakesMax() {
let roh = stakesMaxText.replacingOccurrences(of: ",", with: ".").trimmingCharacters(in: .whitespaces)
cockpit.wahl.geld.stakesMaxBB = Double(roh).flatMap { $0 > 0 ? $0 : nil }
stakesMaxText = cockpit.wahl.geld.stakesMaxBB.map { Format.zahl($0, stellen: 2) } ?? ""
}
}
/// Eine Frage, darunter die Antwort.
private struct Frage<Inhalt: View>: View {
var titel: String
@ViewBuilder var inhalt: Inhalt
init(_ titel: String, @ViewBuilder inhalt: () -> Inhalt) {
self.titel = titel
self.inhalt = inhalt()
}
var body: some View {
VStack(alignment: .leading, spacing: 4) {
Text(titel).font(.caption.weight(.medium))
HStack(spacing: 8) { inhalt }.font(.caption)
}
}
}
/// Zwei Antworten als Kapsel statt eines nackten Schalters.
private struct Wahl: View {
var an: Bool
var aus: String
var an_: String
var setzen: (Bool) -> Void
var body: some View {
Picker("", selection: Binding(get: { an }, set: setzen)) {
Text(aus).tag(false)
Text(an_).tag(true)
}
.pickerStyle(.segmented).labelsHidden().fixedSize()
}
}
private struct PlanAbschnitt<Inhalt: View>: View {
var titel: String
var symbol: String
@ViewBuilder var inhalt: Inhalt
var body: some View {
VStack(alignment: .leading, spacing: 6) {
Label(titel, systemImage: symbol).font(.caption.weight(.semibold)).foregroundStyle(.secondary)
inhalt
}
}
}
/// Minuten von–bis in 5er-Schritten, ausgelost je Sitzung; gleich: fest.
private struct MinutenSpanne: View {
@Binding var wert: Spanne
var unten: Double
var body: some View {
HStack(spacing: 2) {
Stepper(Format.zahl(wert.von, stellen: 0), value: Binding(get: { wert.von }, set: { wert = Spanne($0, max($0, wert.bis)) }),
in: unten...600, step: 5)
Text("bis")
Stepper("\(Format.zahl(wert.bis, stellen: 0)) min", value: Binding(get: { wert.bis }, set: { wert = Spanne(min(wert.von, $0), $0) }),
in: max(unten, 0)...600, step: 5)
}
}
}
/// Ein Stop: an/aus, Wert, BB oder % der Bankroll beim Sitzungsstart.
private struct GrenzeZeile: View {
var titel: String
@Binding var grenze: Grenze?
var vorgabe: Grenze
var body: some View {
HStack(spacing: 6) {
Text(titel).foregroundStyle(.secondary).frame(width: 46, alignment: .leading)
Toggle("", isOn: Binding(get: { grenze != nil }, set: { grenze = $0 ? vorgabe : nil }))
.toggleStyle(.switch).labelsHidden()
if let g = grenze {
Stepper(Format.zahl(g.wert, stellen: 0),
value: Binding(get: { g.wert }, set: { grenze = Grenze($0, prozent: g.prozent) }),
in: 1...(g.prozent ? 100 : 5000), step: g.prozent ? 1 : 10)
Picker("", selection: Binding(get: { g.prozent }, set: {
grenze = Grenze($0 ? min(g.wert, 20) : max(g.wert, 50), prozent: $0)
})) {
Text("BB").tag(false)
Text("%").tag(true)
}
.pickerStyle(.segmented).labelsHidden().frame(width: 70)
} else {
Text("aus").foregroundStyle(.secondary)
}
}
}
}