diff --git a/DouShouQiIOS/DouShouQiIOS.xcodeproj/project.pbxproj b/DouShouQiIOS/DouShouQiIOS.xcodeproj/project.pbxproj index f192034..ee595fb 100644 --- a/DouShouQiIOS/DouShouQiIOS.xcodeproj/project.pbxproj +++ b/DouShouQiIOS/DouShouQiIOS.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 7B2597B82C203AFE0095F010 /* PlayerSelect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B2597B72C203AFE0095F010 /* PlayerSelect.swift */; }; + 7B2597BA2C203FCB0095F010 /* ImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B2597B92C203FCB0095F010 /* ImagePicker.swift */; }; 7B3B17642BF24B32002BC817 /* Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B3B17632BF24B32002BC817 /* Player.swift */; }; 7B3B17672BF24ED6002BC817 /* FullButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B3B17662BF24ED6002BC817 /* FullButtonStyle.swift */; }; 7B4508CD2BF206AF0027E1EF /* DouShouQiIOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4508CC2BF206AF0027E1EF /* DouShouQiIOSApp.swift */; }; @@ -54,6 +56,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 7B2597B72C203AFE0095F010 /* PlayerSelect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerSelect.swift; sourceTree = ""; }; + 7B2597B92C203FCB0095F010 /* ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePicker.swift; sourceTree = ""; }; 7B3B17632BF24B32002BC817 /* Player.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Player.swift; sourceTree = ""; }; 7B3B17662BF24ED6002BC817 /* FullButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullButtonStyle.swift; sourceTree = ""; }; 7B4508C92BF206AF0027E1EF /* DouShouQiIOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DouShouQiIOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -121,6 +125,7 @@ 7B6426FA2C00BFF500575E16 /* SpriteMeeple.swift */, 7BDE976E2C0E18160079F2CD /* PlayerVM.swift */, 7BEAB78C2C19A94100DF39C9 /* GameVM.swift */, + 7B2597B92C203FCB0095F010 /* ImagePicker.swift */, ); path = Class; sourceTree = ""; @@ -206,6 +211,7 @@ 7BB279882BFDF79E00491801 /* GameView.swift */, 7B6426F82C00BDEA00575E16 /* SpriteKitView.swift */, 7BDE976C2C0E13160079F2CD /* EditModalView.swift */, + 7B2597B72C203AFE0095F010 /* PlayerSelect.swift */, ); path = View; sourceTree = ""; @@ -382,12 +388,14 @@ 7BDD43C72BFCC927003984FB /* MainMenuView.swift in Sources */, 7B4508CF2BF206AF0027E1EF /* ContentView.swift in Sources */, 7BE8C5652C09A29A00A6E8C9 /* Color.swift in Sources */, + 7B2597B82C203AFE0095F010 /* PlayerSelect.swift in Sources */, 7B6426FB2C00BFF500575E16 /* SpriteMeeple.swift in Sources */, 7B4508CD2BF206AF0027E1EF /* DouShouQiIOSApp.swift in Sources */, 7BEAB78B2C19A26000DF39C9 /* StubbedPlayers.swift in Sources */, 7B6426F92C00BDEA00575E16 /* SpriteKitView.swift in Sources */, 7BDE976D2C0E13160079F2CD /* EditModalView.swift in Sources */, 7BDE976F2C0E18160079F2CD /* PlayerVM.swift in Sources */, + 7B2597BA2C203FCB0095F010 /* ImagePicker.swift in Sources */, BA5AFD392C09D1020056D332 /* DoubleTextDisplay.swift in Sources */, BA5AFD332C09C7470056D332 /* ClassicTextDisplay.swift in Sources */, BA5AFD352C09CAC10056D332 /* NavButton.swift in Sources */, diff --git a/DouShouQiIOS/DouShouQiIOS/Class/GameVM.swift b/DouShouQiIOS/DouShouQiIOS/Class/GameVM.swift index 5185ed8..269e8db 100644 --- a/DouShouQiIOS/DouShouQiIOS/Class/GameVM.swift +++ b/DouShouQiIOS/DouShouQiIOS/Class/GameVM.swift @@ -92,11 +92,11 @@ class GameVM : ObservableObject, Identifiable { destRow = readInt(withMessage: "\(player.name) please enter the destination row in which you want to move your piece)") destCol = readInt(withMessage: "\(player.name) please enter the destination column in which you want to move your piece)") - self.pieces[player.id][Animal.cat]? + //self.pieces[player.id][Animal.cat]? return Move(of: player.id, fromRow: originRow!, andFromColumn: originCol!, toRow: destRow!, andToColumn: destCol!) } - + func startGame() async throws -> Int diff --git a/DouShouQiIOS/DouShouQiIOS/Class/ImagePicker.swift b/DouShouQiIOS/DouShouQiIOS/Class/ImagePicker.swift new file mode 100644 index 0000000..fbb0b5c --- /dev/null +++ b/DouShouQiIOS/DouShouQiIOS/Class/ImagePicker.swift @@ -0,0 +1,51 @@ +// +// ImagePicker.swift +// DouShouQiIOS +// +// Created by Pierre FERREIRA on 17/06/2024. +// + +import SwiftUI + +struct ImagePicker: UIViewControllerRepresentable { + @Environment(\.presentationMode) private var presentationMode + var sourceType: UIImagePickerController.SourceType = .photoLibrary + @Binding var selectedImage: UIImage + + func makeUIViewController(context: UIViewControllerRepresentableContext) -> UIImagePickerController { + + let imagePicker = UIImagePickerController() + imagePicker.allowsEditing = false + imagePicker.sourceType = sourceType + imagePicker.delegate = context.coordinator + + return imagePicker + } + + func updateUIViewController(_ uiViewController: UIImagePickerController, context: UIViewControllerRepresentableContext) { + + } + + func makeCoordinator() -> Coordinator { + Coordinator(self) + } + + final class Coordinator: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate { + + var parent: ImagePicker + + init(_ parent: ImagePicker) { + self.parent = parent + } + + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { + + if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage { + parent.selectedImage = image + } + + parent.presentationMode.wrappedValue.dismiss() + } + + } +} diff --git a/DouShouQiIOS/DouShouQiIOS/View/MainMenuView.swift b/DouShouQiIOS/DouShouQiIOS/View/MainMenuView.swift index 4c0086a..27d7569 100644 --- a/DouShouQiIOS/DouShouQiIOS/View/MainMenuView.swift +++ b/DouShouQiIOS/DouShouQiIOS/View/MainMenuView.swift @@ -27,10 +27,10 @@ struct MainMenuView: View { .bold() .padding() - NavButton("Jouer Seul", destinationView: {GameView()}) + NavButton("Jouer Seul", destinationView: {PlayerSelect(versus: false)}) .padding(.top, 10) - NavButton("Jouer en Multi", destinationView: {GameView()}) + NavButton("Jouer en Multi", destinationView: {PlayerSelect(versus: true)}) NavButton("Leaderboard", destinationView: {PlayerListView()}) diff --git a/DouShouQiIOS/DouShouQiIOS/View/PlayerSelect.swift b/DouShouQiIOS/DouShouQiIOS/View/PlayerSelect.swift new file mode 100644 index 0000000..e539dd2 --- /dev/null +++ b/DouShouQiIOS/DouShouQiIOS/View/PlayerSelect.swift @@ -0,0 +1,77 @@ +// +// PlayerSelect.swift +// DouShouQiIOS +// +// Created by Pierre FERREIRA on 17/06/2024. +// + +import SwiftUI + +struct PlayerSelect: View { + @State private var image = UIImage() + @State private var showSheet = false + + + var versus : Bool + var body: some View { + ZStack { + Rectangle().fill(Color.bgColor).ignoresSafeArea() + VStack { + VStack{ + Text("Joueur 1") + TextField("Entrez un nom ici",text: .constant("")) + }.foregroundStyle(.primary) + .padding(20) + .overlay( + RoundedRectangle(cornerRadius: 16) + .stroke(Color.player1, lineWidth: 5) + ) + .padding(40) + + if (versus){ + + VStack{ + Text("Joueur 1") + + HStack { + Image(uiImage: self.image) + .resizable() + .cornerRadius(50) + .frame(width: 100, height: 100) + .background(Color.black.opacity(0.2)) + .aspectRatio(contentMode: .fill) + .clipShape(Circle()) + + ClassicTextDisplay(text: "Change photo") + .onTapGesture { + showSheet = true + } + } + .padding(.horizontal, 20) + .sheet(isPresented: $showSheet) { + // Pick an image from the photo library: + ImagePicker(sourceType: .photoLibrary, selectedImage: self.$image) + + // If you wish to take a photo from camera instead: + // ImagePicker(sourceType: .camera, selectedImage: self.$image) + } + + TextField("Entrez un nom ici",text: .constant("")) + }.foregroundStyle(.primary) + .padding(20) + .overlay( + RoundedRectangle(cornerRadius: 16) + .stroke(Color.player2, lineWidth: 5) + ) + .padding(40) + } + } + } + } +} + +struct PlayerSelect_Previews: PreviewProvider { + static var previews: some View { + PlayerSelect(versus: true) + } +}