Beispiel #1
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;
        }
Beispiel #2
0
        public void TestProperties()
        {
            var newElement = new Canvas();

            // test default values
            Assert.AreEqual(float.NaN, newElement.DependencyProperties.Get(RelativeSizePropertyKey).X);
            Assert.AreEqual(float.NaN, newElement.DependencyProperties.Get(RelativeSizePropertyKey).Y);
            Assert.AreEqual(float.NaN, newElement.DependencyProperties.Get(RelativeSizePropertyKey).Z);
            Assert.AreEqual(Vector3.Zero, newElement.DependencyProperties.Get(RelativePositionPropertyKey));
            Assert.AreEqual(Vector3.Zero, newElement.DependencyProperties.Get(AbsolutePositionPropertyKey));
            Assert.AreEqual(Vector3.Zero, newElement.DependencyProperties.Get(PinOriginPropertyKey));

            // test pin origin validator
            newElement.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(-1, -1, -1));
            Assert.AreEqual(Vector3.Zero, newElement.DependencyProperties.Get(PinOriginPropertyKey));
            newElement.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(2, 2, 2));
            Assert.AreEqual(Vector3.One, newElement.DependencyProperties.Get(PinOriginPropertyKey));
            newElement.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(0.5f, 0.5f, 0.5f));
            Assert.AreEqual(new Vector3(0.5f, 0.5f, 0.5f), newElement.DependencyProperties.Get(PinOriginPropertyKey));

            // test relative size validator
            newElement.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(0.5f, 0.5f, 0.5f));
            Assert.AreEqual(new Vector3(0.5f, 0.5f, 0.5f), newElement.DependencyProperties.Get(RelativeSizePropertyKey));
            newElement.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(2.5f, 3.5f, 4.5f));
            Assert.AreEqual(new Vector3(2.5f, 3.5f, 4.5f), newElement.DependencyProperties.Get(RelativeSizePropertyKey));
            Assert.Throws<InvalidOperationException>(() => newElement.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(-2.5f, 3.5f, 4.5f)));
            Assert.Throws<InvalidOperationException>(() => newElement.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(2.5f, -3.5f, 4.5f)));
            Assert.Throws<InvalidOperationException>(() => newElement.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(2.5f, 3.5f, -0.1f)));
        }
Beispiel #3
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var uiGroup = Asset.Load<SpriteSheet>("UIImages");

            element4 = new ContentDecorator
            {
                Name = "4", 
                Width = 200, 
                Height = 100, 
                LocalMatrix = Matrix.Translation(-50, -50, 0),
                BackgroundImage = uiGroup["uvNotRotated"],
            };

            element3 = new ContentDecorator
            {
                Name = "3", 
                Width = 300,
                Height = 150,
                Content = element4,
                LocalMatrix = Matrix.Translation(-200, -100, 0),
                BackgroundImage = uiGroup["uvRotated90"],
            };

            var borderImage = uiGroup["BorderButton"];
            element2 = new ContentDecorator { Name = "2", Width = 600, Height = 300, Content = element3, BackgroundImage = borderImage };
            element2.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(400, 200, 0));
            element2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);

            element1 = new ContentDecorator { Name = "1", Width = 600, Height = 300, BackgroundImage = uiGroup["GameScreen"] };

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

            UIComponent.RootElement = canvas;
        }
Beispiel #4
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var Sprites = Asset.Load<SpriteSheet>("UIImages");
            element1 = new Button { Name = "1", Width = 300, Height = 150 };
            element1.PressedImage = Sprites["Logo"];
            element1.NotPressedImage = 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 = new Sprite(Asset.Load<Texture>("ImageButtonPressed"));
            element2.NotPressedImage = new Sprite(Asset.Load<Texture>("ImageButtonNotPressed"));

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

            UIComponent.RootElement = canvas;
        }
Beispiel #5
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var background = new Entity { new BackgroundComponent { Texture = Asset.Load<Texture>("ParadoxBackground") } };
            Scene.AddChild(background);

            button1 = new Button { Content = new TextBlock { Text = "text block button 1", Font = Asset.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true } };
            button1.SetCanvasRelativePosition(new Vector3(0.025f, 0.05f, 0f));

            edit1 = new EditText(Services) { Text = "Edit text 1", Font = Asset.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true, };
            edit1.SetCanvasRelativePosition(new Vector3(0.025f, 0.15f, 0f));

            button2 = new Button { Content = new TextBlock { Text = "text block button 2", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), SynchronousCharacterGeneration = true } };
            edit2 = new EditText(Services) { Text = "Edit text 2", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), };

            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;};

            UIComponent.RootElement = canvas;
        }
