From c885ae225c7a08a498e41a0db4eaec91f373bdd2 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Fri, 18 Dec 2020 00:04:37 +0100 Subject: [PATCH] Profile editor - Changed data binding behaviour in profile editor --- .../Profile/DataBindings/DataBinding.cs | 22 ++++++++++++- .../Profile/LayerProperties/LayerProperty.cs | 10 ++---- .../DataBindings/DataBindingView.xaml | 21 ++++-------- .../DataBindings/DataBindingViewModel.cs | 33 ++----------------- 4 files changed, 34 insertions(+), 52 deletions(-) diff --git a/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs b/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs index 7a31710a4..0772ade79 100644 --- a/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs +++ b/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs @@ -6,10 +6,12 @@ namespace Artemis.Core /// public class DataBinding : IDataBinding { - private TProperty _currentValue = default!; private bool _disposed; private TimeSpan _easingProgress; + private bool _reapplyValue; + private TProperty _currentValue = default!; private TProperty _previousValue = default!; + private TProperty _lastAppliedValue = default!; internal DataBinding(DataBindingRegistration dataBindingRegistration) { @@ -114,6 +116,9 @@ namespace Artemis.Core _easingProgress = _easingProgress.Add(delta); if (_easingProgress > EasingTime) _easingProgress = EasingTime; + + // Tell Apply() to apply a new value next call + _reapplyValue = false; } private void ResetEasing(TProperty value) @@ -158,6 +163,11 @@ namespace Artemis.Core /// The timeline to apply during update public void Update(Timeline timeline) { + // Don't update data bindings if there is no delta, otherwise this creates an inconsistency between + // data bindings with easing and data bindings without easing (the ones with easing will seemingly not update) + if (timeline.Delta == TimeSpan.Zero) + return; + UpdateWithDelta(timeline.Delta); } @@ -170,9 +180,19 @@ namespace Artemis.Core if (Converter == null) return; + // If Update() has not been called, reapply the previous value + if (_reapplyValue) + { + Converter.ApplyValue(_lastAppliedValue); + return; + } + TProperty converterValue = Converter.GetValue(); TProperty value = GetValue(converterValue); Converter.ApplyValue(value); + + _lastAppliedValue = value; + _reapplyValue = true; } #region IDisposable diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs index a24807ead..6ccb85428 100644 --- a/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs +++ b/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs @@ -289,9 +289,9 @@ namespace Artemis.Core if (keyframeEntity.Position > ProfileElement.Timeline.Length) return null; T value = CoreJson.DeserializeObject(keyframeEntity.Value); - if (value == null) + if (value == null) return null; - + LayerPropertyKeyframe keyframe = new LayerPropertyKeyframe( CoreJson.DeserializeObject(keyframeEntity.Value)!, keyframeEntity.Position, (Easings.Functions) keyframeEntity.EasingFunction, this ); @@ -470,10 +470,6 @@ namespace Artemis.Core private void UpdateDataBindings(Timeline timeline) { - // To avoid data bindings applying at non-regular updating (during editing) only update when not overriden - if (timeline.IsOverridden) - return; - foreach (IDataBinding dataBinding in _dataBindings) { dataBinding.Update(timeline); @@ -543,7 +539,7 @@ namespace Artemis.Core _keyframes.Clear(); try { - foreach (KeyframeEntity keyframeEntity in Entity.KeyframeEntities.Where(k => k.Position <= ProfileElement.Timeline.Length)) + foreach (KeyframeEntity keyframeEntity in Entity.KeyframeEntities.Where(k => k.Position <= ProfileElement.Timeline.Length)) AddKeyframeEntity(keyframeEntity); } catch (JsonException) diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DataBindingView.xaml b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DataBindingView.xaml index 7fe5a0bfe..ef13d8f80 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DataBindingView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DataBindingView.xaml @@ -84,27 +84,20 @@ - - + + - - Test result + + Data binding result + + + Other data bindings not updating? - - Preview on layer - diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DataBindingViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DataBindingViewModel.cs index 76f1b24ce..3f8b67c94 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DataBindingViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DataBindingViewModel.cs @@ -15,7 +15,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings private readonly IDataBindingsVmFactory _dataBindingsVmFactory; private readonly IProfileEditorService _profileEditorService; private readonly Timer _updateTimer; - private bool _applyTestResultToLayer; private int _easingTime; private bool _isDataBindingEnabled; private bool _isEasingTimeEnabled; @@ -68,17 +67,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings get => _isDataBindingEnabled; set => SetAndNotify(ref _isDataBindingEnabled, value); } - - public bool ApplyTestResultToLayer - { - get => _applyTestResultToLayer; - set - { - if (!SetAndNotify(ref _applyTestResultToLayer, value)) return; - _profileEditorService.UpdateProfilePreview(); - } - } - + public TimelineEasingViewModel SelectedEasingViewModel { get => _selectedEasingViewModel; @@ -121,7 +110,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings _updateTimer.Start(); _updateTimer.Elapsed += OnUpdateTimerOnElapsed; - Registration.LayerProperty.Updated += LayerPropertyOnUpdated; CreateDataBindingModeModeViewModel(); Update(); @@ -239,15 +227,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings { TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(default) : default); } - - if (ApplyTestResultToLayer) - { - // TODO: A bit crappy, the ProfileEditorService should really be doing this - bool playing = ((Parent as Screen)?.Parent as LayerPropertiesViewModel)?.Playing ?? true; - if (!playing) - _profileEditorService.UpdateProfilePreview(); - } - + + _profileEditorService.UpdateProfilePreview(); _updatingTestResult = false; } @@ -276,12 +257,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings UpdateTestResult(); } - private void LayerPropertyOnUpdated(object sender, LayerPropertyEventArgs e) - { - if (ApplyTestResultToLayer) - Registration.DataBinding?.Apply(); - } - #region IDisposable /// @@ -289,8 +264,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings { _updateTimer.Dispose(); _updateTimer.Elapsed -= OnUpdateTimerOnElapsed; - - Registration.LayerProperty.Updated -= LayerPropertyOnUpdated; } #endregion