diff --git a/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift b/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift index 0817a21..9db4ca0 100644 --- a/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift +++ b/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift @@ -1,19 +1,19 @@ // // MainMenuButton.swift -// DouShouQi_App +// Dou}Qi_App // // Created by Rémi REGNAULT on 16/05/2024. // import SwiftUI -struct MainMenuButton: View { - +struct MainMenuButton: View { // Text Params var text: String - var destination: Destination var sound: String + // Fonction à executer + var onClick: (() -> Void)? // Button Alignment var horizontalAlignment: Alignment = .center @@ -25,22 +25,22 @@ struct MainMenuButton: View { var bottomRightCorner: CGFloat = 0 var body: some View { - NavigationLink(destination: destination) { - Text(text.uppercased()) - .font(.headline) - .fontWeight(.semibold) - .foregroundColor(.white) - .padding() - .frame(maxWidth: .infinity, maxHeight: 40) - .background( - Color.red - .clipShape(RoundedRectangle(cornerSize: CGSize(width: 0, height: 0))) - .mask(RoundedCornersShape(cornerRadii: (topLeft: topLeftCorner, topRight: topRightCorner, bottomLeft: bottomLeftCorner, bottomRight: bottomRightCorner))) - ) - } - .simultaneousGesture(TapGesture().onEnded { + Button(text.uppercased()) { playSound(named: sound) - }) + if let onClick: () -> Void { + onClick() + } + } + .font(.headline) + .fontWeight(.semibold) + .foregroundColor(.white) + .padding() + .frame(maxWidth: .infinity, maxHeight: 40) + .background( + Color.red + .clipShape(RoundedRectangle(cornerSize: CGSize(width: 0, height: 0))) + .mask(RoundedCornersShape(cornerRadii: (topLeft: topLeftCorner, topRight: topRightCorner, bottomLeft: bottomLeftCorner, bottomRight: bottomRightCorner))) + ) .frame(width: UIScreen.main.bounds.width / 1.7) .frame(maxWidth: .infinity, alignment: horizontalAlignment) } @@ -92,6 +92,6 @@ struct RoundedCornersShape: Shape { struct MainMenuButton_Previews: PreviewProvider { static var previews: some View { - MainMenuButton(text: "test", destination: HistoricView(historicVM: HistoricVM()), sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "test", sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) } } diff --git a/DouShouQi_App/DouShouQi_App/Views/Game/GameView.swift b/DouShouQi_App/DouShouQi_App/Views/Game/GameView.swift index 214b6af..b4f7e98 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Game/GameView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Game/GameView.swift @@ -14,6 +14,9 @@ struct GameView: View { @StateObject var gameVM: PlayingGameVM + @Binding var isDisplayed: Bool + @Binding var parentIsDisplayed: Bool + var body: some View { ZStack { VStack { @@ -49,7 +52,8 @@ struct GameView: View { .onAppear { Timer.scheduledTimer(withTimeInterval: 10, repeats: false) { _ in - // Il faut retourner au home + isDisplayed = false + parentIsDisplayed = false } } } diff --git a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift index 9efa0c5..9e9de28 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift @@ -14,10 +14,16 @@ struct MainMenuView: View { @State private var timer: Timer? @State private var showImage = false + @State var showSelectPlayer = false + @State var showHistoric = false + @State var showBestScores = false + @State var showPlayers = false + @State var showSettings = false + let images: [String] = [AppImages.SemiLion, AppImages.SemiDog, AppImages.SemiRat, AppImages.SemiWolf, AppImages.SemiLeopard, AppImages.SemiElephant, AppImages.SemiCat] // Add your image names here var body: some View { - NavigationView { + NavigationStack { VStack { if showSplash { SplashScreenView() @@ -37,12 +43,28 @@ struct MainMenuView: View { VStack { HStack { VStack(spacing: 25) { - MainMenuButton(text: "Play", destination: SelectPlayerView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) - MainMenuButton(text: "Historique", destination: HistoricView(historicVM: HistoricVM()), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) - MainMenuButton(text: "Best Scores", destination: ScoreBoardView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) - MainMenuButton(text: "Players", destination: PlayersView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) - MainMenuButton(text: "Settings", destination: SettingsView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Play", sound: "TitleScreenButtonSound",onClick: { showSelectPlayer = true }, topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Historique", sound: "TitleScreenButtonSound",onClick: { showHistoric = true }, topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Best Scores", sound: "TitleScreenButtonSound",onClick: { showBestScores = true }, topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Players", sound: "TitleScreenButtonSound",onClick: { showPlayers = true }, topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Settings", sound: "TitleScreenButtonSound",onClick: { showSettings = true }, topRightCorner: 10, bottomRightCorner: 10) + } + .navigationDestination(isPresented: $showSelectPlayer) { + SelectPlayerView(isDisplayed: $showSelectPlayer) + } + .navigationDestination(isPresented: $showHistoric) { + HistoricView(historicVM: HistoricVM()) + } + .navigationDestination(isPresented: $showBestScores) { + ScoreBoardView() + } + .navigationDestination(isPresented: $showPlayers) { + PlayersView() + } + .navigationDestination(isPresented: $showSettings) { + SettingsView() } + if let currentImage = currentImage { Image(currentImage) .resizable() diff --git a/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift b/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift index 72da9a0..7f2d81a 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift @@ -14,6 +14,11 @@ struct SelectPlayerView: View { @StateObject var player1 = PlayerVM() @StateObject var player2 = PlayerVM() + @Binding var isDisplayed: Bool + + @State var gameIsPlaying: Bool = false + @State var gameSettings: Bool = false + var body: some View { VStack { TitlePageFrame(Text: "select players") @@ -27,10 +32,16 @@ struct SelectPlayerView: View { HStack { VStack(alignment: .trailing) { - MainMenuButton(text: "Start", destination: GameView(gameVM: PlayingGameVM(withRules: ClassicRules(), andPlayer1: HumanPlayer(withName: player1.player.name, andId: .player1)!, andPlayer2: HumanPlayer(withName: player2.player.name, andId: .player2)!)!), sound: "Start", horizontalAlignment: .trailing, topLeftCorner: 10, bottomLeftCorner: 10) - MainMenuButton(text: "Settings", destination: ContentView(), sound: "TitleScreenButtonSound", horizontalAlignment: .trailing, topLeftCorner: 10, bottomLeftCorner: 10) + MainMenuButton(text: "Start", sound: "Start", onClick: {gameIsPlaying = true}, horizontalAlignment: .trailing, topLeftCorner: 10, bottomLeftCorner: 10) + MainMenuButton(text: "Settings", sound: "TitleScreenButtonSound", onClick: { gameSettings = true }, horizontalAlignment: .trailing, topLeftCorner: 10, bottomLeftCorner: 10) } + .navigationDestination(isPresented: $gameIsPlaying) { + GameView(gameVM: PlayingGameVM(withRules: ClassicRules(), andPlayer1: HumanPlayer(withName: player1.player.name, andId: .player1)!, andPlayer2: HumanPlayer(withName: player2.player.name, andId: .player2)!)!, isDisplayed: $gameIsPlaying, parentIsDisplayed: $isDisplayed) + } + .navigationDestination(isPresented: $gameSettings) { + ContentView() + } } Spacer()