Пример #1
0
 //Button configuration
 Button SetupButton(string name, float location)
 {
     Button button = new Button
     {
         Height = 25,
         Width = 100
     };
     button.Click += delegate { ((MenuScript)Entity.Get<ScriptComponent>().Scripts[1]).Menu(name); };
     TextBlock text = new TextBlock
     {
         Height = 20,
         Width = 80,
         Font = Asset.Load<SpriteFont>("Font"),
         Text = name,
         TextAlignment = TextAlignment.Center
     };
     text.SetCanvasRelativePosition(new Vector3(0, 0, 0));
     button.Content = new Canvas
     {
         Children =
         {
             text
         }
     };
     button.SetCanvasRelativePosition(new Vector3(0, location, 0));
     return button;
 }
Пример #2
0
        public override void Start()
        {
            base.Start();

            var font = Asset.Load<SpriteFont>("Font");
            var textBlock = new TextBlock { TextColor = Color.White, Font = font, Text = UIText };
            textBlock.SetCanvasPinOrigin(new Vector3(1, 0, 0));
            textBlock.SetCanvasRelativePosition(new Vector3(0.63f, 0.8f, 0f));

            Entity.Get<UIComponent>().RootElement = new Canvas { Children = { textBlock } };
        }
Пример #3
0
        // Create the UI layout and content
        public void Start()
        {
            textBlock = new TextBlock
            {
                Text = "Tap The Screen!",
                Font = Asset.Load<SpriteFont>("Font"),
                TextAlignment = TextAlignment.Center,
            };
            textBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 0f));
            textBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.85f, 0f));

            Entity.Get<UIComponent>().RootElement = new Canvas { Children = { textBlock } };
        }
Пример #4
0
        public override void Start()
        {
            var font = Asset.Load<SpriteFont>("Font");
            var textBlock = new TextBlock
            {
                Font = font,
                TextSize = 18,
                TextColor = Color.Gold,
                Text = "Shoot : Touch in a vertical section where the Agent resides\n" +
                       "Move : Touch in the screen on the corresponding side of the Agent",
            };
            textBlock.SetCanvasRelativePosition(new Vector3(0.008f, 0.9f, 0));

            Entity.Get<UIComponent>().RootElement = new Canvas { Children = { textBlock } };
        }
Пример #5
0
        public override void Start()
        {
            base.Start();

            var textBlock = new TextBlock
            {
                Text = "Shoot the cubes!",
                Font = Asset.Load<SpriteFont>("Font"),
                TextColor = Color.White,
                TextSize = 60
            };
            textBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 0));
            textBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.9f, 0f));

            Entity.Get<UIComponent>().RootElement = new Canvas { Children = { textBlock } };
        }
Пример #6
0
        public override void Start()
        {
            simulation = Entity.Get<PhysicsComponent>().Simulation;
            simulation.Gravity = new Vector3(0, -9, 0);

            cubeRigidBody = cube.Get<PhysicsComponent>()[0].RigidBody;
            cubeRigidBody.CanSleep = false;
            sphereRigidBody = sphere.Get<PhysicsComponent>()[0].RigidBody;
            sphereRigidBody.CanSleep = false;

            // Create the UI
            var font = Asset.Load<SpriteFont>("Font");
            constraintNameBlock = new TextBlock
            {
                Font = font,
                TextSize = 55,
                TextColor = Color.White,
            };
            constraintNameBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 0));
            constraintNameBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.93f, 0));

            Entity.Get<UIComponent>().RootElement = new Canvas
            {
                Children =
                {
                    constraintNameBlock,
                    CreateButton("Next Constraint", font, 1),
                    CreateButton("Last Constraint", font, -1)
                }
            };

            // Create and initialize constraint
            constraintsList.Add(CreatePoint2PointConstraint);
            constraintsList.Add(CreateHingeConstraint);
            constraintsList.Add(CreateGearConstraint);
            constraintsList.Add(CreateSliderConstraint);
            constraintsList.Add(CreateConeTwistConstraint);
            constraintsList.Add(CreateGeneric6DoFConstraint);

            constraintsList[constraintIndex]();
        }
Пример #7
0
        public override async Task Execute()
        {
            var textBlock = new TextBlock
            {
                Text = "Use arrows to play with gravity!", 
                Font = Asset.Load<SpriteFont>("SpriteFont"), 
                TextColor = Color.White, 
                TextSize = 40
            };
            textBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 0));
            textBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.75f, 0f));
            Entity.Get<UIComponent>().RootElement = new Canvas { Children = { textBlock } };

            while (Game.IsRunning)
            {
                await Script.NextFrame();

                if (!Input.IsKeyPressed(Keys.Left) && !Input.IsKeyPressed(Keys.Right) && !Input.IsKeyPressed(Keys.Up) &&
                    !Input.IsKeyPressed(Keys.Down)) continue;

                Entity.Get<UIComponent>().RootElement = null;
                return;
            }
        }
Пример #8
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);
        }
Пример #9
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;
        }
Пример #10
0
 //Textblock configuration
 TextBlock SetupTextBlock(string text, float x, float y)
 {
     TextBlock textBlock = new TextBlock
     {
         Height = 25,
         Width = 100,
         Font = Asset.Load<SpriteFont>("Font"),
         Text = text,
         TextAlignment = TextAlignment.Center
     };
     textBlock.SetCanvasRelativePosition(new Vector3(x, y, 0));
     return textBlock;
 }