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] = []
|
7
|
12 @State private var showingBuyPremiumModalView = false
|
5
|
13 @State private var showingSettingsModalView = false
|
11
|
14 @State private var showingProfileModalView = false
|
0
|
15
|
26
|
16 @StateObject var storeController = StoreController()
|
19
|
17 @StateObject var userController = UserController()
|
|
18
|
|
19 let premiumGames: [GameType] = [.guessTheCapital, .guessTheCountry, .guessThePopulation]
|
13
|
20
|
0
|
21 var body: some View {
|
14
|
22 NavigationStack(path: $path) {
|
|
23 ScrollView(showsIndicators: false) {
|
19
|
24 ForEach(GameType.allCases, id: \.rawValue) { gameType in
|
|
25 NavigationLink(value: gameType) { EmptyView() }
|
|
26 }
|
13
|
27
|
14
|
28 VStack(alignment: .leading, spacing: 30) {
|
|
29 Text("Select a game 🎮")
|
|
30 .font(.largeTitle.bold())
|
|
31 .padding(.bottom)
|
|
32
|
|
33 Button {
|
|
34 path.append(.guessTheFlag)
|
|
35 } label: {
|
19
|
36 GameButton(gameType: .guessTheFlag, isActive: true)
|
14
|
37 }
|
|
38
|
19
|
39 ForEach(premiumGames, id: \.rawValue) { gameType in
|
|
40 Button {
|
26
|
41 if storeController.premiumIsActive {
|
19
|
42 path.append(gameType)
|
|
43 } else {
|
|
44 showingBuyPremiumModalView = true
|
|
45 }
|
|
46 } label: {
|
26
|
47 GameButton(gameType: gameType, isActive: storeController.premiumIsActive)
|
19
|
48 }
|
13
|
49 }
|
0
|
50 }
|
19
|
51 .padding()
|
0
|
52 }
|
19
|
53 .navigationTitle("GeoQuiz")
|
|
54 .navigationBarTitleDisplayMode(.inline)
|
|
55
|
|
56 .navigationDestination(for: GameType.self) { gameMode in
|
|
57 switch gameMode {
|
|
58 case .guessTheFlag:
|
27
|
59 GuessTheFlagView(userController: userController)
|
19
|
60 case .guessTheCapital:
|
21
|
61 GuessTheCapitalView()
|
19
|
62 case .guessTheCountry:
|
|
63 GuessTheCountryView()
|
|
64 case .guessThePopulation:
|
|
65 GuessThePopulationView()
|
5
|
66 }
|
|
67 }
|
|
68
|
19
|
69 .toolbar {
|
|
70 ToolbarItem(placement: .navigationBarLeading) {
|
13
|
71 Button {
|
19
|
72 showingSettingsModalView = true
|
13
|
73 } label: {
|
19
|
74 Label("Settings", systemImage: "gear")
|
13
|
75 }
|
5
|
76 }
|
11
|
77
|
19
|
78 ToolbarItemGroup {
|
26
|
79 if !storeController.premiumIsActive {
|
19
|
80 Button {
|
|
81 showingBuyPremiumModalView = true
|
|
82 } label: {
|
|
83 Label("Buy premium", systemImage: "star")
|
|
84 }
|
|
85 }
|
|
86
|
|
87 Button {
|
|
88 showingProfileModalView = true
|
|
89 } label: {
|
|
90 Label("Profile", systemImage: "person")
|
|
91 }
|
11
|
92 }
|
0
|
93 }
|
19
|
94 .sheet(isPresented: $showingBuyPremiumModalView) {
|
26
|
95 BuyPremiumModalView(storeController: storeController)
|
19
|
96 }
|
|
97
|
|
98 .sheet(isPresented: $showingSettingsModalView) {
|
26
|
99 SettingsModalView(userController: userController)
|
19
|
100 }
|
|
101
|
|
102 .sheet(isPresented: $showingProfileModalView) {
|
26
|
103 ProfileModalView(userController: userController, storeController: storeController)
|
19
|
104 }
|
0
|
105 }
|
19
|
106 .navigationViewStyle(StackNavigationViewStyle())
|
0
|
107 }
|
|
108 }
|
19
|
109
|
|
110 struct ContentView_Previews: PreviewProvider {
|
|
111 static var previews: some View {
|
|
112 ContentView()
|
|
113 .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
|
114 }
|
0
|
115 }
|