276 lines
12 KiB
Swift
276 lines
12 KiB
Swift
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))
|
||
}
|
||
|
||
private func AlleSchliessen(anzahl: Int) -> some View {
|
||
Button { fragtSchliessen = true } label: { Label("Alle schließen", systemImage: "xmark.square") }
|
||
.buttonStyle(.borderless).font(.caption).foregroundStyle(.red.opacity(0.9))
|
||
.help("Alle \(anzahl) Tische schließen")
|
||
}
|
||
|
||
var body: some View {
|
||
let kacheln = LiveKachel.alle(cockpit.ansicht)
|
||
ScrollView {
|
||
VStack(alignment: .leading, spacing: 10) {
|
||
if kacheln.isEmpty {
|
||
Bereit()
|
||
} else {
|
||
Abschnitt(titel: "Tische", hinweis: "Klick holt nach vorn") {
|
||
AlleSchliessen(anzahl: kacheln.count)
|
||
TischWerkzeuge()
|
||
}
|
||
if fragtSchliessen { schliessenFrage(kacheln.count) }
|
||
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 - als ein Menue statt eines eigenen Reiters.
|
||
struct TischWerkzeuge: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
var body: some View {
|
||
Menu {
|
||
Button("Alle nach vorn", systemImage: "macwindow.on.rectangle") { cockpit.steuern("tische_vorn") }
|
||
Button("Anordnen", systemImage: "rectangle.split.2x2") { cockpit.steuern("tische_anordnen") }
|
||
Button("Übungstisch öffnen", systemImage: "plus.rectangle") { cockpit.steuern("uebungstisch_oeffnen") }
|
||
Button("Foto aller Tische", systemImage: "camera") { cockpit.steuern("foto") }
|
||
Divider()
|
||
Button("Alle schließen", systemImage: "xmark.rectangle", role: .destructive) { cockpit.steuern("tische_schliessen") }
|
||
} label: {
|
||
Image(systemName: "ellipsis.circle")
|
||
}
|
||
.menuStyle(.borderlessButton).menuIndicator(.hidden).fixedSize()
|
||
.help("Alle Tische")
|
||
}
|
||
}
|
||
|
||
struct KachelAnsicht: View {
|
||
var k: LiveKachel
|
||
@Environment(Cockpit.self) private var cockpit
|
||
@State private var drueber = false
|
||
|
||
private var topf: Double? {
|
||
cockpit.ansicht.jetzt?.raum == k.raum ? cockpit.ansicht.jetzt?.topf : nil
|
||
}
|
||
|
||
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) }
|
||
}
|
||
MiniTisch(plaetze: k.raumInfo?.groesse ?? 6, board: k.board, topf: topf, zug: k.zug)
|
||
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 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) { TischWerkzeuge() }
|
||
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)
|
||
}
|
||
}
|