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