From 5b6b629eb8a28bc9d37e4a6e0e0527c82cd24082 Mon Sep 17 00:00:00 2001 From: Nik Date: Sun, 22 Oct 2023 19:57:53 +0300 Subject: [PATCH] chore: myra ui init --- src/Apps/GameDesktop/Game.cs | 44 +++++++++++++++++++++++++ src/Apps/GameDesktop/GameDesktop.csproj | 1 + 2 files changed, 45 insertions(+) diff --git a/src/Apps/GameDesktop/Game.cs b/src/Apps/GameDesktop/Game.cs index c1b48b7..e24dd7a 100644 --- a/src/Apps/GameDesktop/Game.cs +++ b/src/Apps/GameDesktop/Game.cs @@ -4,6 +4,8 @@ using LightInject; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Myra; +using Myra.Graphics2D.UI; using Serilog; namespace GameDesktop; @@ -19,6 +21,8 @@ public class Game : Microsoft.Xna.Framework.Game private SpriteBatch _spriteBatch; private float _accumulatedTime; + private Desktop _desktop; + public Game(ILogger logger, IServiceContainer container, float targetFramesPerSecond) { @@ -59,6 +63,45 @@ protected override void LoadContent() // todo: pass tru logger & log places // TODO: Error handling _rootFeature.Initialize(); + + MyraEnvironment.Game = this; + + var grid = new Grid { RowSpacing = 8, ColumnSpacing = 8 }; + + grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto)); + grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto)); + grid.RowsProportions.Add(new Proportion(ProportionType.Auto)); + grid.RowsProportions.Add(new Proportion(ProportionType.Auto)); + + var helloWorld = new Label { Id = "label", Text = "Hello, World!" }; + grid.Widgets.Add(helloWorld); + +// ComboBox + var combo = new ComboBox { GridColumn = 1, GridRow = 0 }; + + combo.Items.Add(new ListItem("Red", Color.Red)); + combo.Items.Add(new ListItem("Green", Color.Green)); + combo.Items.Add(new ListItem("Blue", Color.Blue)); + grid.Widgets.Add(combo); + +// Button + var button = new TextButton { GridColumn = 0, GridRow = 1, Text = "Show" }; + + button.Click += (s, a) => + { + var messageBox = Dialog.CreateMessageBox("Message", "Some message!"); + messageBox.ShowModal(_desktop); + }; + + grid.Widgets.Add(button); + +// Spin button + var spinButton = new SpinButton { GridColumn = 1, GridRow = 1, Width = 100, Nullable = true }; + grid.Widgets.Add(spinButton); + +// Add it to the desktop + _desktop = new Desktop(); + _desktop.Root = grid; _logger.ForContext().Verbose("LoadContent(): end"); } @@ -107,6 +150,7 @@ protected override void Draw(GameTime gameTime) GraphicsDevice.Clear(Color.CornflowerBlue); _rootFeature.Draw(gameTime, _spriteBatch); + _desktop.Render(); base.Draw(gameTime); } diff --git a/src/Apps/GameDesktop/GameDesktop.csproj b/src/Apps/GameDesktop/GameDesktop.csproj index 6f6d886..dbdbb17 100644 --- a/src/Apps/GameDesktop/GameDesktop.csproj +++ b/src/Apps/GameDesktop/GameDesktop.csproj @@ -57,6 +57,7 @@ +