Esempio n. 1
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var sprites = Asset.Load<SpriteSheet>("RotatedImages");
            var img1 = new ImageElement { Source = sprites["NRNR"], StretchType = StretchType.Fill };
            var img2 = new ImageElement { Source = sprites["RNR"], StretchType = StretchType.Fill };
            var img3 = new ImageElement { Source = sprites["NRR"], StretchType = StretchType.Fill };
            var img4 = new ImageElement { Source = sprites["RR"], StretchType = StretchType.Fill };

            img1.SetGridColumnSpan(2);
            img2.SetGridColumnSpan(2);
            img2.SetGridRow(1);
            img3.SetGridRowSpan(2);
            img3.SetGridColumn(2);
            img4.SetGridRowSpan(2);
            img4.SetGridColumn(3);

            var grid = new UniformGrid
            {
                Rows = 2, 
                Columns = 4,
                Children = { img1, img2, img3, img4 }
            };

            UIComponent.RootElement = grid;
        }
Esempio n. 2
0
        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
            };
        }
Esempio n. 3
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            imageElement = new ImageElement { Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv"))};
            UIComponent.RootElement = imageElement;
        }
Esempio n. 4
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var cube = new Entity { new ModelComponent { Model = Asset.Load<Model>("cube Model") } };
            cube.Transform.Scale = new Vector3(10000);
            cube.Transform.Position = new Vector3(0, 0, 10);
            Scene.Entities.Add(cube);

            var imageElement = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")) };
            var imageEntity = new Entity { new UIComponent { RootElement = imageElement, IsFullScreen = false, VirtualResolution = new Vector3(150) } };
            imageEntity.Transform.Position = new Vector3(-500, 0, 0);
            Scene.Entities.Add(imageEntity);

            var imageEntity2 = new Entity { new UIComponent { RootElement = imageElement, IsFullScreen = false, VirtualResolution = new Vector3(200) } };
            imageEntity2.Transform.Position = new Vector3(0, 250, 0);
            Scene.Entities.Add(imageEntity2);

            var imageEntity3 = new Entity { new UIComponent { RootElement = imageElement, IsFullScreen = false, VirtualResolution = new Vector3(250) } };
            imageEntity3.Transform.Position = new Vector3(0, 0, -500);
            Scene.Entities.Add(imageEntity3);
            
            // setup the camera
            var camera = new TestCamera { Yaw = MathUtil.Pi/4, Pitch = MathUtil.Pi/4, Position = new Vector3(500, 500, 500), MoveSpeed = 100 };
            camera.SetTarget(cube, true);
            CameraComponent = camera.Camera;
            Script.Add(camera);
        }
Esempio n. 5
0
        public void TestEventFreezing()
        {
            // check that values can freely be modified by default
            Assert.AreEqual(false, IsBeingRouted);
            var image = new ImageElement();
            var routedEvent = EventManager.RegisterRoutedEvent<RoutedEventArgs>("test", RoutingStrategy.Tunnel, typeof(RoutedEventArgsTest));
            Source = image;
            Assert.AreEqual(image, Source);
            Source = null;
            Assert.AreEqual(null, Source);
            RoutedEvent = routedEvent;
            Assert.AreEqual(routedEvent, RoutedEvent);
            RoutedEvent = null;
            Assert.AreEqual(null, RoutedEvent);

            // check that value of IsBeingRouted is updated
            StartEventRouting();
            Assert.AreEqual(true, IsBeingRouted);

            // check that modifications are now prohibited
            Assert.Throws<InvalidOperationException>(() => Source = null);
            Assert.Throws<InvalidOperationException>(() => RoutedEvent = null);

            // check that value of IsBeingRouted is update
            EndEventRouting();
            Assert.AreEqual(false, IsBeingRouted);
        }
Esempio n. 6
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;
        }
