Mercurial > public > geoquiz
comparison GeoQuiz/SettingsModalView.swift @ 14:136928bae534
add user profile
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Wed, 19 Oct 2022 07:56:33 +0200 |
parents | a793f33f05fb |
children | f140bb277c96 |
comparison
equal
deleted
inserted
replaced
13:bdfff35dd43c | 14:136928bae534 |
---|---|
6 // | 6 // |
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct SettingsModalView: View { | 10 struct SettingsModalView: View { |
11 @ObservedObject var user: User | |
11 @Environment(\.dismiss) var dismiss | 12 @Environment(\.dismiss) var dismiss |
12 @StateObject var user = User() | |
13 | 13 |
14 var lives: [Int] { | 14 var lives: [Int] { |
15 var lives = [Int]() | 15 var lives = [Int]() |
16 for i in stride(from: 5, to: 55, by: 5) { | 16 for i in stride(from: 5, to: 55, by: 5) { |
17 lives.append(i) | 17 lives.append(i) |
22 | 22 |
23 var body: some View { | 23 var body: some View { |
24 NavigationView { | 24 NavigationView { |
25 Form { | 25 Form { |
26 Section { | 26 Section { |
27 Picker("❤️ Lives", selection: $user.settings.numberOfLives) { | 27 Picker("❤️ Lives", selection: $user.data.numberOfLives) { |
28 ForEach(lives, id: \.self) { numberOfLives in | 28 ForEach(lives, id: \.self) { numberOfLives in |
29 Text("\(numberOfLives)") | 29 Text("\(numberOfLives)") |
30 .tag(numberOfLives) | 30 .tag(numberOfLives) |
31 } | 31 } |
32 } | 32 } |
35 } footer: { | 35 } footer: { |
36 Text("Number of lives at the beginning of each game.") | 36 Text("Number of lives at the beginning of each game.") |
37 } | 37 } |
38 | 38 |
39 Section { | 39 Section { |
40 Toggle("Haptics", isOn: $user.settings.haptics) | 40 Toggle("Haptics", isOn: $user.data.haptics) |
41 Toggle("Sound effects", isOn: $user.settings.sound) | 41 Toggle("Sound effects", isOn: $user.data.sound) |
42 } header: { | 42 } header: { |
43 Text("Effects") | 43 Text("Effects") |
44 } | 44 } |
45 | 45 |
46 Section { | 46 Section { |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 struct SettingsModalView_Previews: PreviewProvider { | 85 struct SettingsModalView_Previews: PreviewProvider { |
86 static var previews: some View { | 86 static var previews: some View { |
87 SettingsModalView() | 87 SettingsModalView(user: User()) |
88 } | 88 } |
89 } | 89 } |