import Foundation import AppKit import CockpitKern import SwiftUI /// Die Wurzel im Panel: Pille oder volle Leiste, darueber Meldungen. struct CockpitWurzel: View { @Environment(Cockpit.self) private var cockpit var body: some View { Group { switch cockpit.form { case .pille: Pille() case .leiste: Leiste() } } .environment(\.locale, Locale(identifier: "de_DE")) } } /// Eingeklappt: ein Satz, ein Punkt, der Countdown und der Not-Aus. Das reicht zum Mitlaufen. struct Pille: View { @Environment(Cockpit.self) private var cockpit var body: some View { HStack(spacing: 10) { Statuspunkt(ton: cockpit.ton, groesse: 11) if cockpit.wahl.cash { Abzeichen(text: "ECHTGELD", farbe: .red) } VStack(alignment: .leading, spacing: 1) { Text(cockpit.satz).font(.callout.weight(.medium)).lineLimit(1) if let w = cockpit.wartet.first { Text("läuft: " + w).font(.caption).foregroundStyle(.blue).lineLimit(1) } else if let m = cockpit.meldung { Text(m.text).font(.caption).foregroundStyle(m.ok ? .green : .orange).lineLimit(1) } else if let j = cockpit.ansicht.jetzt, let e = j.entscheidung { Text([e.aktionText ?? e.aktion, j.raum].compactMap { $0 }.joined(separator: " · ")) .font(.caption).foregroundStyle(.secondary).lineLimit(1) } } Spacer(minLength: 4) ZugUhr(zug: cockpit.ansicht.jetzt?.zug, klein: true) if case .belegt = cockpit.verbindung { Button("Übernehmen") { cockpit.uebernehmen() }.controlSize(.small) } else if !cockpit.hauptknopf.schritte.isEmpty, cockpit.hauptknopf != .notAusLoesen { Button { cockpit.hauptknopfDruecken() } label: { Image(systemName: cockpit.hauptknopf.symbol).font(.title3) } .buttonStyle(.borderless).foregroundStyle(cockpit.hauptknopf.farbe) .help(cockpit.hauptknopf.titel + " - " + cockpit.hauptknopf.hilfe) .disabled(!cockpit.laufend.isEmpty) } NotAusKnopf(kompakt: true) Button { cockpit.form = .leiste } label: { Image(systemName: "sidebar.right") } .buttonStyle(.borderless).help("Als Leiste ausklappen (⌃⌥⌘C)") Button { cockpit.beendenWollen() } label: { Image(systemName: "xmark") } .buttonStyle(.borderless).foregroundStyle(.secondary).help("Cockpit beenden (⌘Q)") } .padding(.horizontal, 14) .frame(maxWidth: .infinity, maxHeight: .infinity) .glassEffect(.regular.tint(cockpit.notAus ? .red.opacity(0.35) : cockpit.wahl.cash ? .red.opacity(0.18) : .clear), in: Capsule()) .contentShape(Capsule()) .onTapGesture(count: 2) { cockpit.form = .leiste } } } /// Ausgeklappt: Kopf, Reiter, genau eine Ansicht, Meldungen unten. struct Leiste: View { @Environment(Cockpit.self) private var cockpit private var rand: Color { cockpit.notAus ? .red : cockpit.wahl.cash ? .red.opacity(0.7) : .white.opacity(0.10) } var body: some View { @Bindable var c = cockpit VStack(spacing: 0) { if case .belegt(let b) = cockpit.verbindung { BelegtAnsicht(belegt: b) } else { Kopfzeile() Rueckmeldungen() Divider() Group { switch cockpit.reiter { case .cash: if cockpit.zuschauen { ZuschauerAnsicht() } else { LiveAnsicht() } case .haende: EntscheidungenAnsicht() case .statistik: StatistikAnsicht() case .protokoll: ProtokollAnsicht() case .trainer: TrainerAnsicht() } } .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top) Divider() Navigation() } } .background { Hintergrund(cash: cockpit.wahl.cash) } .clipShape(RoundedRectangle(cornerRadius: 22, style: .continuous)) .overlay(RoundedRectangle(cornerRadius: 22, style: .continuous) .strokeBorder(rand, lineWidth: cockpit.notAus || cockpit.wahl.cash ? 1.5 : 0.5)) .environment(\.colorScheme, .dark) .animation(.easeInOut(duration: 0.4), value: cockpit.wahl.cash) .background(Tastenkuerzel()) } } /// Tiefes Glas mit einem Hauch Farbe: neutral in Übung, glühend rot in Cash. struct Hintergrund: View { var cash: Bool var body: some View { ZStack { Rectangle().fill(.ultraThinMaterial) LinearGradient(colors: [Color(red: 0.10, green: 0.13, blue: 0.18).opacity(0.92), Color(red: 0.05, green: 0.07, blue: 0.10).opacity(0.96)], startPoint: .top, endPoint: .bottom) RadialGradient(colors: [(cash ? Color.red : Color.blue).opacity(cash ? 0.28 : 0.14), .clear], center: .top, startRadius: 0, endRadius: 320) } } } /// Oben links wie bei jedem Mac-Fenster: Rot beendet, Gelb klappt zur Pille, Gruen wechselt die Seite. struct Ampel: View { @Environment(Cockpit.self) private var cockpit @State private var drueber = false var body: some View { HStack(spacing: 8) { knopf(.red, "xmark", "Cockpit beenden (⌘Q)") { cockpit.beendenWollen() } knopf(.yellow, "minus", "Zur Pille einklappen (⌃⌥⌘C)") { cockpit.form = .pille } knopf(.green, cockpit.seite == .rechts ? "arrow.left" : "arrow.right", cockpit.seite == .rechts ? "An den linken Rand" : "An den rechten Rand") { cockpit.seite = cockpit.seite == .rechts ? .links : .rechts } } .onHover { drueber = $0 } } private func knopf(_ farbe: Color, _ symbol: String, _ hilfe: String, _ tun: @escaping () -> Void) -> some View { Button(action: tun) { Circle().fill(farbe.gradient) .overlay(Circle().stroke(.black.opacity(0.15), lineWidth: 0.5)) .overlay(Image(systemName: symbol).font(.system(size: 7, weight: .heavy)) .foregroundStyle(.black.opacity(0.55)).opacity(drueber ? 1 : 0)) .frame(width: 12, height: 12) .contentShape(Circle()) } .buttonStyle(.plain) .help(hilfe) } } /// Rueckfrage nur, wenn der Laeufer laeuft: er spielt weiter, aber der Not-Aus (⌃⌥⌘S) endet mit der App. struct BeendenFrage: View { @Environment(Cockpit.self) private var cockpit var body: some View { VStack(alignment: .leading, spacing: 8) { Text("Cockpit beenden?").font(.callout.weight(.semibold)) Text("Der Läufer spielt weiter. Der Not-Aus (⌃⌥⌘S) wirkt erst wieder, wenn das Cockpit läuft.") .font(.caption).foregroundStyle(.secondary) HStack { Button("Abbrechen") { cockpit.fragtBeenden = false }.keyboardShortcut(.cancelAction) Spacer() Button("Beenden", role: .destructive) { NSApp.terminate(nil) } .buttonStyle(.borderedProminent).tint(.red) } .controlSize(.small) } .padding(10) .background(.red.opacity(0.1), in: RoundedRectangle(cornerRadius: 10)) } } private struct Tastenkuerzel: View { @Environment(Cockpit.self) private var cockpit var body: some View { ZStack { ForEach(Array(Reiter.allCases.enumerated()), id: \.element) { i, r in Button("") { cockpit.reiter = r }.keyboardShortcut(KeyEquivalent(Character("\(i + 1)")), modifiers: []) } } .opacity(0).allowsHitTesting(false) } } struct Kopfzeile: View { @Environment(Cockpit.self) private var cockpit /// Das Not-Aus-Band sagt dasselbe wie die Statuszeile. Ohne Verbindung bleibt sie: dort steht, was los ist. private var notAusSagtAlles: Bool { guard case .verbunden = cockpit.verbindung else { return false } return cockpit.notAus } var body: some View { let k = cockpit.ansicht.kopf VStack(alignment: .leading, spacing: 10) { HStack(spacing: 6) { Ampel() Spacer(minLength: 8) EinstellungenKnopf() if !Umfang.nurSpiel, k?.klon == true || cockpit.klon { Abzeichen(text: "Klon", farbe: .purple) } if let s = k?.laufzeitS, k?.laeuft == true { Label(Zeit.dauer(s), systemImage: "clock").font(.caption).foregroundStyle(.secondary) } } if cockpit.fragtBeenden { BeendenFrage() } // Die Setup-Editoren (Sendung, Stimme & KI, Zeiten, Geld) wohnen jetzt im nativen // Einstellungsfenster (⌘, / Zahnrad), nicht mehr als Einblendung im Overlay (Owner 7.11.). ModusSchalter() if cockpit.cashFragen { LiveFrage().transition(.move(edge: .top).combined(with: .opacity)) } if !cockpit.zuschauen { // der Spielplan gilt nur für den Läufer PlanKacheln() FormatWahl() TurnierBereich() } PhaseBand() if !notAusSagtAlles { HStack(alignment: .firstTextBaseline, spacing: 8) { Statuspunkt(ton: cockpit.ton, groesse: 10) Text(cockpit.satz).font(.subheadline.weight(.semibold)).lineLimit(2).fixedSize(horizontal: false, vertical: true) Spacer(minLength: 0) } } if let alarme = k?.konto?.alarme, !alarme.isEmpty { KontoLeiste(alarme: alarme) // Verdacht, Sperre, laufende Ruhezeit: was uns aussperrt } if cockpit.notAus { NotAusBand().transition(.scale(scale: 0.95).combined(with: .opacity)) } else { HStack(spacing: 10) { HauptknopfAnsicht() NotAusKnopf(kompakt: false) } } if let d = cockpit.ansicht.geld?.deckel, d.gesperrt, let z = d.zuruecksetzen { DeckelBand(deckel: d, zurueck: z) } if !cockpit.freigabe.fensterLesbar { FreigabeHinweis() } else if !cockpit.freigabe.bildschirmaufnahme { BildschirmHinweis() } if cockpit.ansicht.kopf?.clientPort == false, cockpit.laeuft == true { Label("CoinPoker läuft ohne Debug-Port: Tische öffnen und Selbstheilen gehen nicht. Aufhören, dann neu starten.", systemImage: "exclamationmark.triangle.fill") .font(.caption).foregroundStyle(.orange).fixedSize(horizontal: false, vertical: true) } } .padding(.horizontal, 12).padding(.top, 10).padding(.bottom, 10) .animation(.snappy, value: cockpit.cashFragen) .animation(.snappy, value: cockpit.planOffen) .animation(.snappy, value: cockpit.geldOffen) .animation(.snappy, value: cockpit.stimmeOffen) .animation(.snappy, value: cockpit.sendungOffen) .animation(.spring(duration: 0.35), value: cockpit.notAus) } } /// Ohne Freigabe sieht das Cockpit keine Tische, und ein Laeufer von hier waere blind. struct FreigabeHinweis: View { @Environment(Cockpit.self) private var cockpit var body: some View { let f = cockpit.freigabe VStack(alignment: .leading, spacing: 6) { Label("Cockpit sieht keine Tische", systemImage: "eye.slash.fill").font(.callout.weight(.semibold)) Text("macOS lässt „Cockpit“ die Tischfenster nicht lesen. Ein Läufer von hier wäre blind - darum startet der Hauptknopf keinen.") .font(.caption).foregroundStyle(.secondary) if !f.bedienungshilfen { Text("• Bedienungshilfen: „Cockpit“ einschalten").font(.caption) } if f.systemEvents == .verboten { Text("• Automation: „System Events“ für „Cockpit“ erlauben").font(.caption) } Button("Freigeben …") { Freigabe.erbitten(f) } .buttonStyle(.borderedProminent).tint(.red).controlSize(.small) } .padding(10) .frame(maxWidth: .infinity, alignment: .leading) .background(.red.opacity(0.12), in: RoundedRectangle(cornerRadius: 10)) } } /// Ohne Bildschirmaufnahme spielt der Laeufer ueber den Kanal weiter, liest die Tische aber langsam /// ueber System Events (holt den Client nach vorn) und macht keine Fotos (5.11.2026 20:18). struct BildschirmHinweis: View { @Environment(Cockpit.self) private var cockpit var body: some View { HStack(alignment: .firstTextBaseline, spacing: 8) { Label("Bildschirmaufnahme fehlt: Tische nur langsam lesbar, keine Fotos", systemImage: "rectangle.dashed") .font(.caption).foregroundStyle(.orange).fixedSize(horizontal: false, vertical: true) Spacer(minLength: 4) Button("Freigeben …") { Freigabe.erbitten(cockpit.freigabe) } .controlSize(.small) } } } /// Der grosse Knopf: immer der naechste sinnvolle Schritt (Hauptknopf im Kern). struct HauptknopfAnsicht: View { @Environment(Cockpit.self) private var cockpit var body: some View { let k = cockpit.hauptknopf let beschaeftigt = !cockpit.laufend.isEmpty Button { cockpit.hauptknopfDruecken() } label: { HStack(spacing: 6) { if beschaeftigt { ProgressView().controlSize(.small) } else { Image(systemName: k.symbol) } Text(k.titel).fontWeight(.semibold).lineLimit(1) } .frame(maxWidth: .infinity) } .buttonStyle(.borderedProminent) .buttonBorderShape(.capsule) .tint(k.farbe) .controlSize(.extraLarge) .disabled(k.schritte.isEmpty || beschaeftigt) .help(k.hilfe) } } extension Hauptknopf { var titel: String { switch self { case .unbekannt: "…" case .notAusLoesen: "Not-Aus lösen" case .hoertAuf: "Hört auf …" case .aufhoeren: "Aufhören" case .zuschauenBeenden: "Zuschauen beenden" case .starten(let cash): cash ? "Echtgeld starten" : "Übung starten" case .budgetFehlt: "Budget angeben" case .freigabeFehlt: "Freigabe fehlt" case .clientStarten: "CoinPoker starten" case .clientNeuStarten: "CoinPoker neu starten" case .portFehlt: "Debug-Port fehlt" } } var symbol: String { switch self { case .unbekannt: "ellipsis" case .notAusLoesen: "play.fill" case .hoertAuf: "hourglass" case .aufhoeren: "hand.raised.fill" case .zuschauenBeenden: "eye.slash" case .starten(let cash): cash ? "bolt.fill" : "play.fill" case .budgetFehlt: "eurosign.circle" case .freigabeFehlt: "eye.slash" case .clientStarten: "power" case .clientNeuStarten: "arrow.clockwise" case .portFehlt: "exclamationmark.triangle" } } var farbe: Color { switch self { case .aufhoeren, .hoertAuf: .orange case .zuschauenBeenden: .teal case .starten(let cash): cash ? .red : .green case .notAusLoesen, .clientStarten, .clientNeuStarten: .green case .budgetFehlt, .freigabeFehlt, .portFehlt, .unbekannt: .gray } } var hilfe: String { switch self { case .unbekannt: "wartet auf den Server" case .notAusLoesen: "Not-Aus lösen - der Läufer darf wieder klicken" case .hoertAuf: "Er spielt die laufenden Hände zu Ende und schließt dann die Tische - sofort: Not-Aus (⌃⌥⌘S)" case .aufhoeren: "Bei nächster Gelegenheit: ab der nächsten Hand aussetzen, laufende Hände zu Ende spielen, dann Tische zu - sofort: Not-Aus" case .zuschauenBeenden: "Zuschauer stoppen - danach wählst du Übung oder Cash" case .starten(let cash): cash ? "Spielplan auf Echtgeld setzen und den Läufer starten - er öffnet selbst Tische bis zur Tischzahl" : "Spielplan Übung setzen und den Läufer starten - er öffnet selbst Übungstische bis zur Tischzahl" case .budgetFehlt: "Echtgeld braucht ein Guthaben: Budget eintragen, sonst wählte die Lobby blind" case .freigabeFehlt: "macOS lässt das Cockpit keine Tischfenster lesen - erst freigeben, sonst wäre der Läufer blind" case .clientStarten: "CoinPoker mit Debug-Port starten - danach anmelden" case .clientNeuStarten: "CoinPoker läuft ohne Debug-Port - beenden und mit Port neu starten, danach anmelden" case .portFehlt: "CoinPoker läuft ohne Debug-Port, aber Tische sind offen - erst die Tische schließen, dann neu starten" } } } /// Ein anderes Cockpit laeuft schon (App oder Terminal) - es darf nur eines geben. struct BelegtAnsicht: View { var belegt: Belegt @Environment(Cockpit.self) private var cockpit var body: some View { VStack(spacing: 16) { Spacer() Image(systemName: "rectangle.on.rectangle.slash").font(.system(size: 40)).foregroundStyle(.secondary) Text("Cockpit läuft schon").font(.title3.weight(.semibold)) Text(belegt.text + " Es darf nur eines laufen.") .multilineTextAlignment(.center).foregroundStyle(.secondary) Button { cockpit.uebernehmen() } label: { Label("Hier übernehmen", systemImage: "arrow.triangle.swap").frame(maxWidth: 220) } .buttonStyle(.borderedProminent).controlSize(.large) .help("Das andere Cockpit bekommt Strg-C, räumt auf und geht; dieses startet") Button("Diese App beenden") { NSApp.terminate(nil) }.buttonStyle(.link) Spacer() } .padding(24) .frame(maxWidth: .infinity, maxHeight: .infinity) } } /// Not-Aus: ein Klick hält sofort an (die Dateien schreibt die App selbst). Lösen nur durch /// Gedrückthalten - so wird der Laeufer nie aus Versehen wieder scharf. struct NotAusKnopf: View { var kompakt: Bool @Environment(Cockpit.self) private var cockpit @State private var druecken = false var body: some View { if cockpit.notAus { LoesenKnopf(kompakt: kompakt) } else { Button { cockpit.notAusSofort("Knopf") } label: { ZStack { Circle().fill(LinearGradient(colors: [Color(red: 1, green: 0.32, blue: 0.30), Color(red: 0.75, green: 0.08, blue: 0.10)], startPoint: .top, endPoint: .bottom)) Circle().strokeBorder(.white.opacity(0.35), lineWidth: 1) Image(systemName: "hand.raised.fill").font(.system(size: kompakt ? 12 : 17, weight: .bold)).foregroundStyle(.white) } .frame(width: kompakt ? 28 : 44, height: kompakt ? 28 : 44) .shadow(color: .red.opacity(0.55), radius: druecken ? 2 : 8) .scaleEffect(druecken ? 0.92 : 1) } .buttonStyle(.plain) .onLongPressGesture(minimumDuration: 0, pressing: { p in withAnimation(.snappy(duration: 0.12)) { druecken = p } }, perform: {}) .help("Not-Aus - sofort anhalten (⌃⌥⌘S)") .accessibilityLabel("Not-Aus") } } } /// Gedrückt halten (1 s) löst den Not-Aus - der Ring füllt sich dabei. struct LoesenKnopf: View { var kompakt: Bool @Environment(Cockpit.self) private var cockpit @State private var fortschritt = 0.0 static let dauer = 1.0 var body: some View { ZStack { Circle().fill(.white.opacity(0.10)) Circle().trim(from: 0, to: fortschritt).stroke(.green, style: .init(lineWidth: 3, lineCap: .round)) .rotationEffect(.degrees(-90)) Image(systemName: "play.fill").font(.system(size: kompakt ? 11 : 15, weight: .bold)).foregroundStyle(.green) } .frame(width: kompakt ? 28 : 44, height: kompakt ? 28 : 44) .contentShape(Circle()) .onLongPressGesture(minimumDuration: Self.dauer, pressing: { p in withAnimation(p ? .linear(duration: Self.dauer) : .snappy) { fortschritt = p ? 1 : 0 } }, perform: { fortschritt = 0 cockpit.notAusLoesen() }) .help("Gedrückt halten, um den Not-Aus zu lösen") .accessibilityLabel("Not-Aus lösen, gedrückt halten") } } /// Sitzungs- oder Tagesdeckel hat gesperrt: zuruecksetzen nur mit 2 s Gedrueckthalten (Owner 16.11.) - /// der Ring fuellt sich wie beim LoesenKnopf; danach setzt sich der Laeufer wieder hin. struct DeckelBand: View { var deckel: GeldDeckel var zurueck: DeckelZurueck @Environment(Cockpit.self) private var cockpit @State private var fortschritt = 0.0 static let dauer = 2.0 var body: some View { HStack(spacing: 10) { Image(systemName: "exclamationmark.triangle.fill").font(.title3).foregroundStyle(.orange) VStack(alignment: .leading, spacing: 1) { Text(zurueck.text ?? "Verlustdeckel zurücksetzen").font(.callout.weight(.bold)) Text([deckel.satz, zurueck.hinweis].compactMap { $0 }.filter { !$0.isEmpty }.joined(separator: " · ")) .font(.caption2).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true) } Spacer(minLength: 0) ZStack { Circle().fill(.white.opacity(0.10)) Circle().trim(from: 0, to: fortschritt).stroke(.orange, style: .init(lineWidth: 3, lineCap: .round)) .rotationEffect(.degrees(-90)) Image(systemName: "arrow.counterclockwise").font(.system(size: 15, weight: .bold)).foregroundStyle(.orange) } .frame(width: 44, height: 44) .contentShape(Circle()) .onLongPressGesture(minimumDuration: Self.dauer, pressing: { p in withAnimation(p ? .linear(duration: Self.dauer) : .snappy) { fortschritt = p ? 1 : 0 } }, perform: { fortschritt = 0 cockpit.steuern("deckel_zuruecksetzen", daten: #"{"was":"\#(zurueck.was)"}"#) }) .help("2 s gedrückt halten: Verlustdeckel zurücksetzen") .accessibilityLabel("Verlustdeckel zurücksetzen, gedrückt halten") } .padding(10) .background(.orange.opacity(0.16), in: RoundedRectangle(cornerRadius: 14, style: .continuous)) } } /// Ist der Not-Aus aktiv, wird er das Wichtigste im Kopf: ein rotes, atmendes Band. struct NotAusBand: View { @State private var atmen = false var body: some View { HStack(spacing: 10) { Image(systemName: "hand.raised.fill").font(.title3).foregroundStyle(.white) VStack(alignment: .leading, spacing: 1) { Text("Not-Aus aktiv").font(.callout.weight(.bold)).foregroundStyle(.white) Text("Es wird nichts geklickt. Zum Lösen den grünen Knopf gedrückt halten.") .font(.caption2).foregroundStyle(.white.opacity(0.85)).fixedSize(horizontal: false, vertical: true) } Spacer(minLength: 0) NotAusKnopf(kompakt: false) } .padding(10) .background(LinearGradient(colors: [Color(red: 0.85, green: 0.12, blue: 0.14), Color(red: 0.55, green: 0.05, blue: 0.08)], startPoint: .leading, endPoint: .trailing), in: RoundedRectangle(cornerRadius: 14, style: .continuous)) .shadow(color: .red.opacity(atmen ? 0.6 : 0.2), radius: atmen ? 14 : 4) .onAppear { withAnimation(.easeInOut(duration: 1.1).repeatForever(autoreverses: true)) { atmen = true } } } } struct Navigation: View { @Environment(Cockpit.self) private var cockpit var body: some View { HStack(spacing: 2) { ForEach(Reiter.allCases) { r in Button { cockpit.reiter = r } label: { VStack(spacing: 2) { Image(systemName: r.symbol).font(.system(size: 14)) Text(r.titel).font(.caption2) } .frame(maxWidth: .infinity, minHeight: 36) .contentShape(Rectangle()) } .buttonStyle(.plain) .foregroundStyle(cockpit.reiter == r ? Color.accentColor : .secondary) .help("\(r.titel) (\((Reiter.allCases.firstIndex(of: r) ?? 0) + 1))") } } .padding(.horizontal, 6).padding(.vertical, 4) } } /// Was die Knoepfe tun: "läuft: …", solange die Antwort aussteht, danach das Ergebnis. struct Rueckmeldungen: View { @Environment(Cockpit.self) private var cockpit var body: some View { VStack(spacing: 6) { if !cockpit.wartet.isEmpty { HStack(spacing: 8) { ProgressView().controlSize(.small) Text("läuft: " + cockpit.wartet.joined(separator: ", ")).font(.callout).lineLimit(2) Spacer(minLength: 0) } .padding(10) .background(.blue.opacity(0.12), in: RoundedRectangle(cornerRadius: 10)) } if let m = cockpit.meldung { Meldung(r: m) } } .padding(.horizontal, 12) .padding(.bottom, cockpit.wartet.isEmpty && cockpit.meldung == nil ? 0 : 8) .animation(.snappy, value: cockpit.meldung) .animation(.snappy, value: cockpit.wartet) } } struct Meldung: View { var r: Rueckmeldung @Environment(Cockpit.self) private var cockpit var body: some View { HStack(spacing: 8) { Image(systemName: r.ok ? "checkmark.circle.fill" : "exclamationmark.triangle.fill") .foregroundStyle(r.ok ? .green : .orange) Text(r.text).font(.callout).lineLimit(4).textSelection(.enabled) Spacer(minLength: 0) Button { cockpit.meldungWeg() } label: { Image(systemName: "xmark") }.buttonStyle(.borderless) } .padding(10) .background((r.ok ? Color.green : Color.orange).opacity(0.14), in: RoundedRectangle(cornerRadius: 10)) } } /// Restzeit des offenen Zugs, laeuft selbst (der Server schickt nur `bis`). struct ZugUhr: View { var zug: Zug? var klein = false var body: some View { TimelineView(.periodic(from: .now, by: 0.25)) { t in if let c = Countdown(zug: zug, jetzt: t.date.timeIntervalSince1970) { let f: Color = c.anteil < 0.25 ? .red : c.anteil < 0.5 ? .orange : .green if klein { ZStack { Circle().stroke(.quaternary, lineWidth: 3) 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)) } .frame(width: 28, height: 28) } else { HStack(spacing: 8) { ProgressView(value: c.anteil).tint(f) Text("\(Int(c.rest.rounded(.up))) s").font(.caption.monospacedDigit().weight(.semibold)) } } } } } }