- Sliced sprites are scaled instead of tiling (so they work properly even if the UI element is smaller than the sprite)

- Option to use separate sprites for different states of a GUIComponent (e.g. hovered/pressed button)
- Option to configure "child styles" for the individual elements of a GUIComponent (e.g. the background frame and the handle of a scroll bar)
This commit is contained in:
Regalis
2017-04-08 22:22:53 +03:00
parent 3844dd9dac
commit 34f0ae39b6
18 changed files with 296 additions and 182 deletions
+10 -24
View File
@@ -36,7 +36,6 @@ namespace Barotrauma
set
{
enabled = value;
text.TextColor = enabled ? Color.White : Color.White * 0.5f;
}
}
@@ -76,9 +75,10 @@ namespace Barotrauma
box.SelectedColor = Color.DarkGray;
box.CanBeFocused = false;
GUI.Style.Apply(box, "", this);
GUI.Style.Apply(box, "GUITickBox");
text = new GUITextBlock(new Rectangle(rect.Right + 10, rect.Y+2, 20, rect.Height), label, "", this, font);
text = new GUITextBlock(new Rectangle(rect.Right, rect.Y, 20, rect.Height), label, "", Alignment.TopLeft, Alignment.Left | Alignment.CenterY, this, false, font);
GUI.Style.Apply(text, "", this);
this.rect = new Rectangle(box.Rect.X, box.Rect.Y, 240, rect.Height);
@@ -89,15 +89,8 @@ namespace Barotrauma
{
if (!Visible || !Enabled) return;
//if (MouseOn != null && MouseOn != this && !MouseOn.IsParentOf(this)) return;
//if (text.Rect.Contains(PlayerInput.MousePosition)) MouseOn = this;
if (MouseOn==this)//box.Rect.Contains(PlayerInput.MousePosition))
if (MouseOn == this)
{
//ToolTip = this.ToolTip;
//MouseOn = this;
box.State = ComponentState.Hover;
if (PlayerInput.LeftButtonHeld())
@@ -105,7 +98,6 @@ namespace Barotrauma
box.State = ComponentState.Selected;
}
if (PlayerInput.LeftButtonClicked())
{
Selected = !Selected;
@@ -116,24 +108,18 @@ namespace Barotrauma
{
box.State = ComponentState.None;
}
if (selected)
{
box.State = ComponentState.Selected;
}
}
public override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
DrawChildren(spriteBatch);
float alpha = enabled ? 1.0f : 0.8f;
GUI.DrawRectangle(spriteBatch, new Rectangle(box.Rect.X + 1, box.Rect.Y + 1, box.Rect.Width - 2, box.Rect.Height - 2),
(box.State == ComponentState.Hover ? new Color(50, 50, 50, 255) : Color.Black) * alpha, true);
if (!selected) return;
GUI.DrawRectangle(spriteBatch, new Rectangle(box.Rect.X + 5, box.Rect.Y + 5, box.Rect.Width - 10, box.Rect.Height - 10),
Color.Green * 0.8f * alpha, true);
DrawChildren(spriteBatch);
}
}
}