Пример #1
0
        public void AddScreen(GameScreen screen)
        {
            screen.ScreenManager = this;
            screen.IsExiting = false;

            if (isInitialized)
                screen.Activate(false);
            screens.Add(screen);
        }
Пример #2
0
        /// <summary>
        /// Adds a new screen to the screen manager.
        /// </summary>
        public void AddScreen(GameScreen screen, PlayerIndex?controllingPlayer)
        {
            screen.ControllingPlayer = controllingPlayer;
            screen.ScreenManager     = this;
            screen.IsExiting         = false;

            // If we have a graphics device, tell the screen to load content.
            if (isInitialized)
            {
                screen.Activate(false);
            }

            screens.Add(screen);
        }
Пример #3
0
        /// <summary>
        /// Adds a new screen to the screen manager.
        /// </summary>
        public void AddScreen(GameScreen screen, PlayerIndex?controllingPlayer)
        {
            screen.ControllingPlayer = controllingPlayer;
            screen.ScreenManager     = this;
            screen.IsExiting         = false;

            // If we have a graphics device, tell the screen to load content.
            if (isInitialized)
            {
                screen.Activate(false);
            }

            screens.Add(screen);

            // update the TouchPanel to respond to gestures this screen is interested in
        }
Пример #4
0
        /// <summary>
        /// Adds a new screen to the screen manager.
        /// </summary>
        public void AddScreen(GameScreen screen)
        {
            screen.ScreenManager = this;
            screen.IsExiting     = false;

            // If we have a graphics device, tell the screen to load content.
            if (_isInitialized)
            {
                if (screen.content == null)
                {
                    screen.content = new ContentManager(Game.Services, Game.Content.RootDirectory);
                }
                screen.Activate(false);
            }

            _screens.Add(screen);

#if WINDOWS_PHONE || WINDOWS || ANDROID
            // update the TouchPanel to respond to gestures this screen is interested in
            TouchPanel.EnabledGestures = screen.EnabledGestures;
#endif
        }
Пример #5
0
        public bool Activate(bool instancePreserved)
        {
#if !WINDOWS_PHONE
            return(false);
#else
            // If the game instance was preserved, the game wasn't dehydrated so our screens still exist.
            // We just need to activate them and we're ready to go.
            if (instancePreserved)
            {
                // Make a copy of the master screen list, to avoid confusion if
                // the process of activating one screen adds or removes others.
                tempScreensList.Clear();

                foreach (GameScreen screen in screens)
                {
                    tempScreensList.Add(screen);
                }

                foreach (GameScreen screen in tempScreensList)
                {
                    screen.Activate(true);
                }
            }

            // Otherwise we need to refer to our saved file and reconstruct the screens that were present
            // when the game was deactivated.
            else
            {
                // Try to get the screen factory from the services, which is required to recreate the screens
                IScreenFactory screenFactory = Game.Services.GetService(typeof(IScreenFactory)) as IScreenFactory;
                if (screenFactory == null)
                {
                    throw new InvalidOperationException(
                              "Game.Services must contain an IScreenFactory in order to activate the ScreenManager.");
                }

                // Open up isolated storage
                using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    // Check for the file; if it doesn't exist we can't restore state
                    if (!storage.FileExists(StateFilename))
                    {
                        return(false);
                    }

                    // Read the state file so we can build up our screens
                    using (IsolatedStorageFileStream stream = storage.OpenFile(StateFilename, FileMode.Open))
                    {
                        XDocument doc = XDocument.Load(stream);

                        // Iterate the document to recreate the screen stack
                        foreach (XElement screenElem in doc.Root.Elements("GameScreen"))
                        {
                            // Use the factory to create the screen
                            Type       screenType = Type.GetType(screenElem.Attribute("Type").Value);
                            GameScreen screen     = screenFactory.CreateScreen(screenType);

                            // Rehydrate the controlling player for the screen
                            PlayerIndex?controllingPlayer = screenElem.Attribute("ControllingPlayer").Value != ""
                                ? (PlayerIndex)Enum.Parse(typeof(PlayerIndex), screenElem.Attribute("ControllingPlayer").Value, true)
                                : (PlayerIndex?)null;
                            screen.ControllingPlayer = controllingPlayer;

                            // Add the screen to the screens list and activate the screen
                            screen.ScreenManager = this;
                            screens.Add(screen);
                            screen.Activate(false);

                            // update the TouchPanel to respond to gestures this screen is interested in
                            TouchPanel.EnabledGestures = screen.EnabledGestures;
                        }
                    }
                }
            }

            return(true);