Esempio n. 7
0
        public void TestMeasureOverride()
        {
            var rand = new Random();
            var imageSize = new Vector3(100, 50, 0);
            var Sprite = new Sprite { Region = new Rectangle(0, 0, (int)imageSize.X, (int)imageSize.Y), Borders = new Vector4(1, 2, 3, 4) };
            var image = new ImageElement { Source = Sprite };

            // Fixed sized
            image.StretchType = StretchType.None;
            image.Measure(rand.NextVector3());
            Assert.AreEqual(imageSize, image.DesiredSizeWithMargins);

            // Uniform sized
            image.StretchType = StretchType.Uniform;
            image.Measure(new Vector3(50));
            Assert.AreEqual(new Vector3(50, 25, 0), image.DesiredSizeWithMargins);

            // Uniform to fill sized
            image.StretchType = StretchType.UniformToFill;
            image.Measure(new Vector3(50));
            Assert.AreEqual(new Vector3(100, 50, 0), image.DesiredSizeWithMargins);

            // Fill on stretch
            image.StretchType = StretchType.FillOnStretch;
            image.Measure(new Vector3(50));
            Assert.AreEqual(new Vector3(50, 25, 0), image.DesiredSizeWithMargins);

            // Fill
            image.StretchType = StretchType.Fill;
            image.Measure(new Vector3(50));
            Assert.AreEqual(new Vector3(50, 50, 0), image.DesiredSizeWithMargins);

            // Test minimal size due to borders
            image.StretchType = StretchType.Fill;
            image.Measure(new Vector3());
            Assert.AreEqual(new Vector3(4, 6, 0), image.DesiredSizeWithMargins);

            // Test with infinite value
            for (var type = 0; type < 5; ++type)
                TestMeasureOverrideInfiniteValues((StretchType)type);

            // Test stretch directions
            image.StretchType = StretchType.Fill;
            image.StretchDirection = StretchDirection.DownOnly;
            image.Measure(new Vector3(200, 300, 220));
            Assert.AreEqual(new Vector3(100, 50, 0), image.DesiredSizeWithMargins);
            image.Measure(new Vector3(20, 15, 30));
            Assert.AreEqual(new Vector3(20, 15, 0), image.DesiredSizeWithMargins);
            image.StretchDirection = StretchDirection.UpOnly;
            image.Measure(new Vector3(200, 300, 220));
            Assert.AreEqual(new Vector3(200, 300, 0), image.DesiredSizeWithMargins);
            image.Measure(new Vector3(20, 30, 22));
            Assert.AreEqual(new Vector3(100, 50, 0), image.DesiredSizeWithMargins);
        }
Esempio n. 8
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var sprite = new Sprite(Asset.Load<Texture>("BorderButton")) { Borders = new Vector4(64, 64, 64, 64) };

            var bi1 = new ImageElement { Source = sprite, Height = 150 };
            var bi2 = new ImageElement { Source = sprite, Height = 300 };
            var bi3 = new ImageElement { Source = sprite, Height = 500 };

            stackPanel = new StackPanel { Orientation = Orientation.Vertical };
            stackPanel.Children.Add(bi1);
            stackPanel.Children.Add(bi2);
            stackPanel.Children.Add(bi3);

            UIComponent.RootElement = new ScrollViewer { Content = stackPanel, ScrollMode = ScrollingMode.HorizontalVertical };
        }
