/// <summary>
		///     Initializes a new instance of the <see cref="MonoGameNoesisGUIWrapper" /> class.
		/// </summary>
		/// <param name="game">The MonoGame game instance.</param>
		/// <param name="graphics">Graphics device manager of the game instance.</param>
		/// <param name="rootXamlPath">Local XAML file path - will be used as the UI root element</param>
		/// <param name="stylePath">(optional) Local XAML file path - will be used as global ResourceDictionary (UI style)</param>
		/// <param name="dataLocalPath">(optional) Local path to the folder which will be used as root for other paths</param>
		/// <remarks>
		///     PLEASE NOTE: .XAML-files should be prebuilt to .NSB-files by NoesisGUI Build Tool).
		/// </remarks>
		public MonoGameNoesisGUIWrapper(
			Game game,
			GraphicsDeviceManager graphics,
			string rootXamlPath,
			string stylePath = null,
			string dataLocalPath = "Data")
		{
			this.game = game;
			this.graphics = graphics;

			this.graphicsDevice = graphics.GraphicsDevice;
			var device = ((Device)this.graphicsDevice.Handle);
			this.DeviceDX11 = device;

			GUI.InitDirectX11(device.NativePointer);

			GUI.AddResourceProvider(dataLocalPath);

			this.uiRenderer = this.CreateRenderer(rootXamlPath, stylePath);

			this.inputManager = new MonoGameNoesisGUIWrapperInputManager(this.uiRenderer);
			game.Window.TextInput += (sender, args) => this.inputManager.OnTextInput(args);
			game.Window.ClientSizeChanged += this.WindowClientSizeChangedHandler;
			this.graphicsDevice.DeviceReset += this.DeviceResetHandler;
			this.graphicsDevice.DeviceLost += this.DeviceLostHandler;
			this.UpdateSize();
		}
Example #2
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            if (gamestate == GameState.Loading)
            {
                Game.LoadingScene.draw((float)e.Time);

                SwapBuffers();
            }
            else if (gamestate == GameState.Game)
            {
                GLHelper.Clear();
                GL.Enable(EnableCap.DepthTest);

                var mat = Matrix4.CreateTranslation(cam.Position);
                ChunkShader.Use();

                ChunkShader.SetMatrix("projection", GLHelper.proj);
                ChunkShader.SetMatrix("view", cam.View);
                ChunkShader.SetMatrix("transform", Matrix4.Identity);

                tex.bind();
                world.Draw();

                UIRenderer.DrawElement(Crosshair);


                SwapBuffers();
            }
        }
Example #3
0
        public EditorBase(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // Get services from the global service container.
            var services = (ServiceContainer)ServiceLocator.Current;
            UIContentManager = services.GetInstance<ContentManager>("UIContent");
            InputService = services.GetInstance<IInputService>();
            AnimationService = services.GetInstance<IAnimationService>();
            GraphicsService = services.GetInstance<IGraphicsService>();
            GameObjectService = services.GetInstance<IGameObjectService>();
            UIService = services.GetInstance<IUIService>();

            // Create a local service container which can be modified in samples:
            // The local service container is a child container, i.e. it inherits the
            // services of the global service container. Samples can add new services
            // or override existing entries without affecting the global services container
            // or other samples.
            Services = services.CreateChildContainer();

            // Load a UI theme, which defines the appearance and default values of UI controls.
            Theme theme = UIContentManager.Load<Theme>("BlendBlue/Theme");

            FigureRenderer = new FigureRenderer(GraphicsService, 2000);
            DebugRenderer = new DebugRenderer(GraphicsService, UIContentManager.Load<SpriteFont>("BlendBlue/Default"));
            UIRenderer = new UIRenderer(GraphicsService.GraphicsDevice, theme);

            UIScreen = new UIScreen("Main Screen", UIRenderer)
            {
                Background = Color.TransparentBlack,
            };

            UIService.Screens.Add(UIScreen);

            Scene = new Scene();
        }
Example #4
0
 public override void Draw(GameTime gameTime)
 {
     title.Draw(new Vector2(0, 0));
     chara.Draw();
     UIRenderer.Render();
     base.Draw(gameTime);
 }
Example #5
0
    /// <summary>
    /// Initializes a new instance of the <see cref="GuiGraphicsScreen"/> class.
    /// </summary>
    /// <param name="services">The service locator.</param>
    public GuiGraphicsScreen(IServiceLocator services)
      : base(services.GetInstance<IGraphicsService>())
    {
      Name = "GUI"; // Just for debugging.

      // Get required services.
      _inputService = services.GetInstance<IInputService>();
      _uiService = services.GetInstance<IUIService>();
      var contentManager = services.GetInstance<ContentManager>("UIContent");

      // Load a UI theme and create the UI renderer and the UI screen. See the
      // DigitalRune Game UI documentation and samples for more details.
      var theme = contentManager.Load<Theme>("UI Themes/BlendBlue/Theme");
      var renderer = new UIRenderer(GraphicsService.GraphicsDevice, theme);
      UIScreen = new UIScreen("Default", renderer)
      {
        Background = Color.Transparent,
        ZIndex = int.MaxValue,
      };
      _uiService.Screens.Add(UIScreen);

      // When the background is hidden, the UIScreen should block all input.
      UIScreen.InputProcessed += (s, e) =>
                                 {
                                   if (HideBackground)
                                   {
                                     // Set all input devices to 'handled'.
                                     _inputService.IsGamePadHandled(LogicalPlayerIndex.Any);
                                     _inputService.IsKeyboardHandled = true;
                                     _inputService.IsMouseOrTouchHandled = true;
                                   }
                                 };
    }