#endif
        }
Пример #6
0
        /// <summary>
        /// Adds a new screen to the screen manager.
        /// </summary>
        public void AddScreen(GameScreen screen, PlayerIndex? controllingPlayer)
        {
            screen.ControllingPlayer = controllingPlayer;
            screen.ScreenManager = this;
            screen.IsExiting = false;

            // If we have a graphics device, tell the screen to load content.
            if (isInitialized)
            {
                screen.Activate(false);
            }

            screens.Add(screen);

            // update the TouchPanel to respond to gestures this screen is interested in
            TouchPanel.EnabledGestures = screen.EnabledGestures;
        }
Пример #7
0
        /// <summary>
        /// Adds a new screen to the screen manager.
        /// </summary>
        public void AddScreen(GameScreen screen, PlayerIndex? controllingPlayer)
        {
            screen.ControllingPlayer = controllingPlayer;
            screen.ScreenManager = this;
            screen.IsExiting = false;

            // If we have a graphics device, tell the screen to load content.
            if (isInitialized)
            {
                screen.Activate(false);
            }

            screens.Add(screen);
        }
Пример #8
0
        public bool Activate(bool instancePreserved)
#endif
        {
#if !WINDOWS_PHONE && !WINDOWS && !ANDROID
            return(false);
#else
            // If the game instance was preserved, the game wasn't dehydrated so our screens still exist.
            // We just need to activate them and we're ready to go.
            if (instancePreserved)
            {
                // Make a copy of the master screen list, to avoid confusion if
                // the process of activating one screen adds or removes others.
                _tempScreensList.Clear();

                foreach (GameScreen screen in _screens)
                {
                    _tempScreensList.Add(screen);
                }

                foreach (GameScreen screen in _tempScreensList)
                {
                    screen.Activate(true);
                }
            }

            // Otherwise we need to refer to our saved file and reconstruct the screens that were present
            // when the game was deactivated.
            else
            {
                // Try to get the screen factory from the services, which is required to recreate the screens
                var screenFactory = Game.Services.GetService(typeof(IScreenFactory)) as IScreenFactory;
                if (screenFactory == null)
                {
                    throw new InvalidOperationException(
                              "Game.Services must contain an IScreenFactory in order to activate the ScreenManager.");
                }

#if WINDOWS8
                StorageFolder folder = ApplicationData.Current.LocalFolder;
                try
                {
                    using (Stream file = await folder.OpenStreamForReadAsync(StateFilename))
                    {
#else
                // Open up isolated storage
                using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    // Check for the file; if it doesn't exist we can't restore state
                    if (!storage.FileExists(StateFilename))
                    {
                        return(false);
                    }

                    // Read the state file so we can build up our screens
                    using (IsolatedStorageFileStream file = storage.OpenFile(StateFilename, FileMode.Open))
                    {
#endif
                        XDocument doc = XDocument.Load(file);

                        // Iterate the document to recreate the screen stack
                        foreach (XElement screenElem in doc.Root.Elements("GameScreen"))
                        {
                            // Use the factory to create the screen
                            Type       screenType = Type.GetType(screenElem.Attribute("Type").Value);
                            GameScreen screen     = screenFactory.CreateScreen(screenType);

                            if (screen != null)
                            {
                                // Add the screen to the screens list and activate the screen
                                screen.ScreenManager = this;
                                _screens.Add(screen);

                                if (screen.content == null)
                                {
                                    screen.content = new ContentManager(Game.Services, Game.Content.RootDirectory);
                                }
                                screen.Activate(false);

                                // update the TouchPanel to respond to gestures this screen is interested in
                                TouchPanel.EnabledGestures = screen.EnabledGestures;
                            }
                        }
                    }
                }
#if WINDOWS8
                catch (FileNotFoundException)
                {
                    return(false);
                }
#endif
            }

            return(true);
#endif
        }
Пример #9
0
        public void AddScreen(GameScreen screen, PlayerIndex? controllingPlayer)
        {
            screen.ControllingPlayer = controllingPlayer;
            screen.ScreenManager = this;
            screen.IsExiting = false;

            if (isInitialized)
            {
                screen.Activate(false);
            }

            screens.Add(screen);

            TouchPanel.EnabledGestures = screen.EnabledGestures;
        }