implemented skin system to ui modules; progress on functional text button.

This commit is contained in:
2018-12-14 00:43:38 -06:00
parent 4fd37b6675
commit 8ab83b5188
7 changed files with 142 additions and 21 deletions

View File

@@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RecrownedAthenaeum.UI.Skin.Definitions;
namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
{
@@ -15,17 +16,47 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
public class Button : UIModule
{
private NinePatch background;
private ButtonSkinDefinition skinDefinition;
private ISpecialDrawable downTexture, upTexture, highlightedTexture, disabledTexture;
public event Clicked Listeners;
private bool pressed;
public bool disabled = false;
public bool Highlighted { get; private set; }
public Button(NinePatch background = null)
public Button(ISpecialDrawable down, ISpecialDrawable up, ISpecialDrawable disabled = null, ISpecialDrawable selected = null)
{
this.background = background;
this.downTexture = down;
this.upTexture = up;
this.disabledTexture = disabled;
this.highlightedTexture = selected;
}
public Button(Skin.Skin skin, string definitionName = null)
{
this.skinDefinition = skin.ObtainDefinition<ButtonSkinDefinition>(definitionName, GetType());
downTexture = skin.textureAtlas[skinDefinition.downRegion];
upTexture = skin.textureAtlas[skinDefinition.upRegion];
disabledTexture = skin.textureAtlas[skinDefinition.disabledRegion];
highlightedTexture = skin.textureAtlas[skinDefinition.selectedRegion];
}
public override void Draw(SpriteBatch batch)
{
background?.Draw(batch, bounds);
if (disabled)
{
disabledTexture?.Draw(batch, bounds, color);
}
else
{
if (pressed)
{
downTexture.Draw(batch, bounds, color);
}
else
{
upTexture.Draw(batch, bounds, color);
}
}
base.Draw(batch);
}
@@ -33,6 +64,14 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
{
if (InputUtilities.MouseWithinBoundries(bounds))
{
if (state.LeftButton == ButtonState.Pressed)
{
pressed = true;
}
else
{
pressed = false;
}
if (InputUtilities.MouseClicked())
{
OnClick();
@@ -42,6 +81,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
else
{
Highlighted = false;
pressed = false;
}
return base.MouseStateChanged(state);
@@ -57,6 +97,5 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
Listeners?.Invoke();
}
public bool Highlighted { get; private set; }
}
}