1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Profile editor - Changed data binding behaviour in profile editor

This commit is contained in:
SpoinkyNL 2020-12-18 00:04:37 +01:00
parent 15759c9289
commit c885ae225c
4 changed files with 34 additions and 52 deletions

View File

@ -6,10 +6,12 @@ namespace Artemis.Core
/// <inheritdoc /> /// <inheritdoc />
public class DataBinding<TLayerProperty, TProperty> : IDataBinding public class DataBinding<TLayerProperty, TProperty> : IDataBinding
{ {
private TProperty _currentValue = default!;
private bool _disposed; private bool _disposed;
private TimeSpan _easingProgress; private TimeSpan _easingProgress;
private bool _reapplyValue;
private TProperty _currentValue = default!;
private TProperty _previousValue = default!; private TProperty _previousValue = default!;
private TProperty _lastAppliedValue = default!;
internal DataBinding(DataBindingRegistration<TLayerProperty, TProperty> dataBindingRegistration) internal DataBinding(DataBindingRegistration<TLayerProperty, TProperty> dataBindingRegistration)
{ {
@ -114,6 +116,9 @@ namespace Artemis.Core
_easingProgress = _easingProgress.Add(delta); _easingProgress = _easingProgress.Add(delta);
if (_easingProgress > EasingTime) if (_easingProgress > EasingTime)
_easingProgress = EasingTime; _easingProgress = EasingTime;
// Tell Apply() to apply a new value next call
_reapplyValue = false;
} }
private void ResetEasing(TProperty value) private void ResetEasing(TProperty value)
@ -158,6 +163,11 @@ namespace Artemis.Core
/// <param name="timeline">The timeline to apply during update</param> /// <param name="timeline">The timeline to apply during update</param>
public void Update(Timeline timeline) 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); UpdateWithDelta(timeline.Delta);
} }
@ -170,9 +180,19 @@ namespace Artemis.Core
if (Converter == null) if (Converter == null)
return; return;
// If Update() has not been called, reapply the previous value
if (_reapplyValue)
{
Converter.ApplyValue(_lastAppliedValue);
return;
}
TProperty converterValue = Converter.GetValue(); TProperty converterValue = Converter.GetValue();
TProperty value = GetValue(converterValue); TProperty value = GetValue(converterValue);
Converter.ApplyValue(value); Converter.ApplyValue(value);
_lastAppliedValue = value;
_reapplyValue = true;
} }
#region IDisposable #region IDisposable

View File

@ -289,9 +289,9 @@ namespace Artemis.Core
if (keyframeEntity.Position > ProfileElement.Timeline.Length) if (keyframeEntity.Position > ProfileElement.Timeline.Length)
return null; return null;
T value = CoreJson.DeserializeObject<T>(keyframeEntity.Value); T value = CoreJson.DeserializeObject<T>(keyframeEntity.Value);
if (value == null) if (value == null)
return null; return null;
LayerPropertyKeyframe<T> keyframe = new LayerPropertyKeyframe<T>( LayerPropertyKeyframe<T> keyframe = new LayerPropertyKeyframe<T>(
CoreJson.DeserializeObject<T>(keyframeEntity.Value)!, keyframeEntity.Position, (Easings.Functions) keyframeEntity.EasingFunction, this CoreJson.DeserializeObject<T>(keyframeEntity.Value)!, keyframeEntity.Position, (Easings.Functions) keyframeEntity.EasingFunction, this
); );
@ -470,10 +470,6 @@ namespace Artemis.Core
private void UpdateDataBindings(Timeline timeline) 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) foreach (IDataBinding dataBinding in _dataBindings)
{ {
dataBinding.Update(timeline); dataBinding.Update(timeline);
@ -543,7 +539,7 @@ namespace Artemis.Core
_keyframes.Clear(); _keyframes.Clear();
try 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); AddKeyframeEntity(keyframeEntity);
} }
catch (JsonException) catch (JsonException)

View File

@ -84,27 +84,20 @@
<materialDesign:Card Grid.Row="3" Grid.ColumnSpan="2" Margin="0 5 0 0"> <materialDesign:Card Grid.Row="3" Grid.ColumnSpan="2" Margin="0 5 0 0">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition /> <ColumnDefinition Width="Auto"/>
<ColumnDefinition /> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Margin="10 10 4 0"> <TextBlock Grid.Row="0" Margin="10 10 0 0">
Test result Data binding result
</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0 10 10 0" TextAlignment="Right" ToolTip="Click Play to ensure all other data bindings update as well." Cursor="Help">
Other data bindings not updating?
</TextBlock> </TextBlock>
<CheckBox Grid.Row="0"
Grid.Column="1"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Margin="0 6 10 0"
Style="{StaticResource MaterialDesignCheckBox}"
ToolTip="Apply the test value to the layer"
IsChecked="{Binding ApplyTestResultToLayer}">
Preview on layer
</CheckBox>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignLightSeparator}" Margin="0" /> <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignLightSeparator}" Margin="0" />
<Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="10 4 10 10"> <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="10 4 10 10">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>

View File

@ -15,7 +15,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
private readonly IDataBindingsVmFactory _dataBindingsVmFactory; private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
private readonly IProfileEditorService _profileEditorService; private readonly IProfileEditorService _profileEditorService;
private readonly Timer _updateTimer; private readonly Timer _updateTimer;
private bool _applyTestResultToLayer;
private int _easingTime; private int _easingTime;
private bool _isDataBindingEnabled; private bool _isDataBindingEnabled;
private bool _isEasingTimeEnabled; private bool _isEasingTimeEnabled;
@ -68,17 +67,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
get => _isDataBindingEnabled; get => _isDataBindingEnabled;
set => SetAndNotify(ref _isDataBindingEnabled, value); set => SetAndNotify(ref _isDataBindingEnabled, value);
} }
public bool ApplyTestResultToLayer
{
get => _applyTestResultToLayer;
set
{
if (!SetAndNotify(ref _applyTestResultToLayer, value)) return;
_profileEditorService.UpdateProfilePreview();
}
}
public TimelineEasingViewModel SelectedEasingViewModel public TimelineEasingViewModel SelectedEasingViewModel
{ {
get => _selectedEasingViewModel; get => _selectedEasingViewModel;
@ -121,7 +110,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
_updateTimer.Start(); _updateTimer.Start();
_updateTimer.Elapsed += OnUpdateTimerOnElapsed; _updateTimer.Elapsed += OnUpdateTimerOnElapsed;
Registration.LayerProperty.Updated += LayerPropertyOnUpdated;
CreateDataBindingModeModeViewModel(); CreateDataBindingModeModeViewModel();
Update(); Update();
@ -239,15 +227,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{ {
TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(default) : default); TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(default) : default);
} }
if (ApplyTestResultToLayer) _profileEditorService.UpdateProfilePreview();
{
// 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();
}
_updatingTestResult = false; _updatingTestResult = false;
} }
@ -276,12 +257,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
UpdateTestResult(); UpdateTestResult();
} }
private void LayerPropertyOnUpdated(object sender, LayerPropertyEventArgs<TLayerProperty> e)
{
if (ApplyTestResultToLayer)
Registration.DataBinding?.Apply();
}
#region IDisposable #region IDisposable
/// <inheritdoc /> /// <inheritdoc />
@ -289,8 +264,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{ {
_updateTimer.Dispose(); _updateTimer.Dispose();
_updateTimer.Elapsed -= OnUpdateTimerOnElapsed; _updateTimer.Elapsed -= OnUpdateTimerOnElapsed;
Registration.LayerProperty.Updated -= LayerPropertyOnUpdated;
} }
#endregion #endregion