'Wie viele Tische' lag in der Zeitplan-Feineinstellung (Dauer). Owner erwartet es bei den Tischen. Neue TischZahlZeile direkt unter der Tische-Kachel: immer N (Stepper setzt die Zahl) oder ausgelost (Spanne). Aus dem Sitzungs-Abschnitt entfernt, Fussnote angepasst.
200 lines
8.7 KiB
Swift
200 lines
8.7 KiB
Swift
import Foundation
|
||
import CockpitKern
|
||
import SwiftUI
|
||
|
||
/// Übung | Cash als Kapsel - Cash nur nach Rückfrage, dann wird das ganze Cockpit rot.
|
||
struct ModusSchalter: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
var body: some View {
|
||
let zuschauen = cockpit.zuschauen
|
||
let cash = cockpit.wahl.cash && !zuschauen
|
||
HStack(spacing: 0) {
|
||
teil("Zuschauer", an: zuschauen, farbe: .teal) { cockpit.zuschauenWaehlen() }
|
||
teil("Übung", an: !cash && !zuschauen, farbe: .blue) { cockpit.modusWaehlen(cash: false) }
|
||
teil("Cash", an: cash, farbe: .red) { cockpit.modusWaehlen(cash: true) }
|
||
}
|
||
.padding(3)
|
||
.background(.white.opacity(0.07), in: Capsule())
|
||
.animation(.snappy, value: cash)
|
||
.animation(.snappy, value: zuschauen)
|
||
.disabled(cockpit.laeuft == true)
|
||
.help(cockpit.laeuft == true ? "Erst aufhören, dann den Modus wechseln" : "Zuschauer: liest nur, klickt nie · Übung: Claim Chips · Cash: Geld")
|
||
}
|
||
|
||
private func teil(_ titel: String, an: Bool, farbe: Color, _ tun: @escaping () -> Void) -> some View {
|
||
Button(action: tun) {
|
||
Text(titel).font(.callout.weight(.semibold))
|
||
.frame(maxWidth: .infinity).padding(.vertical, 6)
|
||
.foregroundStyle(an ? .white : .secondary)
|
||
.background(an ? farbe.gradient : Color.clear.gradient, in: Capsule())
|
||
.contentShape(Capsule())
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
}
|
||
|
||
/// Cash einschalten nur bewusst: wer tippt, liest einmal, was das heisst.
|
||
struct LiveFrage: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
Label("Cash heißt Geld", systemImage: "exclamationmark.triangle.fill")
|
||
.font(.callout.weight(.semibold)).foregroundStyle(.red)
|
||
Text("Der Läufer öffnet selbst Tische und setzt Geld.")
|
||
.font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
|
||
HStack {
|
||
Button("Abbrechen") { cockpit.cashFragen = false }
|
||
Spacer()
|
||
Button("Cash einschalten") { cockpit.cashBestaetigen() }
|
||
.buttonStyle(.borderedProminent).tint(.red)
|
||
}
|
||
.controlSize(.small)
|
||
}
|
||
.padding(10)
|
||
.background(.red.opacity(0.12), in: RoundedRectangle(cornerRadius: 12))
|
||
}
|
||
}
|
||
|
||
/// Tischzahl und Budget - zwei Kacheln wie Instrumente.
|
||
struct PlanKacheln: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
@State private var budgetText = ""
|
||
|
||
var body: some View {
|
||
let w = cockpit.wahl
|
||
return VStack(alignment: .leading, spacing: 8) {
|
||
HStack(spacing: 8) {
|
||
Kachel(titel: "Tische") {
|
||
// die Zahl je Format steht darunter in "Was spielen" - hier die Summe
|
||
Text(w.tischeBis.map { "\(w.tische)–\($0)" } ?? "\(w.tische)")
|
||
.font(.system(size: w.tischeBis == nil ? 24 : 20, weight: .semibold, design: .rounded)).monospacedDigit()
|
||
.frame(maxWidth: .infinity, alignment: .leading).contentTransition(.numericText())
|
||
.animation(.snappy, value: w.tische)
|
||
} fuss: {
|
||
Text(cockpit.laeuft == true ? "\(cockpit.ansicht.kopf?.tischeOffen ?? 0) von \(w.tische) offen" : "füllt der Läufer auf")
|
||
}
|
||
if w.cash {
|
||
// In Cash bleibt das Budget direkt eintippbar; der Pfeil oben rechts öffnet den Geld-Editor.
|
||
Kachel(titel: "Budget") {
|
||
TextField("ohne", text: $budgetText)
|
||
.font(.system(size: 22, weight: .semibold, design: .rounded))
|
||
.textFieldStyle(.plain)
|
||
.onSubmit { budgetUebernehmen() }
|
||
.onAppear { budgetText = w.budget.map { Format.zahl($0, stellen: 0) } ?? "" }
|
||
} fuss: {
|
||
Text(cockpit.ansicht.kopf?.guthaben.map { "von \(Format.zahl($0, stellen: 0)) Guthaben" } ?? "Guthaben noch unbekannt")
|
||
}
|
||
.overlay(alignment: .topTrailing) { geldPfeil }
|
||
} else {
|
||
Button { oeffneGeld() } label: {
|
||
Kachel(titel: "Geld") {
|
||
Text("Chips").font(.system(size: 20, weight: .semibold, design: .rounded)).foregroundStyle(.secondary)
|
||
} fuss: {
|
||
Text("Buy-in \(w.geld.kauf == .max ? "Max" : "Min")")
|
||
}
|
||
.overlay(alignment: .topTrailing) { geldPfeil }
|
||
}
|
||
.buttonStyle(.plain)
|
||
.help("Stakes, Einkauf und Stopps")
|
||
}
|
||
PlanKachel()
|
||
}
|
||
TischZahlZeile()
|
||
}
|
||
}
|
||
|
||
private var geldPfeil: some View {
|
||
Button { oeffneGeld() } label: {
|
||
Image(systemName: cockpit.geldOffen ? "chevron.up" : "chevron.down")
|
||
.font(.caption2).foregroundStyle(.secondary).padding(8)
|
||
}
|
||
.buttonStyle(.plain)
|
||
.help("Stakes, Einkauf und Stopps")
|
||
}
|
||
|
||
/// Geld-Editor auf/zu - und den Zeitplan dabei zu (immer nur einer offen).
|
||
private func oeffneGeld() {
|
||
cockpit.planOffen = false
|
||
cockpit.geldOffen.toggle()
|
||
}
|
||
|
||
private func budgetUebernehmen() {
|
||
let roh = budgetText.replacingOccurrences(of: ".", with: "").replacingOccurrences(of: ",", with: ".")
|
||
cockpit.wahl.budget = Double(roh.trimmingCharacters(in: .whitespaces)).flatMap { $0 > 0 ? $0 : nil }
|
||
budgetText = cockpit.wahl.budget.map { Format.zahl($0, stellen: 0) } ?? ""
|
||
}
|
||
}
|
||
|
||
struct Kachel<Inhalt: View, Fuss: View>: View {
|
||
var titel: String
|
||
@ViewBuilder var inhalt: Inhalt
|
||
@ViewBuilder var fuss: Fuss
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 2) {
|
||
Text(titel).font(.caption2.weight(.medium)).foregroundStyle(.secondary)
|
||
inhalt.frame(height: 30)
|
||
fuss.font(.caption2).foregroundStyle(.secondary).lineLimit(1)
|
||
}
|
||
.padding(10)
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 14))
|
||
}
|
||
}
|
||
|
||
/// Wie viele Tische - hier bei den Tischen, nicht im Zeitplan (Eigentümer 6.11.: "unter Tische,
|
||
/// nicht unter Dauer"). "immer N" setzt die feste Zahl (Stepper daneben); "ausgelost" würfelt sie
|
||
/// je Sitzung zwischen N und einer Obergrenze.
|
||
struct TischZahlZeile: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
var body: some View {
|
||
@Bindable var c = cockpit
|
||
HStack(spacing: 8) {
|
||
Text("Tische je Sitzung").font(.caption.weight(.medium))
|
||
Picker("", selection: Binding(
|
||
get: { c.wahl.tischeBis != nil },
|
||
set: { c.wahl.tischeBis = $0 ? min(c.wahl.tische + 2, Spielplan.hoechstens) : nil })) {
|
||
Text("immer \(c.wahl.tische)").tag(false)
|
||
Text("ausgelost").tag(true)
|
||
}
|
||
.pickerStyle(.segmented).labelsHidden().fixedSize()
|
||
if let bis = c.wahl.tischeBis {
|
||
Stepper("\(c.wahl.tische) bis \(bis)",
|
||
value: Binding(get: { bis }, set: { c.wahl.tischeBis = $0 }),
|
||
in: (c.wahl.tische + 1)...Spielplan.hoechstens)
|
||
.font(.caption).fixedSize()
|
||
} else {
|
||
Stepper("\(c.wahl.tische) \(c.wahl.tische == 1 ? "Tisch" : "Tische")",
|
||
value: Binding(get: { c.wahl.tische }, set: { c.wahl.tische = $0 }),
|
||
in: 1...Spielplan.hoechstens)
|
||
.font(.caption).fixedSize()
|
||
}
|
||
Spacer(minLength: 0)
|
||
}
|
||
.font(.caption)
|
||
}
|
||
}
|
||
|
||
/// Der lebende Zeiger: zwischen den Zügen driftet, deutet und ruht er wie eine Hand (hand/zeiger.py).
|
||
/// Bewegst du die Maus, weicht er.
|
||
struct ZeigerSchalter: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
var body: some View {
|
||
let an = cockpit.wahl.zeiger
|
||
Button { cockpit.wahl.zeiger.toggle() } label: {
|
||
Label(an ? "Hand lebt" : "Hand ruht", systemImage: an ? "hand.point.up.left.fill" : "hand.point.up.left")
|
||
.font(.caption.weight(.medium))
|
||
.padding(.horizontal, 8).padding(.vertical, 3)
|
||
.background(.white.opacity(an ? 0.16 : 0.08), in: Capsule())
|
||
}
|
||
.buttonStyle(.plain)
|
||
.foregroundStyle(an ? Color.accentColor : Color.secondary)
|
||
.help(an ? "Der Zeiger bewegt sich zwischen den Zügen wie eine Hand - antippen zum Abschalten"
|
||
: "Zeiger steht zwischen den Zügen still - antippen, damit er wie eine Hand lebt")
|
||
}
|
||
}
|