Beispiel #6
0
        private void CreateMainMenuUI()
        {
            var paradoxLogo = new ImageElement { Source = uiImages["pdx_logo"] };

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

            StartButton = new Button
            {
                Content = new TextBlock { Font = spriteFont, Text = "Touch to Start", TextColor = Color.Black,
                    HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center},
                NotPressedImage = buttonImage,
                PressedImage = buttonImage,
                MouseOverImage = buttonImage,
                Padding = new Thickness(80, 27, 25, 35),
                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(paradoxLogo);
            mainMenuCanvas.Children.Add(StartButton);

            mainMenuRoot = new ModalElement
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Content = mainMenuCanvas
            };
        }
Beispiel #7
0
        private void CreateGameUI()
        {
            distanceTextBlock = new TextBlock { Font = spriteFont, TextColor = Color.Gold, VerticalAlignment = VerticalAlignment.Center };
            distanceTextBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f));
            distanceTextBlock.SetCanvasRelativePosition(new Vector3(0.2f, 0.05f, 0f));

            var scoreBoard = new ContentDecorator
            {
                BackgroundImage = uiImages["distance_bg"],
                Content = distanceTextBlock,
                Padding = new Thickness(60, 31, 25, 35),
                MinimumWidth = 290f // Set the minimum width of score button so that it wont modify when the content (text) changes, and less than minimum.
            };

            gameRoot = new Canvas();
            gameRoot.Children.Add(scoreBoard);
        }
Beispiel #8
0
        private void CreateGameOverUI()
        {
            MenuButton = new Button
            {
                Content = new TextBlock { Font = spriteFont, Text = "Menu", TextColor = Color.Black,
                    HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center},
                PressedImage = buttonImage,
                NotPressedImage = buttonImage,
                MouseOverImage = buttonImage,
                Padding = new Thickness(77, 29, 25, 35),
                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 = spriteFont, Text = "Retry", TextColor = Color.Black,
                    HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center},
                Padding = new Thickness(74, 29, 25, 35),
                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,
                MinimumWidth = 200f,
            };
        }
Beispiel #9
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 UIImage(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 UIImage(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 UIImage(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 UIImage(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 UIImage(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 UIImage(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 UIImage(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 UIImage(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;
        }
Beispiel #10
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var middleOfScreen = new Vector3(UIComponent.VirtualResolution.X, UIComponent.VirtualResolution.Y, 0) / 2;

            edit1 = new EditText(Services)
            {
                Name = "TestEdit1",
                Font = Asset.Load<SpriteFont>("MSMincho10"),
                MinimumWidth = 100,
                Text = "Sample Text1",
                MaxLength = 35,
                TextSize = 20,
                SynchronousCharacterGeneration = true
            };
            edit1.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One);
            edit1.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(middleOfScreen.X, 100, 0));
            edit1.TextChanged += Edit1OnTextChanged;

            edit2 = new EditText(Services)
            {
                Name = "TestEdit2",
                Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"),
                MinimumWidth = 100,
                Text = "Sample2 Text2",
                MaxLength = 10,
                CharacterFilterPredicate = IsLetter,
                SynchronousCharacterGeneration = true
            };
            edit2.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One);
            edit2.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(middleOfScreen.X, 200, 0));
            edit2.TextChanged += Edit2OnTextChanged;

            edit3 = new EditText(Services)
            {
                Name = "TestEdit3",
                Font = Asset.Load<SpriteFont>("MSMincho10"),
                MinimumWidth = 100,
                Text = "secret",
                MaxLength = 15,
                TextSize = 24,
                InputType = EditText.InputTypeFlags.Password,
                SynchronousCharacterGeneration = true
            };
            edit3.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One);
            edit3.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(middleOfScreen.X, 300, 0));

            edit4 = new EditText(Services)
            {
                Name = "TestEdit4",
                Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"),
                MinimumWidth = 200,
                Text = "aligned text",
                TextSize = 24,
                SynchronousCharacterGeneration = true
            };
            edit4.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One);
            edit4.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(middleOfScreen.X, 400, 0));

            var canvas = new Canvas();
            canvas.Children.Add(edit1);
            canvas.Children.Add(edit2);
            canvas.Children.Add(edit3);
            canvas.Children.Add(edit4);

            UIComponent.RootElement = canvas;
        }
