diff --git a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj index 864b865..bec9429 100644 --- a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj +++ b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj @@ -30,6 +30,12 @@ 649B59B22BF65392002BAE38 /* TextStyles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649B59B12BF65392002BAE38 /* TextStyles.swift */; }; 649B59B42BF653E1002BAE38 /* ViewTitleTextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649B59B32BF653E1002BAE38 /* ViewTitleTextStyle.swift */; }; EC62C4EF2BFE367F0048CD0B /* SwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C4EE2BFE367F0048CD0B /* SwiftUIView.swift */; }; + EC62C4F92C0371660048CD0B /* MusicPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C4F82C0371660048CD0B /* MusicPlayer.swift */; }; + EC62C4FB2C038BD20048CD0B /* PlayersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C4FA2C038BD20048CD0B /* PlayersView.swift */; }; + EC62C4FD2C0391D30048CD0B /* PlayerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C4FC2C0391D30048CD0B /* PlayerRow.swift */; }; + EC62C4FF2C0457AD0048CD0B /* TitleScreenMusic.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = EC62C4FE2C0457AD0048CD0B /* TitleScreenMusic.mp3 */; }; + EC62C5012C045B590048CD0B /* SoundPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C5002C045B590048CD0B /* SoundPlayer.swift */; }; + EC62C5062C045C1A0048CD0B /* TitleScreenButtonSound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = EC62C5052C045C1A0048CD0B /* TitleScreenButtonSound.mp3 */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -90,6 +96,12 @@ 649B59B12BF65392002BAE38 /* TextStyles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyles.swift; sourceTree = ""; }; 649B59B32BF653E1002BAE38 /* ViewTitleTextStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewTitleTextStyle.swift; sourceTree = ""; }; EC62C4EE2BFE367F0048CD0B /* SwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIView.swift; sourceTree = ""; }; + EC62C4F82C0371660048CD0B /* MusicPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicPlayer.swift; sourceTree = ""; }; + EC62C4FA2C038BD20048CD0B /* PlayersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayersView.swift; sourceTree = ""; }; + EC62C4FC2C0391D30048CD0B /* PlayerRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerRow.swift; sourceTree = ""; }; + EC62C4FE2C0457AD0048CD0B /* TitleScreenMusic.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = TitleScreenMusic.mp3; sourceTree = ""; }; + EC62C5002C045B590048CD0B /* SoundPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoundPlayer.swift; sourceTree = ""; }; + EC62C5052C045C1A0048CD0B /* TitleScreenButtonSound.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = TitleScreenButtonSound.mp3; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -159,6 +171,7 @@ 6458345A2BF5F92300E18321 /* DouShouQi_App */ = { isa = PBXGroup; children = ( + EC62C5022C045BB90048CD0B /* SoundPlayerClass */, 649B59A52BF64B1B002BAE38 /* Assets */, 649ABF5E2BF60ED5002E8894 /* Components */, 649ABF592BF60D13002E8894 /* Views */, @@ -208,6 +221,7 @@ isa = PBXGroup; children = ( 645B4C1F2BFCCA0500FD658A /* PlayerResumeFrame.swift */, + EC62C4FC2C0391D30048CD0B /* PlayerRow.swift */, ); path = Player; sourceTree = ""; @@ -216,16 +230,25 @@ isa = PBXGroup; children = ( 645B4C242BFCD3C600FD658A /* ScoreBoardView.swift */, + EC62C4FA2C038BD20048CD0B /* PlayersView.swift */, ); path = Player; sourceTree = ""; }; + 6493C1BE2C04650200B5121D /* Menu */ = { + isa = PBXGroup; + children = ( + 649ABF5A2BF60D78002E8894 /* MainMenuView.swift */, + ); + path = Menu; + sourceTree = ""; + }; 649ABF592BF60D13002E8894 /* Views */ = { isa = PBXGroup; children = ( 643AB6992BFCFB480018DA73 /* Game */, 645B4C232BFCD39A00FD658A /* Player */, - 649ABF5A2BF60D78002E8894 /* MainMenuView.swift */, + 6493C1BE2C04650200B5121D /* Menu */, ); path = Views; sourceTree = ""; @@ -244,6 +267,8 @@ 649B59A52BF64B1B002BAE38 /* Assets */ = { isa = PBXGroup; children = ( + EC62C5042C045BE00048CD0B /* Musics */, + EC62C5032C045BD30048CD0B /* Sounds */, 649B59B02BF65360002BAE38 /* TextStyles */, 649B59AF2BF64F0A002BAE38 /* Colors */, 649B59AA2BF64DF1002BAE38 /* Images */, @@ -278,6 +303,31 @@ path = TextStyles; sourceTree = ""; }; + EC62C5022C045BB90048CD0B /* SoundPlayerClass */ = { + isa = PBXGroup; + children = ( + EC62C5002C045B590048CD0B /* SoundPlayer.swift */, + EC62C4F82C0371660048CD0B /* MusicPlayer.swift */, + ); + path = SoundPlayerClass; + sourceTree = ""; + }; + EC62C5032C045BD30048CD0B /* Sounds */ = { + isa = PBXGroup; + children = ( + EC62C5052C045C1A0048CD0B /* TitleScreenButtonSound.mp3 */, + ); + path = Sounds; + sourceTree = ""; + }; + EC62C5042C045BE00048CD0B /* Musics */ = { + isa = PBXGroup; + children = ( + EC62C4FE2C0457AD0048CD0B /* TitleScreenMusic.mp3 */, + ); + path = Musics; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -384,9 +434,11 @@ buildActionMask = 2147483647; files = ( 649B59A72BF64BA9002BAE38 /* Colors.xcassets in Resources */, + EC62C5062C045C1A0048CD0B /* TitleScreenButtonSound.mp3 in Resources */, 649B59AC2BF64E12002BAE38 /* Images.xcassets in Resources */, 645834632BF5F92500E18321 /* Preview Assets.xcassets in Resources */, 645834602BF5F92500E18321 /* Assets.xcassets in Resources */, + EC62C4FF2C0457AD0048CD0B /* TitleScreenMusic.mp3 in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -415,12 +467,16 @@ 6458345E2BF5F92300E18321 /* ContentView.swift in Sources */, 649B59A92BF64C6A002BAE38 /* Colors.swift in Sources */, 649B59B42BF653E1002BAE38 /* ViewTitleTextStyle.swift in Sources */, + EC62C5012C045B590048CD0B /* SoundPlayer.swift in Sources */, 645B4C252BFCD3C600FD658A /* ScoreBoardView.swift in Sources */, 649B59AE2BF64EAB002BAE38 /* AppImages.swift in Sources */, 649ABF602BF60F2D002E8894 /* MainMenuButton.swift in Sources */, 643AB6932BFCEFD00018DA73 /* GameResumeFrame.swift in Sources */, EC62C4EF2BFE367F0048CD0B /* SwiftUIView.swift in Sources */, 649B59B22BF65392002BAE38 /* TextStyles.swift in Sources */, + EC62C4F92C0371660048CD0B /* MusicPlayer.swift in Sources */, + EC62C4FD2C0391D30048CD0B /* PlayerRow.swift in Sources */, + EC62C4FB2C038BD20048CD0B /* PlayersView.swift in Sources */, 6458345C2BF5F92300E18321 /* DouShouQi_AppApp.swift in Sources */, 645B4C202BFCCA0500FD658A /* PlayerResumeFrame.swift in Sources */, 649ABF5B2BF60D78002E8894 /* MainMenuView.swift in Sources */, diff --git a/DouShouQi_App/DouShouQi_App/Assets/Colors/Colors.swift b/DouShouQi_App/DouShouQi_App/Assets/Colors/Colors.swift index 5bcf4a8..bc9baf0 100644 --- a/DouShouQi_App/DouShouQi_App/Assets/Colors/Colors.swift +++ b/DouShouQi_App/DouShouQi_App/Assets/Colors/Colors.swift @@ -11,4 +11,5 @@ import SwiftUI public struct Colors { static let TitleText = Color("TitleTextColor") static let Button = Color("ButtonColor") + static let TextButton = Color("ButtonTextColor") } diff --git a/DouShouQi_App/DouShouQi_App/Assets/Musique.xcassets/ScreenTitleMusique.dataset/ytmp3free.cc_1-a-o-t-2-main-theme-attack-on-titan-2-soundtrack-youtubemp3free.org.mp3 b/DouShouQi_App/DouShouQi_App/Assets/Musics/TitleScreenMusic.mp3 similarity index 100% rename from DouShouQi_App/DouShouQi_App/Assets/Musique.xcassets/ScreenTitleMusique.dataset/ytmp3free.cc_1-a-o-t-2-main-theme-attack-on-titan-2-soundtrack-youtubemp3free.org.mp3 rename to DouShouQi_App/DouShouQi_App/Assets/Musics/TitleScreenMusic.mp3 diff --git a/DouShouQi_App/DouShouQi_App/Assets/AppMusic.swift b/DouShouQi_App/DouShouQi_App/Assets/Musique/AppMusic.swift similarity index 50% rename from DouShouQi_App/DouShouQi_App/Assets/AppMusic.swift rename to DouShouQi_App/DouShouQi_App/Assets/Musique/AppMusic.swift index f328ccf..0357b84 100644 --- a/DouShouQi_App/DouShouQi_App/Assets/AppMusic.swift +++ b/DouShouQi_App/DouShouQi_App/Assets/Musique/AppMusic.swift @@ -6,3 +6,9 @@ // import Foundation +import SwiftUI + +public struct AppMusic { + static let ScreenTitleMusic = "ScreenTitleMusique" + +} diff --git a/DouShouQi_App/DouShouQi_App/Assets/Musique.xcassets/Contents.json b/DouShouQi_App/DouShouQi_App/Assets/Musique/Musique.xcassets/Contents.json similarity index 100% rename from DouShouQi_App/DouShouQi_App/Assets/Musique.xcassets/Contents.json rename to DouShouQi_App/DouShouQi_App/Assets/Musique/Musique.xcassets/Contents.json diff --git a/DouShouQi_App/DouShouQi_App/Assets/Musique.xcassets/ScreenTitleMusique.dataset/Contents.json b/DouShouQi_App/DouShouQi_App/Assets/Musique/Musique.xcassets/ScreenTitleMusique.dataset/Contents.json similarity index 100% rename from DouShouQi_App/DouShouQi_App/Assets/Musique.xcassets/ScreenTitleMusique.dataset/Contents.json rename to DouShouQi_App/DouShouQi_App/Assets/Musique/Musique.xcassets/ScreenTitleMusique.dataset/Contents.json diff --git a/DouShouQi_App/DouShouQi_App/Assets/Musique/Musique.xcassets/ScreenTitleMusique.dataset/ytmp3free.cc_1-a-o-t-2-main-theme-attack-on-titan-2-soundtrack-youtubemp3free.org.mp3 b/DouShouQi_App/DouShouQi_App/Assets/Musique/Musique.xcassets/ScreenTitleMusique.dataset/ytmp3free.cc_1-a-o-t-2-main-theme-attack-on-titan-2-soundtrack-youtubemp3free.org.mp3 new file mode 100644 index 0000000..3d9329c Binary files /dev/null and b/DouShouQi_App/DouShouQi_App/Assets/Musique/Musique.xcassets/ScreenTitleMusique.dataset/ytmp3free.cc_1-a-o-t-2-main-theme-attack-on-titan-2-soundtrack-youtubemp3free.org.mp3 differ diff --git a/DouShouQi_App/DouShouQi_App/Assets/Sounds/TitleScreenButtonSound.mp3 b/DouShouQi_App/DouShouQi_App/Assets/Sounds/TitleScreenButtonSound.mp3 new file mode 100644 index 0000000..91ec965 Binary files /dev/null and b/DouShouQi_App/DouShouQi_App/Assets/Sounds/TitleScreenButtonSound.mp3 differ diff --git a/DouShouQi_App/DouShouQi_App/Assets/TitleScreenMusic.mp3 b/DouShouQi_App/DouShouQi_App/Assets/TitleScreenMusic.mp3 new file mode 100644 index 0000000..3d9329c Binary files /dev/null and b/DouShouQi_App/DouShouQi_App/Assets/TitleScreenMusic.mp3 differ diff --git a/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift b/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift index 9393578..b421b74 100644 --- a/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift +++ b/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift @@ -7,11 +7,13 @@ import SwiftUI -struct MainMenuButton: View { +struct MainMenuButton: View { // Text Params var text: String - @State private var isHovered: Bool = false + var destination: Destination + var sound: String + // Button Alignment var horizontalAlignment: Alignment = .center @@ -23,9 +25,7 @@ struct MainMenuButton: View { var bottomRightCorner: CGFloat = 0 var body: some View { - Button(action: { - // Action du bouton - }, label: { + NavigationLink(destination: destination) { Text(text.uppercased()) .font(.headline) .fontWeight(.semibold) @@ -33,18 +33,16 @@ struct MainMenuButton: View { .padding() .frame(maxWidth: .infinity, maxHeight: 40) .background( - Colors.Button + Color.red .clipShape(RoundedRectangle(cornerSize: CGSize(width: 0, height: 0))) .mask(RoundedCornersShape(cornerRadii: (topLeft: topLeftCorner, topRight: topRightCorner, bottomLeft: bottomLeftCorner, bottomRight: bottomRightCorner))) ) + } + .simultaneousGesture(TapGesture().onEnded { + playSound(named: sound) }) .frame(width: UIScreen.main.bounds.width / 1.7) .frame(maxWidth: .infinity, alignment: horizontalAlignment) - .scaleEffect(isHovered ? 1.1 : 1.0) - .animation(.easeInOut(duration: 0.2), value: isHovered) - .onHover { hovering in - self.isHovered = hovering - } } } @@ -94,6 +92,6 @@ struct RoundedCornersShape: Shape { struct MainMenuButton_Previews: PreviewProvider { static var previews: some View { - MainMenuButton(text: "test", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "test", destination: HistoricView(), sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) } } diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift b/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift new file mode 100644 index 0000000..fff7900 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift @@ -0,0 +1,43 @@ +// +// PlayerRow.swift +// DouShouQi_App +// +// Created by étudiant on 26/05/2024. +// + +import Foundation +import SwiftUI + +struct PlayerRow: View { + var player: Player + + var body: some View { + HStack { + VStack(alignment: .leading) { + Text(player.name) + .font(.headline) + Text("Victoires : \(player.wins) Défaites : \(player.losses)") + .font(.subheadline) + } + Spacer() + Button(action: { + // Action pour éditer le joueur + }) { + Image(systemName: "pencil") + .foregroundColor(.red) + } + Button(action: { + // Action pour supprimer le joueur + }) { + Image(systemName: "trash") + .foregroundColor(.red) + } + } + .padding() + .background(Color.white) + .cornerRadius(10) + .shadow(radius: 1) + } +} + + diff --git a/DouShouQi_App/DouShouQi_App/DouShouQi_AppApp.swift b/DouShouQi_App/DouShouQi_App/DouShouQi_AppApp.swift index c341ba1..07aed7a 100644 --- a/DouShouQi_App/DouShouQi_App/DouShouQi_AppApp.swift +++ b/DouShouQi_App/DouShouQi_App/DouShouQi_AppApp.swift @@ -11,7 +11,7 @@ import SwiftUI struct DouShouQi_AppApp: App { var body: some Scene { WindowGroup { - ContentView() + MainMenuView() } } } diff --git a/DouShouQi_App/DouShouQi_App/MusicPlayer.swift b/DouShouQi_App/DouShouQi_App/MusicPlayer.swift deleted file mode 100644 index eba2b45..0000000 --- a/DouShouQi_App/DouShouQi_App/MusicPlayer.swift +++ /dev/null @@ -1,8 +0,0 @@ -// -// MusicPlayer.swift -// DouShouQi_App -// -// Created by étudiant on 26/05/2024. -// - -import Foundation diff --git a/DouShouQi_App/DouShouQi_App/SoundPlayerClass/MusicPlayer.swift b/DouShouQi_App/DouShouQi_App/SoundPlayerClass/MusicPlayer.swift new file mode 100644 index 0000000..d4faadc --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/SoundPlayerClass/MusicPlayer.swift @@ -0,0 +1,34 @@ +// +// MusicPlayer.swift +// DouShouQi_App +// +// Created by étudiant on 26/05/2024. +// + +import Foundation +import AVFoundation + +class MusicPlayer { + static let shared = MusicPlayer() + var audioPlayer: AVAudioPlayer? + + func playBackgroundMusic(music: String) { + if let bundle = Bundle.main.path(forResource: music, ofType: "mp3") { + let backgroundMusic = NSURL(fileURLWithPath: bundle) + do { + audioPlayer = try AVAudioPlayer(contentsOf: backgroundMusic as URL) + guard let audioPlayer = audioPlayer else { return } + audioPlayer.numberOfLoops = -1 // Loop indefinitely + audioPlayer.prepareToPlay() + audioPlayer.play() + } catch { + print(error) + } + } + } + + func stopBackgroundMusic() { + audioPlayer?.stop() + } +} + diff --git a/DouShouQi_App/DouShouQi_App/SoundPlayerClass/SoundPlayer.swift b/DouShouQi_App/DouShouQi_App/SoundPlayerClass/SoundPlayer.swift new file mode 100644 index 0000000..2378b8a --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/SoundPlayerClass/SoundPlayer.swift @@ -0,0 +1,22 @@ +// +// SoundPlayer.swift +// DouShouQi_App +// +// Created by étudiant on 27/05/2024. +// + +import Foundation +import AVFoundation + +var audioPlayer: AVAudioPlayer? + +func playSound(named soundName: String) { + guard let url = Bundle.main.url(forResource: soundName, withExtension: "mp3") else { return } + + do { + audioPlayer = try AVAudioPlayer(contentsOf: url) + audioPlayer?.play() + } catch let error { + print("Error playing sound. \(error.localizedDescription)") + } +} diff --git a/DouShouQi_App/DouShouQi_App/Views/MainMenuView.swift b/DouShouQi_App/DouShouQi_App/Views/MainMenuView.swift deleted file mode 100644 index 6b44b3f..0000000 --- a/DouShouQi_App/DouShouQi_App/Views/MainMenuView.swift +++ /dev/null @@ -1,60 +0,0 @@ -// -// MainMenuView.swift -// DouShouQi_App -// -// Created by Rémi REGNAULT on 16/05/2024. -// - -import SwiftUI - -struct MainMenuView: View { - var body: some View { - VStack { - TitlePageFrame(Text: "DOU SHOU QI", ImageWidth: 200, ImageHeight: 200) - Spacer() - - VStack { - HStack{ - VStack(spacing: 25) { - MainMenuButton(text: "Play", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) - MainMenuButton(text: "Historique", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) - MainMenuButton(text: "Best Scores", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) - MainMenuButton(text: "Players", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) - } - Image(AppImages.SemiLion) - .resizable() - .aspectRatio(contentMode: .fit) - .frame(width: 200, height: 500) - } - - } - Spacer() - HStack { - Text("Copyright @") - .font(.headline) - .frame(alignment: .trailing) - - Text("Dou Shou Qi Team") - - Spacer() - - Text("2024") - .frame(alignment: .trailing) - } - .padding() // Ajout de padding pour éviter que le contenu ne touche la bordure - .background(Color.white) // Couleur de fond pour le HStack - .overlay( - Rectangle() - .stroke(Color.black, lineWidth: 1) // Couleur et épaisseur de la bordure - ) - - Spacer() - } - } -} - -struct MainMenuView_Previews: PreviewProvider { - static var previews: some View { - MainMenuView() - } -} diff --git a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift new file mode 100644 index 0000000..d192947 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift @@ -0,0 +1,71 @@ +// +// MainMenuView.swift +// DouShouQi_App +// +// Created by Rémi REGNAULT on 16/05/2024. +// + +import SwiftUI + +struct MainMenuView: View { + var body: some View { + NavigationView { + VStack { + + TitlePageFrame(Text: "DOU SHOU QI", ImageWidth: 200, ImageHeight: 200) + + Spacer() + + VStack { + HStack{ + VStack(spacing: 25) { + MainMenuButton(text: "Play", destination: ScoreBoardView(), sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Historique", destination: HistoricView(), sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Best Scores", destination: ScoreBoardView(), sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Players", destination: PlayersView(), sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) + } + Image(AppImages.SemiLion) + .resizable() + .aspectRatio(contentMode: .fit) + .frame(width: 200, height: 500) + } + + } + Spacer() + HStack { + Text("Copyright @") + .font(.headline) + .frame(alignment: .trailing) + + Text("Dou Shou Qi Team") + + Spacer() + + Text("2024") + .frame(alignment: .trailing) + } + .padding() // Ajout de padding pour éviter que le contenu ne touche la bordure + .background(Color.white) // Couleur de fond pour le HStack + .overlay( + Rectangle() + .stroke(Color.black, lineWidth: 1) // Couleur et épaisseur de la bordure + ) + + Spacer() + .onAppear { + MusicPlayer.shared.playBackgroundMusic(music: "TitleScreenMusic") + } + .onDisappear { + MusicPlayer.shared.stopBackgroundMusic() + } + + } + } + } +} + +struct MainMenuView_Previews: PreviewProvider { + static var previews: some View { + MainMenuView() + } +} diff --git a/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift b/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift new file mode 100644 index 0000000..8f27145 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift @@ -0,0 +1,119 @@ +// +// PlayersView.swift +// DouShouQi_App +// +// Created by étudiant on 26/05/2024. +// + +import Foundation +import SwiftUI + +// Modèle de données pour un joueur +struct Player: Identifiable { + var id = UUID() + var name: String + var wins: Int + var losses: Int +} + +// 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) + ] + + @State private var searchText = "" + + var filteredPlayers: [Player] { + if searchText.isEmpty { + return players + } else { + return players.filter { $0.name.lowercased().contains(searchText.lowercased()) } + } + } + + 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) + } + } + } + } + + Button(action: { + + }) { + Text("Add a player") + .font(.headline) + .foregroundColor(.white) + .padding() + .frame(maxWidth: .infinity) + .background(Color.red) + .cornerRadius(10) + .padding(.horizontal) + } + .padding(.bottom) + } + } + } + + var groupedPlayers: [String: [Player]] { + Dictionary(grouping: filteredPlayers) { player in + String(player.name.prefix(1)).uppercased() + } + } +} + + +// 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() + } +}