From 2c2b0ca3e185f77f6124f25b64ea7ed03cf80976 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 30 Jun 2020 20:41:46 +0200 Subject: [PATCH] UI - Removed Fody, begone arrogant devs! --- .../Services/Storage/ProfileService.cs | 3 + src/Artemis.UI/Artemis.UI.csproj | 5 - .../DataModelListViewModel.cs | 24 +++- .../DataModelViewModel.cs | 8 +- .../DataModelVisualizationViewModel.cs | 54 +++++++-- .../Ninject/Factories/IVMFactory.cs | 9 ++ .../BrushPropertyInputViewModel.cs | 7 +- .../SKSizePropertyInputViewModel.cs | 2 - .../Dialogs/ProfileCreateViewModel.cs | 8 +- .../ProfileEditor/Dialogs/RenameViewModel.cs | 9 +- .../Abstract/LayerPropertyBaseViewModel.cs | 17 ++- .../LayerEffects/EffectsViewModel.cs | 18 ++- .../LayerPropertiesViewModel.cs | 78 +++++++++++-- .../LayerPropertyGroupViewModel.cs | 31 +++-- .../LayerProperties/LayerPropertyViewModel.cs | 32 +++++- .../Timeline/TimelineEasingViewModel.cs | 23 ++-- .../Timeline/TimelineKeyframeViewModel.cs | 32 +++++- .../TimelinePropertyGroupViewModel.cs | 9 +- .../Timeline/TimelinePropertyViewModel.cs | 9 +- .../Timeline/TimelineViewModel.cs | 34 ++++-- .../Tree/TreePropertyViewModel.cs | 9 +- .../ProfileEditor/ProfileEditorViewModel.cs | 42 ++++++- .../ProfileTree/ProfileTreeViewModel.cs | 9 +- .../ProfileTree/TreeItem/TreeItemViewModel.cs | 36 ++++-- .../Visualization/CanvasViewModel.cs | 16 ++- .../Visualization/ProfileDeviceViewModel.cs | 24 +++- .../Visualization/ProfileLayerViewModel.cs | 54 +++++++-- .../Visualization/ProfileLedViewModel.cs | 41 ++++++- .../Visualization/ProfileViewModel.cs | 108 +++++++++++++----- .../Visualization/Tools/EditToolViewModel.cs | 23 +++- .../Tools/SelectionRemoveToolViewModel.cs | 8 +- .../Tools/SelectionToolViewModel.cs | 7 +- .../Tools/VisualizationToolViewModel.cs | 25 +++- src/Artemis.UI/Screens/RootViewModel.cs | 28 ++++- .../Settings/Debug/DeviceDebugViewModel.cs | 14 ++- .../Debug/Tabs/DataModelDebugViewModel.cs | 32 ++++-- .../Debug/Tabs/RenderDebugViewModel.cs | 25 ++-- .../Screens/Settings/SettingsViewModel.cs | 41 ++++++- .../Tabs/Devices/DeviceSettingsViewModel.cs | 20 +++- .../Tabs/Plugins/PluginSettingsViewModel.cs | 24 +++- .../Screens/Shared/PanZoomViewModel.cs | 67 +++++++++-- .../Screens/Sidebar/SidebarViewModel.cs | 23 +++- .../Screens/Splash/SplashViewModel.cs | 7 +- .../Dialogs/SurfaceCreateViewModel.cs | 8 +- .../Dialogs/SurfaceDeviceConfigViewModel.cs | 39 ++++++- .../SurfaceEditor/SurfaceEditorViewModel.cs | 51 +++++++-- .../Visualization/SurfaceDeviceViewModel.cs | 27 ++++- src/Artemis.UI/Screens/TrayViewModel.cs | 7 +- .../Screens/Workshop/WorkshopViewModel.cs | 16 ++- 49 files changed, 1011 insertions(+), 232 deletions(-) diff --git a/src/Artemis.Core/Services/Storage/ProfileService.cs b/src/Artemis.Core/Services/Storage/ProfileService.cs index cf62ff2f8..1d40e87ee 100644 --- a/src/Artemis.Core/Services/Storage/ProfileService.cs +++ b/src/Artemis.Core/Services/Storage/ProfileService.cs @@ -89,6 +89,9 @@ namespace Artemis.Core.Services.Storage public void ActivateProfile(ProfileModule module, Profile profile) { + if (module.ActiveProfile == profile) + return; + module.ChangeActiveProfile(profile, _surfaceService.ActiveSurface); if (profile != null) { diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index 57e6a4c77..ff6bbe51b 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -128,10 +128,6 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - @@ -141,7 +137,6 @@ - diff --git a/src/Artemis.UI/DataModelVisualization/DataModelListViewModel.cs b/src/Artemis.UI/DataModelVisualization/DataModelListViewModel.cs index 12dba6f05..885d4ce21 100644 --- a/src/Artemis.UI/DataModelVisualization/DataModelListViewModel.cs +++ b/src/Artemis.UI/DataModelVisualization/DataModelListViewModel.cs @@ -9,6 +9,10 @@ namespace Artemis.UI.DataModelVisualization { public class DataModelListViewModel : DataModelVisualizationViewModel { + private BindableCollection _children; + private IList _list; + private string _count; + public DataModelListViewModel(PropertyInfo propertyInfo, DataModelPropertyAttribute propertyDescription, DataModelVisualizationViewModel parent) { PropertyInfo = propertyInfo; @@ -17,9 +21,23 @@ namespace Artemis.UI.DataModelVisualization Children = new BindableCollection(); } - public BindableCollection Children { get; set; } - public IList List { get; set; } - public string Count { get; set; } + public BindableCollection Children + { + get => _children; + set => SetAndNotify(ref _children, value); + } + + public IList List + { + get => _list; + set => SetAndNotify(ref _list, value); + } + + public string Count + { + get => _count; + set => SetAndNotify(ref _count, value); + } public override void Update() { diff --git a/src/Artemis.UI/DataModelVisualization/DataModelViewModel.cs b/src/Artemis.UI/DataModelVisualization/DataModelViewModel.cs index d0bd30c2e..44868fa40 100644 --- a/src/Artemis.UI/DataModelVisualization/DataModelViewModel.cs +++ b/src/Artemis.UI/DataModelVisualization/DataModelViewModel.cs @@ -7,6 +7,8 @@ namespace Artemis.UI.DataModelVisualization { public class DataModelViewModel : DataModelVisualizationViewModel { + private BindableCollection _children; + public DataModelViewModel() { Children = new BindableCollection(); @@ -23,7 +25,11 @@ namespace Artemis.UI.DataModelVisualization PopulateProperties(); } - public BindableCollection Children { get; set; } + public BindableCollection Children + { + get => _children; + set => SetAndNotify(ref _children, value); + } public void PopulateProperties() { diff --git a/src/Artemis.UI/DataModelVisualization/DataModelVisualizationViewModel.cs b/src/Artemis.UI/DataModelVisualization/DataModelVisualizationViewModel.cs index 404584c05..791b1ca79 100644 --- a/src/Artemis.UI/DataModelVisualization/DataModelVisualizationViewModel.cs +++ b/src/Artemis.UI/DataModelVisualization/DataModelVisualizationViewModel.cs @@ -10,15 +10,55 @@ namespace Artemis.UI.DataModelVisualization { public abstract class DataModelVisualizationViewModel : PropertyChangedBase { - public DataModelPropertyAttribute PropertyDescription { get; protected set; } - public PropertyInfo PropertyInfo { get; protected set; } - public Type PropertyType { get; set; } + private DataModelPropertyAttribute _propertyDescription; + private PropertyInfo _propertyInfo; + private Type _propertyType; + private DataModelVisualizationViewModel _parent; + private object _model; + private bool _isListProperty; + private string _listDescription; - public DataModelVisualizationViewModel Parent { get; protected set; } - public object Model { get; set; } + public DataModelPropertyAttribute PropertyDescription + { + get => _propertyDescription; + protected set => SetAndNotify(ref _propertyDescription, value); + } - public bool IsListProperty { get; set; } - public string ListDescription { get; set; } + public PropertyInfo PropertyInfo + { + get => _propertyInfo; + protected set => SetAndNotify(ref _propertyInfo, value); + } + + public Type PropertyType + { + get => _propertyType; + set => SetAndNotify(ref _propertyType, value); + } + + public DataModelVisualizationViewModel Parent + { + get => _parent; + protected set => SetAndNotify(ref _parent, value); + } + + public object Model + { + get => _model; + set => SetAndNotify(ref _model, value); + } + + public bool IsListProperty + { + get => _isListProperty; + set => SetAndNotify(ref _isListProperty, value); + } + + public string ListDescription + { + get => _listDescription; + set => SetAndNotify(ref _listDescription, value); + } public abstract void Update(); diff --git a/src/Artemis.UI/Ninject/Factories/IVMFactory.cs b/src/Artemis.UI/Ninject/Factories/IVMFactory.cs index fc2119706..8eb699bbc 100644 --- a/src/Artemis.UI/Ninject/Factories/IVMFactory.cs +++ b/src/Artemis.UI/Ninject/Factories/IVMFactory.cs @@ -11,6 +11,7 @@ using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree; using Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem; using Artemis.UI.Screens.Module.ProfileEditor.Visualization; +using Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools; using Artemis.UI.Screens.Settings.Debug; using Artemis.UI.Screens.Settings.Tabs.Devices; using Artemis.UI.Screens.Settings.Tabs.Plugins; @@ -63,6 +64,14 @@ namespace Artemis.UI.Ninject.Factories ProfileLayerViewModel Create(Layer layer); } + public interface IVisualizationToolVmFactory : IVmFactory + { + ViewpointMoveToolViewModel ViewpointMoveToolViewModel(ProfileViewModel profileViewModel); + EditToolViewModel EditToolViewModel(ProfileViewModel profileViewModel); + SelectionToolViewModel SelectionToolViewModel(ProfileViewModel profileViewModel); + SelectionRemoveToolViewModel SelectionRemoveToolViewModel(ProfileViewModel profileViewModel); + } + public interface ILayerPropertyVmFactory : IVmFactory { LayerPropertyGroupViewModel LayerPropertyGroupViewModel(LayerPropertyGroup layerPropertyGroup, PropertyGroupDescriptionAttribute propertyGroupDescription); diff --git a/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs b/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs index aa8fe56e0..b6e2485bc 100644 --- a/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs +++ b/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs @@ -15,6 +15,7 @@ namespace Artemis.UI.PropertyInput { private readonly ILayerService _layerService; private readonly IPluginService _pluginService; + private List _descriptors; public BrushPropertyInputViewModel(LayerProperty layerProperty, IProfileEditorService profileEditorService, ILayerService layerService, IPluginService pluginService) : base(layerProperty, profileEditorService) @@ -27,7 +28,11 @@ namespace Artemis.UI.PropertyInput UpdateEnumValues(); } - public List Descriptors { get; set; } + public List Descriptors + { + get => _descriptors; + set => SetAndNotify(ref _descriptors, value); + } public LayerBrushDescriptor SelectedDescriptor { diff --git a/src/Artemis.UI/PropertyInput/SKSizePropertyInputViewModel.cs b/src/Artemis.UI/PropertyInput/SKSizePropertyInputViewModel.cs index b4f371222..84d1fef99 100644 --- a/src/Artemis.UI/PropertyInput/SKSizePropertyInputViewModel.cs +++ b/src/Artemis.UI/PropertyInput/SKSizePropertyInputViewModel.cs @@ -18,14 +18,12 @@ namespace Artemis.UI.PropertyInput } // Since SKSize is immutable we need to create properties that replace the SKSize entirely - // [DependsOn(nameof(InputValue))] public float Width { get => InputValue.Width; set => InputValue = new SKSize(value, Height); } - // [DependsOn(nameof(InputValue))] public float Height { get => InputValue.Height; diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Dialogs/ProfileCreateViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Dialogs/ProfileCreateViewModel.cs index 7fad3c749..2e7a38801 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Dialogs/ProfileCreateViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Dialogs/ProfileCreateViewModel.cs @@ -7,11 +7,17 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs { public class ProfileCreateViewModel : DialogViewModelBase { + private string _profileName; + public ProfileCreateViewModel(IModelValidator validator) : base(validator) { } - public string ProfileName { get; set; } + public string ProfileName + { + get => _profileName; + set => SetAndNotify(ref _profileName, value); + } public async Task Accept() { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Dialogs/RenameViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Dialogs/RenameViewModel.cs index a9965c513..c20b94793 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Dialogs/RenameViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Dialogs/RenameViewModel.cs @@ -7,6 +7,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs { public class RenameViewModel : DialogViewModelBase { + private string _elementName; + public RenameViewModel(IModelValidator validator, string subject, string currentName) : base(validator) { Subject = subject; @@ -14,7 +16,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs } public string Subject { get; } - public string ElementName { get; set; } + + public string ElementName + { + get => _elementName; + set => SetAndNotify(ref _elementName, value); + } public async Task Accept() { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Abstract/LayerPropertyBaseViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Abstract/LayerPropertyBaseViewModel.cs index cbd0e5766..75613d333 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Abstract/LayerPropertyBaseViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Abstract/LayerPropertyBaseViewModel.cs @@ -7,15 +7,28 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract { public abstract class LayerPropertyBaseViewModel : PropertyChangedBase, IDisposable { + private bool _isExpanded; + private List _children; + protected LayerPropertyBaseViewModel() { Children = new List(); } - public virtual bool IsExpanded { get; set; } public abstract bool IsVisible { get; } - public List Children { get; set; } + public virtual bool IsExpanded + { + get => _isExpanded; + set => SetAndNotify(ref _isExpanded, value); + } + + public List Children + { + get => _children; + set => SetAndNotify(ref _children, value); + } + public abstract void Dispose(); public abstract List GetKeyframes(bool expandedOnly); diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs index 3125d238b..07d2392a3 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs @@ -13,8 +13,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerEffects public class EffectsViewModel : PropertyChangedBase { private readonly ILayerService _layerService; - private readonly IProfileEditorService _profileEditorService; private readonly IPluginService _pluginService; + private readonly IProfileEditorService _profileEditorService; + private BindableCollection _layerEffectDescriptors; + private LayerEffectDescriptor _selectedLayerEffectDescriptor; public EffectsViewModel(LayerPropertiesViewModel layerPropertiesViewModel, IPluginService pluginService, ILayerService layerService, IProfileEditorService profileEditorService) { @@ -27,12 +29,20 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerEffects } public LayerPropertiesViewModel LayerPropertiesViewModel { get; } - - public BindableCollection LayerEffectDescriptors { get; set; } public bool HasLayerEffectDescriptors => LayerEffectDescriptors.Any(); - public LayerEffectDescriptor SelectedLayerEffectDescriptor { get; set; } + public BindableCollection LayerEffectDescriptors + { + get => _layerEffectDescriptors; + set => SetAndNotify(ref _layerEffectDescriptors, value); + } + public LayerEffectDescriptor SelectedLayerEffectDescriptor + { + get => _selectedLayerEffectDescriptor; + set => SetAndNotify(ref _selectedLayerEffectDescriptor, value); + } + public void PopulateDescriptors() { var layerBrushProviders = _pluginService.GetPluginsOfType(); diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs index 306f53bad..af491d14e 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs @@ -27,6 +27,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties { private readonly ILayerPropertyVmFactory _layerPropertyVmFactory; private LayerPropertyGroupViewModel _brushPropertyGroup; + private bool _repeatAfterLastKeyframe; + private int _propertyTreeIndex; + private PropertiesProfileElement _selectedPropertiesElement; + private BindableCollection _layerPropertyGroups; + private TreeViewModel _treeViewModel; + private EffectsViewModel _effectsViewModel; + private TimelineViewModel _timelineViewModel; + private bool _playing; public LayerPropertiesViewModel(IProfileEditorService profileEditorService, ICoreService coreService, ISettingsService settingsService, ILayerPropertyVmFactory layerPropertyVmFactory) @@ -46,8 +54,18 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties public ICoreService CoreService { get; } public ISettingsService SettingsService { get; } - public bool Playing { get; set; } - public bool RepeatAfterLastKeyframe { get; set; } + public bool Playing + { + get => _playing; + set => SetAndNotify(ref _playing, value); + } + + public bool RepeatAfterLastKeyframe + { + get => _repeatAfterLastKeyframe; + set => SetAndNotify(ref _repeatAfterLastKeyframe, value); + } + public string FormattedCurrentTime => $"{Math.Floor(ProfileEditorService.CurrentTime.TotalSeconds):00}.{ProfileEditorService.CurrentTime.Milliseconds:000}"; public Thickness TimeCaretPosition @@ -56,17 +74,55 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties set => ProfileEditorService.CurrentTime = TimeSpan.FromSeconds(value.Left / ProfileEditorService.PixelsPerSecond); } - public int PropertyTreeIndex { get; set; } + public int PropertyTreeIndex + { + get => _propertyTreeIndex; + set + { + if (!SetAndNotify(ref _propertyTreeIndex, value)) return; + NotifyOfPropertyChange(nameof(PropertyTreeVisible)); + } + } + public bool PropertyTreeVisible => PropertyTreeIndex == 0; - public PropertiesProfileElement SelectedPropertiesElement { get; set; } + public PropertiesProfileElement SelectedPropertiesElement + { + get => _selectedPropertiesElement; + set + { + if (!SetAndNotify(ref _selectedPropertiesElement, value)) return; + NotifyOfPropertyChange(nameof(SelectedLayer)); + NotifyOfPropertyChange(nameof(SelectedFolder)); + } + } + public Layer SelectedLayer => SelectedPropertiesElement as Layer; public Folder SelectedFolder => SelectedPropertiesElement as Folder; - public BindableCollection LayerPropertyGroups { get; set; } - public TreeViewModel TreeViewModel { get; set; } - public EffectsViewModel EffectsViewModel { get; set; } - public TimelineViewModel TimelineViewModel { get; set; } + public BindableCollection LayerPropertyGroups + { + get => _layerPropertyGroups; + set => SetAndNotify(ref _layerPropertyGroups, value); + } + + public TreeViewModel TreeViewModel + { + get => _treeViewModel; + set => SetAndNotify(ref _treeViewModel, value); + } + + public EffectsViewModel EffectsViewModel + { + get => _effectsViewModel; + set => SetAndNotify(ref _effectsViewModel, value); + } + + public TimelineViewModel TimelineViewModel + { + get => _timelineViewModel; + set => SetAndNotify(ref _timelineViewModel, value); + } protected override void OnInitialActivate() { @@ -116,8 +172,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties private void ProfileEditorServiceOnCurrentTimeChanged(object sender, EventArgs e) { - NotifyOfPropertyChange(() => FormattedCurrentTime); - NotifyOfPropertyChange(() => TimeCaretPosition); + NotifyOfPropertyChange(nameof(FormattedCurrentTime)); + NotifyOfPropertyChange(nameof(TimeCaretPosition)); } private void ProfileEditorServiceOnPixelsPerSecondChanged(object sender, EventArgs e) @@ -261,7 +317,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties var nonEffectProperties = LayerPropertyGroups.Where(l => l.GroupType != LayerEffectRoot).ToList(); // Order the effects var effectProperties = LayerPropertyGroups.Where(l => l.GroupType == LayerEffectRoot).OrderBy(l => l.LayerPropertyGroup.LayerEffect.Order).ToList(); - + // Put the non-effect properties in front for (var index = 0; index < nonEffectProperties.Count; index++) { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyGroupViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyGroupViewModel.cs index f2b8c18fc..34fbd6286 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyGroupViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyGroupViewModel.cs @@ -26,6 +26,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties } private readonly ILayerPropertyVmFactory _layerPropertyVmFactory; + private ViewModelType _groupType; + private TreePropertyGroupViewModel _treePropertyGroupViewModel; + private TimelinePropertyGroupViewModel _timelinePropertyGroupViewModel; public LayerPropertyGroupViewModel(LayerPropertyGroup layerPropertyGroup, PropertyGroupDescriptionAttribute propertyGroupDescription, IProfileEditorService profileEditorService, ILayerPropertyVmFactory layerPropertyVmFactory) @@ -44,22 +47,34 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties DetermineType(); } + public override bool IsVisible => !LayerPropertyGroup.IsHidden; + public IProfileEditorService ProfileEditorService { get; } + public LayerPropertyGroup LayerPropertyGroup { get; } + public PropertyGroupDescriptionAttribute PropertyGroupDescription { get; } + public override bool IsExpanded { get => LayerPropertyGroup.ProfileElement.IsPropertyGroupExpanded(LayerPropertyGroup); set => LayerPropertyGroup.ProfileElement.SetPropertyGroupExpanded(LayerPropertyGroup, value); } - public override bool IsVisible => !LayerPropertyGroup.IsHidden; - public ViewModelType GroupType { get; set; } + public ViewModelType GroupType + { + get => _groupType; + set => SetAndNotify(ref _groupType, value); + } - public IProfileEditorService ProfileEditorService { get; } + public TreePropertyGroupViewModel TreePropertyGroupViewModel + { + get => _treePropertyGroupViewModel; + set => SetAndNotify(ref _treePropertyGroupViewModel, value); + } - public LayerPropertyGroup LayerPropertyGroup { get; } - public PropertyGroupDescriptionAttribute PropertyGroupDescription { get; } - - public TreePropertyGroupViewModel TreePropertyGroupViewModel { get; set; } - public TimelinePropertyGroupViewModel TimelinePropertyGroupViewModel { get; set; } + public TimelinePropertyGroupViewModel TimelinePropertyGroupViewModel + { + get => _timelinePropertyGroupViewModel; + set => SetAndNotify(ref _timelinePropertyGroupViewModel, value); + } public override List GetKeyframes(bool expandedOnly) { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs index f0a727569..bb6aaf9c3 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs @@ -17,6 +17,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties { public class LayerPropertyViewModel : LayerPropertyViewModel { + private TreePropertyViewModel _treePropertyViewModel; + private TimelinePropertyViewModel _timelinePropertyViewModel; + public LayerPropertyViewModel(IProfileEditorService profileEditorService, LayerProperty layerProperty) : base(profileEditorService, layerProperty) { LayerProperty = layerProperty; @@ -44,8 +47,17 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties public LayerProperty LayerProperty { get; } - public TreePropertyViewModel TreePropertyViewModel { get; set; } - public TimelinePropertyViewModel TimelinePropertyViewModel { get; set; } + public TreePropertyViewModel TreePropertyViewModel + { + get => _treePropertyViewModel; + set => SetAndNotify(ref _treePropertyViewModel, value); + } + + public TimelinePropertyViewModel TimelinePropertyViewModel + { + get => _timelinePropertyViewModel; + set => SetAndNotify(ref _timelinePropertyViewModel, value); + } public override List GetKeyframes(bool expandedOnly) { @@ -102,6 +114,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties public abstract class LayerPropertyViewModel : LayerPropertyBaseViewModel { + private TreePropertyViewModel _treePropertyBaseViewModel; + private TimelinePropertyViewModel _timelinePropertyBaseViewModel; + protected LayerPropertyViewModel(IProfileEditorService profileEditorService, BaseLayerProperty baseLayerProperty) { ProfileEditorService = profileEditorService; @@ -111,7 +126,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties public IProfileEditorService ProfileEditorService { get; } public BaseLayerProperty BaseLayerProperty { get; } - public TreePropertyViewModel TreePropertyBaseViewModel { get; set; } - public TimelinePropertyViewModel TimelinePropertyBaseViewModel { get; set; } + public TreePropertyViewModel TreePropertyBaseViewModel + { + get => _treePropertyBaseViewModel; + set => SetAndNotify(ref _treePropertyBaseViewModel, value); + } + + public TimelinePropertyViewModel TimelinePropertyBaseViewModel + { + get => _timelinePropertyBaseViewModel; + set => SetAndNotify(ref _timelinePropertyBaseViewModel, value); + } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineEasingViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineEasingViewModel.cs index 8193f968a..1e787c13f 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineEasingViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineEasingViewModel.cs @@ -18,12 +18,18 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline EasingFunction = easingFunction; Description = easingFunction.Humanize(); - CreateEasingPoints(); + EasingPoints = new PointCollection(); + for (var i = 1; i <= 10; i++) + { + var x = i; + var y = Easings.Interpolate(i / 10.0, EasingFunction) * 10; + EasingPoints.Add(new Point(x, y)); + } } public Easings.Functions EasingFunction { get; } - public PointCollection EasingPoints { get; set; } - public string Description { get; set; } + public PointCollection EasingPoints { get; } + public string Description { get; } public bool IsEasingModeSelected { @@ -35,16 +41,5 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline _keyframeViewModel.SelectEasingMode(this); } } - - private void CreateEasingPoints() - { - EasingPoints = new PointCollection(); - for (var i = 1; i <= 10; i++) - { - var x = i; - var y = Easings.Interpolate(i / 10.0, EasingFunction) * 10; - EasingPoints.Add(new Point(x, y)); - } - } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineKeyframeViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineKeyframeViewModel.cs index 4545a2205..8e320fd77 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineKeyframeViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineKeyframeViewModel.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.Windows; using Artemis.Core.Models.Profile.LayerProperties; using Artemis.Core.Utilities; using Artemis.UI.Shared.Services.Interfaces; @@ -47,7 +46,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline public abstract class TimelineKeyframeViewModel : PropertyChangedBase { private readonly IProfileEditorService _profileEditorService; + private BindableCollection _easingViewModels; + private bool _isSelected; private int _pixelsPerSecond; + private string _timestamp; + private double _x; protected TimelineKeyframeViewModel(IProfileEditorService profileEditorService, BaseLayerPropertyKeyframe baseLayerPropertyKeyframe) { @@ -57,13 +60,30 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline } public BaseLayerPropertyKeyframe BaseLayerPropertyKeyframe { get; } - public BindableCollection EasingViewModels { get; set; } - public bool IsSelected { get; set; } - public double X { get; set; } - public string Timestamp { get; set; } + public BindableCollection EasingViewModels + { + get => _easingViewModels; + set => SetAndNotify(ref _easingViewModels, value); + } - public UIElement ParentView { get; set; } + public bool IsSelected + { + get => _isSelected; + set => SetAndNotify(ref _isSelected, value); + } + + public double X + { + get => _x; + set => SetAndNotify(ref _x, value); + } + + public string Timestamp + { + get => _timestamp; + set => SetAndNotify(ref _timestamp, value); + } public void Update(int pixelsPerSecond) { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelinePropertyGroupViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelinePropertyGroupViewModel.cs index 991f5a9e3..2a8a9578f 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelinePropertyGroupViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelinePropertyGroupViewModel.cs @@ -8,6 +8,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline { public class TimelinePropertyGroupViewModel : PropertyChangedBase { + private BindableCollection _timelineKeyframeViewModels; + public TimelinePropertyGroupViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel) { LayerPropertyGroupViewModel = (LayerPropertyGroupViewModel) layerPropertyBaseViewModel; @@ -19,7 +21,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline } public LayerPropertyGroupViewModel LayerPropertyGroupViewModel { get; } - public BindableCollection TimelineKeyframeViewModels { get; set; } + + public BindableCollection TimelineKeyframeViewModels + { + get => _timelineKeyframeViewModels; + set => SetAndNotify(ref _timelineKeyframeViewModels, value); + } public void UpdateKeyframes() { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelinePropertyViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelinePropertyViewModel.cs index afe080138..9b6ab74f9 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelinePropertyViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelinePropertyViewModel.cs @@ -65,6 +65,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline public abstract class TimelinePropertyViewModel : PropertyChangedBase, IDisposable { + private BindableCollection _timelineKeyframeViewModels; + protected TimelinePropertyViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel) { LayerPropertyBaseViewModel = layerPropertyBaseViewModel; @@ -72,7 +74,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline } public LayerPropertyBaseViewModel LayerPropertyBaseViewModel { get; } - public BindableCollection TimelineKeyframeViewModels { get; set; } + + public BindableCollection TimelineKeyframeViewModels + { + get => _timelineKeyframeViewModels; + set => SetAndNotify(ref _timelineKeyframeViewModels, value); + } public abstract void Dispose(); diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineViewModel.cs index 2a13b80ef..f8dd39b8e 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineViewModel.cs @@ -6,7 +6,6 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Shapes; -using Artemis.Core.Models.Profile.LayerProperties; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract; using Artemis.UI.Shared.Services.Interfaces; using Artemis.UI.Shared.Utilities; @@ -18,6 +17,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline { private readonly LayerPropertiesViewModel _layerPropertiesViewModel; private readonly IProfileEditorService _profileEditorService; + private RectangleGeometry _selectionRectangle; + private double _width; public TimelineViewModel(LayerPropertiesViewModel layerPropertiesViewModel, BindableCollection layerPropertyGroups, IProfileEditorService profileEditorService) @@ -32,8 +33,17 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline public BindableCollection LayerPropertyGroups { get; } - public double Width { get; set; } - public RectangleGeometry SelectionRectangle { get; set; } + public double Width + { + get => _width; + set => SetAndNotify(ref _width, value); + } + + public RectangleGeometry SelectionRectangle + { + get => _selectionRectangle; + set => SetAndNotify(ref _selectionRectangle, value); + } public void UpdateKeyframes() { @@ -60,7 +70,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline if (viewModel == null) return; - ((IInputElement)sender).CaptureMouse(); + ((IInputElement) sender).CaptureMouse(); if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) && !viewModel.IsSelected) SelectKeyframe(viewModel, true, false); else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) @@ -76,7 +86,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline _profileEditorService.UpdateSelectedProfileElement(); ReleaseSelectedKeyframes(); - ((IInputElement)sender).ReleaseMouseCapture(); + ((IInputElement) sender).ReleaseMouseCapture(); } public void KeyframeMouseMove(object sender, MouseEventArgs e) @@ -176,10 +186,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline if (e.LeftButton == MouseButtonState.Released) return; - ((IInputElement)sender).CaptureMouse(); + ((IInputElement) sender).CaptureMouse(); SelectionRectangle.Rect = new Rect(); - _mouseDragStartPoint = e.GetPosition((IInputElement)sender); + _mouseDragStartPoint = e.GetPosition((IInputElement) sender); _mouseDragging = true; e.Handled = true; } @@ -190,25 +200,25 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline if (!_mouseDragging) return; - var position = e.GetPosition((IInputElement)sender); + var position = e.GetPosition((IInputElement) sender); var selectedRect = new Rect(_mouseDragStartPoint, position); SelectionRectangle.Rect = selectedRect; var keyframeViewModels = GetAllKeyframeViewModels(); - var selectedKeyframes = HitTestUtilities.GetHitViewModels((Visual)sender, SelectionRectangle); + var selectedKeyframes = HitTestUtilities.GetHitViewModels((Visual) sender, SelectionRectangle); foreach (var keyframeViewModel in keyframeViewModels) keyframeViewModel.IsSelected = selectedKeyframes.Contains(keyframeViewModel); _mouseDragging = false; e.Handled = true; - ((IInputElement)sender).ReleaseMouseCapture(); + ((IInputElement) sender).ReleaseMouseCapture(); } public void TimelineCanvasMouseMove(object sender, MouseEventArgs e) { if (_mouseDragging && e.LeftButton == MouseButtonState.Pressed) { - var position = e.GetPosition((IInputElement)sender); + var position = e.GetPosition((IInputElement) sender); var selectedRect = new Rect(_mouseDragStartPoint, position); SelectionRectangle.Rect = selectedRect; e.Handled = true; @@ -264,7 +274,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline viewModels.AddRange(layerPropertyGroupViewModel.GetAllChildren()); var keyframes = viewModels.Where(vm => vm is LayerPropertyViewModel) - .SelectMany(vm => ((LayerPropertyViewModel)vm).TimelinePropertyBaseViewModel.TimelineKeyframeViewModels) + .SelectMany(vm => ((LayerPropertyViewModel) vm).TimelinePropertyBaseViewModel.TimelineKeyframeViewModels) .ToList(); return keyframes; diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Tree/TreePropertyViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Tree/TreePropertyViewModel.cs index b786a992a..c0470e579 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Tree/TreePropertyViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Tree/TreePropertyViewModel.cs @@ -9,9 +9,11 @@ using Stylet; namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree { + public class TreePropertyViewModel : TreePropertyViewModel { private readonly IProfileEditorService _profileEditorService; + private PropertyInputViewModel _propertyInputViewModel; public TreePropertyViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel, PropertyInputViewModel propertyInputViewModel, IProfileEditorService profileEditorService) : base(layerPropertyBaseViewModel) @@ -22,7 +24,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree } public LayerPropertyViewModel LayerPropertyViewModel { get; } - public PropertyInputViewModel PropertyInputViewModel { get; set; } + + public PropertyInputViewModel PropertyInputViewModel + { + get => _propertyInputViewModel; + set => SetAndNotify(ref _propertyInputViewModel, value); + } public bool KeyframesEnabled { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs index ffde0654a..383a4bccb 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs @@ -23,6 +23,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor private readonly IProfileEditorService _profileEditorService; private readonly IProfileService _profileService; private readonly ISettingsService _settingsService; + private BindableCollection _profiles; + private PluginSetting _sidePanelsWidth; + private PluginSetting _displayConditionsHeight; + private PluginSetting _bottomPanelsHeight; + private PluginSetting _elementPropertiesWidth; public ProfileEditorViewModel(ProfileModule module, ICollection viewModels, @@ -54,12 +59,36 @@ namespace Artemis.UI.Screens.Module.ProfileEditor public LayerPropertiesViewModel LayerPropertiesViewModel { get; } public ProfileTreeViewModel ProfileTreeViewModel { get; } public ProfileViewModel ProfileViewModel { get; } - public BindableCollection Profiles { get; set; } - public PluginSetting SidePanelsWidth { get; set; } - public PluginSetting DisplayConditionsHeight { get; set; } - public PluginSetting BottomPanelsHeight { get; set; } - public PluginSetting ElementPropertiesWidth { get; set; } + public BindableCollection Profiles + { + get => _profiles; + set => SetAndNotify(ref _profiles, value); + } + + public PluginSetting SidePanelsWidth + { + get => _sidePanelsWidth; + set => SetAndNotify(ref _sidePanelsWidth, value); + } + + public PluginSetting DisplayConditionsHeight + { + get => _displayConditionsHeight; + set => SetAndNotify(ref _displayConditionsHeight, value); + } + + public PluginSetting BottomPanelsHeight + { + get => _bottomPanelsHeight; + set => SetAndNotify(ref _bottomPanelsHeight, value); + } + + public PluginSetting ElementPropertiesWidth + { + get => _elementPropertiesWidth; + set => SetAndNotify(ref _elementPropertiesWidth, value); + } public Profile SelectedProfile { @@ -165,6 +194,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor if (_profileEditorService.SelectedProfile != profile) _profileEditorService.ChangeSelectedProfile(profile); + + NotifyOfPropertyChange(nameof(SelectedProfile)); + NotifyOfPropertyChange(nameof(CanDeleteActiveProfile)); } private void ModuleOnActiveProfileChanged(object sender, EventArgs e) diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/ProfileTreeViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/ProfileTreeViewModel.cs index e2a4c1145..032c410fd 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/ProfileTreeViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/ProfileTreeViewModel.cs @@ -15,6 +15,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree private readonly IProfileEditorService _profileEditorService; private TreeItemViewModel _selectedTreeItem; private bool _updatingTree; + private FolderViewModel _rootFolder; public ProfileTreeViewModel(IProfileEditorService profileEditorService, IFolderVmFactory folderVmFactory) { @@ -26,7 +27,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree _profileEditorService.ProfileElementSelected += OnProfileElementSelected; } - public FolderViewModel RootFolder { get; set; } + public FolderViewModel RootFolder + { + get => _rootFolder; + set => SetAndNotify(ref _rootFolder, value); + } public TreeItemViewModel SelectedTreeItem { @@ -34,7 +39,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree set { if (_updatingTree) return; - _selectedTreeItem = value; + SetAndNotify(ref _selectedTreeItem, value); _profileEditorService.ChangeSelectedProfileElement(value?.ProfileElement); } } diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/TreeItemViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/TreeItemViewModel.cs index c79e31070..d8c3718f5 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/TreeItemViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/TreeItemViewModel.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Artemis.Core.Models.Profile; @@ -20,6 +19,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem private readonly ILayerService _layerService; private readonly ILayerVmFactory _layerVmFactory; private readonly IProfileEditorService _profileEditorService; + private BindableCollection _children; + private TreeItemViewModel _parent; + private ProfileElement _profileElement; protected TreeItemViewModel(TreeItemViewModel parent, ProfileElement profileElement, @@ -42,11 +44,31 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem UpdateProfileElements(); } - public TreeItemViewModel Parent { get; set; } - public ProfileElement ProfileElement { get; set; } + public TreeItemViewModel Parent + { + get => _parent; + set => SetAndNotify(ref _parent, value); + } + + public ProfileElement ProfileElement + { + get => _profileElement; + set => SetAndNotify(ref _profileElement, value); + } + + public BindableCollection Children + { + get => _children; + set => SetAndNotify(ref _children, value); + } public abstract bool SupportsChildren { get; } - public BindableCollection Children { get; set; } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } public List GetAllChildren() { @@ -214,11 +236,5 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem { } } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/CanvasViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/CanvasViewModel.cs index 85a4686f6..2095e0fc0 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/CanvasViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/CanvasViewModel.cs @@ -5,8 +5,20 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization { public abstract class CanvasViewModel : PropertyChangedBase, IDisposable { - public double X { get; set; } - public double Y { get; set; } + private double _x; + private double _y; + + public double X + { + get => _x; + set => SetAndNotify(ref _x, value); + } + + public double Y + { + get => _y; + set => SetAndNotify(ref _y, value); + } protected virtual void Dispose(bool disposing) { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileDeviceViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileDeviceViewModel.cs index ac963eb58..4706628a9 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileDeviceViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileDeviceViewModel.cs @@ -9,6 +9,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization { public class ProfileDeviceViewModel : CanvasViewModel { + private ObservableCollection _leds; + private ArtemisDevice _device; + private bool _addedLeds; + public ProfileDeviceViewModel(ArtemisDevice device) { Device = device; @@ -17,9 +21,23 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization Task.Run(AddLedsAsync); } - public ObservableCollection Leds { get; set; } - public ArtemisDevice Device { get; set; } - public bool AddedLeds { get; private set; } + public ObservableCollection Leds + { + get => _leds; + set => SetAndNotify(ref _leds, value); + } + + public ArtemisDevice Device + { + get => _device; + set => SetAndNotify(ref _device, value); + } + + public bool AddedLeds + { + get => _addedLeds; + private set => SetAndNotify(ref _addedLeds, value); + } public new double X { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLayerViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLayerViewModel.cs index 0176879ac..385bbf096 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLayerViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLayerViewModel.cs @@ -20,6 +20,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization { private readonly ILayerEditorService _layerEditorService; private readonly IProfileEditorService _profileEditorService; + private Geometry _layerGeometry; + private Geometry _opacityGeometry; + private Geometry _shapeGeometry; + private RenderTargetBitmap _layerGeometryBitmap; + private Rect _viewportRectangle; + private bool _isSelected; public ProfileLayerViewModel(Layer layer, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService) { @@ -36,13 +42,47 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization public Layer Layer { get; } - public Geometry LayerGeometry { get; set; } - public Geometry OpacityGeometry { get; set; } - public Geometry ShapeGeometry { get; set; } - public RenderTargetBitmap LayerGeometryBitmap { get; set; } - public Rect ViewportRectangle { get; set; } + public Geometry LayerGeometry + { + get => _layerGeometry; + set => SetAndNotify(ref _layerGeometry, value); + } + + public Geometry OpacityGeometry + { + get => _opacityGeometry; + set => SetAndNotify(ref _opacityGeometry, value); + } + + public Geometry ShapeGeometry + { + get => _shapeGeometry; + set => SetAndNotify(ref _shapeGeometry, value); + } + + public RenderTargetBitmap LayerGeometryBitmap + { + get => _layerGeometryBitmap; + set => SetAndNotify(ref _layerGeometryBitmap, value); + } + + public Rect ViewportRectangle + { + get => _viewportRectangle; + set + { + if (!SetAndNotify(ref _viewportRectangle, value)) return; + NotifyOfPropertyChange(nameof(LayerPosition)); + } + } + public Thickness LayerPosition => new Thickness(ViewportRectangle.Left, ViewportRectangle.Top, 0, 0); - public bool IsSelected { get; set; } + + public bool IsSelected + { + get => _isSelected; + set => SetAndNotify(ref _isSelected, value); + } protected override void Dispose(bool disposing) { @@ -56,7 +96,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization base.Dispose(disposing); } - + private void Update() { IsSelected = _profileEditorService.SelectedProfileElement == Layer; diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedViewModel.cs index cd4eb55b8..c3b1cf972 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedViewModel.cs @@ -11,6 +11,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization { public class ProfileLedViewModel : PropertyChangedBase { + private bool _isSelected; + private bool _isDimmed; + private Geometry _displayGeometry; + private Geometry _strokeGeometry; + private Color _displayColor; + public ProfileLedViewModel(ArtemisLed led) { Led = led; @@ -26,17 +32,40 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization public ArtemisLed Led { get; } - public bool IsSelected { get; set; } - public bool IsDimmed { get; set; } - public double X { get; } public double Y { get; } public double Width { get; } public double Height { get; } - public Geometry DisplayGeometry { get; private set; } - public Geometry StrokeGeometry { get; private set; } - public Color DisplayColor { get; private set; } + public bool IsSelected + { + get => _isSelected; + set => SetAndNotify(ref _isSelected, value); + } + + public bool IsDimmed + { + get => _isDimmed; + set => SetAndNotify(ref _isDimmed, value); + } + + public Geometry DisplayGeometry + { + get => _displayGeometry; + private set => SetAndNotify(ref _displayGeometry, value); + } + + public Geometry StrokeGeometry + { + get => _strokeGeometry; + private set => SetAndNotify(ref _strokeGeometry, value); + } + + public Color DisplayColor + { + get => _displayColor; + private set => SetAndNotify(ref _displayColor, value); + } public void Update() { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileViewModel.cs index 64fc12dd7..6c859b5f6 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileViewModel.cs @@ -8,14 +8,12 @@ using Artemis.Core.Models.Profile; using Artemis.Core.Models.Surface; using Artemis.Core.Plugins.Models; using Artemis.Core.Services; -using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Storage.Interfaces; using Artemis.UI.Events; using Artemis.UI.Extensions; using Artemis.UI.Ninject.Factories; using Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools; using Artemis.UI.Screens.Shared; -using Artemis.UI.Services.Interfaces; using Artemis.UI.Shared.Services.Interfaces; using Stylet; @@ -23,30 +21,38 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization { public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle, IHandle { - private readonly ILayerEditorService _layerEditorService; - private readonly ILayerService _layerService; private readonly IProfileEditorService _profileEditorService; private readonly IProfileLayerVmFactory _profileLayerVmFactory; private readonly ISettingsService _settingsService; private readonly ISurfaceService _surfaceService; + private readonly IVisualizationToolVmFactory _visualizationToolVmFactory; + private int _activeToolIndex; private VisualizationToolViewModel _activeToolViewModel; + private bool _canApplyToLayer; + private bool _canSelectEditTool; + private BindableCollection _canvasViewModels; + private BindableCollection _devices; + private BindableCollection _highlightedLeds; + private PluginSetting _highlightSelectedLayer; + private bool _isInitializing; + private PluginSetting _onlyShowSelectedShape; + private PanZoomViewModel _panZoomViewModel; private Layer _previousSelectedLayer; private int _previousTool; + private BindableCollection _selectedLeds; public ProfileViewModel(IProfileEditorService profileEditorService, - ILayerEditorService layerEditorService, - ILayerService layerService, ISurfaceService surfaceService, ISettingsService settingsService, IEventAggregator eventAggregator, + IVisualizationToolVmFactory visualizationToolVmFactory, IProfileLayerVmFactory profileLayerVmFactory) { _profileEditorService = profileEditorService; - _layerEditorService = layerEditorService; - _layerService = layerService; _surfaceService = surfaceService; _settingsService = settingsService; + _visualizationToolVmFactory = visualizationToolVmFactory; _profileLayerVmFactory = profileLayerVmFactory; Execute.OnUIThreadSync(() => @@ -65,19 +71,59 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization eventAggregator.Subscribe(this); } + public bool IsInitializing + { + get => _isInitializing; + private set => SetAndNotify(ref _isInitializing, value); + } - public bool IsInitializing { get; private set; } - public bool CanSelectEditTool { get; set; } + public bool CanSelectEditTool + { + get => _canSelectEditTool; + set => SetAndNotify(ref _canSelectEditTool, value); + } - public PanZoomViewModel PanZoomViewModel { get; set; } + public PanZoomViewModel PanZoomViewModel + { + get => _panZoomViewModel; + set => SetAndNotify(ref _panZoomViewModel, value); + } - public BindableCollection CanvasViewModels { get; set; } - public BindableCollection Devices { get; set; } - public BindableCollection HighlightedLeds { get; set; } - public BindableCollection SelectedLeds { get; set; } + public BindableCollection CanvasViewModels + { + get => _canvasViewModels; + set => SetAndNotify(ref _canvasViewModels, value); + } - public PluginSetting OnlyShowSelectedShape { get; set; } - public PluginSetting HighlightSelectedLayer { get; set; } + public BindableCollection Devices + { + get => _devices; + set => SetAndNotify(ref _devices, value); + } + + public BindableCollection HighlightedLeds + { + get => _highlightedLeds; + set => SetAndNotify(ref _highlightedLeds, value); + } + + public BindableCollection SelectedLeds + { + get => _selectedLeds; + set => SetAndNotify(ref _selectedLeds, value); + } + + public PluginSetting OnlyShowSelectedShape + { + get => _onlyShowSelectedShape; + set => SetAndNotify(ref _onlyShowSelectedShape, value); + } + + public PluginSetting HighlightSelectedLayer + { + get => _highlightSelectedLayer; + set => SetAndNotify(ref _highlightSelectedLayer, value); + } public VisualizationToolViewModel ActiveToolViewModel { @@ -95,7 +141,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization } // Set the new tool - _activeToolViewModel = value; + SetAndNotify(ref _activeToolViewModel, value); // Add the new tool to the canvas if (_activeToolViewModel != null) { @@ -113,15 +159,17 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization get => _activeToolIndex; set { - if (_activeToolIndex != value) - { - _activeToolIndex = value; - ActivateToolByIndex(value); - NotifyOfPropertyChange(() => ActiveToolIndex); - } + if (!SetAndNotify(ref _activeToolIndex, value)) return; + ActivateToolByIndex(value); } } + public bool CanApplyToLayer + { + get => _canApplyToLayer; + set => SetAndNotify(ref _canApplyToLayer, value); + } + public List GetLedsInRectangle(Rect selectedRect) { return Devices.SelectMany(d => d.Leds) @@ -156,7 +204,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization OnlyShowSelectedShape.Save(); HighlightSelectedLayer.Save(); - foreach (var canvasViewModel in CanvasViewModels) + foreach (var canvasViewModel in CanvasViewModels) canvasViewModel.Dispose(); CanvasViewModels.Clear(); @@ -230,16 +278,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization switch (value) { case 0: - ActiveToolViewModel = new ViewpointMoveToolViewModel(this, _profileEditorService); + ActiveToolViewModel = _visualizationToolVmFactory.ViewpointMoveToolViewModel(this); break; case 1: - ActiveToolViewModel = new EditToolViewModel(this, _profileEditorService, _layerEditorService); + ActiveToolViewModel = _visualizationToolVmFactory.EditToolViewModel(this); break; case 2: - ActiveToolViewModel = new SelectionToolViewModel(this, _profileEditorService, _layerService); + ActiveToolViewModel = _visualizationToolVmFactory.SelectionToolViewModel(this); break; case 3: - ActiveToolViewModel = new SelectionRemoveToolViewModel(this, _profileEditorService); + ActiveToolViewModel = _visualizationToolVmFactory.SelectionRemoveToolViewModel(this); break; } @@ -282,8 +330,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization #region Context menu actions - public bool CanApplyToLayer { get; set; } - public void CreateLayer() { } diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs index 9da3a8a34..135bf9392 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs @@ -18,6 +18,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools private SKPoint _dragOffset; private SKPoint _dragStart; private SKPoint _topLeft; + private SKPath _shapePath; + private SKPoint _shapeAnchor; + private RectangleGeometry _shapeGeometry; public EditToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService) : base(profileViewModel, profileEditorService) @@ -32,9 +35,23 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools profileEditorService.ProfilePreviewUpdated += (sender, args) => Update(); } - public SKPath ShapePath { get; set; } - public SKPoint ShapeAnchor { get; set; } - public RectangleGeometry ShapeGeometry { get; set; } + public SKPath ShapePath + { + get => _shapePath; + set => SetAndNotify(ref _shapePath, value); + } + + public SKPoint ShapeAnchor + { + get => _shapeAnchor; + set => SetAndNotify(ref _shapeAnchor, value); + } + + public RectangleGeometry ShapeGeometry + { + get => _shapeGeometry; + set => SetAndNotify(ref _shapeGeometry, value); + } private void Update() { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionRemoveToolViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionRemoveToolViewModel.cs index 4f67376ad..e7f4050b5 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionRemoveToolViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionRemoveToolViewModel.cs @@ -10,6 +10,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools { public class SelectionRemoveToolViewModel : VisualizationToolViewModel { + private Rect _dragRectangle; + public SelectionRemoveToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService) { using (var stream = new MemoryStream(Resources.aero_pen_min)) @@ -18,7 +20,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools } } - public Rect DragRectangle { get; set; } + public Rect DragRectangle + { + get => _dragRectangle; + set => SetAndNotify(ref _dragRectangle, value); + } public override void MouseUp(object sender, MouseButtonEventArgs e) { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs index e6750bde0..988fc9304 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs @@ -12,6 +12,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools public class SelectionToolViewModel : VisualizationToolViewModel { private readonly ILayerService _layerService; + private Rect _dragRectangle; public SelectionToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerService layerService) : base(profileViewModel, profileEditorService) @@ -23,7 +24,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools } } - public Rect DragRectangle { get; set; } + public Rect DragRectangle + { + get => _dragRectangle; + set => SetAndNotify(ref _dragRectangle, value); + } public override void MouseUp(object sender, MouseButtonEventArgs e) { diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/VisualizationToolViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/VisualizationToolViewModel.cs index 6632c8a1f..c64ee4220 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/VisualizationToolViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/VisualizationToolViewModel.cs @@ -7,6 +7,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools { public abstract class VisualizationToolViewModel : CanvasViewModel { + private Cursor _cursor; + private bool _isMouseDown; + private Point _mouseDownStartPosition; + protected VisualizationToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) { // Not relevant for visualization tools as they overlay the entire canvas @@ -20,9 +24,24 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools public ProfileViewModel ProfileViewModel { get; } public IProfileEditorService ProfileEditorService { get; } - public Cursor Cursor { get; protected set; } - public bool IsMouseDown { get; protected set; } - public Point MouseDownStartPosition { get; protected set; } + + public Cursor Cursor + { + get => _cursor; + protected set => SetAndNotify(ref _cursor, value); + } + + public bool IsMouseDown + { + get => _isMouseDown; + protected set => SetAndNotify(ref _isMouseDown, value); + } + + public Point MouseDownStartPosition + { + get => _mouseDownStartPosition; + protected set => SetAndNotify(ref _mouseDownStartPosition, value); + } public virtual void MouseDown(object sender, MouseButtonEventArgs e) { diff --git a/src/Artemis.UI/Screens/RootViewModel.cs b/src/Artemis.UI/Screens/RootViewModel.cs index b47f68c9f..c65277578 100644 --- a/src/Artemis.UI/Screens/RootViewModel.cs +++ b/src/Artemis.UI/Screens/RootViewModel.cs @@ -24,11 +24,13 @@ namespace Artemis.UI.Screens private readonly ICoreService _coreService; private readonly IDebugService _debugService; private readonly IEventAggregator _eventAggregator; - private readonly ISettingsService _settingsService; private readonly ThemeWatcher _themeWatcher; private readonly Timer _titleUpdateTimer; private readonly PluginSetting _windowSize; private bool _lostFocus; + private bool _isSidebarVisible; + private bool _activeItemReady; + private string _windowTitle; public RootViewModel(IEventAggregator eventAggregator, SidebarViewModel sidebarViewModel, ISettingsService settingsService, ICoreService coreService, IDebugService debugService, ISnackbarMessageQueue snackbarMessageQueue) @@ -36,7 +38,6 @@ namespace Artemis.UI.Screens SidebarViewModel = sidebarViewModel; MainMessageQueue = snackbarMessageQueue; _eventAggregator = eventAggregator; - _settingsService = settingsService; _coreService = coreService; _debugService = debugService; @@ -55,10 +56,25 @@ namespace Artemis.UI.Screens } public SidebarViewModel SidebarViewModel { get; } - public ISnackbarMessageQueue MainMessageQueue { get; set; } - public bool IsSidebarVisible { get; set; } - public bool ActiveItemReady { get; set; } - public string WindowTitle { get; set; } + public ISnackbarMessageQueue MainMessageQueue { get; } + + public bool IsSidebarVisible + { + get => _isSidebarVisible; + set => SetAndNotify(ref _isSidebarVisible, value); + } + + public bool ActiveItemReady + { + get => _activeItemReady; + set => SetAndNotify(ref _activeItemReady, value); + } + + public string WindowTitle + { + get => _windowTitle; + set => SetAndNotify(ref _windowTitle, value); + } public void WindowDeactivated() { diff --git a/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugViewModel.cs b/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugViewModel.cs index ef3e83cd8..c88930c74 100644 --- a/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugViewModel.cs @@ -14,6 +14,7 @@ namespace Artemis.UI.Screens.Settings.Debug { private readonly IDeviceService _deviceService; private readonly IDialogService _dialogService; + private ArtemisLed _selectedLed; public DeviceDebugViewModel(ArtemisDevice device, IDeviceService deviceService, IDialogService dialogService) { @@ -22,11 +23,18 @@ namespace Artemis.UI.Screens.Settings.Debug Device = device; } - // [DependsOn(nameof(SelectedLed))] public List SelectedLeds => SelectedLed != null ? new List {SelectedLed} : null; - public ArtemisDevice Device { get; } - public ArtemisLed SelectedLed { get; set; } + + public ArtemisLed SelectedLed + { + get => _selectedLed; + set + { + if (!SetAndNotify(ref _selectedLed, value)) return; + NotifyOfPropertyChange(nameof(SelectedLeds)); + } + } public bool CanOpenImageDirectory => Device.RgbDevice.DeviceInfo.Image != null; diff --git a/src/Artemis.UI/Screens/Settings/Debug/Tabs/DataModelDebugViewModel.cs b/src/Artemis.UI/Screens/Settings/Debug/Tabs/DataModelDebugViewModel.cs index 8012db24d..f4f867571 100644 --- a/src/Artemis.UI/Screens/Settings/Debug/Tabs/DataModelDebugViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Debug/Tabs/DataModelDebugViewModel.cs @@ -16,6 +16,9 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs private readonly Timer _updateTimer; private bool _isModuleFilterEnabled; private Core.Plugins.Abstract.Module _selectedModule; + private DataModelViewModel _mainDataModel; + private string _propertySearch; + private List _modules; public DataModelDebugViewModel(IDataModelVisualizationService dataModelVisualizationService, IPluginService pluginService) { @@ -27,17 +30,30 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs DisplayName = "Data model"; } - public DataModelViewModel MainDataModel { get; set; } + public DataModelViewModel MainDataModel + { + get => _mainDataModel; + set => SetAndNotify(ref _mainDataModel, value); + } - public string PropertySearch { get; set; } - public List Modules { get; set; } + public string PropertySearch + { + get => _propertySearch; + set => SetAndNotify(ref _propertySearch, value); + } + + public List Modules + { + get => _modules; + set => SetAndNotify(ref _modules, value); + } public Core.Plugins.Abstract.Module SelectedModule { get => _selectedModule; set { - _selectedModule = value; + if (!SetAndNotify(ref _selectedModule, value)) return; GetDataModel(); } } @@ -47,8 +63,8 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs get => _isModuleFilterEnabled; set { - _isModuleFilterEnabled = value; - + SetAndNotify(ref _isModuleFilterEnabled, value); + if (!IsModuleFilterEnabled) SelectedModule = null; else @@ -75,8 +91,8 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs private void GetDataModel() { - MainDataModel = SelectedModule != null - ? _dataModelVisualizationService.GetPluginDataModelVisualization(SelectedModule) + MainDataModel = SelectedModule != null + ? _dataModelVisualizationService.GetPluginDataModelVisualization(SelectedModule) : _dataModelVisualizationService.GetMainDataModelVisualization(); } diff --git a/src/Artemis.UI/Screens/Settings/Debug/Tabs/RenderDebugViewModel.cs b/src/Artemis.UI/Screens/Settings/Debug/Tabs/RenderDebugViewModel.cs index 1e49ca628..b35d07865 100644 --- a/src/Artemis.UI/Screens/Settings/Debug/Tabs/RenderDebugViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Debug/Tabs/RenderDebugViewModel.cs @@ -4,7 +4,6 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using Artemis.Core.Events; using Artemis.Core.Services.Interfaces; -using Artemis.Core.Services.Storage.Interfaces; using SkiaSharp; using SkiaSharp.Views.WPF; using Stylet; @@ -14,20 +13,26 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs public class RenderDebugViewModel : Screen { private readonly ICoreService _coreService; - private readonly IRgbService _rgbService; - private readonly ISurfaceService _surfaceService; + private double _currentFps; + private ImageSource _currentFrame; - public RenderDebugViewModel(ICoreService coreService, IRgbService rgbService, ISurfaceService surfaceService) + public RenderDebugViewModel(ICoreService coreService) { _coreService = coreService; - _rgbService = rgbService; - _surfaceService = surfaceService; - DisplayName = "Rendering"; } - public ImageSource CurrentFrame { get; set; } - public double CurrentFps { get; set; } + public ImageSource CurrentFrame + { + get => _currentFrame; + set => SetAndNotify(ref _currentFrame, value); + } + + public double CurrentFps + { + get => _currentFps; + set => SetAndNotify(ref _currentFps, value); + } protected override void OnActivate() { @@ -47,7 +52,7 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs { Execute.PostToUIThread(() => { - if (e.BitmapBrush?.Bitmap == null) + if (e.BitmapBrush?.Bitmap == null || e.BitmapBrush.Bitmap.Pixels.Length == 0) return; if (!(CurrentFrame is WriteableBitmap writeableBitmap)) diff --git a/src/Artemis.UI/Screens/Settings/SettingsViewModel.cs b/src/Artemis.UI/Screens/Settings/SettingsViewModel.cs index 0535fe682..94cb43679 100644 --- a/src/Artemis.UI/Screens/Settings/SettingsViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/SettingsViewModel.cs @@ -29,6 +29,11 @@ namespace Artemis.UI.Screens.Settings private readonly ISettingsService _settingsService; private readonly IPluginSettingsVmFactory _pluginSettingsVmFactory; private readonly ISurfaceService _surfaceService; + private List> _targetFrameRates; + private List> _renderScales; + private List _sampleSizes; + private BindableCollection _deviceSettingsViewModels; + private BindableCollection _plugins; public SettingsViewModel(ISurfaceService surfaceService, IPluginService pluginService, IDialogService dialogService, IDebugService debugService, ISettingsService settingsService, IPluginSettingsVmFactory pluginSettingsVmFactory, IDeviceSettingsVmFactory deviceSettingsVmFactory) @@ -60,15 +65,39 @@ namespace Artemis.UI.Screens.Settings SampleSizes = new List {1, 9}; } - public List> TargetFrameRates { get; set; } - public List> RenderScales { get; set; } + public List> TargetFrameRates + { + get => _targetFrameRates; + set => SetAndNotify(ref _targetFrameRates, value); + } + + public List> RenderScales + { + get => _renderScales; + set => SetAndNotify(ref _renderScales, value); + } + + public List SampleSizes + { + get => _sampleSizes; + set => SetAndNotify(ref _sampleSizes, value); + } + + public BindableCollection DeviceSettingsViewModels + { + get => _deviceSettingsViewModels; + set => SetAndNotify(ref _deviceSettingsViewModels, value); + } + + public BindableCollection Plugins + { + get => _plugins; + set => SetAndNotify(ref _plugins, value); + } + public IEnumerable LogLevels { get; } public IEnumerable ColorSchemes { get; } - public List SampleSizes { get; set; } - public BindableCollection DeviceSettingsViewModels { get; set; } - public BindableCollection Plugins { get; set; } - public bool StartWithWindows { get => _settingsService.GetSetting("UI.AutoRun", false).Value; diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs index 95df6cd27..29036a008 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs @@ -10,14 +10,15 @@ using Stylet; namespace Artemis.UI.Screens.Settings.Tabs.Devices { - public class DeviceSettingsViewModel + public class DeviceSettingsViewModel : PropertyChangedBase { private readonly IDeviceService _deviceService; private readonly IDialogService _dialogService; private readonly IWindowManager _windowManager; private readonly IDeviceDebugVmFactory _deviceDebugVmFactory; + private bool _isDeviceEnabled; - public DeviceSettingsViewModel(ArtemisDevice device, IDeviceService deviceService, IDialogService dialogService, + public DeviceSettingsViewModel(ArtemisDevice device, IDeviceService deviceService, IDialogService dialogService, IWindowManager windowManager, IDeviceDebugVmFactory deviceDebugVmFactory) { _deviceService = deviceService; @@ -29,15 +30,22 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices Type = Device.RgbDevice.DeviceInfo.DeviceType.ToString().Humanize(); Name = Device.RgbDevice.DeviceInfo.Model; Manufacturer = Device.RgbDevice.DeviceInfo.Manufacturer; + + // TODO: Implement this bad boy IsDeviceEnabled = true; } public ArtemisDevice Device { get; } - public string Type { get; set; } - public string Name { get; set; } - public string Manufacturer { get; set; } - public bool IsDeviceEnabled { get; set; } + public string Type { get; } + public string Name { get; } + public string Manufacturer { get; } + + public bool IsDeviceEnabled + { + get => _isDeviceEnabled; + set => SetAndNotify(ref _isDeviceEnabled, value); + } public void IdentifyDevice() { diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs index 674495900..c3ccbfe55 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs @@ -17,6 +17,9 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins private readonly IPluginService _pluginService; private readonly ISnackbarMessageQueue _snackbarMessageQueue; private readonly IWindowManager _windowManager; + private Plugin _plugin; + private PluginInfo _pluginInfo; + private bool _enabling; public PluginSettingsViewModel(Plugin plugin, IWindowManager windowManager, IDialogService dialogService, IPluginService pluginService, ISnackbarMessageQueue snackbarMessageQueue) @@ -30,9 +33,24 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins _snackbarMessageQueue = snackbarMessageQueue; } - public Plugin Plugin { get; set; } - public PluginInfo PluginInfo { get; set; } - public bool Enabling { get; set; } + public Plugin Plugin + { + get => _plugin; + set => SetAndNotify(ref _plugin, value); + } + + public PluginInfo PluginInfo + { + get => _pluginInfo; + set => SetAndNotify(ref _pluginInfo, value); + } + + public bool Enabling + { + get => _enabling; + set => SetAndNotify(ref _enabling, value); + } + public PackIconKind Icon => GetIconKind(); public string Type => Plugin.GetType().BaseType?.Name ?? Plugin.GetType().Name; public bool CanOpenSettings => IsEnabled && Plugin.HasConfigurationViewModel; diff --git a/src/Artemis.UI/Screens/Shared/PanZoomViewModel.cs b/src/Artemis.UI/Screens/Shared/PanZoomViewModel.cs index fc2c15e17..446d0b3db 100644 --- a/src/Artemis.UI/Screens/Shared/PanZoomViewModel.cs +++ b/src/Artemis.UI/Screens/Shared/PanZoomViewModel.cs @@ -12,8 +12,29 @@ namespace Artemis.UI.Screens.Shared { public class PanZoomViewModel : PropertyChangedBase { - public Point? LastPanPosition { get; set; } - public double Zoom { get; set; } = 1; + private Point? _lastPanPosition; + private double _zoom = 1; + private double _panX; + private double _panY; + private double _canvasWidth; + private double _canvasHeight; + private bool _limitToZero; + + public Point? LastPanPosition + { + get => _lastPanPosition; + set => SetAndNotify(ref _lastPanPosition, value); + } + + public double Zoom + { + get => _zoom; + set + { + if (!SetAndNotify(ref _zoom, value)) return; + NotifyOfPropertyChange(nameof(ZoomPercentage)); + } + } public double ZoomPercentage { @@ -21,11 +42,43 @@ namespace Artemis.UI.Screens.Shared set => SetZoomFromPercentage(value); } - public double PanX { get; set; } - public double PanY { get; set; } - public double CanvasWidth { get; set; } - public double CanvasHeight { get; set; } - public bool LimitToZero { get; set; } + public double PanX + { + get => _panX; + set + { + if (!SetAndNotify(ref _panX, value)) return; + NotifyOfPropertyChange(nameof(BackgroundViewport)); + } + } + + public double PanY + { + get => _panY; + set + { + if (!SetAndNotify(ref _panY, value)) return; + NotifyOfPropertyChange(nameof(BackgroundViewport)); + } + } + + public double CanvasWidth + { + get => _canvasWidth; + set => SetAndNotify(ref _canvasWidth, value); + } + + public double CanvasHeight + { + get => _canvasHeight; + set => SetAndNotify(ref _canvasHeight, value); + } + + public bool LimitToZero + { + get => _limitToZero; + set => SetAndNotify(ref _limitToZero, value); + } public Rect BackgroundViewport => new Rect(PanX, PanY, 20, 20); diff --git a/src/Artemis.UI/Screens/Sidebar/SidebarViewModel.cs b/src/Artemis.UI/Screens/Sidebar/SidebarViewModel.cs index c98c8b165..0bb7decdf 100644 --- a/src/Artemis.UI/Screens/Sidebar/SidebarViewModel.cs +++ b/src/Artemis.UI/Screens/Sidebar/SidebarViewModel.cs @@ -24,6 +24,9 @@ namespace Artemis.UI.Screens.Sidebar private readonly IKernel _kernel; private readonly IModuleVmFactory _moduleVmFactory; private readonly IPluginService _pluginService; + private BindableCollection _sidebarItems; + private Dictionary _sidebarModules; + private IScreen _selectedItem; public SidebarViewModel(IKernel kernel, IEventAggregator eventAggregator, IModuleVmFactory moduleVmFactory, IPluginService pluginService) { @@ -41,9 +44,23 @@ namespace Artemis.UI.Screens.Sidebar eventAggregator.Subscribe(this); } - public BindableCollection SidebarItems { get; set; } - public Dictionary SidebarModules { get; set; } - public IScreen SelectedItem { get; set; } + public BindableCollection SidebarItems + { + get => _sidebarItems; + set => SetAndNotify(ref _sidebarItems, value); + } + + public Dictionary SidebarModules + { + get => _sidebarModules; + set => SetAndNotify(ref _sidebarModules, value); + } + + public IScreen SelectedItem + { + get => _selectedItem; + set => SetAndNotify(ref _selectedItem, value); + } public void SetupSidebar() { diff --git a/src/Artemis.UI/Screens/Splash/SplashViewModel.cs b/src/Artemis.UI/Screens/Splash/SplashViewModel.cs index 9a286719f..2ce1dd927 100644 --- a/src/Artemis.UI/Screens/Splash/SplashViewModel.cs +++ b/src/Artemis.UI/Screens/Splash/SplashViewModel.cs @@ -11,6 +11,7 @@ namespace Artemis.UI.Screens.Splash { private readonly ICoreService _coreService; private readonly IPluginService _pluginService; + private string _status; public SplashViewModel(ICoreService coreService, IPluginService pluginService) { @@ -19,7 +20,11 @@ namespace Artemis.UI.Screens.Splash Status = "Initializing Core"; } - public string Status { get; set; } + public string Status + { + get => _status; + set => SetAndNotify(ref _status, value); + } // ReSharper disable once UnusedMember.Global - Called from view public void MouseDown(object sender, MouseButtonEventArgs e) diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceCreateViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceCreateViewModel.cs index 870af2e86..92047c610 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceCreateViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceCreateViewModel.cs @@ -6,11 +6,17 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs { public class SurfaceCreateViewModel : DialogViewModelBase { + private string _surfaceName; + public SurfaceCreateViewModel(IModelValidator validator) : base(validator) { } - public string SurfaceName { get; set; } + public string SurfaceName + { + get => _surfaceName; + set => SetAndNotify(ref _surfaceName, value); + } public async Task Accept() { diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigViewModel.cs index d8c942332..e2d3cee0b 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigViewModel.cs @@ -9,6 +9,11 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs public class SurfaceDeviceConfigViewModel : DialogViewModelBase { private readonly ICoreService _coreService; + private string _title; + private int _x; + private int _y; + private double _scale; + private int _rotation; public SurfaceDeviceConfigViewModel(SurfaceDeviceViewModel surfaceDeviceViewModel, ICoreService coreService, IModelValidator validator) : base(validator) @@ -24,12 +29,36 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs } public SurfaceDeviceViewModel SurfaceDeviceViewModel { get; } - public string Title { get; set; } - public int X { get; set; } - public int Y { get; set; } - public double Scale { get; set; } - public int Rotation { get; set; } + public string Title + { + get => _title; + set => SetAndNotify(ref _title, value); + } + + public int X + { + get => _x; + set => SetAndNotify(ref _x, value); + } + + public int Y + { + get => _y; + set => SetAndNotify(ref _y, value); + } + + public double Scale + { + get => _scale; + set => SetAndNotify(ref _scale, value); + } + + public int Rotation + { + get => _rotation; + set => SetAndNotify(ref _rotation, value); + } public async Task Accept() { diff --git a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs index cd6ea0662..2a38a2cce 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs @@ -27,6 +27,13 @@ namespace Artemis.UI.Screens.SurfaceEditor private readonly IRgbService _rgbService; private readonly ISettingsService _settingsService; private readonly ISurfaceService _surfaceService; + private ArtemisSurface _selectedSurface; + private ObservableCollection _devices; + private ObservableCollection _surfaceConfigurations; + private RectangleGeometry _selectionRectangle; + private PanZoomViewModel _panZoomViewModel; + private PluginSetting _surfaceListWidth; + private Cursor _cursor; public SurfaceEditorViewModel(IRgbService rgbService, ISurfaceService surfaceService, IDialogService dialogService, ISettingsService settingsService, IDeviceService deviceService) @@ -46,12 +53,41 @@ namespace Artemis.UI.Screens.SurfaceEditor _deviceService = deviceService; } - public ObservableCollection Devices { get; set; } - public ObservableCollection SurfaceConfigurations { get; set; } - public RectangleGeometry SelectionRectangle { get; set; } - public PanZoomViewModel PanZoomViewModel { get; set; } - public PluginSetting SurfaceListWidth { get; set; } - public Cursor Cursor { get; set; } + public ObservableCollection Devices + { + get => _devices; + set => SetAndNotify(ref _devices, value); + } + + public ObservableCollection SurfaceConfigurations + { + get => _surfaceConfigurations; + set => SetAndNotify(ref _surfaceConfigurations, value); + } + + public RectangleGeometry SelectionRectangle + { + get => _selectionRectangle; + set => SetAndNotify(ref _selectionRectangle, value); + } + + public PanZoomViewModel PanZoomViewModel + { + get => _panZoomViewModel; + set => SetAndNotify(ref _panZoomViewModel, value); + } + + public PluginSetting SurfaceListWidth + { + get => _surfaceListWidth; + set => SetAndNotify(ref _surfaceListWidth, value); + } + + public Cursor Cursor + { + get => _cursor; + set => SetAndNotify(ref _cursor, value); + } public ArtemisSurface SelectedSurface { @@ -61,7 +97,7 @@ namespace Artemis.UI.Screens.SurfaceEditor if (value == null) return; - _selectedSurface = value; + SetAndNotify(ref _selectedSurface, value); ApplySelectedSurfaceConfiguration(); } } @@ -260,7 +296,6 @@ namespace Artemis.UI.Screens.SurfaceEditor private MouseDragStatus _mouseDragStatus; private Point _mouseDragStartPoint; - private ArtemisSurface _selectedSurface; // ReSharper disable once UnusedMember.Global - Called from view public void EditorGridMouseClick(object sender, MouseButtonEventArgs e) diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs index cf7b728a6..52a599c7c 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs @@ -10,15 +10,36 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization { private double _dragOffsetX; private double _dragOffsetY; + private ArtemisDevice _device; + private SelectionStatus _selectionStatus; + private Cursor _cursor; public SurfaceDeviceViewModel(ArtemisDevice device) { Device = device; } - public ArtemisDevice Device { get; set; } - public SelectionStatus SelectionStatus { get; set; } - public Cursor Cursor { get; set; } + public ArtemisDevice Device + { + get => _device; + set + { + if (SetAndNotify(ref _device, value)) return; + NotifyOfPropertyChange(nameof(DeviceRectangle)); + } + } + + public SelectionStatus SelectionStatus + { + get => _selectionStatus; + set => SetAndNotify(ref _selectionStatus, value); + } + + public Cursor Cursor + { + get => _cursor; + set => SetAndNotify(ref _cursor, value); + } public Rect DeviceRectangle => Device.RgbDevice == null ? new Rect() diff --git a/src/Artemis.UI/Screens/TrayViewModel.cs b/src/Artemis.UI/Screens/TrayViewModel.cs index cfd4bcb00..0831806b0 100644 --- a/src/Artemis.UI/Screens/TrayViewModel.cs +++ b/src/Artemis.UI/Screens/TrayViewModel.cs @@ -17,6 +17,7 @@ namespace Artemis.UI.Screens private readonly IWindowManager _windowManager; private bool _setGradientPickerService; private SplashViewModel _splashViewModel; + private bool _canShowRootViewModel; public TrayViewModel(IKernel kernel, IWindowManager windowManager, IEventAggregator eventAggregator, ICoreService coreService, ISettingsService settingsService) { @@ -34,7 +35,11 @@ namespace Artemis.UI.Screens } } - public bool CanShowRootViewModel { get; set; } + public bool CanShowRootViewModel + { + get => _canShowRootViewModel; + set => SetAndNotify(ref _canShowRootViewModel, value); + } public void TrayBringToForeground() { diff --git a/src/Artemis.UI/Screens/Workshop/WorkshopViewModel.cs b/src/Artemis.UI/Screens/Workshop/WorkshopViewModel.cs index 3fdbed069..98c8548f1 100644 --- a/src/Artemis.UI/Screens/Workshop/WorkshopViewModel.cs +++ b/src/Artemis.UI/Screens/Workshop/WorkshopViewModel.cs @@ -4,13 +4,25 @@ namespace Artemis.UI.Screens.Workshop { public class WorkshopViewModel : MainScreenViewModel { + private Color _testColor; + private bool _testPopupOpen; + public WorkshopViewModel() { DisplayName = "Workshop"; } - public Color TestColor { get; set; } - public bool TestPopupOpen { get; set; } + public Color TestColor + { + get => _testColor; + set => SetAndNotify(ref _testColor, value); + } + + public bool TestPopupOpen + { + get => _testPopupOpen; + set => SetAndNotify(ref _testPopupOpen, value); + } public void UpdateValues() {