using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; namespace Artemis.Core.LayerEffects { /// /// Allows you to register one or more s usable by profile layers. /// public abstract class LayerEffectProvider : PluginFeature { private readonly List _layerEffectDescriptors; /// /// Allows you to register one or more s usable by profile layers. /// protected LayerEffectProvider() { _layerEffectDescriptors = new List(); LayerEffectDescriptors = new(_layerEffectDescriptors); Disabled += OnDisabled; } /// /// A read-only collection of all layer effects added with /// public ReadOnlyCollection LayerEffectDescriptors { get; } /// /// Adds a layer effect descriptor for a given layer effect, so that it appears in the UI. /// Note: You do not need to manually remove these on disable /// /// The type of the layer effect you wish to register /// The name to display in the UI /// The description to display in the UI /// /// The Material icon to display in the UI, a full reference can be found here. /// May also be a path to an SVG file relative to the directory of the plugin. /// protected void RegisterLayerEffectDescriptor(string displayName, string description, string icon) where T : BaseLayerEffect { if (!IsEnabled) throw new ArtemisPluginFeatureException(this, "Can only add a layer effect descriptor when the plugin is enabled"); if (icon.ToLower().EndsWith(".svg")) icon = Plugin.ResolveRelativePath(icon); LayerEffectDescriptor descriptor = new(displayName, description, icon, typeof(T), this); _layerEffectDescriptors.Add(descriptor); LayerEffectStore.Add(descriptor); } private void OnDisabled(object? sender, EventArgs e) { // The store will clean up the registrations by itself, the plugin just needs to clear its own list _layerEffectDescriptors.Clear(); } } }