Example #6
0
    public WindowsPhoneSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      // Add a DelegateGraphicsScreen as the first graphics screen to the graphics
      // service. This lets us do the rendering in the Render method of this class.
      var graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, graphicsScreen);

      // Load a UI theme, which defines the appearance and default values of UI controls.
      Theme theme = ContentManager.Load<Theme>("UI Themes/WindowsPhone7/ThemeDark");

      // Create a UI renderer, which uses the theme info to renderer UI controls.
      UIRenderer renderer = new UIRenderer(Game, theme);

      // Create a UIScreen and add it to the UI service. The screen is the root of the 
      // tree of UI controls. Each screen can have its own renderer.
      _uiScreen = new UIScreen("SampleUIScreen", renderer)
      {
        // Make the screen transparent.
        Background = new Color(0, 0, 0, 0),
      };
      UIService.Screens.Add(_uiScreen);

      // Open a window.
      var window = new WpWindow();
      window.Show(_uiScreen);
    }
        /// <summary> Initializes the component. Override this method to load any non-
        ///           graphics resources and query for any required services.</summary>
        public override void Initialize()
        {
            var contentManager = ServiceLocator.Current.GetInstance<ContentManager>();
            var theme = Game.Content.Load<Theme>("UI/UITheme");
            var renderer = new UIRenderer(Game, theme);
            var gameSettings = ServiceLocator.Current.GetInstance<GameSettings>();

            _gameBoardManager = new GameBoardManagerObject(_levelObjects[GameSettings.LevelNumber]);

            var content = ServiceLocator.Current.GetInstance<ContentManager>();
            Song music = content.Load<Song>(_levelObjects[GameSettings.LevelNumber]._backgroundSong);
            MediaPlayer.Play(music);
            MediaPlayer.IsRepeating = true;

            _aiHandler = new AIHandlerObject(_gameBoardManager);
            _camera = new CameraObject();

            // Create the inital game objects
            var gameObjectService = ServiceLocator.Current.GetInstance<IGameObjectService>();
            gameObjectService.Objects.Add(_camera);
            gameObjectService.Objects.Add(_gameBoardManager);
            gameObjectService.Objects.Add(_aiHandler);

            _gameHUD = new MainGameHUD("GameHUD", renderer, _gameBoardManager.TurnManager);

            var gameLog = ServiceLocator.Current.GetInstance<GameLog>();
            gameLog.ResetLog();

            var uiService = ServiceLocator.Current.GetInstance<IUIService>();
            uiService.Screens.Add(_gameHUD);
        }
        public WindowsPhoneSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // Disable mouse centering and show the mouse cursor.
            EnableMouseCentering = false;

            // Add a DelegateGraphicsScreen as the first graphics screen to the graphics
            // service. This lets us do the rendering in the Render method of this class.
            _graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };
            GraphicsService.Screens.Insert(0, _graphicsScreen);

            // Load a UI theme, which defines the appearance and default values of UI controls.
            _uiContentManager = new ContentManager(Services, "WindowsPhone7Theme");
            Theme theme = _uiContentManager.Load <Theme>("ThemeDark");

            // Create a UI renderer, which uses the theme info to renderer UI controls.
            UIRenderer renderer = new UIRenderer(Game, theme);

            // Create a UIScreen and add it to the UI service. The screen is the root of the
            // tree of UI controls. Each screen can have its own renderer.
            _uiScreen = new UIScreen("SampleUIScreen", renderer)
            {
                // Make the screen transparent.
                Background = new Color(0, 0, 0, 0),
            };
            UIService.Screens.Add(_uiScreen);

            // Open a window.
            var window = new WpWindow(Game);

            window.Show(_uiScreen);
        }
Example #9
0
        public override void Draw()
        {
            UIRenderer.ListBox(this);

            Items.ForEach(item => UIRenderer.RectangleComponent(item));

            Childs.ForEach(c => c.Draw());
        }
Example #10
0
 /// <summary>
 /// Loads the SpriteBatch and font.
 /// </summary>
 protected override void LoadContent()
 {
     spTex  = content.Load <Texture2D>("Content\\pgi");
     spRend = new UIRenderer(spTex, game);
     spRend.SetAlpha(0.0f);
     spRend.AddFadeEffect(1.0f, 800);
     spRend.AddBloomEffect(0.0f, 800);
 }
Example #11
0
        public override void Draw(GameTime gameTime)
        {
            //SpriteRenderer.Begin();

            spRend.Draw();
            //SpriteRenderer.End();
            UIRenderer.Render();
            base.Draw(gameTime);
        }
Example #12
0
        public static void Attach(Main main, Entity entity, UIRenderer ui, Property <float> health, Property <float> rotation, Property <bool> noteActive, Property <bool> phoneActive)
        {
            Sprite damageOverlay = new Sprite();

            damageOverlay.Image.Value       = "Images\\damage";
            damageOverlay.AnchorPoint.Value = new Vector2(0.5f);
            ui.Root.Children.Add(damageOverlay);

            // Center the damage overlay and scale it to fit the screen
            damageOverlay.Add(new Binding <Vector2, Point>(damageOverlay.Position, x => new Vector2(x.X * 0.5f, x.Y * 0.5f), main.ScreenSize));
            damageOverlay.Add(new Binding <Vector2>(damageOverlay.Scale, () => new Vector2(main.ScreenSize.Value.X / damageOverlay.Size.Value.X, main.ScreenSize.Value.Y / damageOverlay.Size.Value.Y), main.ScreenSize, damageOverlay.Size));
            damageOverlay.Add(new Binding <float, float>(damageOverlay.Opacity, x => 1.0f - x, health));

#if VR
            if (main.VR)
            {
                VirtualReticle reticleController = entity.GetOrCreate <VirtualReticle>();
                reticleController.Add(new Binding <float>(reticleController.Rotation, rotation));

                ModelNonPostProcessed reticle = entity.Create <ModelNonPostProcessed>();
                reticle.Filename.Value       = "Models\\plane";
                reticle.EffectFile.Value     = "Effects\\VirtualUI";
                reticle.DiffuseTexture.Value = "Images\\reticle";
                reticle.Add(new Binding <Matrix>(reticle.Transform, reticleController.Transform));
                reticle.Add(new Binding <bool>(reticle.Enabled, () => !main.Paused && !phoneActive && !noteActive, main.Paused, phoneActive, noteActive));
            }
            else
#endif
            {
                Sprite reticle = new Sprite();
                reticle.Image.Value       = "Images\\reticle";
                reticle.AnchorPoint.Value = new Vector2(0.5f);
                reticle.Opacity.Value     = 0.5f;
                ui.Root.Children.Add(reticle);

                reticle.Add(new Binding <bool>(reticle.Visible, main.Settings.EnableReticle));

                // Center the reticle
                reticle.Add(new Binding <Vector2, Point>(reticle.Position, x => new Vector2(x.X * 0.5f, x.Y * 0.5f), main.ScreenSize));
            }

            UIComponent targets = new UIComponent();
            ui.Root.Children.Add(targets);

            TargetUI targetUi = entity.GetOrCreate <TargetUI>();
            targetUi.Add(new ListBinding <UIComponent>(targetUi.Sprites, targets.Children));

            targets.Add(new ListBinding <UIComponent, Transform>(targets.Children, TargetFactory.Positions, delegate(Transform target)
            {
                Sprite sprite            = new Sprite();
                sprite.Image.Value       = "Images\\target";
                sprite.AnchorPoint.Value = new Vector2(0.5f, 0.5f);
                sprite.UserData.Value    = target;
                sprite.Add(new Binding <bool>(sprite.Visible, target.Enabled));
                return(sprite);
            }));
        }