Beispiel #11
0
        private UIElement CreateMainScreneTopBar()
        {
            // Create Life bar
            lifeBarGaugeImage = mainScreneImages["life_bar"];
            var lifeBarCoverImage = mainScreneImages["character_frame"];
            gaugeBarRegion = lifeBarGaugeImage.Region;

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

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

            var lifebarForeground = new ImageElement
            {
                Name = "LifeBarForeGround",
                Source = lifeBarCoverImage,
                StretchType = StretchType.Fill,
            };
            lifebarForeground.SetGridColumnSpan(3);
            lifebarForeground.SetGridRowSpan(3);
            lifebarForeground.SetCanvasRelativeSize(new Vector3(1f, 1f, 1f));

            // Life count
            lifeCounter = new TextBlock
            {
                Text = CreateLifeCountText(),
                TextColor = Color.Gold,
                Font = westernFont,
                TextSize = 32,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            lifeCounter.SetCanvasAbsolutePosition(new Vector3(lifeBarCoverImage.Borders.X, float.NaN, float.NaN));
            lifeCounter.SetCanvasRelativePosition(new Vector3(float.NaN, 0.44f, 0f));
            lifeCounter.SetPanelZIndex(1);
            LifeStatus = 3;

            // Bonus items
            var bonusIcon = new ImageElement
            {
                Source = mainScreneImages["gold_icon"],
                Name = "bonus Icon",
                VerticalAlignment = VerticalAlignment.Center
            };
            bonusCounter = new TextBlock
            {
                Text = CreateBonusCountText(),
                TextColor = Color.White,
                TextSize = 27,
                Font = westernFont,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(10, 0, 0, 0)
            };

            // Money 
            var moneyIcon = new ImageElement
            {
                Source = mainScreneImages["money_icon"],
                Name = "money Icon",
                Margin = new Thickness(20, 0, 0, 0),
                VerticalAlignment = VerticalAlignment.Center
            };
            moneyCounter = new TextBlock
            {
                Text = CreateMoneyCountText(),
                TextColor = Color.White,
                TextSize = 27,
                Font = westernFont,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(10, 0, 0, 0)
            };

            // Stack panel containing the bonus and money counters
            var moneyBonusStackPanel = new StackPanel
            {
                Name = "MoneyBonusStackPanel",
                Orientation = Orientation.Horizontal,
            };
            moneyBonusStackPanel.Children.Add(bonusIcon);
            moneyBonusStackPanel.Children.Add(bonusCounter);
            moneyBonusStackPanel.Children.Add(moneyIcon);
            moneyBonusStackPanel.Children.Add(moneyCounter);
            moneyBonusStackPanel.SetCanvasRelativePosition(new Vector3(0.93f, 0.44f, 0f));
            moneyBonusStackPanel.SetCanvasRelativeSize(new Vector3(float.NaN, 0.4f, 1f));
            moneyBonusStackPanel.SetCanvasPinOrigin(new Vector3(1f, 0f, 0f));
            moneyBonusStackPanel.SetPanelZIndex(1);

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

            mainLayer.Children.Add(lifeBarGrid);
            mainLayer.Children.Add(lifebarForeground);
            mainLayer.Children.Add(lifeCounter);
            mainLayer.Children.Add(moneyBonusStackPanel);

            return mainLayer;
        }
        private void CreateUI()
        {
            VirtualResolution = new Vector3(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height, 1);

            var font = Asset.Load<SpriteFont>("Font");
            var canvas = new Canvas();
            var stackPanel = new StackPanel
            {
                Orientation = Orientation.Vertical,
                HorizontalAlignment = HorizontalAlignment.Left,
                MinimumWidth = 200
            };

            var buttonLightDirect = CreateButton("direct", GetButtonTextOnOff("Direct light: ", directionalLight.Enabled), font, Thickness.UniformRectangle(5));
            buttonLightDirect.Click += ToggleLight;

            var buttonLightPoint = CreateButton("point", GetButtonTextOnOff("Point lights: ", pointLights[0].Enabled), font, Thickness.UniformRectangle(5));
            buttonLightPoint.Click += ToggleLight;

            var buttonLightSpot = CreateButton("spot", GetButtonTextOnOff("Spot light: ", spotLight.Enabled), font, Thickness.UniformRectangle(5));
            buttonLightSpot.Click += ToggleLight;

            buttonShadow = CreateButton("direct", GetButtonTextOnOff("Shadow: ", directionalLight.ShadowMap), font, new Thickness(20, 5, 5, 5));
            buttonShadow.Opacity = directionalLight.Enabled ? 1.0f : 0.3f;
            buttonShadow.CanBeHitByUser = directionalLight.Enabled;
            buttonShadow.Click += ToggleShadowMap;

            buttonSpotShadow = CreateButton("spot", GetButtonTextOnOff("Shadow: ", spotLight.ShadowMap), font, new Thickness(20, 5, 5, 5));
            buttonSpotShadow.Opacity = spotLight.Enabled ? 1.0f : 0.3f;
            buttonSpotShadow.CanBeHitByUser = spotLight.Enabled;
            buttonSpotShadow.Click += ToggleShadowMap;

            buttonLightRotate = CreateButton("rotate", GetButtonTextOnOff("Lights rotation: ", rotateLights), font, new Thickness(20, 5, 5, 5));
            var enabled = pointLights.Count > 0 && pointLights[0].Enabled;
            buttonLightRotate.Opacity = enabled ? 1.0f : 0.3f;
            buttonLightRotate.CanBeHitByUser = enabled;
            buttonLightRotate.Click += ToogleRotation;

            stackPanel.Children.Add(buttonLightDirect);
            stackPanel.Children.Add(buttonShadow);
            stackPanel.Children.Add(buttonLightPoint);
            stackPanel.Children.Add(buttonLightRotate);
            stackPanel.Children.Add(buttonLightSpot);
            stackPanel.Children.Add(buttonSpotShadow);
            canvas.Children.Add(stackPanel);
            UI.RootElement = canvas;
        }
Beispiel #13
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;
        }
