diff --git a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj index 4340ad1..0a2a314 100644 --- a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj +++ b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj @@ -42,6 +42,8 @@ EC62C5062C045C1A0048CD0B /* TitleScreenButtonSound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = EC62C5052C045C1A0048CD0B /* TitleScreenButtonSound.mp3 */; }; 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 */; }; + EC62C5172C0620C00048CD0B /* rap.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = EC62C5162C0620C00048CD0B /* rap.mp3 */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -114,6 +116,8 @@ EC62C5052C045C1A0048CD0B /* TitleScreenButtonSound.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = TitleScreenButtonSound.mp3; sourceTree = ""; }; 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 = ""; }; + EC62C5162C0620C00048CD0B /* rap.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = rap.mp3; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -233,6 +237,7 @@ children = ( 645B4C1F2BFCCA0500FD658A /* PlayerResumeFrame.swift */, EC62C4FC2C0391D30048CD0B /* PlayerRow.swift */, + EC62C50E2C05D06A0048CD0B /* AddPlayerView.swift */, ); path = Player; sourceTree = ""; @@ -349,6 +354,7 @@ EC62C5042C045BE00048CD0B /* Musics */ = { isa = PBXGroup; children = ( + EC62C5162C0620C00048CD0B /* rap.mp3 */, EC62C4FE2C0457AD0048CD0B /* TitleScreenMusic.mp3 */, ); path = Musics; @@ -462,6 +468,7 @@ 649B59A72BF64BA9002BAE38 /* Colors.xcassets 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 */, @@ -493,6 +500,7 @@ files = ( EC05BFC42C04C3C4000F7B19 /* SettingsView.swift in Sources */, 643AB69B2BFCFB5C0018DA73 /* HistoricView.swift in Sources */, + EC62C50F2C05D06A0048CD0B /* AddPlayerView.swift in Sources */, 6458345E2BF5F92300E18321 /* ContentView.swift in Sources */, 649B59A92BF64C6A002BAE38 /* Colors.swift in Sources */, 649B59B42BF653E1002BAE38 /* ViewTitleTextStyle.swift in Sources */, 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/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 new file mode 100644 index 0000000..49680b1 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Components/Player/AddPlayerView.swift @@ -0,0 +1,150 @@ +// +// AddPlayerView.swift +// DouShouQi_App +// +// Created by étudiant on 28/05/2024. +// + +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) { + Text("Add New Player") + .font(.headline) + + TextField("Player Name", text: $playerName) + .padding() + .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 { + 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 + } + }) { + Text("Add") + .foregroundColor(.white) + .padding() + .background(Color.blue) + .cornerRadius(10) + } + + Button(action: { + isPresented = false + }) { + Text("Cancel") + .foregroundColor(.white) + .padding() + .background(Color.red) + .cornerRadius(10) + } + } + } + .padding() + .frame(maxWidth: 300) + .background(Color.white) + .cornerRadius(20) + .shadow(radius: 10) + .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 fff7900..b8acb4e 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift @@ -10,9 +10,23 @@ import SwiftUI struct PlayerRow: View { var player: Player + @Binding var players: [Player] var body: some View { HStack { + 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) .font(.headline) @@ -24,10 +38,10 @@ struct PlayerRow: View { // Action pour éditer le joueur }) { Image(systemName: "pencil") - .foregroundColor(.red) + .foregroundColor(.black) } Button(action: { - // Action pour supprimer le joueur + }) { Image(systemName: "trash") .foregroundColor(.red) 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/Menu/MainMenuView.swift b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift index e99136c..57d1be8 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift @@ -32,11 +32,11 @@ struct MainMenuView: View { VStack { HStack { VStack(spacing: 25) { - MainMenuButton(text: "Play", destination: ScoreBoardView(), sound: "TitleScreenButtonSound") - MainMenuButton(text: "Historique", destination: HistoricView(), sound: "TitleScreenButtonSound") - MainMenuButton(text: "Best Scores", destination: ScoreBoardView(), sound: "TitleScreenButtonSound") - MainMenuButton(text: "Players", destination: PlayersView(), sound: "TitleScreenButtonSound") - MainMenuButton(text: "Settings", destination: SettingsView(), sound: "TitleScreenButtonSound") + MainMenuButton(text: "Play", destination: ScoreBoardView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Historique", destination: HistoricView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Best Scores", destination: ScoreBoardView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Players", destination: PlayersView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Settings", destination: SettingsView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) } Image(AppImages.SemiLion) .resizable() diff --git a/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift b/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift index 8f27145..3ae9046 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift @@ -14,18 +14,21 @@ 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 = "" + @State private var showingPopup = false + @State private var newPlayerName = "" var filteredPlayers: [Player] { if searchText.isEmpty { @@ -38,26 +41,25 @@ 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)) { ForEach(groupedPlayers[key]!) { player in - PlayerRow(player: player) + PlayerRow(player: player, players: $players) } } } } - + Button(action: { - + showingPopup = true }) { Text("Add a player") .font(.headline) @@ -69,6 +71,9 @@ struct PlayersView: View { .padding(.horizontal) } .padding(.bottom) + .sheet(isPresented: $showingPopup) { + AddPlayerView(isPresented: $showingPopup, players: $players) + } } } } @@ -80,38 +85,38 @@ struct PlayersView: View { } } - // Vue pour la barre de recherche struct SearchBar: UIViewRepresentable { @Binding var text: String - + class Coordinator: NSObject, UISearchBarDelegate { @Binding var text: String - + init(text: Binding) { _text = text } - + func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { text = searchText } } - + func makeCoordinator() -> Coordinator { return Coordinator(text: $text) } - + func makeUIView(context: Context) -> UISearchBar { let searchBar = UISearchBar(frame: .zero) searchBar.delegate = context.coordinator return searchBar } - + func updateUIView(_ uiView: UISearchBar, context: Context) { uiView.text = text } } + struct PlayersPageView_Previews: PreviewProvider { static var previews: some View { PlayersView()