Example #13
0
        public override void Draw()
        {
            Text.X = this.X + this.Width / 2;
            Text.Y = this.Y + this.Hieght / 2;

            UIRenderer.ButtonRect(this);
            UIRenderer.TextBlock(Text);

            Childs.ForEach(ui => ui.Draw());
        }
Example #14
0
        public UIItem(Layer owner, UILayout layout, int depth, bool multiclick = false)
        {
            Layer = owner;

            this.multiClick = multiclick;
            this._Depth     = depth;
            this.Layout     = layout;
            UIRenderer.Add(owner, this);

            Layout.Init(this);
        }
Example #15
0
        //AUDIO
        public void Render(RenderWindow window)
        {
            //HANDLE EVENTS
            window.KeyPressed         += HandleInput;
            window.MouseButtonPressed += HandleMouseButtonInput;
            window.MouseMoved         += HandleMouseInput;

            Renderer.Render(window, objects);
            UIRenderer.RenderButtons(window, buttons);
            AnimationRenderer.Render(animations, window);
            TextRenderer.Render(text, window);
        }
Example #16
0
 public virtual void Update(DeltaTime dt)
 {
     if (IsDirty || Layout.IsDirty)
     {
         if (Layout.IsDirty)
         {
             Layout.Update();
         }
         UIRenderer.Update(this);
         IsDirty = false;
     }
 }
Example #17
0
        public virtual void Init()
        {
            ColorProgram.Init();
            MatrixProgram.Init();
            FBOProgram.Init();
            ParticleProgram.Init();
            GaussianBlurProgram.Init();
            DarkenProgram.Init();

            UIRenderer.Init();
            UIRenderer.Texture = Assets.GetSprite("interface");
        }
Example #18
0
        /// <summary>
        /// Loads the SpriteBatch and font.
        /// </summary>
        protected override void LoadContent()
        {
            menu  = content.Load <Texture2D>("Content\\menu");
            chart = content.Load <Texture2D>("Content\\chars");
            title = new UIRenderer(menu, game);
            chara = new UIRenderer(chart, game);
            chara.AddFadeEffect(0.0f, 1500);

            chara.SetPosition(new Vector2(430, 460));
            title.SetAlpha(0.0f);
            title.AddBloomEffect(0.0f, 800);
            title.AddFadeEffect(1.0f, 800);
        }
Example #19
0
 protected virtual void CreatePipeline()
 {
     // create the render pipeline
     UIRenderer = new UIRenderer(Services);
     RenderSystem.Pipeline.Renderers.Add(new RenderTargetSetter(Services)
     {
         ClearColor = Color.Green, EnableClearStencil = true
     });
     RenderSystem.Pipeline.Renderers.Add(new DelegateRenderer(Services)
     {
         Render = SpecificDrawBeforeUI
     });
     RenderSystem.Pipeline.Renderers.Add(UIRenderer);
 }
        /// <summary> Constructor.</summary>
        ///
        /// <param name="game">    The game.</param>
        /// <param name="allyWin"> true to ally window.</param>
        public EndLevelComponent(Game game, bool allyWin)
            : base(game)
        {
            var content = ServiceLocator.Current.GetInstance<ContentManager>();
            var theme = content.Load<Theme>("UI/UITheme");
            var renderer = new UIRenderer(this.Game, theme);

            _endLevelUI = new UIScreen("EndLevelUI", renderer);

            var uiService = ServiceLocator.Current.GetInstance<IUIService>();
            uiService.Screens.Add(_endLevelUI);

            _returnToMenu = new Button
            {
                Margin = new Vector4F(10),
                Width = 300,
                Height = 60,
                Y = 480,
                X = 200,
                Content = new TextBlock { Text = "Return to Menu", }
            };
            _returnToMenu.Click += (s, e) => EndToMenu();

            _background = new Image
            {
                Texture = content.Load<Texture2D>("UI/background"),
            };

            _endLevelUI.Children.Add(_background);
            _endLevelUI.Children.Add(_returnToMenu);

            if (GameSettings.LevelNumber == 1)
            {
                GameSettings.LevelNumber = 0;
                LoadCredits();
            }
            else if(allyWin)
            {
                GameSettings.LevelNumber++;
                AllyWin();
            }
            else
            {
                EnemyWin();
            }

            MediaPlayer.Play(_backgroundMusic);
            MediaPlayer.IsRepeating = true;
        }
