From 13a9189e8b41a4360b383bedc1be6182403995ef Mon Sep 17 00:00:00 2001 From: Mathieu GROUSSEAU Date: Fri, 20 Jun 2025 19:55:40 +0200 Subject: [PATCH] Useful rule selection --- App/App/View/NewGameView.swift | 41 +++++++++++++++++++------------ App/App/ViewModel/NewGameVM.swift | 2 +- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/App/App/View/NewGameView.swift b/App/App/View/NewGameView.swift index 6e45fee..c7f3c7d 100644 --- a/App/App/View/NewGameView.swift +++ b/App/App/View/NewGameView.swift @@ -29,14 +29,17 @@ struct NewGameView: View { HStack { Picker("newGame.rules.title", systemImage: "slider.horizontal.3", selection: $vm.rulesType) { - Text("generic.rules.classic.name").tag(RulesType.Classic) + ForEach(RulesType.allCases) { + Text($0.baseTranslationKey).tag($0) + } } - Button(action: { - // TODO - }) { - Image(systemName: "questionmark.circle") - } + // TODO: info button + // Button(action: { + // // TODO + // }) { + // Image(systemName: "questionmark.circle") + // } } Section(header: Label("newGame.dimensions", systemImage: "crop")) { @@ -75,7 +78,6 @@ private struct PlayerSectionView: View { @ObservedObject private var settings: PlayerSettingsVM - @State private var name: String = "" @State private var photo: PhotosPickerItem? = nil var body: some View { @@ -85,16 +87,13 @@ private struct PlayerSectionView: View { } } - let binding: Binding = if (settings.type == .Human) { - $name - } else { - .constant(String(localized: String.LocalizationValue("\(settings.type.baseTranslationKey).name" as String))) + if (settings.type == .Human) { + TextField("newGame.player.name", text: $settings.name) + // TODO: MacOS + //.textInputSuggestions(isEnabled: true) { + // + //} } - TextField("newGame.player.name", text: binding) - // TODO: MacOS - //.textInputSuggestions(isEnabled: true) { - // - //} // // TODO: actual photo support // Image(systemName: "camera.viewfinder").overlay { @@ -120,6 +119,16 @@ extension PlayerType { } } +extension RulesType { + var baseTranslationKey: LocalizedStringKey { + return switch (self) { + case .Classic: "generic.rules.classic.name" + case .TicTacToe: "generic.rules.tictactoe.name" + case .PopOut: "generic.rules.popout.name" + } + } +} + #Preview { NewGameView() } diff --git a/App/App/ViewModel/NewGameVM.swift b/App/App/ViewModel/NewGameVM.swift index 790b4c8..7c5983f 100644 --- a/App/App/ViewModel/NewGameVM.swift +++ b/App/App/ViewModel/NewGameVM.swift @@ -12,7 +12,7 @@ class PlayerSettingsVM : ObservableObject, Identifiable { @Published var type: PlayerType @Published var name: String = "" - init(type: PlayerType ) { + init(type: PlayerType) { self.type = type } }