1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 09:43:46 +00:00

Profile editor - Reimplemented a way to get all keyframe times

New implementation does not add clutter to the core
This commit is contained in:
SpoinkyNL 2020-09-11 00:04:06 +02:00
parent 675486fd7e
commit 3009a793dd
6 changed files with 63 additions and 39 deletions

View File

@ -205,7 +205,6 @@ namespace Artemis.Core
return (TimelinePosition - oldPosition).TotalSeconds; return (TimelinePosition - oldPosition).TotalSeconds;
} }
/// <summary> /// <summary>
/// Overrides the progress of the element /// Overrides the progress of the element
/// </summary> /// </summary>

View File

@ -84,10 +84,9 @@ namespace Artemis.UI.Shared.Services
/// <param name="tolerance">How close the time must be to snap</param> /// <param name="tolerance">How close the time must be to snap</param>
/// <param name="snapToSegments">Enable snapping to timeline segments</param> /// <param name="snapToSegments">Enable snapping to timeline segments</param>
/// <param name="snapToCurrentTime">Enable snapping to the current time of the editor</param> /// <param name="snapToCurrentTime">Enable snapping to the current time of the editor</param>
/// <param name="snapToKeyframes">Enable snapping to visible keyframes</param> /// <param name="snapTimes">An optional extra list of times to snap to</param>
/// <param name="excludedKeyframe">A keyframe to exclude during keyframe snapping</param>
/// <returns></returns> /// <returns></returns>
TimeSpan SnapToTimeline(TimeSpan time, TimeSpan tolerance, bool snapToSegments, bool snapToCurrentTime, bool snapToKeyframes, BaseLayerPropertyKeyframe excludedKeyframe = null); TimeSpan SnapToTimeline(TimeSpan time, TimeSpan tolerance, bool snapToSegments, bool snapToCurrentTime, List<TimeSpan> snapTimes = null);
/// <summary> /// <summary>
/// If a matching registration is found, creates a new <see cref="PropertyInputViewModel{T}"/> supporting <typeparamref name="T"/> /// If a matching registration is found, creates a new <see cref="PropertyInputViewModel{T}"/> supporting <typeparamref name="T"/>

View File