Example #21
0
 public World()
 {
     Children = new List<IRenderable>();
     LinesPool = new Line2dPool();
     CollisionConf = new DefaultCollisionConfiguration();
     Dispatcher = new CollisionDispatcher(CollisionConf);
     Broadphase = new DbvtBroadphase();
     PhysicalWorld = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
     PhysicalWorld.Gravity = new Vector3(0, -10, 0);
     PhysicalWorld.SolverInfo.SolverMode = SolverModes.InterleaveContactAndFrictionConstraints;
     PhysicalWorld.SolverInfo.Restitution = 0;
     CollisionObjects = new Dictionary<IRenderable, CollisionObject>();
     UI = new UIRenderer();
     if(Root == null)
         Root = this;
 }
Example #22
0
    public TilingSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      // Add a DelegateGraphicsScreen as the first graphics screen to the graphics
      // service. This lets us do the rendering in the Render method of this class.
      var graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, graphicsScreen);

      // Load a UI theme, which defines the appearance and default values of UI controls.
      Theme theme = ContentManager.Load<Theme>("UI Themes/TilingSample/Theme");

      // Create a UI renderer, which uses the theme info to renderer UI controls.
      UIRenderer renderer = new UIRenderer(Game, theme);

      // Create a UIScreen and add it to the UI service. The screen is the root of the 
      // tree of UI controls. Each screen can have its own renderer.
      _uiScreen = new UIScreen("SampleUIScreen", renderer);
      UIService.Screens.Add(_uiScreen);

      // Create a window using the default style "Window".
      var stretchedWindow = new Window
      {
        X = 100,
        Y = 100,
        Width = 480,
        Height = 320,
        CanResize = true,
      };
      _uiScreen.Children.Add(stretchedWindow);

      // Create a window using the style "TiledWindow".
      var tiledWindow = new Window
      {
        X = 200,
        Y = 200,
        Width = 480,
        Height = 320,
        CanResize = true,
        Style = "TiledWindow",
      };
      _uiScreen.Children.Add(tiledWindow);

      // Check file TilingSampleContent/Theme.xml to see how the styles are defined.
    }
Example #23
0
        public override void LoadContent()
        {
            var theme = _contentService.Load<Theme>("Theme");

            var renderer = new UIRenderer(_game, theme);

            _screen = new UIScreen("Default", renderer)
            {
                Background = new Color(0, 0, 0, 0),
            };

            _uiService.Screens.Add(_screen);

            AddWindowComponents();

            base.LoadContent();
        }
Example #24
0
    private void DrawGraph()
    {
        //update start point
        float xOffset = Time.time - (sampleTime * 60f);

        for (int k = 0; k < allData.Length; k++)
        {
            //update all points
            int usedIndex = 0;
            if (allData[k].valueList.Count < 2)
            {
                return;
            }
            //尋訪所有數值
            List <Vector2> points = new List <Vector2> {
            };
            for (int i = 0; i < allData[k].valueList.Count; i++)
            {
                float deltaTime = allData[k].valueList[i].x - xOffset;
                //超出界線
                if (deltaTime < 0)
                {
                    float nextTime = allData[k].valueList[i + 1].x; float nextValue = allData[k].valueList[i + 1].y;
                    float oldTime = allData[k].valueList[i].x; float oldValue = allData[k].valueList[i].y;
                    if (oldTime < nextTime)//計算超出點跟下一點交會於畫框邊緣之值
                    {
                        float slope = (nextValue - oldValue) / (nextTime - oldTime);
                        allData[k].valueList[i] = new Vector2(xOffset, oldValue - deltaTime * slope);
                    }
                    else
                    {
                        allData[k].valueList.RemoveAt(i);
                    }
                }
                Vector2 nowPos = new Vector2(deltaTime * xSize, (allData[k].valueList[i].y - yMin) * ySize);
                //輸入線段圖型數值
                points.Add(nowPos);
                usedIndex++;
            }
            UIRenderer LineRoot = allData[k].line.GetComponent <UIRenderer>();
            LineRoot.points    = points;
            LineRoot.color     = allData[k].lineColor;
            LineRoot.thickness = allData[k].thickness;
        }
    }
        // Loads stuff. This method is executed in parallel, therefore we can only do
        // thread-safe things.
        public void LoadStuff()
        {
            // Load a UI theme, which defines the appearance and default values of UI controls.
            _uiContentManager = new ContentManager(_services, "NeoforceTheme");
            var theme = _uiContentManager.Load <Theme>("ThemeRed");

            // Create a UI renderer, which uses the theme info to renderer UI controls.
            UIRenderer renderer = new UIRenderer(Game, theme);

            // Create a UIScreen and add it to the UI service. The screen is the root of the
            // tree of UI controls. Each screen can have its own renderer.
            _uiScreen = new UIScreen("SampleUI", renderer)
            {
                // Make the screen transparent.
                Background = new Color(0, 0, 0, 0),
            };

            // Simulate more loading time.
            System.Threading.Thread.Sleep(2000);
        }
Example #26
0
        protected override void LoadContent()
        {
            // Load a UI theme, which defines the appearance and default values of UI controls.
            var content = new ContentManager(Game.Services, "NeoforceTheme");
            var theme   = content.Load <Theme>("ThemeRed");
            // Create a UI renderer, which uses the theme info to renderer UI controls.
            var renderer = new UIRenderer(Game, theme);

            // Create a UIScreen and add it to the UI service. The screen is the root of
            // the tree of UI controls. Each screen can have its own renderer.
            _screen = new UIScreen("Default", renderer)
            {
                // Make the screen transparent.
                Background = new Color(0, 0, 0, 0),
            };

            // Add the screen to the UI service.
            _uiService.Screens.Add(_screen);

            base.LoadContent();
        }
