using System; using System.Collections.Generic; using System.Reflection; using VDash.Overlay.Actions; using VDash.Overlay.Config; using System.Linq; namespace VDash.Overlay { public interface IOverlay : IDisposable { event EventHandler OverlayShown; event EventHandler OverlayHidden; ulong OverlayHandle { get; } IOverlayConfig OverlayConfig { get; } void Create(); void Destroy(); string GetOverlayName(); float GetOverlayWidth(); void SetOverlayWidth(float width); void SetOverlayName(string newName); int CurrentFPS { get; } } public class OverlayInfo : System.Attribute { public OverlayInfo(string description, Type configType, Type editorType) { Description = description; ConfigType = configType; EditorType = editorType; } public string Description { get; private set; } public Type ConfigType { get; private set; } public Type EditorType { get; private set; } public static IEnumerable GetTypesWithAttribute() { var assembly = Assembly.GetExecutingAssembly(); foreach (Type type in assembly.GetTypes()) { if (type.GetCustomAttributes(typeof(OverlayInfo), true).Length > 0) { yield return type; } } } public class OverlayAttributeInfo { public OverlayAttributeInfo(Type type, OverlayInfo info) { OverlayType = type; Info = info; } public Type OverlayType { get; private set; } public OverlayInfo Info { get; private set; } } public static OverlayAttributeInfo[] GetOverlayInfos() { List infos = new List(); var attrs = GetTypesWithAttribute(); foreach(var attr in attrs) { OverlayInfo thingInfo = (OverlayInfo)attr.GetCustomAttribute(typeof(OverlayInfo), true); infos.Add(new OverlayAttributeInfo(attr, thingInfo)); } return infos.ToArray(); } } }