mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Profile editor - Moved layer property input to the Shared UI project
This commit is contained in:
1 parent
a5b66441d9
commit
f1cbfb36e9
71 files changed
+1211
-434
No files matched your search
@@ -1,68 +0,0 @@
|
||||
using System;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.LayerProperties;
|
||||
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree;
|
||||
|
||||
namespace Artemis.UI.Services.Interfaces
|
||||
{
|
||||
public interface IProfileEditorService : IArtemisUIService
|
||||
{
|
||||
Profile SelectedProfile { get; }
|
||||
ProfileElement SelectedProfileElement { get; }
|
||||
TimeSpan CurrentTime { get; set; }
|
||||
int PixelsPerSecond { get; set; }
|
||||
|
||||
LayerPropertyBaseViewModel CreateLayerPropertyViewModel(BaseLayerProperty baseLayerProperty, PropertyDescriptionAttribute propertyDescription);
|
||||
void ChangeSelectedProfile(Profile profile);
|
||||
void UpdateSelectedProfile();
|
||||
void ChangeSelectedProfileElement(ProfileElement profileElement);
|
||||
void UpdateSelectedProfileElement();
|
||||
void UpdateProfilePreview();
|
||||
void UndoUpdateProfile(ProfileModule module);
|
||||
void RedoUpdateProfile(ProfileModule module);
|
||||
void StopRegularRender();
|
||||
void ResumeRegularRender();
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a new profile is selected
|
||||
/// </summary>
|
||||
event EventHandler<ProfileElementEventArgs> ProfileSelected;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs then the currently selected profile is updated
|
||||
/// </summary>
|
||||
event EventHandler<ProfileElementEventArgs> SelectedProfileUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a new profile element is selected
|
||||
/// </summary>
|
||||
event EventHandler<ProfileElementEventArgs> ProfileElementSelected;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the currently selected profile element is updated
|
||||
/// </summary>
|
||||
event EventHandler<ProfileElementEventArgs> SelectedProfileElementUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the current editor time is changed
|
||||
/// </summary>
|
||||
event EventHandler CurrentTimeChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the pixels per second (zoom level) is changed
|
||||
/// </summary>
|
||||
event EventHandler PixelsPerSecondChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the profile preview has been updated
|
||||
/// </summary>
|
||||
event EventHandler ProfilePreviewUpdated;
|
||||
|
||||
TreePropertyViewModel<T> CreateTreePropertyViewModel<T>(LayerPropertyViewModel<T> layerPropertyViewModel);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.Colors;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.PropertyInput;
|
||||
using Artemis.UI.PropertyInput;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using SkiaSharp;
|
||||
using SkiaSharp.Views.WPF;
|
||||
|
||||
@@ -12,10 +17,24 @@ namespace Artemis.UI.Services
|
||||
public class LayerEditorService : ILayerEditorService
|
||||
{
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
|
||||
public LayerEditorService(ISettingsService settingsService)
|
||||
public LayerEditorService(ISettingsService settingsService, IProfileEditorService profileEditorService)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
_profileEditorService = profileEditorService;
|
||||
RegisterBuiltInPropertyEditors();
|
||||
}
|
||||
|
||||
private void RegisterBuiltInPropertyEditors()
|
||||
{
|
||||
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(BrushPropertyInputViewModel));
|
||||
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(ColorGradientPropertyInputViewModel));
|
||||
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(FloatPropertyInputViewModel));
|
||||
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(IntPropertyInputViewModel));
|
||||
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(SKColorPropertyInputViewModel));
|
||||
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(SKPointPropertyInputViewModel));
|
||||
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(SKSizePropertyInputViewModel));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.Colors;
|
||||
using Artemis.Core.Models.Profile.LayerProperties;
|
||||
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Ninject;
|
||||
using Ninject.Parameters;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.UI.Services
|
||||
{
|
||||
public class ProfileEditorService : IProfileEditorService
|
||||
{
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IKernel _kernel;
|
||||
private TimeSpan _currentTime;
|
||||
private TimeSpan _lastUpdateTime;
|
||||
private int _pixelsPerSecond;
|
||||
|
||||
public ProfileEditorService(ICoreService coreService, IProfileService profileService, IKernel kernel)
|
||||
{
|
||||
_coreService = coreService;
|
||||
_profileService = profileService;
|
||||
_kernel = kernel;
|
||||
|
||||
RegisteredPropertyEditors = new Dictionary<Type, Type>
|
||||
{
|
||||
{typeof(LayerBrushReference), typeof(BrushPropertyInputViewModel)},
|
||||
{typeof(ColorGradient), typeof(ColorGradientPropertyInputViewModel)},
|
||||
{typeof(float), typeof(FloatPropertyInputViewModel)},
|
||||
{typeof(int), typeof(IntPropertyInputViewModel)},
|
||||
{typeof(SKColor), typeof(SKColorPropertyInputViewModel)},
|
||||
{typeof(SKPoint), typeof(SKPointPropertyInputViewModel)},
|
||||
{typeof(SKSize), typeof(SKSizePropertyInputViewModel)}
|
||||
};
|
||||
PixelsPerSecond = 31;
|
||||
}
|
||||
|
||||
public Dictionary<Type, Type> RegisteredPropertyEditors { get; set; }
|
||||
|
||||
public Profile SelectedProfile { get; private set; }
|
||||
public ProfileElement SelectedProfileElement { get; private set; }
|
||||
|
||||
public TimeSpan CurrentTime
|
||||
{
|
||||
get => _currentTime;
|
||||
set
|
||||
{
|
||||
if (_currentTime.Equals(value))
|
||||
return;
|
||||
_currentTime = value;
|
||||
UpdateProfilePreview();
|
||||
OnCurrentTimeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public int PixelsPerSecond
|
||||
{
|
||||
get => _pixelsPerSecond;
|
||||
set
|
||||
{
|
||||
_pixelsPerSecond = value;
|
||||
OnPixelsPerSecondChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public LayerPropertyBaseViewModel CreateLayerPropertyViewModel(BaseLayerProperty baseLayerProperty, PropertyDescriptionAttribute propertyDescription)
|
||||
{
|
||||
// Go through the pain of instantiating a generic type VM now via reflection to make things a lot simpler down the line
|
||||
var genericType = baseLayerProperty.GetType().BaseType.GetGenericArguments()[0];
|
||||
// Only create entries for types supported by a tree input VM
|
||||
if (!genericType.IsEnum && !RegisteredPropertyEditors.ContainsKey(genericType))
|
||||
return null;
|
||||
var genericViewModel = typeof(LayerPropertyViewModel<>).MakeGenericType(genericType);
|
||||
var parameters = new IParameter[]
|
||||
{
|
||||
new ConstructorArgument("layerProperty", baseLayerProperty),
|
||||
new ConstructorArgument("propertyDescription", propertyDescription)
|
||||
};
|
||||
|
||||
return (LayerPropertyBaseViewModel) _kernel.Get(genericViewModel, parameters);
|
||||
}
|
||||
|
||||
public TreePropertyViewModel<T> CreateTreePropertyViewModel<T>(LayerPropertyViewModel<T> layerPropertyViewModel)
|
||||
{
|
||||
var type = typeof(T).IsEnum
|
||||
? typeof(EnumPropertyInputViewModel<>).MakeGenericType(typeof(T))
|
||||
: RegisteredPropertyEditors[typeof(T)];
|
||||
|
||||
var parameters = new IParameter[]
|
||||
{
|
||||
new ConstructorArgument("layerPropertyViewModel", layerPropertyViewModel)
|
||||
};
|
||||
return new TreePropertyViewModel<T>(layerPropertyViewModel, (PropertyInputViewModel<T>) _kernel.Get(type, parameters), this);
|
||||
}
|
||||
|
||||
public void ChangeSelectedProfile(Profile profile)
|
||||
{
|
||||
ChangeSelectedProfileElement(null);
|
||||
|
||||
var profileElementEvent = new ProfileElementEventArgs(profile, SelectedProfile);
|
||||
SelectedProfile = profile;
|
||||
UpdateProfilePreview();
|
||||
OnSelectedProfileChanged(profileElementEvent);
|
||||
}
|
||||
|
||||
public void UpdateSelectedProfile()
|
||||
{
|
||||
_profileService.UpdateProfile(SelectedProfile, false);
|
||||
UpdateProfilePreview();
|
||||
OnSelectedProfileElementUpdated(new ProfileElementEventArgs(SelectedProfile));
|
||||
}
|
||||
|
||||
public void ChangeSelectedProfileElement(ProfileElement profileElement)
|
||||
{
|
||||
var profileElementEvent = new ProfileElementEventArgs(profileElement, SelectedProfileElement);
|
||||
SelectedProfileElement = profileElement;
|
||||
OnSelectedProfileElementChanged(profileElementEvent);
|
||||
}
|
||||
|
||||
public void UpdateSelectedProfileElement()
|
||||
{
|
||||
_profileService.UpdateProfile(SelectedProfile, true);
|
||||
UpdateProfilePreview();
|
||||
OnSelectedProfileElementUpdated(new ProfileElementEventArgs(SelectedProfileElement));
|
||||
}
|
||||
|
||||
public void UpdateProfilePreview()
|
||||
{
|
||||
if (SelectedProfile == null)
|
||||
return;
|
||||
|
||||
var delta = CurrentTime - _lastUpdateTime;
|
||||
foreach (var layer in SelectedProfile.GetAllLayers())
|
||||
{
|
||||
layer.OverrideProgress(CurrentTime);
|
||||
layer.LayerBrush?.Update(delta.TotalSeconds);
|
||||
}
|
||||
|
||||
_lastUpdateTime = CurrentTime;
|
||||
OnProfilePreviewUpdated();
|
||||
}
|
||||
|
||||
public void UndoUpdateProfile(ProfileModule module)
|
||||
{
|
||||
var undid = _profileService.UndoUpdateProfile(SelectedProfile, module);
|
||||
if (!undid)
|
||||
return;
|
||||
|
||||
OnSelectedProfileChanged(new ProfileElementEventArgs(SelectedProfile, SelectedProfile));
|
||||
|
||||
if (SelectedProfileElement != null)
|
||||
{
|
||||
var elements = SelectedProfile.GetAllLayers().Cast<ProfileElement>().ToList();
|
||||
elements.AddRange(SelectedProfile.GetAllFolders());
|
||||
var element = elements.FirstOrDefault(l => l.EntityId == SelectedProfileElement.EntityId);
|
||||
ChangeSelectedProfileElement(element);
|
||||
}
|
||||
|
||||
UpdateProfilePreview();
|
||||
}
|
||||
|
||||
public void RedoUpdateProfile(ProfileModule module)
|
||||
{
|
||||
var redid = _profileService.RedoUpdateProfile(SelectedProfile, module);
|
||||
if (!redid)
|
||||
return;
|
||||
|
||||
OnSelectedProfileChanged(new ProfileElementEventArgs(SelectedProfile, SelectedProfile));
|
||||
|
||||
if (SelectedProfileElement != null)
|
||||
{
|
||||
var elements = SelectedProfile.GetAllLayers().Cast<ProfileElement>().ToList();
|
||||
elements.AddRange(SelectedProfile.GetAllFolders());
|
||||
var element = elements.FirstOrDefault(l => l.EntityId == SelectedProfileElement.EntityId);
|
||||
ChangeSelectedProfileElement(element);
|
||||
}
|
||||
|
||||
UpdateProfilePreview();
|
||||
}
|
||||
|
||||
public event EventHandler<ProfileElementEventArgs> ProfileSelected;
|
||||
public event EventHandler<ProfileElementEventArgs> SelectedProfileUpdated;
|
||||
public event EventHandler<ProfileElementEventArgs> ProfileElementSelected;
|
||||
public event EventHandler<ProfileElementEventArgs> SelectedProfileElementUpdated;
|
||||
public event EventHandler CurrentTimeChanged;
|
||||
public event EventHandler PixelsPerSecondChanged;
|
||||
public event EventHandler ProfilePreviewUpdated;
|
||||
|
||||
public void StopRegularRender()
|
||||
{
|
||||
_coreService.ModuleUpdatingDisabled = true;
|
||||
}
|
||||
|
||||
public void ResumeRegularRender()
|
||||
{
|
||||
_coreService.ModuleUpdatingDisabled = false;
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileChanged(ProfileElementEventArgs e)
|
||||
{
|
||||
ProfileSelected?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileUpdated(ProfileElementEventArgs e)
|
||||
{
|
||||
SelectedProfileUpdated?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileElementChanged(ProfileElementEventArgs e)
|
||||
{
|
||||
ProfileElementSelected?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileElementUpdated(ProfileElementEventArgs e)
|
||||
{
|
||||
SelectedProfileElementUpdated?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnCurrentTimeChanged()
|
||||
{
|
||||
CurrentTimeChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnPixelsPerSecondChanged()
|
||||
{
|
||||
PixelsPerSecondChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnProfilePreviewUpdated()
|
||||
{
|
||||
ProfilePreviewUpdated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user