Files
pokerfreak/mac/Sources/Cockpit/Tische.swift
T
mmintel c2398ae475 Cockpit: Profit/Verlust je Tisch in CHIPS statt BB (BB fehlt oft)
Befund 6.11.: die Haende tragen netto (Chips: +1157, -1320, ...), aber netto_bb ist
None (Big Blind je Hand wird nicht mitgeschrieben) -> die bb-Pille zeigte 0/nichts.
nettoAnzeige(): BB wenn bekannt (!=0), sonst Chips. TischNetto + Mini-Chip nutzen es.
So sieht man endlich das echte +/- je Tisch. (netto_bb-Erfassung bleibt offen.)
2026-11-06 21:36:16 +01:00

325 lines
14 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
/// : oben die Tische (Klick holt einen nach vorn), darunter was gerade geschah. Sitzt der Laeufer
/// 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 Läufer 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.count > 1 { TischMiniLeiste(kacheln: kacheln) } // alle Tische auf einen Blick, ganz oben
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.cash ? "Cash" : "Übung") { EmptyView() }
GeldUebersicht()
if let konto = cockpit.ansicht.kopf?.konto, !konto.felder.isEmpty {
KontoKarte(konto: konto)
}
Abschnitt(titel: "Gerade eben", hinweis: nil) { EmptyView() }
HandFeed()
}
.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.raumInfo?.titel ?? k.raum).font(.subheadline.weight(.semibold)).lineLimit(1)
if let z = k.raumInfo?.zustand { Abzeichen(text: z, farbe: Farben.zustand(z)) }
Spacer(minLength: 0)
TischNetto(raum: k.raumInfo)
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)
HStack(alignment: .top, spacing: 10) {
// deine Karten groß, daneben was der Laeufer damit tut
if !k.karten.isEmpty {
HStack(spacing: 4) { ForEach(Array(k.karten.enumerated()), id: \.offset) { KarteAnsicht(code: $0.element, gross: true) } }
}
VStack(alignment: .leading, spacing: 3) {
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(3)
.fixedSize(horizontal: false, vertical: true)
}
} 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 }) {
if let u = t.urteil { UrteilBand(urteil: u) }
HStack {
Text("Was ich über die Gegner denke").font(.caption2.weight(.semibold)).foregroundStyle(.secondary)
Spacer()
Text("antippen: alle Werte").font(.system(size: 9)).foregroundStyle(.tertiary)
}
GegnerListe(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)
}
}
/// Profit/Verlust zum Anzeigen: BB wenn bekannt (und != 0), sonst Chips - Hauptsache der Spieler
/// sieht +/-. Nil, wenn gar nichts gewertet ist. (6.11.: netto_bb fehlt oft, weil der Big Blind je
/// Hand nicht mitgeschrieben wird; die Chip-Summe ist aber da - also Chips zeigen.)
func nettoAnzeige(_ r: Raum?) -> (text: String, wert: Double)? {
guard let r else { return nil }
if let bb = r.nettoBB, bb != 0 { return (Format.vorzeichen(bb, stellen: 1) + " bb", bb) }
if let c = r.netto { return (Format.vorzeichen(c, stellen: 0), c) }
if let bb = r.nettoBB { return (Format.vorzeichen(bb, stellen: 1) + " bb", bb) }
return nil
}
/// Profit/Verlust an diesem Tisch als Pille: grün im Plus, rot im Minus, Pfeil in die Richtung.
struct TischNetto: View {
var raum: Raum?
var body: some View {
if let a = nettoAnzeige(raum) {
let farbe = Farben.ergebnis(a.wert)
Label {
Text(a.text).font(.caption.monospacedDigit().weight(.semibold))
} icon: {
Image(systemName: a.wert >= 0 ? "arrow.up.right" : "arrow.down.right").font(.system(size: 9, weight: .bold))
}
.foregroundStyle(farbe)
.padding(.horizontal, 7).padding(.vertical, 2)
.background(farbe.opacity(0.15), in: Capsule())
.help(hilfe)
}
}
private var hilfe: String {
var t = "Profit/Verlust an diesem Tisch"
if let c = raum?.netto { t += ": \(Format.vorzeichen(c, stellen: 0)) Chips" }
if let bb = raum?.nettoBB, bb != 0 { t += " · \(Format.vorzeichen(bb, stellen: 1)) bb" }
if let h = raum?.nettoHaende { t += " · \(h) \(h == 1 ? "Hand" : "Hände") gewertet" }
return t
}
}
/// Alle Tische in Miniatur, ganz oben (Eigentümer 6.11.: "alle Tische auf einmal, über dem
/// Einzeltisch"): Name, Zustand-Punkt, Gewinn/Verlust; der Tisch am Zug orange umrandet. Antippen
/// holt den Tisch nach vorn. Waagerecht scrollbar, erst ab zwei Tischen.
struct TischMiniLeiste: View {
var kacheln: [LiveKachel]
@Environment(Cockpit.self) private var cockpit
var body: some View {
VStack(alignment: .leading, spacing: 4) {
Text("Alle Tische (\(kacheln.count))").font(.caption2.weight(.medium)).foregroundStyle(.secondary)
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 6) {
ForEach(kacheln) { k in
Button { cockpit.steuern("tische_vorn", raum: k.raum) } label: { TischChip(k: k) }
.buttonStyle(.plain)
}
}
.padding(.bottom, 2)
}
}
.padding(.horizontal, 2)
}
}
private struct TischChip: View {
var k: LiveKachel
@State private var drueber = false
var body: some View {
let amZug = k.zug?.offen == true
VStack(alignment: .leading, spacing: 3) {
HStack(spacing: 4) {
Circle().fill(Farben.zustand(k.raumInfo?.zustand ?? "")).frame(width: 6, height: 6)
Text(kurz(k.raumInfo?.titel ?? k.raum)).font(.system(size: 10, weight: .semibold)).lineLimit(1)
}
if let a = nettoAnzeige(k.raumInfo) {
Text(a.text)
.font(.system(size: 10, weight: .semibold).monospacedDigit())
.foregroundStyle(Farben.ergebnis(a.wert))
} else {
Text(k.raumInfo?.zustand ?? "–").font(.system(size: 9)).foregroundStyle(.secondary).lineLimit(1)
}
}
.padding(.horizontal, 8).padding(.vertical, 6)
.frame(width: 104, alignment: .leading)
.background(.white.opacity(drueber ? 0.12 : 0.06), in: RoundedRectangle(cornerRadius: 10))
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(amZug ? Color.orange : .clear, lineWidth: 1.5))
.onHover { drueber = $0 }
.help("\(k.raum) nach vorn holen")
}
/// "Big Ben 1727243" -> "Big Ben" (die Nummer weglassen).
private func kurz(_ s: String) -> String {
s.split(separator: " ").filter { Int($0) == nil }.joined(separator: " ")
}
}
/// Sitzt der Laeufer 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 {
Abschnitt(titel: "Bis zum Spielen", hinweis: nil) { EmptyView() }
Schrittleiste()
SitzungsKarte()
if let konto = cockpit.ansicht.kopf?.konto, !konto.felder.isEmpty {
KontoKarte(konto: konto)
}
}
}
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)
}
}