Esempio n. 9
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var image1 = new ImageElement
            {
                Source = new Sprite(Asset.Load<Texture>("BorderButtonCentered")) { Region = new Rectangle(256, 128, 512, 256), Borders = new Vector4(0.125f, 0.25f, 0.125f, 0.25f) },
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            var image2 = new ImageElement
            {
                Source = new Sprite(Asset.Load<Texture>("uv")) { Region = new Rectangle(0, 0, 512, 512) },
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            var image3 = new ImageElement
            {
                Source = new Sprite(Asset.Load<Texture>("uv")) { Region = new Rectangle(512, 0, 512, 512) },
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            var image4 = new ImageElement
            {
                Source = new Sprite(Asset.Load<Texture>("uv")) { Region = new Rectangle(0, 512, 512, 512) },
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            var image5 = new ImageElement
            {
                Source = new Sprite(Asset.Load<Texture>("uv")) { Region = new Rectangle(512, 512, 512, 512) },
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            stackPanel = new StackPanel { Orientation = Orientation.Vertical };
            stackPanel.Children.Add(image1);
            stackPanel.Children.Add(image2);
            stackPanel.Children.Add(image3);
            stackPanel.Children.Add(image4);
            stackPanel.Children.Add(image5);

            UIComponent.RootElement = new ScrollViewer { Content = stackPanel };
        }
Esempio n. 10
0
        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();

            var sprites = Content.Load<SpriteSheet>("UIImages");

            var img1 = new ImageElement { Name = "UV 1 stack panel", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            var img2 = new ImageElement { Name = "UV 2 stack panel", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            img3 = new ImageElement { Name = "UV 3 stack panel", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };

            stackPanel = new StackPanel { Orientation = Orientation.Vertical };
            stackPanel.Children.Add(img1);
            stackPanel.Children.Add(img2);
            stackPanel.Children.Add(img3);

            var img4 = new ImageElement { Name = "UV grid", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            var img5 = new ImageElement { Name = "UV grid 2", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            var img6 = new ImageElement { Name = "Game screen grid", Source = SpriteFromSheet.Create(sprites, "GameScreen") };

            img4.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            img4.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            img5.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            img5.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            img6.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            img6.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            img6.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);

            grid = new UniformGrid { Columns = 2, Rows = 2 };
            grid.Children.Add(img4);
            grid.Children.Add(img5);
            grid.Children.Add(img6);

            scrollViewer = new ScrollViewer { Content = grid, ScrollMode = ScrollingMode.HorizontalVertical};

            contentDecorator = new ContentDecorator { Content = scrollViewer };

            UIComponent.Page = new Engine.UIPage { RootElement = contentDecorator };
        }
Esempio n. 12
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            const float relativeSize = 1 / 6f;

            var canvas = new Canvas();
            canvas.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);

            // left/top
            var image1 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image1.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image1.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(0, 0, 0));
            image1.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 0, 0));
            canvas.Children.Add(image1);

            // right/top
            var image2 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image2.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image2.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1, 0, 0));
            image2.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(1, 0, 0));
            canvas.Children.Add(image2);

            // left/bottom
            var image3 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image3.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image3.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(0, 1, 0));
            image3.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 1, 0));
            canvas.Children.Add(image3);

            // 1/3 right/bottom
            var image4 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image4.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image4.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1, 1, 0));
            image4.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(1, 1, 0));
            canvas.Children.Add(image4);

            // 1/3 left/top middle centered
            var image5 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image5.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image5.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1/3f, 1/3f, 0));
            image5.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 0.5f, 0));
            canvas.Children.Add(image5);

            // 1/3 right/top right aligned 
            var image6 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image6.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image6.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(2 / 3f, 1 / 3f, 0));
            image6.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 0.5f, 0));
            canvas.Children.Add(image6);

            // 1/3 left/bottom bottom aligned
            var image7 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image7.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image7.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1/3f, 2/3f, 0));
            image7.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 0, 0));
            canvas.Children.Add(image7);

            // 1/3 right/bottom top aligned
            var image8 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image8.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image8.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(2/3f, 2/3f, 0));
            image8.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 1, 0));
            canvas.Children.Add(image8);
            
            var grid = new UniformGrid { Rows = 3, Columns = 3 };
            for (int c = 0; c < 3; c++)
                for (int r = 0; r < 3; r++)
                    CreateAndInsertButton(grid, c, r);

            var baseGrid = new UniformGrid();
            baseGrid.Children.Add(grid);
            baseGrid.Children.Add(canvas);

            UIComponent.RootElement = baseGrid;
        }
Esempio n. 13
0
        public void TestArrangeOverrideInfiniteValues(StretchType stretch)
        {
            var imageSize = new Vector3(100, 50, 0);
            var Sprite = new Sprite { Region = new Rectangle(0, 0, (int)imageSize.X, (int)imageSize.Y), Borders = new Vector4(1, 2, 3, 4) };
            var image = new ImageElement { Source = Sprite, StretchType = stretch };

            image.Arrange(new Vector3(float.PositiveInfinity), false);
            Assert.AreEqual(imageSize, image.RenderSize);

            image.Arrange(new Vector3(150, float.PositiveInfinity, 10), false);
            Assert.AreEqual(stretch == StretchType.None ? imageSize : new Vector3(150, 75, 0), image.RenderSize);
        }
Esempio n. 14
0
        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(); };
        }
        public void TestMeasureOverrideInfiniteValues(StretchType stretch)
        {
            var imageSize = new Vector3(100, 50, 0);
            var sprite = new Sprite { Region = new Rectangle(0, 0, (int)imageSize.X, (int)imageSize.Y), Borders = new Vector4(1, 2, 3, 4) };
            var image = new ImageElement { Source = (SpriteFromTexture)sprite, StretchType = stretch };
            
            image.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(imageSize, image.DesiredSizeWithMargins);

            image.Measure(new Vector3(150, float.PositiveInfinity, 10));
            Assert.AreEqual(stretch == StretchType.None ? imageSize : new Vector3(150, 75, 0), image.DesiredSizeWithMargins);
        }
