progress on text buttons (untested)

This commit is contained in:
2018-11-22 01:12:40 -06:00
parent f63a7b76e3
commit 6f43cbffbb
7 changed files with 76 additions and 13 deletions

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace RhythmBullet.Utilities.DataTypes
{
public struct NinePatch
public class NinePatch
{
public Color color;
readonly Texture2D texture;
@@ -34,8 +34,6 @@ namespace RhythmBullet.Utilities.DataTypes
this.c = c;
this.d = d;
sourceRectangle = new Rectangle();
drawnRectangle = new Rectangle();
color = Color.White;
}

View File

@@ -1,5 +1,7 @@
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using RhythmBullet.UI.Modular;
using RhythmBullet.Utilities.DataTypes;
using RhythmBullet.Utilities.Input;
using System;
using System.Collections.Generic;
@@ -11,13 +13,20 @@ namespace RhythmBullet.Utilities.UI.Modular.Modules.Interactive
{
public delegate bool Clicked();
public class BasicButton : UIModuleGroup
public class Button : UIModule
{
private NinePatch background;
public event Clicked Listeners;
public BasicButton()
public Button(NinePatch background = null)
{
this.background = background;
}
public override void Draw(SpriteBatch batch)
{
background?.Draw(batch, bounds);
base.Draw(batch);
}
public sealed override bool MouseStateChanged(MouseState state)
@@ -29,7 +38,8 @@ namespace RhythmBullet.Utilities.UI.Modular.Modules.Interactive
OnClick();
}
Highlighted = true;
} else
}
else
{
Highlighted = false;
}

View File

@@ -0,0 +1,37 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.UI.Modular.Modules;
using RhythmBullet.Utilities.DataTypes;
using RhythmBullet.Utilities.UI.Modular.Modules.Interactive;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Utilities.UI.Modular.Modules.Interactive
{
internal class TextButton : Button
{
private TextLabel label;
internal TextButton(string text, SpriteFont font, NinePatch background) : base(background)
{
label = new TextLabel(font, text);
label.autoScale = true;
}
public override void Update(GameTime gameTime)
{
label.bounds = bounds;
label.Update(gameTime);
base.Update(gameTime);
}
public override void Draw(SpriteBatch batch)
{
label.Draw(batch);
base.Draw(batch);
}
}
}

View File

@@ -51,11 +51,21 @@ namespace RhythmBullet.UI.Modular
Parent.RemoveModule(this);
}
/// <summary>
/// Called whenever the keyboard state is changed.
/// </summary>
/// <param name="state">The current keyboard state.</param>
/// <returns>Returning whether or not to continue to call the next listener.</returns>
public virtual bool KeyboardStateChanged(KeyboardState state)
{
return true;
}
/// <summary>
/// Called whenever the state of the mouse changes. This includes movement.
/// </summary>
/// <param name="state">The current state of the mouse.</param>
/// <returns>Returning whether or not to continue to call the next listener.</returns>
public virtual bool MouseStateChanged(MouseState state)
{
return true;

View File

@@ -46,8 +46,8 @@ namespace RhythmBullet.UI.Modular
{
int offsetX = module.bounds.X;
int offsetY = module.bounds.Y;
module.bounds.X = bounds.X + offsetX;
module.bounds.Y = bounds.Y + offsetY;
module.bounds.X = bounds.X + offsetX - (int)module.origin.X;
module.bounds.Y = bounds.Y + offsetY - (int)module.origin.Y;
module.Draw(batch);
module.bounds.X = offsetX;
module.bounds.Y = offsetY;
@@ -94,7 +94,7 @@ namespace RhythmBullet.UI.Modular
{
module.KeyboardStateChanged(state);
}
return false;
return base.KeyboardStateChanged(state);
}
public override bool MouseStateChanged(MouseState state)
@@ -103,7 +103,7 @@ namespace RhythmBullet.UI.Modular
{
module.MouseStateChanged(state);
}
return false;
return base.MouseStateChanged(state);
}
}
}