コード例 #1
0
        /// <summary>
        /// The constructor is private: loading screens should
        /// be activated via the static Load method instead.
        /// </summary>
        private LoadingScreen(ScreenManager screenManager, bool loadingIsSlow,
                              GameScreen[] screensToLoad)
        {
            this.loadingIsSlow = loadingIsSlow;
            this.screensToLoad = screensToLoad;

            TransitionOnTime = TimeSpan.FromSeconds(0.5);

            // If this is going to be a slow load operation, create a background
            // thread that will update the network session and draw the load screen
            // animation while the load is taking place.
            if (loadingIsSlow)
            {
                backgroundThread = new Thread(BackgroundWorkerThread);
                backgroundThreadExit = new ManualResetEvent(false);

                graphicsDevice = screenManager.GraphicsDevice;

                // Look up some services that will be used by the background thread.
                IServiceProvider services = screenManager.Game.Services;

                networkSession = (NetworkSession)services.GetService(
                                                            typeof(NetworkSession));

                messageDisplay = (IMessageDisplay)services.GetService(
                                                            typeof(IMessageDisplay));
            }
        }
コード例 #2
0
        /// <summary>
        /// The constructor is private: external callers should use the Create method.
        /// </summary>
        NetworkSessionComponent(ScreenManager screenManager,
                                NetworkSession networkSession)
            : base(screenManager.Game)
        {
            this.screenManager = screenManager;
            this.networkSession = networkSession;

            // Hook up our session event handlers.
            networkSession.GamerJoined += GamerJoined;
            networkSession.GamerLeft += GamerLeft;
            networkSession.SessionEnded += NetworkSessionEnded;
        }
コード例 #3
0
        /// <summary>
        /// Activates the loading screen.
        /// </summary>
        public static void Load(ScreenManager screenManager, bool loadingIsSlow,
                                PlayerIndex? controllingPlayer,
                                params GameScreen[] screensToLoad)
        {
            // Tell all the current screens to transition off.
            foreach (GameScreen screen in screenManager.GetScreens())
                screen.ExitScreen();

            // Create and activate the loading screen.
            LoadingScreen loadingScreen = new LoadingScreen(screenManager,
                                                            loadingIsSlow,
                                                            screensToLoad);

            screenManager.AddScreen(loadingScreen, controllingPlayer);
        }
コード例 #4
0
        /// <summary>
        /// Public method called when the user wants to leave the network session.
        /// Displays a confirmation message box, then disposes the session, removes
        /// the NetworkSessionComponent, and returns them to the main menu screen.
        /// </summary>
        public static void LeaveSession(ScreenManager screenManager,
                                        PlayerIndex playerIndex)
        {
            NetworkSessionComponent self = FindSessionComponent(screenManager.Game);

            if (self != null)
            {
                // Display a message box to confirm the user really wants to leave.
                string message;

                if (self.networkSession.IsHost)
                    message = Resources.ConfirmEndSession;
                else
                    message = Resources.ConfirmLeaveSession;

                MessageBoxScreen confirmMessageBox = new MessageBoxScreen(message);

                // Hook the messge box ok event to actually leave the session.
                confirmMessageBox.Accepted += delegate
                {
                    self.LeaveSession();
                };

                screenManager.AddScreen(confirmMessageBox, playerIndex);
            }
        }
コード例 #5
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(screenManager.Game as ParentGame),
                                                               errorScreen);
            }
        }
コード例 #6
0
        /// <summary>
        /// Creates a new NetworkSessionComponent.
        /// </summary>
        public static void Create(ScreenManager screenManager,
                                  NetworkSession networkSession)
        {
            Game game = screenManager.Game;

            // Register this network session as a service.
            game.Services.AddService(typeof(NetworkSession), networkSession);

            // Create a NetworkSessionComponent, and add it to the Game.
            game.Components.Add(new NetworkSessionComponent(screenManager,
                                                            networkSession));
        }
コード例 #7
0
ファイル: ParentGame.cs プロジェクト: alittle1234/XNA_Project
        void MenuPostLoad()
        {
            // SCREENS FROM NETWORK STATE MANAGEMENT
            screenManager = new ScreenManager(this);
            Components.Add(screenManager);

            //bloom = new BloomComponent(this);

            //Components.Add(bloom);

            backgroundThread.Start();
            backgroundThread.Name = "Initialize Screens";
            ScreensStarted = true;
        }