2 using Microsoft.Xna.Framework;
4 using System.Collections.Generic;
51 public readonly Dictionary<Identifier, GUIComponentStyle>
ChildStyles;
55 if (hierarchy is
null || hierarchy.None()) {
return null; }
57 for (
int i = 1; i < hierarchy.Count; i++)
59 if (style is
null) {
return null; }
60 style.
ChildStyles.TryGetValue(hierarchy[i], out style);
67 List<Identifier> ids =
new List<Identifier>();
77 public readonly
string Name;
79 public int?
Width {
get;
private set; }
80 public int?
Height {
get;
private set; }
91 Sprites[state] =
new List<UISprite>();
95 ChildStyles =
new Dictionary<Identifier, GUIComponentStyle>();
125 foreach (var subElement
in element.Elements())
127 switch (subElement.Name.ToString().ToLowerInvariant())
132 if ((sourceRect.Width <= 1 || sourceRect.Height <= 1) && newSprite.
Tile)
134 DebugConsole.AddWarning($
"Sprite \"{subElement.GetAttributeString("name
", Name)}\" has a size of 1 or less which may cause performance problems.", contentPackage: element.ContentPackage);
138 if (subElement.GetAttribute(
"state") !=
null)
140 string stateStr = subElement.GetAttributeString(
"state",
"None");
141 Enum.TryParse(stateStr, out spriteState);
142 Sprites[spriteState].Add(newSprite);
160 Identifier styleName = subElement.NameAsIdentifier();
163 DebugConsole.ThrowError(
"UI style \"" + element.Name.ToString() +
"\" contains multiple child styles with the same name (\"" + styleName +
"\")!");
183 return Sprites.ContainsKey(state) ?
Sprites[state]?.First()?.Sprite :
null;
193 childStyle.RefreshSize();
197 private void GetSize(XElement element)
199 Point size =
new Point(0, 0);
200 foreach (var subElement
in element.Elements())
202 if (!subElement.Name.ToString().Equals(
"size", StringComparison.OrdinalIgnoreCase)) {
continue; }
203 Point maxResolution = subElement.GetAttributePoint(
"maxresolution",
new Point(
int.MaxValue,
int.MaxValue));
204 if (GameMain.GraphicsWidth <= maxResolution.X && GameMain.GraphicsHeight <= maxResolution.Y)
212 if (size.X > 0) {
Width = size.X; }
213 if (size.Y > 0) {
Height = size.Y; }
string? GetAttributeString(string key, string? def)
Vector4 GetAttributeVector4(string key, in Vector4 def)
Color GetAttributeColor(string key, in Color def)
float GetAttributeFloat(string key, float def)
bool GetAttributeBool(string key, bool def)
Identifier GetAttributeIdentifier(string key, string def)
readonly Color HoverColor
readonly TransitionMode TransitionMode
readonly Dictionary< GUIComponent.ComponentState, List< UISprite > > Sprites
readonly Color SelectedTextColor
static Identifier[] ToHierarchy(GUIComponentStyle style)
readonly Color PressedColor
readonly GUIComponentStyle ParentStyle
SpriteFallBackState FallBackState
Sprite GetDefaultSprite()
readonly float ColorCrossFadeTime
readonly Color OutlineColor
static GUIComponentStyle FromHierarchy(IReadOnlyList< Identifier > hierarchy)
readonly bool ForceUpperCase
GUIComponentStyle(ContentXElement element, UIStyleFile file, GUIComponentStyle parent=null)
readonly Color HoverTextColor
Sprite GetSprite(GUIComponent.ComponentState state)
readonly Color DisabledColor
readonly float SpriteCrossFadeTime
readonly Dictionary< Identifier, GUIComponentStyle > ChildStyles
readonly Color SelectedColor
readonly Color DisabledTextColor
readonly ContentXElement Element
int ParseSize(XElement element, string attributeName)
readonly Identifier Identifier