From 0c24e2adac64b25ab6a965be7889a43fc66c33ba Mon Sep 17 00:00:00 2001
From: Apollo Zhu <zhuzhiyu@cs.washington.edu>
Date: Thu, 1 Jun 2023 10:32:54 -0700
Subject: [PATCH] Pop to root instead of full screen overlay

---
 VAST.xcodeproj/project.pbxproj             |  4 ++++
 VAST/GameView/GameView.swift               | 10 ++++------
 VAST/GameView/HumansWinView.swift          | 12 ++++--------
 VAST/GameView/InfectorsWinView.swift       | 10 +++-------
 VAST/Menu/MenuView.swift                   | 19 +++++++++++--------
 VAST/VASTApp.swift                         |  1 +
 VAST/ViewModel/NavigationPathManager.swift | 17 +++++++++++++++++
 7 files changed, 44 insertions(+), 29 deletions(-)
 create mode 100644 VAST/ViewModel/NavigationPathManager.swift

diff --git a/VAST.xcodeproj/project.pbxproj b/VAST.xcodeproj/project.pbxproj
index 0bd279d..7156a93 100644
--- a/VAST.xcodeproj/project.pbxproj
+++ b/VAST.xcodeproj/project.pbxproj
@@ -19,6 +19,7 @@
 		D2BE11A929F7314600D63884 /* TagPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2BE11A829F7314600D63884 /* TagPlayerView.swift */; };
 		D2E506DA2A12FC68005CF678 /* NearbyInteractionManager+MPC.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E506D92A12FC68005CF678 /* NearbyInteractionManager+MPC.swift */; };
 		D2E506DC2A12FD05005CF678 /* NearbyInteractionManager+Firebase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E506DB2A12FD05005CF678 /* NearbyInteractionManager+Firebase.swift */; };
+		D2FA1B982A2909CA00A09FBE /* NavigationPathManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FA1B972A2909CA00A09FBE /* NavigationPathManager.swift */; };
 		D2FAF20729DF376900B2BF8B /* VASTApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FAF20629DF376900B2BF8B /* VASTApp.swift */; };
 		D2FAF20929DF376900B2BF8B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FAF20829DF376900B2BF8B /* ContentView.swift */; };
 		D2FAF20B29DF376A00B2BF8B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D2FAF20A29DF376A00B2BF8B /* Assets.xcassets */; };
@@ -50,6 +51,7 @@
 		D2BE11A829F7314600D63884 /* TagPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagPlayerView.swift; sourceTree = "<group>"; };
 		D2E506D92A12FC68005CF678 /* NearbyInteractionManager+MPC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NearbyInteractionManager+MPC.swift"; sourceTree = "<group>"; };
 		D2E506DB2A12FD05005CF678 /* NearbyInteractionManager+Firebase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NearbyInteractionManager+Firebase.swift"; sourceTree = "<group>"; };
+		D2FA1B972A2909CA00A09FBE /* NavigationPathManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationPathManager.swift; sourceTree = "<group>"; };
 		D2FAF20329DF376900B2BF8B /* VAST.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VAST.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		D2FAF20629DF376900B2BF8B /* VASTApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VASTApp.swift; sourceTree = "<group>"; };
 		D2FAF20829DF376900B2BF8B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -182,6 +184,7 @@
 			children = (
 				DB6480602A17FAA600DD0A0F /* ViewPlayers.swift */,
 				DB64806E2A25AEA800DD0A0F /* ViewGame.swift */,
+				D2FA1B972A2909CA00A09FBE /* NavigationPathManager.swift */,
 			);
 			path = ViewModel;
 			sourceTree = "<group>";
@@ -300,6 +303,7 @@
 				D211792E2A1A0C3C007370C6 /* TagPlayerView1D.swift in Sources */,
 				D211792C2A1A0B20007370C6 /* TagPlayerView3D.swift in Sources */,
 				DB6480612A17FAA600DD0A0F /* ViewPlayers.swift in Sources */,
+				D2FA1B982A2909CA00A09FBE /* NavigationPathManager.swift in Sources */,
 				DB64806D2A21465000DD0A0F /* JoinGame.swift in Sources */,
 				DB6480692A17FD8000DD0A0F /* Player.swift in Sources */,
 				D222A8A72A1BF76B00048798 /* RadarBackground.swift in Sources */,
diff --git a/VAST/GameView/GameView.swift b/VAST/GameView/GameView.swift
index 2dc60fd..091c50c 100644
--- a/VAST/GameView/GameView.swift
+++ b/VAST/GameView/GameView.swift
@@ -101,12 +101,10 @@ struct GameView: View {
             
         }
         .fullScreenCover(isPresented: $isPresented) {
-            NavigationStack {
-                if humansWin {
-                    HumansWinView()
-                } else {
-                    InfectorsWinView()
-                }
+            if humansWin {
+                HumansWinView()
+            } else {
+                InfectorsWinView()
             }
         }
     }
