diff --git a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj index 8f191fd..bf697b9 100644 --- a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj +++ b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj @@ -41,6 +41,8 @@ EC62C5092C0467240048CD0B /* SplashScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C5082C0467240048CD0B /* SplashScreenView.swift */; }; EC62C50D2C046D9E0048CD0B /* SplashScreenSound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = EC62C50C2C046D9E0048CD0B /* SplashScreenSound.mp3 */; }; EC62C50F2C05D06A0048CD0B /* AddPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C50E2C05D06A0048CD0B /* AddPlayerView.swift */; }; + EC62C5152C061C350048CD0B /* shrek.png in Resources */ = {isa = PBXBuildFile; fileRef = EC62C5142C061C350048CD0B /* shrek.png */; }; + EC62C5172C0620C00048CD0B /* rap.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = EC62C5162C0620C00048CD0B /* rap.mp3 */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -112,6 +114,8 @@ EC62C5082C0467240048CD0B /* SplashScreenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashScreenView.swift; sourceTree = ""; }; EC62C50C2C046D9E0048CD0B /* SplashScreenSound.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = SplashScreenSound.mp3; sourceTree = ""; }; EC62C50E2C05D06A0048CD0B /* AddPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddPlayerView.swift; sourceTree = ""; }; + EC62C5142C061C350048CD0B /* shrek.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = shrek.png; sourceTree = ""; }; + EC62C5162C0620C00048CD0B /* rap.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = rap.mp3; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -291,6 +295,7 @@ 649B59AA2BF64DF1002BAE38 /* Images */ = { isa = PBXGroup; children = ( + EC62C5142C061C350048CD0B /* shrek.png */, 649B59AB2BF64E12002BAE38 /* Images.xcassets */, 649B59AD2BF64EAB002BAE38 /* AppImages.swift */, ); @@ -338,6 +343,7 @@ EC62C5042C045BE00048CD0B /* Musics */ = { isa = PBXGroup; children = ( + EC62C5162C0620C00048CD0B /* rap.mp3 */, EC62C4FE2C0457AD0048CD0B /* TitleScreenMusic.mp3 */, ); path = Musics; @@ -449,8 +455,10 @@ buildActionMask = 2147483647; files = ( 649B59A72BF64BA9002BAE38 /* Colors.xcassets in Resources */, + EC62C5152C061C350048CD0B /* shrek.png in Resources */, 6493C1C02C046BF900B5121D /* samurai.ttf in Resources */, EC62C5062C045C1A0048CD0B /* TitleScreenButtonSound.mp3 in Resources */, + EC62C5172C0620C00048CD0B /* rap.mp3 in Resources */, 649B59AC2BF64E12002BAE38 /* Images.xcassets in Resources */, EC62C50D2C046D9E0048CD0B /* SplashScreenSound.mp3 in Resources */, 645834632BF5F92500E18321 /* Preview Assets.xcassets in Resources */, diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/AppImages.swift b/DouShouQi_App/DouShouQi_App/Assets/Images/AppImages.swift index f26776f..1a06ad9 100644 --- a/DouShouQi_App/DouShouQi_App/Assets/Images/AppImages.swift +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/AppImages.swift @@ -11,4 +11,11 @@ import SwiftUI public struct AppImages { static let TitleImage = "TitlePageImage" static let SemiLion = "SemiLion" + static let Lion = "Lion" + static let Rat = "Rat" + static let Elephant = "Elephant" + static let Cat = "Cat" + static let Dog = "Dog" + static let Leopard = "Leopard" + static let Wolf = "Wolf" } diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Cat.imageset/Contents.json b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Cat.imageset/Contents.json new file mode 100644 index 0000000..cf9e340 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Cat.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "doushouqi-cat.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Cat.imageset/doushouqi-cat.svg b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Cat.imageset/doushouqi-cat.svg new file mode 100644 index 0000000..efbcb8b --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Cat.imageset/doushouqi-cat.svg @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + + + + + + + + + diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Dog.imageset/Contents.json b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Dog.imageset/Contents.json new file mode 100644 index 0000000..d18d976 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Dog.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "doushouqi-dog.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Dog.imageset/doushouqi-dog.svg b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Dog.imageset/doushouqi-dog.svg new file mode 100644 index 0000000..c19368b --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Dog.imageset/doushouqi-dog.svg @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + + + + + + + + + diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Elephant.imageset/Contents.json b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Elephant.imageset/Contents.json new file mode 100644 index 0000000..7326d74 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Elephant.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "doushouqi-elephant.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Elephant.imageset/doushouqi-elephant.svg b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Elephant.imageset/doushouqi-elephant.svg new file mode 100644 index 0000000..fd7e877 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Elephant.imageset/doushouqi-elephant.svg @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + + + + + + + + + diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Leopard.imageset/Contents.json b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Leopard.imageset/Contents.json new file mode 100644 index 0000000..0a3aa08 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Leopard.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "doushouqi-leopard.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Leopard.imageset/doushouqi-leopard.svg b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Leopard.imageset/doushouqi-leopard.svg new file mode 100644 index 0000000..477b3f0 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Leopard.imageset/doushouqi-leopard.svg @@ -0,0 +1,442 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + + + + + + + + + diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Lion.imageset/Contents.json b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Lion.imageset/Contents.json new file mode 100644 index 0000000..f123ff0 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Lion.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "doushouqi-lion.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Lion.imageset/doushouqi-lion.svg b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Lion.imageset/doushouqi-lion.svg new file mode 100644 index 0000000..2bf2e5d --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Lion.imageset/doushouqi-lion.svg @@ -0,0 +1,245 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + + + + + + + + + diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Rat.imageset/Contents.json b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Rat.imageset/Contents.json new file mode 100644 index 0000000..7250ab4 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Rat.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "doushouqi-rat.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Rat.imageset/doushouqi-rat.svg b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Rat.imageset/doushouqi-rat.svg new file mode 100644 index 0000000..7cb8da0 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Rat.imageset/doushouqi-rat.svg @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + + + + + + + + + diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Wolf.imageset/Contents.json b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Wolf.imageset/Contents.json new file mode 100644 index 0000000..b9d1c0a --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Wolf.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "doushouqi-wolf.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Wolf.imageset/doushouqi-wolf.svg b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Wolf.imageset/doushouqi-wolf.svg new file mode 100644 index 0000000..ea28a01 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Assets/Images/Images.xcassets/Wolf.imageset/doushouqi-wolf.svg @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + + + + + + + + + diff --git a/DouShouQi_App/DouShouQi_App/Assets/Images/shrek.png b/DouShouQi_App/DouShouQi_App/Assets/Images/shrek.png new file mode 100644 index 0000000..9479186 Binary files /dev/null and b/DouShouQi_App/DouShouQi_App/Assets/Images/shrek.png differ diff --git a/DouShouQi_App/DouShouQi_App/Assets/Musics/rap.mp3 b/DouShouQi_App/DouShouQi_App/Assets/Musics/rap.mp3 new file mode 100644 index 0000000..0b61f4f Binary files /dev/null and b/DouShouQi_App/DouShouQi_App/Assets/Musics/rap.mp3 differ diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/AddPlayerView.swift b/DouShouQi_App/DouShouQi_App/Components/Player/AddPlayerView.swift index 80b25ba..49680b1 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/AddPlayerView.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/AddPlayerView.swift @@ -6,12 +6,18 @@ // import SwiftUI +import UIKit struct AddPlayerView: View { @Binding var isPresented: Bool @Binding var players: [Player] @State private var playerName: String = "" @State private var showAlert = false + @State private var showImagePicker = false + @State private var profileImage: UIImage? = nil + @State private var profileImagePath: String = "" + @State private var imagePickerSourceType: UIImagePickerController.SourceType = .photoLibrary + @State private var showActionSheet = false var body: some View { VStack(spacing: 20) { @@ -23,12 +29,37 @@ struct AddPlayerView: View { .background(Color(.systemGray6)) .cornerRadius(10) + if let profileImage = profileImage { + Image(uiImage: profileImage) + .resizable() + .frame(width: 100, height: 100) + .clipShape(Circle()) + } else { + Button(action: { + showActionSheet = true + }) { + Text("Select Profile Photo") + .foregroundColor(.white) + .padding() + .background(Color.blue) + .cornerRadius(10) + } + } + HStack { Button(action: { if players.contains(where: { $0.name.lowercased() == playerName.lowercased() }) { showAlert = true } else { - let newPlayer = Player(name: playerName, wins: 0, losses: 0) + if let image = profileImage, let imageData = image.jpegData(compressionQuality: 0.8) { + let filename = UUID().uuidString + ".jpg" + let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) + let documentsDirectory = paths[0] + let fileURL = documentsDirectory.appendingPathComponent(filename) + try? imageData.write(to: fileURL) + profileImagePath = fileURL.path + } + let newPlayer = Player(name: playerName, wins: 0, losses: 0, photo: profileImagePath) players.append(newPlayer) isPresented = false } @@ -59,5 +90,61 @@ struct AddPlayerView: View { .alert(isPresented: $showAlert) { Alert(title: Text("Error"), message: Text("Player already exists."), dismissButton: .default(Text("OK"))) } + .actionSheet(isPresented: $showActionSheet) { + ActionSheet(title: Text("Select Photo"), message: Text("Choose a photo from the library or take a new one."), buttons: [ + .default(Text("Photo Library")) { + imagePickerSourceType = .photoLibrary + showImagePicker = true + }, + .default(Text("Camera")) { + imagePickerSourceType = .camera + showImagePicker = true + }, + .cancel() + ]) + } + .sheet(isPresented: $showImagePicker) { + ImagePicker(image: $profileImage, sourceType: imagePickerSourceType) + } } } + +struct ImagePicker: UIViewControllerRepresentable { + @Binding var image: UIImage? + var sourceType: UIImagePickerController.SourceType + + class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate { + var parent: ImagePicker + + init(parent: ImagePicker) { + self.parent = parent + } + + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { + if let uiImage = info[.originalImage] as? UIImage { + parent.image = uiImage + } + + parent.presentationMode.wrappedValue.dismiss() + } + + func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { + parent.presentationMode.wrappedValue.dismiss() + } + } + + func makeCoordinator() -> Coordinator { + Coordinator(parent: self) + } + + @Environment(\.presentationMode) var presentationMode + + func makeUIViewController(context: Context) -> UIImagePickerController { + let picker = UIImagePickerController() + picker.delegate = context.coordinator + picker.sourceType = sourceType + return picker + } + + func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {} +} diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift b/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift index 950a364..b8acb4e 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift @@ -14,8 +14,18 @@ struct PlayerRow: View { var body: some View { HStack { - Image(systemName: "custom.person") - .foregroundColor(.black) + if let image = UIImage(contentsOfFile: player.photo) { + Image(uiImage: image) + .resizable() + .frame(width: 50, height: 50) + .clipShape(Circle()) + } else { + Image(systemName: "person.circle.fill") + .resizable() + .frame(width: 50, height: 50) + .clipShape(Circle()) + .foregroundColor(.gray) + } VStack(alignment: .leading) { Text(player.name) diff --git a/DouShouQi_App/DouShouQi_App/DouShouQi_AppApp.swift b/DouShouQi_App/DouShouQi_App/DouShouQi_AppApp.swift index 07aed7a..f2d4e8d 100644 --- a/DouShouQi_App/DouShouQi_App/DouShouQi_AppApp.swift +++ b/DouShouQi_App/DouShouQi_App/DouShouQi_AppApp.swift @@ -7,6 +7,7 @@ import SwiftUI + @main struct DouShouQi_AppApp: App { var body: some Scene { diff --git a/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift b/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift index 5dfea67..3ae9046 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift @@ -14,15 +14,16 @@ struct Player: Identifiable { var name: String var wins: Int var losses: Int + var photo: String } // Exemple de vue pour l'interface utilisateur des joueurs struct PlayersView: View { // Liste de joueurs pour l'exemple @State private var players = [ - Player(name: "Rayhan", wins: 7, losses: 6), - Player(name: "Remi", wins: 7, losses: 2), - Player(name: "Nathan", wins: 14, losses: 5) + Player(name: "Rayhan", wins: 7, losses: 6, photo: "shrek"), + Player(name: "Remi", wins: 7, losses: 2, photo: "shrek"), + Player(name: "Nathan", wins: 14, losses: 5, photo: "shrek") ] @State private var searchText = "" @@ -40,14 +41,13 @@ struct PlayersView: View { var body: some View { NavigationView { VStack { - // Image en haut + TitlePageFrame(Text: "PLAYERS", ImageWidth: 200, ImageHeight: 200) - // Barre de recherche + SearchBar(text: $searchText) .padding(.horizontal) - // Liste de joueurs List { ForEach(groupedPlayers.keys.sorted(), id: \.self) { key in Section(header: Text(key)) {