Files
pokerfreak-shell/mac/Sources/Cockpit/LiveTische.swift
T
mmintelandClaude Opus 5.5 f40ae277c0 Mac-App: Modus je Tisch - Turnier mit Spur zum Geld, K-Poker mit Tasten und Uhr
The data layer already sends `modus` on jetzt and on each decision row.
The app now decodes it (TischModus, lenient like the other models) and
shows it on every live tile and in the opened decision: tournament level,
blinds, a pulsing Bubble / green "im Geld" capsule and one tick per
remaining player (filled = paid place, a bar above 40 players); K-Poker
as key caps with sizes and the move clock; Cash as a quiet chip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 10:10:18 +01:00

297 lines
13 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 CockpitKern
import SwiftUI
/// Live: oben die Tische (Klick holt einen nach vorn), darunter was gerade geschah. Sitzt der Bot
/// nirgends, steht dort, was bis zum Spielen fehlt, und wie die letzte Sitzung lief.
struct LiveAnsicht: View {
@Environment(Cockpit.self) private var cockpit
@State private var fragtSchliessen = false
private func schliessenFrage(_ n: Int) -> some View {
HStack {
Text("Alle \(n) Tische schließen? An jedem, an dem der Bot sitzt, steht er auf.").font(.caption)
.fixedSize(horizontal: false, vertical: true)
Spacer()
Button("Abbrechen") { fragtSchliessen = false }
Button("Schließen") {
fragtSchliessen = false
cockpit.steuern("tische_schliessen")
}
.buttonStyle(.borderedProminent).tint(.red)
}
.controlSize(.small)
.padding(8)
.background(.red.opacity(0.12), in: RoundedRectangle(cornerRadius: 10))
}
var body: some View {
let kacheln = LiveKachel.alle(cockpit.ansicht)
ScrollView {
VStack(alignment: .leading, spacing: 10) {
TischLeiste(anzahl: cockpit.ansicht.kopf?.tischeOffen ?? kacheln.count) { fragtSchliessen = true }
if fragtSchliessen { schliessenFrage(max(kacheln.count, cockpit.ansicht.kopf?.tischeOffen ?? 0)) }
if kacheln.isEmpty {
Bereit()
} else {
Abschnitt(titel: "Tische", hinweis: "Klick holt nach vorn") { EmptyView() }
ForEach(kacheln) { KachelAnsicht(k: $0) }
}
Abschnitt(titel: "Geld", hinweis: cockpit.wahl.live ? "Live" : "Übung") { EmptyView() }
GeldInstrumente()
Abschnitt(titel: "Gerade eben", hinweis: nil) { EmptyView() }
Feed()
}
.padding(12)
}
}
}
struct Abschnitt<Rechts: View>: View {
var titel: String
var hinweis: String?
@ViewBuilder var rechts: Rechts
var body: some View {
HStack(alignment: .firstTextBaseline, spacing: 6) {
Text(titel).font(.caption.weight(.semibold)).foregroundStyle(.secondary)
if let hinweis { Text(hinweis).font(.caption2).foregroundStyle(.tertiary) }
Spacer(minLength: 0)
rechts
}
.padding(.top, 4)
}
}
/// Alles, was alle Tische betrifft - immer sichtbar, nicht in einem Menü versteckt.
struct TischLeiste: View {
var anzahl: Int
var schliessen: () -> Void
@Environment(Cockpit.self) private var cockpit
var body: some View {
HStack(spacing: 6) {
knopf("Nach vorn", "macwindow.on.rectangle", "tische_vorn", aus: anzahl == 0)
knopf("Anordnen", "rectangle.split.2x2", "tische_anordnen", aus: anzahl == 0)
knopf("Foto", "camera", "foto", aus: anzahl == 0)
Button(action: schliessen) { kachel("Schließen", "xmark.rectangle", rot: true) }
.buttonStyle(.plain).disabled(anzahl == 0).opacity(anzahl == 0 ? 0.4 : 1)
.help("Alle Tische schließen")
}
}
private func knopf(_ titel: String, _ symbol: String, _ aktion: String, aus: Bool) -> some View {
Button { cockpit.steuern(aktion) } label: {
if cockpit.laeuftGerade(aktion) {
ProgressView().controlSize(.small).frame(maxWidth: .infinity, minHeight: 44)
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 10))
} else {
kachel(titel, symbol, rot: false)
}
}
.buttonStyle(.plain).disabled(aus).opacity(aus ? 0.4 : 1)
.help(titel)
}
private func kachel(_ titel: String, _ symbol: String, rot: Bool) -> some View {
VStack(spacing: 3) {
Image(systemName: symbol).font(.system(size: 14, weight: .semibold))
Text(titel).font(.system(size: 9.5, weight: .medium)).lineLimit(1).minimumScaleFactor(0.8)
}
.foregroundStyle(rot ? Color.red.opacity(0.9) : Color.primary)
.frame(maxWidth: .infinity, minHeight: 44)
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 10))
.contentShape(RoundedRectangle(cornerRadius: 10))
}
}
struct KachelAnsicht: View {
var k: LiveKachel
@Environment(Cockpit.self) private var cockpit
@State private var drueber = false
private var topf: Double? { k.topf }
var body: some View {
// Ein Knopf, keine Geste: das Panel ist am Hintergrund verschiebbar - ein Antippen freier
// Flaeche begann dort ein Fenster-Ziehen, und der Tisch kam nicht nach vorn.
Button { cockpit.steuern("tische_vorn", raum: k.raum) } label: { inhalt }
.buttonStyle(KartenDruck())
}
private var inhalt: some View {
VStack(alignment: .leading, spacing: 7) {
HStack(spacing: 6) {
Text(k.raum).font(.subheadline.weight(.semibold)).lineLimit(1)
if let z = k.raumInfo?.zustand { Abzeichen(text: z, farbe: Farben.zustand(z)) }
Spacer(minLength: 0)
symbolKnopf("camera", "Foto") { cockpit.steuern("foto", raum: k.raum) }
symbolKnopf("xmark", "Tisch schließen") { cockpit.steuern("tische_schliessen", raum: k.raum) }
}
if let m = k.modus { ModusLeiste(modus: m) }
MiniTisch(plaetze: k.raumInfo?.groesse ?? 6, board: k.board, topf: topf, zug: k.zug, tisch: k.raumInfo?.tisch)
if !k.karten.isEmpty {
HStack(spacing: 4) { ForEach(Array(k.karten.enumerated()), id: \.offset) { KarteAnsicht(code: $0.element, gross: true) } }
}
if let a = k.aktion {
HStack(alignment: .firstTextBaseline, spacing: 6) {
Text(Aktionstext.mitBetrag(a, k.betragBB)).font(.callout.weight(.semibold))
if let e = k.equity { Text("Equity \(Format.prozent(e))").font(.caption).foregroundStyle(.secondary) }
Spacer(minLength: 0)
KlickSymbol(status: k.klick?.status, warum: k.klick?.warum)
}
if let t = k.klartext, !t.isEmpty {
Text(t).font(.caption).foregroundStyle(.secondary).lineLimit(2)
}
} else {
Text(k.hinweis ?? "noch keine Entscheidung an diesem Tisch").font(.caption).foregroundStyle(.secondary)
}
if let t = k.raumInfo?.tisch, t.spieler.contains(where: { !$0.ich }) {
HStack {
Text("Gegner").font(.caption2.weight(.semibold)).foregroundStyle(.secondary)
Spacer()
Text("VPIP/PFR/Fold to Bet").font(.system(size: 9)).foregroundStyle(.tertiary)
}
SpielerListe(tisch: t)
}
if let r = k.raumInfo, r.platz != nil || r.stack != nil {
Text("Platz \(r.platz ?? "–") · Stack \(Format.auto(r.stack))" + (r.bb.map { " · BB \($0)" } ?? ""))
.font(.caption2).foregroundStyle(.tertiary)
}
if let b = cockpit.fotos[k.raum] { Foto(url: b) }
}
.padding(10)
.background(.white.opacity(drueber ? 0.09 : 0.05), in: RoundedRectangle(cornerRadius: 16, style: .continuous))
.overlay(RoundedRectangle(cornerRadius: 16, style: .continuous)
.strokeBorder(k.zug?.offen == true ? Color.orange : .clear, lineWidth: 1.5))
.contentShape(RoundedRectangle(cornerRadius: 16))
.animation(.snappy, value: k.zug?.offen)
.onHover { drueber = $0 }
.overlay(alignment: .topTrailing) {
if cockpit.laeuftGerade("tische_vorn", raum: k.raum) { ProgressView().controlSize(.mini).padding(8) }
}
.help("Klick: \(k.raum) nach vorn holen")
}
private func symbolKnopf(_ symbol: String, _ hilfe: String, _ tun: @escaping () -> Void) -> some View {
Button(action: tun) { Image(systemName: symbol).font(.caption) }
.buttonStyle(.borderless).foregroundStyle(.secondary).help(hilfe)
}
}
/// Sitzt der Bot nirgends: was bis zum Spielen fehlt, und wie die letzte Sitzung lief.
struct Bereit: View {
@Environment(Cockpit.self) private var cockpit
var body: some View {
let k = cockpit.ansicht.kopf
let punkte = Checkliste.punkte(k, fensterLesbar: cockpit.freigabe.fensterLesbar)
let naechster = punkte.firstIndex { !$0.erledigt }
Abschnitt(titel: "Bis zum Spielen", hinweis: nil) { EmptyView() }
VStack(alignment: .leading, spacing: 6) {
ForEach(Array(punkte.enumerated()), id: \.offset) { i, p in
HStack(spacing: 8) {
Image(systemName: p.erledigt ? "checkmark.circle.fill" : "circle")
.foregroundStyle(p.erledigt ? Color.green : i == naechster ? Color.accentColor : .secondary)
Text(p.titel).font(.callout)
.foregroundStyle(p.erledigt ? .secondary : .primary)
.fontWeight(i == naechster ? .semibold : .regular)
Spacer(minLength: 0)
}
}
Text("Den Tisch öffnet der Läufer selbst - bis zur Tischzahl oben.").font(.caption).foregroundStyle(.secondary)
}
.padding(10)
.frame(maxWidth: .infinity, alignment: .leading)
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 14))
LetzteSitzung()
}
}
struct LetzteSitzung: View {
@Environment(Cockpit.self) private var cockpit
var body: some View {
let ende = cockpit.ansicht.kopf?.ende
let s = cockpit.ansicht.wachstum?.sitzungen.max { ($0.bis ?? 0) < ($1.bis ?? 0) }
if ende != nil || s != nil {
Abschnitt(titel: "Letzte Sitzung", hinweis: ende?.zeit.map { Zeit.kurz($0) }) { EmptyView() }
Grid(alignment: .leading, horizontalSpacing: 12, verticalSpacing: 4) {
if let e = ende {
GridRow {
Text(e.abbruch ? "Abgebrochen" : "Beendet").foregroundStyle(.secondary)
Text(e.grund ?? "–").foregroundStyle(e.abbruch ? Color.red : .primary).lineLimit(2)
}
}
if let s {
GridRow { Text("Tisch").foregroundStyle(.secondary); Text(s.raum ?? "–").lineLimit(1) }
GridRow { Text("Hände").foregroundStyle(.secondary); Text("\(s.haende ?? 0)") }
GridRow {
Text("Netto").foregroundStyle(.secondary)
Text(Format.vorzeichen(s.nettoBB, stellen: 1) + " bb").foregroundStyle(Farben.ergebnis(s.nettoBB))
}
}
}
.font(.callout)
.padding(10)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.primary.opacity(0.04), in: RoundedRectangle(cornerRadius: 10))
}
}
}
/// Die letzten Entscheidungen, kurz - die ganze Liste steht unter "Hände".
struct Feed: View {
@Environment(Cockpit.self) private var cockpit
static let zeilen = 12
var body: some View {
let z = Array((cockpit.ansicht.entscheidungen?.zeilen ?? []).prefix(Self.zeilen))
if z.isEmpty {
Text("Noch keine Entscheidung.").font(.caption).foregroundStyle(.secondary)
} else {
VStack(spacing: 0) {
ForEach(z) { e in
HStack(spacing: 8) {
Text(Zeit.kurz(e.zeit)).font(.caption.monospacedDigit()).foregroundStyle(.secondary)
.frame(width: 38, alignment: .leading)
Text(e.karten.compactMap { Karte($0) }.map { $0.rang + $0.farbe.symbol }.joined(separator: " "))
.font(.caption.monospaced()).lineLimit(1).minimumScaleFactor(0.6)
.frame(width: 62, alignment: .leading)
Text(Aktionstext.mitBetrag(e.aktionText ?? e.aktion, e.betragBB)).font(.callout).lineLimit(1)
Spacer(minLength: 0)
if let x = e.ergebnisBB {
Text(Format.vorzeichen(x, stellen: 1)).font(.caption.monospacedDigit()).foregroundStyle(Farben.ergebnis(x))
}
}
.padding(.vertical, 4)
.help(e.klartext ?? e.grund ?? "")
Divider().opacity(0.5)
}
Button("Alle Hände") { cockpit.reiter = .haende }.buttonStyle(.link).font(.caption).padding(.top, 6)
}
}
}
}
struct Foto: View {
var url: URL
var body: some View {
AsyncImage(url: url) { bild in
bild.resizable().scaledToFit().clipShape(RoundedRectangle(cornerRadius: 8))
} placeholder: {
ProgressView().frame(maxWidth: .infinity, minHeight: 80)
}
}
}
/// Die Karte gibt beim Drücken sichtbar nach - man sieht, dass der Klick ankam.
struct KartenDruck: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.98 : 1)
.brightness(configuration.isPressed ? 0.06 : 0)
.animation(.snappy(duration: 0.12), value: configuration.isPressed)
}
}