using System; using System.ComponentModel; using System.Linq; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract; using Stylet; namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline { public class TimelinePropertyGroupViewModel : PropertyChangedBase { private BindableCollection _timelineKeyframeViewModels; public TimelinePropertyGroupViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel) { LayerPropertyGroupViewModel = (LayerPropertyGroupViewModel) layerPropertyBaseViewModel; TimelineKeyframeViewModels = new BindableCollection(); LayerPropertyGroupViewModel.ProfileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged; LayerPropertyGroupViewModel.PropertyChanged += LayerPropertyGroupViewModelOnPropertyChanged; UpdateKeyframes(); } public LayerPropertyGroupViewModel LayerPropertyGroupViewModel { get; } public BindableCollection TimelineKeyframeViewModels { get => _timelineKeyframeViewModels; set => SetAndNotify(ref _timelineKeyframeViewModels, value); } public void UpdateKeyframes() { TimelineKeyframeViewModels.Clear(); TimelineKeyframeViewModels.AddRange(LayerPropertyGroupViewModel.GetKeyframes(false) .Select(k => LayerPropertyGroupViewModel.ProfileEditorService.PixelsPerSecond * k.Position.TotalSeconds)); } public void Dispose() { LayerPropertyGroupViewModel.ProfileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged; LayerPropertyGroupViewModel.PropertyChanged -= LayerPropertyGroupViewModelOnPropertyChanged; } private void LayerPropertyGroupViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(LayerPropertyGroupViewModel.IsExpanded)) UpdateKeyframes(); } private void ProfileEditorServiceOnPixelsPerSecondChanged(object sender, EventArgs e) { UpdateKeyframes(); } } }