protected Entity GetUIEntity(SpriteFont font, bool fixedSize, Vector3 position) { // Create and initialize "Touch Screen to Start" var touchStartLabel = new ContentDecorator { Content = new TextBlock { Font = font, TextSize = 32, Text = (fixedSize) ? "Fixed Size UI" : "Regular UI", TextColor = Color.White }, Padding = new Thickness(30, 20, 30, 25), HorizontalAlignment = HorizontalAlignment.Center }; //touchStartLabel.SetPanelZIndex(1); var grid = new Grid { BackgroundColor = (fixedSize) ? new Color(255, 0, 255) : new Color(255, 255, 0), MaximumWidth = 100, MaximumHeight = 100, MinimumWidth = 100, MinimumHeight = 100, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, }; grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); grid.ColumnDefinitions.Add(new StripDefinition()); grid.LayerDefinitions.Add(new StripDefinition()); grid.Children.Add(touchStartLabel); // Add the background var background = new ImageElement { StretchType = StretchType.Fill }; background.SetPanelZIndex(-1); var uiEntity = new Entity(); // Create a procedural model with a diffuse material var uiComponent = new UIComponent(); uiComponent.RootElement = new UniformGrid { Children = { background, grid } }; uiComponent.Resolution = new Vector3(100, 100, 100); // Same size as the inner grid uiComponent.IsFullScreen = false; // uiComponent.IsBillboard = true; uiComponent.IsFixedSize = fixedSize; uiComponent.Size = new Vector3(0.1f); // 10% of the vertical resolution uiEntity.Add(uiComponent); uiEntity.Transform.Position = position; return uiEntity; }
protected override void LoadScene() { // Allow user to resize the window with the mouse. Game.Window.AllowUserResizing = true; // Create and initialize "Xenko Samples" Text var xenkoSampleTextBlock = new ContentDecorator { BackgroundImage = SpriteFromSheet.Create(SplashScreenImages, "xenko_sample_text_bg"), Content = new TextBlock { Font = WesternFont, TextSize = 60, Text = "Xenko UI Particles", TextColor = Color.White, }, Padding = new Thickness(35, 15, 35, 25), HorizontalAlignment = HorizontalAlignment.Center }; xenkoSampleTextBlock.SetPanelZIndex(1); //********************************* // Confetti button var buttonImage = SpriteFromSheet.Create(SplashScreenImages, "button_long"); var xenkoButtonConfetti = new Button { NotPressedImage = buttonImage, PressedImage = buttonImage, MouseOverImage = buttonImage, Content = new TextBlock { Font = WesternFont, TextColor = Color.White, Text = "Click here to start the game over", TextSize = 24 }, HorizontalAlignment = HorizontalAlignment.Right, Padding = new Thickness(90, 22, 25, 35), // BackgroundColor = Color.DarkOrchid }; xenkoButtonConfetti.SetPanelZIndex(1); xenkoButtonConfetti.SetGridRow(1); xenkoButtonConfetti.Click += delegate { fusePercentage = 1f; desiredState = GameState.NewGame; var effectOffset = new Vector3(45 - xenkoButtonConfetti.RenderSize.X / 2, -5, 0); SpawnParticles(xenkoButtonConfetti.WorldMatrix.TranslationVector + effectOffset, Prefab, 2f); }; //********************************* //********************************* // Stars button var buttonStars = SpriteFromSheet.Create(SplashScreenImages, "button_short"); var xenkoButtonStars = new Button { NotPressedImage = buttonStars, PressedImage = buttonStars, MouseOverImage = buttonStars, Content = new TextBlock { Font = WesternFont, TextColor = Color.White, Text = "Congratulations", TextSize = 24 }, HorizontalAlignment = HorizontalAlignment.Right, Padding = new Thickness(90, 22, 25, 35), // BackgroundColor = Color.DarkOrchid }; xenkoButtonStars.SetPanelZIndex(1); xenkoButtonStars.SetGridRow(4); xenkoButtonStars.Click += delegate { desiredState = GameState.EndGame; var effectOffset = new Vector3(45 - xenkoButtonStars.RenderSize.X / 2, -5, 0); SpawnParticles(xenkoButtonStars.WorldMatrix.TranslationVector + effectOffset, Prefab, 2f); }; //********************************* var bottomBar = CreateBottomBar(); bottomBar.SetPanelZIndex(1); bottomBar.SetGridRow(6); var grid = new Grid { MaximumWidth = virtualWidth, MaximumHeight = virtualHeight, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, }; grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); // 0 grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); // 1 grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); // 2 grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); // 3 grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); // 4 grid.RowDefinitions.Add(new StripDefinition(StripType.Fixed, 100)); // 5 grid.RowDefinitions.Add(new StripDefinition(StripType.Fixed, 50)); // 5 grid.ColumnDefinitions.Add(new StripDefinition()); grid.LayerDefinitions.Add(new StripDefinition()); grid.Children.Add(xenkoSampleTextBlock); grid.Children.Add(xenkoButtonConfetti); grid.Children.Add(xenkoButtonStars); grid.Children.Add(bottomBar); // Add the background var background = new ImageElement { Source = SpriteFromSheet.Create(SplashScreenImages, "background_uiimage"), StretchType = StretchType.Fill }; background.SetPanelZIndex(-1); Entity.Get<UIComponent>().Page = new UIPage { RootElement = new UniformGrid { Children = { background, grid } } }; }