diff --git a/Sources/Lichtkasten/LichtkastenApp.swift b/Sources/Lichtkasten/LichtkastenApp.swift index 6b05957..866b2c9 100644 --- a/Sources/Lichtkasten/LichtkastenApp.swift +++ b/Sources/Lichtkasten/LichtkastenApp.swift @@ -118,6 +118,8 @@ struct AppCommands: Commands { .keyboardShortcut("j", modifiers: [.command, .shift]) .disabled(state.folder == nil || state.jerseyRunning) Button("Trikot-Erkennung einrichten (Teams & Farben) …") { state.showJerseySetup = true } + Toggle("Matchday-Ansicht", isOn: $state.settings.jersey.matchday) + .keyboardShortcut("m", modifiers: [.command, .option]) Divider() Button(state.previewMode ? "Kontaktabzug (Leertaste)" : "Vorschau (Leertaste)") { state.previewMode.toggle() } Button(state.isInSentFolder ? "Zum INPUT/RAW-Ordner" : "Zum SENT-Ordner") { state.toggleRawSent() } diff --git a/Sources/Lichtkasten/Services/AppState.swift b/Sources/Lichtkasten/Services/AppState.swift index 7986391..56c2388 100644 --- a/Sources/Lichtkasten/Services/AppState.swift +++ b/Sources/Lichtkasten/Services/AppState.swift @@ -1199,13 +1199,17 @@ final class AppState: ObservableObject { return map.values.sorted { ($0.count, $1.name) > ($1.count, $0.name) } } - /// Event and date for the Matchday header (most common IPTC event in the folder). + /// Event and date for the Matchday header: those of the current image (SENT holds several games), + /// else the most common event in the folder. var matchdayEvent: (event: String, date: String) { + let f = DateFormatter(); f.dateFormat = "dd.MM.yyyy" + if let c = cursorItem, let e = c.iptc.text["event"], !e.isEmpty { + return (e, c.captureDate.map { f.string(from: $0) } ?? "") + } var counts: [String: Int] = [:] for i in items { if let e = i.iptc.text["event"], !e.isEmpty { counts[e, default: 0] += 1 } } let event = counts.max { $0.value < $1.value }?.key ?? (folder?.lastPathComponent ?? "") - let f = DateFormatter(); f.dateFormat = "dd.MM.yyyy" - let date = items.compactMap(\.captureDate).min().map { f.string(from: $0) } ?? "" + let date = (cursorItem?.captureDate ?? items.compactMap(\.captureDate).min()).map { f.string(from: $0) } ?? "" return (event, date) } diff --git a/Sources/Lichtkasten/Services/Persistence.swift b/Sources/Lichtkasten/Services/Persistence.swift index f16e583..9d32809 100644 --- a/Sources/Lichtkasten/Services/Persistence.swift +++ b/Sources/Lichtkasten/Services/Persistence.swift @@ -67,14 +67,19 @@ struct LightroomSettings: Codable, Hashable { /// Jersey number recognition settings (teams of the current match). struct JerseySettings: Codable, Hashable { + enum CodingKeys: String, CodingKey { + case teams, useShirt, useShorts, minConfidence, autoAfterIngest, separator + case matchday = "matchdayEnabled" // new key: the old default (on) is not carried over + } + var teams: [JerseyTeam] = [] var useShirt = true var useShorts = true var minConfidence = 0.35 var autoAfterIngest = false var separator = ", " - /// Matchday view (team header, player list, team-colored cards) when two teams are set up - var matchday = true + /// Matchday view (team header, player list, team-colored cards) – opt-in, needs two teams + var matchday = false init() {} init(from decoder: Decoder) throws { diff --git a/Sources/Lichtkasten/Views/ContentView.swift b/Sources/Lichtkasten/Views/ContentView.swift index eee4474..e0182cf 100644 --- a/Sources/Lichtkasten/Views/ContentView.swift +++ b/Sources/Lichtkasten/Views/ContentView.swift @@ -348,7 +348,7 @@ struct PMSidebar: View { .frame(minHeight: 80, idealHeight: 150) if state.matchdayActive { - panel("Spielerinnen") { MatchdayPlayerList() } accessory: { + panel("Spieler:innen") { MatchdayPlayerList() } accessory: { if state.filter.person != nil || state.filter.team != nil || state.filter.withoutPlayer { Button("Alle") { state.setTeamFilter(nil) }.buttonStyle(.borderless).font(.system(size: 11)) } diff --git a/Sources/Lichtkasten/Views/JerseySetupView.swift b/Sources/Lichtkasten/Views/JerseySetupView.swift index e70fe58..3ae644f 100644 --- a/Sources/Lichtkasten/Views/JerseySetupView.swift +++ b/Sources/Lichtkasten/Views/JerseySetupView.swift @@ -74,9 +74,9 @@ struct JerseySetupView: View { Text("Pro Spiel die Teams wählen und die Trikotfarbe festlegen. Lichtkasten liest Nummern auf Trikot und Hose, bestimmt das Team über die Farbe und schlägt den Spieler aus deinen Code-Ersetzungen vor (Präfix + Nummer, z. B. w10).") .font(.callout).foregroundStyle(.secondary) - ForEach(state.settings.jersey.teams) { t in - if let i = state.settings.jersey.teams.firstIndex(where: { $0.id == t.id }) { teamRow(i) } - } + Toggle("Matchday-Ansicht verwenden (Teamleiste, Spieler:innen-Liste, Teamfarben in den Kacheln)", + isOn: jersey.matchday) + ForEach(state.settings.jersey.teams) { t in teamRow(t.id) } HStack { Menu("Team hinzufügen") { ForEach(state.codeLibrary.sets) { set in @@ -126,9 +126,28 @@ struct JerseySetupView: View { } } + /// Binding by id – stays valid while a team is being removed (index-based bindings crashed here). + private func teamBinding(_ id: UUID) -> Binding { + Binding( + get: { state.settings.jersey.teams.first { $0.id == id } + ?? JerseyTeam(name: "", prefix: "", shirtColor: KitColor(r: 0, g: 0, b: 0)) }, + set: { new in + if let i = state.settings.jersey.teams.firstIndex(where: { $0.id == id }) { state.settings.jersey.teams[i] = new } + }) + } + + private func remove(_ id: UUID) { + if target?.team == id { target = nil } + // after the current view update – removing inside it invalidates the row's bindings + DispatchQueue.main.async { + state.settings.jersey.teams.removeAll { $0.id == id } + if target == nil, let first = state.settings.jersey.teams.first { target = PickTarget(team: first.id, shorts: false) } + } + } + @ViewBuilder - private func teamRow(_ i: Int) -> some View { - let team = jersey.teams[i] + private func teamRow(_ id: UUID) -> some View { + let team = teamBinding(id) GroupBox { HStack(spacing: 12) { VStack(alignment: .leading, spacing: 6) { @@ -136,34 +155,34 @@ struct JerseySetupView: View { HStack { Text("Code-Präfix") TextField("w", text: team.prefix).frame(width: 50).textFieldStyle(.roundedBorder) - Text(example(state.settings.jersey.teams[i])) + Text(example(team.wrappedValue)) .font(.caption).foregroundStyle(.secondary).lineLimit(1) } } Spacer() - swatchButton(i, shorts: false) + swatchButton(team.wrappedValue, shorts: false) Toggle("Hose", isOn: Binding( - get: { state.settings.jersey.teams[i].shortsColor != nil }, + get: { team.wrappedValue.shortsColor != nil }, set: { on in - state.settings.jersey.teams[i].shortsColor = on ? state.settings.jersey.teams[i].shirtColor : nil - if on { target = PickTarget(team: state.settings.jersey.teams[i].id, shorts: true) } + team.wrappedValue.shortsColor = on ? team.wrappedValue.shirtColor : nil + if on { target = PickTarget(team: id, shorts: true) } })) .toggleStyle(.checkbox) .help("Eigene Hosenfarbe (z. B. weißes Trikot, grüne Hose)") - if state.settings.jersey.teams[i].shortsColor != nil { swatchButton(i, shorts: true) } + if team.wrappedValue.shortsColor != nil { swatchButton(team.wrappedValue, shorts: true) } ColorPicker("", selection: cgBinding(team.shirtColor), supportsOpacity: false) .labelsHidden() .help("Alternativ: Farbe manuell wählen") - Button(role: .destructive) { state.settings.jersey.teams.remove(at: i) } label: { Image(systemName: "trash") } + Button(role: .destructive) { remove(id) } label: { Image(systemName: "trash") } .buttonStyle(.borderless) + .help("Team entfernen") } .padding(4) } } /// Color swatch; click = "next click in the photo sets this color". - private func swatchButton(_ i: Int, shorts: Bool) -> some View { - let team = state.settings.jersey.teams[i] + private func swatchButton(_ team: JerseyTeam, shorts: Bool) -> some View { let c = shorts ? (team.shortsColor ?? team.shirtColor) : team.shirtColor let active = target == PickTarget(team: team.id, shorts: shorts) return Button { target = PickTarget(team: team.id, shorts: shorts) } label: { diff --git a/Sources/Lichtkasten/Views/MatchdayViews.swift b/Sources/Lichtkasten/Views/MatchdayViews.swift index 9cace4b..af58c17 100644 --- a/Sources/Lichtkasten/Views/MatchdayViews.swift +++ b/Sources/Lichtkasten/Views/MatchdayViews.swift @@ -39,7 +39,7 @@ struct MatchdayHeader: View { ForEach(teams) { t in chip(t.name, color: t.shirtColor.swiftUI, on: state.filter.team == t.id) { state.setTeamFilter(t.id) } } - chip("Ohne Spielerin", on: state.filter.withoutPlayer) { + chip("Ohne Spieler:in", on: state.filter.withoutPlayer) { state.setTeamFilter(nil); state.filter.withoutPlayer = true } if let p = state.filter.person { @@ -85,7 +85,7 @@ struct MatchdayHeader: View { let open = state.items.filter { !state.openSuggestions(for: $0.id).isEmpty }.count return HStack(spacing: 18) { counter(tagged, "GETAGGT", highlight: true) - counter(withPlayer, "MIT SPIELERIN") + counter(withPlayer, "MIT SPIELER:IN") counter(open, "OFFEN") } } @@ -121,7 +121,7 @@ struct MatchdayPlayerList: View { ScrollView { VStack(alignment: .leading, spacing: 2) { if players.isEmpty { - Text("Noch keine Spielerinnen – Nummern erkennen (⌘⇧J) oder Vorschläge annehmen.") + 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 diff --git a/Sources/Lichtkasten/Views/SettingsView.swift b/Sources/Lichtkasten/Views/SettingsView.swift index 33d7502..05a6dd5 100644 --- a/Sources/Lichtkasten/Views/SettingsView.swift +++ b/Sources/Lichtkasten/Views/SettingsView.swift @@ -36,6 +36,13 @@ struct GeneralSettings: View { } Text("Vorschau: Z = Einpassen/100 %, + / − oder Trackpad zum Zoomen.").font(.caption).foregroundStyle(.secondary) } + Section("Ansicht") { + Toggle("Matchday-Ansicht (Teamleiste, Spieler:innen-Liste, Teamfarben)", isOn: $state.settings.jersey.matchday) + if state.settings.jersey.matchday && state.settings.jersey.teams.count < 2 { + Text("Braucht zwei Teams in Bild → Trikot-Erkennung einrichten.").font(.caption).foregroundStyle(.secondary) + } + Toggle("IPTC-Panel neben der Vorschau", isOn: $state.settings.loupePanel) + } Section("Ingest") { Toggle("Ingest-Fenster öffnen, wenn eine Speicherkarte erkannt wird", isOn: $state.settings.autoIngestOnCardMount) Toggle("Karte nach dem Ingest automatisch auswerfen", isOn: $state.settings.ingest.unmountAfter)