Esempio n. 16
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;
        }
        public void TestArrangeOverride()
        {
            var rand = new Random();
            var imageSize = new Vector3(100, 50, 0);
            var sprite = new Sprite { Region = new Rectangle(0, 0, (int)imageSize.X, (int)imageSize.Y), Borders = new Vector4(1, 2, 3, 4) };
            var image = new ImageElement { Source = (SpriteFromTexture)sprite };

            // Fixed sized
            image.StretchType = StretchType.None;
            image.Arrange(rand.NextVector3(), false);
            Assert.AreEqual(imageSize, image.RenderSize);

            // Uniform sized
            image.StretchType = StretchType.Uniform;
            image.Arrange(new Vector3(50), false);
            Assert.AreEqual(new Vector3(50, 25, 0), image.RenderSize);

            // Uniform to fill sized
            image.StretchType = StretchType.UniformToFill;
            image.Arrange(new Vector3(50), false);
            Assert.AreEqual(new Vector3(100, 50, 0), image.RenderSize);

            // Fill on stretch
            image.StretchType = StretchType.FillOnStretch;
            image.Arrange(new Vector3(50), false);
            Assert.AreEqual(new Vector3(50, 50, 0), image.RenderSize);

            // Fill
            image.StretchType = StretchType.Fill;
            image.Arrange(new Vector3(50), false);
            Assert.AreEqual(new Vector3(50, 50, 0), image.RenderSize);

            // Test there is no minimal size due to borders in arrange
            image.StretchType = StretchType.Fill;
            image.Arrange(new Vector3(), false);
            Assert.AreEqual(new Vector3(), image.RenderSize);

            // Test with infinite value
            for (var type = 0; type < 5; ++type)
                TestArrangeOverrideInfiniteValues((StretchType)type);

            // Test stretch directions
            image.StretchType = StretchType.Fill;
            image.StretchDirection = StretchDirection.DownOnly;
            image.Arrange(new Vector3(200, 300, 220), false);
            Assert.AreEqual(new Vector3(100, 50, 0), image.RenderSize);
            image.Arrange(new Vector3(20, 15, 30), false);
            Assert.AreEqual(new Vector3(20, 15, 0), image.RenderSize);
            image.StretchDirection = StretchDirection.UpOnly;
            image.Arrange(new Vector3(200, 300, 220), false);
            Assert.AreEqual(new Vector3(200, 300, 0), image.RenderSize);
            image.Arrange(new Vector3(20, 30, 22), false);
            Assert.AreEqual(new Vector3(100, 50, 0), image.RenderSize);
        }
Esempio n. 18
0
        protected  Entity GetUIEntity(SpriteFont font, bool fixedSize, Vector3 position)
        {
            // Create and initialize "Touch Screen to Start"
            var touchStartLabel = new ContentDecorator
            {
                Content = new TextBlock
                {
                    Font = font,
                    TextSize = 32,
                    Text = (fixedSize) ? "Fixed Size UI" : "Regular UI",
                    TextColor = Color.White
                },
                Padding = new Thickness(30, 20, 30, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            //touchStartLabel.SetPanelZIndex(1);

            var grid = new Grid
            {
                BackgroundColor = (fixedSize) ? new Color(255, 0, 255) : new Color(255, 255, 0),
                MaximumWidth = 100,
                MaximumHeight = 100,
                MinimumWidth = 100,
                MinimumHeight = 100,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition());
            grid.LayerDefinitions.Add(new StripDefinition());

            grid.Children.Add(touchStartLabel);

            // Add the background
            var background = new ImageElement { StretchType = StretchType.Fill };
            background.SetPanelZIndex(-1);

            var uiEntity = new Entity();

            // Create a procedural model with a diffuse material
            var uiComponent = new UIComponent();
            uiComponent.RootElement = new UniformGrid { Children = { background, grid } };

            uiComponent.Resolution = new Vector3(100, 100, 100);    // Same size as the inner grid
            uiComponent.IsFullScreen = false;
//            uiComponent.IsBillboard = true;
            uiComponent.IsFixedSize = fixedSize;
            uiComponent.Size = new Vector3(0.1f);   // 10% of the vertical resolution

            uiEntity.Add(uiComponent);

            uiEntity.Transform.Position = position;

            return uiEntity;
        }
Esempio n. 19
0
        private UIElement CreateBottomBar()
        {
            // Create Life bar
            lifeBarGaugeImage = ButtonsImages["rope_small"];
            gaugeBarRegion = lifeBarGaugeImage.Region;

            var lifebarGauge = new ImageElement
            {
                Name = "LifeBarBackground",
                Source = SpriteFromSheet.Create(ButtonsImages, "rope_small"),
                StretchType = StretchType.Fill,
            };
            lifebarGauge.SetGridColumn(1);

            lifeBarGrid = new Grid();
            lifeBarGrid.Children.Add(lifebarGauge);
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 8));
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 0));
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 100));
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 8));
            lifeBarGrid.RowDefinitions.Add(new StripDefinition());
            lifeBarGrid.LayerDefinitions.Add(new StripDefinition());
            lifeBarGrid.SetCanvasRelativePosition(new Vector3(0f, 0.185f, 0f));
            lifeBarGrid.SetCanvasRelativeSize(new Vector3(1f, 1f, 1f));
            lifeBarGrid.SetPanelZIndex(-1);


            // the main grid of the top bar
            var mainLayer = new Canvas
            {
                VerticalAlignment = VerticalAlignment.Top,
                MaximumHeight = 10
            };

            mainLayer.Children.Add(lifeBarGrid);

            return mainLayer;
        }