Beispiel #14
0
        public void TestBasicInvalidations()
        {
            var canvas = new Canvas();
            var child = new Canvas();
            canvas.Children.Add(child);

            // - test the properties that are supposed to invalidate the object measurement
            UIElementLayeringTests.TestMeasureInvalidation(canvas, () => child.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(0.1f, 0.2f, 0.3f)));
            UIElementLayeringTests.TestMeasureInvalidation(canvas, () => child.DependencyProperties.Set(RelativePositionPropertyKey, new Vector3(1f, 2f, 3f)));
            UIElementLayeringTests.TestMeasureInvalidation(canvas, () => child.DependencyProperties.Set(AbsolutePositionPropertyKey, new Vector3(1f, 2f, 3f)));
            UIElementLayeringTests.TestMeasureInvalidation(canvas, () => child.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(1f, 2f, 3f)));
        }
Beispiel #15
0
        public void TestMeasureOverrideInfinite()
        {
            var child1 = new MeasureValidator();
            var canvas = new Canvas { Children = { child1 } };

            // check that relative 0 x inf available = 0 
            child1.SetCanvasRelativeSize(Vector3.Zero);
            child1.ExpectedMeasureValue = Vector3.Zero;
            canvas.Measure(new Vector3(float.PositiveInfinity));
            child1.SetCanvasRelativeSize(new Vector3(float.NaN));

            // check sizes with infinite measure values and absolute position
            child1.SetCanvasAbsolutePosition(new Vector3(1, -1, -3));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity, 0, 0);
            child1.ReturnedMeasuredValue = new Vector3(2);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(3, 1, 0), canvas.DesiredSizeWithMargins);

            // check sizes with infinite measure values and relative position
            child1.SetCanvasPinOrigin(new Vector3(0, .5f, 1));
            child1.SetCanvasRelativePosition(new Vector3(-1));
            child1.ExpectedMeasureValue = new Vector3(0);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(0.5f, 0.25f, 0), canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(0));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity, 0, 0);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(1, 0.5f, 0), canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(0.5f));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(2, 1, 2), canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(1f));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(0, 0.5f, 1), canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(2f));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(0, 0.25f, 0.5f), canvas.DesiredSizeWithMargins);

            // check that the maximum is correctly taken
            var child2 = new MeasureValidator();
            var child3 = new MeasureValidator();
            canvas.Children.Add(child2);
            canvas.Children.Add(child3);
            child1.InvalidateMeasure();
            child1.SetCanvasPinOrigin(new Vector3(0.5f));
            child1.SetCanvasRelativePosition(new Vector3(0.5f));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(10);
            child2.SetCanvasPinOrigin(new Vector3(0.5f));
            child2.SetCanvasRelativePosition(new Vector3(-.1f, .5f, 1.2f));
            child2.ExpectedMeasureValue = new Vector3(0, float.PositiveInfinity, float.PositiveInfinity);
            child2.ReturnedMeasuredValue = new Vector3(30.8f, 5, 48);
            child3.SetCanvasRelativeSize(new Vector3(0f, 1f, 2f));
            child3.ExpectedMeasureValue = new Vector3(0, float.PositiveInfinity, float.PositiveInfinity);
            child3.ReturnedMeasuredValue = new Vector3(0, 5, 50);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(14f, 10f, 25f), canvas.DesiredSizeWithMargins);
        }
