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 SubLocationIcon =
new GUISprite(
"SubLocationIcon");
56 public readonly
static GUISprite ShuttleIcon =
new GUISprite(
"ShuttleIcon");
57 public readonly
static GUISprite WreckIcon =
new GUISprite(
"WreckIcon");
58 public readonly
static GUISprite CaveIcon =
new GUISprite(
"CaveIcon");
59 public readonly
static GUISprite OutpostIcon =
new GUISprite(
"OutpostIcon");
60 public readonly
static GUISprite RuinIcon =
new GUISprite(
"RuinIcon");
61 public readonly
static GUISprite EnemyIcon =
new GUISprite(
"EnemyIcon");
62 public readonly
static GUISprite CorpseIcon =
new GUISprite(
"CorpseIcon");
63 public readonly
static GUISprite BeaconIcon =
new GUISprite(
"BeaconIcon");
65 public readonly
static GUISprite Radiation =
new GUISprite(
"Radiation");
66 public readonly
static GUISpriteSheet RadiationAnimSpriteSheet =
new GUISpriteSheet(
"RadiationAnimSpriteSheet");
68 public readonly
static GUISpriteSheet SavingIndicator =
new GUISpriteSheet(
"SavingIndicator");
69 public readonly
static GUISpriteSheet GenericThrobber =
new GUISpriteSheet(
"GenericThrobber");
71 public readonly
static GUISprite UIGlow =
new GUISprite(
"UIGlow");
72 public readonly
static GUISprite TalentGlow =
new GUISprite(
"TalentGlow");
73 public readonly
static GUISprite PingCircle =
new GUISprite(
"PingCircle");
74 public readonly
static GUISprite UIGlowCircular =
new GUISprite(
"UIGlowCircular");
75 public readonly
static GUISprite UIGlowSolidCircular =
new GUISprite(
"UIGlowSolidCircular");
76 public readonly
static GUISprite UIThermalGlow =
new GUISprite(
"UIGlowSolidCircular");
77 public readonly
static GUISprite ButtonPulse =
new GUISprite(
"ButtonPulse");
78 public readonly
static GUISprite WalletPortraitBG =
new GUISprite(
"WalletPortraitBG");
79 public readonly
static GUISprite CrewWalletIconSmall =
new GUISprite(
"CrewWalletIconSmall");
81 public readonly
static GUISprite EndRoundButtonPulse =
new GUISprite(
"EndRoundButtonPulse");
83 public readonly
static GUISpriteSheet FocusIndicator =
new GUISpriteSheet(
"FocusIndicator");
85 public readonly
static GUISprite IconOverflowIndicator =
new GUISprite(
"IconOverflowIndicator");
90 public readonly
static GUIColor Green =
new GUIColor(
"Green",
new Color(154, 213, 163, 255));
95 public readonly
static GUIColor Orange =
new GUIColor(
"Orange",
new Color(243, 162, 50, 255));
100 public readonly
static GUIColor Red =
new GUIColor(
"Red",
new Color(245, 105, 105, 255));
105 public readonly
static GUIColor Blue =
new GUIColor(
"Blue",
new Color(126, 211, 224, 255));
110 public readonly
static GUIColor Yellow =
new GUIColor(
"Yellow",
new Color(255, 255, 0, 255));
115 public readonly
static GUIColor ModdedServerColor =
new GUIColor(
"ModdedServerColor",
new Color(154, 185, 160, 255));
117 public readonly
static GUIColor ColorInventoryEmpty =
new GUIColor(
"ColorInventoryEmpty",
new Color(245, 105, 105, 255));
118 public readonly
static GUIColor ColorInventoryHalf =
new GUIColor(
"ColorInventoryHalf",
new Color(243, 162, 50, 255));
119 public readonly
static GUIColor ColorInventoryFull =
new GUIColor(
"ColorInventoryFull",
new Color(96, 222, 146, 255));
120 public readonly
static GUIColor ColorInventoryBackground =
new GUIColor(
"ColorInventoryBackground",
new Color(56, 56, 56, 255));
121 public readonly
static GUIColor ColorInventoryEmptyOverlay =
new GUIColor(
"ColorInventoryEmptyOverlay",
new Color(125, 125, 125, 255));
123 public readonly
static GUIColor TextColorNormal =
new GUIColor(
"TextColorNormal",
new Color(228, 217, 167, 255));
124 public readonly
static GUIColor TextColorBright =
new GUIColor(
"TextColorBright",
new Color(255, 255, 255, 255));
125 public readonly
static GUIColor TextColorDark =
new GUIColor(
"TextColorDark",
new Color(0, 0, 0, 230));
126 public readonly
static GUIColor TextColorDim =
new GUIColor(
"TextColorDim",
new Color(153, 153, 153, 153));
128 public readonly
static GUIColor ItemQualityColorPoor =
new GUIColor(
"ItemQualityColorPoor",
new Color(128, 128, 128, 255));
129 public readonly
static GUIColor ItemQualityColorNormal =
new GUIColor(
"ItemQualityColorNormal",
new Color(255, 255, 255, 255));
130 public readonly
static GUIColor ItemQualityColorGood =
new GUIColor(
"ItemQualityColorGood",
new Color(144, 238, 144, 255));
131 public readonly
static GUIColor ItemQualityColorExcellent =
new GUIColor(
"ItemQualityColorExcellent",
new Color(173, 216, 230, 255));
132 public readonly
static GUIColor ItemQualityColorMasterwork =
new GUIColor(
"ItemQualityColorMasterwork",
new Color(147, 112, 219, 255));
134 public readonly
static GUIColor ColorReputationVeryLow =
new GUIColor(
"ColorReputationVeryLow",
new Color(192, 60, 60, 255));
135 public readonly
static GUIColor ColorReputationLow =
new GUIColor(
"ColorReputationLow",
new Color(203, 145, 23, 255));
136 public readonly
static GUIColor ColorReputationNeutral =
new GUIColor(
"ColorReputationNeutral",
new Color(228, 217, 167, 255));
137 public readonly
static GUIColor ColorReputationHigh =
new GUIColor(
"ColorReputationHigh",
new Color(51, 152, 64, 255));
138 public readonly
static GUIColor ColorReputationVeryHigh =
new GUIColor(
"ColorReputationVeryHigh",
new Color(71, 160, 164, 255));
140 public readonly
static GUIColor InteractionLabelColor =
new GUIColor(
"InteractionLabelColor",
new Color(255, 255, 255, 255));
141 public readonly
static GUIColor InteractionLabelHoverColor =
new GUIColor(
"InteractionLabelHoverColor",
new Color(0, 255, 255, 255));
144 public readonly
static GUIColor EquipmentSlotIconColor =
new GUIColor(
"EquipmentSlotIconColor",
new Color(99, 70, 64, 255));
147 public readonly
static GUIColor BuffColorLow =
new GUIColor(
"BuffColorLow",
new Color(66, 170, 73, 255));
148 public readonly
static GUIColor BuffColorMedium =
new GUIColor(
"BuffColorMedium",
new Color(110, 168, 118, 255));
149 public readonly
static GUIColor BuffColorHigh =
new GUIColor(
"BuffColorHigh",
new Color(154, 213, 163, 255));
151 public readonly
static GUIColor DebuffColorLow =
new GUIColor(
"DebuffColorLow",
new Color(243, 162, 50, 255));
152 public readonly
static GUIColor DebuffColorMedium =
new GUIColor(
"DebuffColorMedium",
new Color(155, 55, 55, 255));
153 public readonly
static GUIColor DebuffColorHigh =
new GUIColor(
"DebuffColorHigh",
new Color(228, 27, 27, 255));
155 public readonly
static GUIColor HealthBarColorLow =
new GUIColor(
"HealthBarColorLow",
new Color(255, 0, 0, 255));
156 public readonly
static GUIColor HealthBarColorMedium =
new GUIColor(
"HealthBarColorMedium",
new Color(255, 165, 0, 255));
157 public readonly
static GUIColor HealthBarColorHigh =
new GUIColor(
"HealthBarColorHigh",
new Color(78, 114, 88));
158 public readonly
static GUIColor HealthBarColorPoisoned =
new GUIColor(
"HealthBarColorPoisoned",
new Color(100, 150, 0, 255));
160 private readonly
static Point defaultItemFrameMargin =
new Point(50, 56);
162 public static Point ItemFrameMargin
166 Point size = defaultItemFrameMargin.Multiply(GUI.SlicedSpriteScale);
168 var style = GetComponentStyle(
"ItemUI");
169 var sprite = style?.Sprites[GUIComponent.ComponentState.None].First();
172 size.X = Math.Min(sprite.Slices[0].Width + sprite.Slices[2].Width, size.X);
173 size.Y = Math.Min(sprite.Slices[0].Height + sprite.Slices[6].Height, size.Y);
179 public static int ItemFrameTopBarHeight
183 var style = GetComponentStyle(
"ItemUI");
184 var sprite = style?.Sprites[GUIComponent.ComponentState.None].First();
185 return (
int)Math.Min(sprite?.Slices[0].Height ?? 0, defaultItemFrameMargin.Y / 2 * GUI.SlicedSpriteScale);
189 public static Point ItemFrameOffset =>
new Point(0, 3).Multiply(GUI.SlicedSpriteScale);
191 public static GUIComponentStyle GetComponentStyle(
string styleName)
193 return GetComponentStyle(styleName.ToIdentifier());
196 public static GUIComponentStyle GetComponentStyle(Identifier identifier)
197 => ComponentStyles.TryGet(identifier, out var style) ? style :
null;
199 public static void Apply(GUIComponent targetComponent,
string styleName =
"", GUIComponent parent =
null)
201 Apply(targetComponent, styleName.ToIdentifier(), parent);
204 public static void Apply(GUIComponent targetComponent, Identifier styleName, GUIComponent parent =
null)
206 GUIComponentStyle componentStyle;
209 GUIComponentStyle parentStyle = parent.Style;
211 if (parentStyle ==
null)
213 Identifier parentStyleName = ReflectionUtils.GetTypeNameWithoutGenericArity(parent.GetType());
214 if (!ComponentStyles.ContainsKey(parentStyleName))
216 DebugConsole.ThrowError($
"Couldn't find a GUI style \"{parentStyleName}\"");
219 parentStyle = ComponentStyles[parentStyleName];
221 Identifier childStyleName = styleName.IsEmpty ? ReflectionUtils.GetTypeNameWithoutGenericArity(targetComponent.GetType()) : styleName;
222 parentStyle.ChildStyles.TryGetValue(childStyleName, out componentStyle);
226 Identifier styleIdentifier = styleName.ToIdentifier();
227 if (styleIdentifier == Identifier.Empty)
229 styleIdentifier = ReflectionUtils.GetTypeNameWithoutGenericArity(targetComponent.GetType());
231 if (!ComponentStyles.ContainsKey(styleIdentifier))
233 DebugConsole.ThrowError($
"Couldn't find a GUI style \"{styleIdentifier}\"");
236 componentStyle = ComponentStyles[styleIdentifier];
239 targetComponent.ApplyStyle(componentStyle);
242 public static GUIColor GetQualityColor(
int quality)
247 return ItemQualityColorGood;
249 return ItemQualityColorExcellent;
251 return ItemQualityColorMasterwork;
253 return ItemQualityColorPoor;
255 return ItemQualityColorNormal;
259 public static void RecalculateFonts()
261 foreach (var font
in Fonts.Values)
263 font.Prefabs.ForEach(p => p.LoadFont());
267 public static void RecalculateSizeRestrictions()
269 foreach (var componentStyle
in ComponentStyles)
271 componentStyle.RefreshSize();