UI - My poor UI :< I regret starting this refactor

This commit is contained in:
SpoinkyNL committed 2020-04-30 00:12:24 +02:00
1 parent e97fc046f5
commit 41b3c77210
13 files changed
+130 -59

No files matched your search

+15 -5
View File
@@ -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);
+7 -1
View File
@@ -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};
}
}
}