2using System.Collections.Generic;
4using System.Reflection;
6using System.Diagnostics;
9using Microsoft.Xna.Framework;
10using Microsoft.Xna.Framework.Input;
11using Microsoft.Xna.Framework.Graphics;
15using System.Diagnostics;
18 public class CUIStyleLoader
20 internal static void InitStatic()
22 CUI.OnInit += () => LoadDefaultStyles();
25 public static string DefaultStylesPath => Path.Combine(CUI.AssetsPath,
"Default Styles.xml");
28 public static void LoadDefaultStyles()
30 Stopwatch sw = Stopwatch.StartNew();
32 if (CUI.AssetsPath ==
null)
return;
33 if (!File.Exists(DefaultStylesPath))
return;
36 Dictionary<Type, CUIStyle> DefaultStyles =
new();
38 XDocument xdoc = XDocument.Load(DefaultStylesPath);
39 XElement root = xdoc.Element(
"DefaultStyles");
40 foreach (XElement componentStyle
in root.Elements())
42 Type componentType = CUIReflection.GetComponentTypeByName(componentStyle.Name.ToString());
43 if (componentType ==
null)
45 CUI.Warning($
"Couldn't find type for default style {componentStyle.Name}");
49 DefaultStyles[componentType] = CUIStyle.FromXML(componentStyle);
52 CUIDebug.Log($
"Parsing default styles took {sw.ElapsedMilliseconds}ms");
56 foreach (Type T
in DefaultStyles.Keys)
58 CUITypeMetaData.Get(T).DefaultStyle = DefaultStyles[T];
62 CUIDebug.Log($
"Applying default styles took {sw.ElapsedMilliseconds}ms");