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) } } // Weniger Tische offen als geplant: je fehlenden Tisch eine SICHTBARE Such-Kachel - damit man // merkt, dass die Lücke Absicht ist (kein freier Holdem-Cash in der Lobby), kein Hänger. Nur im // laufenden Spielbetrieb (Owner 7.11.). let fehlt = cockpit.wahl.tische - kacheln.count if cockpit.laeuft == true, !cockpit.zuschauen, fehlt > 0 { ForEach(0.. 0 } private var typ: String { cockpit.wahl.turnier.kategorie ?? "Turnier" } var body: some View { VStack(alignment: .leading, spacing: 6) { HStack(spacing: 6) { Image(systemName: turnier ? "trophy" : "magnifyingglass").foregroundStyle(.secondary) Text(turnier ? "Warte auf das nächste \(typ) …" : "Suche weiteren Tisch …") .font(.callout.weight(.medium)) Spacer() ProgressView().controlSize(.small) } Text(turnier ? "Gerade kein anmeldbares \(typ) in der Lobby – laufende/volle und beendete zählen nicht. " + "Sobald der nächste angekündigt wird (Anmeldung offen), meldet er automatisch an." : "Gerade kein freier Holdem-Cash-Tisch in der Lobby. Tipp: unter „Tische“ ein zweites " + "Format dazunehmen (z. B. All-In-or-Fold) – dann füllt er auf.") .font(.caption).foregroundStyle(.secondary) .fixedSize(horizontal: false, vertical: true) } .padding(10) .frame(maxWidth: .infinity, alignment: .leading) .background( RoundedRectangle(cornerRadius: 10) .strokeBorder(style: StrokeStyle(lineWidth: 1, dash: [5])) .foregroundStyle(.secondary.opacity(0.5))) } } struct Abschnitt: 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) } } /// Ein einklappbarer Abschnitt: Kopfzeile mit Symbol und Chevron, Inhalt nur offen. Der Zustand /// merkt sich je `schluessel` (bleibt über Neustarts). So wird die lange Seite kurz - Nebeninfos /// liegen hinter einem Klick (Owner 7.11.: Infos hinter Expandables verstecken). struct EinklappAbschnitt: View { var titel: String var symbol: String var hinweis: String? var schluessel: String @ViewBuilder var inhalt: Inhalt @State private var offen: Bool init(titel: String, symbol: String, hinweis: String? = nil, schluessel: String, vorgabe: Bool = true, @ViewBuilder inhalt: () -> Inhalt) { self.titel = titel; self.symbol = symbol; self.hinweis = hinweis; self.schluessel = schluessel self.inhalt = inhalt() _offen = State(initialValue: UserDefaults.standard.object(forKey: schluessel) as? Bool ?? vorgabe) } var body: some View { VStack(alignment: .leading, spacing: 8) { Button { offen.toggle() UserDefaults.standard.set(offen, forKey: schluessel) } label: { HStack(alignment: .firstTextBaseline, spacing: 6) { Image(systemName: symbol).font(.caption2).foregroundStyle(.secondary).frame(width: 14) Text(titel).font(.caption.weight(.semibold)).foregroundStyle(.secondary) if let hinweis { Text(hinweis).font(.caption2).foregroundStyle(.tertiary) } Spacer(minLength: 0) Image(systemName: offen ? "chevron.down" : "chevron.right") .font(.caption2).foregroundStyle(.tertiary) } .contentShape(Rectangle()) } .buttonStyle(.plain) if offen { inhalt } } .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) { Button { if cockpit.pausiertGewollt { cockpit.fortsetzen() } else { cockpit.pausieren() } } label: { kachel(cockpit.pausiertGewollt ? "Fortsetzen" : "Pause", cockpit.pausiertGewollt ? "play.fill" : "pause.fill", rot: false) } .buttonStyle(.plain) .help(cockpit.pausiertGewollt ? "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.") 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() // Sicherheit/Kontozustand im Detail jetzt im Einstellungsfenster (⌘, → Sicherheit). } } 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) } }