Mercurial > public > geoquiz
comparison GeoQuiz/ContentView.swift @ 14:136928bae534
add user profile
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Wed, 19 Oct 2022 07:56:33 +0200 |
parents | bdfff35dd43c |
children | 1011e56b7832 |
comparison
equal
deleted
inserted
replaced
13:bdfff35dd43c | 14:136928bae534 |
---|---|
6 // | 6 // |
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct ContentView: View { | 10 struct ContentView: View { |
11 @State private var gameModeSelection: GameMode? = nil | 11 @State private var path: [GameType] = [] |
12 | 12 |
13 @State private var showingBuyPremiumModalView = false | 13 @State private var showingBuyPremiumModalView = false |
14 @State private var showingSettingsModalView = false | 14 @State private var showingSettingsModalView = false |
15 @State private var showingProfileModalView = false | 15 @State private var showingProfileModalView = false |
16 | 16 |
17 @StateObject var storeKitRC = StoreKitRC() | 17 @StateObject var storeKitRC = StoreKitRC() |
18 @StateObject var user = User() | |
18 | 19 |
19 var body: some View { | 20 var body: some View { |
20 NavigationView { | 21 NavigationStack(path: $path) { |
21 VStack { | 22 ScrollView(showsIndicators: false) { |
22 NavigationLink( | 23 |
23 destination: GuessTheFlagView(), | 24 NavigationLink(value: GameType.guessTheFlag) { EmptyView() } |
24 tag: GameMode.guessTheFlag, | 25 NavigationLink(value: GameType.guessTheCapital) { EmptyView() } |
25 selection: $gameModeSelection) | 26 NavigationLink(value: GameType.guessTheCountry) { EmptyView() } |
26 { | 27 NavigationLink(value: GameType.guessThePopulation) { EmptyView() } |
27 EmptyView() | 28 |
29 VStack(alignment: .leading, spacing: 30) { | |
30 Text("Select a game 🎮") | |
31 .font(.largeTitle.bold()) | |
32 .padding(.bottom) | |
33 | |
34 Button { | |
35 path.append(.guessTheFlag) | |
36 } label: { | |
37 GameButton( | |
38 gradient: .main, | |
39 level: "Level 1", | |
40 symbol: "flag.fill", | |
41 name: "Guess the flag" | |
42 ) | |
43 } | |
44 | |
45 Button { | |
46 if storeKitRC.isActive { | |
47 path.append(.guessTheCapital) | |
48 } else { | |
49 showingBuyPremiumModalView = true | |
50 } | |
51 } label: { | |
52 GameButton( | |
53 gradient: .secondary, | |
54 level: "Level 2", | |
55 symbol: storeKitRC.isActive ? "building.2.fill": "lock.fill", | |
56 name: "Guess the capital" | |
57 ) | |
58 } | |
59 | |
60 Button { | |
61 if storeKitRC.isActive { | |
62 path.append(.guessTheCountry) | |
63 } else { | |
64 showingBuyPremiumModalView = true | |
65 } | |
66 } label: { | |
67 GameButton( | |
68 gradient: .tertiary, | |
69 level: "Level 3", | |
70 symbol: storeKitRC.isActive ? "globe.americas.fill": "lock.fill", | |
71 name: "Guess the country" | |
72 ) | |
73 } | |
74 | |
75 Button { | |
76 if storeKitRC.isActive { | |
77 path.append(.guessThePopulation) | |
78 } else { | |
79 showingBuyPremiumModalView = true | |
80 } | |
81 } label: { | |
82 GameButton( | |
83 gradient: .quaternary, | |
84 level: "Level 4", | |
85 symbol: storeKitRC.isActive ? "person.fill": "lock.fill", | |
86 name: "Guess the population" | |
87 ) | |
88 } | |
89 | |
28 } | 90 } |
29 | 91 .padding() |
30 NavigationLink( | |
31 destination: GuessTheCapitalView(), | |
32 tag: GameMode.guessTheCapital, | |
33 selection: $gameModeSelection) | |
34 { | |
35 EmptyView() | |
36 } | |
37 | |
38 NavigationLink( | |
39 destination: GuessTheCountryView(), | |
40 tag: GameMode.guessTheCountry, | |
41 selection: $gameModeSelection) | |
42 { | |
43 EmptyView() | |
44 } | |
45 | |
46 NavigationLink( | |
47 destination: GuessThePopulationView(), | |
48 tag: GameMode.guessThePopulation, | |
49 selection: $gameModeSelection) | |
50 { | |
51 EmptyView() | |
52 } | |
53 | |
54 ScrollView(showsIndicators: false) { | |
55 VStack(alignment: .leading, spacing: 30) { | |
56 Text("Select a game 🎮") | |
57 .font(.largeTitle.bold()) | |
58 .padding(.bottom) | |
59 | |
60 Button { | |
61 gameModeSelection = .guessTheFlag | |
62 } label: { | |
63 GameButton( | |
64 gradient: .main, | |
65 level: "Level 1", | |
66 symbol: "flag.fill", | |
67 name: "Guess the flag" | |
68 ) | |
69 } | |
70 | |
71 Button { | |
72 if storeKitRC.isActive { | |
73 gameModeSelection = .guessTheCapital | |
74 } else { | |
75 showingBuyPremiumModalView = true | |
76 } | |
77 } label: { | |
78 GameButton( | |
79 gradient: .secondary, | |
80 level: "Level 2", | |
81 symbol: storeKitRC.isActive ? "building.2.fill": "lock.fill", | |
82 name: "Guess the capital" | |
83 ) | |
84 } | |
85 | |
86 Button { | |
87 if storeKitRC.isActive { | |
88 gameModeSelection = .guessTheCountry | |
89 } else { | |
90 showingBuyPremiumModalView = true | |
91 } | |
92 } label: { | |
93 GameButton( | |
94 gradient: .tertiary, | |
95 level: "Level 3", | |
96 symbol: storeKitRC.isActive ? "globe.americas.fill": "lock.fill", | |
97 name: "Guess the country" | |
98 ) | |
99 } | |
100 | |
101 Button { | |
102 if storeKitRC.isActive { | |
103 gameModeSelection = .guessThePopulation | |
104 } else { | |
105 showingBuyPremiumModalView = true | |
106 } | |
107 } label: { | |
108 GameButton( | |
109 gradient: .quaternary, | |
110 level: "Level 4", | |
111 symbol: storeKitRC.isActive ? "person.fill": "lock.fill", | |
112 name: "Guess the population" | |
113 ) | |
114 } | |
115 } | |
116 .padding() | |
117 } | |
118 } | 92 } |
119 .navigationTitle("GeoQuiz") | 93 .navigationTitle("GeoQuiz") |
120 .navigationBarTitleDisplayMode(.inline) | 94 .navigationBarTitleDisplayMode(.inline) |
95 | |
96 .navigationDestination(for: GameType.self) { gameMode in | |
97 switch gameMode { | |
98 case .guessTheFlag: | |
99 GuessTheFlagView() | |
100 case .guessTheCapital: | |
101 GuessTheFlagView() | |
102 case .guessTheCountry: | |
103 GuessTheCountryView() | |
104 case .guessThePopulation: | |
105 GuessThePopulationView() | |
106 } | |
107 } | |
108 | |
121 .toolbar { | 109 .toolbar { |
122 ToolbarItem(placement: .navigationBarLeading) { | 110 ToolbarItem(placement: .navigationBarLeading) { |
123 Button { | 111 Button { |
124 showingSettingsModalView = true | 112 showingSettingsModalView = true |
125 } label: { | 113 } label: { |
146 .sheet(isPresented: $showingBuyPremiumModalView) { | 134 .sheet(isPresented: $showingBuyPremiumModalView) { |
147 BuyPremiumModalView(storeKitRC: storeKitRC) | 135 BuyPremiumModalView(storeKitRC: storeKitRC) |
148 } | 136 } |
149 | 137 |
150 .sheet(isPresented: $showingSettingsModalView) { | 138 .sheet(isPresented: $showingSettingsModalView) { |
151 SettingsModalView() | 139 SettingsModalView(user: user) |
152 } | 140 } |
153 | 141 |
154 .sheet(isPresented: $showingProfileModalView) { | 142 .sheet(isPresented: $showingProfileModalView) { |
155 ProfileModalView() | 143 ProfileModalView(user: user, storeKitRC: storeKitRC) |
156 } | 144 } |
157 } | 145 } |
158 .navigationViewStyle(StackNavigationViewStyle()) | 146 .navigationViewStyle(StackNavigationViewStyle()) |
159 } | 147 } |
160 } | 148 } |