mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Profile editor - Refactored a lot of VMs so they clean up nicely
This commit is contained in:
1 parent
0dac4c7387
commit
4db66e1e3e
37 files changed
+531
-496
No files matched your search
@@ -15,7 +15,7 @@
|
||||
<Rectangle.OpacityMask>
|
||||
<VisualBrush Stretch="Uniform">
|
||||
<VisualBrush.Visual>
|
||||
<svgc:SvgViewbox Source="{Binding}" Name="SvgDisplay"/>
|
||||
<Image Source="{Binding Converter={svgc:SvgImageConverter}, Mode=OneWay}"/>
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
</Rectangle.OpacityMask>
|
||||
|
||||
@@ -13,7 +13,8 @@ namespace Artemis.UI.Shared
|
||||
public abstract class PropertyInputViewModel<T> : PropertyInputViewModel
|
||||
{
|
||||
private bool _inputDragging;
|
||||
[AllowNull] private T _inputValue = default!;
|
||||
[AllowNull]
|
||||
private T _inputValue = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="PropertyInputViewModel" /> class
|
||||
@@ -24,11 +25,6 @@ namespace Artemis.UI.Shared
|
||||
{
|
||||
LayerProperty = layerProperty;
|
||||
ProfileEditorService = profileEditorService;
|
||||
LayerProperty.Updated += LayerPropertyOnUpdated;
|
||||
LayerProperty.CurrentValueSet += LayerPropertyOnUpdated;
|
||||
LayerProperty.DataBindingEnabled += LayerPropertyOnDataBindingChange;
|
||||
LayerProperty.DataBindingDisabled += LayerPropertyOnDataBindingChange;
|
||||
UpdateInputValue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,11 +37,6 @@ namespace Artemis.UI.Shared
|
||||
{
|
||||
LayerProperty = layerProperty;
|
||||
ProfileEditorService = profileEditorService;
|
||||
LayerProperty.Updated += LayerPropertyOnUpdated;
|
||||
LayerProperty.CurrentValueSet += LayerPropertyOnUpdated;
|
||||
LayerProperty.DataBindingEnabled += LayerPropertyOnDataBindingChange;
|
||||
LayerProperty.DataBindingDisabled += LayerPropertyOnDataBindingChange;
|
||||
UpdateInputValue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,20 +78,27 @@ namespace Artemis.UI.Shared
|
||||
|
||||
internal override object InternalGuard { get; } = new();
|
||||
|
||||
#region IDisposable
|
||||
#region Overrides of Screen
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Dispose(bool disposing)
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
LayerProperty.Updated -= LayerPropertyOnUpdated;
|
||||
LayerProperty.CurrentValueSet -= LayerPropertyOnUpdated;
|
||||
LayerProperty.DataBindingEnabled -= LayerPropertyOnDataBindingChange;
|
||||
LayerProperty.DataBindingDisabled -= LayerPropertyOnDataBindingChange;
|
||||
}
|
||||
LayerProperty.Updated += LayerPropertyOnUpdated;
|
||||
LayerProperty.CurrentValueSet += LayerPropertyOnUpdated;
|
||||
LayerProperty.DataBindingEnabled += LayerPropertyOnDataBindingChange;
|
||||
LayerProperty.DataBindingDisabled += LayerPropertyOnDataBindingChange;
|
||||
UpdateInputValue();
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
/// <inheritdoc />
|
||||
protected override void OnClose()
|
||||
{
|
||||
LayerProperty.Updated -= LayerPropertyOnUpdated;
|
||||
LayerProperty.CurrentValueSet -= LayerPropertyOnUpdated;
|
||||
LayerProperty.DataBindingEnabled -= LayerPropertyOnDataBindingChange;
|
||||
LayerProperty.DataBindingDisabled -= LayerPropertyOnDataBindingChange;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -207,7 +205,7 @@ namespace Artemis.UI.Shared
|
||||
/// <summary>
|
||||
/// For internal use only, implement <see cref="PropertyInputViewModel{T}" /> instead.
|
||||
/// </summary>
|
||||
public abstract class PropertyInputViewModel : ValidatingModelBase, IDisposable
|
||||
public abstract class PropertyInputViewModel : Screen
|
||||
{
|
||||
/// <summary>
|
||||
/// For internal use only, implement <see cref="PropertyInputViewModel{T}" /> instead.
|
||||
@@ -228,30 +226,5 @@ namespace Artemis.UI.Shared
|
||||
/// </summary>
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
internal abstract object InternalGuard { get; }
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
|
||||
@@ -41,6 +42,11 @@ namespace Artemis.UI.Shared.Services
|
||||
/// </summary>
|
||||
ReadOnlyCollection<PropertyInputRegistration> RegisteredPropertyEditors { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether the editor is currently playing
|
||||
/// </summary>
|
||||
bool Playing { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Changes the selected profile
|
||||
/// </summary>
|
||||
@@ -129,6 +135,12 @@ namespace Artemis.UI.Shared.Services
|
||||
/// <returns></returns>
|
||||
TimeSpan SnapToTimeline(TimeSpan time, TimeSpan tolerance, bool snapToSegments, bool snapToCurrentTime, List<TimeSpan>? snapTimes = null);
|
||||
|
||||
/// <summary>
|
||||
/// Determines if there is a matching registration for the provided layer property
|
||||
/// </summary>
|
||||
/// <param name="layerProperty">The layer property to try to find a view model for</param>
|
||||
bool CanCreatePropertyInputViewModel(ILayerProperty layerProperty);
|
||||
|
||||
/// <summary>
|
||||
/// If a matching registration is found, creates a new <see cref="PropertyInputViewModel{T}" /> supporting
|
||||
/// <typeparamref name="T" />
|
||||
@@ -160,7 +172,13 @@ namespace Artemis.UI.Shared.Services
|
||||
/// Gets a boolean indicating whether a profile element is on the clipboard
|
||||
/// </summary>
|
||||
bool GetCanPasteProfileElement();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determines all LEDs on the current active surface contained in the specified rectangle
|
||||
/// </summary>
|
||||
/// <returns>A list containing all the LEDs that are in the provided rect</returns>
|
||||
List<ArtemisLed> GetLedsInRectangle(Rect rect);
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a new profile is selected
|
||||
/// </summary>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Core.Services;
|
||||
@@ -11,6 +12,7 @@ using Newtonsoft.Json;
|
||||
using Ninject;
|
||||
using Ninject.Parameters;
|
||||
using Serilog;
|
||||
using SkiaSharp.Views.WPF;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Shared.Services
|
||||
@@ -71,6 +73,8 @@ namespace Artemis.UI.Shared.Services
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<PropertyInputRegistration> RegisteredPropertyEditors => _registeredPropertyEditors.AsReadOnly();
|
||||
|
||||
public bool Playing { get; set; }
|
||||
public Profile? SelectedProfile { get; private set; }
|
||||
public RenderProfileElement? SelectedProfileElement { get; private set; }
|
||||
public ILayerProperty? SelectedDataBinding { get; private set; }
|
||||
@@ -302,6 +306,15 @@ namespace Artemis.UI.Shared.Services
|
||||
return time;
|
||||
}
|
||||
|
||||
public bool CanCreatePropertyInputViewModel(ILayerProperty layerProperty)
|
||||
{
|
||||
PropertyInputRegistration? registration = RegisteredPropertyEditors.FirstOrDefault(r => r.SupportedType == layerProperty.PropertyType);
|
||||
if (registration == null && layerProperty.PropertyType.IsEnum)
|
||||
registration = RegisteredPropertyEditors.FirstOrDefault(r => r.SupportedType == typeof(Enum));
|
||||
|
||||
return registration != null;
|
||||
}
|
||||
|
||||
public PropertyInputViewModel<T>? CreatePropertyInputViewModel<T>(LayerProperty<T> layerProperty)
|
||||
{
|
||||
Type? viewModelType = null;
|
||||
@@ -339,6 +352,11 @@ namespace Artemis.UI.Shared.Services
|
||||
return SelectedProfile?.Module;
|
||||
}
|
||||
|
||||
public List<ArtemisLed> GetLedsInRectangle(Rect rect)
|
||||
{
|
||||
return _surfaceService.ActiveSurface.Devices.SelectMany(d => d.Leds).Where(led => led.AbsoluteRectangle.IntersectsWith(rect.ToSKRect())).ToList();
|
||||
}
|
||||
|
||||
#region Copy/paste
|
||||
|
||||
public ProfileElement? DuplicateProfileElement(ProfileElement profileElement)
|
||||
|
||||
Reference in new issue
Block a user