Example #27
0
    // Loads stuff. This method is executed in parallel, therefore we can only do 
    // thread-safe things.
    public void LoadStuff()
    {
      // Load a UI theme, which defines the appearance and default values of UI controls.
      var contentManager = _services.GetInstance<ContentManager>();
      var theme = contentManager.Load<Theme>("UI Themes/BlendBlue/Theme");

      // Create a UI renderer, which uses the theme info to renderer UI controls.
      UIRenderer renderer = new UIRenderer(Game, theme);

      // Create a UIScreen and add it to the UI service. The screen is the root of the 
      // tree of UI controls. Each screen can have its own renderer. 
      _uiScreen = new UIScreen("SampleUI", renderer)
      {
        // Make the screen transparent.
        Background = new Color(0, 0, 0, 0),
      };

      // Simulate more loading time.
#if NETFX_CORE
      System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(2)).Wait();
#else
      System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2));
#endif
    }
        /// <summary> Initializes the component. Override this method to load any non-
        ///           graphics resources and query for any required services.</summary>
        public override void Initialize()
        {
            var content = ServiceLocator.Current.GetInstance<ContentManager>();
            var theme = content.Load<Theme>("UI/UITheme");
            var renderer = new UIRenderer(this.Game, theme);

            _menuUI = new UIScreen("MenuUI", renderer);

            var uiService = ServiceLocator.Current.GetInstance<IUIService>();
            uiService.Screens.Add(_menuUI);

            _startGame = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                Y = 330,
                X = 200,
                Content = new TextBlock { Text = "Start Game" },
            };
            _startGame.Click += (s, e) => MenuToGame();

            /*_about = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                Y = 405,
                X = 200,
                Content = new TextBlock { Text = "About Us" },
            };*/

            var Game = ServiceLocator.Current.GetInstance<Game>();
            _exit = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                X = 200,
                Y = 405,
                Content = new TextBlock { Text = "Exit" },
            };
            _exit.Click += (s, e) => Game.Exit();

            _gameLogo = new Image
            {
                Texture = content.Load<Texture2D>("UI/goldcrestlogo"),
                HorizontalAlignment = HorizontalAlignment.Center,
                Y = 100,
            };

            _background = new Image
            {
                Texture = content.Load<Texture2D>("UI/background"),
            };

            _menuPic = new Image
            {
                Texture = content.Load<Texture2D>("UI/menupic"),
                X = 550,
                Y = 300,
            };

            _menuUI.Children.Add(_background);
            _menuUI.Children.Add(_menuPic);
            _menuUI.Children.Add(_gameLogo);
            _menuUI.Children.Add(_startGame);
            //_menuUI.Children.Add(_about);
            _menuUI.Children.Add(_exit);

            backgroundMusic = content.Load<Song>("SoundFX/Menu_loop");
            MediaPlayer.Play(backgroundMusic);
            MediaPlayer.IsRepeating = true;

            base.Initialize();
        }
Example #29
0
        /// <summary>
        /// Load content for this game component
        /// </summary>
        protected override void LoadContent()
        {
            // TODO: Add your initialization code here
            var content = new ContentManager(Game.Services, "NeoforceTheme");
            Theme theme;
            theme = content.Load<Theme>("ThemeRed");

            // Create a UI renderer, which uses the theme info to renderer UI controls.
            var renderer = new UIRenderer(Game, theme);

            // Create a UIScreen and add it to the UI service. The screen is the root of
            // the tree of UI controls. Each screen can have its own renderer.
            _screen = new UIScreen("Default", renderer)
            {
                // Make the screen transparent.
                Background = new Color(0, 0, 0, 0),

            };
            var test = new Canvas()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };

            var maprender = new UIControls.GalaxyMapControl(Game.Services)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };
            var minimap = new UIControls.MinimapControl(Game.Services);
            var miniMapWindow = new MiniMapWindow()
            {
                Height = 200,
                Width = 200,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Bottom,
                Name = "MiniMap"
            };
            var controlButtonPanel = new StackPanel()
            {
                Orientation = Orientation.Horizontal,
                VerticalAlignment = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            var testButton = new Button()
            {
                Height = 40,
                Width = 200
            };
            controlButtonPanel.Children.Add(testButton);
            miniMapWindow.Content = minimap;
            test.Children.Add(maprender);
            test.Children.Add(controlButtonPanel);
            test.Children.Add(miniMapWindow);

            var mainTabPanel = new TabControl
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch
            };

            var systemMap = new UIControls.SystemMapControl(Game.Services)
            {
                Opacity = 5,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                ViewData = new SystemMapViewModel() { Rings = new[]
                                                                  {
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 1", Scale = 1},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 1 - Moon", Scale = 0.4f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 2", Scale = 0.5f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 3", Scale = 0.7f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 3 - Moon 1", Scale = 0.3f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 3 - Moon 2", Scale = 0.3f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 4", Scale = 0.2f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 5", Scale = 0.9f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 6", Scale = 0.6f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 7", Scale = 0.3f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 8", Scale = 0.5f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9", Scale = 0.8f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 1", Scale = 0.2f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 2", Scale = 0.2f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 3", Scale = 0.2f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 4", Scale = 0.3f},
                                                                                                                   }}
                                                                  }}
            };

            var planetMap = new PlanetMapControl(Game.Services)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                ViewData = new PlanetMapViewModel()
                               {
                                   Name = "Earth",
                                   BuildingCells = new[,]
                                                       {
                                                           { new BuildingCellViewModel(), new BuildingCellViewModel { Type = CellMultiplier.ExtraEnergy }, new BuildingCellViewModel() },
                                                           { new BuildingCellViewModel(), new BuildingCellViewModel(), new BuildingCellViewModel { Type = CellMultiplier.ExtraEnergy } },
                                                           { new BuildingCellViewModel { Type = CellMultiplier.ExtraEnergy }, new BuildingCellViewModel(), new BuildingCellViewModel() }
                                                       }
                               }
            };

            mainTabPanel.Items.Add(new TabItem() { Content = new TextBlock() { Text = "Star map" }, TabPage = test });
            mainTabPanel.Items.Add(new TabItem() { Content = new TextBlock() { Text = "System map" }, TabPage = systemMap });
            mainTabPanel.Items.Add(new TabItem() { Content = new TextBlock() { Text = "Planet map" }, TabPage = planetMap });

            _console = new ConsoleWindow(_consoleManager);

            StartMenuScreen start = new StartMenuScreen(Game.Services);
            start.Init();
            _screen.Children.Add(start);

            //_screen.Children.Add(mainTabPanel);
            //_screen.Children.Add(_console);
            //_screen.Children.Add(miniMapWindow);
            //_screen.Children.Add(maprender);

            // Add the screen to the UI service.
            _uiService.Screens.Add(_screen);

            base.LoadContent();
        }