Esempio n. 20
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var random = new Random(0);

            var Sprites = Asset.Load<SpriteSheet>("UIImages");
            var img1 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")) };
            var img2 = new ImageElement { Source = Sprites["GameScreenLeft"] };
            var img3 = new ImageElement { Source = Sprites["GameScreenRight"] };

            stackPanel1 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true };
            stackPanel1.Children.Add(img1);
            stackPanel1.Children.Add(img2);
            stackPanel1.Children.Add(img3);

            stackPanel2 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true };
            for (var i = 0; i < 1000; i++)
                stackPanel2.Children.Add(new Button { Name = "" + i, Height = 75, Content = new TextBlock { Text = "button number " + i, Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") } });

            stackPanel3 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true, VerticalAlignment = VerticalAlignment.Center };
            for (var i = 0; i < 103; i++)
                stackPanel3.Children.Add(new Button { Name = "" + i, Height = 50 + 500 * random.NextFloat(), Content = new TextBlock { Text = "random button number " + i, Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") } });

            stackPanel4 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true };
            for (var i = 0; i < 5; i++)
                stackPanel4.Children.Add(new Button { Name = "" + i, Height = i * 30, Content = new TextBlock { Text = "random button number " + i, Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") } });

            currentStackPanel = stackPanel1;

            scrollViewer = new ScrollViewer { Name = "sv", Content = currentStackPanel, ScrollMode = ScrollingMode.Vertical };

            UIComponent.RootElement = scrollViewer;
        }
Esempio n. 21
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var random = new Random(0);

            var sprites = Content.Load<SpriteSheet>("UIImages");
            var img1 = new ImageElement { Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            var img2 = new ImageElement { Source = SpriteFromSheet.Create(sprites, "GameScreenLeft") };
            var img3 = new ImageElement { Source = SpriteFromSheet.Create(sprites, "GameScreenRight") };

            stackPanel1 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true };
            stackPanel1.Children.Add(img1);
            stackPanel1.Children.Add(img2);
            stackPanel1.Children.Add(img3);

            stackPanel2 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true };
            for (var i = 0; i < 1000; i++)
                stackPanel2.Children.Add(CreateButton("" + i, 75, "button number " + i));

            stackPanel3 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true, VerticalAlignment = VerticalAlignment.Center };
            for (var i = 0; i < 103; i++)
                stackPanel3.Children.Add(CreateButton("" + i, 50 + 500 * random.NextFloat(), "random button number " + i));

            stackPanel4 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true };
            for (var i = 0; i < 5; i++)
                stackPanel4.Children.Add(CreateButton("" + i, i * 30, "random button number "));

            currentStackPanel = stackPanel1;

            scrollViewer = new ScrollViewer { Name = "sv", Content = currentStackPanel, ScrollMode = ScrollingMode.Vertical };

            UIComponent.Page = new Engine.UIPage { RootElement = scrollViewer };
        }
Esempio n. 22
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 } } };
        }