Plugins - Simplified and streamlined the way plugins provide VMs

Plugins - Added dependency injection to all plugin VMs
Plugin settings - Allow injecting plugin settings into any class defined in the plugin assembly
This commit is contained in:
Robert committed 2020-08-21 11:14:53 +02:00
1 parent aa3c3d6b95
commit c71faba2c9
29 files changed
+349 -165

No files matched your search

@@ -1,6 +1,5 @@
using System;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
@@ -15,6 +14,7 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
public abstract class BaseLayerBrush : PropertyChangedBase, IDisposable
{
private LayerBrushType _brushType;
private LayerBrushConfigurationDialog _configurationDialog;
private LayerBrushDescriptor _descriptor;
private Layer _layer;
private bool _supportsTransformation = true;
@@ -37,6 +37,15 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
internal set => SetAndNotify(ref _descriptor, value);
}
/// <summary>
/// Gets or sets a configuration dialog complementing the regular properties
/// </summary>
public LayerBrushConfigurationDialog ConfigurationDialog
{
get => _configurationDialog;
protected set => SetAndNotify(ref _configurationDialog, value);
}
/// <summary>
/// Gets the type of layer brush
/// </summary>
@@ -71,17 +80,12 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
}
}
/// <summary>
/// Gets or sets whether this plugin has a configuration view model.
/// If set to true, <see cref="GetConfigurationViewModel" /> will be called when the plugin is configured from the UI.
/// </summary>
public bool HasConfigurationViewModel { get; protected set; }
/// <inheritdoc />
public void Dispose()
{
DisableLayerBrush();
BaseProperties.Dispose();
Dispose(true);
GC.SuppressFinalize(this);
}
@@ -102,16 +106,6 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
/// <param name="deltaTime">Seconds passed since last update</param>
public abstract void Update(double deltaTime);
/// <summary>
/// Called when the brush configuration window is opened from the UI. The UI will only attempt to open if
/// <see cref="HasConfigurationViewModel" /> is set to True.
/// </summary>
/// <returns></returns>
public virtual BrushConfigurationViewModel GetConfigurationViewModel()
{
return null;
}
// Not only is this needed to initialize properties on the layer brushes, it also prevents implementing anything
// but LayerBrush<T> and RgbNetLayerBrush<T> outside the core
internal abstract void Initialize(IRenderElementService renderElementService);
@@ -123,9 +117,19 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
}
}
/// <summary>
/// Describes the type of a layer brush
/// </summary>
public enum LayerBrushType
{
/// <summary>
/// A regular brush that users Artemis' SkiaSharp-based rendering engine
/// </summary>
Regular,
/// <summary>
/// An RGB.NET brush that uses RGB.NET's per-LED rendering engine.
/// </summary>
RgbNet
}
}
@@ -8,8 +8,16 @@ using SkiaSharp;
namespace Artemis.Core.Plugins.LayerBrush.Abstract
{
/// <summary>
/// An RGB.NET brush that uses RGB.NET's per-LED rendering engine.
/// <para>Note: This brush type always renders on top of regular brushes</para>
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class RgbNetLayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup
{
/// <summary>
/// Creates a new instance of the <see cref="RgbNetLayerBrush{T}" /> class
/// </summary>
protected RgbNetLayerBrush()
{
BrushType = LayerBrushType.RgbNet;
@@ -0,0 +1,29 @@
using System;
using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.LayerBrush.Abstract;
namespace Artemis.Core.Plugins.LayerBrush
{
/// <inheritdoc />
public class LayerBrushConfigurationDialog<T> : LayerBrushConfigurationDialog where T : BrushConfigurationViewModel
{
/// <inheritdoc />
public override Type Type => typeof(T);
}
/// <summary>
/// Describes a UI tab for a layer brush
/// </summary>
public abstract class LayerBrushConfigurationDialog
{
/// <summary>
/// The layer brush this dialog belongs to
/// </summary>
internal BaseLayerBrush LayerBrush { get; set; }
/// <summary>
/// The type of view model the tab contains
/// </summary>
public abstract Type Type { get; }
}
}
@@ -3,6 +3,9 @@ using Artemis.Core.Plugins.Abstract;
namespace Artemis.Core.Plugins.LayerBrush
{
/// <summary>
/// A class that describes a layer brush
/// </summary>
public class LayerBrushDescriptor
{
internal LayerBrushDescriptor(string displayName, string description, string icon, Type layerBrushType, LayerBrushProvider layerBrushProvider)
@@ -14,10 +17,30 @@ namespace Artemis.Core.Plugins.LayerBrush
LayerBrushProvider = layerBrushProvider;
}
/// <summary>
/// The name that is displayed in the UI
/// </summary>
public string DisplayName { get; }
/// <summary>
/// The description that is displayed in the UI
/// </summary>
public string Description { get; }
/// <summary>
/// The Material icon to display in the UI, a full reference can be found
/// <see href="https://materialdesignicons.com">here</see>
/// </summary>
public string Icon { get; }
/// <summary>
/// The type of the layer brush
/// </summary>
public Type LayerBrushType { get; }
/// <summary>
/// The plugin that provided this <see cref="LayerBrushDescriptor" />
/// </summary>
public LayerBrushProvider LayerBrushProvider { get; }
}
}