Example #30
0
    public HealthBarSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      // The base class has created the graphics screen for the 3D objects.
      GraphicsScreen.ClearBackground = true;
      GraphicsScreen.BackgroundColor = Color.CornflowerBlue;
      SetCamera(new Vector3F(0, 1, 3), 0, 0);
      _cameraObject = GameObjectService.Objects.OfType<CameraObject>().First();

      // We add another graphics screen on top which renders the GUI.
      var graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(1, graphicsScreen);

      // Create a UIScreen.
      Theme theme = ContentManager.Load<Theme>("UI Themes/BlendBlue/Theme");
      UIRenderer renderer = new UIRenderer(Game, theme);
      _uiScreen = new UIScreen("HealthBarScreen", renderer)
      {
        Background = Color.Transparent,   // Background must not hide the 3D graphics screen.
      };
      UIService.Screens.Add(_uiScreen);

      // Standard force effects.
      Simulation.ForceEffects.Add(new Gravity());
      Simulation.ForceEffects.Add(new Damping());

      // Standard game objects.
      GameObjectService.Objects.Add(new GroundObject(Services));

      // Create a new game object property. This allows to attach a z value to all UIControls.
      _zPropertyId = UIControl.CreateProperty<float>(
        typeof(UIControl), 
        "Z", 
        GamePropertyCategories.Appearance, 
        "The layer depth. Objects with lower depth value are in front.", 
        0.0f, 
        UIPropertyOptions.AffectsRender);

      // Create 3D objects and a progress bar for each object.
      for (int i = 0; i < 10; i++)
      {
        var dynamicObject = new DynamicObject(Services, 1);
        GameObjectService.Objects.Add(dynamicObject);

        var progressBar = new ProgressBar
        {
          Value = RandomHelper.Random.NextFloat(0, 100),
          Maximum = 100,
          X = 100,
          Y = 100,
          Width = 100,
          Height = 20,
          Margin = new Vector4F(-50, -10, 0, 0),  // Use a margin to center the control.
        };
        _uiScreen.Children.Add(progressBar);

        _objects.Add(new Pair<DynamicObject, ProgressBar>(dynamicObject, progressBar));
      }
    }
Example #31
0
        protected override void Initialize()
        {
            _serviceContainer = new ServiceContainer();
            ServiceLocator.SetLocatorProvider(() => _serviceContainer);

            _serviceContainer.Register(typeof(Game), null, this);
            _serviceContainer.Register(typeof(ContentManager), null, Content);

            // Adds the input service, which manages device input, button presses etc.
            _inputManager = new InputManager(false);
            _serviceContainer.Register(typeof(IInputService), null, _inputManager);

            // Adds the UI service which manages UI screens
            _uiManager = new UIManager(this, _inputManager);
            _serviceContainer.Register(typeof(IUIService), null, _uiManager);

            _graphicsManager = new GraphicsManager(GraphicsDevice, Window, Content);
            Services.AddService(typeof(IGraphicsService), _graphicsManager);
            _serviceContainer.Register(typeof(IGraphicsService), null, _graphicsManager);

            _animationManager = new AnimationManager();
            _serviceContainer.Register(typeof(IAnimationService), null, _animationManager);

            _gameObjectManager = new GameObjectManager();
            _serviceContainer.Register(typeof(IGameObjectService), null, _gameObjectManager);

            _debugRenderer = new DebugRenderer(_graphicsManager, Content.Load<SpriteFont>("UI/MiramonteBold"));
            _serviceContainer.Register(typeof(DebugRenderer), null, _debugRenderer);

            _serviceContainer.Register(typeof(ContentManager), null, Content);

            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _serviceContainer.Register(typeof(SpriteBatch), null, _spriteBatch);

            _gameLog = new GameLog();
            _serviceContainer.Register(typeof(GameLog), null, _gameLog);

            _gameSettings = new GameSettings();
            _serviceContainer.Register(typeof(GameSettings), null, _gameSettings);

            var uiTheme = Content.Load<Theme>("UI/UITheme");
            UIRenderer renderer = new UIRenderer(this, uiTheme);

            var screen = new UIScreen("Default", renderer)
            {
                Background = new Color(0, 0, 0, 0),
            };

            _uiManager.Screens.Add(screen);

            _mainGameComponent = new MainGameComponent(this);
            Components.Add(new StartScreenComponent(this));
            Components.Add(new GamerServicesComponent(this));

            //_updateAnimation = () => _animationManager.Update(_deltaTime);

            base.Initialize();
        }
