Example #1
0
        /// <summary>
        /// Event handler called when the system delivers an invite notification.
        /// This can occur when the user accepts an invite that was sent to them by
        /// a friend (pull mode), or if they choose the "Join Session In Progress"
        /// option in their friends screen (push mode). The handler leaves the
        /// current session (if any), then joins the session referred to by the
        /// invite. It is not necessary to prompt the user before doing this, as
        /// the Guide will already have taken care of the necessary confirmations
        /// before the invite was delivered to you.
        /// </summary>
        public static void InviteAccepted(ScreenManager screenManager,
                                          InviteAcceptedEventArgs e)
        {
            // If we are already in a network session, leave it now.
            NetworkSessionComponent self = FindSessionComponent(screenManager.Game);

            if (self != null)
            {
                self.Dispose();
            }

            try
            {
                // Which local profiles should we include in this session?
                IEnumerable <SignedInGamer> localGamers =
                    ChooseGamers(NetworkSessionType.PlayerMatch, e.Gamer.PlayerIndex);

                // Begin an asynchronous join-from-invite operation.
                IAsyncResult asyncResult = NetworkSession.BeginJoinInvited(localGamers,
                                                                           null, null);

                // Use the loading screen to replace whatever screens were previously
                // active. This will completely reset the screen state, regardless of
                // whether we were in the menus or playing a game when the invite was
                // delivered. When the loading screen finishes, it will activate the
                // network busy screen, which displays an animation as it waits for
                // the join operation to complete.
                NetworkBusyScreen busyScreen = new NetworkBusyScreen(asyncResult);

                busyScreen.OperationCompleted += JoinInvitedOperationCompleted;

                LoadingScreen.Load(screenManager, false, null, new BackgroundScreen(),
                                   busyScreen);
            }
            catch (Exception exception)
            {
                NetworkErrorScreen errorScreen = new NetworkErrorScreen(exception);

                LoadingScreen.Load(screenManager, false, null, new BackgroundScreen(),
                                   new MainMenuScreen(),
                                   errorScreen);
            }
        }
Example #2
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                    bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
            // HighscoreComponent.Global.ClearHighscores();
            if (IsActive)
            {
                gamepadstate = GamePad.GetState(BackgroundScreen.playerwhoselectedplay);
                keyboard     = Keyboard.GetState();
                if ((gamepadstate.IsButtonDown(Buttons.A) && lastgamepadstate.IsButtonUp(Buttons.A)) || (keyboard.IsKeyDown(Keys.Enter) && keyboardlast.IsKeyUp(Keys.Enter)))
                {
                    if (imageToDisplay < images.Length - 1)
                    {
                        imageToDisplay++;
                    }
                    else
                    {
                        LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(),
                                           new MainMenuScreen());
                    }
                }

                if (gamepadstate.IsButtonDown(Buttons.B) && lastgamepadstate.IsButtonUp(Buttons.B))
                {
                    if (imageToDisplay == 0)
                    {
                        LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(),
                                           new MainMenuScreen());
                    }
                    else
                    {
                        imageToDisplay--;
                    }
                }

                keyboardlast     = Keyboard.GetState();
                lastgamepadstate = GamePad.GetState(BackgroundScreen.playerwhoselectedplay);
            }
        }    //this ends update is active. put stuff before it.
Example #3
0
 void screenshotsMenuEntrySelected(object sender, PlayerIndexEventArgs e)
 {
     BackgroundScreen.playerwhoselectedplay = e.PlayerIndex;
     if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.One)
     {
         BackgroundScreen.player1isplaying = true;
     }
     if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.Two)
     {
         BackgroundScreen.player2isplaying = true;
     }
     if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.Three)
     {
         BackgroundScreen.player3isplaying = true;
     }
     if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.Four)
     {
         BackgroundScreen.player4isplaying = true;
     }
     LoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
                        new Screenshots());
 }
Example #4
0
 void howtoplaytextMenuEntrySelected(object sender, PlayerIndexEventArgs e)
 {
     BackgroundScreen.playerwhoselectedplay = e.PlayerIndex;
     if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.One)
     {
         BackgroundScreen.player1isplaying = true;
     }
     if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.Two)
     {
         BackgroundScreen.player2isplaying = true;
     }
     if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.Three)
     {
         BackgroundScreen.player3isplaying = true;
     }
     if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.Four)
     {
         BackgroundScreen.player4isplaying = true;
     }
     LoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
                        new HowToPlayText(null));
 }
        /// <summary>
        /// Event handler for when the asynchronous create network session
        /// operation has completed.
        /// </summary>
        void CreateSessionOperationCompleted(object sender,
                                             OperationCompletedEventArgs e)
        {
            try
            {
                // End the asynchronous create network session operation.
                NetworkSession networkSession;
                try
                {
                    networkSession = NetworkSession.EndCreate(e.AsyncResult);
                    NetworkSessionComponent.Create(ScreenManager, networkSession);
                    // Go to the lobby screen. We pass null as the controlling player,
                    // because the lobby screen accepts input from all local players
                    // who are in the session, not just a single controlling player.
                    ScreenManager.AddScreen(new LobbyScreen(networkSession), null);
                }
                catch
                {
                    try
                    {
                        Game game = this.ScreenManager.Game;
                        game.Services.RemoveService(typeof(NetworkSession));
                        //game.Services.AddService(typeof(NetworkSession), networkSession);
                        LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(),
                                           new MainMenuScreen());
                    }
                    catch { }
                }

                // Create a component that will manage the session we just created.
            }
            catch (Exception exception)
            {
                NetworkErrorScreen errorScreen = new NetworkErrorScreen(exception);

                ScreenManager.AddScreen(errorScreen, ControllingPlayer);
            }
        }
