Mercurial > public > geoquiz
diff 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 |
line wrap: on
line diff
--- a/GeoQuiz/ContentView.swift Wed Oct 12 11:47:29 2022 +0200 +++ b/GeoQuiz/ContentView.swift Wed Oct 19 07:56:33 2022 +0200 @@ -8,116 +8,104 @@ import SwiftUI struct ContentView: View { - @State private var gameModeSelection: GameMode? = nil + @State private var path: [GameType] = [] @State private var showingBuyPremiumModalView = false @State private var showingSettingsModalView = false @State private var showingProfileModalView = false @StateObject var storeKitRC = StoreKitRC() + @StateObject var user = User() var body: some View { - NavigationView { - VStack { - NavigationLink( - destination: GuessTheFlagView(), - tag: GameMode.guessTheFlag, - selection: $gameModeSelection) - { - EmptyView() - } + NavigationStack(path: $path) { + ScrollView(showsIndicators: false) { - 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() - } + NavigationLink(value: GameType.guessTheFlag) { EmptyView() } + NavigationLink(value: GameType.guessTheCapital) { EmptyView() } + NavigationLink(value: GameType.guessTheCountry) { EmptyView() } + NavigationLink(value: GameType.guessThePopulation) { 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" - ) + VStack(alignment: .leading, spacing: 30) { + Text("Select a game 🎮") + .font(.largeTitle.bold()) + .padding(.bottom) + + Button { + path.append(.guessTheFlag) + } label: { + GameButton( + gradient: .main, + level: "Level 1", + symbol: "flag.fill", + name: "Guess the flag" + ) + } + + Button { + if storeKitRC.isActive { + path.append(.guessTheCapital) + } else { + showingBuyPremiumModalView = true } - - 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" - ) + } label: { + GameButton( + gradient: .secondary, + level: "Level 2", + symbol: storeKitRC.isActive ? "building.2.fill": "lock.fill", + name: "Guess the capital" + ) + } + + Button { + if storeKitRC.isActive { + path.append(.guessTheCountry) + } else { + showingBuyPremiumModalView = true } - - 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" - ) + } label: { + GameButton( + gradient: .tertiary, + level: "Level 3", + symbol: storeKitRC.isActive ? "globe.americas.fill": "lock.fill", + name: "Guess the country" + ) + } + + Button { + if storeKitRC.isActive { + path.append(.guessThePopulation) + } else { + showingBuyPremiumModalView = true } + } label: { + GameButton( + gradient: .quaternary, + level: "Level 4", + symbol: storeKitRC.isActive ? "person.fill": "lock.fill", + name: "Guess the population" + ) } - .padding() + } + .padding() } .navigationTitle("GeoQuiz") .navigationBarTitleDisplayMode(.inline) + + .navigationDestination(for: GameType.self) { gameMode in + switch gameMode { + case .guessTheFlag: + GuessTheFlagView() + case .guessTheCapital: + GuessTheFlagView() + case .guessTheCountry: + GuessTheCountryView() + case .guessThePopulation: + GuessThePopulationView() + } + } + .toolbar { ToolbarItem(placement: .navigationBarLeading) { Button { @@ -148,11 +136,11 @@ } .sheet(isPresented: $showingSettingsModalView) { - SettingsModalView() + SettingsModalView(user: user) } .sheet(isPresented: $showingProfileModalView) { - ProfileModalView() + ProfileModalView(user: user, storeKitRC: storeKitRC) } } .navigationViewStyle(StackNavigationViewStyle())