private void BuildUI() { Left = 0; Top = 0; ItemListBox = new ListBox(); ItemListBox.Id = "ItemListBox"; TopPanel = new HorizontalStackPanel() { Padding = new Thickness(10), Margin = new Thickness(0, 10, 0, 0), }; HintText = new Label() { Margin = new Thickness(10, 0, 0, 10), TextColor = Color.White, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Bottom }; TopPanel.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; TopPanel.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Top; for (var i = 0; i < 8; i++) { var panel = new Panel(); panel.Width = 64; panel.Height = 64; panel.VerticalAlignment = VerticalAlignment.Center; var inventorySlotBackground = new Image(); inventorySlotBackground.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Stretch; inventorySlotBackground.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Stretch; var inventorySlotItemImage = new Image(); inventorySlotItemImage.Width = 32; inventorySlotItemImage.Height = 32; inventorySlotItemImage.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; inventorySlotItemImage.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Center; var inventorySlotCount = new Label(); inventorySlotCount.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Right; inventorySlotCount.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Bottom; InventorySlotBackgrounds.Add(inventorySlotBackground); InventorySlotItemImages.Add(inventorySlotItemImage); InventorySlotItemCounts.Add(inventorySlotCount); panel.Widgets.Add(inventorySlotBackground); panel.Widgets.Add(inventorySlotItemImage); panel.Widgets.Add(inventorySlotCount); TopPanel.Widgets.Add(panel); } var topPanel = new Panel() { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top, Background = null, Padding = new Thickness(5) }; InventoryPanel = new VerticalStackPanel() { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Background = new SolidBrush(Color.Black * 0.5f), IsDraggable = true, DragHandle = topPanel }; InventoryPanel.AddChild(topPanel); topPanel.AddChild(new Label() { Text = "Inventory", TextColor = Color.White, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }); var closeInventoryButton = topPanel.AddChild(new TextButton() { Text = "x", Background = null, FocusedBackground = null, OverBackground = null, PressedBackground = null, DisabledBackground = null, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Center }); closeInventoryButton.Click += (sender, args) => InventoryPanel.Visible = false; for (var i = 0; i < 4; i++) { var horizontalRow = new HorizontalStackPanel(); for (var j = 0; j < 6; j++) { var panel = new Panel(); panel.Width = 64; panel.Height = 64; var inventorySlotBackground = new Image(); inventorySlotBackground.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Stretch; inventorySlotBackground.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Stretch; var inventorySlotItemImage = new Image(); inventorySlotItemImage.Width = 32; inventorySlotItemImage.Height = 32; inventorySlotItemImage.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; inventorySlotItemImage.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Center; var inventorySlotCount = new Label(); inventorySlotCount.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Right; inventorySlotCount.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Bottom; MainInventorySlotBackgrounds.Add(inventorySlotBackground); MainInventorySlotItemImages.Add(inventorySlotItemImage); MainInventorySlotItemCounts.Add(inventorySlotCount); panel.Widgets.Add(inventorySlotBackground); panel.Widgets.Add(inventorySlotItemImage); panel.Widgets.Add(inventorySlotCount); horizontalRow.AddChild(panel); } InventoryPanel.AddChild(horizontalRow); } ; Widgets.Add(ItemListBox); Widgets.Add(TopPanel); Widgets.Add(InventoryPanel); Widgets.Add(HintText); }
protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); _font = Content.Load <SpriteFont>("MainFont"); _fontSmall = Content.Load <SpriteFont>("FontSmall"); // TODO: use this.Content to load your game content MyraEnvironment.Game = this; var vstack = new VerticalStackPanel(); vstack.AddChild(new Label { Id = "hello", Text = "This is synthy." }); var kbdBtn = new TextButton { Text = $"Keyboard ({Piano.Devices.Count}): {Piano.SelectedDevice?.Name}" }; kbdBtn.Click += (s, a) => { Piano.Rotate(); kbdBtn.Text = $"Keyboard: {Piano.SelectedDevice?.Name}"; }; vstack.AddChild(kbdBtn); vstack.AddChild(new Label { Id = "Songs", Text = "Songs:" }); var hstack = new HorizontalStackPanel(); hstack.AddChild(new Label { Id = "sldjk", Text = "Time Window: " }); var timeWindowLabel = new Label { Id = "twL", Text = $"{Settings.TimeWindowMillis} ms" }; var plusBtn = new TextButton { Text = " + " }; plusBtn.Click += (sender, args) => { Settings.TimeWindowMillis += 50; timeWindowLabel.Text = $"{Settings.TimeWindowMillis} ms"; }; var minusBtn = new TextButton { Text = " - " }; minusBtn.Click += (sender, args) => { if ((Settings.TimeWindowMillis - 50) != 0) { Settings.TimeWindowMillis -= 50; } timeWindowLabel.Text = $"{Settings.TimeWindowMillis} ms"; }; hstack.AddChild(minusBtn); hstack.AddChild(timeWindowLabel); hstack.AddChild(plusBtn); vstack.AddChild(hstack); foreach (var file in Directory.GetFiles(Program.SynthyRoot, "*.mid*")) { var btn = new TextButton { Text = file }; btn.Click += (sender, args) => { this._currentSong = new Song(btn.Text, this); this._currentSong.Start(); }; vstack.AddChild(btn); } _desktop = new Desktop(); _desktop.Root = vstack; Textures.InitTextures(this); OnScreenPiano = new DrawnPiano(this); }