diff GeoQuiz/ContentView.swift @ 13:bdfff35dd43c

implement RevenueCat
author Dennis C. M. <dennis@denniscm.com>
date Wed, 12 Oct 2022 11:47:29 +0200
parents 039b26a99a48
children 136928bae534
line wrap: on
line diff
--- a/GeoQuiz/ContentView.swift	Sun Oct 09 19:46:44 2022 +0200
+++ b/GeoQuiz/ContentView.swift	Wed Oct 12 11:47:29 2022 +0200
@@ -8,47 +8,113 @@
 import SwiftUI
 
 struct ContentView: View {
+    @State private var gameModeSelection: GameMode? = nil
+    
     @State private var showingBuyPremiumModalView = false
     @State private var showingSettingsModalView = false
     @State private var showingProfileModalView = false
     
+    @StateObject var storeKitRC = StoreKitRC()
+    
     var body: some View {
         NavigationView {
-            ScrollView(showsIndicators: false) {
-                VStack(alignment: .leading, spacing: 30) {
-                    Text("Select a game 🎮")
-                        .font(.largeTitle.bold())
-                        .padding(.bottom)
-                    
-                    NavigationLink(destination: GuessTheFlagView()) {
-                        GameButton(
-                            gradient: .main,
-                            level: "Level 1", symbol: "flag.fill", name: "Guess the flag"
-                        )
+            VStack {
+                NavigationLink(
+                    destination: GuessTheFlagView(),
+                    tag: GameMode.guessTheFlag,
+                    selection: $gameModeSelection)
+                {
+                    EmptyView()
+                }
+                
+                NavigationLink(
+                    destination: GuessTheCapitalView(),
+                    tag: GameMode.guessTheCapital,
+                    selection: $gameModeSelection)
+                {
+                    EmptyView()
+                }
+                
+                NavigationLink(
+                    destination: GuessTheCountryView(),
+                    tag: GameMode.guessTheCountry,
+                    selection: $gameModeSelection)
+                {
+                    EmptyView()
+                }
+                
+                NavigationLink(
+                    destination: GuessThePopulationView(),
+                    tag: GameMode.guessThePopulation,
+                    selection: $gameModeSelection)
+                {
+                    EmptyView()
+                }
+                
+                ScrollView(showsIndicators: false) {
+                    VStack(alignment: .leading, spacing: 30) {
+                        Text("Select a game 🎮")
+                            .font(.largeTitle.bold())
+                            .padding(.bottom)
+                        
+                        Button {
+                            gameModeSelection = .guessTheFlag
+                        } label: {
+                            GameButton(
+                                gradient: .main,
+                                level: "Level 1",
+                                symbol: "flag.fill",
+                                name: "Guess the flag"
+                            )
+                        }
+                        
+                        Button {
+                            if storeKitRC.isActive {
+                                gameModeSelection = .guessTheCapital
+                            } else {
+                                showingBuyPremiumModalView = true
+                            }
+                        } label: {
+                            GameButton(
+                                gradient: .secondary,
+                                level: "Level 2",
+                                symbol: storeKitRC.isActive ? "building.2.fill": "lock.fill",
+                                name: "Guess the capital"
+                            )
+                        }
+                        
+                        Button {
+                            if storeKitRC.isActive {
+                                gameModeSelection = .guessTheCountry
+                            } else {
+                                showingBuyPremiumModalView = true
+                            }
+                        } label: {
+                            GameButton(
+                                gradient: .tertiary,
+                                level: "Level 3",
+                                symbol: storeKitRC.isActive ? "globe.americas.fill": "lock.fill",
+                                name: "Guess the country"
+                            )
+                        }
+                        
+                        Button {
+                            if storeKitRC.isActive {
+                                gameModeSelection = .guessThePopulation
+                            } else {
+                                showingBuyPremiumModalView = true
+                            }
+                        } label: {
+                            GameButton(
+                                gradient: .quaternary,
+                                level: "Level 4",
+                                symbol: storeKitRC.isActive ? "person.fill": "lock.fill",
+                                name: "Guess the population"
+                            )
+                        }
                     }
-                    
-                    NavigationLink(destination: GuessTheCapitalView()) {
-                        GameButton(
-                            gradient: .secondary,
-                            level: "Level 2", symbol: "building.2.fill", name: "Guess the capital"
-                        )
-                    }
-                    
-                    NavigationLink(destination: GuessTheCountryView()) {
-                        GameButton(
-                            gradient: .tertiary,
-                            level: "Level 3", symbol: "globe.americas.fill", name: "Guess the country"
-                        )
-                    }
-                    
-                    NavigationLink(destination: GuessThePopulationView()) {
-                        GameButton(
-                            gradient: .quaternary,
-                            level: "Level 4", symbol: "person.fill", name: "Guess the population"
-                        )
-                    }
+                    .padding()
                 }
-                .padding()
             }
             .navigationTitle("GeoQuiz")
             .navigationBarTitleDisplayMode(.inline)
@@ -62,10 +128,12 @@
                 }
                 
                 ToolbarItemGroup {
-                    Button {
-                        showingBuyPremiumModalView = true
-                    } label: {
-                        Label("Buy premium", systemImage: "star")
+                    if !storeKitRC.isActive {
+                        Button {
+                            showingBuyPremiumModalView = true
+                        } label: {
+                            Label("Buy premium", systemImage: "star")
+                        }
                     }
                     
                     Button {
@@ -76,7 +144,7 @@
                 }
             }
             .sheet(isPresented: $showingBuyPremiumModalView) {
-                BuyPremiumModalView()
+                BuyPremiumModalView(storeKitRC: storeKitRC)
             }
             
             .sheet(isPresented: $showingSettingsModalView) {