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 UIElement CreateMainScreneTopBar()
        {
            // Create Life bar
            lifeBarGaugeImage = MainSceneImages["life_bar"];
            gaugeBarRegion    = lifeBarGaugeImage.Region;

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

            lifebarGauge.SetGridColumn(1);

            lifeBarGrid = new Grid();
            lifeBarGrid.Children.Add(lifebarGauge);
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 128));
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 0));
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 100));
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 85));
            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      = SpriteFromSheet.Create(MainSceneImages, "character_frame"),
                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(128, 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            = SpriteFromSheet.Create(MainSceneImages, "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            = SpriteFromSheet.Create(MainSceneImages, "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);
        }