diff --git a/VAST/GameView/HumansWinView.swift b/VAST/GameView/HumansWinView.swift
index 9f96f87..c31f03c 100644
--- a/VAST/GameView/HumansWinView.swift
+++ b/VAST/GameView/HumansWinView.swift
@@ -8,19 +8,15 @@
 import SwiftUI
 
 struct HumansWinView: View {
-    @State private var isPresented = false
-
+    @EnvironmentObject
+    private var navigationPathManager: NavigationPathManager
+    
     var body: some View {
         ZStack {
             Color.black.ignoresSafeArea()
             VStack {
                 Button("HUMANS WIN") {
-                    isPresented = true
-                }
-                .fullScreenCover(isPresented: $isPresented) {
-                    NavigationStack {
-                        MenuView()
-                    }
+                    navigationPathManager.path = []
                 }
                         .fontWeight(.bold)
                         .font(.title)
diff --git a/VAST/GameView/InfectorsWinView.swift b/VAST/GameView/InfectorsWinView.swift
index 44cc973..bf17681 100644
--- a/VAST/GameView/InfectorsWinView.swift
+++ b/VAST/GameView/InfectorsWinView.swift
@@ -8,7 +8,8 @@
 import SwiftUI
 
 struct InfectorsWinView: View {
-    @State private var isPresented = false
+    @EnvironmentObject
+    private var navigationPathManager: NavigationPathManager
     
     @ObservedObject private var viewGame = ViewGame.shared
 
@@ -17,12 +18,7 @@ struct InfectorsWinView: View {
             Color.black.ignoresSafeArea()
             VStack {
                 Button("INFECTORS WIN") {
-                    isPresented = true
-                }
-                .fullScreenCover(isPresented: $isPresented) {
-                    NavigationStack {
-                        MenuView()
-                    }
+                    navigationPathManager.path = []
                 }
                         .fontWeight(.bold)
                         .font(.title)
diff --git a/VAST/Menu/MenuView.swift b/VAST/Menu/MenuView.swift
index 211fbcc..79fc4a6 100644
--- a/VAST/Menu/MenuView.swift
+++ b/VAST/Menu/MenuView.swift
@@ -8,8 +8,11 @@
 import SwiftUI
 
 struct MenuView: View {
+    @EnvironmentObject
+    private var navigationPathManager: NavigationPathManager
+    
     var body: some View {
-        NavigationStack {
+        NavigationStack(path: $navigationPathManager.path) {
             ZStack {
                 Color.black.ignoresSafeArea()
                 
@@ -19,8 +22,7 @@ struct MenuView: View {
                         .foregroundColor(Color.white)
                     Spacer()
                         .frame(height: 200)
-                    NavigationLink(destination: JoinGameView(), label:
-                        {
+                    NavigationLink(value: NavigationPathManager.PageKind.joinGame) {
                         Text("PLAY")
                             .fontWeight(.bold)
                             .font(.title)
@@ -29,12 +31,10 @@ struct MenuView: View {
                             .padding(10)
                             .frame(maxWidth: .infinity)
                             .border(Color.white, width: 5)
-                    })
+                    }
                     Spacer()
                         .frame(height: 100)
-                    NavigationLink(destination: JoinGameView(),
-                                   label:
-                                    {
+                    NavigationLink(value: NavigationPathManager.PageKind.joinGame) {
                         Text("TUTORIAL")
                             .fontWeight(.bold)
                             .font(.title)
@@ -43,10 +43,13 @@ struct MenuView: View {
                             .padding(10)
                             .frame(maxWidth: .infinity)
                             .border(Color.white, width: 5)
-                    })
+                    }
                 }
                 .fixedSize(horizontal: true, vertical: false)
             }
+            .navigationDestination(for: NavigationPathManager.PageKind.self) { page in
+                JoinGameView()
+            }
         }
     }
 
diff --git a/VAST/VASTApp.swift b/VAST/VASTApp.swift
index a31a846..427431a 100644
--- a/VAST/VASTApp.swift
+++ b/VAST/VASTApp.swift
@@ -26,6 +26,7 @@ struct VASTApp: App {
             ContentView()
                 .preferredColorScheme(.dark)
                 .environmentObject(NearbyInteractionManager.shared)
+                .environmentObject(NavigationPathManager())
         }
     }
 }
diff --git a/VAST/ViewModel/NavigationPathManager.swift b/VAST/ViewModel/NavigationPathManager.swift
new file mode 100644
index 0000000..195c0eb
--- /dev/null
+++ b/VAST/ViewModel/NavigationPathManager.swift
@@ -0,0 +1,17 @@
+//
+//  NavigationPathManager.swift
+//  VAST
+//
+//  Created by Apollo Zhu on 6/1/23.
+//
+
+import Foundation
+
+class NavigationPathManager: ObservableObject {
+    @Published
+    var path: [PageKind] = []
+    
+    enum PageKind: Hashable {
+        case joinGame
+    }
+}
-- 
GitLab