Files
pokerfreak/mac/Sources/Cockpit/Tische.swift
T
mmintel faebc1df04 mac: Swift ohne live im Dateinamen, Positions-Spec ohne live
LiveTische.swift -> Tische.swift, LiveKachel.swift -> Kachel.swift (Swift importiert keine
Dateien, also ohne Folgen); tests/live_position_spec.py -> tests/position_spec.py mit den
zwei Verweisen. Swift 132 gruen, die drei Specs gruen. Der Putz hatte in Swift #expect fuer
einen #-Kommentar gehalten - mac deshalb von vor dem Putz neu geputzt.
2026-11-01 22:33:57 +01:00

226 lines
9.8 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
/// : 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.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)
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)
}
}
/// 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)
}
}