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>
623 lines
32 KiB
Swift
623 lines
32 KiB
Swift
import Foundation
|
||
import CockpitKern
|
||
import SwiftUI
|
||
|
||
/// Die Spielseite wie WinUI `CashSeite`: EIN Bereich rollt, Status und Knoepfe stehen unten fest. Vor dem Lauf
|
||
/// stehen alle Einstellungen offen als Karten (Spiel, Stufen, Geld und Verlustlimits); im Lauf zuerst Ergebnis und
|
||
/// Tische, die Einstellungen als eine Falte darunter. Im Zuschauer: Sammeln, der eigene Zug, dieselbe Tischuebersicht.
|
||
struct SpielenAnsicht: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
@State private var planOffen = false
|
||
|
||
var body: some View {
|
||
let laeuft = cockpit.laeuft == true
|
||
let zuschauen = cockpit.zuschauen
|
||
VStack(spacing: 0) {
|
||
ScrollView {
|
||
VStack(alignment: .leading, spacing: 12) {
|
||
if zuschauen, let s = cockpit.ansicht.zuschauer?.sammler { SammelnFalte(s: s) }
|
||
if !laeuft { SpielEinstellungen() } // vor dem Lauf offen oben, im Lauf als Falte unten
|
||
TurnierBereich(teil: .anmeldungen)
|
||
if zuschauen { ZuschauerAnsicht() }
|
||
LiveTeil {
|
||
if laeuft, !zuschauen {
|
||
VStack(alignment: .leading, spacing: 10) {
|
||
Falte(titel: "Einstellungen", wert: laufKurz, offen: planOffen) { planOffen.toggle() }
|
||
if planOffen { SpielEinstellungen() }
|
||
}
|
||
}
|
||
}
|
||
}
|
||
.padding(12)
|
||
}
|
||
Divider()
|
||
SpielFuss()
|
||
}
|
||
.onChange(of: laeuft) { _, _ in planOffen = false }
|
||
}
|
||
|
||
/// "4 Tische · NL5 › NL2" - die Falte im Lauf.
|
||
private var laufKurz: String {
|
||
let w = cockpit.wahl
|
||
let zahl = w.tischeBis.map { "\(w.tische)–\($0)" } ?? "\(w.tische)"
|
||
let stufen = StufenKarte.kurz(w, cockpit.ansicht.kopf?.stufen[w.cash ? "cash" : "uebung"])
|
||
return ["\(zahl) Tische", stufen].filter { !$0.isEmpty }.joined(separator: " · ")
|
||
}
|
||
}
|
||
|
||
/// Eine Faltzeile: Titel, Wert rechts, Chevron.
|
||
struct Falte: View {
|
||
var titel: String
|
||
var wert: String
|
||
var offen: Bool
|
||
var tippen: () -> Void
|
||
|
||
var body: some View {
|
||
Button(action: tippen) {
|
||
HStack(spacing: 8) {
|
||
Text(titel).font(.callout.weight(.semibold))
|
||
Spacer(minLength: 8)
|
||
Text(wert).font(.caption).foregroundStyle(.secondary).lineLimit(1)
|
||
Image(systemName: offen ? "chevron.up" : "chevron.down").font(.caption2).foregroundStyle(.tertiary)
|
||
}
|
||
.padding(.horizontal, 12).padding(.vertical, 10)
|
||
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 10))
|
||
.contentShape(RoundedRectangle(cornerRadius: 10))
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
}
|
||
|
||
/// Eine Einstellkarte: Titel, darunter Zeilen auf einer Flaeche.
|
||
struct Einstellkarte<Inhalt: View>: View {
|
||
var titel: String
|
||
@ViewBuilder var inhalt: Inhalt
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 6) {
|
||
Text(titel).font(.caption.weight(.semibold)).foregroundStyle(.secondary).padding(.leading, 2)
|
||
VStack(alignment: .leading, spacing: 0) { inhalt }
|
||
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 10))
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Eine Zeile in einer Einstellkarte: Symbol, Titel, Hinweis, rechts das Steuerelement.
|
||
struct Einstellzeile<Rechts: View>: View {
|
||
var symbol: String
|
||
var titel: String
|
||
var hinweis: String = ""
|
||
@ViewBuilder var rechts: Rechts
|
||
|
||
var body: some View {
|
||
HStack(spacing: 10) {
|
||
Image(systemName: symbol).font(.caption).foregroundStyle(.secondary).frame(width: 16)
|
||
VStack(alignment: .leading, spacing: 1) {
|
||
Text(titel).font(.callout).lineLimit(1).fixedSize()
|
||
if !hinweis.isEmpty {
|
||
Text(hinweis).font(.caption2).foregroundStyle(.secondary).lineLimit(2).fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
}
|
||
.layoutPriority(1)
|
||
Spacer(minLength: 8)
|
||
rechts
|
||
}
|
||
.padding(.horizontal, 12).padding(.vertical, 8)
|
||
.frame(minHeight: 44)
|
||
}
|
||
}
|
||
|
||
// MARK: - Einstellungen der Spielseite
|
||
|
||
/// Karte "Spiel" (Tische, Anzahl auslosen, Was spielen, Tischform, Zeitplan), "Stufen", "Geld und Verlustlimits".
|
||
/// Im Zuschauer bleibt nur die Tischzahl einstellbar (Owner 29.11.); Stufen und Geld gehoeren zum Laeufer.
|
||
struct SpielEinstellungen: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
@State private var wasOffen = false
|
||
@State private var budgetText = ""
|
||
|
||
var body: some View {
|
||
let w = cockpit.wahl
|
||
let zuschauen = cockpit.zuschauen
|
||
let laeuft = cockpit.laeuft == true
|
||
VStack(alignment: .leading, spacing: 10) {
|
||
Einstellkarte(titel: "Spiel") {
|
||
Einstellzeile(symbol: "square.grid.2x2", titel: "Tische",
|
||
hinweis: laeuft ? "\(cockpit.ansicht.kopf?.tischeOffen ?? 0) offen"
|
||
: w.cash ? "" : "Chips · Buy-in \(w.geld.kauf == .max ? "Max" : "Min")") {
|
||
HStack(spacing: 6) {
|
||
Stepper("\(w.tische)", value: Binding(get: { w.tische }, set: { cockpit.wahl.tische = $0 }),
|
||
in: 1...max(1, Spielplan.hoechstens))
|
||
.monospacedDigit().fixedSize()
|
||
if let bis = w.tischeBis {
|
||
Text("bis").font(.caption).foregroundStyle(.secondary)
|
||
Stepper("\(bis)", value: Binding(get: { bis }, set: { cockpit.wahl.tischeBis = $0 }),
|
||
in: min(w.tische + 1, Spielplan.hoechstens)...max(w.tische + 1, Spielplan.hoechstens))
|
||
.monospacedDigit().fixedSize()
|
||
}
|
||
}
|
||
}
|
||
Divider().padding(.leading, 38)
|
||
Einstellzeile(symbol: "dice", titel: "Anzahl auslosen", hinweis: "jede Sitzung eine andere Tischzahl") {
|
||
Toggle("", isOn: Binding(get: { w.tischeBis != nil },
|
||
set: { cockpit.wahl.tischeBis = $0 ? min(Spielplan.hoechstens, w.tische + 2) : nil }))
|
||
.toggleStyle(.switch).labelsHidden().controlSize(.small)
|
||
}
|
||
if !zuschauen {
|
||
Divider().padding(.leading, 38)
|
||
Einstellzeile(symbol: "rectangle.stack", titel: "Was spielen", hinweis: arten(w).count > 1 ? arten(w).joined(separator: ", ") : "") {
|
||
Button(artenText(w)) { wasOffen.toggle() }
|
||
.controlSize(.small)
|
||
.popover(isPresented: $wasOffen, arrowEdge: .leading) {
|
||
VStack(alignment: .leading, spacing: 10) {
|
||
FormatWahl()
|
||
TurnierBereich(teil: .plan)
|
||
}
|
||
.padding(12)
|
||
.frame(width: 320)
|
||
.environment(cockpit)
|
||
}
|
||
}
|
||
Divider().padding(.leading, 38)
|
||
Einstellzeile(symbol: "person.2", titel: "Tischform") {
|
||
EngeWahl {
|
||
Picker("", selection: Binding(get: { w.tischform }, set: { cockpit.wahl.tischform = $0 })) {
|
||
ForEach(Spielplan.Tischform.allCases, id: \.self) { Text($0.name).tag($0) }
|
||
}
|
||
}
|
||
.help("Multiway = Ring-Tische (Engine-Stärke). Heads-Up = nur 2-Platz-Tische. Beide = egal.")
|
||
}
|
||
Divider().padding(.leading, 38)
|
||
Button { NotificationCenter.default.post(name: .einstellungenOeffnen, object: "zeiten") } label: {
|
||
Einstellzeile(symbol: "calendar", titel: "Zeitplan", hinweis: planText(w)) {
|
||
Image(systemName: "chevron.right").font(.caption2).foregroundStyle(.secondary)
|
||
}
|
||
.contentShape(Rectangle())
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
}
|
||
if !zuschauen, let s = cockpit.ansicht.kopf?.stufen[w.cash ? "cash" : "uebung"] {
|
||
Einstellkarte(titel: "Stufen") { StufenKarte(stand: s).padding(10) }
|
||
}
|
||
if w.cash, !zuschauen {
|
||
Einstellkarte(titel: "Geld und Verlustlimits") {
|
||
Einstellzeile(symbol: "dollarsign.circle", titel: "Budget",
|
||
hinweis: cockpit.ansicht.kopf?.guthaben.map { "Konto \(Format.zahl($0, stellen: 2)) $" } ?? "") {
|
||
TextField("alles", text: $budgetText)
|
||
.textFieldStyle(.roundedBorder).frame(width: 110).multilineTextAlignment(.trailing)
|
||
.onSubmit { budgetUebernehmen() }
|
||
.onAppear { budgetText = w.budget.map { Format.zahl($0, stellen: 0) } ?? "" }
|
||
}
|
||
if let d = cockpit.ansicht.geld?.deckel, !d.einstellen.isEmpty {
|
||
Divider().padding(.leading, 38)
|
||
LimitKarte(deckel: d).padding(12)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private func arten(_ w: Spielplan) -> [String] { w.folge.filter { w.anzahl($0) > 0 }.map(\.name) }
|
||
|
||
private func artenText(_ w: Spielplan) -> String {
|
||
let a = arten(w)
|
||
return a.isEmpty ? "nichts gewählt" : a.count == 1 ? a[0] : "\(a.count) Formate"
|
||
}
|
||
|
||
private func planText(_ w: Spielplan) -> String {
|
||
if let v = PlanVorlage.erkennen(w) { return [v.titel, v.untertitel].filter { !$0.isEmpty }.joined(separator: " · ") }
|
||
let k = w.zeitplan.kurz
|
||
return k.isEmpty ? "Eigener" : "Eigener · \(k)"
|
||
}
|
||
|
||
private func budgetUebernehmen() {
|
||
let roh = budgetText.replacingOccurrences(of: ".", with: "").replacingOccurrences(of: ",", with: ".")
|
||
cockpit.wahl.budget = Double(roh.trimmingCharacters(in: .whitespaces)).flatMap { $0 > 0 ? $0 : nil }
|
||
budgetText = cockpit.wahl.budget.map { Format.zahl($0, stellen: 0) } ?? ""
|
||
}
|
||
}
|
||
|
||
// MARK: - Stufen nach Vorrang (Spielen und Sammeln)
|
||
|
||
/// Stufen nach Vorrang (WinUI `StufenPrio`): oben die gewaehlten mit Pfeilen und ✕, darunter die weiteren zum
|
||
/// Dazunehmen, Cash und Turniere getrennt. Die Reihenfolge haelt der Besitzer (`setzen`).
|
||
struct StufenPrio<Mitte: View>: View {
|
||
var stufen: [StufeInfo]
|
||
var reihe: [Double]
|
||
var erklaerung: String
|
||
var leer: String
|
||
var weg: String
|
||
var text: (StufeInfo) -> String
|
||
var geht: (StufeInfo) -> Bool = { _ in true }
|
||
var setzen: ([Double]) -> Void
|
||
/// Unter dem Namen einer gewaehlten Stufe (Tische je Stufe) bzw. rechts daneben (Handzahl beim Sammeln).
|
||
@ViewBuilder var mitte: (StufeInfo) -> Mitte
|
||
var mitteUnten = true
|
||
|
||
var body: some View {
|
||
let absteigend = reihe == Spielplan.hoechsteZuerst(reihe)
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
HStack {
|
||
Text("Priorität").font(.callout.weight(.semibold))
|
||
Spacer()
|
||
Button("Höchste zuerst") { setzen(Spielplan.hoechsteZuerst(reihe)) }
|
||
.controlSize(.small).disabled(absteigend)
|
||
}
|
||
HStack(spacing: 4) {
|
||
Text("Vorrang").font(.caption2.weight(.semibold)).foregroundStyle(.secondary)
|
||
Image(systemName: "info.circle").font(.caption2).foregroundStyle(.tertiary).help(erklaerung)
|
||
}
|
||
ForEach(Array(reihe.enumerated()), id: \.element) { i, bb in
|
||
zeile(info(bb), i)
|
||
}
|
||
if reihe.isEmpty { Text(leer).font(.caption).foregroundStyle(.secondary) }
|
||
let rest = stufen.filter { !reihe.contains($0.bb) }.sorted { Spielplan.hoeherImVorrang($0.bb, $1.bb) }
|
||
if !rest.isEmpty {
|
||
Text("Weitere Stufen").font(.caption2).foregroundStyle(.secondary)
|
||
let gruppen = [("Cash", rest.filter { !$0.turnier }), ("Turniere", rest.filter(\.turnier))].filter { !$0.1.isEmpty }
|
||
ForEach(gruppen, id: \.0) { titel, liste in
|
||
if gruppen.count > 1 { Text(titel).font(.caption.weight(.semibold)).foregroundStyle(.secondary).padding(.top, 2) }
|
||
LazyVGrid(columns: [GridItem(.flexible(), spacing: 6), GridItem(.flexible(), spacing: 6)], alignment: .leading, spacing: 6) {
|
||
ForEach(liste) { weitere($0, absteigend: absteigend) }
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private func info(_ bb: Double) -> StufeInfo { stufen.first { $0.bb == bb } ?? StufeInfo(bb: bb, name: Format.roh(bb)) }
|
||
|
||
private func zeile(_ st: StufeInfo, _ i: Int) -> some View {
|
||
let ok = geht(st)
|
||
let ton: Color = ok ? .blue : .orange
|
||
return HStack(alignment: .center, spacing: 8) {
|
||
Text("\(i + 1)").font(.callout.weight(.bold).monospacedDigit()).foregroundStyle(ton).frame(width: 16)
|
||
VStack(alignment: .leading, spacing: 2) {
|
||
HStack(spacing: 6) {
|
||
Text(st.name).font(.caption.weight(.semibold))
|
||
ArtSchild(turnier: st.turnier)
|
||
if !mitteUnten { Spacer(minLength: 0); mitte(st) }
|
||
}
|
||
Text(text(st)).font(.caption2).foregroundStyle(ok ? AnyShapeStyle(.tertiary) : AnyShapeStyle(Color.orange))
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
if mitteUnten { mitte(st) }
|
||
}
|
||
Spacer(minLength: 0)
|
||
HStack(spacing: 0) {
|
||
Button { schieben(st.bb, -1) } label: { Image(systemName: "chevron.up") }.disabled(i == 0).help("höhere Priorität")
|
||
Button { schieben(st.bb, 1) } label: { Image(systemName: "chevron.down") }.disabled(i == reihe.count - 1)
|
||
.help("niedrigere Priorität")
|
||
Button { setzen(reihe.filter { $0 != st.bb }) } label: { Image(systemName: "xmark") }.help(weg)
|
||
}
|
||
.buttonStyle(.borderless).font(.caption)
|
||
}
|
||
.padding(.horizontal, 10).padding(.vertical, 6)
|
||
.frame(minHeight: 44)
|
||
.background(ton.opacity(0.14), in: RoundedRectangle(cornerRadius: 6))
|
||
.overlay(RoundedRectangle(cornerRadius: 6).strokeBorder(ton.opacity(0.5)))
|
||
}
|
||
|
||
private func weitere(_ st: StufeInfo, absteigend: Bool) -> some View {
|
||
Button {
|
||
let r = reihe + [st.bb]
|
||
setzen(absteigend ? Spielplan.hoechsteZuerst(r) : r)
|
||
} label: {
|
||
HStack(alignment: .center) {
|
||
VStack(alignment: .leading, spacing: 1) {
|
||
Text("+ " + st.name).font(.caption.weight(.semibold))
|
||
Text(st.text).font(.caption2).foregroundStyle(geht(st) ? AnyShapeStyle(.tertiary) : AnyShapeStyle(Color.orange))
|
||
.lineLimit(3).fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
if !mitteUnten, st.haende > 0 { Spacer(minLength: 0); mitte(st) }
|
||
}
|
||
.padding(.horizontal, 8).padding(.vertical, 5)
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 6))
|
||
.contentShape(RoundedRectangle(cornerRadius: 6))
|
||
}
|
||
.buttonStyle(.plain)
|
||
.help("diese Stufe dazunehmen")
|
||
}
|
||
|
||
private func schieben(_ bb: Double, _ schritt: Int) {
|
||
var r = reihe
|
||
guard let i = r.firstIndex(of: bb), r.indices.contains(i + schritt) else { return }
|
||
r.swapAt(i, i + schritt)
|
||
setzen(r)
|
||
}
|
||
}
|
||
|
||
/// Kleines Schild "Cash" / "Turnier" neben dem Namen, damit die beiden Arten nie verwechselt werden.
|
||
private struct ArtSchild: View {
|
||
var turnier: Bool
|
||
var body: some View {
|
||
let ton: Color = turnier ? .purple : .green
|
||
Text(turnier ? "Turnier" : "Cash").font(.system(size: 9.5, weight: .semibold)).foregroundStyle(ton)
|
||
.padding(.horizontal, 5).padding(.vertical, 1)
|
||
.background(ton.opacity(0.18), in: RoundedRectangle(cornerRadius: 4))
|
||
.overlay(RoundedRectangle(cornerRadius: 4).strokeBorder(ton.opacity(0.6)))
|
||
}
|
||
}
|
||
|
||
/// Welche Stufen gespielt werden (WinUI `StufenTeil`): die Vorrang-Liste, je gewaehlter Cash-Stufe die Tischzahl;
|
||
/// ohne Wahl gilt die Bankroll-Automatik. Das Urteil je Stufe rechnet der Server (betrieb/stufenwahl.py).
|
||
struct StufenKarte: View {
|
||
var stand: StufenStand
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
static func kurz(_ w: Spielplan, _ s: StufenStand?) -> String {
|
||
guard let s else { return "" }
|
||
return w.stufen.isEmpty ? "automatisch" : w.stufen.map { s.info($0)?.name ?? Format.roh($0) }.joined(separator: " › ")
|
||
}
|
||
|
||
var body: some View {
|
||
let w = cockpit.wahl
|
||
let laeuft = cockpit.laeuft == true
|
||
let reihe = w.stufen
|
||
let cashReihe = reihe.filter { $0 > 0 }
|
||
let keine = !cashReihe.isEmpty && cashReihe.allSatisfy { stand.info($0)?.geht == false }
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
StufenPrio(
|
||
stufen: stand.stufen, reihe: reihe,
|
||
erklaerung: "Oben zuerst: freie Tische der ersten Stufe, den Rest füllt die nächste. Ein Turnier ganz oben hält ab 10 Minuten vor dem Start einen Tischplatz frei, weiter unten nimmt es nur einen freien. Orange: geht gerade nicht und wird übersprungen. Die Zahl je Stufe: höchstens so viele Tische dort, frei = so viele, wie die Gesamtzahl hergibt.",
|
||
leer: "Nichts gewählt: automatisch nach Bankroll - unten antippen.", weg: "diese Stufe nicht spielen",
|
||
text: { x in
|
||
(laeuft && x.offen > 0 ? "\(x.offen) offen" + (x.sitzt < x.offen ? ", \(x.offen - x.sitzt) warten" : "") + " · " : "") + x.text
|
||
},
|
||
geht: { $0.geht != false },
|
||
setzen: { r in cockpit.wahl.stufenSetzen(r) },
|
||
mitte: { st in tischeJeStufe(st) })
|
||
let fuss = reihe.isEmpty ? stand.auto : keine ? "Die Bankroll trägt keine Cash-Stufe davon – es geht kein Cash-Tisch auf" : ""
|
||
if !fuss.isEmpty {
|
||
Text(fuss).font(.caption2).foregroundStyle(keine ? AnyShapeStyle(Color.orange) : AnyShapeStyle(.secondary))
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
if let t = stand.turnier, !t.zeile.isEmpty {
|
||
Text(t.zeile).font(.caption2).foregroundStyle(t.stand == "gesperrt" ? AnyShapeStyle(Color.orange) : AnyShapeStyle(.secondary))
|
||
.fixedSize(horizontal: false, vertical: true).help(t.grund)
|
||
}
|
||
}
|
||
}
|
||
|
||
/// In der Zeile einer gewaehlten Cash-Stufe: "Tische − n +" (frei = so viele, wie die Gesamtzahl hergibt).
|
||
@ViewBuilder private func tischeJeStufe(_ st: StufeInfo) -> some View {
|
||
if st.bb > 0, cockpit.wahl.stufen.contains(st.bb) {
|
||
let n = cockpit.wahl.tischeJeStufe(st.bb)
|
||
let basis = n ?? max(st.offen, 1) // aus "frei" heraus beginnt die Zahl bei den offenen Tischen
|
||
HStack(spacing: 4) {
|
||
Text("Tische").font(.caption2).foregroundStyle(.secondary)
|
||
Button("−") { cockpit.wahl.tischeJeStufeSetzen(st.bb, max(0, basis - (n == nil ? 0 : 1))) }
|
||
.help("\(st.name): ein Tisch weniger")
|
||
Text(n.map(String.init) ?? "frei").font(.caption.weight(n == nil ? .regular : .semibold).monospacedDigit())
|
||
.foregroundStyle(n == nil ? AnyShapeStyle(.secondary) : AnyShapeStyle(.primary)).frame(minWidth: 30)
|
||
.help(n == nil ? "\(st.name): keine eigene Zahl (Antippen auf − oder + setzt eine)" : "\(st.name): höchstens \(n!) Tische")
|
||
Button("+") { cockpit.wahl.tischeJeStufeSetzen(st.bb, basis + (n == nil ? 0 : 1)) }
|
||
.help("\(st.name): ein Tisch mehr")
|
||
if n != nil {
|
||
Button("frei") { cockpit.wahl.tischeJeStufeSetzen(st.bb, nil) }.help("\(st.name): keine eigene Zahl")
|
||
}
|
||
}
|
||
.controlSize(.mini)
|
||
}
|
||
}
|
||
}
|
||
|
||
// MARK: - Verlustlimits
|
||
|
||
/// Sitzungs- und Tagesdeckel einstellen (WinUI `LimitTeil`): Stufe waehlen (★ = Empfehlung), Verbrauch als Balken.
|
||
struct LimitKarte: View {
|
||
var deckel: GeldDeckel
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 14) {
|
||
ForEach(Array(deckel.einstellen.enumerated()), id: \.element.id) { i, e in
|
||
let k = i < deckel.kacheln.count ? deckel.kacheln[i] : nil
|
||
let verlust = max(0, -(k?.bb ?? 0))
|
||
VStack(alignment: .leading, spacing: 6) {
|
||
HStack(spacing: 10) {
|
||
Text(e.name).font(.callout).frame(width: 62, alignment: .leading)
|
||
Picker("", selection: Binding(
|
||
get: { e.optionen.first(where: \.gewaehlt)?.bb ?? e.bb },
|
||
set: { cockpit.deckelEinstellen(e.was, bb: $0) })) {
|
||
ForEach(Array(e.optionen.enumerated()), id: \.offset) { _, o in
|
||
Text(o.text + (o.empfohlen ? " ★" : "")).tag(o.bb)
|
||
}
|
||
}
|
||
.labelsHidden()
|
||
.help("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.")
|
||
}
|
||
ProgressView(value: min(1, max(0, k?.anteil ?? 0))).tint(Farben.name(k?.ton ?? "gruen"))
|
||
HStack(spacing: 4) {
|
||
Text(verlust < 0.5 ? "noch nichts verloren · Deckel \(Format.zahl(e.bb)) BB"
|
||
: "−\(Format.zahl(verlust)) von \(Format.zahl(e.bb)) BB")
|
||
.font(.caption2).foregroundStyle(.secondary)
|
||
if !e.empfehlung.isEmpty {
|
||
Image(systemName: "info.circle").font(.caption2).foregroundStyle(.tertiary).help(e.empfehlung)
|
||
}
|
||
Spacer(minLength: 0)
|
||
if let emp = e.empfohlenBB, abs(emp - e.bb) > 1e-6 {
|
||
Button("Empfehlung nehmen") { cockpit.deckelEinstellen(e.was, bb: emp) }.controlSize(.mini)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// MARK: - Sammeln
|
||
|
||
/// Sammeln (WinUI `SammlerTeil`): fremden Tischen der gewaehlten Stufen nur zusehen und ihre Haende sammeln - nie
|
||
/// setzen, nie klicken. Eine Gesamtzahl und die Stufen nach Vorrang; jede Aenderung gilt sofort, auch im Lauf.
|
||
/// Gestartet und gestoppt wird ueber den Hauptknopf. Offen, solange er nicht sammelt.
|
||
struct SammelnFalte: View {
|
||
var s: Sammler
|
||
@Environment(Cockpit.self) private var cockpit
|
||
@State private var offen: Bool?
|
||
/// Angetippt, bis der Server es zeigt (hoechstens 4 s) - sonst sprang die Liste bei schnellen Klicks zurueck.
|
||
@State private var wunsch: (tische: Int, reihe: [Double], seit: Date)?
|
||
|
||
private var tische: Int { aktuellerWunsch?.tische ?? s.tische }
|
||
private var reihe: [Double] { aktuellerWunsch?.reihe ?? s.reihe }
|
||
private var aktuellerWunsch: (tische: Int, reihe: [Double], seit: Date)? {
|
||
guard let w = wunsch, Date().timeIntervalSince(w.seit) < 4, w.tische != s.tische || w.reihe != s.reihe else { return nil }
|
||
return w
|
||
}
|
||
|
||
var body: some View {
|
||
let istOffen = offen ?? !s.laeuft
|
||
VStack(alignment: .leading, spacing: 10) {
|
||
Falte(titel: "Sammeln", wert: kurz, offen: istOffen) { offen = !istOffen }
|
||
if istOffen {
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
Text(s.text).font(.caption)
|
||
.foregroundStyle((s.gesperrt && !s.laeuft) || s.hinweis != nil ? AnyShapeStyle(Color.orange)
|
||
: s.laeuft ? AnyShapeStyle(Color.green) : AnyShapeStyle(.secondary))
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
HStack {
|
||
Text("Tische insgesamt").font(.callout.weight(.semibold))
|
||
Spacer()
|
||
Stepper("\(tische)", value: Binding(get: { tische }, set: { neu in
|
||
wunsch = (neu, reihe, Date())
|
||
cockpit.sammlerWahl(tische: neu)
|
||
}), in: 1...Sammler.tischeHoechstens)
|
||
.monospacedDigit().fixedSize()
|
||
}
|
||
StufenPrio(
|
||
stufen: s.stufen, reihe: reihe,
|
||
erklaerung: "Oben zuerst: alle Tische der ersten Stufe, freie Plätze füllt die nächste. Öffnet oben einer, macht unten einer Platz.",
|
||
leer: "Keine Stufe gewählt - unten antippen.", weg: "diese Stufe nicht sammeln",
|
||
text: { x in (s.laeuft ? "\(x.offen) offen · " : "") + x.text },
|
||
setzen: { r in
|
||
wunsch = (tische, r, Date())
|
||
cockpit.sammlerWahl(reihe: r)
|
||
},
|
||
mitte: { st in
|
||
VStack(alignment: .trailing, spacing: 0) {
|
||
Text(Format.zahl(Double(st.haende), stellen: 0)).font(.callout.weight(.semibold).monospacedDigit())
|
||
Text("Hände").font(.caption2).foregroundStyle(.tertiary)
|
||
}
|
||
.help("gesammelte Hände dieser Stufe")
|
||
},
|
||
mitteUnten: false)
|
||
}
|
||
.padding(10)
|
||
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 10))
|
||
}
|
||
}
|
||
.onChange(of: s.laeuft) { _, _ in offen = nil }
|
||
}
|
||
|
||
private var kurz: String {
|
||
let namen = reihe.map { bb in s.stufen.first { $0.bb == bb }?.name ?? Format.roh(bb) }
|
||
return "\(tische) Tische · " + (namen.isEmpty ? "keine Stufe" : namen.joined(separator: " › "))
|
||
}
|
||
}
|
||
|
||
// MARK: - Unten fest: was gerade ist und die Knoepfe
|
||
|
||
/// Warteschlange, Status (mit Phase), Konto-Alarme, Freigaben, Debug-Port, Deckel, Hauptknopf + Pause + Not-Aus,
|
||
/// "Nur offene Tische spielen" - oder das Not-Aus-Band.
|
||
struct SpielFuss: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
var body: some View {
|
||
let k = cockpit.ansicht.kopf
|
||
let laeuft = cockpit.laeuft == true
|
||
let zuschauen = cockpit.zuschauen
|
||
let notAus = cockpit.notAus
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
let schlange = (k?.warteschlange ?? []).filter { !$0.text.isEmpty }
|
||
if !zuschauen, !schlange.isEmpty {
|
||
VStack(alignment: .leading, spacing: 4) {
|
||
ForEach(Array(schlange.enumerated()), id: \.offset) { _, z in
|
||
Label {
|
||
Text(z.text).font(.caption.weight(z.turnier ? .semibold : .regular)).fixedSize(horizontal: false, vertical: true)
|
||
} icon: {
|
||
Image(systemName: z.turnier ? "trophy.fill" : "list.bullet").foregroundStyle(Self.schlangenTon(z.art))
|
||
}
|
||
}
|
||
}
|
||
.padding(8)
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.background(.teal.opacity(0.10), in: RoundedRectangle(cornerRadius: 8))
|
||
}
|
||
if !(notAus && cockpit.verbindung == .verbunden) {
|
||
HStack(alignment: .center, spacing: 8) {
|
||
Statuspunkt(ton: cockpit.ton, groesse: 10)
|
||
VStack(alignment: .leading, spacing: 1) {
|
||
Text(RaumName.kurz(cockpit.satz)).font(.subheadline.weight(.semibold)).lineLimit(2)
|
||
.fixedSize(horizontal: false, vertical: true).help(cockpit.satz)
|
||
if laeuft, let p = k?.phase, !p.text.isEmpty {
|
||
Text(Self.ohneTischzahl(p.text)).font(.caption)
|
||
.foregroundStyle(p.art == .spielen ? AnyShapeStyle(.secondary) : AnyShapeStyle(Color.orange))
|
||
}
|
||
}
|
||
Spacer(minLength: 0)
|
||
}
|
||
}
|
||
if let alarme = k?.konto?.alarme, !alarme.isEmpty { KontoLeiste(alarme: alarme) }
|
||
if !cockpit.freigabe.fensterLesbar { FreigabeHinweis() } else if !cockpit.freigabe.bildschirmaufnahme { BildschirmHinweis() }
|
||
if laeuft, k?.clientPort == false {
|
||
Text("CoinPoker ohne Debug-Port").font(.caption.weight(.semibold)).foregroundStyle(.orange)
|
||
.help("Tische öffnen und Selbstheilen gehen nicht. Aufhören, dann neu starten.")
|
||
}
|
||
if cockpit.wahl.cash, !zuschauen, let d = cockpit.ansicht.geld?.deckel, d.gesperrt, let z = d.zuruecksetzen {
|
||
DeckelBand(deckel: d, zurueck: z)
|
||
}
|
||
if notAus {
|
||
NotAusBand().transition(.scale(scale: 0.95).combined(with: .opacity))
|
||
} else {
|
||
HStack(spacing: 8) {
|
||
HauptknopfAnsicht()
|
||
if !zuschauen, laeuft || cockpit.pausiertGewollt { PauseKnopf() }
|
||
NotAusKnopf(kompakt: false)
|
||
}
|
||
if !zuschauen, cockpit.hauptknopf.uebernehmbar(k) {
|
||
Button { cockpit.offeneUebernehmen() } label: {
|
||
Label("Nur offene Tische spielen", systemImage: "rectangle.on.rectangle").font(.callout.weight(.semibold))
|
||
.frame(maxWidth: .infinity)
|
||
}
|
||
.buttonStyle(.bordered).controlSize(.large)
|
||
.disabled(!cockpit.laufend.isEmpty)
|
||
.help("Übernimmt die Tische, die gerade offen sind - öffnet keine neuen, schließt keine, meldet kein Turnier an. Aufhören wie sonst.")
|
||
}
|
||
}
|
||
}
|
||
.padding(.horizontal, 12).padding(.vertical, 10)
|
||
.animation(.spring(duration: 0.35), value: notAus)
|
||
}
|
||
|
||
static func schlangenTon(_ art: String) -> Color {
|
||
switch art { case "spielt": .green; case "angemeldet", "wartet": .teal; case "aus": .secondary; default: .orange }
|
||
}
|
||
|
||
/// Die Tischzahl der Phase stammt vom Sitzungsbeginn; danach geaendert stand hier eine zweite, falsche Zahl.
|
||
static func ohneTischzahl(_ t: String) -> String {
|
||
t.replacing(#/ · \d+ Tische?(?= ·|$)/#, with: "")
|
||
}
|
||
}
|
||
|
||
/// Pause: der Laeufer klickt nicht mehr, Tische und Sitz bleiben (lokale Pause-Dateien).
|
||
private struct PauseKnopf: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
var body: some View {
|
||
let p = cockpit.pausiertGewollt
|
||
Button { if p { cockpit.fortsetzen() } else { cockpit.pausieren() } } label: {
|
||
Image(systemName: p ? "play.fill" : "pause.fill").font(.system(size: 15, weight: .semibold))
|
||
.foregroundStyle(p ? Color.green : .primary)
|
||
.frame(width: 44, height: 44)
|
||
.background(.white.opacity(0.08), in: RoundedRectangle(cornerRadius: 10))
|
||
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(.white.opacity(0.10)))
|
||
.contentShape(RoundedRectangle(cornerRadius: 10))
|
||
}
|
||
.buttonStyle(.plain)
|
||
.disabled(cockpit.verbindung != .verbunden)
|
||
.help(p ? "Fortsetzen - der Läufer spielt weiter"
|
||
: "Pause - der Läufer klickt nicht mehr, Tische und Sitz bleiben (du kannst manuell spielen). Kein Schließen, umkehrbar.")
|
||
}
|
||
}
|