Example #32
0
    public DebuggingComponent(Microsoft.Xna.Framework.Game game, IServiceLocator services)
      : base(game)
    {
      _inputService = services.GetInstance<IInputService>();
      _graphicsService = services.GetInstance<IGraphicsService>();
      _uiService = services.GetInstance<IUIService>();

      // Get graphics service and add a DelegateGraphicsScreen as the first 
      // graphics screen. This lets us do the rendering in the Render method of
      // this class.
      
      _graphicsScreen = new DelegateGraphicsScreen(_graphicsService)
      {
        RenderCallback = Render,
      };
      _graphicsService.Screens.Insert(0, _graphicsScreen);

      // Load a UI theme and create a renderer. 
      // We could use the same renderer as the "Default" screen (see StartScreenComponent.cs).
      // But usually, the debug screen will use a more efficient theme (smaller fonts, no
      // fancy graphics). Here, we simply use the BlendBlue theme again.
      var contentManager = services.GetInstance<ContentManager>();
      var theme = contentManager.Load<Theme>("UI Themes/BlendBlue/Theme");
      UIRenderer renderer = new UIRenderer(Game, theme);

      // Create a UIScreen and add it to the UI service. 
      _uiScreen = new UIScreen("Debug", renderer)
      {
        // A transparent background.
        Background = new Color(0, 0, 0, 0),

        // The z-index is equal to the draw order. The z-index defines in which order the 
        // screens are updated. This screen with the debug console should be updated before
        // the actual game under this screen.
        ZIndex = 10,

        // Hide the screen. The user has to press a button to make the debug screen visible.
        IsVisible = false,
      };

      // Optional: 
      // The debug screen handles gamepad input first, then the other screens and game components
      // can handle input. We do not want that the game is controllable when the debug screen is
      // visible, therefore we set the IsHandled flags when the screen is finished with the input.
      _uiScreen.InputProcessed += (s, e) => _inputService.SetGamePadHandled(LogicalPlayerIndex.Any, true);

      // Add a console control on the left.
      _console = new Console
      {
        HorizontalAlignment = HorizontalAlignment.Left,
        VerticalAlignment = VerticalAlignment.Stretch,
        Width = 500,
        Margin = new Vector4F(20),
      };
      _uiScreen.Children.Add(_console);

      // Print a few info messages in the console.
      _console.WriteLine("Press TAB or ChatPadGreen to display/hide console.");
      _console.WriteLine("Enter 'help' to view console commands.");

      // Add a custom command:
      _console.Interpreter.Commands.Add(new ConsoleCommand("greet", "greet [<name>] ... Prints a greeting message.", Greet));

      // Add the screen to the UI service. 
      _uiService.Screens.Add(_uiScreen);
    }