Example #6
0
        /// <summary>
        /// Updates the state of the game.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                    bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);

            // Gradually fade in or out depending on whether we are covered by the pause screen.
            if (coveredByOtherScreen)
            {
                pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1);
            }
            else
            {
                pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0);
            }

            if (IsActive)
            {
                if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed ||
                    GamePad.GetState(PlayerIndex.Two).Buttons.B == ButtonState.Pressed ||
                    GamePad.GetState(PlayerIndex.Three).Buttons.B == ButtonState.Pressed ||
                    GamePad.GetState(PlayerIndex.Four).Buttons.B == ButtonState.Pressed)
                {
                    Global_Variables.shouldLoadMainMenu = true;
                    this.ExitScreen();
                }
            }

            // If we are in a network game, check if we should return to the lobby.
            if ((networkSession != null) && !IsExiting)
            {
                if (networkSession.SessionState == NetworkSessionState.Lobby)
                {
                    LoadingScreen.Load(ScreenManager, true, null,
                                       new BackgroundScreen(),
                                       new LobbyScreen(networkSession));
                }
            }
        }
Example #7
0
        void SinglePlayerMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            Global_Variables.playerWhoBeganGame = e.PlayerIndex;
            switch (e.PlayerIndex)
            {
            case PlayerIndex.One:
                Global_Variables.playerWhoBeganGameZeroIndexedInt = 0;
                break;

            case PlayerIndex.Two:
                Global_Variables.playerWhoBeganGameZeroIndexedInt = 1;
                break;

            case PlayerIndex.Three:
                Global_Variables.playerWhoBeganGameZeroIndexedInt = 2;
                break;

            case PlayerIndex.Four:
                Global_Variables.playerWhoBeganGameZeroIndexedInt = 3;
                break;
            }
            LoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
                               new AAgameplayScreen(null));
        }
Example #8
0
        /// <summary>
        /// Updates the lobby screen.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                    bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (!IsExiting)
            {
                if (networkSession.SessionState == NetworkSessionState.Playing)
                {
                    // Check if we should leave the lobby and begin gameplay.
                    // We pass null as the controlling player, because the networked
                    // gameplay screen accepts input from any local players who
                    // are in the session, not just a single controlling player.
                    LoadingScreen.Load(ScreenManager, true, null,
                                       new AAgameplayScreen(networkSession));
                }
                else if (networkSession.IsHost && networkSession.IsEveryoneReady)
                {
                    // The host checks whether everyone has marked themselves
                    // as ready, and starts the game in response.
                    networkSession.StartGame();
                }
            }
        }
Example #9
0
 void youwinMessageBoxCancelled(object sender, PlayerIndexEventArgs e)
 {
     LoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
                        new HowToPlay());
 }
Example #10
0
 void youwinMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
 {
     LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(),
                        new MainMenuScreen());
 }
Example #11
0
        void multiplayerMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            if (Guide.IsTrialMode == true &&
                PlayerIndexExtensions.CanBuyGame(e.PlayerIndex)
                )
            {
                Guide.ShowMarketplace(e.PlayerIndex);
            }
            if (Guide.IsTrialMode)
            {
                MessageBoxScreen purchaseMessageBox;
                purchaseMessageBox            = new MessageBoxScreen("Multiplayer gameplay is not available in the\ntrial version. Please purchase the game!\nA button = Okay", false);
                purchaseMessageBox.Accepted  += purchaseMessageBoxCancelled;
                purchaseMessageBox.Cancelled += purchaseMessageBoxCancelled;
                ScreenManager.AddScreen(purchaseMessageBox, e.PlayerIndex);
            }
            if (Guide.IsTrialMode == false)
            {
                BackgroundScreen.player1isplaying = false;
                BackgroundScreen.player2isplaying = false;
                BackgroundScreen.player3isplaying = false;
                BackgroundScreen.player4isplaying = false;

                Global_Variables.playerWhoBeganGame = e.PlayerIndex;
                switch (e.PlayerIndex)
                {
                case PlayerIndex.One:
                    Global_Variables.playerWhoBeganGameZeroIndexedInt = 0;
                    break;

                case PlayerIndex.Two:
                    Global_Variables.playerWhoBeganGameZeroIndexedInt = 1;
                    break;

                case PlayerIndex.Three:
                    Global_Variables.playerWhoBeganGameZeroIndexedInt = 2;
                    break;

                case PlayerIndex.Four:
                    Global_Variables.playerWhoBeganGameZeroIndexedInt = 3;
                    break;
                }
                BackgroundScreen.playerwhoselectedplay = e.PlayerIndex;
                if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.One)
                {
                    BackgroundScreen.player1isplaying = true;
                }
                if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.Two)
                {
                    BackgroundScreen.player2isplaying = true;
                }
                if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.Three)
                {
                    BackgroundScreen.player3isplaying = true;
                }
                if (BackgroundScreen.playerwhoselectedplay == PlayerIndex.Four)
                {
                    BackgroundScreen.player4isplaying = true;
                }


                Guide.ShowSignIn(4, false);


                LoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
                                   new Black(null));
            }
        }
