Gegnerprofile kamen bei mehreren Tischen vom falschen Platz: spot_from_log ordnet die hud_stats jetzt ueber die Sitzliste des eigenen Raums zu (profil.aus_sitzliste). Die Vorschau zeigt alle Plaetze mit Rolle, Stack, Aktion, Typ und VPIP/PFR/F2B, auch ohne laufenden Laeufer, und keine alten Karten an Tischen, an denen du nicht sitzt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
274 lines
12 KiB
Swift
274 lines
12 KiB
Swift
import CockpitKern
|
||
import SwiftUI
|
||
|
||
/// Ein Tisch als Bild: Filz-Oval, Sitze rundherum, Board und Topf in der Mitte, der eigene Platz
|
||
/// unten mit dem Countdown als Ring. Groesse und eigener Platz aus dem Log (sitzen.raeume).
|
||
struct MiniTisch: View {
|
||
var plaetze: Int
|
||
var board: [String]
|
||
var topf: Double?
|
||
var zug: Zug?
|
||
/// Mit Plätzen aus dem Log: jeder Sitz als Schild (Name, Stack, Rolle, Aktion).
|
||
var tisch: TischAnsicht? = nil
|
||
|
||
private static let filzHell = Color(red: 0.08, green: 0.45, blue: 0.30)
|
||
private static let filzDunkel = Color(red: 0.03, green: 0.25, blue: 0.17)
|
||
private static let bande = Color(red: 0.36, green: 0.24, blue: 0.13)
|
||
private static let sitzFarbe = Color(red: 0.14, green: 0.19, blue: 0.25)
|
||
|
||
var body: some View {
|
||
GeometryReader { g in
|
||
let w: Double = g.size.width
|
||
let h: Double = g.size.height
|
||
let mitte = CGPoint(x: w / 2, y: h / 2 - 6)
|
||
let rx: Double = w / 2 - (tisch == nil ? 22 : 40)
|
||
let ry: Double = h / 2 - (tisch == nil ? 20 : 26)
|
||
ZStack {
|
||
filz(breite: rx * 2 + 16, hoehe: ry * 2 + 14, radius: w / 2)
|
||
.position(x: mitte.x, y: mitte.y)
|
||
tischmitte.position(mitte)
|
||
ForEach(0..<sitzzahl, id: \.self) { i in
|
||
sitz(i).position(Self.lage(i, von: sitzzahl, mitte: mitte, rx: rx, ry: ry))
|
||
}
|
||
}
|
||
}
|
||
.frame(height: tisch == nil ? 118 : 176)
|
||
}
|
||
|
||
/// Der Spieler an Stelle i (0 = unten, dein Platz).
|
||
private func spieler(an i: Int) -> Spieler? {
|
||
guard let t = tisch else { return nil }
|
||
return t.spieler.first { Sitzlage.stelle(sitz: $0.sitz, ich: t.ich, plaetze: sitzzahl) == i }
|
||
}
|
||
|
||
private var sitzzahl: Int { max(2, plaetze) }
|
||
|
||
/// Sitz i auf dem Oval; Sitz 0 (der eigene) unten in der Mitte.
|
||
private static func lage(_ i: Int, von n: Int, mitte: CGPoint, rx: Double, ry: Double) -> CGPoint {
|
||
let winkel = Double.pi / 2 + 2 * Double.pi * Double(i) / Double(n)
|
||
return CGPoint(x: mitte.x + rx * cos(winkel), y: mitte.y + ry * sin(winkel))
|
||
}
|
||
|
||
private func filz(breite: Double, hoehe: Double, radius: Double) -> some View {
|
||
let verlauf = RadialGradient(colors: [Self.filzHell, Self.filzDunkel], center: .center, startRadius: 4, endRadius: radius)
|
||
return Ellipse().fill(verlauf)
|
||
.overlay(Ellipse().strokeBorder(Self.bande, lineWidth: 5))
|
||
.frame(width: breite, height: hoehe)
|
||
}
|
||
|
||
private var tischmitte: some View {
|
||
let karten = Array(board.filter { Karte($0) != nil }.prefix(5))
|
||
return VStack(spacing: 4) {
|
||
if let topf {
|
||
Text("Topf \(Format.auto(topf))").font(.caption2.weight(.semibold)).foregroundStyle(.white.opacity(0.85))
|
||
}
|
||
HStack(spacing: 3) {
|
||
ForEach(Array(karten.enumerated()), id: \.offset) { _, k in
|
||
KarteAnsicht(code: k).scaleEffect(0.8).frame(width: 22, height: 28)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
@ViewBuilder private func sitz(_ i: Int) -> some View {
|
||
if let s = spieler(an: i) {
|
||
SitzSchild(spieler: s, zug: s.ich ? zug : nil)
|
||
} else if tisch != nil {
|
||
Circle().fill(Self.sitzFarbe.opacity(0.5)).frame(width: 12, height: 12) // frei
|
||
} else if i == 0 {
|
||
EigenerPlatz(zug: zug)
|
||
} else {
|
||
Circle().fill(Self.sitzFarbe).frame(width: 16, height: 16)
|
||
.overlay(Circle().stroke(.white.opacity(0.12)))
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Ein Platz am Tisch: Name, Stack in BB, Rolle (BTN/SB/BB) und die letzte Aktion dieser Hand.
|
||
/// Wer aussitzt, ist blass; dein Platz trägt den Countdown-Ring.
|
||
struct SitzSchild: View {
|
||
var spieler: Spieler
|
||
var zug: Zug?
|
||
|
||
var body: some View {
|
||
VStack(spacing: 1) {
|
||
HStack(spacing: 2) {
|
||
if spieler.ich { EigenerPlatz(zug: zug).scaleEffect(0.62).frame(width: 16, height: 16) }
|
||
if let r = spieler.rolle { RollenChip(rolle: r) }
|
||
Text(spieler.name).font(.system(size: 9, weight: .semibold)).lineLimit(1).truncationMode(.tail)
|
||
}
|
||
Text(spieler.stackBB.map { "\(Format.auto($0)) bb" } ?? "–")
|
||
.font(.system(size: 8.5, weight: .medium).monospacedDigit()).foregroundStyle(.white.opacity(0.75))
|
||
if let a = spieler.aktion {
|
||
Text(Aktionstext.kurz(a, spieler.betragBB))
|
||
.font(.system(size: 8, weight: .bold)).foregroundStyle(Aktionstext.farbe(a))
|
||
}
|
||
}
|
||
.padding(.horizontal, 4).padding(.vertical, 2)
|
||
.frame(maxWidth: 74)
|
||
.background(spieler.ich ? Color.accentColor.opacity(0.35) : Color.black.opacity(0.45),
|
||
in: RoundedRectangle(cornerRadius: 6))
|
||
.opacity(spieler.draussen ? 0.45 : 1)
|
||
}
|
||
}
|
||
|
||
struct RollenChip: View {
|
||
var rolle: String
|
||
var body: some View {
|
||
Text(rolle == "BTN" ? "D" : rolle).font(.system(size: 7, weight: .heavy))
|
||
.padding(.horizontal, 2.5).padding(.vertical, 0.5)
|
||
.foregroundStyle(rolle == "BTN" ? Color.black : Color.white)
|
||
.background(rolle == "BTN" ? Color.white : Color.blue.opacity(0.8), in: Capsule())
|
||
}
|
||
}
|
||
|
||
/// Die Gegner als Liste: Rolle, Name, Stack, Aktion - und was der Bot über sie weiss (VPIP, PFR,
|
||
/// Fold to Bet aus hud_stats) mit einer Einordnung in einem Wort.
|
||
struct SpielerListe: View {
|
||
var tisch: TischAnsicht
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 3) {
|
||
ForEach(tisch.spieler.filter { !$0.ich }) { s in zeile(s) }
|
||
}
|
||
}
|
||
|
||
private func zeile(_ s: Spieler) -> some View {
|
||
HStack(spacing: 5) {
|
||
Group {
|
||
if let r = s.rolle { RollenChip(rolle: r) } else { Color.clear }
|
||
}
|
||
.frame(width: 18)
|
||
Text(s.name).font(.caption2.weight(.semibold)).lineLimit(1).frame(maxWidth: 96, alignment: .leading)
|
||
Text(s.stackBB.map { "\(Format.auto($0)) bb" } ?? "–").font(.caption2.monospacedDigit())
|
||
.foregroundStyle(.secondary).frame(width: 52, alignment: .trailing)
|
||
if let a = s.aktion {
|
||
Text(Aktionstext.kurz(a, s.betragBB)).font(.caption2.weight(.bold)).foregroundStyle(Aktionstext.farbe(a))
|
||
}
|
||
Spacer(minLength: 2)
|
||
profil(s.profil)
|
||
}
|
||
.opacity(s.draussen ? 0.5 : 1)
|
||
}
|
||
|
||
@ViewBuilder private func profil(_ p: Spieler.Profil?) -> some View {
|
||
if let p {
|
||
HStack(spacing: 4) {
|
||
if let t = p.typ { Abzeichen(text: t.kurz, farbe: Self.farbe(t.kurz)).help(t.lang) }
|
||
Text(werte(p)).font(.system(size: 9).monospacedDigit()).foregroundStyle(.secondary)
|
||
if let d = Spielertyp.druck(p.foldToBet) {
|
||
Text(d).font(.system(size: 9, weight: .medium)).foregroundStyle(.orange)
|
||
}
|
||
}
|
||
} else {
|
||
Text("noch keine Werte").font(.system(size: 9)).foregroundStyle(.tertiary)
|
||
}
|
||
}
|
||
|
||
private func werte(_ p: Spieler.Profil) -> String {
|
||
let z = { (x: Double?) in x.map { "\(Int(($0 * 100).rounded()))" } ?? "–" }
|
||
return "\(z(p.vpip))/\(z(p.pfr))/\(z(p.foldToBet))"
|
||
}
|
||
|
||
static func farbe(_ typ: String) -> Color {
|
||
switch typ {
|
||
case "Fisch": .green
|
||
case "Maniac": .red
|
||
case "Loose": .orange
|
||
case "Nit": .gray
|
||
case "TAG": .blue
|
||
default: .purple
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Der eigene Platz: pulsiert, solange ein Zug offen ist; der Ring ist die Restzeit.
|
||
struct EigenerPlatz: View {
|
||
var zug: Zug?
|
||
|
||
var body: some View {
|
||
TimelineView(.periodic(from: .now, by: 0.25)) { t in
|
||
let c = Countdown(zug: zug, jetzt: t.date.timeIntervalSince1970)
|
||
let f: Color = (c?.anteil ?? 1) < 0.25 ? .red : (c?.anteil ?? 1) < 0.5 ? .orange : .green
|
||
ZStack {
|
||
Circle().fill(Color(red: 0.10, green: 0.13, blue: 0.18))
|
||
if let c {
|
||
Circle().trim(from: 0, to: c.anteil).stroke(f, style: .init(lineWidth: 3, lineCap: .round)).rotationEffect(.degrees(-90))
|
||
Text("\(Int(c.rest.rounded(.up)))").font(.caption2.monospacedDigit().weight(.bold)).foregroundStyle(.white)
|
||
} else {
|
||
Circle().stroke(.white.opacity(0.35), lineWidth: 1.5)
|
||
Image(systemName: "person.fill").font(.system(size: 9)).foregroundStyle(.white.opacity(0.7))
|
||
}
|
||
}
|
||
.frame(width: 26, height: 26)
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Geld als Instrument: Netto gegen die Stop-Grenze, gesamt und je Tisch, dazu die Regeln.
|
||
struct GeldInstrumente: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
var body: some View {
|
||
let g = cockpit.ansicht.geld
|
||
let r = g?.regeln
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
if let s = g?.stand, let netto = s.sitzungBB {
|
||
StopBalken(titel: "Sitzung", netto: netto, grenze: r?.stopSitzungBB)
|
||
ForEach(s.tische) { t in
|
||
StopBalken(titel: t.raum, netto: t.nettoBB ?? 0, grenze: r?.stopTischBB)
|
||
}
|
||
} else {
|
||
Text("Keine laufende Sitzung.").font(.caption).foregroundStyle(.secondary)
|
||
}
|
||
if let r {
|
||
Text(regelzeile(r, live: cockpit.wahl.live)).font(.caption2).foregroundStyle(.secondary)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
}
|
||
.padding(10)
|
||
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 14))
|
||
}
|
||
|
||
private func regelzeile(_ r: GeldRegeln, live: Bool) -> String {
|
||
var teile: [String] = []
|
||
teile.append("Buy-in " + ((live ? r.buyinEcht : r.buyinUebung) ?? "–"))
|
||
if let n = r.nachkaufUnterBB { teile.append("Nachkauf unter \(Format.zahl(n, stellen: 0)) bb") }
|
||
if let a = r.aufstehenUnterBB { teile.append("Aufstehen unter \(Format.zahl(a, stellen: 0)) bb") }
|
||
if let t = r.hoechstensTische { teile.append("höchstens \(t) Tische") }
|
||
if r.ratholing { teile.append("Ratholing an") }
|
||
return teile.joined(separator: " · ")
|
||
}
|
||
}
|
||
|
||
/// Ein Balken: links der Verlust bis zur Grenze (füllt sich rot), rechts der Gewinn (grün).
|
||
struct StopBalken: View {
|
||
var titel: String
|
||
var netto: Double
|
||
var grenze: Double?
|
||
|
||
var body: some View {
|
||
let g = max(1, grenze ?? 100)
|
||
let anteil = min(1, abs(netto) / g)
|
||
VStack(alignment: .leading, spacing: 4) {
|
||
HStack {
|
||
Text(titel).font(.caption).lineLimit(1)
|
||
Spacer()
|
||
Text(Format.vorzeichen(netto, stellen: 1) + " bb").font(.caption.monospacedDigit().weight(.semibold))
|
||
.foregroundStyle(Farben.ergebnis(netto))
|
||
if grenze != nil { Text("/ −\(Format.zahl(g, stellen: 0))").font(.caption2).foregroundStyle(.secondary) }
|
||
}
|
||
GeometryReader { geo in
|
||
ZStack(alignment: .leading) {
|
||
Capsule().fill(.white.opacity(0.08))
|
||
Capsule().fill(netto < 0 ? (anteil > 0.75 ? Color.red : .orange).gradient : Color.green.gradient)
|
||
.frame(width: max(4, geo.size.width * (netto < 0 ? anteil : min(1, netto / g))))
|
||
}
|
||
}
|
||
.frame(height: 6)
|
||
.animation(.snappy, value: netto)
|
||
}
|
||
.help(netto < 0 ? "Bei −\(Format.zahl(g, stellen: 0)) bb steht der Bot auf" : "im Plus")
|
||
}
|
||
}
|