protected override async Task LoadContent() { await base.LoadContent(); UIComponent.Resolution = new Vector3(GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height, 500); textBlock = new TextBlock { WrapText = true, TextSize = 15, TextColor = Color.Black, Font = Content.Load<SpriteFont>("HanSans13"), Text = @"This is a very long sentence that will hopefully be wrapped up. Does it work with kanjis too? let's see that in the following line. Here we goes. 漢字も大丈夫そうですね!良かった!でも、文章の切る所は本当に合ってますか?どうかな。。 やった!", SynchronousCharacterGeneration = true, }; var decorator = new ContentDecorator { Width = 200, Content = textBlock, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, BackgroundImage = (SpriteFromTexture)new Sprite(Content.Load<Texture>("DumbWhite")) }; UIComponent.Page = new Engine.UIPage { RootElement = decorator }; }
public override async Task Execute() { if (Input.Gravity.IsSupported) // do not display any message when orientation sensor is available return; if (IsLiveReloading) return; var textBlock = new TextBlock { Text = "Use arrows to play with gravity!", Font = Font, TextColor = Color.White, TextSize = 40 }; textBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 0)); textBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.75f, 0f)); Entity.Get<UIComponent>().Page = new UIPage { RootElement = new Canvas { Children = { textBlock } } }; while (Game.IsRunning) { await Script.NextFrame(); if (!Input.IsKeyPressed(Keys.Left) && !Input.IsKeyPressed(Keys.Right) && !Input.IsKeyPressed(Keys.Up) && !Input.IsKeyPressed(Keys.Down)) continue; Entity.Get<UIComponent>().Page = null; return; } }
protected override async Task LoadContent() { await base.LoadContent(); Sprites = Asset.Load<SpriteSheet>("UIImages"); var lifeBar = new ImageElement { Source = Sprites["Logo"], HorizontalAlignment = HorizontalAlignment.Center }; lifeBar.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3); var quitGameButton = new Button { Content = new TextBlock { Text = "Quit Game", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left, Padding = Thickness.UniformRectangle(10), }; quitGameButton.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0); quitGameButton.DependencyProperties.Set(GridBase.RowPropertyKey, 2); quitGameButton.Click += (sender, args) => Exit(); modalButton1Text = new TextBlock { Text = "Close Modal window 1", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }; var modalButton1 = new Button { Name = "Button Modal 1", Content = modalButton1Text, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Padding = Thickness.UniformRectangle(10), }; modalButton1.Click += ModalButton1OnClick; modal1 = new ModalElement { Content = modalButton1, Name = "Modal 1"}; modal1.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1); modal1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); modal1.DependencyProperties.Set(GridBase.RowPropertyKey, 1); modal1.OutsideClick += Modal1OnOutsideClick; modalButton2Text = new TextBlock { Text = "Close Modal window 2", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }; var modalButton2 = new Button { Name = "Button Modal 2", Content = modalButton2Text, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Padding = Thickness.UniformRectangle(10), }; modalButton2.Click += ModalButton2OnClick; modal2 = new ModalElement { Content = modalButton2, Name = "Modal 2" }; modal2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 2); modal2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); modal2.DependencyProperties.Set(GridBase.RowPropertyKey, 2); modal2.OutsideClick += Modal2OnOutsideClick; uniformGrid = new UniformGrid { Columns = 3, Rows = 3 }; uniformGrid.Children.Add(modal1); uniformGrid.Children.Add(modal2); uniformGrid.Children.Add(lifeBar); uniformGrid.Children.Add(quitGameButton); UIComponent.RootElement = uniformGrid; }
public override void Start() { simulation = this.GetSimulation(); simulation.Gravity = new Vector3(0, -9, 0); cubeRigidBody = cube.Get<RigidbodyComponent>(); cubeRigidBody.CanSleep = false; sphereRigidBody = sphere.Get<RigidbodyComponent>(); sphereRigidBody.CanSleep = false; // Create the UI constraintNameBlock = new TextBlock { Font = Font, TextSize = 55, TextColor = Color.White, }; constraintNameBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 0)); constraintNameBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.83f, 0)); Entity.Get<UIComponent>().Page = new UIPage { RootElement = new Canvas { Children = { constraintNameBlock, CreateButton("Next", Font, 1), CreateButton("Previous", Font, -1) } } }; // Create and initialize constraint PhysicsSampleList.Add(CreatePoint2PointConstraint); PhysicsSampleList.Add(CreateHingeConstraint); PhysicsSampleList.Add(CreateGearConstraint); PhysicsSampleList.Add(CreateSliderConstraint); PhysicsSampleList.Add(CreateConeTwistConstraint); PhysicsSampleList.Add(CreateGeneric6DoFConstraint); PhysicsSampleList[constraintIndex](); //Add a script for the slider constraint, to apply an impulse on collision cubeRigidBody.ProcessCollisions = true; Script.AddTask(async () => { while (Game.IsRunning) { var collision = await cubeRigidBody.NewCollision(); if (!(currentConstraint is SliderConstraint)) continue; if (collision.ColliderA != sphereRigidBody && collision.ColliderB != sphereRigidBody) continue; sphereRigidBody.LinearVelocity = Vector3.Zero; //clear any existing velocity sphereRigidBody.ApplyImpulse(new Vector3(-25, 0, 0)); //fire impulse } }); }
public override void Start() { base.Start(); var textBlock = new TextBlock { TextColor = Color.White, Font = Font, Text = UIText }; textBlock.SetCanvasPinOrigin(new Vector3(1, 0, 0)); textBlock.SetCanvasRelativePosition(new Vector3(0.63f, 0.8f, 0f)); Entity.Get<UIComponent>().RootElement = new Canvas { Children = { textBlock } }; }
// Create the UI layout and content public void Start() { textBlock = new TextBlock { Text = "Tap The Screen!", Font = Font, TextAlignment = TextAlignment.Center, }; textBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 0f)); textBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.85f, 0f)); Entity.Get<UIComponent>().RootElement = new Canvas { Children = { textBlock } }; }
public override void Start() { var textBlock = new TextBlock { Font = Font, TextSize = 18, TextColor = Color.Gold, Text = "Shoot : Touch in a vertical section where the Agent resides\n" + "Move : Touch in the screen on the corresponding side of the Agent", }; textBlock.SetCanvasRelativePosition(new Vector3(0.008f, 0.9f, 0)); Entity.Get<UIComponent>().RootElement = new Canvas { Children = { textBlock } }; }
public override void Start() { base.Start(); var textBlock = new TextBlock { Text = "Shoot the cubes!", Font = Font, TextColor = Color.White, TextSize = 60 }; textBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 0)); textBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.9f, 0f)); Entity.Get<UIComponent>().Page = new UIPage { RootElement = new Canvas { Children = { textBlock } } }; }
protected override async Task LoadContent() { await base.LoadContent(); var background = new Entity { new BackgroundComponent { Texture = Content.Load<Texture>("XenkoBackground") } }; Scene.Entities.Add(background); var text1 = new TextBlock { Text = "text block button 1", Font = Content.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true }; ApplyTextBlockDefaultStyle(text1); button1 = new Button { Content = text1 }; ApplyButtonDefaultStyle(button1); button1.SetCanvasRelativePosition(new Vector3(0.025f, 0.05f, 0f)); edit1 = new EditText() { Text = "Edit text 1", Font = Content.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true, }; ApplyEditTextDefaultStyle(edit1); edit1.SetCanvasRelativePosition(new Vector3(0.025f, 0.15f, 0f)); var text2 = new TextBlock { Text = "text block button 2", Font = Content.Load<SpriteFont>("MicrosoftSansSerif15"), SynchronousCharacterGeneration = true }; ApplyTextBlockDefaultStyle(text2); button2 = new Button { Content = text2 }; ApplyButtonDefaultStyle(button2); edit2 = new EditText() { Text = "Edit text 2", Font = Content.Load<SpriteFont>("MicrosoftSansSerif15"), }; ApplyEditTextDefaultStyle(edit2); stackPanel = new StackPanel { Children = { button2, edit2 }, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Orientation = Orientation.Horizontal }; stackPanel.SetCanvasRelativePosition(new Vector3(0.5f, 0.5f, 0f)); stackPanel.SetCanvasPinOrigin(new Vector3(.5f)); canvas = new Canvas { Children = {button1, edit1, stackPanel}, CanBeHitByUser = true }; button1.MouseOverStateChanged += (sender, args) => { triggeredButton1 = true; oldValueButton1 = args.OldValue; newValueButton1 = args.NewValue;}; button2.MouseOverStateChanged += (sender, args) => { triggeredButton2 = true;}; edit1.MouseOverStateChanged += (sender, args) => { triggeredEdit1 = true;}; edit2.MouseOverStateChanged += (sender, args) => { triggeredEdit2 = true;}; canvas.MouseOverStateChanged += (sender, args) => { triggeredCanvas = true;}; stackPanel.MouseOverStateChanged += (sender, args) => { triggeredStackPanel = true;}; canvas.UIElementServices = new UIElementServices { Services = this.Services }; UIComponent.Page = new Engine.UIPage { RootElement = canvas }; }
protected override async Task LoadContent() { await base.LoadContent(); // setup the camera var camera = new TestCamera { Yaw = 0, Pitch = 0, Position = new Vector3(0, 0, 1000), MoveSpeed = 100 }; CameraComponent = camera.Camera; Script.Add(camera); UIRoot.Transform.Rotation = Quaternion.RotationX(MathUtil.Pi / 3f); UIComponent.RootElement = new ImageElement { Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv"))}; UIComponent.IsFullScreen = false; UIComponent.IsBillboard = false; UIComponent.Resolution = new Vector3(200, 200, 100); UIRoot.Transform.Scale = new Vector3(200, 200, 100); var cube = new Entity { new ModelComponent { Model = Content.Load<Model>("cube Model") } }; cube.Transform.Scale = new Vector3(10000); cube.Transform.Position = new Vector3(0, 0, 10); Scene.Entities.Add(cube); var font = Content.Load<SpriteFont>("CourierNew12"); var textBlockZ0 = new TextBlock { Font = font, TextColor = Color.Black, TextSize = 20, Text = "At depth 0", VerticalAlignment = VerticalAlignment.Center, SynchronousCharacterGeneration = true, BackgroundColor = Color.Red }; var entity1 = new Entity { new UIComponent { RootElement = textBlockZ0, IsFullScreen = false, IsBillboard = false, Resolution = new Vector3(150) } }; entity1.Transform.Scale = new Vector3(150); entity1.Transform.Position = new Vector3(-500, 0, 0); Scene.Entities.Add(entity1); var textBlockZ500 = new TextBlock { Font = font, TextColor = Color.Black, TextSize = 20, Text = "At depth 300", VerticalAlignment = VerticalAlignment.Center, SynchronousCharacterGeneration = true, BackgroundColor = Color.Red }; var entity2 = new Entity { new UIComponent { RootElement = textBlockZ500, IsFullScreen = false, IsBillboard = false, Resolution = new Vector3(150) } }; entity2.Transform.Scale = new Vector3(150); entity2.Transform.Position = new Vector3(300, 0, 300); Scene.Entities.Add(entity2); var textBlockZM500 = new TextBlock { Font = font, TextColor = Color.Black, TextSize = 20, Text = "At depth -300", VerticalAlignment = VerticalAlignment.Center, SynchronousCharacterGeneration = true, BackgroundColor = Color.Red }; var entity3 = new Entity { new UIComponent { RootElement = textBlockZM500, IsFullScreen = false, IsBillboard = false, Resolution = new Vector3(150) } }; entity3.Transform.Scale = new Vector3(150); entity3.Transform.Position = new Vector3(0, 300, -300); Scene.Entities.Add(entity3); elements.Add(entity1); elements.Add(entity2); elements.Add(entity3); }
protected override async Task LoadContent() { await base.LoadContent(); var textblock = new TextBlock { Font = Content.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true }; ApplyTextBlockDefaultStyle(textblock); var element1 = new Button { Name = "1", Width = 800, Height = 400, Content = textblock }; ApplyButtonDefaultStyle(element1); element1.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(100, 50, 0)); element1.DependencyProperties.Set(Panel.ZIndexPropertyKey, -1); textblock = new TextBlock { Font = Content.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true }; ApplyTextBlockDefaultStyle(textblock); var element2 = new Button { Name = "2", Width = 400, Height = 200, Content = textblock }; ApplyButtonDefaultStyle(element2); element2.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(300, 150, 0)); element2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1); textblock = new TextBlock { Font = Content.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true }; ApplyTextBlockDefaultStyle(textblock); var element3 = new Button { Name = "3", Width = 400, Height = 200, Content = textblock }; ApplyButtonDefaultStyle(element3); element3.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(150, 225, 0)); element3.DependencyProperties.Set(Panel.ZIndexPropertyKey, 2); textblock = new TextBlock { Font = Content.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true }; ApplyTextBlockDefaultStyle(textblock); var element4 = new Button { Name = "4", Width = 400, Height = 200, Content = textblock }; ApplyButtonDefaultStyle(element4); element4.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(450, 75, 0)); element4.DependencyProperties.Set(Panel.ZIndexPropertyKey, 0); var canvas = new Canvas(); canvas.Children.Add(element1); canvas.Children.Add(element2); canvas.Children.Add(element3); canvas.Children.Add(new Canvas { Children = { element4 } }); elements = new List<Button> { element1, element2, element3, element4 }; UIComponent.Page = new Engine.UIPage { RootElement = canvas }; }
protected override async Task LoadContent() { await base.LoadContent(); var imgElt = new ImageElement { Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")), StretchType = StretchType.Fill }; imgElt.DependencyProperties.Set(GridBase.RowSpanPropertyKey, 2); imgElt.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2); imgElt.DependencyProperties.Set(GridBase.RowPropertyKey, 1); imgElt.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); var button1 = new Button(); ApplyButtonDefaultStyle(button1); button1.DependencyProperties.Set(GridBase.RowPropertyKey, 3); button1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0); var button2 = new Button(); ApplyButtonDefaultStyle(button2); button2.DependencyProperties.Set(GridBase.RowPropertyKey, 3); button2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 3); var text = new TextBlock { Text = "Test Uniform Grid", Font = Content.Load<SpriteFont>("MicrosoftSansSerif15"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; ApplyTextBlockDefaultStyle(text); text.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2); text.DependencyProperties.Set(GridBase.RowPropertyKey, 0); text.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); var grid = new UniformGrid { Rows = 4, Columns = 4}; grid.Children.Add(imgElt); grid.Children.Add(button1); grid.Children.Add(button2); grid.Children.Add(text); UIComponent.Page = new Engine.UIPage { RootElement = grid }; }
protected override async Task LoadContent() { await base.LoadContent(); textBlock = new TextBlock { TextColor = Color.Black, Font = Asset.Load<SpriteFont>("MSMincho10"), Text = @"Simple sample text surrounded by decorator.", SynchronousCharacterGeneration = true }; var decorator = new ContentDecorator { Content = textBlock, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, BackgroundImage = new Sprite(Asset.Load<Texture>("DumbWhite")) }; UIComponent.RootElement = decorator; }
protected override async Task LoadContent() { await base.LoadContent(); UIComponent.Resolution = new Vector3(GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height, 500); textBlock = new TextBlock { TextColor = Color.Black, Font = Content.Load<SpriteFont>("HanSans13"), Text = @"Text Block test にほんご ニホンゴ 人 Several line of texts with different width. Next is empty. This is the last line.", SynchronousCharacterGeneration = true, BackgroundColor = Color.LightSkyBlue }; UIComponent.Page = new Engine.UIPage { RootElement = textBlock }; }
protected override async Task LoadContent() { await base.LoadContent(); textBlock = new TextBlock { Font = Content.Load<SpriteFont>("HanSans13"), Text = "Simple Text - 簡単な文章。", TextColor = Color.Black, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, SynchronousCharacterGeneration = true }; decorator = new ContentDecorator { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, BackgroundImage = (SpriteFromTexture)new Sprite(Content.Load<Texture>("DumbWhite")), Content = textBlock }; UIComponent.Page = new Engine.UIPage { RootElement = decorator }; }
private Button CreateButton(int col, int row, float minimumHeight = 0, float minimumWidth = 0, bool randomMinHeight = false, bool randowMinWidth = false) { var textBlock = new TextBlock { Text = "Col " + col + " - Row " + row, Font = Content.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center}; ApplyTextBlockDefaultStyle(textBlock); var button = new Button { Name = "Button at col " + col + " - row " + row, MinimumHeight = minimumHeight, MinimumWidth = minimumWidth, Content = textBlock }; ApplyButtonDefaultStyle(button); if (randomMinHeight) button.MinimumHeight = minimumHeight + 3 * (float)random.NextDouble() * minimumHeight; if (randowMinWidth) button.MinimumWidth = minimumWidth + 3 * (float)random.NextDouble() * minimumWidth; button.DependencyProperties.Set(GridBase.ColumnPropertyKey, col); button.DependencyProperties.Set(GridBase.RowPropertyKey, row); return button; }
private void InitializeMainPage() { var rootElement = page.RootElement; // counters bonusCounter = rootElement.FindVisualChildOfType<TextBlock>("bonusCounter"); lifeCounter = rootElement.FindVisualChildOfType<TextBlock>("lifeCounter"); moneyCounter = rootElement.FindVisualChildOfType<TextBlock>("moneyCounter"); Bonus = 30; LifeStatus = 3; Money = 30; // lifebar lifebarGaugeImage = MainSceneImages["life_bar"]; lifebarGrid = rootElement.FindVisualChildOfType<Grid>("lifebarGrid"); gaugeBarRegion = lifebarGaugeImage.Region; // character name nameTextBlock = rootElement.FindVisualChildOfType<TextBlock>("nameTextBlock"); // explanation // FIXME: UI asset should support multiline text var explanationText = rootElement.FindVisualChildOfType<TextBlock>("explanationText"); explanationText.Text = "Pictogram-based alphabets are easily supported.\n日本語も簡単に入れることが出来ます。"; // status stars var statusPanel = rootElement.FindVisualChildOfType<UniformGrid>("statusPanel"); powerStatusStar = statusPanel.FindVisualChildOfType<ImageElement>("powerStatusStar"); controlStatusStar = statusPanel.FindVisualChildOfType<ImageElement>("controlStatusStar"); speedStatusStar = statusPanel.FindVisualChildOfType<ImageElement>("speedStatusStar"); PowerStatus = shipList[activeShipIndex].Power; ControlStatus = shipList[activeShipIndex].Control; SpeedStatus = shipList[activeShipIndex].Speed; // ship selection var currentShipButton = rootElement.FindVisualChildOfType<Button>("currentShipButton"); currentShipButton.Click += delegate { // Once click, update the SpaceShip status pop-up and show it. UpdateShipStatus(); ShowShipSelectionPopup(); }; currentShipImage = currentShipButton.FindVisualChildOfType<ImageElement>("currentShipImage"); // upgrade buttons var statusUpgradePanel = rootElement.FindVisualChildOfType<UniformGrid>("statusUpgradePanel"); SetupStatusButton(statusUpgradePanel.FindVisualChildOfType<ButtonBase>("powerStatusButton"), 2, 0, () => PowerStatus, () => PowerStatus++); SetupStatusButton(statusUpgradePanel.FindVisualChildOfType<ButtonBase>("controlStatusButton"), 2, 0, () => ControlStatus, () => ControlStatus++); SetupStatusButton(statusUpgradePanel.FindVisualChildOfType<ButtonBase>("speedStatusButton"), 2, 0, () => SpeedStatus, () => SpeedStatus++); SetupStatusButton(statusUpgradePanel.FindVisualChildOfType<ButtonBase>("lifeStatusButton"), 1, 1, () => 0, () => LifeStatus++); // quit button var quitButton = rootElement.FindVisualChildOfType<Button>("quitButton"); quitButton.Click += delegate { UIGame.Exit(); }; }
private void BuildUI() { var width = 400; var bufferRatio = GraphicsDevice.Presenter.BackBuffer.Width / (float)GraphicsDevice.Presenter.BackBuffer.Height; var ui = new UIComponent { Resolution = new Vector3(width, width / bufferRatio, 500) }; SceneSystem.SceneInstance.Scene.Entities.Add(new Entity { ui }); currentText = new TextBlock { Font = font, TextColor = Color.White, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Center }; var buttonBack = new Button { Content = new TextBlock { Font = font, Text = "Previous" }, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left }; var buttonNext = new Button { Content = new TextBlock { Font = font, Text = "Next" }, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right }; currentText.SetGridColumn(1); buttonNext.SetGridColumn(2); buttonBack.Click += (o, _) => ChangeScene(-1); buttonNext.Click += (o, _) => ChangeScene(+1); ui.RootElement = new UniformGrid { Columns = 3, Children = { buttonBack, currentText, buttonNext } }; }
private void CreateGameUI() { scoreTextBlock = new TextBlock { Font = Font, TextColor = Color.Black, VerticalAlignment = VerticalAlignment.Center }; scoreTextBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f)); scoreTextBlock.SetCanvasRelativePosition(new Vector3(0.2f, 0.05f, 0f)); var scoreBoard = new ContentDecorator { BackgroundImage = SpriteFromSheet.Create(UIImages, "score_bg"), Content = scoreTextBlock, Padding = new Thickness(60, 31, 25, 35), MinimumWidth = 190f // Set the minimum width of score button so that it wont modify when the content (text) changes, and less than minimum. }; gameRoot = new Canvas(); gameRoot.Children.Add(scoreBoard); }
/// <summary> /// Creates UI showing parameters of Fault formation algorithm /// </summary> private void CreateUI() { var virtualResolution = new Vector3(GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height, 1); loadingModal = new ModalElement { Visibility = Visibility.Collapsed }; loadingTextBlock = new TextBlock { Font = Font, Text = "Loading a model...", Visibility = Visibility.Collapsed, TextColor = Color.White, TextSize = 22 }; loadingTextBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f)); loadingTextBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.5f, 0)); // Parameters Grid var parametersGrid = new Grid(); parametersGrid.LayerDefinitions.Add(new StripDefinition(StripType.Auto)); parametersGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); parametersGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); parametersGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); parametersGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); parametersGrid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); parametersGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto)); parametersGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Star)); parametersGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 30)); parametersGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 30)); // Terrain Size var terrainSizeText = new TextBlock { Font = Font, Text = "" + (int)Math.Pow(2, terrainSizePowerFactor), TextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, MinimumWidth = 60 }; terrainSizeText.SetGridRow(0); terrainSizeText.SetGridColumn(1); var terrainSizeIncButton = new Button { Content = new TextBlock { Text = "+", Font = Font, TextAlignment = TextAlignment.Center } }; terrainSizeIncButton.SetGridRow(0); terrainSizeIncButton.SetGridColumn(3); var terrainSizeDecButton = new Button { Content = new TextBlock { Text = "-", Font = Font, TextAlignment = TextAlignment.Center } }; terrainSizeDecButton.SetGridRow(0); terrainSizeDecButton.SetGridColumn(2); terrainSizeIncButton.Click += (s, e) => { TerrainSizePowerFactor++; terrainSizeText.Text = "" + (int)Math.Pow(2, TerrainSizePowerFactor); }; terrainSizeDecButton.Click += (s, e) => { TerrainSizePowerFactor--; terrainSizeText.Text = "" + (int)Math.Pow(2, TerrainSizePowerFactor); }; var terrainSizeDescription = new TextBlock { Font = Font, Text = "Terrain Size:", TextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left }; terrainSizeDescription.SetGridRow(0); terrainSizeDescription.SetGridColumn(0); parametersGrid.Children.Add(terrainSizeDescription); parametersGrid.Children.Add(terrainSizeText); parametersGrid.Children.Add(terrainSizeDecButton); parametersGrid.Children.Add(terrainSizeIncButton); // Iteration var iterationText = new TextBlock { Font = Font, Text = "" + (int)Math.Pow(2, IterationPowerFactor), TextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; iterationText.SetGridRow(1); iterationText.SetGridColumn(1); var iterationIncButton = new Button { Content = new TextBlock { Text = "+", Font = Font, TextAlignment = TextAlignment.Center } }; iterationIncButton.SetGridRow(1); iterationIncButton.SetGridColumn(3); var iterationDecButton = new Button { Content = new TextBlock { Text = "-", Font = Font, TextAlignment = TextAlignment.Center } }; iterationDecButton.SetGridRow(1); iterationDecButton.SetGridColumn(2); iterationIncButton.Click += (s, e) => { IterationPowerFactor++; iterationText.Text = "" + (int)Math.Pow(2, IterationPowerFactor); }; iterationDecButton.Click += (s, e) => { IterationPowerFactor--; iterationText.Text = "" + (int)Math.Pow(2, IterationPowerFactor); }; var iterationDescription = new TextBlock { Font = Font, Text = "Iteration:", TextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left }; iterationDescription.SetGridRow(1); iterationDescription.SetGridColumn(0); parametersGrid.Children.Add(iterationDescription); parametersGrid.Children.Add(iterationText); parametersGrid.Children.Add(iterationDecButton); parametersGrid.Children.Add(iterationIncButton); // Filter Intensity var filterIntensityText = new TextBlock { Font = Font, Text = "" + FilterHeightBandStrength, TextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; filterIntensityText.SetGridRow(2); filterIntensityText.SetGridColumn(1); var filterIncButton = new Button { Content = new TextBlock { Text = "+", Font = Font, TextAlignment = TextAlignment.Center } }; filterIncButton.SetGridRow(2); filterIncButton.SetGridColumn(3); var filterDecButton = new Button { Content = new TextBlock { Text = "-", Font = Font, TextAlignment = TextAlignment.Center } }; filterDecButton.SetGridRow(2); filterDecButton.SetGridColumn(2); filterIncButton.Click += (s, e) => { FilterHeightBandStrength += 0.1f; filterIntensityText.Text = "" + FilterHeightBandStrength; }; filterDecButton.Click += (s, e) => { FilterHeightBandStrength -= 0.1f; filterIntensityText.Text = "" + FilterHeightBandStrength; }; var filterIntensityDescription = new TextBlock { Font = Font, Text = "Filter Intensity:", TextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left }; filterIntensityDescription.SetGridRow(2); filterIntensityDescription.SetGridColumn(0); parametersGrid.Children.Add(filterIntensityDescription); parametersGrid.Children.Add(filterIntensityText); parametersGrid.Children.Add(filterDecButton); parametersGrid.Children.Add(filterIncButton); // Height Scale var heightScaleText = new TextBlock { Font = Font, Text = "" + TerrainHeightScale, TextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; heightScaleText.SetGridRow(3); heightScaleText.SetGridColumn(1); var heightScaleIncButton = new Button { Content = new TextBlock { Text = "+", Font = Font, TextAlignment = TextAlignment.Center } }; heightScaleIncButton.SetGridRow(3); heightScaleIncButton.SetGridColumn(3); var heightScaleDecButton = new Button { Content = new TextBlock { Text = "-", Font = Font, TextAlignment = TextAlignment.Center } }; heightScaleDecButton.SetGridRow(3); heightScaleDecButton.SetGridColumn(2); heightScaleIncButton.Click += (s, e) => { TerrainHeightScale++; heightScaleText.Text = "" + TerrainHeightScale; }; heightScaleDecButton.Click += (s, e) => { TerrainHeightScale--; heightScaleText.Text = "" + TerrainHeightScale; }; var heightScaleDescription = new TextBlock { Font = Font, Text = "Height Scale:", TextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left }; heightScaleDescription.SetGridRow(3); heightScaleDescription.SetGridColumn(0); parametersGrid.Children.Add(heightScaleDescription); parametersGrid.Children.Add(heightScaleText); parametersGrid.Children.Add(heightScaleDecButton); parametersGrid.Children.Add(heightScaleIncButton); // Zoom var zoomFactorIncButton = new Button { Content = new TextBlock { Text = "+", Font = Font, TextAlignment = TextAlignment.Center } }; zoomFactorIncButton.SetGridRow(4); zoomFactorIncButton.SetGridColumn(3); var zoomFactorDecButton = new Button { Content = new TextBlock { Text = "-", Font = Font, TextAlignment = TextAlignment.Center } }; zoomFactorDecButton.SetGridRow(4); zoomFactorDecButton.SetGridColumn(2); zoomFactorIncButton.Click += (s, e) => { zoomFactor -= 0.1f; UpdateCamera(); }; zoomFactorDecButton.Click += (s, e) => { zoomFactor += 0.1f; UpdateCamera(); }; var zoomDescription = new TextBlock { Font = Font, Text = "Zoom", TextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Right }; zoomDescription.SetGridRow(4); zoomDescription.SetGridColumn(0); parametersGrid.Children.Add(zoomDescription); parametersGrid.Children.Add(zoomFactorDecButton); parametersGrid.Children.Add(zoomFactorIncButton); // Light toggle button var lightToggleButton = new Button { Content = new TextBlock { Text = "Directional Light Off", Font = Font }, HorizontalAlignment = HorizontalAlignment.Left }; lightToggleButton.Click += (s, e) => { var ligh0 = DirectionalLight0.Get<LightComponent>(); var ligh1 = DirectionalLight1.Get<LightComponent>(); ligh0.Enabled = !ligh0.Enabled; ligh1.Enabled = !ligh1.Enabled; ((TextBlock)lightToggleButton.Content).Text = ligh0.Enabled ? "Directional Light Off" : "Directional Light On"; }; // Re-create terrain var reCreateTerrainButton = new Button { Content = new TextBlock { Text = "Recreate terrain", Font = Font }, HorizontalAlignment = HorizontalAlignment.Left }; reCreateTerrainButton.Click += (s, e) => GenerateTerrain(); var descriptionCanvas = new StackPanel { Children = { new TextBlock { Font = Font, Text = "Fault formation parameters", TextSize = 19}, parametersGrid, lightToggleButton, reCreateTerrainButton } }; var activeButton = new Button { Content = new TextBlock { Text = "Description Off", Font = Font }, Padding = new Thickness(10, 10, 10, 10), Margin = new Thickness(0, 0, 0, 20), HorizontalAlignment = HorizontalAlignment.Left }; var isDescriptionOn = true; activeButton.Click += (s, e) => { isDescriptionOn = !isDescriptionOn; ((TextBlock)activeButton.Content).Text = isDescriptionOn ? "Description Off" : "Description On"; descriptionCanvas.Visibility = isDescriptionOn ? Visibility.Visible : Visibility.Collapsed; }; var buttonDescription = new StackPanel { Orientation = Orientation.Vertical, Children = { activeButton, descriptionCanvas } }; var uiComponent = UIEntity.Get<UIComponent>(); uiComponent.RootElement = new Canvas { Children = { buttonDescription, loadingModal, loadingTextBlock } }; uiComponent.Resolution = virtualResolution; }
private Button CreateButton(string name, float height, string text) { var textBlock = new TextBlock { Text = text, Font = Content.Load<SpriteFont>("MicrosoftSansSerif15") }; ApplyTextBlockDefaultStyle(textBlock); var button = new Button { Name = name, Height = height, Content = textBlock }; ApplyButtonDefaultStyle(button); return button; }
protected void ApplyTextBlockDefaultStyle(TextBlock textBlock) { if (textBlock == null) throw new ArgumentNullException(nameof(textBlock)); textBlock.TextColor = textBlockTextColor; }
protected override async Task LoadContent() { await base.LoadContent(); var resolution = (Vector3)UIComponent.VirtualResolution; var canvas = new Canvas(); var imgElt = new ImageElement { Name = "UV image", Source = new Sprite(Asset.Load<Texture>("uv")), Width = resolution.X / 5, Height = resolution.Y / 5, StretchType = StretchType.Fill }; imgElt.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One); imgElt.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(resolution.X / 10, resolution.Y / 10, 0)); imgElt.DependencyProperties.Set(Panel.ZIndexPropertyKey, -1); stackPanel = new StackPanel { Orientation = Orientation.Vertical }; scrollViewer = new ScrollViewer { ScrollMode = ScrollingMode.Vertical }; scrollViewer.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(resolution.X / 4, resolution.Y / 10, 0)); scrollViewer.Content = stackPanel; var button1 = new Button { Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5), LocalMatrix = Matrix.Scaling(2, 2, 2) }; var textOnly = new TextBlock { Text = "Text only button", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextColor = new Color(1f, 0, 0, 0.5f) }; button1.Content = textOnly; var button2 = new Button { Name = "Button2", Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5) }; var imageContent = new ImageElement { Name = "Image Button2", Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch, MaximumHeight = 50 }; button2.Content = imageContent; var button3 = new Button { Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5) }; var stackContent = new StackPanel { Orientation = Orientation.Horizontal }; var stackImage = new ImageElement { Name = "Image stack panel", Source = new Sprite(Asset.Load<Texture>("uv")), MaximumHeight = 50 }; var stackText = new TextBlock { Text = "button text", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), Margin = Thickness.UniformRectangle(5) }; stackContent.Children.Add(stackImage); stackContent.Children.Add(stackText); button3.Content = stackContent; var button4 = new Button { Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Right, Padding = Thickness.UniformRectangle(5) }; var imageContent2 = new ImageElement { Name = "button 4 uv image", Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch, MaximumHeight = 40, Opacity = 0.5f }; button4.Content = imageContent2; var button5 = new Button { Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Left, Padding = Thickness.UniformRectangle(5) }; var textOnly2 = new TextBlock { Text = "Left aligned", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }; button5.Content = textOnly2; var button6 = new ImageButton { Height = 50, Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Center, PressedImage = new Sprite(Asset.Load<Texture>("ImageButtonPressed")), NotPressedImage = new Sprite(Asset.Load<Texture>("ImageButtonNotPressed")), }; toggle = new ToggleButton { Content = new TextBlock { Text = "Toggle button test", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }, IsThreeState = true }; scrollingText = new ScrollingText { Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), Text = "<<<--- Scrolling text in a button ", IsEnabled = IsUpdateAutomatic }; var button7 = new Button { Margin = Thickness.UniformRectangle(5), Content = scrollingText }; var uniformGrid = new UniformGrid { Rows = 2, Columns = 2 }; var gridText = new TextBlock { Text = "Uniform grid", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center}; gridText.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2); var buttonLeft = new Button { Content = new TextBlock { Text = "unif-grid left", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center } }; buttonLeft.DependencyProperties.Set(GridBase.RowPropertyKey, 1); var buttonRight = new Button { Content = new TextBlock { Text = "unif-grid right", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center } }; buttonRight.DependencyProperties.Set(GridBase.RowPropertyKey, 1); buttonRight.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); uniformGrid.Children.Add(gridText); uniformGrid.Children.Add(buttonLeft); uniformGrid.Children.Add(buttonRight); stackPanel.Children.Add(button1); stackPanel.Children.Add(button2); stackPanel.Children.Add(button3); stackPanel.Children.Add(button4); stackPanel.Children.Add(button5); stackPanel.Children.Add(button6); stackPanel.Children.Add(toggle); stackPanel.Children.Add(button7); stackPanel.Children.Add(uniformGrid); canvas.Children.Add(imgElt); canvas.Children.Add(scrollViewer); UIComponent.RootElement = canvas; }