diff --git a/06-monogame/GUI/Content/Content.mgcb b/06-monogame/GUI/Content/Content.mgcb index ddc4c36..8a4a692 100644 --- a/06-monogame/GUI/Content/Content.mgcb +++ b/06-monogame/GUI/Content/Content.mgcb @@ -13,3 +13,15 @@ #---------------------------------- Content ---------------------------------# +#begin button-default-texture.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:button-default-texture.png + diff --git a/06-monogame/GUI/Content/button-default-texture.png b/06-monogame/GUI/Content/button-default-texture.png new file mode 100644 index 0000000..b347aa3 Binary files /dev/null and b/06-monogame/GUI/Content/button-default-texture.png differ diff --git a/06-monogame/GUI/Game1.cs b/06-monogame/GUI/Game1.cs index 00581e0..6129ad4 100644 --- a/06-monogame/GUI/Game1.cs +++ b/06-monogame/GUI/Game1.cs @@ -1,4 +1,6 @@ -using Microsoft.Xna.Framework; +using System; +using System.Linq; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using GUI.UIElements; @@ -9,7 +11,7 @@ public class Game1 : Game { private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; - private Button mainButton; + private Scene mainScene; public Game1() { @@ -20,14 +22,34 @@ public class Game1 : Game protected override void Initialize() { - mainButton = new Button(new Vector2(10.0f, 10.0f), new Vector2(80.0f, 40.0f), null, _graphics); + _spriteBatch = new SpriteBatch(GraphicsDevice); + + Scene.graphics = _graphics; + Scene.spriteBatch = _spriteBatch; + Scene.content = Content; + + mainScene = new Scene(); + DrawableData drawableData = new DrawableData(null); + drawableData.scale = new Vector2(80.0f, 40.0f); + + void buttonOnClick(Button obj) + { + Console.WriteLine("ACTION CALLED SUCCESSFULLY!"); + } + + ButtonData buttonData = new ButtonData(buttonOnClick); + buttonData.bgColor = Color.Red; + buttonData.fgColor = Color.White; + + Button mainButton = new Button(drawableData, buttonData); + + mainScene.drawables.Add(mainButton); base.Initialize(); } protected override void LoadContent() { - _spriteBatch = new SpriteBatch(GraphicsDevice); } protected override void Update(GameTime gameTime) @@ -35,7 +57,7 @@ public class Game1 : Game if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); - mainButton.Update(gameTime); + mainScene.Update(gameTime); base.Update(gameTime); } @@ -44,9 +66,7 @@ public class Game1 : Game { GraphicsDevice.Clear(Color.Black); - _spriteBatch.Begin(); - mainButton.Draw(_spriteBatch, gameTime); - _spriteBatch.End(); + mainScene.Draw(gameTime); base.Draw(gameTime); } diff --git a/06-monogame/GUI/UI/Button.cs b/06-monogame/GUI/UI/Button.cs new file mode 100644 index 0000000..b98e250 --- /dev/null +++ b/06-monogame/GUI/UI/Button.cs @@ -0,0 +1,136 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using Vector2 = Microsoft.Xna.Framework.Vector2; + +namespace GUI.UIElements; + +public class ButtonData +{ + public Color bgColor; + public Color fgColor; + + public Color hoverBgColor; + public Color hoverFgColor; + + public Color pressedBgColor; + public Color pressedFgColor; + + public bool isPressed = false; + public bool isReleased = false; + public bool isHovered = false; + public bool isNone = false; + + public Action