2019-08-09 22:04:26 +02:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using MLEM.Extensions;
|
|
|
|
using MLEM.Textures;
|
2019-08-10 21:37:10 +02:00
|
|
|
using MLEM.Ui.Style;
|
2019-08-09 22:04:26 +02:00
|
|
|
|
|
|
|
namespace MLEM.Ui.Elements {
|
|
|
|
public class Button : Element {
|
|
|
|
|
2019-08-10 21:37:10 +02:00
|
|
|
public NinePatch Texture;
|
|
|
|
public NinePatch HoveredTexture;
|
|
|
|
public Color HoveredColor;
|
2019-08-13 21:23:20 +02:00
|
|
|
public Paragraph Text;
|
2019-08-13 23:54:29 +02:00
|
|
|
public Tooltip Tooltip;
|
2019-08-09 22:04:26 +02:00
|
|
|
|
2019-08-13 23:54:29 +02:00
|
|
|
public Button(Anchor anchor, Vector2 size, string text = null, string tooltipText = null, float tooltipWidth = 50) : base(anchor, size) {
|
2019-08-09 22:04:26 +02:00
|
|
|
if (text != null) {
|
2019-08-13 21:23:20 +02:00
|
|
|
this.Text = new Paragraph(Anchor.Center, 1, text, true);
|
2019-08-09 22:04:26 +02:00
|
|
|
this.AddChild(this.Text);
|
|
|
|
}
|
2019-08-24 20:45:40 +02:00
|
|
|
if (tooltipText != null)
|
|
|
|
this.Tooltip = new Tooltip(tooltipWidth, tooltipText, this);
|
2019-08-09 22:04:26 +02:00
|
|
|
}
|
|
|
|
|
2019-08-12 19:44:16 +02:00
|
|
|
public override void Draw(GameTime time, SpriteBatch batch, float alpha, Point offset) {
|
2019-08-09 22:04:26 +02:00
|
|
|
var tex = this.Texture;
|
2019-08-10 13:42:18 +02:00
|
|
|
var color = Color.White * alpha;
|
2019-08-09 22:04:26 +02:00
|
|
|
if (this.IsMouseOver) {
|
|
|
|
if (this.HoveredTexture != null)
|
|
|
|
tex = this.HoveredTexture;
|
2019-08-10 13:42:18 +02:00
|
|
|
color = this.HoveredColor * alpha;
|
2019-08-09 22:04:26 +02:00
|
|
|
}
|
2019-08-12 19:44:16 +02:00
|
|
|
batch.Draw(tex, this.DisplayArea.OffsetCopy(offset), color, this.Scale);
|
|
|
|
base.Draw(time, batch, alpha, offset);
|
2019-08-09 22:04:26 +02:00
|
|
|
}
|
|
|
|
|
2019-08-10 21:37:10 +02:00
|
|
|
protected override void InitStyle(UiStyle style) {
|
|
|
|
base.InitStyle(style);
|
|
|
|
this.Texture = style.ButtonTexture;
|
|
|
|
this.HoveredTexture = style.ButtonHoveredTexture;
|
|
|
|
this.HoveredColor = style.ButtonHoveredColor;
|
|
|
|
}
|
|
|
|
|
2019-08-09 22:04:26 +02:00
|
|
|
}
|
|
|
|
}
|