You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.2 KiB
103 lines
3.2 KiB
//
|
|
// NewGameView.swift
|
|
// App
|
|
//
|
|
// Created by etudiant2 on 21/05/2025.
|
|
//
|
|
|
|
import SwiftUI
|
|
import PhotosUI
|
|
|
|
struct NewGameView: View {
|
|
@StateObject
|
|
private var vm: NewGameVM = NewGameVM()
|
|
@StateObject
|
|
private var p1: PlayerSettingsVM = PlayerSettingsVM(type: .Human)
|
|
@StateObject
|
|
private var p2: PlayerSettingsVM = PlayerSettingsVM(type: .AISimpleNegaMax)
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Form {
|
|
Section(header: Label("generic.player1.name", systemImage: "person")) {
|
|
PlayerSectionView(settings: p1)
|
|
}
|
|
|
|
Section(header: Label("generic.player2.name", systemImage: "person")) {
|
|
PlayerSectionView(settings: p2)
|
|
}
|
|
|
|
HStack {
|
|
Picker("newGame.rules.title", systemImage: "slider.horizontal.3", selection: $vm.rulesType) {
|
|
Text("generic.rules.classic.name").tag(RulesType.Classic)
|
|
}
|
|
|
|
Button(action: {
|
|
// TODO
|
|
}) {
|
|
Image(systemName: "questionmark.circle")
|
|
}
|
|
}
|
|
|
|
Section(header: Label("newGame.dimensions", systemImage: "crop")) {
|
|
Stepper("newGame.dimensions.width \(vm.width)", value: $vm.width)
|
|
Stepper("newGame.dimensions.height \(vm.height)", value: $vm.height)
|
|
Stepper("newGame.dimensions.alignedTokens \(vm.alignedTokens)", value: $vm.alignedTokens)
|
|
}
|
|
|
|
Section(header: Label("newGame.timeLimit", systemImage: "stopwatch")) {
|
|
|
|
}
|
|
|
|
Button("newGame.play", systemImage: "play") {
|
|
// TODO: yes
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct PlayerSectionView: View {
|
|
@ObservedObject
|
|
private var settings: PlayerSettingsVM
|
|
|
|
@State private var name: String = ""
|
|
@State private var photo: PhotosPickerItem? = nil
|
|
|
|
var body: some View {
|
|
Picker("newGame.player.type", selection: $settings.type) {
|
|
Text("generic.player.type.human").tag(PlayerType.Human)
|
|
Text("generic.player.type.aiRandom").tag(PlayerType.AIRandom)
|
|
Text("generic.player.type.aiFinnishHim").tag(PlayerType.AIFinnishHim)
|
|
Text("generic.player.type.aiSimpleNegaMax").tag(PlayerType.AISimpleNegaMax)
|
|
}
|
|
|
|
let binding: Binding<String> = if (settings.type == .Human) {
|
|
$name
|
|
} else {
|
|
// FIXME: make text field readonly
|
|
.constant("TODO constant name")
|
|
}
|
|
TextField("newGame.player.name", text: binding)
|
|
// TODO: MacOS
|
|
//.textInputSuggestions(isEnabled: true) {
|
|
//
|
|
//}
|
|
|
|
// TODO: actual photo support
|
|
Image(systemName: "camera.viewfinder").overlay {
|
|
PhotosPicker(selection: $photo) {
|
|
Text("newGame.player.photo.picker")
|
|
}
|
|
}
|
|
}
|
|
|
|
init(settings: PlayerSettingsVM) {
|
|
self.settings = settings
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
NewGameView()
|
|
}
|