add players pop up is done

pull/10/head
étudiant 11 months ago
parent f11218e90e
commit 0b964c92cf

@ -40,6 +40,7 @@
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 */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -110,6 +111,7 @@
EC62C5052C045C1A0048CD0B /* TitleScreenButtonSound.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = TitleScreenButtonSound.mp3; sourceTree = "<group>"; };
EC62C5082C0467240048CD0B /* SplashScreenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashScreenView.swift; sourceTree = "<group>"; };
EC62C50C2C046D9E0048CD0B /* SplashScreenSound.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = SplashScreenSound.mp3; sourceTree = "<group>"; };
EC62C50E2C05D06A0048CD0B /* AddPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddPlayerView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -230,6 +232,7 @@
children = (
645B4C1F2BFCCA0500FD658A /* PlayerResumeFrame.swift */,
EC62C4FC2C0391D30048CD0B /* PlayerRow.swift */,
EC62C50E2C05D06A0048CD0B /* AddPlayerView.swift */,
);
path = Player;
sourceTree = "<group>";
@ -478,6 +481,7 @@
buildActionMask = 2147483647;
files = (
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 */,

@ -0,0 +1,63 @@
//
// AddPlayerView.swift
// DouShouQi_App
//
// Created by étudiant on 28/05/2024.
//
import SwiftUI
struct AddPlayerView: View {
@Binding var isPresented: Bool
@Binding var players: [Player]
@State private var playerName: String = ""
@State private var showAlert = 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)
HStack {
Button(action: {
if players.contains(where: { $0.name.lowercased() == playerName.lowercased() }) {
showAlert = true
} else {
let newPlayer = Player(name: playerName, wins: 0, losses: 0)
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")))
}
}
}

@ -10,9 +10,13 @@ import SwiftUI
struct PlayerRow: View {
var player: Player
@Binding var players: [Player]
var body: some View {
HStack {
Image(systemName: "custom.person")
.foregroundColor(.black)
VStack(alignment: .leading) {
Text(player.name)
.font(.headline)
@ -27,7 +31,7 @@ struct PlayerRow: View {
.foregroundColor(.black)
}
Button(action: {
// Action pour supprimer le joueur
}) {
Image(systemName: "trash")
.foregroundColor(.red)

@ -26,6 +26,8 @@ struct PlayersView: View {
]
@State private var searchText = ""
@State private var showingPopup = false
@State private var newPlayerName = ""
var filteredPlayers: [Player] {
if searchText.isEmpty {
@ -50,14 +52,14 @@ struct PlayersView: View {
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<String>) {
_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()

Loading…
Cancel
Save