121 lines
5.3 KiB
Swift
121 lines
5.3 KiB
Swift
import CockpitKern
|
|
import SwiftUI
|
|
|
|
/// Übung | Live als Kapsel - Live nur nach Rückfrage, dann wird das ganze Cockpit rot.
|
|
struct ModusSchalter: View {
|
|
@Environment(Cockpit.self) private var cockpit
|
|
|
|
var body: some View {
|
|
let live = cockpit.wahl.live
|
|
HStack(spacing: 0) {
|
|
teil("Übung", an: !live, farbe: .blue) { cockpit.modusWaehlen(live: false) }
|
|
teil("Live", an: live, farbe: .red) { cockpit.modusWaehlen(live: true) }
|
|
}
|
|
.padding(3)
|
|
.background(.white.opacity(0.07), in: Capsule())
|
|
.animation(.snappy, value: live)
|
|
.disabled(cockpit.laeuft == true)
|
|
.help(cockpit.laeuft == true ? "Erst aufhören, dann den Modus wechseln" : "Übung: Spielgeld · Live: Echtgeld")
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
/// Live 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("Live heißt Echtgeld", systemImage: "exclamationmark.triangle.fill")
|
|
.font(.callout.weight(.semibold)).foregroundStyle(.red)
|
|
Text("Der Bot öffnet selbst Cash-Tische und setzt echtes Geld ein - höchstens \(cockpit.wahl.tische) Tisch\(cockpit.wahl.tische == 1 ? "" : "e") und nie mehr als das Budget.")
|
|
.font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
|
|
HStack {
|
|
Button("Abbrechen") { cockpit.liveFragen = false }
|
|
Spacer()
|
|
Button("Live einschalten") { cockpit.liveBestaetigen() }
|
|
.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
|
|
HStack(spacing: 8) {
|
|
Kachel(titel: "Tische") {
|
|
HStack(spacing: 0) {
|
|
Button { cockpit.wahl.tische -= 1 } label: { Image(systemName: "minus").frame(width: 24, height: 24) }
|
|
.disabled(w.tische <= 1)
|
|
Text("\(w.tische)").font(.system(size: 24, weight: .semibold, design: .rounded)).monospacedDigit()
|
|
.frame(maxWidth: .infinity).contentTransition(.numericText())
|
|
Button { cockpit.wahl.tische += 1 } label: { Image(systemName: "plus").frame(width: 24, height: 24) }
|
|
.disabled(w.tische >= Spielplan.hoechstens)
|
|
}
|
|
.buttonStyle(.borderless)
|
|
.animation(.snappy, value: w.tische)
|
|
} fuss: {
|
|
Text(cockpit.laeuft == true ? "\(cockpit.ansicht.kopf?.tischeOffen ?? 0) offen" : "füllt der Läufer auf")
|
|
}
|
|
Kachel(titel: w.live ? "Budget" : "Geld") {
|
|
if w.live {
|
|
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) } ?? "" }
|
|
} else {
|
|
Text("Spielgeld").font(.system(size: 20, weight: .semibold, design: .rounded)).foregroundStyle(.secondary)
|
|
}
|
|
} fuss: {
|
|
if w.live {
|
|
Text(cockpit.ansicht.kopf?.guthaben.map { "von \(Format.zahl($0, stellen: 0)) Guthaben" } ?? "Guthaben noch unbekannt")
|
|
} else {
|
|
Text("Buy-in immer Max")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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))
|
|
}
|
|
}
|