Beispiel #16
0
        public void TestArrangeOverrideAbsolute()
        {
            // test that arrange set render size to provided size when there is no children
            var nullCanvas = new Canvas { DepthAlignment = DepthAlignment.Stretch};
            var providedSize = 1000 * rand.NextVector3();
            var providedSizeWithoutMargins = CalculateSizeWithoutThickness(ref providedSize, ref MarginInternal);
            nullCanvas.Measure(providedSize);
            nullCanvas.Arrange(providedSize, false);
            Assert.AreEqual(providedSizeWithoutMargins, nullCanvas.RenderSize);

            // test that arrange works properly with valid children.
            var availablesizeWithMargins = new Vector3(200, 300, 500);
            var canvas = new Canvas { DepthAlignment = DepthAlignment.Stretch };
            for (int i = 0; i < 10; i++)
            {
                var child = new ArrangeValidator { Name = i.ToString() };

                child.SetCanvasPinOrigin(new Vector3(0, 0.5f, 1));
                child.SetCanvasAbsolutePosition(((i>>1)-1) * 0.5f * availablesizeWithMargins);
                child.Margin = new Thickness(10, 11, 12, 13, 14, 15);

                child.ReturnedMeasuredValue = (i%2)==0? new Vector3(1000) : availablesizeWithMargins/3f;
                child.ExpectedArrangeValue = new Vector3(
                    Math.Min(child.ReturnedMeasuredValue.X, Math.Max(0, i > 1 ? availablesizeWithMargins.X * (1 - ((i >> 1) - 1) * 0.5f) - 23 : 0)),
                    Math.Min(child.ReturnedMeasuredValue.Y, (i>> 1) == 2? availablesizeWithMargins.Y - 25 : 0),
                    Math.Min(child.ReturnedMeasuredValue.Z, Math.Max(0, i < 8 ? availablesizeWithMargins.Z * (((i >> 1) - 1) * 0.5f) - 27 : 0)));

                canvas.Children.Add(child);
            }

            // Measure the stack
            canvas.Measure(availablesizeWithMargins);
            canvas.Arrange(availablesizeWithMargins, false);

            // checks the stack arranged size
            Assert.AreEqual(availablesizeWithMargins, canvas.RenderSize);

            // Checks the children arrange matrix
            for (int i = 0; i < canvas.Children.Count; i++)
            {
                var pinPosition = canvas.Children[i].DependencyProperties.Get(AbsolutePositionPropertyKey);
                var pinOrigin = canvas.Children[i].DependencyProperties.Get(PinOriginPropertyKey);
                var childOffsets = (pinPosition - Vector3.Modulate(pinOrigin, canvas.Children[i].RenderSize)) - canvas.RenderSize / 2;
                Assert.AreEqual(Matrix.Translation(childOffsets), canvas.Children[i].DependencyProperties.Get(PanelArrangeMatrixPropertyKey));
            }
        }