- 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
+18 -3
View File
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
@@ -57,14 +58,21 @@ namespace Barotrauma
public readonly Color OutlineColor;
public readonly List<UISprite> Sprites;
public readonly Dictionary<GUIComponent.ComponentState, List<UISprite>> Sprites;
public readonly bool TileSprites;
public Dictionary<string, GUIComponentStyle> ChildStyles;
public GUIComponentStyle(XElement element)
{
Sprites = new List<UISprite>();
Sprites = new Dictionary<GUIComponent.ComponentState, List<UISprite>>();
foreach (GUIComponent.ComponentState state in Enum.GetValues(typeof(GUIComponent.ComponentState)))
{
Sprites[state] = new List<UISprite>();
}
ChildStyles = new Dictionary<string, GUIComponentStyle>();
Padding = ToolBox.GetAttributeVector4(element, "padding", Vector4.Zero);
@@ -92,6 +100,10 @@ namespace Barotrauma
bool maintainAspect = ToolBox.GetAttributeBool(subElement, "maintainaspectratio",false);
bool tile = ToolBox.GetAttributeBool(subElement, "tile", true);
string stateStr = ToolBox.GetAttributeString(subElement, "state", "None");
GUIComponent.ComponentState spriteState = GUIComponent.ComponentState.None;
Enum.TryParse(stateStr, out spriteState);
UISprite newSprite = new UISprite(sprite, tile, maintainAspect);
Vector4 sliceVec = ToolBox.GetAttributeVector4(subElement, "slice", Vector4.Zero);
@@ -125,7 +137,10 @@ namespace Barotrauma
newSprite.Slices[8] = new Rectangle(newSprite.Slices[2].X, slice.Bottom, newSprite.Slices[2].Width, newSprite.Sprite.SourceRect.Bottom - slice.Bottom);
}
Sprites.Add(newSprite);
Sprites[spriteState].Add(newSprite);
break;
default:
ChildStyles.Add(subElement.Name.ToString().ToLowerInvariant(), new GUIComponentStyle(subElement));
break;
}
}