100 lines
3.9 KiB
Swift
100 lines
3.9 KiB
Swift
import SwiftUI
|
||
|
||
struct SettingsView: View {
|
||
@ObservedObject var controller: GameController
|
||
@State private var showDeleteAccountAlert = false
|
||
@State private var deleteConfirmationUsername = ""
|
||
|
||
var body: some View {
|
||
ScrollView {
|
||
VStack(alignment: .leading, spacing: 20) {
|
||
HStack {
|
||
Text("New Game")
|
||
.font(.system(.largeTitle, design: .rounded).weight(.bold))
|
||
Spacer()
|
||
Button("Log out") { controller.logout() }
|
||
.font(.footnote)
|
||
}
|
||
|
||
Text("Signed in as \(controller.username)")
|
||
.font(.subheadline)
|
||
.foregroundStyle(.secondary)
|
||
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
Text("Eliminate at").font(.headline)
|
||
Stepper(value: $controller.draftPointsToEnd, in: 10...500, step: 10) {
|
||
Text("\(controller.draftPointsToEnd) points")
|
||
.font(.title3.monospacedDigit())
|
||
}
|
||
}
|
||
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
Text("Players to start").font(.headline)
|
||
Stepper(value: $controller.draftPlayersToStart, in: 1...12) {
|
||
Text("\(controller.draftPlayersToStart)")
|
||
.font(.title3.monospacedDigit())
|
||
}
|
||
}
|
||
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
Text("Bots").font(.headline)
|
||
Stepper(value: $controller.draftBots, in: 0...10) {
|
||
Text("\(controller.draftBots)")
|
||
.font(.title3.monospacedDigit())
|
||
}
|
||
}
|
||
|
||
VStack(alignment: .leading, spacing: 8) {
|
||
Text("Decks").font(.headline)
|
||
Stepper(value: $controller.draftDecks, in: 1...20) {
|
||
Text("\(controller.draftDecks)")
|
||
.font(.title3.monospacedDigit())
|
||
}
|
||
Text("Last flip scores ×2.")
|
||
.font(.footnote)
|
||
.foregroundStyle(.secondary)
|
||
}
|
||
|
||
if let error = controller.errorMessage {
|
||
Text(error)
|
||
.font(.footnote)
|
||
.foregroundStyle(.red)
|
||
}
|
||
|
||
Button { controller.startGame() } label: {
|
||
Text(controller.isBusy ? "Creating…" : "Start Game")
|
||
.font(.headline)
|
||
.frame(maxWidth: .infinity)
|
||
.padding(.vertical, 12)
|
||
}
|
||
.buttonStyle(.borderedProminent)
|
||
.disabled(controller.isBusy)
|
||
|
||
Button {
|
||
deleteConfirmationUsername = ""
|
||
showDeleteAccountAlert = true
|
||
} label: {
|
||
Text("Delete Account")
|
||
.font(.headline)
|
||
.frame(maxWidth: .infinity)
|
||
.padding(.vertical, 12)
|
||
}
|
||
.buttonStyle(.bordered)
|
||
.tint(.red)
|
||
.disabled(controller.isBusy)
|
||
}
|
||
.padding(20)
|
||
}
|
||
.alert("Delete Account", isPresented: $showDeleteAccountAlert) {
|
||
TextField("Username", text: $deleteConfirmationUsername)
|
||
.textInputAutocapitalization(.never)
|
||
.autocorrectionDisabled()
|
||
Button("Delete", role: .destructive) {
|
||
controller.deleteAccount(confirmation: deleteConfirmationUsername)
|
||
}
|
||
Button("Cancel", role: .cancel) {}
|
||
} message: {
|
||
Text("This permanently deletes your account. Type \"\(controller.username)\" to confirm.")
|
||
}
|
||
}
|
||
}
|