Die App ist die scharfe Schicht (Bedienkonsole des Laufs) - und sie hat es erzaehlt: Menuepunkt 'Klon statt echtem Client', 'Cash heisst Echtgeld', 'Der Bot oeffnet selbst Cash-Tische und setzt echtes Geld ein.', Abzeichen 'Spielgeld/Echtgeld', '(nur Live)'. Jetzt spricht sie mechanisch: Uebung, Cash, Geld, Chips, Tisch, Laeufer, Klon, Client, Not-Aus. swift build laeuft, swift run Pruefung 132 gruen. Die installierte App zeigt die alten Woerter noch, bis sie neu gebaut und installiert wird.
340 lines
15 KiB
Swift
340 lines
15 KiB
Swift
import CockpitKern
|
||
import SwiftUI
|
||
|
||
/// Die Phase des Zeitplans, solange der Läufer läuft - Sitzung, Pause, Fenster zu, fertig.
|
||
struct PhaseBand: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
var body: some View {
|
||
if cockpit.laeuft == true, let p = cockpit.ansicht.kopf?.phase {
|
||
Label(p.text, systemImage: Self.symbol(p.art))
|
||
.font(.caption.weight(.medium)).lineLimit(2)
|
||
.foregroundStyle(p.art == .spielen ? Color.primary : Color.orange)
|
||
.padding(.horizontal, 10).padding(.vertical, 6)
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.background(.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 10))
|
||
.contentTransition(.numericText())
|
||
}
|
||
}
|
||
|
||
static func symbol(_ a: Phase.Art?) -> String {
|
||
switch a {
|
||
case .spielen: "play.circle.fill"
|
||
case .pause: "cup.and.saucer.fill"
|
||
case .ausserhalb: "moon.zzz.fill"
|
||
case .fertig: "flag.checkered"
|
||
case nil: "clock"
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Zeitplan und Geldmodell auf einen Blick - antippen klappt den Plan auf.
|
||
struct PlanKachel: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
|
||
var body: some View {
|
||
let w = cockpit.wahl
|
||
let vorlage = PlanVorlage.erkennen(w)
|
||
Button { cockpit.planOffen.toggle() } label: {
|
||
Kachel(titel: "Plan") {
|
||
Label(vorlage?.titel ?? "Eigener", systemImage: vorlage?.symbol ?? "slider.horizontal.3")
|
||
.font(.callout.weight(.semibold)).lineLimit(1)
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
} fuss: {
|
||
Text(vorlage?.untertitel ?? w.zeitplan.kurz)
|
||
}
|
||
.overlay(alignment: .topTrailing) {
|
||
Image(systemName: cockpit.planOffen ? "chevron.up" : "chevron.down")
|
||
.font(.caption2).foregroundStyle(.secondary).padding(8)
|
||
}
|
||
}
|
||
.buttonStyle(.plain)
|
||
.help("Wie lange, wie oft, mit welchen Stops")
|
||
}
|
||
}
|
||
|
||
/// Der Plan: drei Vorlagen als Knöpfe, darunter in einem Satz, was der Läufer damit tut. Die
|
||
/// Feineinstellung bleibt eingeklappt. Jede Änderung geht gleich an den Läufer.
|
||
struct PlanEditor: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
@State private var fein = false
|
||
|
||
var body: some View {
|
||
@Bindable var c = cockpit
|
||
let aktiv = PlanVorlage.erkennen(c.wahl)
|
||
VStack(alignment: .leading, spacing: 10) {
|
||
HStack(spacing: 6) {
|
||
ForEach(PlanVorlage.allCases) { v in
|
||
VorlageKnopf(vorlage: v, an: aktiv == v) { v.anwenden(auf: &c.wahl) }
|
||
}
|
||
}
|
||
Text(c.wahl.ablauf)
|
||
.font(.caption).foregroundStyle(.secondary)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
DisclosureGroup(isExpanded: $fein) {
|
||
Feineinstellung().padding(.top, 8)
|
||
} label: {
|
||
Text(aktiv == nil ? "Feineinstellung · eigener Plan" : "Feineinstellung")
|
||
.font(.caption.weight(.medium))
|
||
}
|
||
HStack {
|
||
Spacer()
|
||
Button("Fertig") { c.planOffen = false }.buttonStyle(.borderedProminent)
|
||
}
|
||
}
|
||
.controlSize(.small)
|
||
.padding(10)
|
||
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 14))
|
||
}
|
||
}
|
||
|
||
private struct VorlageKnopf: View {
|
||
var vorlage: PlanVorlage
|
||
var an: Bool
|
||
var tun: () -> Void
|
||
|
||
var body: some View {
|
||
Button(action: tun) {
|
||
VStack(spacing: 4) {
|
||
Image(systemName: vorlage.symbol).font(.system(size: 20, weight: .semibold))
|
||
Text(vorlage.titel).font(.caption.weight(.semibold)).lineLimit(1).minimumScaleFactor(0.8)
|
||
Text(vorlage.untertitel).font(.caption2).foregroundStyle(an ? .white.opacity(0.85) : .secondary)
|
||
.lineLimit(2).multilineTextAlignment(.center)
|
||
}
|
||
.frame(maxWidth: .infinity, minHeight: 74)
|
||
.padding(.vertical, 6).padding(.horizontal, 4)
|
||
.foregroundStyle(an ? Color.white : Color.primary)
|
||
.background(an ? AnyShapeStyle(Color.accentColor.gradient) : AnyShapeStyle(.white.opacity(0.07)),
|
||
in: RoundedRectangle(cornerRadius: 12))
|
||
.contentShape(RoundedRectangle(cornerRadius: 12))
|
||
}
|
||
.buttonStyle(.plain)
|
||
.animation(.snappy, value: an)
|
||
}
|
||
}
|
||
|
||
/// Alles einzeln, als Sätze: jede Zeile sagt, was der Läufer tut.
|
||
private struct Feineinstellung: View {
|
||
@Environment(Cockpit.self) private var cockpit
|
||
@State private var stakesText = ""
|
||
|
||
var body: some View {
|
||
@Bindable var c = cockpit
|
||
VStack(alignment: .leading, spacing: 12) {
|
||
PlanAbschnitt(titel: "Sitzungen", symbol: "calendar.badge.clock") {
|
||
Frage("Wie viele Tische je Sitzung?") {
|
||
Wahl(an: c.wahl.tischeBis != nil, aus: "immer \(c.wahl.tische)", an_: "ausgelost") {
|
||
c.wahl.tischeBis = $0 ? min(c.wahl.tische + 2, Spielplan.hoechstens) : nil
|
||
}
|
||
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)
|
||
}
|
||
}
|
||
Frage("Wie lange dauert eine Sitzung?") {
|
||
Wahl(an: c.wahl.zeitplan.sitzung != nil, aus: "ohne Ende", an_: "begrenzt") {
|
||
c.wahl.zeitplan.sitzung = $0 ? Spanne(45, 90) : nil
|
||
}
|
||
if c.wahl.zeitplan.sitzung != nil {
|
||
MinutenSpanne(wert: Binding(get: { c.wahl.zeitplan.sitzung ?? Spanne(45, 90) },
|
||
set: { c.wahl.zeitplan.sitzung = $0 }), unten: 5)
|
||
}
|
||
}
|
||
if c.wahl.zeitplan.sitzung != nil {
|
||
Frage("Und danach?") {
|
||
Wahl(an: c.wahl.zeitplan.pause.bis > 0, aus: "Schluss", an_: "Pause, dann weiter") {
|
||
c.wahl.zeitplan.pause = $0 ? Spanne(10, 20) : Spanne(0, 0)
|
||
}
|
||
if c.wahl.zeitplan.pause.bis > 0 {
|
||
MinutenSpanne(wert: $c.wahl.zeitplan.pause, unten: 1)
|
||
}
|
||
}
|
||
if c.wahl.zeitplan.pause.bis > 0 {
|
||
Frage("Wie oft?") {
|
||
Stepper(c.wahl.zeitplan.sitzungen.map { "\($0) Sitzungen, dann Schluss" } ?? "immer wieder",
|
||
value: Binding(get: { c.wahl.zeitplan.sitzungen ?? 1 },
|
||
set: { c.wahl.zeitplan.sitzungen = $0 > 1 ? $0 : nil }),
|
||
in: 1...24)
|
||
}
|
||
}
|
||
}
|
||
Frage("Nur zu bestimmten Uhrzeiten?") { uhrzeiten }
|
||
Text("Zufall: Dauer, Pause und Tischzahl werden je Sitzung neu ausgelost - kein starres Muster.")
|
||
.font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
PlanAbschnitt(titel: "Geld", symbol: "banknote") {
|
||
Frage("Welche Stakes?") { stakes }
|
||
Frage("Wie viel kaufen?") {
|
||
Picker("", selection: $c.wahl.geld.kauf) {
|
||
Text("Max (tief)").tag(Geldplan.Kauf.max)
|
||
Text("Min").tag(Geldplan.Kauf.min)
|
||
}
|
||
.pickerStyle(.segmented).labelsHidden()
|
||
}
|
||
Frage("Wann ist eine Sitzung vorbei?") {
|
||
VStack(alignment: .leading, spacing: 4) {
|
||
GrenzeZeile(titel: "Verlust", grenze: $c.wahl.geld.sitzungVerlust, vorgabe: Grenze(250))
|
||
GrenzeZeile(titel: "Gewinn", grenze: $c.wahl.geld.sitzungGewinn, vorgabe: Grenze(150))
|
||
}
|
||
}
|
||
Frage("Wann ist der Tag vorbei?") {
|
||
VStack(alignment: .leading, spacing: 4) {
|
||
GrenzeZeile(titel: "Verlust", grenze: $c.wahl.geld.tagVerlust, vorgabe: Grenze(500))
|
||
GrenzeZeile(titel: "Gewinn", grenze: $c.wahl.geld.tagGewinn, vorgabe: Grenze(300))
|
||
}
|
||
}
|
||
Frage("Am einzelnen Tisch") {
|
||
VStack(alignment: .leading, spacing: 2) {
|
||
Stepper("aufstehen nach \(Format.zahl(c.wahl.geld.tischVerlustBB, stellen: 0)) BB Verlust",
|
||
value: $c.wahl.geld.tischVerlustBB, in: 10...1000, step: 10)
|
||
Stepper("nachkaufen unter \(Format.zahl(c.wahl.geld.nachkaufUnterBB, stellen: 0)) BB",
|
||
value: $c.wahl.geld.nachkaufUnterBB, in: 10...100, step: 5)
|
||
Stepper("aufstehen unter \(Format.zahl(c.wahl.geld.aufstehenUnterBB, stellen: 0)) BB Stack",
|
||
value: $c.wahl.geld.aufstehenUnterBB, in: 5...max(5, c.wahl.geld.nachkaufUnterBB - 5), step: 5)
|
||
}
|
||
}
|
||
Text("% heißt: Anteil der Bankroll beim Sitzungsstart (nur Cash).")
|
||
.font(.caption2).foregroundStyle(.tertiary)
|
||
}
|
||
}
|
||
.onAppear { stakesText = c.wahl.geld.stakesBB.map { Format.zahl($0, stellen: 2) } ?? "" }
|
||
}
|
||
|
||
private var uhrzeiten: some View {
|
||
@Bindable var c = cockpit
|
||
let f = c.wahl.zeitplan.fenster
|
||
let stunde = { (t: String) in Int(t.prefix(2)) ?? 0 }
|
||
let setzen = { (start: Int, ende: Int) in
|
||
c.wahl.zeitplan.fenster = start == ende ? nil
|
||
: .init(start: String(format: "%02d:00", start), ende: String(format: "%02d:00", ende))
|
||
}
|
||
let uhr = { (wert: Int, neu: @escaping (Int) -> Void) in
|
||
Picker("", selection: Binding(get: { wert }, set: neu)) {
|
||
ForEach(0..<24, id: \.self) { Text(String(format: "%02d Uhr", $0)).tag($0) }
|
||
}
|
||
.labelsHidden().frame(width: 84)
|
||
}
|
||
return HStack(spacing: 6) {
|
||
Wahl(an: f != nil, aus: "jederzeit", an_: "nur von–bis") { setzen($0 ? 18 : 0, $0 ? 2 : 0) }
|
||
if let f {
|
||
uhr(stunde(f.start)) { setzen($0, stunde(f.ende)) }
|
||
Text("bis")
|
||
uhr(stunde(f.ende)) { setzen(stunde(f.start), $0) }
|
||
}
|
||
}
|
||
}
|
||
|
||
private var stakes: some View {
|
||
@Bindable var c = cockpit
|
||
return HStack {
|
||
Picker("", selection: $c.wahl.geld.modell) {
|
||
Text("nach Guthaben").tag(Geldplan.Modell.leiter)
|
||
Text("fest").tag(Geldplan.Modell.fest)
|
||
}
|
||
.pickerStyle(.segmented).labelsHidden()
|
||
.help("nach Guthaben: eine Stufe hoch bei doppeltem, runter bei halbem Guthaben · fest: genau dieser Big Blind")
|
||
if c.wahl.geld.modell == .fest {
|
||
TextField("Big Blind", text: $stakesText)
|
||
.textFieldStyle(.roundedBorder).frame(width: 74)
|
||
.onSubmit {
|
||
let roh = stakesText.replacingOccurrences(of: ",", with: ".").trimmingCharacters(in: .whitespaces)
|
||
c.wahl.geld.stakesBB = Double(roh).flatMap { $0 > 0 ? $0 : nil }
|
||
stakesText = c.wahl.geld.stakesBB.map { Format.zahl($0, stellen: 2) } ?? ""
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Eine Frage, darunter die Antwort.
|
||
private struct Frage<Inhalt: View>: View {
|
||
var titel: String
|
||
@ViewBuilder var inhalt: Inhalt
|
||
|
||
init(_ titel: String, @ViewBuilder inhalt: () -> Inhalt) {
|
||
self.titel = titel
|
||
self.inhalt = inhalt()
|
||
}
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 4) {
|
||
Text(titel).font(.caption.weight(.medium))
|
||
HStack(spacing: 8) { inhalt }.font(.caption)
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Zwei Antworten als Kapsel statt eines nackten Schalters.
|
||
private struct Wahl: View {
|
||
var an: Bool
|
||
var aus: String
|
||
var an_: String
|
||
var setzen: (Bool) -> Void
|
||
|
||
var body: some View {
|
||
Picker("", selection: Binding(get: { an }, set: setzen)) {
|
||
Text(aus).tag(false)
|
||
Text(an_).tag(true)
|
||
}
|
||
.pickerStyle(.segmented).labelsHidden().fixedSize()
|
||
}
|
||
}
|
||
|
||
private struct PlanAbschnitt<Inhalt: View>: View {
|
||
var titel: String
|
||
var symbol: String
|
||
@ViewBuilder var inhalt: Inhalt
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 6) {
|
||
Label(titel, systemImage: symbol).font(.caption.weight(.semibold)).foregroundStyle(.secondary)
|
||
inhalt
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Minuten von–bis in 5er-Schritten, ausgelost je Sitzung; gleich: fest.
|
||
private struct MinutenSpanne: View {
|
||
@Binding var wert: Spanne
|
||
var unten: Double
|
||
|
||
var body: some View {
|
||
HStack(spacing: 2) {
|
||
Stepper(Format.zahl(wert.von, stellen: 0), value: Binding(get: { wert.von }, set: { wert = Spanne($0, max($0, wert.bis)) }),
|
||
in: unten...600, step: 5)
|
||
Text("bis")
|
||
Stepper("\(Format.zahl(wert.bis, stellen: 0)) min", value: Binding(get: { wert.bis }, set: { wert = Spanne(min(wert.von, $0), $0) }),
|
||
in: max(unten, 0)...600, step: 5)
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Ein Stop: an/aus, Wert, BB oder % der Bankroll beim Sitzungsstart.
|
||
private struct GrenzeZeile: View {
|
||
var titel: String
|
||
@Binding var grenze: Grenze?
|
||
var vorgabe: Grenze
|
||
|
||
var body: some View {
|
||
HStack(spacing: 6) {
|
||
Text(titel).foregroundStyle(.secondary).frame(width: 46, alignment: .leading)
|
||
Toggle("", isOn: Binding(get: { grenze != nil }, set: { grenze = $0 ? vorgabe : nil }))
|
||
.toggleStyle(.switch).labelsHidden()
|
||
if let g = grenze {
|
||
Stepper(Format.zahl(g.wert, stellen: 0),
|
||
value: Binding(get: { g.wert }, set: { grenze = Grenze($0, prozent: g.prozent) }),
|
||
in: 1...(g.prozent ? 100 : 5000), step: g.prozent ? 1 : 10)
|
||
Picker("", selection: Binding(get: { g.prozent }, set: {
|
||
grenze = Grenze($0 ? min(g.wert, 20) : max(g.wert, 50), prozent: $0)
|
||
})) {
|
||
Text("BB").tag(false)
|
||
Text("%").tag(true)
|
||
}
|
||
.pickerStyle(.segmented).labelsHidden().frame(width: 70)
|
||
} else {
|
||
Text("aus").foregroundStyle(.secondary)
|
||
}
|
||
}
|
||
}
|
||
}
|