Mercurial > public > geoquiz
annotate GeoQuiz/ContentView.swift @ 17:8dac58bb4569
fix build bug
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Thu, 20 Oct 2022 18:07:51 +0200 |
parents | 1011e56b7832 |
children | f140bb277c96 |
rev | line source |
---|---|
0 | 1 // |
2 // ContentView.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 5/9/22. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 struct ContentView: View { | |
14 | 11 @State private var path: [GameType] = [] |
13 | 12 |
7 | 13 @State private var showingBuyPremiumModalView = false |
5 | 14 @State private var showingSettingsModalView = false |
11 | 15 @State private var showingProfileModalView = false |
0 | 16 |
13 | 17 @StateObject var storeKitRC = StoreKitRC() |
14 | 18 @StateObject var user = User() |
13 | 19 |
0 | 20 var body: some View { |
14 | 21 NavigationStack(path: $path) { |
22 ScrollView(showsIndicators: false) { | |
13 | 23 |
14 | 24 NavigationLink(value: GameType.guessTheFlag) { EmptyView() } |
25 NavigationLink(value: GameType.guessTheCapital) { EmptyView() } | |
26 NavigationLink(value: GameType.guessTheCountry) { EmptyView() } | |
27 NavigationLink(value: GameType.guessThePopulation) { EmptyView() } | |
13 | 28 |
14 | 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( | |
16 | 38 gradient: GuessTheFlagInfo.gradient, |
39 level: GuessTheFlagInfo.level, | |
40 symbol: GuessTheFlagInfo.symbol, | |
41 name: GuessTheFlagInfo.name | |
14 | 42 ) |
43 } | |
44 | |
45 Button { | |
46 if storeKitRC.isActive { | |
47 path.append(.guessTheCapital) | |
48 } else { | |
49 showingBuyPremiumModalView = true | |
13 | 50 } |
14 | 51 } label: { |
52 GameButton( | |
16 | 53 gradient: GuessTheCapitalInfo.gradient, |
54 level: GuessTheCapitalInfo.level, | |
55 symbol: storeKitRC.isActive ? GuessTheCapitalInfo.symbol: "lock.fill", | |
56 name: GuessTheCapitalInfo.name | |
14 | 57 ) |
58 } | |
59 | |
60 Button { | |
61 if storeKitRC.isActive { | |
62 path.append(.guessTheCountry) | |
63 } else { | |
64 showingBuyPremiumModalView = true | |
13 | 65 } |
14 | 66 } label: { |
67 GameButton( | |
16 | 68 gradient: GuessTheCountryInfo.gradient, |
69 level: GuessTheCountryInfo.level, | |
70 symbol: storeKitRC.isActive ? GuessTheCountryInfo.symbol: "lock.fill", | |
71 name: GuessTheCountryInfo.name | |
14 | 72 ) |
73 } | |
74 | |
75 Button { | |
76 if storeKitRC.isActive { | |
77 path.append(.guessThePopulation) | |
78 } else { | |
79 showingBuyPremiumModalView = true | |
13 | 80 } |
14 | 81 } label: { |
82 GameButton( | |
16 | 83 gradient: GuessThePopulationInfo.gradient, |
84 level: GuessThePopulationInfo.level, | |
85 symbol: storeKitRC.isActive ? GuessThePopulationInfo.symbol: "lock.fill", | |
86 name: GuessThePopulationInfo.name | |
14 | 87 ) |
0 | 88 } |
14 | 89 |
0 | 90 } |
14 | 91 .padding() |
0 | 92 } |
10
a793f33f05fb
refactor code and fix layout
Dennis C. M. <dennis@denniscm.com>
parents:
8
diff
changeset
|
93 .navigationTitle("GeoQuiz") |
a793f33f05fb
refactor code and fix layout
Dennis C. M. <dennis@denniscm.com>
parents:
8
diff
changeset
|
94 .navigationBarTitleDisplayMode(.inline) |
14 | 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 | |
0 | 109 .toolbar { |
5 | 110 ToolbarItem(placement: .navigationBarLeading) { |
111 Button { | |
112 showingSettingsModalView = true | |
113 } label: { | |
114 Label("Settings", systemImage: "gear") | |
115 } | |
116 } | |
117 | |
118 ToolbarItemGroup { | |
13 | 119 if !storeKitRC.isActive { |
120 Button { | |
121 showingBuyPremiumModalView = true | |
122 } label: { | |
123 Label("Buy premium", systemImage: "star") | |
124 } | |
5 | 125 } |
11 | 126 |
127 Button { | |
128 showingProfileModalView = true | |
129 } label: { | |
130 Label("Profile", systemImage: "person") | |
131 } | |
0 | 132 } |
133 } | |
7 | 134 .sheet(isPresented: $showingBuyPremiumModalView) { |
13 | 135 BuyPremiumModalView(storeKitRC: storeKitRC) |
0 | 136 } |
5 | 137 |
138 .sheet(isPresented: $showingSettingsModalView) { | |
14 | 139 SettingsModalView(user: user) |
5 | 140 } |
11 | 141 |
142 .sheet(isPresented: $showingProfileModalView) { | |
14 | 143 ProfileModalView(user: user, storeKitRC: storeKitRC) |
11 | 144 } |
0 | 145 } |
6 | 146 .navigationViewStyle(StackNavigationViewStyle()) |
0 | 147 } |
148 } | |
149 | |
150 struct ContentView_Previews: PreviewProvider { | |
151 static var previews: some View { | |
152 ContentView() | |
16 | 153 .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) |
0 | 154 } |
155 } |