diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/BaseLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/BaseLayerProperty.cs index a84a2e375..184415ff9 100644 --- a/src/Artemis.Core/Models/Profile/LayerProperties/BaseLayerProperty.cs +++ b/src/Artemis.Core/Models/Profile/LayerProperties/BaseLayerProperty.cs @@ -7,12 +7,14 @@ using Artemis.Core.Plugins.Models; using Artemis.Core.Utilities; using Artemis.Storage.Entities.Profile; using Newtonsoft.Json; +using Stylet; namespace Artemis.Core.Models.Profile.LayerProperties { - public abstract class BaseLayerProperty + public abstract class BaseLayerProperty : PropertyChangedBase { private object _baseValue; + private bool _isHidden; protected BaseLayerProperty(Layer layer, PluginInfo pluginInfo, BaseLayerProperty parent, string id, string name, string description, Type type) { @@ -118,6 +120,19 @@ namespace Artemis.Core.Models.Profile.LayerProperties /// public Type Type { get; protected set; } + /// + /// Gets or sets whether this property is hidden in the UI. + /// + public bool IsHidden + { + get => _isHidden; + set + { + _isHidden = value; + OnVisibilityChanged(); + } + } + /// /// Gets a list of keyframes defining different values of the property in time, this list contains the untyped /// . @@ -337,11 +352,23 @@ namespace Artemis.Core.Models.Profile.LayerProperties /// public event EventHandler ValueChanged; + /// + /// Occurs when this property or any of it's ancestors visibility is changed + /// + public event EventHandler VisibilityChanged; + protected virtual void OnValueChanged() { ValueChanged?.Invoke(this, EventArgs.Empty); } + protected virtual void OnVisibilityChanged() + { + VisibilityChanged?.Invoke(this, EventArgs.Empty); + foreach (var baseLayerProperty in Children) + baseLayerProperty.OnVisibilityChanged(); + } + #endregion } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs index 3be5e163d..cc4ef6b8f 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs @@ -45,7 +45,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties _layerPropertyViewModels = new List(); PixelsPerSecond = 31; - } + } public bool Playing { get; set; } public bool RepeatAfterLastKeyframe { get; set; } @@ -79,7 +79,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties _profileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected; _profileEditorService.CurrentTimeChanged += ProfileEditorServiceOnCurrentTimeChanged; - + base.OnInitialActivate(); } @@ -87,7 +87,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties { _profileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected; _profileEditorService.CurrentTimeChanged -= ProfileEditorServiceOnCurrentTimeChanged; - + if (_lastSelectedLayer != null) { _lastSelectedLayer.Properties.LayerPropertyRegistered -= LayerOnPropertyRegistered; @@ -106,7 +106,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties Pause(); base.OnDeactivate(); } - + private void ProfileEditorServiceOnProfileElementSelected(object sender, ProfileElementEventArgs e) { PopulateProperties(e.ProfileElement); diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs index 114997ef2..497e6f379 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs @@ -14,6 +14,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties private readonly IKernel _kernel; private readonly IProfileEditorService _profileEditorService; private bool _keyframesEnabled; + private bool _isExpanded; public LayerPropertyViewModel(BaseLayerProperty layerProperty, LayerPropertyViewModel parent, IKernel kernel, IProfileEditorService profileEditorService) { @@ -34,7 +35,15 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties public LayerPropertyViewModel Parent { get; } public List Children { get; } - public bool IsExpanded { get; set; } + public bool IsExpanded + { + get => _isExpanded; + set + { + _isExpanded = value; + OnExpandedStateChanged(); + } + } public bool KeyframesEnabled { @@ -75,5 +84,17 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties _profileEditorService.UpdateSelectedProfileElement(); } + + #region Events + + public event EventHandler ExpandedStateChanged; + protected virtual void OnExpandedStateChanged() + { + ExpandedStateChanged?.Invoke(this, EventArgs.Empty); + foreach (var layerPropertyViewModel in Children) + layerPropertyViewModel.OnExpandedStateChanged(); + } + + #endregion } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/PropertyTree/PropertyTreeView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/PropertyTree/PropertyTreeView.xaml index cb405f2f6..cfb33f63b 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/PropertyTree/PropertyTreeView.xaml +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/PropertyTree/PropertyTreeView.xaml @@ -87,6 +87,7 @@ diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/PropertyTrackView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/PropertyTrackView.xaml index 49825e4dc..497e47dff 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/PropertyTrackView.xaml +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/PropertyTrackView.xaml @@ -12,7 +12,7 @@ + Visibility="{Binding MustDisplay, Converter={StaticResource BoolToVisibilityConverter}}"> diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/PropertyTrackViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/PropertyTrackViewModel.cs index 67fad3f59..5c62a5cb5 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/PropertyTrackViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/PropertyTrackViewModel.cs @@ -19,12 +19,44 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline PopulateKeyframes(); UpdateKeyframes(PropertyTimelineViewModel.LayerPropertiesViewModel.PixelsPerSecond); + + LayerPropertyViewModel.ExpandedStateChanged += (sender, args) => UpdateMustDisplay(); + LayerPropertyViewModel.LayerProperty.VisibilityChanged += (sender, args) => UpdateMustDisplay(); + UpdateMustDisplay(); } public PropertyTimelineViewModel PropertyTimelineViewModel { get; } public LayerPropertyViewModel LayerPropertyViewModel { get; } public BindableCollection KeyframeViewModels { get; set; } + public bool MustDisplay { get; set; } + + private void UpdateMustDisplay() + { + var expandedTest = LayerPropertyViewModel.Parent; + while (expandedTest != null) + { + if (!expandedTest.IsExpanded) + { + MustDisplay = false; + return; + } + expandedTest = expandedTest.Parent; + } + + var visibilityTest = LayerPropertyViewModel.LayerProperty; + while (visibilityTest != null) + { + if (visibilityTest.IsHidden) + { + MustDisplay = false; + return; + } + visibilityTest = visibilityTest.Parent; + } + + MustDisplay = true; + } public void PopulateKeyframes() { diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs index 14bf9d89c..605320449 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs @@ -19,11 +19,18 @@ namespace Artemis.Plugins.LayerBrushes.Color { GradientTypeProperty = RegisterLayerProperty("Brush.GradientType", "Gradient type", "The type of color brush to draw", GradientType.Solid); GradientTypeProperty.CanUseKeyframes = false; + ColorProperty = RegisterLayerProperty("Brush.Color", "Color", "The color of the brush", new SKColor(255, 0, 0)); + GradientProperty = RegisterLayerProperty("Brush.Gradient", "Gradient", "The gradient of the brush", new ColorGradient()); + GradientProperty.CanUseKeyframes = false; + if (!GradientProperty.Value.Stops.Any()) + GradientProperty.Value.MakeFabulous(); UpdateColorProperties(); Layer.RenderPropertiesUpdated += (sender, args) => CreateShader(); GradientTypeProperty.ValueChanged += (sender, args) => UpdateColorProperties(); + ColorProperty.ValueChanged += (sender, args) => CreateShader(); + GradientProperty.Value.PropertyChanged += (sender, args) => CreateShader(); } public LayerProperty ColorProperty { get; set; } @@ -57,23 +64,9 @@ namespace Artemis.Plugins.LayerBrushes.Color private void UpdateColorProperties() { - if (GradientTypeProperty.Value == GradientType.Solid) - { - UnRegisterLayerProperty(GradientProperty); - ColorProperty = RegisterLayerProperty("Brush.Color", "Color", "The color of the brush", new SKColor(255, 0, 0)); - ColorProperty.ValueChanged += (sender, args) => CreateShader(); - } - else - { - UnRegisterLayerProperty(ColorProperty); - GradientProperty = RegisterLayerProperty("Brush.Gradient", "Gradient", "The gradient of the brush", new ColorGradient()); - GradientProperty.CanUseKeyframes = false; - GradientProperty.Value.PropertyChanged += (sender, args) => CreateShader(); - - if (!GradientProperty.Value.Stops.Any()) - GradientProperty.Value.MakeFabulous(); - } - + ColorProperty.IsHidden = GradientTypeProperty.Value != GradientType.Solid; + GradientProperty.IsHidden = GradientTypeProperty.Value == GradientType.Solid; + CreateShader(); } diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs index 81b8919c7..8bd35f190 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs @@ -30,11 +30,11 @@ namespace Artemis.Plugins.LayerBrushes.Noise _y = Rand.Next(0, 4096); _z = Rand.Next(0, 4096); _noise = new OpenSimplexNoise(Rand.Next(0, 4096)); + DetermineRenderScale(); ColorTypeProperty = RegisterLayerProperty("Brush.ColorType", "Color mapping type", "The way the noise is converted to colors", ColorMappingType.Simple); + ColorTypeProperty.CanUseKeyframes = false; ColorTypeProperty.ValueChanged += (sender, args) => UpdateColorProperties(); - UpdateColorProperties(); - ScaleProperty = RegisterLayerProperty("Brush.Scale", "Scale", "The scale of the noise.", new SKSize(100, 100)); ScaleProperty.MinInputValue = 0f; HardnessProperty = RegisterLayerProperty("Brush.Hardness", "Hardness", "The hardness of the noise, lower means there are gradients in the noise, higher means hard lines", 500f); @@ -47,8 +47,16 @@ namespace Artemis.Plugins.LayerBrushes.Noise AnimationSpeedProperty.MinInputValue = 0f; AnimationSpeedProperty.MaxInputValue = 64f; ScaleProperty.InputAffix = "%"; + MainColorProperty = RegisterLayerProperty("Brush.MainColor", "Main color", "The main color of the noise", new SKColor(255, 0, 0)); + SecondaryColorProperty = RegisterLayerProperty("Brush.SecondaryColor", "Secondary color", "The secondary color of the noise", new SKColor(0, 0, 255)); + GradientColorProperty = RegisterLayerProperty("Brush.GradientColor", "Noise gradient map", "The gradient the noise will map it's value to", new ColorGradient()); + GradientColorProperty.CanUseKeyframes = false; + if (!GradientColorProperty.Value.Stops.Any()) + GradientColorProperty.Value.MakeFabulous(); + GradientColorProperty.Value.PropertyChanged += CreateColorMap; - DetermineRenderScale(); + UpdateColorProperties(); + CreateColorMap(null, null); } @@ -64,25 +72,9 @@ namespace Artemis.Plugins.LayerBrushes.Noise private void UpdateColorProperties() { - if (GradientColorProperty != null) - GradientColorProperty.Value.PropertyChanged -= CreateColorMap; - if (ColorTypeProperty.Value == ColorMappingType.Simple) - { - UnRegisterLayerProperty(GradientColorProperty); - MainColorProperty = RegisterLayerProperty("Brush.MainColor", "Main color", "The main color of the noise", new SKColor(255, 0, 0)); - SecondaryColorProperty = RegisterLayerProperty("Brush.SecondaryColor", "Secondary color", "The secondary color of the noise", new SKColor(0, 0, 255)); - } - else - { - UnRegisterLayerProperty(MainColorProperty); - UnRegisterLayerProperty(SecondaryColorProperty); - GradientColorProperty = RegisterLayerProperty("Brush.GradientColor", "Noise gradient map", "The gradient the noise will map it's value to", new ColorGradient()); - if (!GradientColorProperty.Value.Stops.Any()) - GradientColorProperty.Value.MakeFabulous(); - - GradientColorProperty.Value.PropertyChanged += CreateColorMap; - CreateColorMap(null, null); - } + GradientColorProperty.IsHidden = ColorTypeProperty.Value != ColorMappingType.Gradient; + MainColorProperty.IsHidden = ColorTypeProperty.Value != ColorMappingType.Simple; + SecondaryColorProperty.IsHidden = ColorTypeProperty.Value != ColorMappingType.Simple; } public override void Update(double deltaTime) @@ -136,7 +128,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise else if (gradientColor != null && _colorMap.Length == 101) { var color = _colorMap[(int) Math.Round(alpha / 255f * 100, MidpointRounding.AwayFromZero)]; - _bitmap.SetPixel(x, y, new SKColor(color.Red, color.Green, color.Blue, 255)); + _bitmap.SetPixel(x, y, color); } } }