parent
f11218e90e
commit
0b964c92cf
@ -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")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue