示例#1
0
文件: UIScript.cs 项目: cg123/xenko
        private void CreateMainMenuUI()
        {
            var xenkoLogo = new ImageElement { Source = SpriteFromSheet.Create(UIImages, "xk_logo") };

            xenkoLogo.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f));
            xenkoLogo.SetCanvasRelativeSize(new Vector3(0.75f, 0.5f, 1f));
            xenkoLogo.SetCanvasRelativePosition(new Vector3(0.5f, 0.3f, 1f));

            StartButton = new Button
            {
                Content = new TextBlock {Font = Font, Text = "Touch to Start", TextColor = Color.Black, 
                    HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center},
                NotPressedImage = buttonImage,
                PressedImage = buttonImage,
                MouseOverImage = buttonImage,
                Padding = new Thickness(77, 30, 25, 30),
                MinimumWidth = 250f,
            };

            StartButton.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f));
            StartButton.SetCanvasRelativePosition(new Vector3(0.5f, 0.7f, 0f));

            var mainMenuCanvas = new Canvas();
            mainMenuCanvas.Children.Add(xenkoLogo);
            mainMenuCanvas.Children.Add(StartButton);

            mainMenuRoot = new ModalElement
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Content = mainMenuCanvas
            };
        }
示例#2
0
        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;
        }
示例#3
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();
            
            buttonLeftTop2 = new Button { Padding = new Thickness(50, 50, 0, 50) };
            buttonLeftTop1 = new Button { Padding = new Thickness(50, 50, 0, 50), Content = buttonLeftTop2 };
            buttonLeftTop0 = new Button { Padding = new Thickness(50, 50, 0, 50), Content = buttonLeftTop1};

            var bottomGrid = new UniformGrid { Rows = 1, Columns = 2 };
            bottomButton = new Button { Content = bottomGrid };
            bottomButton.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            bottomButton.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);

            buttonBottomLeft1 = new Button { Margin = new Thickness(50, 50, 0, 50) };
            buttonBottomLeft0 = new Button { Margin = new Thickness(50, 0, 0, 100), Content = buttonBottomLeft1 };

            bottonBottomRight1 = new Button { Margin = new Thickness(0, 0, 50, 100) };
            buttomBottonRight0 = new Button { Margin = new Thickness(0, 0, 50, 50), Content = bottonBottomRight1 };
            buttomBottonRight0.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);

            bottomGrid.Children.Add(buttonBottomLeft0);
            bottomGrid.Children.Add(buttomBottonRight0);

            var mainGrid = new UniformGrid { Rows = 2, Columns = 2 };
            mainGrid.Children.Add(buttonLeftTop0);
            mainGrid.Children.Add(bottomButton);

            UIComponent.RootElement = mainGrid;
        }
示例#4
0
        public void TestProperties()
        {
            var control = new Button();

            // test properties default values
            Assert.AreEqual(new Thickness(10, 5, 10, 7), control.Padding);
        }
示例#5
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var element1 = new Button { Name = "1", Width = 800, Height = 400, Content = new TextBlock { Font = Asset.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true } };
            element1.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(100, 50, 0));
            element1.DependencyProperties.Set(Panel.ZIndexPropertyKey, -1);

            var element2 = new Button { Name = "2", Width = 400, Height = 200, Content = new TextBlock { Font = Asset.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true } };
            element2.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(300, 150, 0));
            element2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);

            var element3 = new Button { Name = "3", Width = 400, Height = 200, Content = new TextBlock { Font = Asset.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true } };
            element3.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(150, 225, 0));
            element3.DependencyProperties.Set(Panel.ZIndexPropertyKey, 2);

            var element4 = new Button { Name = "4", Width = 400, Height = 200, Content = new TextBlock { Font = Asset.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true } };
            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.RootElement = canvas;
        }
示例#6
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            button = new Button();

            UIComponent.RootElement = button;
        }
示例#7
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            button = new Button();
            ApplyButtonDefaultStyle(button);

            UIComponent.Page = new Engine.UIPage { RootElement = button };
        }
示例#8
0
        public void TestBasicInvalidations()
        {
            var newButton = new Button();

            // - test the properties that are supposed to invalidate the object measurement
            UIElementLayeringTests.TestMeasureInvalidation(this, () => Content = newButton);

            var sameButton = newButton;

            // - test the properties that are not supposed to invalidate the object layout state
            UIElementLayeringTests.TestNoInvalidation(this, () => Content = sameButton);
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            button = new Button
            {
                PressedImage = (SpriteFromTexture)new Sprite(Content.Load<Texture>("ImageButtonPressed")),
                NotPressedImage = (SpriteFromTexture)new Sprite(Content.Load<Texture>("ImageButtonNotPressed")),
                Content = null,
                SizeToContent = false
            };

            UIComponent.Page = new Engine.UIPage { RootElement = button };
        }
示例#10
0
        protected override void LoadScene()
        {
            Game.Window.AllowUserResizing = false;

            var backBufferSize = new Vector2(GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height);
            centerPoint = new Vector2(backBufferSize.X / 2, backBufferSize.Y / 2);

            var longButton = (SpriteFromTexture) SplashScreenImages["button_long"];
            var longSize = new Vector3(SplashScreenImages["button_long"].SizeInPixels.X,
                SplashScreenImages["button_long"].SizeInPixels.Y, 0);

            // This button will be followed
            followedButton = new Button
            {
                PressedImage = longButton,
                NotPressedImage = longButton,
                MouseOverImage =  longButton,

                Size = longSize,

                // This element will be followed, because we have specified the same name in the FollowingEntity's UI Element Link
                Name = "ElementName",
            };

            // Load the next scene when the user clicks the button
            followedButton.Click += delegate { LoadNextScene(); };

            // Corner buttons
            var boxButton = (SpriteFromTexture)SplashScreenImages["button_box"];
            var boxSize = new Vector3(SplashScreenImages["button_box"].SizeInPixels.X,
                SplashScreenImages["button_box"].SizeInPixels.Y, 0);

            var cornerTL = new Button { PressedImage = boxButton, NotPressedImage = boxButton, MouseOverImage = boxButton, Size = boxSize };
            cornerTL.SetCanvasAbsolutePosition(new Vector3(0, 0, 0));

            var cornerTR = new Button { PressedImage = boxButton, NotPressedImage = boxButton, MouseOverImage = boxButton, Size = boxSize };
            cornerTR.SetCanvasAbsolutePosition(new Vector3(backBufferSize.X - boxSize.X, 0, 0));

            var cornerBL = new Button { PressedImage = boxButton, NotPressedImage = boxButton, MouseOverImage = boxButton, Size = boxSize };
            cornerBL.SetCanvasAbsolutePosition(new Vector3(0, backBufferSize.Y - boxSize.Y, 0));

            var cornerBR = new Button { PressedImage = boxButton, NotPressedImage = boxButton, MouseOverImage = boxButton, Size = boxSize };
            cornerBR.SetCanvasAbsolutePosition(new Vector3(backBufferSize.X - boxSize.X, backBufferSize.Y - boxSize.Y, 0));

            var rootElement = new Canvas() { Children = { followedButton, cornerTL, cornerTR, cornerBL, cornerBR },
                MaximumWidth = backBufferSize.X, MaximumHeight = backBufferSize.Y };

            Entity.Get<UIComponent>().RootElement = rootElement;
        }
示例#11
0
        /// <summary>
        /// Create a button and link the click action to the corresponding animation.
        /// </summary>
        private Button CreateButton(string animationName)
        {
            var idleButton = new Button
            {
                Content = new TextBlock
                {
                    Text = "Play " + animationName,
                    Font = Font,
                },
                Padding = new Thickness(10, 10, 10, 10),
                Margin = new Thickness(0, 0, 0, 10),
            };
            idleButton.Click += (s, e) => Knight.Get<AnimationComponent>().Crossfade(animationName, TimeSpan.FromSeconds(0.1));

            return idleButton;
        }
示例#12
0
        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 };
        }
        private Button CreateButton(string text, int textSize, int columnId, Scene targetScene)
        {
            var button = new Button
            {
                Name = text,
                HorizontalAlignment = HorizontalAlignment.Center,
                Content = new TextBlock { Text = text, Font = Font, TextSize = textSize, TextColor = new Color(200, 200, 200, 255), VerticalAlignment = VerticalAlignment.Center },
                BackgroundColor = new Color(new Vector4(0.2f, 0.2f, 0.2f, 0.2f)),
            };

            button.SetGridColumn(columnId);

            button.Click += (sender, args) =>
            {
                SceneSystem.SceneInstance.Scene = targetScene;
                Cancel();
            };

            return button;
        }
        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 };
        }
示例#15
0
        public void TestUpdateWorldMatrixInvalidation()
        {
            var children = new Button();
            Content = children;

            var worldMatrix = Matrix.Zero;
            var localMatrix = Matrix.Identity;

            Measure(Vector3.Zero);
            Arrange(Vector3.Zero, false);
            UpdateWorldMatrix(ref worldMatrix, false);

            worldMatrix.M11 = 2;
            UpdateWorldMatrix(ref worldMatrix, true);
            Assert.AreEqual(worldMatrix.M11, children.WorldMatrix.M11);

            worldMatrix.M11 = 3;
            UpdateWorldMatrix(ref worldMatrix, false);
            Assert.AreEqual(2, children.WorldMatrix.M11);

            worldMatrix.M11 = 1;
            localMatrix.M11 = 4;
            LocalMatrix = localMatrix;
            UpdateWorldMatrix(ref worldMatrix, false);
            Assert.AreEqual(localMatrix.M11, children.WorldMatrix.M11);

            localMatrix.M11 = 1;
            LocalMatrix = localMatrix;
            UpdateWorldMatrix(ref worldMatrix, false);
            Assert.AreEqual(localMatrix.M11, children.WorldMatrix.M11);

            InvalidateArrange();
            Arrange(Vector3.Zero, false);

            worldMatrix.M11 = 5;
            UpdateWorldMatrix(ref worldMatrix, false);
            Assert.AreEqual(worldMatrix.M11, children.WorldMatrix.M11);
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var sprites = Content.Load<SpriteSheet>("UIImages");
            element1 = new Button { Name = "1", Width = 300, Height = 150 };
            element1.PressedImage = SpriteFromSheet.Create(sprites, "Logo");
            element1.NotPressedImage = SpriteFromSheet.Create(sprites, "BorderButton");
            element1.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(350, 300, 0));
            element1.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);

            element2 = new Button { Name = "2", Width = 600, Height = 300 };
            element2.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(200, 100, -50));
            element2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 0);
            element2.PressedImage = (SpriteFromTexture)new Sprite(Content.Load<Texture>("ImageButtonPressed"));
            element2.NotPressedImage = (SpriteFromTexture)new Sprite(Content.Load<Texture>("ImageButtonNotPressed"));

            var canvas = new Canvas();
            canvas.Children.Add(element1);
            canvas.Children.Add(element2);

            UIComponent.Page = new Engine.UIPage { RootElement = canvas };
        }
示例#17
0
        public void TestUpdateWorldMatrixInvalidation()
        {
            ResetState();

            var child = new Button();
            Children.Add(child);

            var worldMatrix = Matrix.Zero;
            var localMatrix = Matrix.Identity;
            
            Measure(Vector3.Zero);
            Arrange(Vector3.Zero, false);
            UpdateWorldMatrix(ref worldMatrix, false);
            
            worldMatrix.M11 = 2;
            UpdateWorldMatrix(ref worldMatrix, true);
            Assert.AreEqual(worldMatrix.M11, child.WorldMatrix.M11);
            
            worldMatrix.M11 = 3;
            UpdateWorldMatrix(ref worldMatrix, false);
            Assert.AreEqual(2, child.WorldMatrix.M11);
            
            worldMatrix.M11 = 1;
            localMatrix.M11 = 4;
            LocalMatrix = localMatrix;
            UpdateWorldMatrix(ref worldMatrix, false);
            Assert.AreEqual(localMatrix.M11, child.WorldMatrix.M11);
            
            localMatrix.M11 = 1;
            LocalMatrix = localMatrix;
            UpdateWorldMatrix(ref worldMatrix, false);
            Assert.AreEqual(localMatrix.M11, child.WorldMatrix.M11);
            
            InvalidateArrange();
            Arrange(Vector3.Zero, false);
            
            worldMatrix.M11 = 5;
            UpdateWorldMatrix(ref worldMatrix, false);
            Assert.AreEqual(worldMatrix.M11, child.WorldMatrix.M11);

            var secondButton = new Button();
            Children.Add(secondButton);
            Measure(Vector3.Zero);
            Arrange(Vector3.Zero, false);
            worldMatrix.M11 = 7;
            UpdateWorldMatrix(ref worldMatrix, false);
            Assert.AreEqual(worldMatrix.M11, child.WorldMatrix.M11);

            Children.Remove(secondButton);
            Measure(Vector3.Zero);
            Arrange(Vector3.Zero, false);
            worldMatrix.M11 = 9;
            UpdateWorldMatrix(ref worldMatrix, false);
            Assert.AreEqual(worldMatrix.M11, child.WorldMatrix.M11);

            worldMatrix.M11 = 1;
            UpdateWorldMatrix(ref worldMatrix, true);
            Assert.AreEqual(worldMatrix.M11, child.WorldMatrix.M11);

            var childArrangeMatrix = 10 * Matrix.Identity;
            child.DependencyProperties.Set(PanelArrangeMatrixPropertyKey, childArrangeMatrix);
            worldMatrix.M11 = 1;
            UpdateWorldMatrix(ref worldMatrix, false);
            Assert.AreEqual(childArrangeMatrix.M11, child.WorldMatrix.M11);
        }
示例#18
0
        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 } } };
        }
示例#19
0
        protected void ApplyButtonDefaultStyle(Button button)
        {
            if (button == null) throw new ArgumentNullException(nameof(button));

            button.PressedImage = buttonPressedImage;
            button.NotPressedImage = buttonNotPressedImage;
            button.MouseOverImage = buttonMouseOverImage;
        }
示例#20
0
 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;
 }
示例#21
0
        public void TestUnregisterHandlerInsideHandler()
        {
            testUnregisterHandlerCallCount = 0;

            var button = new Button();
            button.Click += TestUnregisterHandlerOnClick;
            button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));

            Assert.AreEqual(1, testUnregisterHandlerCallCount);
        }
示例#22
0
        public void TestHandlerRaiseOrder()
        {
            lastHandlerCalledId = 0;

            var button = new Button();
            button.Click += TestHandlerRaiseOrderOnClick1;
            button.Click += TestHandlerRaiseOrderOnClick2;
            button.Click += TestHandlerRaiseOrderOnClick3;
            button.Click += TestHandlerRaiseOrderOnClick4;

            button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));

            Assert.AreEqual(4, lastHandlerCalledId);
        }
示例#23
0
        public void TestReccursiveRaise()
        {
            clickCount = 0;

            var button = new Button();
            button.Click += TestReccursiveRaiseOnClick;
            button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));

            Assert.AreEqual(10, clickCount);
        }
示例#24
0
        private Button CreateButton(int col, int row, float minimumHeight = 0, float minimumWidth = 0, bool randomMinHeight = false, bool randowMinWidth = false)
        {
            var button =  new Button
            {
                Name = "Button at col " + col + " - row " + row,
                MinimumHeight = minimumHeight,
                MinimumWidth = minimumWidth,
                Content = new TextBlock { Text = "Col " + col + " - Row " + row, Font = Content.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center}
            };

            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;
        }
示例#25
0
文件: UIScript.cs 项目: cg123/xenko
        // Create a button that can toggle on/off the light shadow map
        private Button CreateShadowButton(UIElement parentButton, LightComponent component)
        {
            var button = new Button
            {
                Margin = new Thickness(20, 5, 5, 5),
                Name = "Shadow Button " + component.Entity.Name,
                Opacity = component.Enabled ? 1.0f : 0.3f,
                CanBeHitByUser = component.Enabled,
                Content = new TextBlock
                {
                    Font = Font,
                    TextAlignment = TextAlignment.Right,
                    Text = GetButtonTextOnOffShadow(component),
                },
            };

            button.Click += ToggleShadowMap;

            button.DependencyProperties.Set(LightKey, component);
            parentButton.DependencyProperties.Set(ShadowButtonKey, button);

            return button;
        }
示例#26
0
文件: UIScript.cs 项目: cg123/xenko
        // Create a button that can toggle on/off the Light component
        private Button CreateLightButton(LightComponent component)
        {
            var button = new Button
            {
                Name = component.Entity.Name,
                Margin = Thickness.UniformRectangle(5),
                Content = new TextBlock
                {
                    Font = Font, 
                    TextAlignment = TextAlignment.Right,
                    Text = GetButtonTextOnOffLight(component), 
                },
            };
            button.Click += ToggleLight;
            button.DependencyProperties.Set(LightKey, component);

            return button;
        }
示例#27
0
        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 } };
        }
示例#28
0
        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;
        }
示例#29
0
        /// <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;
        }
示例#30
0
文件: UIScript.cs 项目: cg123/xenko
        private void CreateGameOverUI()
        {
            MenuButton = new Button
            {
                Content = new TextBlock { Font = Font, Text = "Menu", TextColor = Color.Black, 
                    HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center},
                PressedImage = buttonImage,
                NotPressedImage = buttonImage,
                MouseOverImage = buttonImage,
                Padding = new Thickness(77, 30, 25, 30),
                MinimumWidth = 190f,
            };

            MenuButton.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f));
            MenuButton.SetCanvasRelativePosition(new Vector3(0.70f, 0.7f, 0f));

            RetryButton = new Button
            {
                Content = new TextBlock { Font = Font, Text = "Retry", TextColor = Color.Black, 
                    HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center},
                Padding = new Thickness(74, 30, 25, 30),
                MinimumWidth = 190f,
                PressedImage = buttonImage,
                MouseOverImage = buttonImage,
                NotPressedImage = buttonImage
            };

            RetryButton.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f));
            RetryButton.SetCanvasRelativePosition(new Vector3(0.3f, 0.7f, 0f));

            var gameOverCanvas = new Canvas();
            gameOverCanvas.Children.Add(MenuButton);
            gameOverCanvas.Children.Add(RetryButton);
            
            gameOverRoot = new ModalElement
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Content = gameOverCanvas
            };
        }