Base class for screens that contain a menu of options. The user can move up and down to select an entry, or cancel to back out of the screen.
Inheritance: GameScreen
Exemple #1
0
 /// <summary>
 /// Constructs a new menu entry with the specified text.
 /// </summary>
 public MenuEntry(MenuScreen menu, string text, EntryType type, GameScreen screen)
 {
     Text = text;
     Screen = screen;
     _type = type;
     _menu = menu;
     _scale = 0.9f;
     Alpha = 1.0f;
 }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            SimpleDemo1 simple1 = new SimpleDemo1();
            SimpleDemo2 simple2 = new SimpleDemo2();
            SimpleDemo3 simple3 = new SimpleDemo3();
            SimpleDemo4 simple4 = new SimpleDemo4();
            SimpleDemo5 simple5 = new SimpleDemo5();
            SimpleDemo6 simple6 = new SimpleDemo6();
            SimpleDemo7 simple7 = new SimpleDemo7();
            SimpleDemo8 simple8 = new SimpleDemo8();
            SimpleDemo9 simple9 = new SimpleDemo9();

            AdvancedDemo1 advanced1 = new AdvancedDemo1();
            AdvancedDemo2 advanced2 = new AdvancedDemo2();
            AdvancedDemo3 advanced3 = new AdvancedDemo3();
            AdvancedDemo4 advanced4 = new AdvancedDemo4();
            AdvancedDemo5 advanced5 = new AdvancedDemo5();

            GameDemo1 game1 = new GameDemo1();

            MenuScreen menuScreen = new MenuScreen("Farseer Samples");

            menuScreen.AddMenuItem("Simple Samples", EntryType.Separator, null);
            menuScreen.AddMenuItem(simple1.GetTitle(), EntryType.Screen, simple1);
            menuScreen.AddMenuItem(simple2.GetTitle(), EntryType.Screen, simple2);
            menuScreen.AddMenuItem(simple3.GetTitle(), EntryType.Screen, simple3);
            menuScreen.AddMenuItem(simple4.GetTitle(), EntryType.Screen, simple4);
            menuScreen.AddMenuItem(simple5.GetTitle(), EntryType.Screen, simple5);
            menuScreen.AddMenuItem(simple6.GetTitle(), EntryType.Screen, simple6);
            menuScreen.AddMenuItem(simple7.GetTitle(), EntryType.Screen, simple7);
            menuScreen.AddMenuItem(simple8.GetTitle(), EntryType.Screen, simple8);
            menuScreen.AddMenuItem(simple9.GetTitle(), EntryType.Screen, simple9);

            menuScreen.AddMenuItem("Advanced Samples", EntryType.Separator, null);
            menuScreen.AddMenuItem(advanced1.GetTitle(), EntryType.Screen, advanced1);
            menuScreen.AddMenuItem(advanced2.GetTitle(), EntryType.Screen, advanced2);
            menuScreen.AddMenuItem(advanced3.GetTitle(), EntryType.Screen, advanced3);
            menuScreen.AddMenuItem(advanced4.GetTitle(), EntryType.Screen, advanced4);
            menuScreen.AddMenuItem(advanced5.GetTitle(), EntryType.Screen, advanced5);

            menuScreen.AddMenuItem("Game Samples", EntryType.Separator, null);
            menuScreen.AddMenuItem(game1.GetTitle(), EntryType.Screen, game1);

            menuScreen.AddMenuItem("", EntryType.Separator, null);
            menuScreen.AddMenuItem("Exit", EntryType.ExitItem, null);

            ScreenManager.AddScreen(new BackgroundScreen());
            ScreenManager.AddScreen(menuScreen);
            ScreenManager.AddScreen(new LogoScreen(TimeSpan.FromSeconds(3.0)));
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            var simple5 = new SimpleDemo5();

            var menuScreen = new MenuScreen("Open Pool Projection");
            menuScreen.AddMenuItem("", EntryType.Separator, null);
            menuScreen.AddMenuItem(simple5.GetTitle(), EntryType.Screen, simple5);

            menuScreen.AddMenuItem("Exit", EntryType.ExitItem, null);

            ScreenManager.AddScreen(new BackgroundScreen());
            ScreenManager.AddScreen(menuScreen);
        }
        protected override void LoadContent()
        {
            base.LoadContent();

            ContentWrapper.Initialize(this);

            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _lineBatch = new LineBatch(GraphicsDevice);
            _quadRenderer = new QuadRenderer(GraphicsDevice);

            _input.LoadContent(GraphicsDevice.Viewport);
#if WINDOWS
            _counter.LoadContent();
#endif

            // Create rendertarget for transitions
            PresentationParameters pp = GraphicsDevice.PresentationParameters;
            _transitions.Add(new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, SurfaceFormat.Color, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents));

            _menuScreen = new MenuScreen();

            List<Type> DemosToLoad = new List<Type>();
            Assembly samplesFramework = Assembly.GetExecutingAssembly();
            foreach (Type sampleType in samplesFramework.GetTypes())
            {
                if (sampleType.IsSubclassOf(typeof(PhysicsDemoScreen)))
                {
                    DemosToLoad.Add(sampleType);
                }
            }
            DemosToLoad.Add(DemosToLoad[0]); // HACK: Load the first sample two times, since some delayed creation stuff with the rendertargets always breaks the first preview picture.
            Boolean firstPreview = true;
            foreach (Type sampleType in DemosToLoad)
            {
                PhysicsDemoScreen demoScreen = samplesFramework.CreateInstance(sampleType.ToString()) as PhysicsDemoScreen;
#if WINDOWS
                if (!firstPreview) { Console.WriteLine("Loading demo: " + demoScreen.GetTitle()); }
#endif
                RenderTarget2D preview = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth / 2, pp.BackBufferHeight / 2, false, SurfaceFormat.Color, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents);

                demoScreen.Framework = this;
                demoScreen.IsExiting = false;

                demoScreen.Sprites = _spriteBatch;
                demoScreen.Lines = _lineBatch;
                demoScreen.Quads = _quadRenderer;

                demoScreen.LoadContent();

                // "Abuse" transition rendertarget to render screen preview
                GraphicsDevice.SetRenderTarget(_transitions[0]);
                GraphicsDevice.Clear(Color.Transparent);

                _quadRenderer.Begin();
                _quadRenderer.Render(Vector2.Zero, new Vector2(_transitions[0].Width, _transitions[0].Height), null, true, ContentWrapper.Grey, Color.White * 0.3f);
                _quadRenderer.End();

                // Update ensures that the screen is fully visible, we "cover" it so that no physics are run
                demoScreen.Update(new GameTime(demoScreen.TransitionOnTime, demoScreen.TransitionOnTime), true, false);
                demoScreen.Draw(new GameTime());
                demoScreen.Draw(new GameTime());

                GraphicsDevice.SetRenderTarget(preview);
                GraphicsDevice.Clear(Color.Transparent);

                _spriteBatch.Begin();
                _spriteBatch.Draw(_transitions[0], preview.Bounds, Color.White);
                _spriteBatch.End();

                GraphicsDevice.SetRenderTarget(null);

                demoScreen.ExitScreen();
                demoScreen.Update(new GameTime(demoScreen.TransitionOffTime, demoScreen.TransitionOffTime), true, false);
                if (!firstPreview)
                {
                    _menuScreen.AddMenuItem(demoScreen, preview);
                }
                else
                {
                    firstPreview = false;
                }
            }

            AddScreen(new BackgroundScreen());
            AddScreen(_menuScreen);
            AddScreen(new LogoScreen(new TimeSpan(0, 0, 0, 3)));

            ResetElapsedTime();
        }