From 3c42f5c42a022da37adc536701c2d86d1492125b Mon Sep 17 00:00:00 2001 From: Rayhan Date: Fri, 31 May 2024 11:57:49 +0200 Subject: [PATCH] add stat for players --- .../DouShouQi_App.xcodeproj/project.pbxproj | 4 ++ .../Components/Player/PlayerRow.swift | 18 +++--- .../Components/Player/PlayerStatView.swift | 61 +++++++++++++++++++ 3 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 DouShouQi_App/DouShouQi_App/Components/Player/PlayerStatView.swift diff --git a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj index 33acf23..f0f7764 100644 --- a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj +++ b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj @@ -45,6 +45,7 @@ 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 */; }; + EC62C51B2C09D1790048CD0B /* PlayerStatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C51A2C09D1790048CD0B /* PlayerStatView.swift */; }; ECB636552C047992007CD5E2 /* Image.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ECB636542C047992007CD5E2 /* Image.xcassets */; }; /* End PBXBuildFile section */ @@ -108,6 +109,7 @@ 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 = ""; }; + EC62C51A2C09D1790048CD0B /* PlayerStatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerStatView.swift; sourceTree = ""; }; ECB636542C047992007CD5E2 /* Image.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Image.xcassets; sourceTree = ""; }; /* End PBXFileReference section */ @@ -231,6 +233,7 @@ 647D565B2BFD0212008D02EA /* PlayerResumeFrame.swift */, EC62C4FC2C0391D30048CD0B /* PlayerRow.swift */, EC62C50E2C05D06A0048CD0B /* AddPlayerView.swift */, + EC62C51A2C09D1790048CD0B /* PlayerStatView.swift */, ); path = Player; sourceTree = ""; @@ -504,6 +507,7 @@ 645B4C252BFCD3C600FD658A /* ScoreBoardView.swift in Sources */, 649B59AE2BF64EAB002BAE38 /* AppImages.swift in Sources */, 649ABF602BF60F2D002E8894 /* MainMenuButton.swift in Sources */, + EC62C51B2C09D1790048CD0B /* PlayerStatView.swift in Sources */, 643AB6932BFCEFD00018DA73 /* GameResumeFrame.swift in Sources */, 649B59B22BF65392002BAE38 /* TextStyles.swift in Sources */, EC62C5092C0467240048CD0B /* SplashScreenView.swift in Sources */, diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift b/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift index 9f5d053..d93ed30 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/PlayerRow.swift @@ -12,6 +12,8 @@ struct PlayerRow: View { var player: Player @Binding var players: [Player] + @State private var showDetailView = false + var body: some View { HStack { if let image = UIImage(contentsOfFile: player.photo) { @@ -35,17 +37,13 @@ struct PlayerRow: View { } Spacer() Button(action: { - // Action pour éditer le joueur + showDetailView.toggle() }) { - Image(systemName: "pencil") - .foregroundColor(.black) + Image(systemName: "info.circle") + .foregroundColor(.blue) } - Button(action: { - - - }) { - Image(systemName: "trash") - .foregroundColor(.red) + .sheet(isPresented: $showDetailView) { + PlayerStatView(player: player) } } .padding() @@ -54,5 +52,3 @@ struct PlayerRow: View { .shadow(radius: 1) } } - - diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/PlayerStatView.swift b/DouShouQi_App/DouShouQi_App/Components/Player/PlayerStatView.swift new file mode 100644 index 0000000..c223c26 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Components/Player/PlayerStatView.swift @@ -0,0 +1,61 @@ +// +// PlayerStatView.swift +// DouShouQi_App +// +// Created by étudiant on 31/05/2024. +// + +import SwiftUI + +struct PlayerStatView: View { + var player: Player + + var body: some View { + VStack { + if let image = UIImage(contentsOfFile: player.photo) { + Image(uiImage: image) + .resizable() + .frame(width: 100, height: 100) + .clipShape(Circle()) + .padding(.top, 10) + } else { + Image(systemName: "person.circle.fill") + .resizable() + .frame(width: 100, height: 100) + .clipShape(Circle()) + .foregroundColor(.gray) + .padding(.top, 10) + } + + Text(player.name) + .font(.largeTitle) + .foregroundColor(.black) + .padding(.top, 10) + + VStack(alignment: .leading, spacing: 10) { + HStack { + Image(systemName: "trophy.fill") + Text("Win : \(player.wins)") + .font(.title2) + } + HStack { + Image(systemName: "xmark.circle.fill") + Text("Loose : \(player.losses)") + .font(.title2) + } + HStack { + Image(systemName: "chart.line.uptrend.xyaxis") + Text("Win Rate : \(String(format: "%.2f", Double(player.wins) / Double(player.wins + player.losses) * 100))%") + .font(.title2) + } + HStack { + Image(systemName: "list.number") + Text("Rank : 3") + .font(.title2) + } + } + .padding() + Spacer() + } + } +}