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 committed 2020-09-12 10:39:44 +02:00
1 parent 675486fd7e
commit 3009a793dd
6 files changed
+63 -39

No files matched your search

@@ -84,10 +84,9 @@ namespace Artemis.UI.Shared.Services
/// <param name="tolerance">How close the time must be to snap</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="snapToKeyframes">Enable snapping to visible keyframes</param>
/// <param name="excludedKeyframe">A keyframe to exclude during keyframe snapping</param>
/// <param name="snapTimes">An optional extra list of times to snap to</param>
/// <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>
/// If a matching registration is found, creates a new <see cref="PropertyInputViewModel{T}"/> supporting <typeparamref name="T"/>
@@ -35,7 +35,7 @@ namespace Artemis.UI.Shared.Services
public IReadOnlyList<PropertyInputRegistration> RegisteredPropertyEditors => _registeredPropertyEditors.AsReadOnly();
public Profile SelectedProfile { get; private set; }
public RenderProfileElement SelectedProfileElement { get; private set; }
public BaseLayerProperty SelectedDataBinding { get; private set; }
public ILayerProperty SelectedDataBinding { get; private set; }
public TimeSpan CurrentTime
{
@@ -128,7 +128,7 @@ namespace Artemis.UI.Shared.Services
}
}
public void ChangeSelectedDataBinding(BaseLayerProperty layerProperty)
public void ChangeSelectedDataBinding(ILayerProperty layerProperty)
{
SelectedDataBinding = layerProperty;
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)
{
@@ -254,17 +254,12 @@ namespace Artemis.UI.Shared.Services
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
var closeKeyframe = keyframes.FirstOrDefault(k => Math.Abs(time.TotalMilliseconds - k.Position.TotalMilliseconds) < tolerance.TotalMilliseconds);
if (closeKeyframe != null)
return closeKeyframe.Position;
var closeSnapTime = snapTimes.FirstOrDefault(s => Math.Abs(time.TotalMilliseconds - s.TotalMilliseconds) < tolerance.TotalMilliseconds);
if (closeSnapTime != TimeSpan.Zero)
return closeSnapTime;
}
return time;