Files
lichtkasten/Sources/Lichtkasten/Views/MatchdayViews.swift
T

163 lines
7.4 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 SwiftUI
import LichtkastenCore
/// Layout C in the Leuchttisch look: match header with both teams (kit colors from the jersey setup),
/// event + date from IPTC, counters and team filter chips.
struct MatchdayHeader: View {
@EnvironmentObject var state: AppState
var body: some View {
let teams = state.settings.jersey.teams
let info = state.matchdayEvent
VStack(spacing: 0) {
HStack(spacing: 24) {
if let home = teams.first {
teamBadge(home, alignTrailing: true).frame(maxWidth: .infinity, alignment: .trailing)
}
VStack(spacing: 2) {
Text(info.event.uppercased())
.font(.system(size: 11, weight: .bold)).tracking(1.4)
.foregroundStyle(LK.muted).lineLimit(1)
Text(info.date).font(.system(size: 22, weight: .heavy, design: .rounded)).foregroundStyle(LK.text)
}
.padding(.horizontal, 18).padding(.vertical, 6)
.background(RoundedRectangle(cornerRadius: 10).fill(LK.deep))
.overlay(RoundedRectangle(cornerRadius: 10).stroke(LK.border))
.frame(maxWidth: 420)
if teams.count > 1 {
teamBadge(teams[1], alignTrailing: false).frame(maxWidth: .infinity, alignment: .leading)
}
counters
}
.padding(.horizontal, 20)
.padding(.vertical, 12)
HStack(spacing: 8) {
chip("Alle", on: state.filter.team == nil && !state.filter.withoutPlayer && state.filter.person == nil) {
state.setTeamFilter(nil)
}
ForEach(teams) { t in
chip(t.name, color: t.shirtColor.swiftUI, on: state.filter.team == t.id) { state.setTeamFilter(t.id) }
}
chip("Ohne Spieler:in", on: state.filter.withoutPlayer) {
state.setTeamFilter(nil); state.filter.withoutPlayer = true
}
if let p = state.filter.person {
chip("✕ " + p, on: true) { state.filter.person = nil }
}
Spacer()
Button("Trikot-Erkennung …") { state.showJerseySetup = true }
.buttonStyle(LKButtonStyle(compact: true))
Button("Nummern erkennen ⌘⇧J") { state.recognizeJerseys() }
.buttonStyle(LKButtonStyle(primary: true, compact: true))
.disabled(state.jerseyRunning)
}
.padding(.horizontal, 20)
.padding(.bottom, 10)
}
.background(LK.bar)
.overlay(alignment: .bottom) { Rectangle().fill(LK.border).frame(height: 1) }
}
private func teamBadge(_ t: JerseyTeam, alignTrailing: Bool) -> some View {
HStack(spacing: 12) {
if alignTrailing { name(t) }
RoundedRectangle(cornerRadius: 8)
.fill(t.shirtColor.swiftUI)
.frame(width: 32, height: 32)
.overlay(RoundedRectangle(cornerRadius: 8).stroke((t.shortsColor ?? t.shirtColor).swiftUI, lineWidth: 3))
.overlay(RoundedRectangle(cornerRadius: 8).stroke(LK.border, lineWidth: 1))
if !alignTrailing { name(t) }
}
}
private func name(_ t: JerseyTeam) -> some View {
Text(t.name.uppercased())
.font(.system(size: 22, weight: .heavy, design: .rounded))
.foregroundStyle(LK.text)
.lineLimit(1)
.minimumScaleFactor(0.6)
}
private var counters: some View {
let tagged = state.items.filter(\.tagged).count
let withPlayer = state.items.filter { state.playerInfo(for: $0)?.confirmed == true }.count
let open = state.items.filter { !state.openSuggestions(for: $0.id).isEmpty }.count
return HStack(spacing: 18) {
counter(tagged, "GETAGGT", highlight: true)
counter(withPlayer, "MIT SPIELER:IN")
counter(open, "OFFEN")
}
}
private func counter(_ n: Int, _ label: String, highlight: Bool = false) -> some View {
VStack(alignment: .trailing, spacing: 0) {
Text("\(n)").font(.system(size: 22, weight: .heavy, design: .rounded)).foregroundStyle(highlight ? LK.amber : LK.text)
Text(label).font(.system(size: 10, weight: .bold)).tracking(1).foregroundStyle(LK.muted)
}
}
private func chip(_ title: String, color: Color? = nil, on: Bool, action: @escaping () -> Void) -> some View {
Button(action: action) {
HStack(spacing: 6) {
if let color { Circle().fill(color).frame(width: 9, height: 9).overlay(Circle().stroke(LK.border)) }
Text(title).font(.system(size: 12, weight: .bold))
}
.foregroundStyle(on ? LK.onAmber : LK.text2)
.padding(.horizontal, 12).frame(height: 28)
.background(Capsule().fill(on ? LK.amber : LK.raised))
.overlay(Capsule().stroke(on ? Color.clear : LK.borderStrong))
}
.buttonStyle(.plain)
}
}
/// Sidebar list of players in this folder with number of images – click filters.
struct MatchdayPlayerList: View {
@EnvironmentObject var state: AppState
var body: some View {
let players = state.playerCounts
ScrollView {
VStack(alignment: .leading, spacing: 2) {
if players.isEmpty {
Text("Noch keine Spieler:innen – Nummern erkennen (⌘⇧J) oder Vorschläge annehmen.")
.font(.system(size: 12)).foregroundStyle(LK.muted).padding(.horizontal, 16)
}
ForEach(players) { p in
let on = state.filter.person == p.name
Button {
state.filter.team = nil; state.filter.withoutPlayer = false
state.filter.person = on ? nil : p.name
} label: {
HStack(spacing: 10) {
Text(p.number.map(String.init) ?? "–")
.font(LK.mono(12, .bold))
.foregroundStyle(textColor(on: p.team?.shirtColor))
.frame(width: 28, height: 22)
.background(RoundedRectangle(cornerRadius: 5).fill(p.team?.shirtColor.swiftUI ?? LK.raised))
Text(p.name).font(.system(size: 13)).lineLimit(1)
Spacer()
Text("\(p.count)").font(LK.mono(12)).foregroundStyle(LK.muted)
}
.foregroundStyle(on ? LK.amber : LK.text)
.padding(.horizontal, 10).padding(.vertical, 5)
.background(RoundedRectangle(cornerRadius: 7).fill(on ? LK.selected : Color.clear))
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.padding(.horizontal, 6)
}
}
.padding(.bottom, 8)
}
}
/// Readable number on the kit color (dark text on light kits).
private func textColor(on c: KitColor?) -> Color {
guard let c else { return LK.text }
let luminance = 0.299 * c.r + 0.587 * c.g + 0.114 * c.b
return luminance > 0.6 ? LK.onAmber : .white
}
}