Example #33
0
    private void CreateGui()
    {
      // Remove old screen.
      if (_uiScreen != null)
        UIService.Screens.Remove(_uiScreen);

      // Load a UI theme, which defines the appearance and default values of UI controls.
      string themeName;
      if (_themeNumber == 0)
        themeName = "UI Themes/BlendBlue/Theme";
      else
        themeName = "UI Themes/Aero/Theme";

      Theme theme = ContentManager.Load<Theme>(themeName);

      // Create a UI renderer, which uses the theme info to renderer UI controls.
      UIRenderer renderer = new UIRenderer(Game, theme);

      // Create a UIScreen and add it to the UI service. The screen is the root of the 
      // tree of UI controls. Each screen can have its own renderer.
      _uiScreen = new UIScreen("SampleUIScreen", renderer);
      UIService.Screens.Add(_uiScreen);

      // Add a text block that displays the frame rate.
      _uiScreen.Children.Add(new FpsTextBlock
      {
        HorizontalAlignment = HorizontalAlignment.Right,
        VerticalAlignment = VerticalAlignment.Top,
        Margin = new Vector4F(40),
      });

      // Add a text label.
      var textBlock = new TextBlock
      {
        Text = "Press button to open window: ",
        Margin = new Vector4F(4)
      };

      // Add buttons that open samples.
      var button0 = new Button
      {
        Content = new TextBlock { Text = "Sample #1: Controls" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };
      button0.Click += (s, e) =>
      {
        var allControlsWindow = new AllControlsWindow(ContentManager, renderer);
        allControlsWindow.Show(_uiScreen);
      };

      var button1 = new Button
      {
        Content = new TextBlock { Text = "Sample #2: ScrollViewer" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button1.Click += (s, e) =>
      {
        var resizableWindow = new ResizableWindow(ContentManager);
        resizableWindow.Show(_uiScreen);
      };

      var button2 = new Button
      {
        Content = new TextBlock { Text = "Sample #3: Transformations" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button2.Click += (s, e) =>
      {
        var renderTransformWindow = new RenderTransformWindow();
        renderTransformWindow.Show(_uiScreen);
      };

      var button3 = new Button
      {
        Content = new TextBlock { Text = "Sample #4: Dialogs" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button3.Click += (s, e) =>
      {
        var dialogDemoWindow = new DialogDemoWindow();
        dialogDemoWindow.Show(_uiScreen);
      };

      var button4 = new Button
      {
        Content = new TextBlock { Text = "Sample #5: Console" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button4.Click += (s, e) =>
      {
        var consoleWindow = new ConsoleWindow();
        consoleWindow.Show(_uiScreen);
      };

      var button5 = new Button
      {
        Content = new TextBlock { Text = "Switch UI Theme" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button5.Click += (s, e) =>
      {
        // Set a flag. In the next Update() we will load a new theme.
        // Note: We should not load the theme here because the UI is currently updated.
        _changeTheme = true;
      };

      var stackPanel = new StackPanel { Margin = new Vector4F(40) };
      stackPanel.Children.Add(textBlock);
      stackPanel.Children.Add(button0);
      stackPanel.Children.Add(button1);
      stackPanel.Children.Add(button2);
      stackPanel.Children.Add(button3);
      stackPanel.Children.Add(button4);
      stackPanel.Children.Add(button5);
      _uiScreen.Children.Add(stackPanel);

      // Optional: If we want to allow the user to use buttons in the screen with 
      // keyboard or game pad, we have to make it a focus scope. Normally, only 
      // windows are focus scopes.
      _uiScreen.IsFocusScope = true;
      _uiScreen.Focus();
    }
Example #34
0
    public InGameUISample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      // Add gravity and damping to the physics simulation.
      Simulation.ForceEffects.Add(new Gravity());
      Simulation.ForceEffects.Add(new Damping());

      // Create the DeferredGraphicsScreen.
      var graphicsScreen = new DeferredGraphicsScreen(Services);
      graphicsScreen.DrawReticle = true;
      GraphicsService.Screens.Insert(0, graphicsScreen);

      Services.Register(typeof(DebugRenderer), null, graphicsScreen.DebugRenderer);
      Services.Register(typeof(IScene), null, graphicsScreen.Scene);

      // some 3D objects
      var cameraGameObject = new CameraObject(Services);
      GameObjectService.Objects.Add(cameraGameObject);
      graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode;
      GameObjectService.Objects.Add(new GrabObject(Services));
      GameObjectService.Objects.Add(new StaticSkyObject(Services));
      GameObjectService.Objects.Add(new GroundObject(Services));
      for (int i = 0; i < 10; i++)
        GameObjectService.Objects.Add(new DynamicObject(Services, 3));

      // Create the UIScreen which is rendered into the back buffer.
      Theme theme = ContentManager.Load<Theme>("UI Themes/Aero/Theme");
      UIRenderer renderer = new UIRenderer(Game, theme);
      _normalUIScreen = new NormalUIScreen(renderer);
      UIService.Screens.Add(_normalUIScreen);

      // Handle the InputProcessed event of the Image control.
      _normalUIScreen.Image.InputProcessed += OnGameViewControlInputProcessed;

      // Create the DelegateGraphicsScreen. This graphics screen is on top of the
      // DeferredGraphicsScreen and instructs the graphics service to render the
      // previous screen into an off-screen render target.
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
        RenderPreviousScreensToTexture = true,
        SourceTextureFormat = new RenderTargetFormat(
          (int)_normalUIScreen.Image.Width,
          (int)_normalUIScreen.Image.Height,
          false,
          SurfaceFormat.Color,
          DepthFormat.Depth24),
      };
      GraphicsService.Screens.Insert(1, delegateGraphicsScreen);

      // Create the UIScreen that is rendered into a render target and mapped onto the 3D game objects.
      _inGameUIScreenRenderTarget = new RenderTarget2D(GraphicsService.GraphicsDevice, 600, 250, false, SurfaceFormat.Color, DepthFormat.None);
      _inGameScreen = new InGameUIScreen(Services, renderer)
      {
        InputEnabled = false,
        Width = _inGameUIScreenRenderTarget.Width,
        Height = _inGameUIScreenRenderTarget.Height,
      };
      UIService.Screens.Add(_inGameScreen);

      // We can use the off-screen render target anywhere in the 3D scene. Here, we 
      // use it to replace the normal "TestCard" texture of the TV objects and the ProjectorLights.
      foreach (var node in graphicsScreen.Scene.GetDescendants())
      {
        var meshNode = node as MeshNode;
        if (meshNode != null)
        {
          foreach (var material in meshNode.Mesh.Materials)
          {
            if (material.Name == "TestCard")
            {
              material["Material"].Set("EmissiveTexture", (Texture)_inGameUIScreenRenderTarget);
              material["Material"].Set("Exposure", 0.1f);
            }
          }
          continue;
        }

        var lightNode = node as LightNode;
        if (lightNode != null && lightNode.Light is ProjectorLight)
        {
          ((ProjectorLight)lightNode.Light).Texture = _inGameUIScreenRenderTarget;
        }
      }
    }
Example #35
0
    public UIAnimationSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      // Add a DelegateGraphicsScreen as the first graphics screen to the graphics
      // service. This lets us do the rendering in the Render method of this class.
      _graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, _graphicsScreen);

      // Load a UI theme, which defines the appearance and default values of UI controls.
      Theme theme = ContentManager.Load<Theme>("UI Themes/BlendBlue/Theme");

      // Create a UI renderer, which uses the theme info to renderer UI controls.
      UIRenderer renderer = new UIRenderer(Game, theme);

      // Create a UIScreen and add it to the UI service. The screen is the root of the 
      // tree of UI controls. Each screen can have its own renderer.
      _uiScreen = new UIScreen("SampleUIScreen", renderer);
      UIService.Screens.Add(_uiScreen);

      // ----- Add buttons.
      Button button0 = new Button
      {
        Name = "Button0",
        Content = new TextBlock { Text = "Animate Buttons" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };
      button0.Click += (s, e) => PlayStartAnimation();

      Button button1 = new Button
      {
        Name = "Button1",
        Content = new TextBlock { Text = "Open FadingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button1.Click += (s, e) => new FadingWindow(Services).Show(_uiScreen);

      Button button2 = new Button
      {
        Name = "Button2",
        Content = new TextBlock { Text = "Open ScalingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button2.Click += (s, e) => new ScalingWindow(Services).Show(_uiScreen);

      Button button3 = new Button
      {
        Name = "Button3",
        Content = new TextBlock { Text = "Open RotatingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button3.Click += (s, e) => new RotatingWindow(Services).Show(_uiScreen);

      Button button4 = new Button
      {
        Name = "Button4",
        Content = new TextBlock { Text = "Open EasingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button4.Click += (s, e) => new EasingWindow(Services).Show(_uiScreen);

      Button button5 = new Button
      {
        Name = "Button5",
        Content = new TextBlock { Text = "Close All Windows" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button5.Click += (s, e) => CloseWindows();

      Button button6 = new Button
      {
        Name = "Button6",
        Content = new TextBlock { Text = "Exit" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button6.Click += (s, e) => Exit();

      _buttonStackPanel = new StackPanel { Margin = new Vector4F(40) };
      _buttonStackPanel.Children.Add(button0);
      _buttonStackPanel.Children.Add(button1);
      _buttonStackPanel.Children.Add(button2);
      _buttonStackPanel.Children.Add(button3);
      _buttonStackPanel.Children.Add(button4);
      _buttonStackPanel.Children.Add(button5);
      _buttonStackPanel.Children.Add(button6);
      _uiScreen.Children.Add(_buttonStackPanel);

      // Optional: If we want to allow the user to use buttons in the screen with 
      // keyboard or game pad, we have to make it a focus scope. Normally, only 
      // windows are focus scopes.
      _uiScreen.IsFocusScope = true;
      _uiScreen.Focus();

      PlayStartAnimation();
    }