@ -35,7 +35,7 @@ namespace Artemis.UI.Shared.Services
public IReadOnlyList<PropertyInputRegistration> RegisteredPropertyEditors => _registeredPropertyEditors.AsReadOnly(); public IReadOnlyList<PropertyInputRegistration> RegisteredPropertyEditors => _registeredPropertyEditors.AsReadOnly();
public Profile SelectedProfile { get; private set; } public Profile SelectedProfile { get; private set; }
public RenderProfileElement SelectedProfileElement { get; private set; } public RenderProfileElement SelectedProfileElement { get; private set; }
public BaseLayerProperty SelectedDataBinding { get; private set; } public ILayerProperty SelectedDataBinding { get; private set; }
public TimeSpan CurrentTime public TimeSpan CurrentTime
{ {
@ -128,7 +128,7 @@ namespace Artemis.UI.Shared.Services
} }
} }
public void ChangeSelectedDataBinding(BaseLayerProperty layerProperty) public void ChangeSelectedDataBinding(ILayerProperty layerProperty)
{ {
SelectedDataBinding = layerProperty; SelectedDataBinding = layerProperty;
OnSelectedDataBindingChanged(); OnSelectedDataBindingChanged();
@ -229,7 +229,7 @@ namespace Artemis.UI.Shared.Services
} }
} }
public TimeSpan SnapToTimeline(TimeSpan time, TimeSpan tolerance, bool snapToSegments, bool snapToCurrentTime, bool snapToKeyframes, BaseLayerPropertyKeyframe excludedKeyframe = null) public TimeSpan SnapToTimeline(TimeSpan time, TimeSpan tolerance, bool snapToSegments, bool snapToCurrentTime, List<TimeSpan> snapTimes = null)
{ {
if (snapToSegments) if (snapToSegments)
{ {
@ -254,17 +254,12 @@ namespace Artemis.UI.Shared.Services
return SelectedProfileElement.StartSegmentLength; return SelectedProfileElement.StartSegmentLength;
} }
if (snapToKeyframes) if (snapTimes != null)
{ {
// Get all visible keyframes
var keyframes = SelectedProfileElement.GetAllKeyframes()
.Where(k => k != excludedKeyframe && SelectedProfileElement.IsPropertyGroupExpanded(k.BaseLayerProperty.Parent))
.ToList();
// Find the closest keyframe // Find the closest keyframe
var closeKeyframe = keyframes.FirstOrDefault(k => Math.Abs(time.TotalMilliseconds - k.Position.TotalMilliseconds) < tolerance.TotalMilliseconds); var closeSnapTime = snapTimes.FirstOrDefault(s => Math.Abs(time.TotalMilliseconds - s.TotalMilliseconds) < tolerance.TotalMilliseconds);
if (closeKeyframe != null) if (closeSnapTime != TimeSpan.Zero)
return closeKeyframe.Position; return closeSnapTime;
} }
return time; return time;

View File

@ -16,6 +16,7 @@ using Artemis.UI.Shared;
using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services;
using GongSolutions.Wpf.DragDrop; using GongSolutions.Wpf.DragDrop;
using Stylet; using Stylet;
using static Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree.LayerPropertyGroupTreeViewModel.LayerPropertyGroupType;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
{ {
@ -397,9 +398,14 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
private void SortProperties() private void SortProperties()
{ {
// Get all non-effect properties // Get all non-effect properties
var nonEffectProperties = LayerPropertyGroups.Where(l => l.GroupType != LayerEffectRoot).ToList(); var nonEffectProperties = LayerPropertyGroups
.Where(l => l.LayerPropertyGroupTreeViewModel.GroupType != LayerEffectRoot)
.ToList();
// Order the effects // Order the effects
var effectProperties = LayerPropertyGroups.Where(l => l.GroupType == LayerEffectRoot).OrderBy(l => l.LayerPropertyGroup.LayerEffect.Order).ToList(); var effectProperties = LayerPropertyGroups
.Where(l => l.LayerPropertyGroupTreeViewModel.GroupType == LayerEffectRoot)
.OrderBy(l => l.LayerPropertyGroup.LayerEffect.Order)
.ToList();
// Put the non-effect properties in front // Put the non-effect properties in front
for (var index = 0; index < nonEffectProperties.Count; index++) for (var index = 0; index < nonEffectProperties.Count; index++)
@ -435,7 +441,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
var source = dropInfo.Data as LayerPropertyGroupViewModel; var source = dropInfo.Data as LayerPropertyGroupViewModel;
var target = dropInfo.TargetItem as LayerPropertyGroupViewModel; var target = dropInfo.TargetItem as LayerPropertyGroupViewModel;
if (source == target || target?.GroupType != LayerEffectRoot || source?.GroupType != LayerEffectRoot) if (source == target ||
target?.LayerPropertyGroupTreeViewModel.GroupType != LayerEffectRoot ||
source?.LayerPropertyGroupTreeViewModel.GroupType != LayerEffectRoot)
return; return;
dropInfo.DropTargetAdorner = DropTargetAdorners.Insert; dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
@ -452,7 +460,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
var source = dropInfo.Data as LayerPropertyGroupViewModel; var source = dropInfo.Data as LayerPropertyGroupViewModel;
var target = dropInfo.TargetItem as LayerPropertyGroupViewModel; var target = dropInfo.TargetItem as LayerPropertyGroupViewModel;
if (source == target || target?.GroupType != LayerEffectRoot || source?.GroupType != LayerEffectRoot) if (source == target ||
target?.LayerPropertyGroupTreeViewModel.GroupType != LayerEffectRoot ||
source?.LayerPropertyGroupTreeViewModel.GroupType != LayerEffectRoot)
return; return;
if (dropInfo.InsertPosition == RelativeInsertPosition.BeforeTargetItem) if (dropInfo.InsertPosition == RelativeInsertPosition.BeforeTargetItem)
@ -481,7 +491,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
private void ApplyCurrentEffectsOrder() private void ApplyCurrentEffectsOrder()
{ {
var order = 1; var order = 1;
foreach (var groupViewModel in LayerPropertyGroups.Where(p => p.GroupType == LayerEffectRoot)) foreach (var groupViewModel in LayerPropertyGroups.Where(p => p.LayerPropertyGroupTreeViewModel.GroupType == LayerEffectRoot))
{ {
groupViewModel.UpdateOrder(order); groupViewModel.UpdateOrder(order);
order++; order++;
@ -551,16 +561,13 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
private TimeSpan CalculateEndTime() private TimeSpan CalculateEndTime()
{ {
if (!(ProfileEditorService.SelectedProfileElement is Layer layer)) var keyframeTimes = LayerPropertyGroups.SelectMany(g => g.GetAllKeyframePositions(false)).ToList();
return TimeSpan.MaxValue;
var keyframes = GetKeyframes(false);
// If there are no keyframes, don't stop at all // If there are no keyframes, don't stop at all
if (!keyframes.Any()) if (!keyframeTimes.Any())
return TimeSpan.MaxValue; return TimeSpan.MaxValue;
// If there are keyframes, stop after the last keyframe + 10 sec // If there are keyframes, stop after the last keyframe + 10 sec
return keyframes.Max(k => k.Position).Add(TimeSpan.FromSeconds(10)); return keyframeTimes.Max().Add(TimeSpan.FromSeconds(10));
} }
private void CoreServiceOnFrameRendering(object sender, FrameRenderingEventArgs e) private void CoreServiceOnFrameRendering(object sender, FrameRenderingEventArgs e)
@ -617,7 +624,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
// If holding down shift, snap to the closest segment or keyframe // If holding down shift, snap to the closest segment or keyframe
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
{ {
var snappedTime = ProfileEditorService.SnapToTimeline(newTime, TimeSpan.FromMilliseconds(1000f / ProfileEditorService.PixelsPerSecond * 5), true, false, true); var snapTimes = LayerPropertyGroups.SelectMany(g => g.GetAllKeyframePositions(true)).ToList();
var snappedTime = ProfileEditorService.SnapToTimeline(newTime, TimeSpan.FromMilliseconds(1000f / ProfileEditorService.PixelsPerSecond * 5), true, false, snapTimes);
ProfileEditorService.CurrentTime = snappedTime; ProfileEditorService.CurrentTime = snappedTime;
return; return;
} }
@ -634,15 +642,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
} }
} }
private List<BaseLayerPropertyKeyframe> GetKeyframes(bool visibleOnly)
{
var result = new List<BaseLayerPropertyKeyframe>();
foreach (var layerPropertyGroupViewModel in LayerPropertyGroups)
result.AddRange(layerPropertyGroupViewModel.GetKeyframes(visibleOnly));
return result;
}
#endregion #endregion
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using Artemis.Core; using Artemis.Core;
using Artemis.UI.Ninject.Factories; using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree; using Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree;
@ -69,5 +70,28 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
disposableChild.Dispose(); disposableChild.Dispose();
} }
} }
public void UpdateOrder(int order)
{
LayerPropertyGroup.LayerEffect.Order = order;
NotifyOfPropertyChange(nameof(IsExpanded));
}
public List<TimeSpan> GetAllKeyframePositions(bool expandedOnly)
{
var result = new List<TimeSpan>();
if (expandedOnly == IsExpanded)
return result;
foreach (var child in Children)
{
if (child is LayerPropertyViewModel layerPropertyViewModel)
result.AddRange(layerPropertyViewModel.LayerPropertyTimelineViewModel.GetAllKeyframePositions());
else if (child is LayerPropertyGroupViewModel layerPropertyGroupViewModel)
result.AddRange(layerPropertyGroupViewModel.GetAllKeyframePositions(expandedOnly));
}
return result;
}
} }
} }

View File

@ -1,4 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core; using Artemis.Core;
using Stylet; using Stylet;
@ -15,6 +17,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
LayerPropertyViewModel = layerPropertyViewModel; LayerPropertyViewModel = layerPropertyViewModel;
} }
public List<TimeSpan> GetAllKeyframePositions()
{
return LayerProperty.Keyframes.Select(k => k.Position).ToList();
}
public void Dispose() public void Dispose()
{ {
} }
@ -22,5 +29,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
public interface ILayerPropertyTimelineViewModel : IScreen, IDisposable public interface ILayerPropertyTimelineViewModel : IScreen, IDisposable
{ {
List<TimeSpan> GetAllKeyframePositions();
} }
} }