Files
pokerfreak/mac/Sources/Cockpit/StatistikKarten.swift
T
mmintelandClaude Opus 5.5 383f125769 Mac cockpit: catch up with WinUI (server-built live views, stakes, limits, sammler, statistik)
WinUI is ahead; the Swift app now draws what sicht/ precomputes instead of
computing its own views:
- Spielen page: live tables from sitzen.live (raster, kacheln, bereit, search,
  close question), "Gerade eben" from entscheidungen.feed, money from geld.anzeige
- Stakes priority with tables per stake (spielplan.stufen/stufen_tische);
  micro_only is gone
- Loss limits (deckel_einstellen), sammler in Zuschauer mode (main button
  becomes Sammeln starten/stoppen), "Nur offene Tische spielen", queue
- Statistik: full auswertung (key figures, EV/SD curve, bb/100 by ...,
  history, best times, play/opponent picture, tournaments)
- Small items: Spickzettel, streamer toggle, sendung_lesen, daily limits editor

Intentional deviations: "highest first" compares instead of 1e15 + bb (WinUI
cannot separate NL2 and NL5 there), a single table shows its tile, narrow
segment pickers fall back to menus. Plan: plans/2026-11-30_swift-winui-abgleich.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 09:55:51 +01:00

176 lines
6.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import CockpitKern
import SwiftUI
// Bausteine der Statistik-Seite (winui/Seiten/StatistikSeite.cs: Karte, Paar, Kachel, Wertfenster).
enum StatistikFarbe {
/// Die Farbnamen des Servers; "lila" und "gelb" kennt `Farben.name` nicht.
static func ton(_ name: String?) -> Color {
switch name {
case "lila": .purple
case "gelb": .yellow
default: Farben.name(name)
}
}
/// Ergebnisfarbe nach Vorzeichen; ohne Wert oder bei Null grau.
static func ergebnis(_ x: Double?) -> String {
AuswertungText.ton(x) ?? "grau"
}
}
enum StatistikZeit {
/// Ortszeit mit festem Muster ("dd.MM. HH:mm"), deutsch.
static func format(_ t: Double?, _ muster: String) -> String {
guard let t else { return "–" }
let f = DateFormatter()
f.locale = Locale(identifier: "de_DE")
f.dateFormat = muster
return f.string(from: t.datum)
}
static func tagUhr(_ t: Double?) -> String { format(t, "dd.MM. HH:mm") }
}
/// Eine Karte mit Titel, Hinweis und Steuerung rechts oben (schmal: darunter).
struct StatistikKarte<Inhalt: View, Rechts: View>: View {
var titel: String
var hinweis: String?
@ViewBuilder var rechts: Rechts
@ViewBuilder var inhalt: Inhalt
init(_ titel: String, hinweis: String? = nil, @ViewBuilder rechts: () -> Rechts, @ViewBuilder inhalt: () -> Inhalt) {
self.titel = titel; self.hinweis = hinweis; self.rechts = rechts(); self.inhalt = inhalt()
}
var body: some View {
VStack(alignment: .leading, spacing: 10) {
ViewThatFits(in: .horizontal) {
HStack(alignment: .top, spacing: 8) { kopf; Spacer(minLength: 8); rechts }
VStack(alignment: .leading, spacing: 8) { kopf; rechts }
}
inhalt
}
.padding(14)
.frame(maxWidth: .infinity, alignment: .leading)
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 14))
}
private var kopf: some View {
VStack(alignment: .leading, spacing: 1) {
Text(titel).font(.callout.weight(.semibold))
if let hinweis { Text(hinweis).font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true) }
}
}
}
extension StatistikKarte where Rechts == EmptyView {
init(_ titel: String, hinweis: String? = nil, @ViewBuilder inhalt: () -> Inhalt) {
self.init(titel, hinweis: hinweis, rechts: { EmptyView() }, inhalt: inhalt)
}
}
/// Zwei Karten nebeneinander, wenn sie breit genug sind, sonst untereinander.
struct StatistikPaar<A: View, B: View>: View {
var a: A
var b: B
init(@ViewBuilder a: () -> A, @ViewBuilder b: () -> B) { self.a = a(); self.b = b() }
var body: some View {
ViewThatFits(in: .horizontal) {
HStack(alignment: .top, spacing: 12) {
a.frame(minWidth: 420)
b.frame(minWidth: 420)
}
VStack(spacing: 12) { a; b }
}
}
}
/// Eine Kachel der Kennzahlen: Titel, Wert, Unterzeile (Spanne, Zusatz), Hilfe beim Zeigen.
struct AuswertungKachel: View {
var kachel: KennzahlKachel
var body: some View {
VStack(alignment: .leading, spacing: 2) {
Text(kachel.titel).font(.caption2).foregroundStyle(.secondary).lineLimit(1)
Text(kachel.wert)
.font(.system(kachel.klein ? .body : .title3, design: .rounded).weight(.semibold))
.monospacedDigit()
.foregroundStyle(kachel.ton.map(StatistikFarbe.ton) ?? .primary)
.lineLimit(1).minimumScaleFactor(0.6)
.frame(minHeight: 24, alignment: .leading)
Text(kachel.unter).font(.caption2).foregroundStyle(.tertiary).lineLimit(2).fixedSize(horizontal: false, vertical: true)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(10)
.background(.quaternary.opacity(0.5), in: RoundedRectangle(cornerRadius: 10))
.help(kachel.hilfe ?? "")
}
}
struct KachelRaster: View {
var kacheln: [KennzahlKachel]
var body: some View {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 170), spacing: 8, alignment: .top)], spacing: 8) {
ForEach(kacheln) { AuswertungKachel(kachel: $0) }
}
}
}
/// Das Fenster neben dem Zeiger: eine Kopfzeile, dann Zeilen mit farbigem Punkt (oder ohne Ton: Text).
struct Wertfenster: View {
struct Zeile: Identifiable {
var text: String
var ton: String?
var id = UUID()
}
var zeilen: [Zeile]
var body: some View {
VStack(alignment: .leading, spacing: 1) {
ForEach(zeilen) { z in
if let ton = z.ton {
HStack(spacing: 5) {
Circle().fill(StatistikFarbe.ton(ton)).frame(width: 7, height: 7)
Text(z.text).font(.caption2.monospacedDigit())
}
} else {
Text(z.text).font(.caption2).foregroundStyle(.secondary)
}
}
}
.padding(.horizontal, 8).padding(.vertical, 5)
.background(.regularMaterial, in: RoundedRectangle(cornerRadius: 6))
.overlay(RoundedRectangle(cornerRadius: 6).stroke(.white.opacity(0.12)))
.fixedSize()
}
}
/// Kleine Segmentwahl, die sich ihre Breite selbst nimmt.
struct Segmente<W: Hashable & CaseIterable & RawRepresentable>: View where W.RawValue == String, W.AllCases: RandomAccessCollection {
@Binding var wahl: W
var body: some View {
// In der schmalen Leiste passen fuenf Segmente nicht: dann ein Menue statt ueber den Rand zu ragen
ViewThatFits(in: .horizontal) {
Picker("", selection: $wahl) { ForEach(Array(W.allCases), id: \.self) { Text($0.rawValue) } }
.pickerStyle(.segmented).labelsHidden().fixedSize()
Picker("", selection: $wahl) { ForEach(Array(W.allCases), id: \.self) { Text($0.rawValue) } }
.pickerStyle(.menu).labelsHidden().fixedSize()
}
}
}
/// Ein Strich unter einer Karte: kleine Erklaerung des Diagramms.
struct Fussnote: View {
var text: String
init(_ text: String) { self.text = text }
var body: some View {
Text(text).font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
}
}