mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
UI - My poor UI :< I regret starting this refactor
This commit is contained in:
parent
e97fc046f5
commit
41b3c77210
@ -122,6 +122,7 @@ namespace Artemis.Core.Models.Profile
|
||||
LayerEntity.Order = Order;
|
||||
LayerEntity.Name = Name;
|
||||
LayerEntity.ProfileId = Profile.EntityId;
|
||||
|
||||
General.ApplyToEntity();
|
||||
Transform.ApplyToEntity();
|
||||
LayerBrush.ApplyToEntity();
|
||||
@ -184,27 +185,36 @@ namespace Artemis.Core.Models.Profile
|
||||
if (LayerBrush == null)
|
||||
return;
|
||||
|
||||
General.Update(deltaTime);
|
||||
Transform.Update(deltaTime);
|
||||
LayerBrush.UpdateProperties(deltaTime);
|
||||
|
||||
var properties = new List<BaseLayerProperty>(General.GetAllLayerProperties());
|
||||
properties.AddRange(Transform.GetAllLayerProperties());
|
||||
properties.AddRange(LayerBrush.GetAllLayerProperties());
|
||||
|
||||
// For now, reset all keyframe engines after the last keyframe was hit
|
||||
// This is a placeholder method of repeating the animation until repeat modes are implemented
|
||||
var timeLineEnd = properties.Max(p => p.GetLastKeyframePosition());
|
||||
var timeLineEnd = properties.Max(p => p.BaseKeyframes.Max(k => k.Position));
|
||||
if (properties.Any(p => p.TimelineProgress >= timeLineEnd))
|
||||
{
|
||||
General.Override(TimeSpan.Zero);
|
||||
Transform.Override(TimeSpan.Zero);
|
||||
LayerBrush.OverrideProperties(TimeSpan.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
General.Update(deltaTime);
|
||||
Transform.Update(deltaTime);
|
||||
LayerBrush.UpdateProperties(deltaTime);
|
||||
}
|
||||
|
||||
LayerBrush.Update(deltaTime);
|
||||
}
|
||||
|
||||
public void OverrideProgress(TimeSpan timeOverride)
|
||||
{
|
||||
General.Override(timeOverride);
|
||||
Transform.Override(timeOverride);
|
||||
LayerBrush.OverrideProperties(timeOverride);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Render(double deltaTime, SKCanvas canvas, SKImageInfo canvasInfo)
|
||||
{
|
||||
|
||||
@ -9,12 +9,9 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
/// </summary>
|
||||
public abstract class BaseLayerProperty
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to declare that this property doesn't belong to a plugin and should use the core plugin GUID
|
||||
/// </summary>
|
||||
internal bool IsCoreProperty { get; set; }
|
||||
internal PropertyEntity PropertyEntity { get; set; }
|
||||
internal LayerPropertyGroup LayerPropertyGroup { get; set; }
|
||||
internal BaseLayerProperty()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether keyframes are supported on this property
|
||||
@ -42,6 +39,15 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
/// </summary>
|
||||
public TimeSpan TimelineProgress { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to declare that this property doesn't belong to a plugin and should use the core plugin GUID
|
||||
/// </summary>
|
||||
internal bool IsCoreProperty { get; set; }
|
||||
|
||||
internal PropertyEntity PropertyEntity { get; set; }
|
||||
internal LayerPropertyGroup LayerPropertyGroup { get; set; }
|
||||
internal abstract IReadOnlyList<BaseLayerPropertyKeyframe> BaseKeyframes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Applies the provided property entity to the layer property by deserializing the JSON base value and keyframe values
|
||||
/// </summary>
|
||||
@ -54,8 +60,5 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
/// <see cref="ApplyToLayerProperty" />
|
||||
/// </summary>
|
||||
internal abstract void ApplyToEntity();
|
||||
|
||||
internal abstract List<TimeSpan> GetKeyframePositions();
|
||||
internal abstract TimeSpan GetLastKeyframePosition();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Artemis.Core.Utilities;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
{
|
||||
/// <summary>
|
||||
/// For internal use only, use <see cref="LayerPropertyKeyframe{T}" /> instead.
|
||||
/// </summary>
|
||||
public abstract class BaseLayerPropertyKeyframe
|
||||
{
|
||||
internal BaseLayerPropertyKeyframe()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The position of this keyframe in the timeline
|
||||
/// </summary>
|
||||
public abstract TimeSpan Position { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The easing function applied on the value of the keyframe
|
||||
/// </summary>
|
||||
public abstract Easings.Functions EasingFunction { get; set; }
|
||||
|
||||
internal abstract BaseLayerProperty BaseLayerProperty { get; }
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,8 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
/// <summary>
|
||||
/// Represents a property on a layer. Properties are saved in storage and can optionally be modified from the UI.
|
||||
/// <para>
|
||||
/// Note: You cannot initialize layer properties yourself. If properly placed and annotated, the Artemis core will initialize
|
||||
/// Note: You cannot initialize layer properties yourself. If properly placed and annotated, the Artemis core will
|
||||
/// initialize
|
||||
/// these for you.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
@ -53,12 +54,12 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
get => !KeyframesEnabled || !KeyframesSupported ? BaseValue : _currentValue;
|
||||
internal set => _currentValue = value;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only list of all the keyframes on this layer property
|
||||
/// </summary>
|
||||
public IReadOnlyList<LayerPropertyKeyframe<T>> Keyframes => _keyframes.AsReadOnly();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current keyframe in the timeline according to the current progress
|
||||
/// </summary>
|
||||
@ -68,7 +69,9 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
/// Gets the next keyframe in the timeline according to the current progress
|
||||
/// </summary>
|
||||
public LayerPropertyKeyframe<T> NextKeyframe { get; protected set; }
|
||||
|
||||
|
||||
internal override IReadOnlyList<BaseLayerPropertyKeyframe> BaseKeyframes => _keyframes.Cast<BaseLayerPropertyKeyframe>().ToList().AsReadOnly();
|
||||
|
||||
/// <summary>
|
||||
/// Adds a keyframe to the layer property
|
||||
/// </summary>
|
||||
@ -93,6 +96,16 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
OnKeyframeRemoved();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all keyframes from the layer property
|
||||
/// </summary>
|
||||
public void ClearKeyframes()
|
||||
{
|
||||
var keyframes = new List<LayerPropertyKeyframe<T>>(_keyframes);
|
||||
foreach (var layerPropertyKeyframe in keyframes)
|
||||
RemoveKeyframe(layerPropertyKeyframe);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every update (if keyframes are both supported and enabled) to determine the new <see cref="CurrentValue" />
|
||||
/// based on the provided progress
|
||||
@ -167,6 +180,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
IsLoadedFromStorage = true;
|
||||
BaseValue = JsonConvert.DeserializeObject<T>(entity.Value);
|
||||
CurrentValue = BaseValue;
|
||||
KeyframesEnabled = entity.KeyframesEnabled;
|
||||
|
||||
_keyframes.Clear();
|
||||
_keyframes.AddRange(entity.KeyframeEntities.Select(k => new LayerPropertyKeyframe<T>(
|
||||
@ -194,6 +208,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
throw new ArtemisCoreException("Layer property is not yet initialized");
|
||||
|
||||
PropertyEntity.Value = JsonConvert.SerializeObject(BaseValue);
|
||||
PropertyEntity.KeyframesEnabled = KeyframesEnabled;
|
||||
PropertyEntity.KeyframeEntities.Clear();
|
||||
PropertyEntity.KeyframeEntities.AddRange(Keyframes.Select(k => new KeyframeEntity
|
||||
{
|
||||
@ -203,16 +218,6 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
}));
|
||||
}
|
||||
|
||||
internal override List<TimeSpan> GetKeyframePositions()
|
||||
{
|
||||
return Keyframes.Select(k => k.Position).ToList();
|
||||
}
|
||||
|
||||
internal override TimeSpan GetLastKeyframePosition()
|
||||
{
|
||||
return Keyframes.LastOrDefault()?.Position ?? TimeSpan.Zero;
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler Updated;
|
||||
|
||||
@ -3,7 +3,7 @@ using Artemis.Core.Utilities;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
{
|
||||
public class LayerPropertyKeyframe<T>
|
||||
public class LayerPropertyKeyframe<T> : BaseLayerPropertyKeyframe
|
||||
{
|
||||
private TimeSpan _position;
|
||||
|
||||
@ -14,10 +14,18 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
EasingFunction = easingFunction;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The layer property this keyframe is applied to
|
||||
/// </summary>
|
||||
public LayerProperty<T> LayerProperty { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The value of this keyframe
|
||||
/// </summary>
|
||||
public T Value { get; set; }
|
||||
|
||||
public TimeSpan Position
|
||||
/// <inheritdoc />
|
||||
public override TimeSpan Position
|
||||
{
|
||||
get => _position;
|
||||
set
|
||||
@ -27,6 +35,9 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
}
|
||||
}
|
||||
|
||||
public Easings.Functions EasingFunction { get; set; }
|
||||
/// <inheritdoc />
|
||||
public sealed override Easings.Functions EasingFunction { get; set; }
|
||||
|
||||
internal override BaseLayerProperty BaseLayerProperty => LayerProperty;
|
||||
}
|
||||
}
|
||||
@ -29,6 +29,8 @@ namespace Artemis.Core.Plugins.LayerBrush
|
||||
/// </summary>
|
||||
public PluginInfo PluginInfo => Descriptor.LayerBrushProvider.PluginInfo;
|
||||
|
||||
internal virtual LayerPropertyGroup BaseProperties => null;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the brush is being removed from the layer
|
||||
/// </summary>
|
||||
|
||||
@ -46,6 +46,9 @@ namespace Artemis.Core.Plugins.LayerBrush
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
internal override LayerPropertyGroup BaseProperties => Properties;
|
||||
|
||||
internal override void InitializeProperties(ILayerService layerService, string path)
|
||||
{
|
||||
Properties.InitializeProperties(layerService, Layer, path);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Plugins.LayerBrush;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
@ -75,5 +76,10 @@ namespace Artemis.Core.Services
|
||||
|
||||
layer.LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == brush.PluginInfo.Guid);
|
||||
}
|
||||
|
||||
public void GetLayerPropertyGroups(Layer layer)
|
||||
{
|
||||
var groups = new List<LayerPropertyGroup> {layer.General, layer.Transform, layer.LayerBrush.BrushProperties};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -14,7 +14,7 @@ namespace Artemis.Storage.Entities.Profile
|
||||
public string Path { get; set; }
|
||||
|
||||
public string Value { get; set; }
|
||||
public bool IsUsingKeyframes { get; set; }
|
||||
public bool KeyframesEnabled { get; set; }
|
||||
|
||||
public List<KeyframeEntity> KeyframeEntities { get; set; }
|
||||
}
|
||||
|
||||
@ -70,6 +70,6 @@ namespace Artemis.UI.Ninject.Factories
|
||||
|
||||
public interface IPropertyTrackKeyframeVmFactory : IVmFactory
|
||||
{
|
||||
PropertyTrackKeyframeViewModel Create(PropertyTrackViewModel propertyTrackViewModel, BaseKeyframe keyframe);
|
||||
PropertyTrackKeyframeViewModel<T> Create<T>(PropertyTrackViewModel propertyTrackViewModel, LayerPropertyKeyframe<T> keyframe);
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile.LayerProperties;
|
||||
using Artemis.Core.Utilities;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Ninject;
|
||||
@ -9,31 +10,30 @@ using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
{
|
||||
public class LayerPropertyViewModel : PropertyChangedBase
|
||||
public class LayerPropertyViewModel<T> : LayerPropertyViewModel
|
||||
{
|
||||
private readonly IKernel _kernel;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private bool _keyframesEnabled;
|
||||
private bool _isExpanded;
|
||||
|
||||
public LayerPropertyViewModel(BaseLayerProperty layerProperty, LayerPropertyViewModel parent, IKernel kernel, IProfileEditorService profileEditorService)
|
||||
public LayerPropertyViewModel(LayerProperty<T> layerProperty, LayerPropertyViewModel parent, IKernel kernel, IProfileEditorService profileEditorService)
|
||||
{
|
||||
_kernel = kernel;
|
||||
_profileEditorService = profileEditorService;
|
||||
_keyframesEnabled = layerProperty.IsUsingKeyframes;
|
||||
_keyframesEnabled = layerProperty.KeyframesEnabled;
|
||||
|
||||
LayerProperty = layerProperty;
|
||||
Parent = parent;
|
||||
Children = new List<LayerPropertyViewModel>();
|
||||
IsExpanded = layerProperty.ExpandByDefault;
|
||||
|
||||
// TODO: Get from attribute
|
||||
IsExpanded = false;
|
||||
|
||||
Parent?.Children.Add(this);
|
||||
}
|
||||
|
||||
public BaseLayerProperty LayerProperty { get; }
|
||||
|
||||
public LayerPropertyViewModel Parent { get; }
|
||||
public List<LayerPropertyViewModel> Children { get; }
|
||||
public LayerProperty<T> LayerProperty { get; }
|
||||
|
||||
public bool IsExpanded
|
||||
{
|
||||
@ -58,7 +58,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
public PropertyInputViewModel GetPropertyInputViewModel()
|
||||
{
|
||||
// If the type is an enum type, search for Enum instead.
|
||||
var type = LayerProperty.Type;
|
||||
var type = typeof(T);
|
||||
if (type.IsEnum)
|
||||
type = typeof(Enum);
|
||||
|
||||
@ -72,15 +72,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
|
||||
private void UpdateKeyframes()
|
||||
{
|
||||
|
||||
// Either create a new first keyframe or clear all the keyframes
|
||||
if (_keyframesEnabled)
|
||||
LayerProperty.CreateNewKeyframe(_profileEditorService.CurrentTime, LayerProperty.GetCurrentValue());
|
||||
LayerProperty.AddKeyframe(new LayerPropertyKeyframe<T>(LayerProperty.CurrentValue, _profileEditorService.CurrentTime, Easings.Functions.Linear));
|
||||
else
|
||||
LayerProperty.ClearKeyframes();
|
||||
|
||||
// Force the keyframe engine to update, the new keyframe is the current keyframe
|
||||
LayerProperty.IsUsingKeyframes = _keyframesEnabled;
|
||||
LayerProperty.KeyframeEngine?.Update(0);
|
||||
LayerProperty.KeyframesEnabled = _keyframesEnabled;
|
||||
LayerProperty.Update(0);
|
||||
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
@ -88,6 +89,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
#region Events
|
||||
|
||||
public event EventHandler<EventArgs> ExpandedStateChanged;
|
||||
|
||||
protected virtual void OnExpandedStateChanged()
|
||||
{
|
||||
ExpandedStateChanged?.Invoke(this, EventArgs.Empty);
|
||||
@ -97,4 +99,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class LayerPropertyViewModel : PropertyChangedBase
|
||||
{
|
||||
public LayerPropertyViewModel Parent { get; protected set; }
|
||||
public List<LayerPropertyViewModel> Children { get; protected set; }
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
@ -10,12 +9,12 @@ using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline
|
||||
{
|
||||
public class PropertyTrackKeyframeViewModel : PropertyChangedBase
|
||||
public class PropertyTrackKeyframeViewModel<T> : PropertyTrackKeyframeViewModel
|
||||
{
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private int _pixelsPerSecond;
|
||||
|
||||
public PropertyTrackKeyframeViewModel(PropertyTrackViewModel propertyTrackViewModel, BaseKeyframe keyframe, IProfileEditorService profileEditorService)
|
||||
public PropertyTrackKeyframeViewModel(PropertyTrackViewModel propertyTrackViewModel, LayerPropertyKeyframe<T> keyframe, IProfileEditorService profileEditorService)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
|
||||
@ -27,7 +26,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline
|
||||
|
||||
public bool IsSelected { get; set; }
|
||||
public PropertyTrackViewModel PropertyTrackViewModel { get; }
|
||||
public BaseKeyframe Keyframe { get; }
|
||||
public LayerPropertyKeyframe<T> Keyframe { get; }
|
||||
public BindableCollection<PropertyTrackEasingViewModel> EasingViewModels { get; set; }
|
||||
public double X { get; set; }
|
||||
public string Timestamp { get; set; }
|
||||
@ -170,4 +169,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public abstract class PropertyTrackKeyframeViewModel : PropertyChangedBase
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -74,18 +74,11 @@ namespace Artemis.UI.Services
|
||||
{
|
||||
if (SelectedProfile == null)
|
||||
return;
|
||||
|
||||
var delta = CurrentTime - _lastUpdateTime;
|
||||
foreach (var layer in SelectedProfile.GetAllLayers())
|
||||
{
|
||||
// Override keyframe progress
|
||||
foreach (var baseLayerProperty in layer.Properties)
|
||||
baseLayerProperty.KeyframeEngine?.OverrideProgress(CurrentTime);
|
||||
|
||||
// Force layer shape to redraw
|
||||
layer.LayerShape?.CalculateRenderProperties();
|
||||
// Manually update the layer's engine and brush
|
||||
foreach (var property in layer.Properties)
|
||||
property.KeyframeEngine?.Update(delta.TotalSeconds);
|
||||
layer.OverrideProgress(CurrentTime);
|
||||
layer.LayerBrush?.Update(delta.TotalSeconds);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user