2 using Microsoft.Xna.Framework;
4 using System.Collections.Immutable;
6 using System.Reflection;
10 public static class GUIStyle
12 public readonly
static ImmutableDictionary<Identifier, GUIFont> Fonts;
13 public readonly
static ImmutableDictionary<Identifier, GUISprite> Sprites;
14 public readonly
static ImmutableDictionary<Identifier, GUISpriteSheet> SpriteSheets;
15 public readonly
static ImmutableDictionary<Identifier, GUIColor> Colors;
18 var guiClassProperties = typeof(GUIStyle).GetFields(BindingFlags.Public | BindingFlags.Static);
20 ImmutableDictionary<Identifier, T> getPropertiesOfType<T>() where T : class
22 return guiClassProperties
23 .Where(p => p.FieldType == typeof(T))
24 .Select(p => (p.Name.ToIdentifier(), p.GetValue(
null) as T))
25 .ToImmutableDictionary();
28 Fonts = getPropertiesOfType<GUIFont>();
29 Sprites = getPropertiesOfType<GUISprite>();
30 SpriteSheets = getPropertiesOfType<GUISpriteSheet>();
31 Colors = getPropertiesOfType<GUIColor>();
34 public readonly
static PrefabCollection<GUIComponentStyle> ComponentStyles =
new PrefabCollection<GUIComponentStyle>();
36 public readonly
static GUIFont Font =
new GUIFont(
"Font");
37 public readonly
static GUIFont UnscaledSmallFont =
new GUIFont(
"UnscaledSmallFont");
38 public readonly
static GUIFont SmallFont =
new GUIFont(
"SmallFont");
39 public readonly
static GUIFont LargeFont =
new GUIFont(
"LargeFont");
40 public readonly
static GUIFont SubHeadingFont =
new GUIFont(
"SubHeadingFont");
41 public readonly
static GUIFont DigitalFont =
new GUIFont(
"DigitalFont");
42 public readonly
static GUIFont HotkeyFont =
new GUIFont(
"HotkeyFont");
43 public readonly
static GUIFont MonospacedFont =
new GUIFont(
"MonospacedFont");
45 public readonly
static GUICursor CursorSprite =
new GUICursor(
"Cursor");
47 public readonly
static GUISprite SubmarineLocationIcon =
new GUISprite(
"SubmarineLocationIcon");
48 public readonly
static GUISprite Arrow =
new GUISprite(
"Arrow");
49 public readonly
static GUISprite SpeechBubbleIcon =
new GUISprite(
"SpeechBubbleIcon");
50 public readonly
static GUISprite SpeechBubbleIconSliced =
new GUISprite(
"SpeechBubbleIconSliced");
51 public readonly
static GUISprite InteractionLabelBackground =
new GUISprite(
"InteractionLabelBackground");
52 public readonly
static GUISprite BrokenIcon =
new GUISprite(
"BrokenIcon");
53 public readonly
static GUISprite YouAreHereCircle =
new GUISprite(
"YouAreHereCircle");
55 public readonly
static GUISprite Radiation =
new GUISprite(
"Radiation");
56 public readonly
static GUISpriteSheet RadiationAnimSpriteSheet =
new GUISpriteSheet(
"RadiationAnimSpriteSheet");
58 public readonly
static GUISpriteSheet SavingIndicator =
new GUISpriteSheet(
"SavingIndicator");
59 public readonly
static GUISpriteSheet GenericThrobber =
new GUISpriteSheet(
"GenericThrobber");
61 public readonly
static GUISprite UIGlow =
new GUISprite(
"UIGlow");
62 public readonly
static GUISprite TalentGlow =
new GUISprite(
"TalentGlow");
63 public readonly
static GUISprite PingCircle =
new GUISprite(
"PingCircle");
64 public readonly
static GUISprite UIGlowCircular =
new GUISprite(
"UIGlowCircular");
65 public readonly
static GUISprite UIGlowSolidCircular =
new GUISprite(
"UIGlowSolidCircular");
66 public readonly
static GUISprite UIThermalGlow =
new GUISprite(
"UIGlowSolidCircular");
67 public readonly
static GUISprite ButtonPulse =
new GUISprite(
"ButtonPulse");
68 public readonly
static GUISprite WalletPortraitBG =
new GUISprite(
"WalletPortraitBG");
69 public readonly
static GUISprite CrewWalletIconSmall =
new GUISprite(
"CrewWalletIconSmall");
71 public readonly
static GUISprite EndRoundButtonPulse =
new GUISprite(
"EndRoundButtonPulse");
73 public readonly
static GUISpriteSheet FocusIndicator =
new GUISpriteSheet(
"FocusIndicator");
75 public readonly
static GUISprite IconOverflowIndicator =
new GUISprite(
"IconOverflowIndicator");
80 public readonly
static GUIColor Green =
new GUIColor(
"Green",
new Color(154, 213, 163, 255));
85 public readonly
static GUIColor Orange =
new GUIColor(
"Orange",
new Color(243, 162, 50, 255));
90 public readonly
static GUIColor Red =
new GUIColor(
"Red",
new Color(245, 105, 105, 255));
95 public readonly
static GUIColor Blue =
new GUIColor(
"Blue",
new Color(126, 211, 224, 255));
100 public readonly
static GUIColor Yellow =
new GUIColor(
"Yellow",
new Color(255, 255, 0, 255));
105 public readonly
static GUIColor ModdedServerColor =
new GUIColor(
"ModdedServerColor",
new Color(154, 185, 160, 255));
107 public readonly
static GUIColor ColorInventoryEmpty =
new GUIColor(
"ColorInventoryEmpty",
new Color(245, 105, 105, 255));
108 public readonly
static GUIColor ColorInventoryHalf =
new GUIColor(
"ColorInventoryHalf",
new Color(243, 162, 50, 255));
109 public readonly
static GUIColor ColorInventoryFull =
new GUIColor(
"ColorInventoryFull",
new Color(96, 222, 146, 255));
110 public readonly
static GUIColor ColorInventoryBackground =
new GUIColor(
"ColorInventoryBackground",
new Color(56, 56, 56, 255));
111 public readonly
static GUIColor ColorInventoryEmptyOverlay =
new GUIColor(
"ColorInventoryEmptyOverlay",
new Color(125, 125, 125, 255));
113 public readonly
static GUIColor TextColorNormal =
new GUIColor(
"TextColorNormal",
new Color(228, 217, 167, 255));
114 public readonly
static GUIColor TextColorBright =
new GUIColor(
"TextColorBright",
new Color(255, 255, 255, 255));
115 public readonly
static GUIColor TextColorDark =
new GUIColor(
"TextColorDark",
new Color(0, 0, 0, 230));
116 public readonly
static GUIColor TextColorDim =
new GUIColor(
"TextColorDim",
new Color(153, 153, 153, 153));
118 public readonly
static GUIColor ItemQualityColorPoor =
new GUIColor(
"ItemQualityColorPoor",
new Color(128, 128, 128, 255));
119 public readonly
static GUIColor ItemQualityColorNormal =
new GUIColor(
"ItemQualityColorNormal",
new Color(255, 255, 255, 255));
120 public readonly
static GUIColor ItemQualityColorGood =
new GUIColor(
"ItemQualityColorGood",
new Color(144, 238, 144, 255));
121 public readonly
static GUIColor ItemQualityColorExcellent =
new GUIColor(
"ItemQualityColorExcellent",
new Color(173, 216, 230, 255));
122 public readonly
static GUIColor ItemQualityColorMasterwork =
new GUIColor(
"ItemQualityColorMasterwork",
new Color(147, 112, 219, 255));
124 public readonly
static GUIColor ColorReputationVeryLow =
new GUIColor(
"ColorReputationVeryLow",
new Color(192, 60, 60, 255));
125 public readonly
static GUIColor ColorReputationLow =
new GUIColor(
"ColorReputationLow",
new Color(203, 145, 23, 255));
126 public readonly
static GUIColor ColorReputationNeutral =
new GUIColor(
"ColorReputationNeutral",
new Color(228, 217, 167, 255));
127 public readonly
static GUIColor ColorReputationHigh =
new GUIColor(
"ColorReputationHigh",
new Color(51, 152, 64, 255));
128 public readonly
static GUIColor ColorReputationVeryHigh =
new GUIColor(
"ColorReputationVeryHigh",
new Color(71, 160, 164, 255));
130 public readonly
static GUIColor InteractionLabelColor =
new GUIColor(
"InteractionLabelColor",
new Color(255, 255, 255, 255));
131 public readonly
static GUIColor InteractionLabelHoverColor =
new GUIColor(
"InteractionLabelHoverColor",
new Color(0, 255, 255, 255));
134 public readonly
static GUIColor EquipmentSlotIconColor =
new GUIColor(
"EquipmentSlotIconColor",
new Color(99, 70, 64, 255));
137 public readonly
static GUIColor BuffColorLow =
new GUIColor(
"BuffColorLow",
new Color(66, 170, 73, 255));
138 public readonly
static GUIColor BuffColorMedium =
new GUIColor(
"BuffColorMedium",
new Color(110, 168, 118, 255));
139 public readonly
static GUIColor BuffColorHigh =
new GUIColor(
"BuffColorHigh",
new Color(154, 213, 163, 255));
141 public readonly
static GUIColor DebuffColorLow =
new GUIColor(
"DebuffColorLow",
new Color(243, 162, 50, 255));
142 public readonly
static GUIColor DebuffColorMedium =
new GUIColor(
"DebuffColorMedium",
new Color(155, 55, 55, 255));
143 public readonly
static GUIColor DebuffColorHigh =
new GUIColor(
"DebuffColorHigh",
new Color(228, 27, 27, 255));
145 public readonly
static GUIColor HealthBarColorLow =
new GUIColor(
"HealthBarColorLow",
new Color(255, 0, 0, 255));
146 public readonly
static GUIColor HealthBarColorMedium =
new GUIColor(
"HealthBarColorMedium",
new Color(255, 165, 0, 255));
147 public readonly
static GUIColor HealthBarColorHigh =
new GUIColor(
"HealthBarColorHigh",
new Color(78, 114, 88));
148 public readonly
static GUIColor HealthBarColorPoisoned =
new GUIColor(
"HealthBarColorPoisoned",
new Color(100, 150, 0, 255));
150 private readonly
static Point defaultItemFrameMargin =
new Point(50, 56);
152 public static Point ItemFrameMargin
156 Point size = defaultItemFrameMargin.Multiply(GUI.SlicedSpriteScale);
158 var style = GetComponentStyle(
"ItemUI");
159 var sprite = style?.Sprites[GUIComponent.ComponentState.None].First();
162 size.X = Math.Min(sprite.Slices[0].Width + sprite.Slices[2].Width, size.X);
163 size.Y = Math.Min(sprite.Slices[0].Height + sprite.Slices[6].Height, size.Y);
169 public static int ItemFrameTopBarHeight
173 var style = GetComponentStyle(
"ItemUI");
174 var sprite = style?.Sprites[GUIComponent.ComponentState.None].First();
175 return (
int)Math.Min(sprite?.Slices[0].Height ?? 0, defaultItemFrameMargin.Y / 2 * GUI.SlicedSpriteScale);
179 public static Point ItemFrameOffset =>
new Point(0, 3).Multiply(GUI.SlicedSpriteScale);
181 public static GUIComponentStyle GetComponentStyle(
string styleName)
183 return GetComponentStyle(styleName.ToIdentifier());
186 public static GUIComponentStyle GetComponentStyle(Identifier identifier)
187 => ComponentStyles.TryGet(identifier, out var style) ? style :
null;
189 public static void Apply(GUIComponent targetComponent,
string styleName =
"", GUIComponent parent =
null)
191 Apply(targetComponent, styleName.ToIdentifier(), parent);
194 public static void Apply(GUIComponent targetComponent, Identifier styleName, GUIComponent parent =
null)
196 GUIComponentStyle componentStyle;
199 GUIComponentStyle parentStyle = parent.Style;
201 if (parentStyle ==
null)
203 Identifier parentStyleName = ReflectionUtils.GetTypeNameWithoutGenericArity(parent.GetType());
204 if (!ComponentStyles.ContainsKey(parentStyleName))
206 DebugConsole.ThrowError($
"Couldn't find a GUI style \"{parentStyleName}\"");
209 parentStyle = ComponentStyles[parentStyleName];
211 Identifier childStyleName = styleName.IsEmpty ? ReflectionUtils.GetTypeNameWithoutGenericArity(targetComponent.GetType()) : styleName;
212 parentStyle.ChildStyles.TryGetValue(childStyleName, out componentStyle);
216 Identifier styleIdentifier = styleName.ToIdentifier();
217 if (styleIdentifier == Identifier.Empty)
219 styleIdentifier = ReflectionUtils.GetTypeNameWithoutGenericArity(targetComponent.GetType());
221 if (!ComponentStyles.ContainsKey(styleIdentifier))
223 DebugConsole.ThrowError($
"Couldn't find a GUI style \"{styleIdentifier}\"");
226 componentStyle = ComponentStyles[styleIdentifier];
229 targetComponent.ApplyStyle(componentStyle);
232 public static GUIColor GetQualityColor(
int quality)
237 return ItemQualityColorGood;
239 return ItemQualityColorExcellent;
241 return ItemQualityColorMasterwork;
243 return ItemQualityColorPoor;
245 return ItemQualityColorNormal;
249 public static void RecalculateFonts()
251 foreach (var font
in Fonts.Values)
253 font.Prefabs.ForEach(p => p.LoadFont());
257 public static void RecalculateSizeRestrictions()
259 foreach (var componentStyle
in ComponentStyles)
261 componentStyle.RefreshSize();