/// <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; } }; }
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(); }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="FocusManager"/> class. /// </summary> /// <param name="screen">The screen.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="screen"/> is <see langword="null"/>. /// </exception> public FocusManager(UIScreen screen) { if (screen == null) throw new ArgumentNullException("screen"); Screen = screen; }
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); }
public MyGameComponent(Microsoft.Xna.Framework.Game game, IServiceLocator services) : base(game) { // Get the services that this component needs regularly. _services = services; _inputService = services.GetInstance<IInputService>(); _simulation = services.GetInstance<Simulation>(); _graphicsService = services.GetInstance<IGraphicsService>(); _gameObjectService = services.GetInstance<IGameObjectService>(); _uiService = services.GetInstance<IUIService>(); // Add gravity and damping to the physics simulation. _simulation.ForceEffects.Add(new Gravity()); _simulation.ForceEffects.Add(new Damping()); // Create the DeferredGraphicsScreen and some 3D objects. _deferredGraphicsScreen = new DeferredGraphicsScreen(services); _deferredGraphicsScreen.DrawReticle = true; _graphicsService.Screens.Insert(0, _deferredGraphicsScreen); // The GameObjects below expect try to retrieve DebugRenderer and Scene via // service container. var serviceContainer = (ServiceContainer)services; serviceContainer.Register(typeof(DebugRenderer), null, _deferredGraphicsScreen.DebugRenderer); serviceContainer.Register(typeof(IScene), null, _deferredGraphicsScreen.Scene); _cameraGameObject = new CameraObject(services); _gameObjectService.Objects.Add(_cameraGameObject); _deferredGraphicsScreen.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, 1)); // Get the "SampleUI" screen that was created by the StartScreenComponent. _uiScreen = _uiService.Screens["SampleUI"]; // Add a second GraphicsScreen. This time it is a DelegateGraphicsScreen that // draws the UI over DeferredGraphicsScreen. _delegateGraphicsScreen = new DelegateGraphicsScreen(_graphicsService) { RenderCallback = context => _uiScreen.Draw(context.DeltaTime) }; _graphicsService.Screens.Insert(1, _delegateGraphicsScreen); // Create the game menu window. But do not display it yet. _gameMenuWindow = new GameMenuWindow { // If the menu is opened and closed a lot, it is more efficient when _gameMenuWindow.Close() // makes the window invisible but does not remove it from the screen. HideOnClose = true, }; }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="ToolTipManager"/> class. /// </summary> /// <param name="screen">The screen.</param> internal ToolTipManager(UIScreen screen) { Screen = screen; Screen.InputProcessed += OnScreenInputProcessed; ToolTipControl = new ContentControl { Name = "ToolTip", Style = "ToolTip", IsVisible = false, }; }
/// <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; }
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. }
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(); }
public override void Initialize() { base.Initialize(); // 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); // Get the "SampleUI" screen that was created by the StartScreenComponent. _uiScreen = _uiService.Screens["SampleUI"]; // Show the main menu window. _mainMenuWindow = new MainMenuWindow(); _mainMenuWindow.Show(_uiScreen); }
// 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 }
public CustomControlSample(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); // Create a theme. A theme defines the images of the controls and the default values of // the UI control properties. Theme theme = ContentManager.Load<Theme>("UI Themes/BlendBlue/Theme"); // Create a renderer that uses the theme information. We do not use the default UIRenderer // class, instead we use our own MyUIRenderer that adds rendering of tree view items. var renderer = new MyUIRenderer(Game, theme); // Create the screen. A screen is the root of the UI control hierarchy. _uiScreen = new UIScreen("SampleUIScreen", renderer); // Screens must be added to the UI service to be updated each frame. UIService.Screens.Add(_uiScreen); // Add a tree view control to the screen. var padding = new Vector4F(0, 2, 4, 2); var treeView = new TreeView { X = 10, Y = 60, Items = { new TreeViewItem { Header = new TextBlock { Text = "Item 1", Padding = padding, }, UserData = "1", }, new TreeViewItem { Header = new TextBlock { Text = "Item 2", Padding = padding, }, UserData = "2", Items = { new TreeViewItem { Header = new TextBlock { Text = "Item 2.1", Padding = padding, }, UserData = "2.1", }, new TreeViewItem { Header = new TextBlock { Text = "Item 2.2", Padding = padding, }, UserData = "2.2", Items = { new TreeViewItem { Header = new TextBlock { Text = "Item 2.2.1", Padding = padding, }, UserData = "2.2.1", }, new TreeViewItem { Header = new TextBlock { Text = "Item 2.2.2", Padding = padding, }, UserData = "2.2.2", }, } }, new TreeViewItem { Header = new TextBlock { Text = "Item 2.3", Padding = padding, }, UserData = "2.3", }, } }, new TreeViewItem { Header = new TextBlock { Text = "Item 3 (The quick brown fox jumps over the lazy dog.)", Padding = padding, }, UserData = "3", Items = { new TreeViewItem { Header = new TextBlock { Text = "Item 3.1", Padding = padding, }, UserData = "3.1", }, new TreeViewItem { Header = new TextBlock { Text = "Item 3.2", Padding = padding, }, UserData = "3.2", }, new TreeViewItem { Header = new Image { Texture = theme.Textures["UITexture"].Texture, SourceRectangle = new Rectangle(214, 66, 16, 16), Padding = padding, }, UserData = "3.3", }, new TreeViewItem { Header = new TextBlock { Text = "Item 3.4", Padding = padding, }, UserData = "3.4", }, } }, } }; _uiScreen.Children.Add(treeView); // Handle InputProcessed events. treeView.InputProcessed += OnTreeViewInputProcessed; }
/// <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(); }
/// <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(); }
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(); }
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(); }
protected override void Dispose(bool disposing) { if (disposing) { if (_uiScreen != null) // This check is necessary because Dispose() might be called more than once. { _uiService.Screens.Remove(_uiScreen); _uiScreen = null; _graphicsService.Screens.Remove(_graphicsScreen); _graphicsScreen = null; } } base.Dispose(disposing); }
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); }
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(); }
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)); } }
//-------------------------------------------------------------- //-------------------------------------------------------------- //-------------------------------------------------------------- //-------------------------------------------------------------- #endregion Other #if !WP7 && !XBOX /// <summary> /// Gets the nearest index of the caret for a given screen position (e.g. for a mouse click). /// </summary> /// <param name="position">The absolute screen position.</param> /// <param name="screen">The screen.</param> /// <returns>The index of the caret.</returns> private int GetIndex(Vector2F position, UIScreen screen) { string text = Text ?? string.Empty; var buffer = new StringBuilder(); var font = screen.Renderer.GetFont(Font); if (!IsMultiline) { // ----- Single-line // Measure substrings until we now the number of characters before the position. for (int i = 0; i < VisualText.Length; i++) { buffer.Clear(); buffer.Append(text, 0, i + 1); float x = VisualClip.X - VisualOffset + font.MeasureString(buffer).X; if (x > position.X) return i; } return VisualText.Length; } // ----- Multi-line // Find line number. float textY = VisualClip.Y - VisualOffset; int line = (int)(position.Y - textY) / font.LineSpacing; if (line < 0) return 0; if (line >= _lineStarts.Count) return text.Length; // Get info for this line. int lineStartIndex = Math.Abs(_lineStarts[line]); int lineEndIndex = (line + 1 < _lineStarts.Count) ? Math.Abs(_lineStarts[line + 1]) : text.Length; int lineLength = lineEndIndex - lineStartIndex; // Measure substrings until we know the column. for (int i = 0; i < lineLength; i++) { buffer.Clear(); buffer.Append(text, lineStartIndex, i + 1); float x = VisualClip.X + font.MeasureString(buffer).X; if (x > position.X) return lineStartIndex + i; } // If the last character is a newline, then we want to position the caret before // the newline, otherwise the caret is displayed on the next line. if (lineEndIndex > lineStartIndex && text[lineEndIndex - 1] == '\n') return lineEndIndex - 1; return lineEndIndex; }