Profile editor - Refactored a lot of VMs so they clean up nicely

This commit is contained in:
SpoinkyNL committed 2020-12-20 18:13:56 +01:00
1 parent 0dac4c7387
commit 4db66e1e3e
37 files changed
+531 -496

No files matched your search

@@ -17,9 +17,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{
_profileEditorService = profileEditorService;
_dataBindingsVmFactory = dataBindingsVmFactory;
_profileEditorService.SelectedDataBindingChanged += ProfileEditorServiceOnSelectedDataBindingChanged;
CreateDataBindingViewModels();
}
public int SelectedItemIndex
@@ -27,13 +24,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
get => _selectedItemIndex;
set => SetAndNotify(ref _selectedItemIndex, value);
}
protected override void OnClose()
{
_profileEditorService.SelectedDataBindingChanged -= ProfileEditorServiceOnSelectedDataBindingChanged;
base.OnClose();
}
private void CreateDataBindingViewModels()
{
Items.Clear();
@@ -48,7 +39,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
// and creating the actual data bindings
foreach (IDataBindingRegistration registration in registrations)
Items.Add(_dataBindingsVmFactory.DataBindingViewModel(registration));
SelectedItemIndex = 0;
}
@@ -56,5 +47,23 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{
CreateDataBindingViewModels();
}
#region Overrides of Screen
/// <inheritdoc />
protected override void OnInitialActivate()
{
_profileEditorService.SelectedDataBindingChanged += ProfileEditorServiceOnSelectedDataBindingChanged;
CreateDataBindingViewModels();
base.OnInitialActivate();
}
protected override void OnClose()
{
_profileEditorService.SelectedDataBindingChanged -= ProfileEditorServiceOnSelectedDataBindingChanged;
base.OnClose();
}
#endregion
}
}
@@ -23,11 +23,10 @@ using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
{
public class LayerPropertiesViewModel : Conductor<IScreen>.Collection.AllActive, IProfileEditorPanelViewModel, IDropTarget
public class LayerPropertiesViewModel : Conductor<LayerPropertyGroupViewModel>.Collection.AllActive, IProfileEditorPanelViewModel, IDropTarget
{
private readonly ILayerPropertyVmFactory _layerPropertyVmFactory;
private LayerPropertyGroupViewModel _brushPropertyGroup;
private bool _playing;
private bool _repeating;
private bool _repeatSegment;
private bool _repeatTimeline = true;
@@ -49,31 +48,27 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
CoreService = coreService;
SettingsService = settingsService;
LayerPropertyGroups = new BindableCollection<LayerPropertyGroupViewModel>();
PropertyChanged += HandlePropertyTreeIndexChanged;
// Left side
TreeViewModel = _layerPropertyVmFactory.TreeViewModel(this, LayerPropertyGroups);
TreeViewModel = _layerPropertyVmFactory.TreeViewModel(this, Items);
TreeViewModel.ConductWith(this);
EffectsViewModel = _layerPropertyVmFactory.EffectsViewModel(this);
Items.Add(TreeViewModel);
Items.Add(EffectsViewModel);
EffectsViewModel.ConductWith(this);
// Right side
StartTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.Start, LayerPropertyGroups);
MainTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.Main, LayerPropertyGroups);
EndTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.End, LayerPropertyGroups);
TimelineViewModel = _layerPropertyVmFactory.TimelineViewModel(this, LayerPropertyGroups);
StartTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.Start, Items);
StartTimelineSegmentViewModel.ConductWith(this);
MainTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.Main, Items);
MainTimelineSegmentViewModel.ConductWith(this);
EndTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.End, Items);
EndTimelineSegmentViewModel.ConductWith(this);
TimelineViewModel = _layerPropertyVmFactory.TimelineViewModel(this, Items);
TimelineViewModel.ConductWith(this);
DataBindingsViewModel = dataBindingsViewModel;
Items.Add(StartTimelineSegmentViewModel);
Items.Add(MainTimelineSegmentViewModel);
Items.Add(EndTimelineSegmentViewModel);
Items.Add(TimelineViewModel);
Items.Add(DataBindingsViewModel);
DataBindingsViewModel.ConductWith(this);
}
public BindableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
#region Child VMs
public TreeViewModel TreeViewModel { get; }
@@ -92,8 +87,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
public bool Playing
{
get => _playing;
set => SetAndNotify(ref _playing, value);
get => ProfileEditorService.Playing;
set
{
ProfileEditorService.Playing = value;
NotifyOfPropertyChange(nameof(Playing));
}
}
public bool Repeating
@@ -239,8 +238,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
public List<LayerPropertyGroupViewModel> GetAllLayerPropertyGroupViewModels()
{
List<LayerPropertyGroupViewModel> groups = LayerPropertyGroups.ToList();
List<LayerPropertyGroupViewModel> toAdd = groups.SelectMany(g => g.Children).Where(g => g is LayerPropertyGroupViewModel).Cast<LayerPropertyGroupViewModel>().ToList();
List<LayerPropertyGroupViewModel> groups = Items.ToList();
List<LayerPropertyGroupViewModel> toAdd = groups.SelectMany(g => g.Items).Where(g => g is LayerPropertyGroupViewModel).Cast<LayerPropertyGroupViewModel>().ToList();
groups.AddRange(toAdd);
return groups;
}
@@ -254,9 +253,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
SelectedLayer.LayerBrushUpdated -= SelectedLayerOnLayerBrushUpdated;
// Clear old properties
foreach (LayerPropertyGroupViewModel layerPropertyGroupViewModel in LayerPropertyGroups)
layerPropertyGroupViewModel.Dispose();
LayerPropertyGroups.Clear();
Items.Clear();
_brushPropertyGroup = null;
if (profileElement == null)
@@ -271,8 +268,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
SelectedLayer.LayerBrushUpdated += SelectedLayerOnLayerBrushUpdated;
// Add the built-in root groups of the layer
LayerPropertyGroups.Add(_layerPropertyVmFactory.LayerPropertyGroupViewModel(SelectedLayer.General));
LayerPropertyGroups.Add(_layerPropertyVmFactory.LayerPropertyGroupViewModel(SelectedLayer.Transform));
Items.Add(_layerPropertyVmFactory.LayerPropertyGroupViewModel(SelectedLayer.General));
Items.Add(_layerPropertyVmFactory.LayerPropertyGroupViewModel(SelectedLayer.Transform));
}
ApplyLayerBrush();
@@ -302,14 +299,14 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
if (_brushPropertyGroup != null)
{
LayerPropertyGroups.Remove(_brushPropertyGroup);
Items.Remove(_brushPropertyGroup);
_brushPropertyGroup = null;
}
if (SelectedLayer.LayerBrush != null)
{
_brushPropertyGroup = _layerPropertyVmFactory.LayerPropertyGroupViewModel(SelectedLayer.LayerBrush.BaseProperties);
LayerPropertyGroups.Add(_brushPropertyGroup);
Items.Add(_brushPropertyGroup);
}
SortProperties();
@@ -321,19 +318,19 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
return;
// Remove VMs of effects no longer applied on the layer
List<LayerPropertyGroupViewModel> toRemove = LayerPropertyGroups
List<LayerPropertyGroupViewModel> toRemove = Items
.Where(l => l.LayerPropertyGroup.LayerEffect != null && !SelectedProfileElement.LayerEffects.Contains(l.LayerPropertyGroup.LayerEffect))
.ToList();
LayerPropertyGroups.RemoveRange(toRemove);
Items.RemoveRange(toRemove);
foreach (LayerPropertyGroupViewModel layerPropertyGroupViewModel in toRemove)
layerPropertyGroupViewModel.Dispose();
layerPropertyGroupViewModel.RequestClose();
foreach (BaseLayerEffect layerEffect in SelectedProfileElement.LayerEffects)
{
if (LayerPropertyGroups.Any(l => l.LayerPropertyGroup.LayerEffect == layerEffect) || layerEffect.BaseProperties == null)
if (Items.Any(l => l.LayerPropertyGroup.LayerEffect == layerEffect) || layerEffect.BaseProperties == null)
continue;
LayerPropertyGroups.Add(_layerPropertyVmFactory.LayerPropertyGroupViewModel(layerEffect.BaseProperties));
Items.Add(_layerPropertyVmFactory.LayerPropertyGroupViewModel(layerEffect.BaseProperties));
}
SortProperties();
@@ -342,11 +339,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
private void SortProperties()
{
// Get all non-effect properties
List<LayerPropertyGroupViewModel> nonEffectProperties = LayerPropertyGroups
List<LayerPropertyGroupViewModel> nonEffectProperties = Items
.Where(l => l.TreeGroupViewModel.GroupType != LayerEffectRoot)
.ToList();
// Order the effects
List<LayerPropertyGroupViewModel> effectProperties = LayerPropertyGroups
List<LayerPropertyGroupViewModel> effectProperties = Items
.Where(l => l.TreeGroupViewModel.GroupType == LayerEffectRoot)
.OrderBy(l => l.LayerPropertyGroup.LayerEffect.Order)
.ToList();
@@ -355,14 +352,14 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
for (int index = 0; index < nonEffectProperties.Count; index++)
{
LayerPropertyGroupViewModel layerPropertyGroupViewModel = nonEffectProperties[index];
LayerPropertyGroups.Move(LayerPropertyGroups.IndexOf(layerPropertyGroupViewModel), index);
((BindableCollection<LayerPropertyGroupViewModel>) Items).Move(Items.IndexOf(layerPropertyGroupViewModel), index);
}
// Put the effect properties after, sorted by their order
for (int index = 0; index < effectProperties.Count; index++)
{
LayerPropertyGroupViewModel layerPropertyGroupViewModel = effectProperties[index];
LayerPropertyGroups.Move(LayerPropertyGroups.IndexOf(layerPropertyGroupViewModel), index + nonEffectProperties.Count);
((BindableCollection<LayerPropertyGroupViewModel>) Items).Move(Items.IndexOf(layerPropertyGroupViewModel), index + nonEffectProperties.Count);
}
}
@@ -424,22 +421,22 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
private void MoveBefore(LayerPropertyGroupViewModel source, LayerPropertyGroupViewModel target)
{
if (LayerPropertyGroups.IndexOf(target) == LayerPropertyGroups.IndexOf(source) + 1)
if (Items.IndexOf(target) == Items.IndexOf(source) + 1)
return;
LayerPropertyGroups.Move(LayerPropertyGroups.IndexOf(source), LayerPropertyGroups.IndexOf(target));
((BindableCollection<LayerPropertyGroupViewModel>) Items).Move(Items.IndexOf(source), Items.IndexOf(target));
}
private void MoveAfter(LayerPropertyGroupViewModel source, LayerPropertyGroupViewModel target)
{
LayerPropertyGroups.Remove(source);
LayerPropertyGroups.Insert(LayerPropertyGroups.IndexOf(target) + 1, source);
Items.Remove(source);
Items.Insert(Items.IndexOf(target) + 1, source);
}
private void ApplyCurrentEffectsOrder()
{
int order = 1;
foreach (LayerPropertyGroupViewModel groupViewModel in LayerPropertyGroups.Where(p => p.TreeGroupViewModel.GroupType == LayerEffectRoot))
foreach (LayerPropertyGroupViewModel groupViewModel in Items.Where(p => p.TreeGroupViewModel.GroupType == LayerEffectRoot))
{
groupViewModel.UpdateOrder(order);
order++;
@@ -530,7 +527,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
private TimeSpan CalculateEndTime()
{
List<ITimelineKeyframeViewModel> keyframeViewModels = LayerPropertyGroups.SelectMany(g => g.GetAllKeyframeViewModels(false)).ToList();
List<ITimelineKeyframeViewModel> keyframeViewModels = Items.SelectMany(g => g.GetAllKeyframeViewModels(false)).ToList();
// If there are no keyframes, don't stop at all
if (!keyframeViewModels.Any())
@@ -627,7 +624,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
// If holding down shift, snap to the closest segment or keyframe
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
{
List<TimeSpan> snapTimes = LayerPropertyGroups.SelectMany(g => g.GetAllKeyframeViewModels(true)).Select(k => k.Position).ToList();
List<TimeSpan> snapTimes = Items.SelectMany(g => g.GetAllKeyframeViewModels(true)).Select(k => k.Position).ToList();
TimeSpan snappedTime = ProfileEditorService.SnapToTimeline(newTime, TimeSpan.FromMilliseconds(1000f / ProfileEditorService.PixelsPerSecond * 5), true, false, snapTimes);
ProfileEditorService.CurrentTime = snappedTime;
return;
@@ -5,42 +5,53 @@ using Artemis.Core;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree;
using Artemis.UI.Shared.Services;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
{
public sealed class LayerPropertyGroupViewModel : PropertyChangedBase, IDisposable
public sealed class LayerPropertyGroupViewModel : Conductor<Screen>.Collection.AllActive
{
private readonly IProfileEditorService _profileEditorService;
private readonly ILayerPropertyVmFactory _layerPropertyVmFactory;
private bool _isVisible;
private TreeGroupViewModel _treeGroupViewModel;
private TimelineGroupViewModel _timelineGroupViewModel;
public LayerPropertyGroupViewModel(LayerPropertyGroup layerPropertyGroup, ILayerPropertyVmFactory layerPropertyVmFactory)
public LayerPropertyGroupViewModel(LayerPropertyGroup layerPropertyGroup, IProfileEditorService profileEditorService, ILayerPropertyVmFactory layerPropertyVmFactory)
{
_profileEditorService = profileEditorService;
_layerPropertyVmFactory = layerPropertyVmFactory;
LayerPropertyGroup = layerPropertyGroup;
Children = new BindableCollection<PropertyChangedBase>();
TreeGroupViewModel = layerPropertyVmFactory.TreeGroupViewModel(this);
TimelineGroupViewModel = layerPropertyVmFactory.TimelineGroupViewModel(this);
LayerPropertyGroup.VisibilityChanged += LayerPropertyGroupOnVisibilityChanged;
IsVisible = !LayerPropertyGroup.IsHidden;
PopulateChildren();
TreeGroupViewModel = _layerPropertyVmFactory.TreeGroupViewModel(this);
TreeGroupViewModel.ConductWith(this);
TimelineGroupViewModel = _layerPropertyVmFactory.TimelineGroupViewModel(this);
TimelineGroupViewModel.ConductWith(this);
}
public LayerPropertyGroup LayerPropertyGroup { get; }
public TreeGroupViewModel TreeGroupViewModel { get; }
public TimelineGroupViewModel TimelineGroupViewModel { get; }
public BindableCollection<PropertyChangedBase> Children { get; }
public TreeGroupViewModel TreeGroupViewModel
{
get => _treeGroupViewModel;
set => SetAndNotify(ref _treeGroupViewModel, value);
}
public TimelineGroupViewModel TimelineGroupViewModel
{
get => _timelineGroupViewModel;
set => SetAndNotify(ref _timelineGroupViewModel, value);
}
public bool IsVisible
{
get => _isVisible;
set => SetAndNotify(ref _isVisible, value);
}
public bool IsExpanded
{
get => LayerPropertyGroup.ProfileElement.IsPropertyGroupExpanded(LayerPropertyGroup);
@@ -51,25 +62,26 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
}
}
#region IDisposable
/// <inheritdoc />
public void Dispose()
protected override void OnInitialActivate()
{
TimelineGroupViewModel.Dispose();
LayerPropertyGroup.VisibilityChanged -= LayerPropertyGroupOnVisibilityChanged;
foreach (PropertyChangedBase child in Children)
{
if (child is IDisposable disposableChild)
disposableChild.Dispose();
}
LayerPropertyGroup.VisibilityChanged += LayerPropertyGroupOnVisibilityChanged;
PopulateChildren();
base.OnInitialActivate();
}
#endregion
protected override void OnClose()
{
LayerPropertyGroup.VisibilityChanged -= LayerPropertyGroupOnVisibilityChanged;
base.OnClose();
}
public void UpdateOrder(int order)
{
LayerPropertyGroup.LayerEffect.Order = order;
if (LayerPropertyGroup.LayerEffect != null)
LayerPropertyGroup.LayerEffect.Order = order;
NotifyOfPropertyChange(nameof(IsExpanded));
}
@@ -79,7 +91,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
if (expandedOnly && !IsExpanded)
return result;
foreach (PropertyChangedBase child in Children)
foreach (Screen child in Items)
{
if (child is LayerPropertyViewModel layerPropertyViewModel)
result.AddRange(layerPropertyViewModel.TimelinePropertyViewModel.GetAllKeyframeViewModels());
@@ -98,11 +110,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
/// <param name="end">The position at which to start removing keyframes, if null this will end at the last keyframe</param>
public void WipeKeyframes(TimeSpan? start, TimeSpan? end)
{
foreach (PropertyChangedBase child in Children)
foreach (Screen item in Items)
{
if (child is LayerPropertyViewModel layerPropertyViewModel)
if (item is LayerPropertyViewModel layerPropertyViewModel)
layerPropertyViewModel.TimelinePropertyViewModel.WipeKeyframes(start, end);
else if (child is LayerPropertyGroupViewModel layerPropertyGroupViewModel)
else if (item is LayerPropertyGroupViewModel layerPropertyGroupViewModel)
layerPropertyGroupViewModel.WipeKeyframes(start, end);
}
@@ -118,11 +130,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
/// <param name="amount">The amount to shift the keyframes for</param>
public void ShiftKeyframes(TimeSpan? start, TimeSpan? end, TimeSpan amount)
{
foreach (PropertyChangedBase child in Children)
foreach (Screen item in Items)
{
if (child is LayerPropertyViewModel layerPropertyViewModel)
if (item is LayerPropertyViewModel layerPropertyViewModel)
layerPropertyViewModel.TimelinePropertyViewModel.ShiftKeyframes(start, end, amount);
else if (child is LayerPropertyGroupViewModel layerPropertyGroupViewModel)
else if (item is LayerPropertyGroupViewModel layerPropertyGroupViewModel)
layerPropertyGroupViewModel.ShiftKeyframes(start, end, amount);
}
@@ -147,16 +159,13 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
// Create VMs for properties on the group
if (propertyAttribute != null && value is ILayerProperty layerProperty)
{
LayerPropertyViewModel layerPropertyViewModel = _layerPropertyVmFactory.LayerPropertyViewModel(layerProperty);
// After creation ensure a supported input VM was found, if not, discard the VM
if (!layerPropertyViewModel.TreePropertyViewModel.HasPropertyInputViewModel)
layerPropertyViewModel.Dispose();
else
Children.Add(layerPropertyViewModel);
// Ensure a supported input VM was found, otherwise don't add it
if (_profileEditorService.CanCreatePropertyInputViewModel(layerProperty))
Items.Add(_layerPropertyVmFactory.LayerPropertyViewModel(layerProperty));
}
// Create VMs for child groups on this group, resulting in a nested structure
else if (groupAttribute != null && value is LayerPropertyGroup layerPropertyGroup)
Children.Add(_layerPropertyVmFactory.LayerPropertyGroupViewModel(layerPropertyGroup));
Items.Add(_layerPropertyVmFactory.LayerPropertyGroupViewModel(layerPropertyGroup));
}
}
}
@@ -1,5 +1,4 @@
using System;
using Artemis.Core;
using Artemis.Core;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree;
@@ -7,23 +6,38 @@ using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
{
public sealed class LayerPropertyViewModel : PropertyChangedBase, IDisposable
public sealed class LayerPropertyViewModel : Screen
{
private bool _isVisible;
private bool _isHighlighted;
private bool _isExpanded;
private bool _isHighlighted;
private bool _isVisible;
private ITimelinePropertyViewModel _timelinePropertyViewModel;
private ITreePropertyViewModel _treePropertyViewModel;
public LayerPropertyViewModel(ILayerProperty layerProperty, IPropertyVmFactory propertyVmFactory)
{
LayerProperty = layerProperty;
TreePropertyViewModel = propertyVmFactory.TreePropertyViewModel(layerProperty, this);
TimelinePropertyViewModel = propertyVmFactory.TimelinePropertyViewModel(layerProperty, this);
TreePropertyViewModel = propertyVmFactory.TreePropertyViewModel(LayerProperty, this);
TreePropertyViewModel.ConductWith(this);
TimelinePropertyViewModel = propertyVmFactory.TimelinePropertyViewModel(LayerProperty, this);
TimelinePropertyViewModel.ConductWith(this);
}
public ILayerProperty LayerProperty { get; }
public ITreePropertyViewModel TreePropertyViewModel { get; }
public ITimelinePropertyViewModel TimelinePropertyViewModel { get; }
public ITreePropertyViewModel TreePropertyViewModel
{
get => _treePropertyViewModel;
set => SetAndNotify(ref _treePropertyViewModel, value);
}
public ITimelinePropertyViewModel TimelinePropertyViewModel
{
get => _timelinePropertyViewModel;
set => SetAndNotify(ref _timelinePropertyViewModel, value);
}
public bool IsVisible
{
@@ -42,11 +56,5 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
get => _isExpanded;
set => SetAndNotify(ref _isExpanded, value);
}
public void Dispose()
{
TreePropertyViewModel?.Dispose();
TimelinePropertyViewModel?.Dispose();
}
}
}
@@ -48,7 +48,7 @@
<Rectangle Grid.Row="1" HorizontalAlignment="Stretch" Fill="{DynamicResource MaterialDesignDivider}" Height="1" />
<ItemsControl Grid.Row="2"
ItemsSource="{Binding LayerPropertyGroupViewModel.Children}"
ItemsSource="{Binding LayerPropertyGroupViewModel.Items}"
Visibility="{Binding LayerPropertyGroupViewModel.IsExpanded, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch">
@@ -7,7 +7,7 @@ using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
{
public sealed class TimelineGroupViewModel : PropertyChangedBase, IDisposable
public sealed class TimelineGroupViewModel : Screen
{
private readonly IProfileEditorService _profileEditorService;
@@ -19,13 +19,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
LayerPropertyGroup = LayerPropertyGroupViewModel.LayerPropertyGroup;
KeyframePositions = new BindableCollection<double>();
_profileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
LayerPropertyGroupViewModel.PropertyChanged += LayerPropertyGroupViewModelOnPropertyChanged;
UpdateKeyframePositions();
UpdateKeyframePositions();
}
public LayerPropertyGroupViewModel LayerPropertyGroupViewModel { get; }
public LayerPropertyGroup LayerPropertyGroup { get; }
@@ -39,16 +35,26 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
.Select(p => p.Position.TotalSeconds * _profileEditorService.PixelsPerSecond));
}
#region IDisposable
#region Overrides of Screen
public void Dispose()
/// <inheritdoc />
protected override void OnInitialActivate()
{
_profileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
LayerPropertyGroupViewModel.PropertyChanged += LayerPropertyGroupViewModelOnPropertyChanged;
base.OnInitialActivate();
}
/// <inheritdoc />
protected override void OnClose()
{
_profileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
LayerPropertyGroupViewModel.PropertyChanged -= LayerPropertyGroupViewModelOnPropertyChanged;
base.OnClose();
}
#endregion
#region Event handlers
private void LayerPropertyGroupViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -20,12 +20,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
_profileEditorService = profileEditorService;
LayerPropertyKeyframe = layerPropertyKeyframe;
EasingViewModels = new BindableCollection<TimelineEasingViewModel>();
_profileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
LayerPropertyKeyframe.PropertyChanged += LayerPropertyKeyframeOnPropertyChanged;
}
public LayerPropertyKeyframe<T> LayerPropertyKeyframe { get; }
public BindableCollection<TimelineEasingViewModel> EasingViewModels { get; }
@@ -50,15 +46,29 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
public TimeSpan Position => LayerPropertyKeyframe.Position;
public ILayerPropertyKeyframe Keyframe => LayerPropertyKeyframe;
public void Dispose()
#region Overrides of Screen
protected override void OnInitialActivate()
{
_profileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
LayerPropertyKeyframe.PropertyChanged += LayerPropertyKeyframeOnPropertyChanged;
base.OnInitialActivate();
}
protected override void OnClose()
{
_profileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
LayerPropertyKeyframe.PropertyChanged -= LayerPropertyKeyframeOnPropertyChanged;
foreach (TimelineEasingViewModel timelineEasingViewModel in EasingViewModels)
timelineEasingViewModel.EasingModeSelected -= TimelineEasingViewModelOnEasingModeSelected;
base.OnClose();
}
#endregion
public void Update()
{
X = _profileEditorService.PixelsPerSecond * LayerPropertyKeyframe.Position.TotalSeconds;
@@ -159,7 +169,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
#endregion
#region Context menu actions
public void Delete(bool save = true)
{
LayerPropertyKeyframe.LayerProperty.RemoveKeyframe(LayerPropertyKeyframe);
@@ -170,7 +180,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
#endregion
}
public interface ITimelineKeyframeViewModel : IScreen, IDisposable
public interface ITimelineKeyframeViewModel : IScreen
{
bool IsSelected { get; set; }
TimeSpan Position { get; }
@@ -10,9 +10,7 @@
d:DesignHeight="450" d:DesignWidth="800"
HorizontalAlignment="Stretch">
<Border Height="25" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource MaterialDesignDivider}">
<ItemsControl ItemsSource="{Binding Items}"
Background="{DynamicResource MaterialDesignToolBarBackground}"
HorizontalAlignment="Left">
<ItemsControl ItemsSource="{Binding Items}" Background="{DynamicResource MaterialDesignToolBarBackground}" HorizontalAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
@@ -18,11 +18,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
LayerProperty = layerProperty;
LayerPropertyViewModel = layerPropertyViewModel;
LayerProperty.KeyframesToggled += LayerPropertyOnKeyframesToggled;
LayerProperty.KeyframeAdded += LayerPropertyOnKeyframeAdded;
LayerProperty.KeyframeRemoved += LayerPropertyOnKeyframeRemoved;
UpdateKeyframes();
}
public LayerProperty<T> LayerProperty { get; }
@@ -59,15 +54,27 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
List<LayerPropertyKeyframe<T>> toShift = LayerProperty.Keyframes.Where(k => k.Position > start && k.Position < end).ToList();
foreach (LayerPropertyKeyframe<T> keyframe in toShift)
keyframe.Position += amount;
UpdateKeyframes();
}
public void Dispose()
protected override void OnClose()
{
LayerProperty.KeyframesToggled -= LayerPropertyOnKeyframesToggled;
LayerProperty.KeyframeAdded -= LayerPropertyOnKeyframeAdded;
LayerProperty.KeyframeRemoved -= LayerPropertyOnKeyframeRemoved;
base.OnClose();
}
protected override void OnInitialActivate()
{
LayerProperty.KeyframesToggled += LayerPropertyOnKeyframesToggled;
LayerProperty.KeyframeAdded += LayerPropertyOnKeyframeAdded;
LayerProperty.KeyframeRemoved += LayerPropertyOnKeyframeRemoved;
UpdateKeyframes();
base.OnInitialActivate();
}
private void LayerPropertyOnKeyframesToggled(object sender, LayerPropertyEventArgs<T> e)
@@ -92,14 +99,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
if (LayerProperty.KeyframesEnabled)
{
List<LayerPropertyKeyframe<T>> keyframes = LayerProperty.Keyframes.ToList();
List<TimelineKeyframeViewModel<T>> toRemove = Items.Where(t => !keyframes.Contains(t.LayerPropertyKeyframe)).ToList();
foreach (TimelineKeyframeViewModel<T> timelineKeyframeViewModel in toRemove)
timelineKeyframeViewModel.Dispose();
Items.RemoveRange(toRemove);
Items.AddRange(keyframes
.Where(k => Items.All(t => t.LayerPropertyKeyframe != k))
.Select(k => new TimelineKeyframeViewModel<T>(k, _profileEditorService))
Items.RemoveRange(Items.Where(t => !keyframes.Contains(t.LayerPropertyKeyframe)).ToList());
Items.AddRange(
keyframes.Where(k => Items.All(t => t.LayerPropertyKeyframe != k)).Select(k => new TimelineKeyframeViewModel<T>(k, _profileEditorService))
);
}
else
@@ -110,7 +113,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
}
}
public interface ITimelinePropertyViewModel : IScreen, IDisposable
public interface ITimelinePropertyViewModel : IScreen
{
List<ITimelineKeyframeViewModel> GetAllKeyframeViewModels();
void WipeKeyframes(TimeSpan? start, TimeSpan? end);
@@ -14,7 +14,7 @@ using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
{
public sealed class TimelineSegmentViewModel : Screen, IDisposable
public sealed class TimelineSegmentViewModel : Screen
{
private readonly IDialogService _dialogService;
private bool _draggingSegment;
@@ -28,7 +28,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
private bool _showRepeatButton;
private bool _showSegmentName;
public TimelineSegmentViewModel(SegmentViewModelType segment, BindableCollection<LayerPropertyGroupViewModel> layerPropertyGroups,
public TimelineSegmentViewModel(SegmentViewModelType segment, IObservableCollection<LayerPropertyGroupViewModel> layerPropertyGroups,
IProfileEditorService profileEditorService, IDialogService dialogService)
{
_dialogService = dialogService;
@@ -43,18 +43,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
else if (Segment == SegmentViewModelType.End)
ToolTip = "This segment is played once a condition is no longer met";
IsMainSegment = Segment == SegmentViewModelType.Main;
ProfileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
ProfileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
if (ProfileEditorService.SelectedProfileElement != null)
ProfileEditorService.SelectedProfileElement.Timeline.PropertyChanged += TimelineOnPropertyChanged;
Update();
}
public RenderProfileElement SelectedProfileElement => ProfileEditorService.SelectedProfileElement;
public SegmentViewModelType Segment { get; }
public BindableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
public IObservableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
public IProfileEditorService ProfileEditorService { get; }
public string ToolTip { get; }
@@ -160,14 +153,28 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
layerPropertyGroupViewModel.ShiftKeyframes(start, end, amount);
}
#region IDIsposable
#region Overrides of Screen
public void Dispose()
/// <inheritdoc />
protected override void OnInitialActivate()
{
ProfileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
ProfileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
if (ProfileEditorService.SelectedProfileElement != null)
ProfileEditorService.SelectedProfileElement.Timeline.PropertyChanged += TimelineOnPropertyChanged;
Update();
base.OnInitialActivate();
}
/// <inheritdoc />
protected override void OnClose()
{
ProfileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
ProfileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected;
if (SelectedProfileElement != null)
SelectedProfileElement.Timeline.PropertyChanged -= TimelineOnPropertyChanged;
base.OnClose();
}
#endregion
@@ -11,33 +11,26 @@ using Artemis.Core;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Models;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.Models;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
{
public sealed class TimelineViewModel : Screen, IDisposable
public sealed class TimelineViewModel : Screen
{
private readonly IProfileEditorService _profileEditorService;
private RectangleGeometry _selectionRectangle;
public TimelineViewModel(LayerPropertiesViewModel layerPropertiesViewModel, BindableCollection<LayerPropertyGroupViewModel> layerPropertyGroups, IProfileEditorService profileEditorService)
public TimelineViewModel(LayerPropertiesViewModel layerPropertiesViewModel, IObservableCollection<LayerPropertyGroupViewModel> layerPropertyGroups, IProfileEditorService profileEditorService)
{
_profileEditorService = profileEditorService;
LayerPropertiesViewModel = layerPropertiesViewModel;
LayerPropertyGroups = layerPropertyGroups;
SelectionRectangle = new RectangleGeometry();
_profileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
_profileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
if (_profileEditorService.SelectedProfileElement != null)
_profileEditorService.SelectedProfileElement.Timeline.PropertyChanged += TimelineOnPropertyChanged;
Update();
}
public LayerPropertiesViewModel LayerPropertiesViewModel { get; }
public BindableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
public IObservableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
public RectangleGeometry SelectionRectangle
{
@@ -101,14 +94,27 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
Update();
}
#region IDisposable
#region Overrides of Screen
public void Dispose()
/// <inheritdoc />
protected override void OnInitialActivate()
{
_profileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
_profileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
if (_profileEditorService.SelectedProfileElement != null)
_profileEditorService.SelectedProfileElement.Timeline.PropertyChanged += TimelineOnPropertyChanged;
Update();
base.OnInitialActivate();
}
/// <inheritdoc />
protected override void OnClose()
{
_profileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
_profileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected;
if (_profileEditorService.SelectedProfileElement != null)
_profileEditorService.SelectedProfileElement.Timeline.PropertyChanged -= TimelineOnPropertyChanged;
base.OnClose();
}
#endregion
@@ -224,7 +224,7 @@
Do not bind directly to the LayerPropertyGroupViewModel.Children collection
Instead use a reference provided by the VM that is null when collapsed, virtualization for noobs
-->
<ItemsControl ItemsSource="{Binding Children}"
<ItemsControl ItemsSource="{Binding Items}"
Visibility="{Binding LayerPropertyGroupViewModel.IsExpanded, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
@@ -18,7 +18,7 @@ using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
{
public class TreeGroupViewModel : PropertyChangedBase
public class TreeGroupViewModel : Screen
{
public enum LayerPropertyGroupType
{
@@ -30,27 +30,18 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
}
private readonly IDialogService _dialogService;
private readonly IKernel _kernel;
private readonly IProfileEditorService _profileEditorService;
private readonly IWindowManager _windowManager;
public TreeGroupViewModel(
LayerPropertyGroupViewModel layerPropertyGroupViewModel,
IProfileEditorService profileEditorService,
IDialogService dialogService,
IWindowManager windowManager,
IKernel kernel)
public TreeGroupViewModel(LayerPropertyGroupViewModel layerPropertyGroupViewModel, IProfileEditorService profileEditorService, IDialogService dialogService, IWindowManager windowManager)
{
_profileEditorService = profileEditorService;
_dialogService = dialogService;
_windowManager = windowManager;
_kernel = kernel;
LayerPropertyGroupViewModel = layerPropertyGroupViewModel;
LayerPropertyGroup = LayerPropertyGroupViewModel.LayerPropertyGroup;
LayerPropertyGroupViewModel.PropertyChanged += LayerPropertyGroupViewModelOnPropertyChanged;
DetermineGroupType();
}
@@ -58,10 +49,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
public LayerPropertyGroup LayerPropertyGroup { get; }
public LayerPropertyGroupType GroupType { get; set; }
public BindableCollection<PropertyChangedBase> Children =>
LayerPropertyGroupViewModel.IsExpanded && LayerPropertyGroupViewModel.IsVisible
? LayerPropertyGroupViewModel.Children
: null;
public IObservableCollection<Screen> Items => LayerPropertyGroupViewModel.IsExpanded &&
LayerPropertyGroupViewModel.IsVisible
? LayerPropertyGroupViewModel.Items
: null;
public void OpenBrushSettings()
{
@@ -164,7 +155,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
private void LayerPropertyGroupViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(LayerPropertyGroupViewModel.IsExpanded) || e.PropertyName == nameof(LayerPropertyGroupViewModel.IsVisible))
NotifyOfPropertyChange(nameof(Children));
NotifyOfPropertyChange(nameof(Items));
}
private void DetermineGroupType()
@@ -180,5 +171,23 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
else
GroupType = LayerPropertyGroupType.None;
}
#region Overrides of Screen
/// <inheritdoc />
protected override void OnInitialActivate()
{
LayerPropertyGroupViewModel.PropertyChanged += LayerPropertyGroupViewModelOnPropertyChanged;
base.OnInitialActivate();
}
/// <inheritdoc />
protected override void OnClose()
{
LayerPropertyGroupViewModel.PropertyChanged -= LayerPropertyGroupViewModelOnPropertyChanged;
base.OnClose();
}
#endregion
}
}
@@ -19,12 +19,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
LayerPropertyViewModel = layerPropertyViewModel;
PropertyInputViewModel = _profileEditorService.CreatePropertyInputViewModel(LayerProperty);
_profileEditorService.SelectedDataBindingChanged += ProfileEditorServiceOnSelectedDataBindingChanged;
LayerProperty.VisibilityChanged += LayerPropertyOnVisibilityChanged;
LayerProperty.DataBindingEnabled += LayerPropertyOnDataBindingChange;
LayerProperty.DataBindingDisabled += LayerPropertyOnDataBindingChange;
LayerProperty.KeyframesToggled += LayerPropertyOnKeyframesToggled;
LayerPropertyViewModel.IsVisible = !LayerProperty.IsHidden;
PropertyInputViewModel.ConductWith(this);
}
public LayerProperty<T> LayerProperty { get; }
@@ -89,19 +84,30 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
return depth;
}
#region Overrides of Screen
public bool HasPropertyInputViewModel => PropertyInputViewModel != null;
/// <inheritdoc />
protected override void OnInitialActivate()
{
_profileEditorService.SelectedDataBindingChanged += ProfileEditorServiceOnSelectedDataBindingChanged;
LayerProperty.VisibilityChanged += LayerPropertyOnVisibilityChanged;
LayerProperty.DataBindingEnabled += LayerPropertyOnDataBindingChange;
LayerProperty.DataBindingDisabled += LayerPropertyOnDataBindingChange;
LayerProperty.KeyframesToggled += LayerPropertyOnKeyframesToggled;
LayerPropertyViewModel.IsVisible = !LayerProperty.IsHidden;
base.OnInitialActivate();
}
#region IDisposable
public void Dispose()
/// <inheritdoc />
protected override void OnClose()
{
_propertyInputViewModel?.Dispose();
_profileEditorService.SelectedDataBindingChanged -= ProfileEditorServiceOnSelectedDataBindingChanged;
LayerProperty.VisibilityChanged -= LayerPropertyOnVisibilityChanged;
LayerProperty.DataBindingEnabled -= LayerPropertyOnDataBindingChange;
LayerProperty.DataBindingDisabled -= LayerPropertyOnDataBindingChange;
LayerProperty.KeyframesToggled -= LayerPropertyOnKeyframesToggled;
base.OnClose();
}
#endregion
@@ -131,9 +137,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
#endregion
}
public interface ITreePropertyViewModel : IScreen, IDisposable
public interface ITreePropertyViewModel : IScreen
{
bool HasPropertyInputViewModel { get; }
bool HasDataBinding { get; }
double GetDepth();
}
@@ -7,7 +7,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
{
public class TreeViewModel : Screen
{
public TreeViewModel(LayerPropertiesViewModel layerPropertiesViewModel, BindableCollection<LayerPropertyGroupViewModel> layerPropertyGroups)
public TreeViewModel(LayerPropertiesViewModel layerPropertiesViewModel, IObservableCollection<LayerPropertyGroupViewModel> layerPropertyGroups)
{
LayerPropertiesViewModel = layerPropertiesViewModel;
@@ -16,7 +16,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
}
public LayerPropertiesViewModel LayerPropertiesViewModel { get; }
public BindableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
public IObservableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
public void PropertyTreePreviewMouseWheel(object sender, MouseWheelEventArgs e)
{