Example #12
0
 void youwinMessageBoxCancelled(object sender, PlayerIndexEventArgs e)
 {
     LoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
                        new AAgameplayScreen(null));
 }
Example #13
0
        public override void Update(GameTime gameTime)
        {
            // Read the keyboard and gamepad.
            input.Update();

            if (Global_Variables.shouldLoadMainMenu)
            {
                Global_Variables.shouldLoadMainMenu = false;

                LoadingScreen.Load(this, false, null, new BackgroundScreen(),
                                   new MainMenuScreen());
            }

            // Make a copy of the master screen list, to avoid confusion if
            // the process of updating one screen adds or removes others.
            screensToUpdate.Clear();

            if (shouldPlayIntroVideo)
            {
                if (intromoviepassed)
                {
                    intromovieJUSTpassedTimer += gameTime.ElapsedGameTime.Milliseconds;
                }
            }
            foreach (GameScreen screen in screens)
            {
                screensToUpdate.Add(screen);
            }

            bool otherScreenHasFocus  = !Game.IsActive;
            bool coveredByOtherScreen = false;

            // Loop as long as there are screens waiting to be updated.
            while (screensToUpdate.Count > 0)
            {
                // Pop the topmost screen off the waiting list.
                GameScreen screen = screensToUpdate[screensToUpdate.Count - 1];

                screensToUpdate.RemoveAt(screensToUpdate.Count - 1);

                // Update the screen.
                screen.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

                if (screen.ScreenState == ScreenState.TransitionOn ||
                    screen.ScreenState == ScreenState.Active)
                {
                    // If this is the first active screen we came across,
                    // give it a chance to handle input.
                    if (!otherScreenHasFocus)
                    {
                        screen.HandleInput(input);

                        otherScreenHasFocus = true;
                    }

                    // If this is an active non-popup, inform any subsequent
                    // screens that they are covered by it.
                    if (!screen.IsPopup)
                    {
                        coveredByOtherScreen = true;
                    }
                }
            }

            // Print debug trace?
            if (traceEnabled)
            {
                TraceScreens();
            }
        }
Example #14
0
        /// <summary>
        /// Internal method for leaving the network session. This disposes the
        /// session, removes the NetworkSessionComponent, and returns the user
        /// to the main menu screen.
        /// </summary>
        void LeaveSession()
        {
            // Destroy this NetworkSessionComponent.
            Dispose();

            // If we have a sessionEndMessage string explaining why the session has
            // ended (maybe this was a network disconnect, or perhaps the host kicked
            // us out?) create a message box to display this reason to the user.
            MessageBoxScreen messageBox;

            if (!string.IsNullOrEmpty(sessionEndMessage))
            {
                messageBox = new MessageBoxScreen(sessionEndMessage, false);
            }
            else
            {
                messageBox = null;
            }

            // At this point we want to return the user all the way to the main
            // menu screen. But what if they just joined a session? In that case
            // they went through this flow of screens:
            //
            //  - MainMenuScreen
            //  - CreateOrFindSessionsScreen
            //  - JoinSessionScreen (if joining, skipped if creating a new session)
            //  - LobbyScreeen
            //
            // If we have these previous screens on the history stack, and the user
            // backs out of the LobbyScreen, the right thing is just to pop off the
            // intermediate screens, returning them to the existing MainMenuScreen
            // instance without bothering to reload everything. But if the user is
            // in gameplay, or has been in gameplay and then returned to the lobby,
            // the screen stack will have been emptied.
            //
            // To do the right thing in both cases, we scan through the screen history
            // stack looking for a MainMenuScreen. If we find one, we pop any
            // subsequent screens so as to return back to it, while if we don't
            // find it, we just reset everything via the LoadingScreen.

            GameScreen[] screens = screenManager.GetScreens();

            // Look for the MainMenuScreen.
            for (int i = 0; i < screens.Length; i++)
            {
                if (screens[i] is MainMenuScreen)
                {
                    // If we found one, pop everything since then to return back to it.
                    for (int j = i + 1; j < screens.Length; j++)
                    {
                        screens[j].ExitScreen();
                    }

                    // Display the why-did-the-session-end message box.
                    if (messageBox != null)
                    {
                        screenManager.AddScreen(messageBox, null);
                    }

                    return;
                }
            }

            // If we didn't find an existing MainMenuScreen, reload everything.
            // The why-did-the-session-end message box will be displayed after
            // the loading screen has completed.
            LoadingScreen.Load(screenManager, false, null, new BackgroundScreen(),
                               new MainMenuScreen(),
                               messageBox);
        }