parent
9dae915bcd
commit
37f67c603e
@ -0,0 +1,100 @@
|
|||||||
|
//
|
||||||
|
// NewGameView.swift
|
||||||
|
// App
|
||||||
|
//
|
||||||
|
// Created by etudiant2 on 21/05/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import PhotosUI
|
||||||
|
|
||||||
|
struct NewGameView: View {
|
||||||
|
@State private var p2: PlayerType = .AISimpleNegaMax
|
||||||
|
@State private var rules_type: RulesType = .Classic
|
||||||
|
@State private var width: UInt = 7
|
||||||
|
@State private var height: UInt = 7
|
||||||
|
@State private var alignedTokens: UInt = 4
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
Form {
|
||||||
|
Section("generic.player1.name") {
|
||||||
|
PlayerSectionView(initialType: .Human)
|
||||||
|
}
|
||||||
|
|
||||||
|
Section("generic.player2.name") {
|
||||||
|
PlayerSectionView(initialType: .AISimpleNegaMax)
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Picker("newGame.rules.title", systemImage: "globe", selection: $rules_type) {
|
||||||
|
Text("generic.rules.classic.name").tag(RulesType.Classic)
|
||||||
|
}
|
||||||
|
|
||||||
|
Image(systemName: "globe")
|
||||||
|
}
|
||||||
|
|
||||||
|
Section("newGame.dimensions") {
|
||||||
|
Stepper("newGame.dimensions.width \(width)", value: $width)
|
||||||
|
Stepper("newGame.dimensions.height \(height)", value: $height)
|
||||||
|
Stepper("newGame.dimensions.alignedTokens \(alignedTokens)", value: $alignedTokens)
|
||||||
|
}
|
||||||
|
|
||||||
|
Button("newGame.play") {
|
||||||
|
// TODO: yes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct PlayerSectionView: View {
|
||||||
|
@State private var type: PlayerType
|
||||||
|
@State private var name: String
|
||||||
|
@State private var photo: PhotosPickerItem? = nil
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Picker("newGame.player.type", selection: $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 (self.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: "globe").overlay {
|
||||||
|
PhotosPicker(selection: $photo) {
|
||||||
|
Text("newGame.player.photo.picker")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init(initialType type: PlayerType) {
|
||||||
|
self.type = type
|
||||||
|
self.name = "TODO default name"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum PlayerType {
|
||||||
|
case Human, AIRandom, AIFinnishHim, AISimpleNegaMax
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum RulesType {
|
||||||
|
case Classic
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
NewGameView()
|
||||||
|
}
|
Loading…
Reference in new issue