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

Profile editor - Finished most of the refactor except databindings

This commit is contained in:
SpoinkyNL 2020-09-14 01:24:07 +02:00
parent 7fff1a593f
commit fea454ad12
56 changed files with 866 additions and 459 deletions

View File

@ -23,6 +23,7 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Clayerproperties_005Ctypes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Clayershapes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Csurface/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=placeholders/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=plugins/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=plugins_005Cdatamodelexpansions_005Cattributes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=plugins_005Cdatamodelexpansions_005Cinternal/@EntryIndexedValue">True</s:Boolean>

View File

@ -32,7 +32,13 @@ namespace Artemis.Core
/// <summary>
/// The plugin info used by core components of Artemis
/// </summary>
public static readonly PluginInfo CorePluginInfo = new PluginInfo {Guid = Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff"), Name = "Artemis Core"};
public static readonly PluginInfo CorePluginInfo = new PluginInfo
{
Guid = Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff"), Name = "Artemis Core", Enabled = true
};
internal static readonly CorePlugin CorePlugin = new CorePlugin {PluginInfo = CorePluginInfo};
internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new EffectPlaceholderPlugin {PluginInfo = CorePluginInfo};
/// <summary>
/// A read-only collection containing all primitive numeric types

View File

@ -1,4 +1,5 @@
using System;
using SkiaSharp;
namespace Artemis.Core
{
@ -36,12 +37,23 @@ namespace Artemis.Core
/// <inheritdoc />
public override void ApplyValue(float value)
{
if (SetExpression == null)
return;
if (DataBinding.LayerProperty.PropertyDescription.MaxInputValue is float max)
value = Math.Min(value, max);
if (DataBinding.LayerProperty.PropertyDescription.MinInputValue is float min)
value = Math.Max(value, min);
SetExpression?.Invoke(value);
var test = new SKSize(5,5);
test.Width = 10;
SetExpression(DataBinding.LayerProperty.CurrentValue, value);
}
private void Mehtest(ref SKSize test)
{
test.Width = 20;
}
/// <inheritdoc />

View File

@ -26,7 +26,7 @@ namespace Artemis.Core
/// <inheritdoc />
public override void ApplyValue(object value)
{
SetExpression?.Invoke(value);
SetExpression?.Invoke(DataBinding.LayerProperty.CurrentValue, value);
}
/// <inheritdoc />

View File

@ -41,7 +41,7 @@ namespace Artemis.Core
/// <inheritdoc />
public override void ApplyValue(int value)
{
SetExpression?.Invoke(value);
SetExpression?.Invoke(DataBinding.LayerProperty.CurrentValue, value);
}
/// <inheritdoc />

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Artemis.Core.DataModelExpansions;
using Artemis.Storage.Entities.Profile.DataBindings;
@ -14,9 +13,9 @@ namespace Artemis.Core
private readonly List<DataBindingModifier<TLayerProperty, TProperty>> _modifiers = new List<DataBindingModifier<TLayerProperty, TProperty>>();
private TProperty _currentValue;
private bool _disposed;
private TimeSpan _easingProgress;
private TProperty _previousValue;
private bool _disposed;
internal DataBinding(DataBindingRegistration<TLayerProperty, TProperty> dataBindingRegistration)
{
@ -53,11 +52,6 @@ namespace Artemis.Core
/// </summary>
public DataBindingConverter<TLayerProperty, TProperty> Converter { get; private set; }
/// <summary>
/// Gets the property on the <see cref="LayerProperty" /> this data binding targets
/// </summary>
public PropertyInfo TargetProperty { get; private set; }
/// <summary>
/// Gets the currently used instance of the data model that contains the source of the data binding
/// </summary>
@ -118,8 +112,21 @@ namespace Artemis.Core
if (Converter == null)
return;
var value = GetValue(Converter.GetValue());
Converter.ApplyValue(GetValue(value));
var converterValue = Converter.GetValue();
var value = GetValue(converterValue);
Converter.ApplyValue(value);
}
/// <inheritdoc />
public void Dispose()
{
_disposed = true;
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
foreach (var dataBindingModifier in Modifiers)
dataBindingModifier.Dispose();
}
/// <summary>
@ -218,7 +225,7 @@ namespace Artemis.Core
/// </summary>
public Type GetTargetType()
{
return TargetProperty.PropertyType;
return Registration.PropertyExpression.ReturnType;
}
/// <summary>
@ -257,7 +264,6 @@ namespace Artemis.Core
Converter = dataBindingRegistration?.Converter;
Registration = dataBindingRegistration;
TargetProperty = dataBindingRegistration?.Property;
if (GetTargetType().IsValueType)
{
@ -305,7 +311,7 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("DataBinding");
// General
var registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetProperty);
var registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetExpression);
ApplyRegistration(registration);
Mode = (DataBindingMode) Entity.DataBindingMode;
@ -329,7 +335,7 @@ namespace Artemis.Core
LayerProperty.Entity.DataBindingEntities.Add(Entity);
// General
Entity.TargetProperty = TargetProperty?.Name;
Entity.TargetExpression = Registration.PropertyExpression.ToString();
Entity.DataBindingMode = (int) Mode;
Entity.EasingTime = EasingTime;
Entity.EasingFunction = (int) EasingFunction;
@ -340,7 +346,7 @@ namespace Artemis.Core
Entity.SourceDataModelGuid = SourceDataModel.PluginInfo.Guid;
Entity.SourcePropertyPath = SourcePropertyPath;
}
// Modifiers
Entity.Modifiers.Clear();
foreach (var dataBindingModifier in Modifiers)
@ -381,18 +387,6 @@ namespace Artemis.Core
}
#endregion
/// <inheritdoc />
public void Dispose()
{
_disposed = true;
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
foreach (var dataBindingModifier in Modifiers)
dataBindingModifier.Dispose();
}
}
/// <summary>

View File

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core
{
@ -18,7 +19,7 @@ namespace Artemis.Core
/// <summary>
/// A dynamically compiled setter pointing to the data bound property
/// </summary>
public Action<TProperty> SetExpression { get; private set; }
public Action<TLayerProperty, TProperty> SetExpression { get; private set; }
/// <summary>
/// Gets the data binding this converter is applied to
@ -81,19 +82,34 @@ namespace Artemis.Core
OnInitialized();
}
private Action<TProperty> CreateValueSetter()
private Action<TLayerProperty, TProperty> CreateValueSetter()
{
if (DataBinding.TargetProperty?.DeclaringType == null)
return null;
MethodInfo setterMethod = null;
if (DataBinding.Registration.Member != null)
{
if (DataBinding.Registration.Member is PropertyInfo propertyInfo)
setterMethod = propertyInfo.GetSetMethod();
}
var setterMethod = DataBinding.TargetProperty.GetSetMethod();
if (setterMethod == null)
return null;
var parameter = Expression.Parameter(typeof(TLayerProperty), "currentValue");
var propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
var body = DataBinding.Registration.PropertyExpression;
var lambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
var memberAccess = Expression.MakeMemberAccess(parameter, DataBinding.Registration.Member);
var assignment = Expression.Assign(memberAccess, propertyValue);
var lambda = Expression.Lambda<Action<TLayerProperty, TProperty>>(assignment, parameter, propertyValue);
if (typeof(TLayerProperty).IsValueType)
{
// var layerProperty = Expression.Constant(DataBinding.LayerProperty);
// var layerPropertyMemberAccess = Expression.MakeMemberAccess(layerProperty, DataBinding.LayerProperty.GetType().GetMember(nameof(DataBinding.LayerProperty.CurrentValue))[0]);
// var assingment = Expression.Assign()
}
return lambda.Compile();
}
}

View File

@ -175,7 +175,7 @@ namespace Artemis.Core
return;
}
var targetType = DataBinding.TargetProperty.PropertyType;
var targetType = DataBinding.GetTargetType();
if (!modifierType.SupportsType(targetType))
{
throw new ArtemisCoreException($"Cannot apply modifier type {modifierType.GetType().Name} to this modifier because " +
@ -227,7 +227,7 @@ namespace Artemis.Core
ParameterDataModel = null;
ParameterPropertyPath = null;
var targetType = DataBinding.TargetProperty.PropertyType;
var targetType = DataBinding.GetTargetType();
// If not null ensure the types match and if not, convert it
if (staticValue != null && staticValue.GetType() == targetType)
@ -269,7 +269,7 @@ namespace Artemis.Core
else if (ParameterType == ProfileRightSideType.Static && Entity.ParameterStaticValue != null && ParameterStaticValue == null)
{
// Use the target type so JSON.NET has a better idea what to do
var targetType = DataBinding.TargetProperty.PropertyType;
var targetType = DataBinding.GetTargetType();
object staticValue;
try

View File

@ -8,13 +8,16 @@ namespace Artemis.Core
/// <inheritdoc />
public class DataBindingRegistration<TLayerProperty, TProperty> : IDataBindingRegistration
{
internal DataBindingRegistration(LayerProperty<TLayerProperty> layerProperty,
DataBindingConverter<TLayerProperty, TProperty> converter,
internal DataBindingRegistration(LayerProperty<TLayerProperty> layerProperty,
DataBindingConverter<TLayerProperty, TProperty> converter,
Expression<Func<TLayerProperty, TProperty>> propertyExpression)
{
LayerProperty = layerProperty ?? throw new ArgumentNullException(nameof(layerProperty));
Converter = converter ?? throw new ArgumentNullException(nameof(converter));
PropertyExpression = propertyExpression ?? throw new ArgumentNullException(nameof(propertyExpression));
if (propertyExpression.Body is MemberExpression memberExpression)
Member = memberExpression.Member;
}
/// <summary>
@ -28,15 +31,16 @@ namespace Artemis.Core
public DataBindingConverter<TLayerProperty, TProperty> Converter { get; }
/// <summary>
/// Gets the expression that that accesses the property
/// Gets the expression that that accesses the property
/// </summary>
public Expression<Func<TLayerProperty, TProperty>> PropertyExpression { get; }
/// <summary>
/// Gets the registered property
/// Gets the member the <see cref="PropertyExpression" /> targets
/// <para><c>null</c> if the <see cref="PropertyExpression" /> is not a member expression</para>
/// </summary>
public PropertyInfo Property { get; }
public MemberInfo Member { get; }
/// <summary>
/// Gets the data binding created using this registration
/// </summary>
@ -48,7 +52,7 @@ namespace Artemis.Core
if (DataBinding != null)
return DataBinding;
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetProperty == PropertyExpression.ToString());
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetExpression == PropertyExpression.ToString());
if (dataBinding == null)
return null;

View File

@ -193,7 +193,7 @@ namespace Artemis.Core
canvas.Restore();
}
/// <inheritdoc />
public override void AddChild(ProfileElement child, int? order = null)
{
@ -242,17 +242,13 @@ namespace Artemis.Core
protected override void Dispose(bool disposing)
{
if (!disposing)
return;
_disposed = true;
foreach (var baseLayerEffect in LayerEffects)
baseLayerEffect.Dispose();
foreach (var profileElement in Children)
profileElement.Dispose();
_folderBitmap?.Dispose();
base.Dispose(disposing);
}
internal override void Load()
@ -290,10 +286,6 @@ namespace Artemis.Core
FolderEntity.ExpandedPropertyGroups.Clear();
FolderEntity.ExpandedPropertyGroups.AddRange(_expandedPropertyGroups);
// Conditions
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity;
DisplayConditionGroup?.Save();
SaveRenderElement();
}

View File

@ -124,20 +124,16 @@ namespace Artemis.Core
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
if (!disposing)
return;
_disposed = true;
// Brush first in case it depends on any of the other disposables during it's own disposal
_layerBrush?.Dispose();
foreach (var baseLayerEffect in LayerEffects)
baseLayerEffect.Dispose();
_general?.Dispose();
_layerBitmap?.Dispose();
_transform?.Dispose();
base.Dispose(disposing);
}
#endregion
@ -210,10 +206,6 @@ namespace Artemis.Core
LayerEntity.Leds.Add(ledEntity);
}
// Conditions
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity;
DisplayConditionGroup?.Save();
SaveRenderElement();
}
@ -691,14 +683,8 @@ namespace Artemis.Core
// Ensure the brush reference matches the brush
var current = General.BrushReference.CurrentValue;
if (current.BrushPluginGuid != descriptor.LayerBrushProvider.PluginInfo.Guid || current.BrushType != descriptor.LayerBrushType.Name)
{
General.BrushReference.CurrentValue = new LayerBrushReference
{
BrushPluginGuid = descriptor.LayerBrushProvider.PluginInfo.Guid,
BrushType = descriptor.LayerBrushType.Name
};
}
if (!descriptor.MatchesLayerBrushReference(current))
General.BrushReference.CurrentValue = new LayerBrushReference(descriptor);
ActivateLayerBrush();
}
@ -746,7 +732,7 @@ namespace Artemis.Core
private void LayerBrushStoreOnLayerBrushRemoved(object sender, LayerBrushStoreEvent e)
{
if (LayerBrush.Descriptor == e.Registration.LayerBrushDescriptor)
if (LayerBrush?.Descriptor == e.Registration.LayerBrushDescriptor)
DeactivateLayerBrush();
}

View File

@ -17,5 +17,15 @@ namespace Artemis.Core
/// The full type name of the brush descriptor
/// </summary>
public string BrushType { get; set; }
public LayerBrushReference()
{
}
public LayerBrushReference(LayerBrushDescriptor descriptor)
{
BrushPluginGuid = descriptor.LayerBrushProvider.PluginInfo.Guid;
BrushType = descriptor.LayerBrushType.Name;
}
}
}

View File

@ -26,10 +26,5 @@ namespace Artemis.Core
/// Returns a list off all data binding registrations
/// </summary>
List<IDataBindingRegistration> GetAllDataBindingRegistrations();
/// <summary>
/// Gets or sets whether the property is hidden in the UI
/// </summary>
bool IsHidden { get; set; }
}
}

View File

@ -61,7 +61,9 @@ namespace Artemis.Core
private bool _isHidden;
/// <inheritdoc />
/// <summary>
/// Gets or sets whether the property is hidden in the UI
/// </summary>
public bool IsHidden
{
get => _isHidden;
@ -318,13 +320,13 @@ namespace Artemis.Core
/// </summary>
public bool DataBindingsSupported { get; protected internal set; } = true;
public DataBindingRegistration<T, TProperty> GetDataBindingRegistration<TProperty>(string propertyName)
public DataBindingRegistration<T, TProperty> GetDataBindingRegistration<TProperty>(string expression)
{
if (_disposed)
throw new ObjectDisposedException("LayerProperty");
var match = _dataBindingRegistrations.FirstOrDefault(r => r is DataBindingRegistration<T, TProperty> registration &&
registration.Property.Name == propertyName);
registration.PropertyExpression.ToString() == expression);
return (DataBindingRegistration<T, TProperty>) match;
}

View File

@ -237,6 +237,10 @@ namespace Artemis.Core
if (instance == null)
throw new ArtemisPluginException($"Failed to create instance of layer property group at {path + propertyInfo.Name}");
// Ensure the description has a name, if not this is a good point to set it based on the property info
if (string.IsNullOrWhiteSpace(propertyGroupDescription.Name))
propertyGroupDescription.Name = propertyInfo.Name.Humanize();
instance.Parent = this;
instance.GroupDescription = propertyGroupDescription;
instance.LayerBrush = LayerBrush;

View File

@ -32,6 +32,10 @@ namespace Artemis.Core
DisplayContinuously = RenderElementEntity.DisplayContinuously;
AlwaysFinishTimeline = RenderElementEntity.AlwaysFinishTimeline;
DisplayConditionGroup = RenderElementEntity.RootDisplayCondition != null
? new DisplayConditionGroup(null, RenderElementEntity.RootDisplayCondition)
: new DisplayConditionGroup(null);
ActivateEffects();
}
@ -49,7 +53,7 @@ namespace Artemis.Core
var layerEffectEntity = new LayerEffectEntity
{
Id = layerEffect.EntityId,
PluginGuid = layerEffect.PluginInfo.Guid,
PluginGuid = layerEffect.Descriptor.PlaceholderFor ?? layerEffect.PluginInfo.Guid,
EffectType = layerEffect.GetEffectTypeName(),
Name = layerEffect.Name,
Enabled = layerEffect.Enabled,
@ -59,6 +63,10 @@ namespace Artemis.Core
RenderElementEntity.LayerEffects.Add(layerEffectEntity);
layerEffect.BaseProperties.ApplyToEntity();
}
// Conditions
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity;
DisplayConditionGroup?.Save();
}
#region Properties
@ -204,7 +212,7 @@ namespace Artemis.Core
return (TimelinePosition - oldPosition).TotalSeconds;
}
/// <summary>
/// Overrides the progress of the element
/// </summary>
@ -238,6 +246,8 @@ namespace Artemis.Core
Order = LayerEffects.Count + 1
};
descriptor.CreateInstance(this, entity);
OrderEffects();
OnLayerEffectsUpdated();
}
@ -254,6 +264,12 @@ namespace Artemis.Core
effect.Dispose();
// Update the order on the remaining effects
OrderEffects();
OnLayerEffectsUpdated();
}
private void OrderEffects()
{
var index = 0;
foreach (var baseLayerEffect in LayerEffects.OrderBy(e => e.Order))
{
@ -261,7 +277,7 @@ namespace Artemis.Core
index++;
}
OnLayerEffectsUpdated();
_layerEffects.Sort((a, b) => a.Order.CompareTo(b.Order));
}
internal void ActivateEffects()
@ -270,7 +286,7 @@ namespace Artemis.Core
{
// If there is a non-placeholder existing effect, skip this entity
var existing = _layerEffects.FirstOrDefault(e => e.EntityId == layerEffectEntity.Id);
if (existing != null && !existing.Descriptor.IsPlaceHolder)
if (existing != null && existing.Descriptor.PlaceholderFor == null)
continue;
var descriptor = LayerEffectStore.Get(layerEffectEntity.PluginGuid, layerEffectEntity.EffectType)?.LayerEffectDescriptor;
@ -282,37 +298,42 @@ namespace Artemis.Core
_layerEffects.Remove(existing);
existing.Dispose();
}
// Create an instance with the descriptor
descriptor.CreateInstance(this, layerEffectEntity);
}
else if (existing == null)
{
// If no descriptor was found and there was no existing placeholder, create a placeholder
descriptor = PlaceholderLayerEffectDescriptor.Create();
descriptor = PlaceholderLayerEffectDescriptor.Create(layerEffectEntity.PluginGuid);
descriptor.CreateInstance(this, layerEffectEntity);
}
}
OrderEffects();
}
internal void ActivateLayerEffect(BaseLayerEffect layerEffect)
{
_layerEffects.Add(layerEffect);
// Update the order on the effects
var index = 0;
foreach (var baseLayerEffect in LayerEffects.OrderBy(e => e.Order))
{
baseLayerEffect.Order = Order = index + 1;
index++;
}
OnLayerEffectsUpdated();
}
private void LayerEffectStoreOnLayerEffectRemoved(object? sender, LayerEffectStoreEvent e)
private void LayerEffectStoreOnLayerEffectRemoved(object sender, LayerEffectStoreEvent e)
{
throw new NotImplementedException();
// If effects provided by the plugin are on the element, replace them with placeholders
var pluginEffects = _layerEffects.Where(ef => ef.Descriptor.LayerEffectProvider != null &&
ef.PluginInfo.Guid == e.Registration.Plugin.PluginInfo.Guid).ToList();
foreach (var pluginEffect in pluginEffects)
{
var entity = RenderElementEntity.LayerEffects.First(en => en.Id == pluginEffect.EntityId);
_layerEffects.Remove(pluginEffect);
pluginEffect.Dispose();
var descriptor = PlaceholderLayerEffectDescriptor.Create(pluginEffect.PluginInfo.Guid);
descriptor.CreateInstance(this, entity);
}
}
private void LayerEffectStoreOnLayerEffectAdded(object sender, LayerEffectStoreEvent e)
@ -359,6 +380,21 @@ namespace Artemis.Core
#endregion
#region IDisposable
protected override void Dispose(bool disposing)
{
LayerEffectStore.LayerEffectAdded -= LayerEffectStoreOnLayerEffectAdded;
LayerEffectStore.LayerEffectRemoved -= LayerEffectStoreOnLayerEffectRemoved;
foreach (var baseLayerEffect in LayerEffects)
baseLayerEffect.Dispose();
base.Dispose(disposing);
}
#endregion
#region Events
public event EventHandler LayerEffectsUpdated;

View File

@ -61,5 +61,12 @@ namespace Artemis.Core.LayerBrushes
layer.LayerBrush = brush;
layer.OnLayerBrushUpdated();
}
public bool MatchesLayerBrushReference(LayerBrushReference reference)
{
if (reference == null)
return false;
return LayerBrushProvider.PluginInfo.Guid == reference.BrushPluginGuid && LayerBrushType.Name == reference.BrushType;
}
}
}

View File

@ -95,7 +95,7 @@ namespace Artemis.Core.LayerEffects
/// <summary>
/// Gets the plugin info that defined this effect
/// </summary>
public PluginInfo PluginInfo => Descriptor.LayerEffectProvider.PluginInfo;
public PluginInfo PluginInfo => Descriptor.LayerEffectProvider?.PluginInfo;
/// <summary>
/// Gets a reference to the layer property group without knowing it's type
@ -108,7 +108,7 @@ namespace Artemis.Core.LayerEffects
public void Dispose()
{
DisableLayerEffect();
BaseProperties.Dispose();
BaseProperties?.Dispose();
}
/// <summary>

View File

@ -1,5 +1,6 @@
using System;
using System.Linq;
using Artemis.Core.LayerEffects.Placeholder;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile;
using Ninject;
@ -47,9 +48,9 @@ namespace Artemis.Core.LayerEffects
public LayerEffectProvider LayerEffectProvider { get; }
/// <summary>
/// Gets a boolean indicating if this descriptor is a placeholder for a missing plugin
/// Gets the GUID this descriptor is acting as a placeholder for. If null, this descriptor is not a placeholder
/// </summary>
public bool IsPlaceHolder { get; internal set; }
public Guid? PlaceholderFor { get; internal set; }
/// <summary>
/// Creates an instance of the described effect and applies it to the render element
@ -60,7 +61,7 @@ namespace Artemis.Core.LayerEffects
if (renderElement.LayerEffects.Any(e => e.EntityId == entity.Id))
return;
if (IsPlaceHolder)
if (PlaceholderFor != null)
{
CreatePlaceHolderInstance(renderElement, entity);
return;
@ -82,7 +83,8 @@ namespace Artemis.Core.LayerEffects
private void CreatePlaceHolderInstance(RenderProfileElement renderElement, LayerEffectEntity entity)
{
var effect = new PlaceholderLayerEffect(entity) {ProfileElement = renderElement, Descriptor = this};
var effect = new PlaceholderLayerEffect(entity, PlaceholderFor.Value) {ProfileElement = renderElement, Descriptor = this};
effect.Initialize();
renderElement.ActivateLayerEffect(effect);
}
}

View File

@ -1,17 +1,19 @@
using Artemis.Storage.Entities.Profile;
using System;
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
namespace Artemis.Core.LayerEffects
namespace Artemis.Core.LayerEffects.Placeholder
{
/// <summary>
/// Represents a layer effect that could not be loaded due to a missing plugin
/// </summary>
public class PlaceholderLayerEffect : BaseLayerEffect
internal class PlaceholderLayerEffect : LayerEffect<PlaceholderProperties>
{
internal PlaceholderLayerEffect(LayerEffectEntity originalEntity)
internal PlaceholderLayerEffect(LayerEffectEntity originalEntity, Guid placeholderFor)
{
OriginalEntity = originalEntity;
PlaceholderFor = placeholderFor;
EntityId = OriginalEntity.Id;
Order = OriginalEntity.Order;
Name = OriginalEntity.Name;
@ -20,6 +22,7 @@ namespace Artemis.Core.LayerEffects
}
internal LayerEffectEntity OriginalEntity { get; }
public Guid PlaceholderFor { get; }
/// <inheritdoc />
public override void EnableLayerEffect()
@ -50,8 +53,22 @@ namespace Artemis.Core.LayerEffects
{
return OriginalEntity.EffectType;
}
}
internal override void Initialize()
/// <summary>
/// This is in place so that the UI has something to show
/// </summary>
internal class PlaceholderProperties : LayerPropertyGroup
{
protected override void PopulateDefaults()
{
}
protected override void EnableProperties()
{
}
protected override void DisableProperties()
{
}
}

View File

@ -1,10 +1,16 @@
namespace Artemis.Core.LayerEffects.Placeholder
using System;
namespace Artemis.Core.LayerEffects.Placeholder
{
internal static class PlaceholderLayerEffectDescriptor
{
public static LayerEffectDescriptor Create()
public static LayerEffectDescriptor Create(Guid missingPluginGuid)
{
var descriptor = new LayerEffectDescriptor("Missing effect", "This effect could not be loaded", "FileQuestion", null, null) {IsPlaceHolder = true};
var descriptor = new LayerEffectDescriptor("Missing effect", "This effect could not be loaded", "FileQuestion", null, Constants.EffectPlaceholderPlugin)
{
PlaceholderFor = missingPluginGuid
};
return descriptor;
}
}

View File

@ -16,7 +16,7 @@ namespace Artemis.Core
/// <summary>
/// Gets whether the plugin is enabled
/// </summary>
public bool Enabled { get; private set; }
public bool Enabled { get; internal set; }
/// <summary>
/// Gets or sets a configuration dialog for this plugin that is accessible in the UI under Settings > Plugins

View File

@ -22,5 +22,10 @@ namespace Artemis.Core.Services
/// Returns a list of all registered layer brush descriptors
/// </summary>
List<LayerBrushDescriptor> GetLayerBrushes();
/// <summary>
/// Returns the descriptor of the default layer brush
/// </summary>
LayerBrushDescriptor GetDefaultLayerBrush();
}
}

View File

@ -7,6 +7,13 @@ namespace Artemis.Core.Services
{
internal class LayerBrushService : ILayerBrushService
{
private readonly ISettingsService _settingsService;
public LayerBrushService(ISettingsService settingsService)
{
_settingsService = settingsService;
}
public LayerBrushRegistration RegisterLayerBrush(LayerBrushDescriptor descriptor)
{
if (descriptor == null)
@ -26,5 +33,16 @@ namespace Artemis.Core.Services
{
return LayerBrushStore.GetAll().Select(r => r.LayerBrushDescriptor).ToList();
}
public LayerBrushDescriptor GetDefaultLayerBrush()
{
var defaultReference = _settingsService.GetSetting("ProfileEditor.DefaultLayerBrushDescriptor", new LayerBrushReference
{
BrushPluginGuid = Guid.Parse("92a9d6ba-6f7a-4937-94d5-c1d715b4141a"),
BrushType = "ColorBrush"
});
return LayerBrushStore.Get(defaultReference.Value.BrushPluginGuid, defaultReference.Value.BrushType)?.LayerBrushDescriptor;
}
}
}

View File

@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Core.LayerBrushes;
using Artemis.Core.LayerEffects;
using Artemis.Core.Modules;
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Repositories.Interfaces;
@ -19,7 +17,12 @@ namespace Artemis.Core.Services
private readonly IProfileRepository _profileRepository;
private readonly ISurfaceService _surfaceService;
internal ProfileService(ILogger logger, IPluginService pluginService, ISurfaceService surfaceService, IProfileRepository profileRepository)
internal ProfileService(ILogger logger,
IPluginService pluginService,
ISurfaceService surfaceService,
IConditionOperatorService conditionOperatorService,
IDataBindingService dataBindingService,
IProfileRepository profileRepository)
{
_logger = logger;
_pluginService = pluginService;
@ -261,7 +264,7 @@ namespace Artemis.Core.Services
_profileRepository.Save(profileEntity);
}
}
/// <summary>
/// Populates all missing LEDs on all currently active profiles
/// </summary>
@ -272,7 +275,7 @@ namespace Artemis.Core.Services
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
profileModule.ActiveProfile.PopulateLeds(surface);
}
#region Event handlers
private void OnActiveSurfaceConfigurationSelected(object sender, SurfaceConfigurationEventArgs e)
@ -285,7 +288,7 @@ namespace Artemis.Core.Services
if (e.Surface.IsActive)
ActiveProfilesPopulateLeds(e.Surface);
}
#endregion
}
}

View File

@ -0,0 +1,40 @@
using Artemis.Core.LayerEffects;
namespace Artemis.Core
{
/// <summary>
/// An empty plugin used by <see cref="Constants.CorePluginInfo"/>
/// </summary>
internal class CorePlugin : Plugin
{
public CorePlugin()
{
Constants.CorePluginInfo.Instance = this;
Enabled = true;
}
public override void EnablePlugin()
{
}
public override void DisablePlugin()
{
}
}
internal class EffectPlaceholderPlugin : LayerEffectProvider
{
public EffectPlaceholderPlugin()
{
Enabled = true;
}
public override void EnablePlugin()
{
}
public override void DisablePlugin()
{
}
}
}

View File

@ -10,7 +10,7 @@ namespace Artemis.Storage.Entities.Profile.DataBindings
Modifiers = new List<DataBindingModifierEntity>();
}
public string TargetProperty { get; set; }
public string TargetExpression { get; set; }
public Guid? SourceDataModelGuid { get; set; }
public string SourcePropertyPath { get; set; }
public int DataBindingMode { get; set; }

View File

@ -69,12 +69,6 @@ namespace Artemis.UI.Ninject.Factories
DisplayConditionListPredicateViewModel DisplayConditionListPredicateViewModel(DisplayConditionListPredicate displayConditionListPredicate);
}
public interface IDataBindingsVmFactory : IVmFactory
{
IDataBindingViewModel DataBindingViewModel(IDataBindingRegistration registration);
DataBindingModifierViewModel<TLayerProperty, TProperty> DataBindingModifierViewModel<TLayerProperty, TProperty>(DataBindingModifier<TLayerProperty, TProperty> modifier);
}
public interface ILayerPropertyVmFactory : IVmFactory
{
LayerPropertyViewModel LayerPropertyViewModel(ILayerProperty layerProperty);
@ -89,6 +83,12 @@ namespace Artemis.UI.Ninject.Factories
TimelineSegmentViewModel TimelineSegmentViewModel(SegmentViewModelType segment, BindableCollection<LayerPropertyGroupViewModel> layerPropertyGroups);
}
public interface IDataBindingsVmFactory
{
IDataBindingViewModel DataBindingViewModel(IDataBindingRegistration registration);
DataBindingModifierViewModel<TLayerProperty, TProperty> DataBindingModifierViewModel<TLayerProperty, TProperty>(DataBindingModifier<TLayerProperty, TProperty> modifier);
}
public interface IPropertyVmFactory
{
ITreePropertyViewModel TreePropertyViewModel(ILayerProperty layerProperty, LayerPropertyViewModel layerPropertyViewModel);

View File

@ -1,5 +1,7 @@
using System;
using System.Reflection;
using Artemis.Core;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings;
using Ninject.Extensions.Factory;
namespace Artemis.UI.Ninject.InstanceProviders
@ -8,7 +10,17 @@ namespace Artemis.UI.Ninject.InstanceProviders
{
protected override Type GetType(MethodInfo methodInfo, object[] arguments)
{
return base.GetType(methodInfo, arguments);
if (methodInfo.ReturnType != typeof(IDataBindingViewModel))
return base.GetType(methodInfo, arguments);
// Find LayerProperty type
var descriptionPropertyType = arguments[0].GetType();
while (descriptionPropertyType != null && (!descriptionPropertyType.IsGenericType || descriptionPropertyType.GetGenericTypeDefinition() != typeof(DataBindingRegistration<,>)))
descriptionPropertyType = descriptionPropertyType.BaseType;
if (descriptionPropertyType == null)
return base.GetType(methodInfo, arguments);
return typeof(DataBindingViewModel<,>).MakeGenericType(descriptionPropertyType.GetGenericArguments());
}
}
}

View File

@ -50,6 +50,7 @@ namespace Artemis.UI.Ninject
.BindToFactory();
});
Kernel.Bind<IDataBindingsVmFactory>().ToFactory(() => new DataBindingsViewModelInstanceProvider());
Kernel.Bind<IPropertyVmFactory>().ToFactory(() => new LayerPropertyViewModelInstanceProvider());
// Bind profile editor VMs

View File

@ -11,28 +11,11 @@
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type propertyInput:BrushPropertyInputViewModel}}">
<UserControl.Resources>
<DataTemplate x:Key="SimpleTemplate">
<StackPanel d:DataContext="{d:DesignInstance {x:Type layerBrush:LayerBrushDescriptor}}" Orientation="Horizontal">
<materialDesign:PackIcon Kind="{Binding Icon}" Height="13" Width="13" Margin="0 1 3 0" />
<TextBlock Text="{Binding DisplayName}" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="ExtendedTemplate">
<Grid d:DataContext="{d:DesignInstance {x:Type layerBrush:LayerBrushDescriptor}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<materialDesign:PackIcon Grid.Row="0" Grid.RowSpan="2" Kind="{Binding Icon}" Height="20" Width="20" Margin="-5 -2 10 0" VerticalAlignment="Center" />
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding DisplayName}" TextWrapping="Wrap" MaxWidth="350" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Description}" TextWrapping="Wrap" MaxWidth="350" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" />
</Grid>
</DataTemplate>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Artemis.UI;component/ResourceDictionaries/LayerBrushDescriptors.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel Orientation="Horizontal">
<TextBlock Width="10" Text="{Binding LayerProperty.PropertyDescription.InputPrefix}" />
@ -46,8 +29,8 @@
ItemsSource="{Binding Path=Descriptors}"
SelectedValue="{Binding Path=SelectedDescriptor}"
ItemTemplateSelector="{dataTemplateSelectors:ComboBoxTemplateSelector
SelectedItemTemplate={StaticResource SimpleTemplate},
DropdownItemsTemplate={StaticResource ExtendedTemplate}}" />
SelectedItemTemplate={StaticResource SimpleLayerBrushDescriptorTemplate},
DropdownItemsTemplate={StaticResource ExtendedLayerBrushDescriptorTemplate}}" />
<TextBlock Width="10" Text="{Binding LayerProperty.PropertyDescription.InputAffix}" />
</StackPanel>
</UserControl>

View File

@ -5,16 +5,17 @@ using Artemis.Core.LayerBrushes;
using Artemis.Core.Services;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Stylet;
namespace Artemis.UI.PropertyInput
{
public class BrushPropertyInputViewModel : PropertyInputViewModel<LayerBrushReference>
{
private readonly IPluginService _pluginService;
private List<LayerBrushDescriptor> _descriptors;
private BindableCollection<LayerBrushDescriptor> _descriptors;
public BrushPropertyInputViewModel(LayerProperty<LayerBrushReference> layerProperty,
IProfileEditorService profileEditorService,
IProfileEditorService profileEditorService,
IPluginService pluginService) : base(layerProperty, profileEditorService)
{
_pluginService = pluginService;
@ -24,7 +25,7 @@ namespace Artemis.UI.PropertyInput
UpdateEnumValues();
}
public List<LayerBrushDescriptor> Descriptors
public BindableCollection<LayerBrushDescriptor> Descriptors
{
get => _descriptors;
set => SetAndNotify(ref _descriptors, value);
@ -32,14 +33,14 @@ namespace Artemis.UI.PropertyInput
public LayerBrushDescriptor SelectedDescriptor
{
get => Descriptors.FirstOrDefault(d => d.LayerBrushProvider.PluginInfo.Guid == InputValue?.BrushPluginGuid && d.LayerBrushType.Name == InputValue?.BrushType);
get => Descriptors.FirstOrDefault(d => d.MatchesLayerBrushReference(InputValue));
set => SetBrushByDescriptor(value);
}
public void UpdateEnumValues()
{
var layerBrushProviders = _pluginService.GetPluginsOfType<LayerBrushProvider>();
Descriptors = layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors).ToList();
Descriptors = new BindableCollection<LayerBrushDescriptor>(layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors));
NotifyOfPropertyChange(nameof(SelectedDescriptor));
}
@ -53,13 +54,13 @@ namespace Artemis.UI.PropertyInput
protected override void OnInputValueApplied()
{
if (LayerProperty.ProfileElement is Layer layer)
if (LayerProperty.ProfileElement is Layer layer)
layer.ChangeLayerBrush(SelectedDescriptor);
}
private void SetBrushByDescriptor(LayerBrushDescriptor value)
{
InputValue = new LayerBrushReference {BrushPluginGuid = value.LayerBrushProvider.PluginInfo.Guid, BrushType = value.LayerBrushType.Name};
InputValue = new LayerBrushReference(value);
}
private void PluginServiceOnPluginLoaded(object sender, PluginEventArgs e)

View File

@ -0,0 +1,27 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Artemis.UI.ResourceDictionaries"
xmlns:layerBrush="clr-namespace:Artemis.Core.LayerBrushes;assembly=Artemis.Core"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
<DataTemplate x:Key="SimpleLayerBrushDescriptorTemplate">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="{Binding Icon}" Height="13" Width="13" Margin="0 1 3 0" />
<TextBlock Text="{Binding DisplayName}" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="ExtendedLayerBrushDescriptorTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<materialDesign:PackIcon Grid.Row="0" Grid.RowSpan="2" Kind="{Binding Icon}" Height="20" Width="20" Margin="-5 -2 10 0" VerticalAlignment="Center" />
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding DisplayName}" TextWrapping="Wrap" MaxWidth="350" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Description}" TextWrapping="Wrap" MaxWidth="350" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" />
</Grid>
</DataTemplate>
</ResourceDictionary>

View File

@ -11,8 +11,6 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
{
private readonly IDisplayConditionsVmFactory _displayConditionsVmFactory;
private readonly IProfileEditorService _profileEditorService;
private bool _alwaysFinishTimeline;
private bool _displayContinuously;
private RenderProfileElement _renderProfileElement;
private int _transitionerIndex;
@ -37,20 +35,22 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public bool DisplayContinuously
{
get => _displayContinuously;
get => RenderProfileElement?.DisplayContinuously ?? false;
set
{
if (!SetAndNotify(ref _displayContinuously, value)) return;
if (RenderProfileElement == null || RenderProfileElement.DisplayContinuously == value) return;
RenderProfileElement.DisplayContinuously = value;
_profileEditorService.UpdateSelectedProfileElement();
}
}
public bool AlwaysFinishTimeline
{
get => _alwaysFinishTimeline;
get => RenderProfileElement?.AlwaysFinishTimeline ?? false;
set
{
if (!SetAndNotify(ref _alwaysFinishTimeline, value)) return;
if (RenderProfileElement == null || RenderProfileElement.AlwaysFinishTimeline == value) return;
RenderProfileElement.AlwaysFinishTimeline = value;
_profileEditorService.UpdateSelectedProfileElement();
}
}
@ -70,12 +70,9 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private void ProfileEditorServiceOnProfileElementSelected(object sender, RenderProfileElementEventArgs e)
{
RenderProfileElement = e.RenderProfileElement;
NotifyOfPropertyChange(nameof(ConditionBehaviourEnabled));
_displayContinuously = RenderProfileElement?.DisplayContinuously ?? false;
NotifyOfPropertyChange(nameof(DisplayContinuously));
_alwaysFinishTimeline = RenderProfileElement?.AlwaysFinishTimeline ?? false;
NotifyOfPropertyChange(nameof(AlwaysFinishTimeline));
NotifyOfPropertyChange(nameof(ConditionBehaviourEnabled));
if (e.RenderProfileElement == null)
{

View File

@ -4,14 +4,10 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:converters="clr-namespace:Artemis.UI.Converters"
xmlns:utilities="clr-namespace:Artemis.UI.Utilities"
xmlns:dd="urn:gong-wpf-dragdrop"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:local="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:DataBindingViewModel}">
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

View File

@ -36,7 +36,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
_dataModelUIService = dataModelUIService;
_dataBindingsVmFactory = dataBindingsVmFactory;
DisplayName = Registration.Property.Name.ToUpper();
if (Registration.Member != null)
DisplayName = Registration.Member.Name.ToUpper();
else
DisplayName = Registration.LayerProperty.PropertyDescription.Name.ToUpper();
DataBindingModes = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(typeof(DataBindingMode)));
EasingViewModels = new BindableCollection<TimelineEasingViewModel>();
@ -203,7 +206,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
TargetSelectionViewModel.IsEnabled = true;
TargetSelectionViewModel.PopulateSelectedPropertyViewModel(DataBinding.SourceDataModel, DataBinding.SourcePropertyPath);
TargetSelectionViewModel.FilterTypes = new[] {DataBinding.TargetProperty.PropertyType};
TargetSelectionViewModel.FilterTypes = new[] {DataBinding.GetTargetType()};
UpdateModifierViewModels();
@ -225,11 +228,18 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
private void UpdateTestResult()
{
if (DataBinding == null)
{
TestInputValue = default;
TestResultValue = default;
return;
}
var currentValue = TargetSelectionViewModel.SelectedPropertyViewModel?.GetCurrentValue();
if (currentValue == null && Registration.Property.PropertyType.IsValueType)
currentValue = Activator.CreateInstance(Registration.Property.PropertyType);
TestInputValue = currentValue is TProperty testInputValue ? testInputValue : default;
if (currentValue == null)
currentValue = default(TProperty);
TestInputValue = (TProperty) Convert.ChangeType(currentValue, typeof(TProperty));
if (DataBinding != null)
TestResultValue = DataBinding.GetValue(TestInputValue);
else

View File

@ -6,7 +6,7 @@
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<TabControl ItemsSource="{Binding Items}" DisplayMemberPath="DisplayName" Style="{StaticResource MaterialDesignTabControl}">
<TabControl ItemsSource="{Binding Items}" SelectedIndex="{Binding SelectedItemIndex}" DisplayMemberPath="DisplayName" Style="{StaticResource MaterialDesignTabControl}">
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl s:View.Model="{Binding}" TextElement.Foreground="{DynamicResource MaterialDesignBody}" />

View File

@ -9,6 +9,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
private readonly IProfileEditorService _profileEditorService;
private int _selectedItemIndex;
public DataBindingsViewModel(IProfileEditorService profileEditorService, IDataBindingsVmFactory dataBindingsVmFactory)
{
@ -19,6 +20,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
CreateDataBindingViewModels();
}
public int SelectedItemIndex
{
get => _selectedItemIndex;
set => SetAndNotify(ref _selectedItemIndex, value);
}
private void CreateDataBindingViewModels()
{
Items.Clear();
@ -33,6 +40,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
// and creating the actual data bindings
foreach (var registration in registrations)
ActivateItem(_dataBindingsVmFactory.DataBindingViewModel(registration));
SelectedItemIndex = 0;
}
protected override void OnClose()

View File

@ -23,7 +23,7 @@
Think of things like blur, black &amp; white but also audio visualization etc.
</TextBlock>
</StackPanel>
<ListBox ItemsSource="{Binding LayerEffectDescriptors}" SelectedItem="{Binding SelectedLayerEffectDescriptor}" HorizontalContentAlignment="Stretch"
<ListBox ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedLayerEffectDescriptor}" HorizontalContentAlignment="Stretch"
Visibility="{Binding HasLayerEffectDescriptors, Converter={x:Static s:BoolToVisibilityConverter.Instance}}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">

View File

@ -310,7 +310,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
foreach (var layerEffect in SelectedProfileElement.LayerEffects)
{
if (LayerPropertyGroups.Any(l => l.LayerPropertyGroup.LayerEffect == layerEffect))
if (LayerPropertyGroups.Any(l => l.LayerPropertyGroup.LayerEffect == layerEffect) || layerEffect.BaseProperties == null)
continue;
// TODO: wat?

View File

@ -11,6 +11,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
public class LayerPropertyGroupViewModel : PropertyChangedBase, IDisposable
{
private readonly ILayerPropertyVmFactory _layerPropertyVmFactory;
private bool _isVisible;
public LayerPropertyGroupViewModel(LayerPropertyGroup layerPropertyGroup, ILayerPropertyVmFactory layerPropertyVmFactory)
{
@ -21,6 +22,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
TreeGroupViewModel = layerPropertyVmFactory.TreeGroupViewModel(this);
TimelineGroupViewModel = layerPropertyVmFactory.TimelineGroupViewModel(this);
LayerPropertyGroup.VisibilityChanged += LayerPropertyGroupOnVisibilityChanged;
IsVisible = !LayerPropertyGroup.IsHidden;
PopulateChildren();
}
@ -29,7 +34,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
public TimelineGroupViewModel TimelineGroupViewModel { get; }
public BindableCollection<PropertyChangedBase> Children { get; }
public bool IsVisible => !LayerPropertyGroup.IsHidden;
public bool IsVisible
{
get => _isVisible;
set => SetAndNotify(ref _isVisible, value);
}
public bool IsExpanded
{
@ -41,6 +50,83 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
}
}
public void Dispose()
{
LayerPropertyGroup.VisibilityChanged -= LayerPropertyGroupOnVisibilityChanged;
foreach (var child in Children)
{
if (child is IDisposable disposableChild)
disposableChild.Dispose();
}
}
public void UpdateOrder(int order)
{
LayerPropertyGroup.LayerEffect.Order = order;
NotifyOfPropertyChange(nameof(IsExpanded));
}
public List<ITimelineKeyframeViewModel> GetAllKeyframeViewModels(bool expandedOnly)
{
var result = new List<ITimelineKeyframeViewModel>();
if (expandedOnly && !IsExpanded)
return result;
foreach (var child in Children)
{
if (child is LayerPropertyViewModel layerPropertyViewModel)
result.AddRange(layerPropertyViewModel.TimelinePropertyViewModel.GetAllKeyframeViewModels());
else if (child is LayerPropertyGroupViewModel layerPropertyGroupViewModel)
result.AddRange(layerPropertyGroupViewModel.GetAllKeyframeViewModels(expandedOnly));
}
return result;
}
/// <summary>
/// Removes the keyframes between the <paramref name="start" /> and <paramref name="end" /> position from this property
/// group
/// </summary>
/// <param name="start">The position at which to start removing keyframes, if null this will start at the first keyframe</param>
/// <param name="end">The position at which to start removing keyframes, if null this will end at the last keyframe</param>
public virtual void WipeKeyframes(TimeSpan? start, TimeSpan? end)
{
foreach (var child in Children)
{
if (child is LayerPropertyViewModel layerPropertyViewModel)
layerPropertyViewModel.TimelinePropertyViewModel.WipeKeyframes(start, end);
else if (child is LayerPropertyGroupViewModel layerPropertyGroupViewModel)
layerPropertyGroupViewModel.WipeKeyframes(start, end);
}
TimelineGroupViewModel.UpdateKeyframePositions();
}
/// <summary>
/// Shifts the keyframes between the <paramref name="start" /> and <paramref name="end" /> position by the provided
/// <paramref name="amount" />
/// </summary>
/// <param name="start">The position at which to start shifting keyframes, if null this will start at the first keyframe</param>
/// <param name="end">The position at which to start shifting keyframes, if null this will end at the last keyframe</param>
/// <param name="amount">The amount to shift the keyframes for</param>
public void ShiftKeyframes(TimeSpan? start, TimeSpan? end, TimeSpan amount)
{
foreach (var child in Children)
{
if (child is LayerPropertyViewModel layerPropertyViewModel)
layerPropertyViewModel.TimelinePropertyViewModel.ShiftKeyframes(start, end, amount);
else if (child is LayerPropertyGroupViewModel layerPropertyGroupViewModel)
layerPropertyGroupViewModel.ShiftKeyframes(start, end, amount);
}
TimelineGroupViewModel.UpdateKeyframePositions();
}
private void LayerPropertyGroupOnVisibilityChanged(object sender, EventArgs e)
{
IsVisible = !LayerPropertyGroup.IsHidden;
}
private void PopulateChildren()
{
// Get all properties and property groups and create VMs for them
@ -66,70 +152,5 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
Children.Add(_layerPropertyVmFactory.LayerPropertyGroupViewModel(layerPropertyGroup));
}
}
public void Dispose()
{
foreach (var child in Children)
{
if (child is IDisposable disposableChild)
disposableChild.Dispose();
}
}
public void UpdateOrder(int order)
{
LayerPropertyGroup.LayerEffect.Order = order;
NotifyOfPropertyChange(nameof(IsExpanded));
}
public List<ITimelineKeyframeViewModel> GetAllKeyframeViewModels(bool expandedOnly)
{
var result = new List<ITimelineKeyframeViewModel>();
if (expandedOnly == IsExpanded)
return result;
foreach (var child in Children)
{
if (child is LayerPropertyViewModel layerPropertyViewModel)
result.AddRange(layerPropertyViewModel.TimelinePropertyViewModel.GetAllKeyframeViewModels());
else if (child is LayerPropertyGroupViewModel layerPropertyGroupViewModel)
result.AddRange(layerPropertyGroupViewModel.GetAllKeyframeViewModels(expandedOnly));
}
return result;
}
/// <summary>
/// Removes the keyframes between the <paramref name="start"/> and <paramref name="end"/> position from this property group
/// </summary>
/// <param name="start">The position at which to start removing keyframes, if null this will start at the first keyframe</param>
/// <param name="end">The position at which to start removing keyframes, if null this will end at the last keyframe</param>
public virtual void WipeKeyframes(TimeSpan? start, TimeSpan? end)
{
foreach (var child in Children)
{
if (child is LayerPropertyViewModel layerPropertyViewModel)
layerPropertyViewModel.TimelinePropertyViewModel.WipeKeyframes(start, end);
else if (child is LayerPropertyGroupViewModel layerPropertyGroupViewModel)
layerPropertyGroupViewModel.WipeKeyframes(start, end);
}
}
/// <summary>
/// Shifts the keyframes between the <paramref name="start"/> and <paramref name="end"/> position by the provided <paramref name="amount"/>
/// </summary>
/// <param name="start">The position at which to start shifting keyframes, if null this will start at the first keyframe</param>
/// <param name="end">The position at which to start shifting keyframes, if null this will end at the last keyframe</param>
/// <param name="amount">The amount to shift the keyframes for</param>
public void ShiftKeyframes(TimeSpan? start, TimeSpan? end, TimeSpan amount)
{
foreach (var child in Children)
{
if (child is LayerPropertyViewModel layerPropertyViewModel)
layerPropertyViewModel.TimelinePropertyViewModel.ShiftKeyframes(start, end, amount);
else if (child is LayerPropertyGroupViewModel layerPropertyGroupViewModel)
layerPropertyGroupViewModel.ShiftKeyframes(start, end, amount);
}
}
}
}

View File

@ -3,14 +3,14 @@ using Artemis.Core;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree;
using Ninject;
using Ninject.Parameters;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
{
public class LayerPropertyViewModel : PropertyChangedBase, IDisposable
{
private bool _isVisible;
public LayerPropertyViewModel(ILayerProperty layerProperty, IPropertyVmFactory propertyVmFactory)
{
LayerProperty = layerProperty;
@ -23,8 +23,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
public ITreePropertyViewModel TreePropertyViewModel { get; }
public ITimelinePropertyViewModel TimelinePropertyViewModel { get; }
public bool IsVisible => !LayerProperty.IsHidden;
public bool IsVisible
{
get => _isVisible;
set => SetAndNotify(ref _isVisible, value);
}
public void Dispose()
{
TreePropertyViewModel?.Dispose();

View File

@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Linq;
using Artemis.Core;
using Artemis.UI.Shared.Services;
@ -19,24 +20,17 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
KeyframePositions = new BindableCollection<double>();
_profileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
LayerPropertyGroupViewModel.PropertyChanged += LayerPropertyGroupViewModelOnPropertyChanged;
UpdateKeyframePositions();
}
public LayerPropertyGroupViewModel LayerPropertyGroupViewModel { get; }
public LayerPropertyGroup LayerPropertyGroup { get; }
public BindableCollection<double> KeyframePositions { get; }
public void Dispose()
{
_profileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
}
private void ProfileEditorServiceOnPixelsPerSecondChanged(object? sender, EventArgs e)
{
UpdateKeyframePositions();
}
public void UpdateKeyframePositions()
{
KeyframePositions.Clear();
@ -44,5 +38,30 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
.GetAllKeyframeViewModels(false)
.Select(p => p.Position.TotalSeconds * _profileEditorService.PixelsPerSecond));
}
#region IDisposable
public void Dispose()
{
_profileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
LayerPropertyGroupViewModel.PropertyChanged -= LayerPropertyGroupViewModelOnPropertyChanged;
}
#endregion
#region Event handlers
private void LayerPropertyGroupViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(LayerPropertyGroupViewModel.IsExpanded))
UpdateKeyframePositions();
}
private void ProfileEditorServiceOnPixelsPerSecondChanged(object sender, EventArgs e)
{
UpdateKeyframePositions();
}
#endregion
}
}

View File

@ -20,16 +20,15 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
{
_profileEditorService = profileEditorService;
LayerPropertyKeyframe = layerPropertyKeyframe;
EasingViewModels = new BindableCollection<TimelineEasingViewModel>();
_profileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
LayerPropertyKeyframe.PropertyChanged += LayerPropertyKeyframeOnPropertyChanged;
}
public LayerPropertyKeyframe<T> LayerPropertyKeyframe { get; }
public BindableCollection<TimelineEasingViewModel> EasingViewModels
{
get => _easingViewModels;
set => SetAndNotify(ref _easingViewModels, value);
}
public LayerPropertyKeyframe<T> LayerPropertyKeyframe { get; }
public BindableCollection<TimelineEasingViewModel> EasingViewModels { get; }
public double X
{
@ -53,6 +52,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
public void Dispose()
{
_profileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
LayerPropertyKeyframe.PropertyChanged -= LayerPropertyKeyframeOnPropertyChanged;
foreach (var timelineEasingViewModel in EasingViewModels)
@ -65,6 +65,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
Timestamp = $"{Math.Floor(LayerPropertyKeyframe.Position.TotalSeconds):00}.{LayerPropertyKeyframe.Position.Milliseconds:000}";
}
private void ProfileEditorServiceOnPixelsPerSecondChanged(object? sender, EventArgs e)
{
Update();
}
private void LayerPropertyKeyframeOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(LayerPropertyKeyframe.Position))
@ -73,7 +78,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
#region Easing
public void CreateEasingViewModels()
public void PopulateEasingViewModels()
{
if (EasingViewModels.Any())
return;
@ -86,6 +91,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
timelineEasingViewModel.EasingModeSelected += TimelineEasingViewModelOnEasingModeSelected;
}
public void ClearEasingViewModels()
{
EasingViewModels.Clear();
}
private void TimelineEasingViewModelOnEasingModeSelected(object sender, EventArgs e)
{
SelectEasingMode((TimelineEasingViewModel) sender);
@ -150,18 +160,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
#region Context menu actions
public void ContextMenuOpening()
{
CreateEasingViewModels();
}
public void ContextMenuClosing()
{
foreach (var timelineEasingViewModel in EasingViewModels)
timelineEasingViewModel.EasingModeSelected -= TimelineEasingViewModelOnEasingModeSelected;
EasingViewModels.Clear();
}
public void Copy()
{
var newKeyframe = new LayerPropertyKeyframe<T>(
@ -211,6 +209,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
#region Context menu actions
void PopulateEasingViewModels();
void ClearEasingViewModels();
void Copy();
void Delete();

View File

@ -38,7 +38,7 @@
MouseDown="{s:Action KeyframeMouseDown}"
MouseUp="{s:Action KeyframeMouseUp}"
MouseMove="{s:Action KeyframeMouseMove}"
ContextMenuOpening="{s:Action ContextMenuOpening}"
ContextMenuOpening="{s:Action ContextMenuOpening}"
ContextMenuClosing="{s:Action ContextMenuClosing}">
<Ellipse.Style>
<Style TargetType="{x:Type Ellipse}">

View File

@ -19,6 +19,25 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
LayerProperty = layerProperty;
LayerPropertyViewModel = layerPropertyViewModel;
LayerProperty.KeyframesToggled += LayerPropertyOnKeyframesToggled;
LayerProperty.KeyframeAdded += LayerPropertyOnKeyframeAdded;
LayerProperty.KeyframeRemoved += LayerPropertyOnKeyframeRemoved;
UpdateKeyframes();
}
private void LayerPropertyOnKeyframesToggled(object sender, LayerPropertyEventArgs<T> e)
{
UpdateKeyframes();
}
private void LayerPropertyOnKeyframeRemoved(object sender, LayerPropertyEventArgs<T> e)
{
UpdateKeyframes();
}
private void LayerPropertyOnKeyframeAdded(object sender, LayerPropertyEventArgs<T> e)
{
UpdateKeyframes();
}
@ -55,8 +74,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
start ??= TimeSpan.Zero;
end ??= TimeSpan.MaxValue;
var toShift = LayerProperty.Keyframes.Where(k => k.Position >= start && k.Position <= end).ToList();
foreach (var keyframe in toShift)
var toShift = LayerProperty.Keyframes.Where(k => k.Position >= start && k.Position < end).ToList();
foreach (var keyframe in toShift)
LayerProperty.RemoveKeyframe(keyframe);
UpdateKeyframes();
@ -67,7 +86,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
start ??= TimeSpan.Zero;
end ??= TimeSpan.MaxValue;
var toShift = LayerProperty.Keyframes.Where(k => k.Position >= start && k.Position <= end).ToList();
var toShift = LayerProperty.Keyframes.Where(k => k.Position >= start && k.Position < end).ToList();
foreach (var keyframe in toShift)
keyframe.Position += amount;
@ -76,6 +95,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
public void Dispose()
{
LayerProperty.KeyframesToggled -= LayerPropertyOnKeyframesToggled;
LayerProperty.KeyframeAdded -= LayerPropertyOnKeyframeAdded;
LayerProperty.KeyframeRemoved -= LayerPropertyOnKeyframeRemoved;
}
}

View File

@ -17,6 +17,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
private bool _showDisableButton;
private bool _showRepeatButton;
private bool _showSegmentName;
private TimeSpan _segmentLength;
private double _segmentWidth;
private bool _segmentEnabled;
private double _segmentStartPosition;
public TimelineSegmentViewModel(SegmentViewModelType segment, BindableCollection<LayerPropertyGroupViewModel> layerPropertyGroups,
IProfileEditorService profileEditorService)
@ -24,55 +28,54 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
ProfileEditorService = profileEditorService;
Segment = segment;
LayerPropertyGroups = layerPropertyGroups;
SelectedProfileElement = ProfileEditorService.SelectedProfileElement;
switch (Segment)
{
case SegmentViewModelType.Start:
ToolTip = "This segment is played when a layer starts displaying because it's conditions are met";
break;
case SegmentViewModelType.Main:
ToolTip = "This segment is played while a condition is met, either once or on a repeating loop";
break;
case SegmentViewModelType.End:
ToolTip = "This segment is played once a condition is no longer met";
break;
default:
throw new ArgumentOutOfRangeException(nameof(segment));
}
if (Segment == SegmentViewModelType.Start)
ToolTip = "This segment is played when a layer starts displaying because it's conditions are met";
else if (Segment == SegmentViewModelType.Main)
ToolTip = "This segment is played while a condition is met, either once or on a repeating loop";
else if (Segment == SegmentViewModelType.End)
ToolTip = "This segment is played once a condition is no longer met";
IsMainSegment = Segment == SegmentViewModelType.Main;
UpdateDisplay();
ProfileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
ProfileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
if (ProfileEditorService.SelectedProfileElement != null)
ProfileEditorService.SelectedProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
Update();
}
public RenderProfileElement SelectedProfileElement { get; }
public RenderProfileElement SelectedProfileElement => ProfileEditorService.SelectedProfileElement;
public SegmentViewModelType Segment { get; }
public BindableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
public IProfileEditorService ProfileEditorService { get; }
public string ToolTip { get; }
public bool IsMainSegment { get; }
public TimeSpan SegmentLength
{
get
{
return Segment switch
{
SegmentViewModelType.Start => SelectedProfileElement?.StartSegmentLength ?? TimeSpan.Zero,
SegmentViewModelType.Main => SelectedProfileElement?.MainSegmentLength ?? TimeSpan.Zero,
SegmentViewModelType.End => SelectedProfileElement?.EndSegmentLength ?? TimeSpan.Zero,
_ => throw new ArgumentOutOfRangeException()
};
}
get => _segmentLength;
set => SetAndNotify(ref _segmentLength, value);
}
public double SegmentWidth => ProfileEditorService.PixelsPerSecond * SegmentLength.TotalSeconds;
public double SegmentWidth
{
get => _segmentWidth;
set => SetAndNotify(ref _segmentWidth, value);
}
public bool SegmentEnabled => SegmentLength != TimeSpan.Zero;
public bool IsMainSegment => Segment == SegmentViewModelType.Main;
public double SegmentStartPosition
{
get => _segmentStartPosition;
set => SetAndNotify(ref _segmentStartPosition, value);
}
public bool SegmentEnabled
{
get => _segmentEnabled;
set => SetAndNotify(ref _segmentEnabled, value);
}
// Only the main segment supports this, for any other segment the getter always returns false and the setter does nothing
public bool RepeatSegment
@ -95,23 +98,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
}
}
public double SegmentStartPosition
{
get
{
if (SelectedProfileElement == null)
return 0;
return Segment switch
{
SegmentViewModelType.Start => 0,
SegmentViewModelType.Main => ProfileEditorService.PixelsPerSecond * SelectedProfileElement.StartSegmentLength.TotalSeconds,
SegmentViewModelType.End => ProfileEditorService.PixelsPerSecond * (SelectedProfileElement.StartSegmentLength.TotalSeconds + SelectedProfileElement.MainSegmentLength.TotalSeconds),
_ => throw new ArgumentOutOfRangeException()
};
}
}
public bool ShowSegmentName
{
get => _showSegmentName;
@ -130,14 +116,57 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
set => SetAndNotify(ref _showDisableButton, value);
}
public void Dispose()
#region Updating
private void UpdateHeader()
{
ProfileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
ProfileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected;
if (SelectedProfileElement != null)
SelectedProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
if (!IsMainSegment)
ShowSegmentName = SegmentWidth > 60;
else
ShowSegmentName = SegmentWidth > 80;
ShowRepeatButton = SegmentWidth > 45 && IsMainSegment;
ShowDisableButton = SegmentWidth > 25;
}
private void Update()
{
if (SelectedProfileElement == null)
{
SegmentLength = TimeSpan.Zero;
SegmentStartPosition = 0;
SegmentWidth = 0;
SegmentEnabled = false;
return;
}
if (Segment == SegmentViewModelType.Start)
{
SegmentLength = SelectedProfileElement.StartSegmentLength;
SegmentStartPosition = 0;
}
else if (Segment == SegmentViewModelType.Main)
{
SegmentLength = SelectedProfileElement.MainSegmentLength;
SegmentStartPosition = ProfileEditorService.PixelsPerSecond * SelectedProfileElement.StartSegmentLength.TotalSeconds;
}
else if (Segment == SegmentViewModelType.End)
{
SegmentLength = SelectedProfileElement.EndSegmentLength;
SegmentStartPosition = ProfileEditorService.PixelsPerSecond * (SelectedProfileElement.StartSegmentLength.TotalSeconds +
SelectedProfileElement.MainSegmentLength.TotalSeconds);
}
SegmentWidth = ProfileEditorService.PixelsPerSecond * SegmentLength.TotalSeconds;
SegmentEnabled = SegmentLength != TimeSpan.Zero;
UpdateHeader();
}
#endregion
#region Controls
public void DisableSegment()
{
var startSegmentEnd = SelectedProfileElement.StartSegmentLength;
@ -164,9 +193,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
SelectedProfileElement.EndSegmentLength = TimeSpan.Zero;
}
NotifyOfPropertyChange(nameof(SegmentEnabled));
ShiftNextSegment(SegmentLength - oldSegmentLength);
ProfileEditorService.UpdateSelectedProfileElement();
Update();
}
public void EnableSegment()
@ -179,23 +208,13 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
else if (Segment == SegmentViewModelType.End)
SelectedProfileElement.EndSegmentLength = TimeSpan.FromSeconds(1);
NotifyOfPropertyChange(nameof(SegmentEnabled));
ProfileEditorService.UpdateSelectedProfileElement();
UpdateDisplay();
Update();
}
public void ShiftNextSegment(TimeSpan amount)
{
var segmentEnd = TimeSpan.Zero;
if (Segment == SegmentViewModelType.Start)
segmentEnd = SelectedProfileElement.StartSegmentLength;
else if (Segment == SegmentViewModelType.Main)
segmentEnd = SelectedProfileElement.StartSegmentLength + SelectedProfileElement.MainSegmentLength;
else if (Segment == SegmentViewModelType.End)
segmentEnd = SelectedProfileElement.TimelineLength;
#endregion
ShiftKeyframes(segmentEnd, null, amount);
}
#region Mouse events
public void SegmentMouseDown(object sender, MouseButtonEventArgs e)
{
@ -260,18 +279,34 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
SelectedProfileElement.EndSegmentLength = newTime - SelectedProfileElement.StartSegmentLength - SelectedProfileElement.MainSegmentLength;
}
NotifyOfPropertyChange(nameof(SegmentLength));
NotifyOfPropertyChange(nameof(SegmentWidth));
ShiftNextSegment(SegmentLength - oldSegmentLength);
UpdateDisplay();
Update();
}
#endregion
#region IDIsposable
public void Dispose()
{
ProfileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
ProfileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected;
if (SelectedProfileElement != null)
SelectedProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
}
#endregion
#region Event handlers
private void ProfileEditorServiceOnProfileElementSelected(object? sender, RenderProfileElementEventArgs e)
{
if (e.PreviousRenderProfileElement != null)
e.PreviousRenderProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
e.RenderProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
if (e.RenderProfileElement != null)
e.RenderProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
Update();
}
private void SelectedProfileElementOnPropertyChanged(object sender, PropertyChangedEventArgs e)
@ -279,31 +314,29 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
if (e.PropertyName == nameof(RenderProfileElement.StartSegmentLength) ||
e.PropertyName == nameof(RenderProfileElement.MainSegmentLength) ||
e.PropertyName == nameof(RenderProfileElement.EndSegmentLength))
{
NotifyOfPropertyChange(nameof(SegmentStartPosition));
NotifyOfPropertyChange(nameof(SegmentWidth));
}
Update();
else if (e.PropertyName == nameof(RenderProfileElement.DisplayContinuously))
NotifyOfPropertyChange(nameof(RepeatSegment));
}
private void ProfileEditorServiceOnPixelsPerSecondChanged(object? sender, EventArgs e)
{
NotifyOfPropertyChange(nameof(SegmentWidth));
NotifyOfPropertyChange(nameof(SegmentStartPosition));
UpdateDisplay();
Update();
}
private void UpdateDisplay()
{
if (!IsMainSegment)
ShowSegmentName = SegmentWidth > 60;
else
ShowSegmentName = SegmentWidth > 80;
#endregion
ShowRepeatButton = SegmentWidth > 45 && IsMainSegment;
ShowDisableButton = SegmentWidth > 25;
public void ShiftNextSegment(TimeSpan amount)
{
var segmentEnd = TimeSpan.Zero;
if (Segment == SegmentViewModelType.Start)
segmentEnd = SelectedProfileElement.StartSegmentLength;
else if (Segment == SegmentViewModelType.Main)
segmentEnd = SelectedProfileElement.StartSegmentLength + SelectedProfileElement.MainSegmentLength;
else if (Segment == SegmentViewModelType.End)
segmentEnd = SelectedProfileElement.TimelineLength;
ShiftKeyframes(segmentEnd, null, amount);
}
private void WipeKeyframes(TimeSpan? start, TimeSpan? end)

View File

@ -50,7 +50,7 @@
Y1="0"
Y2="{Binding ActualHeight, ElementName=TimelineContainerGrid}"
HorizontalAlignment="Left"
Visibility="{Binding StartSegmentEnabled, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" />
Visibility="{Binding LayerPropertiesViewModel.StartTimelineSegmentViewModel.SegmentEnabled, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" />
<Line Stroke="{StaticResource PrimaryHueDarkBrush}"
Opacity="0.5"
StrokeDashArray="4 2"
@ -65,7 +65,7 @@
X2="{Binding EndSegmentEndPosition}"
Y1="0"
Y2="{Binding ActualHeight, ElementName=TimelineContainerGrid}"
Visibility="{Binding EndSegmentEnabled, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" />
Visibility="{Binding LayerPropertiesViewModel.EndTimelineSegmentViewModel.SegmentEnabled, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" />
<!-- Multi-selection rectangle -->
<Path x:Name="MultiSelectionPath"

View File

@ -15,15 +15,14 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
{
public class TimelineViewModel : Screen, IDisposable
{
private readonly LayerPropertiesViewModel _layerPropertiesViewModel;
private readonly IProfileEditorService _profileEditorService;
private RectangleGeometry _selectionRectangle;
public TimelineViewModel(LayerPropertiesViewModel layerPropertiesViewModel, BindableCollection<LayerPropertyGroupViewModel> layerPropertyGroups, IProfileEditorService profileEditorService)
{
_layerPropertiesViewModel = layerPropertiesViewModel;
_profileEditorService = profileEditorService;
LayerPropertiesViewModel = layerPropertiesViewModel;
LayerPropertyGroups = layerPropertyGroups;
SelectionRectangle = new RectangleGeometry();
@ -31,10 +30,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
_profileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
if (_profileEditorService.SelectedProfileElement != null)
_profileEditorService.SelectedProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
Update();
}
public RenderProfileElement SelectedProfileElement => _profileEditorService.SelectedProfileElement;
public LayerPropertiesViewModel LayerPropertiesViewModel { get; }
public BindableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
public RectangleGeometry SelectionRectangle
@ -43,68 +42,57 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
set => SetAndNotify(ref _selectionRectangle, value);
}
public double StartSegmentWidth => _profileEditorService.PixelsPerSecond * (SelectedProfileElement?.StartSegmentLength.TotalSeconds ?? 0);
public double StartSegmentEndPosition => StartSegmentWidth;
public double MainSegmentWidth => _profileEditorService.PixelsPerSecond * (SelectedProfileElement?.MainSegmentLength.TotalSeconds ?? 0);
public double MainSegmentEndPosition => StartSegmentWidth + MainSegmentWidth;
public double EndSegmentWidth => _profileEditorService.PixelsPerSecond * (SelectedProfileElement?.EndSegmentLength.TotalSeconds ?? 0);
public double EndSegmentEndPosition => StartSegmentWidth + MainSegmentWidth + EndSegmentWidth;
public double TotalTimelineWidth => _profileEditorService.PixelsPerSecond * (SelectedProfileElement?.TimelineLength.TotalSeconds ?? 0);
public bool StartSegmentEnabled => SelectedProfileElement?.StartSegmentLength != TimeSpan.Zero;
public bool EndSegmentEnabled => SelectedProfileElement?.EndSegmentLength != TimeSpan.Zero;
public void Dispose()
public double StartSegmentEndPosition
{
_profileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
_profileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected;
if (_profileEditorService.SelectedProfileElement != null)
_profileEditorService.SelectedProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
get => _startSegmentEndPosition;
set => SetAndNotify(ref _startSegmentEndPosition, value);
}
public double MainSegmentEndPosition
{
get => _mainSegmentEndPosition;
set => SetAndNotify(ref _mainSegmentEndPosition, value);
}
public double EndSegmentEndPosition
{
get => _endSegmentEndPosition;
set => SetAndNotify(ref _endSegmentEndPosition, value);
}
public double TotalTimelineWidth
{
get => _totalTimelineWidth;
set => SetAndNotify(ref _totalTimelineWidth, value);
}
private void Update()
{
StartSegmentEndPosition = LayerPropertiesViewModel.StartTimelineSegmentViewModel.SegmentWidth;
MainSegmentEndPosition = StartSegmentEndPosition + LayerPropertiesViewModel.MainTimelineSegmentViewModel.SegmentWidth;
EndSegmentEndPosition = MainSegmentEndPosition + LayerPropertiesViewModel.EndTimelineSegmentViewModel.SegmentWidth;
TotalTimelineWidth = EndSegmentEndPosition;
}
private void SelectedProfileElementOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(_profileEditorService.SelectedProfileElement.StartSegmentLength))
{
NotifyOfPropertyChange(nameof(StartSegmentWidth));
NotifyOfPropertyChange(nameof(StartSegmentEndPosition));
NotifyOfPropertyChange(nameof(MainSegmentEndPosition));
NotifyOfPropertyChange(nameof(EndSegmentEndPosition));
NotifyOfPropertyChange(nameof(StartSegmentEnabled));
NotifyOfPropertyChange(nameof(TotalTimelineWidth));
}
else if (e.PropertyName == nameof(_profileEditorService.SelectedProfileElement.MainSegmentLength))
{
NotifyOfPropertyChange(nameof(MainSegmentWidth));
NotifyOfPropertyChange(nameof(MainSegmentEndPosition));
NotifyOfPropertyChange(nameof(EndSegmentEndPosition));
NotifyOfPropertyChange(nameof(TotalTimelineWidth));
}
else if (e.PropertyName == nameof(_profileEditorService.SelectedProfileElement.EndSegmentLength))
{
NotifyOfPropertyChange(nameof(EndSegmentWidth));
NotifyOfPropertyChange(nameof(EndSegmentEndPosition));
NotifyOfPropertyChange(nameof(EndSegmentEnabled));
NotifyOfPropertyChange(nameof(TotalTimelineWidth));
}
Update();
}
private void ProfileEditorServiceOnPixelsPerSecondChanged(object sender, EventArgs e)
{
NotifyOfPropertyChange(nameof(StartSegmentWidth));
NotifyOfPropertyChange(nameof(StartSegmentEndPosition));
NotifyOfPropertyChange(nameof(MainSegmentWidth));
NotifyOfPropertyChange(nameof(MainSegmentEndPosition));
NotifyOfPropertyChange(nameof(EndSegmentWidth));
NotifyOfPropertyChange(nameof(EndSegmentEndPosition));
NotifyOfPropertyChange(nameof(TotalTimelineWidth));
Update();
}
private void ProfileEditorServiceOnProfileElementSelected(object? sender, RenderProfileElementEventArgs e)
{
if (e.PreviousRenderProfileElement != null)
e.PreviousRenderProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
e.RenderProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
if (e.RenderProfileElement != null)
e.RenderProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
Update();
}
#region Command handlers
@ -139,26 +127,42 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
public void KeyframeMouseMove(object sender, MouseEventArgs e)
{
var viewModel = (sender as Ellipse)?.DataContext as ITimelineKeyframeViewModel;
if (viewModel == null)
return;
if (sender is Ellipse ellipse && ellipse.DataContext is ITimelineKeyframeViewModel viewModel)
{
if (e.LeftButton == MouseButtonState.Pressed)
MoveSelectedKeyframes(GetCursorTime(e.GetPosition(View)), viewModel);
if (e.LeftButton == MouseButtonState.Pressed)
MoveSelectedKeyframes(GetCursorTime(e.GetPosition(View)), viewModel);
e.Handled = true;
e.Handled = true;
}
}
#region Context menu actions
public void ContextMenuOpening(object sender, EventArgs e)
{
if (sender is Ellipse ellipse && ellipse.DataContext is ITimelineKeyframeViewModel viewModel)
viewModel.PopulateEasingViewModels();
}
public void ContextMenuClosing(object sender, EventArgs e)
{
if (sender is Ellipse ellipse && ellipse.DataContext is ITimelineKeyframeViewModel viewModel)
viewModel.ClearEasingViewModels();
}
public void Copy(ITimelineKeyframeViewModel viewModel)
{
viewModel.Copy();
// viewModel.Copy();
var keyframeViewModels = GetAllKeyframeViewModels();
foreach (var keyframeViewModel in keyframeViewModels.Where(k => k.IsSelected))
keyframeViewModel.Copy();
}
public void Delete(ITimelineKeyframeViewModel viewModel)
{
viewModel.Delete();
var keyframeViewModels = GetAllKeyframeViewModels();
foreach (var keyframeViewModel in keyframeViewModels.Where(k => k.IsSelected))
keyframeViewModel.Delete();
}
#endregion
@ -220,7 +224,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
foreach (var keyframeViewModel in keyframeViewModels.Where(k => k.IsSelected))
keyframeViewModel.ApplyOffsetToKeyframe(sourceKeyframeViewModel);
_layerPropertiesViewModel.ProfileEditorService.UpdateProfilePreview();
_profileEditorService.UpdateProfilePreview();
}
@ -237,6 +241,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
private Point _mouseDragStartPoint;
private bool _mouseDragging;
private double _startSegmentEndPosition;
private double _mainSegmentEndPosition;
private double _endSegmentEndPosition;
private double _totalTimelineWidth;
// ReSharper disable once UnusedMember.Global - Called from view
public void TimelineCanvasMouseDown(object sender, MouseButtonEventArgs e)
@ -335,5 +343,17 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
}
#endregion
#region IDisposable
public void Dispose()
{
_profileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
_profileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected;
if (_profileEditorService.SelectedProfileElement != null)
_profileEditorService.SelectedProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
}
#endregion
}
}

View File

@ -20,6 +20,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
PropertyInputViewModel = _profileEditorService.CreatePropertyInputViewModel(LayerProperty);
_profileEditorService.SelectedDataBindingChanged += ProfileEditorServiceOnSelectedDataBindingChanged;
LayerProperty.VisibilityChanged += LayerPropertyOnVisibilityChanged;
LayerPropertyViewModel.IsVisible = !LayerProperty.IsHidden;
}
public LayerProperty<T> LayerProperty { get; }
@ -51,6 +54,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
{
_propertyInputViewModel?.Dispose();
_profileEditorService.SelectedDataBindingChanged -= ProfileEditorServiceOnSelectedDataBindingChanged;
LayerProperty.VisibilityChanged -= LayerPropertyOnVisibilityChanged;
}
#endregion
@ -83,6 +87,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
NotifyOfPropertyChange(nameof(DataBindingsOpen));
}
private void LayerPropertyOnVisibilityChanged(object? sender, LayerPropertyEventArgs<T> e)
{
LayerPropertyViewModel.IsVisible = !LayerProperty.IsHidden;
}
#endregion
}

View File

@ -1,4 +1,5 @@
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Shared.Services;
@ -10,8 +11,10 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
public FolderViewModel(ProfileElement folder,
IProfileEditorService profileEditorService,
IDialogService dialogService,
IProfileTreeVmFactory profileTreeVmFactory) :
base(folder, profileEditorService, dialogService, profileTreeVmFactory)
IProfileTreeVmFactory profileTreeVmFactory,
ILayerBrushService layerBrushService,
ISurfaceService surfaceService) :
base(folder, profileEditorService, dialogService, profileTreeVmFactory, layerBrushService, surfaceService)
{
}

View File

@ -1,4 +1,5 @@
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Shared.Services;
@ -9,8 +10,10 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
public LayerViewModel(ProfileElement layer,
IProfileEditorService profileEditorService,
IDialogService dialogService,
IProfileTreeVmFactory profileTreeVmFactory) :
base(layer, profileEditorService, dialogService, profileTreeVmFactory)
IProfileTreeVmFactory profileTreeVmFactory,
ILayerBrushService layerBrushService,
ISurfaceService surfaceService) :
base(layer, profileEditorService, dialogService, profileTreeVmFactory, layerBrushService, surfaceService)
{
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Exceptions;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.Dialogs;
@ -16,16 +17,22 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
private readonly IDialogService _dialogService;
private readonly IProfileEditorService _profileEditorService;
private readonly IProfileTreeVmFactory _profileTreeVmFactory;
private readonly ILayerBrushService _layerBrushService;
private readonly ISurfaceService _surfaceService;
private ProfileElement _profileElement;
protected TreeItemViewModel(ProfileElement profileElement,
IProfileEditorService profileEditorService,
IDialogService dialogService,
IProfileTreeVmFactory profileTreeVmFactory)
IProfileTreeVmFactory profileTreeVmFactory,
ILayerBrushService layerBrushService,
ISurfaceService surfaceService)
{
_profileEditorService = profileEditorService;
_dialogService = dialogService;
_profileTreeVmFactory = profileTreeVmFactory;
_layerBrushService = layerBrushService;
_surfaceService = surfaceService;
ProfileElement = profileElement;
@ -129,8 +136,11 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
if (!SupportsChildren)
throw new ArtemisUIException("Cannot add a layer to a profile element of type " + ProfileElement.GetType().Name);
var _ = new Layer(ProfileElement, "New layer");
var layer = new Layer(ProfileElement, "New layer");
layer.ChangeLayerBrush(_layerBrushService.GetDefaultLayerBrush());
layer.AddLeds(_surfaceService.ActiveSurface.Devices.SelectMany(d => d.Leds));
_profileEditorService.UpdateSelectedProfile();
_profileEditorService.ChangeSelectedProfileElement(layer);
}
// ReSharper disable once UnusedMember.Global - Called from view
@ -167,6 +177,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
parent.RemoveExistingElement(this);
_profileEditorService.UpdateSelectedProfile();
_profileEditorService.ChangeSelectedProfileElement(null);
}
public void UpdateProfileElements()

View File

@ -1,8 +1,10 @@
using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Properties;
using Artemis.UI.Shared.Services;
@ -10,10 +12,14 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
{
public class SelectionToolViewModel : VisualizationToolViewModel
{
private readonly ILayerBrushService _layerBrushService;
private Rect _dragRectangle;
public SelectionToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
public SelectionToolViewModel(ProfileViewModel profileViewModel,
IProfileEditorService profileEditorService,
ILayerBrushService layerBrushService) : base(profileViewModel, profileEditorService)
{
_layerBrushService = layerBrushService;
using (var stream = new MemoryStream(Resources.aero_crosshair))
{
Cursor = new Cursor(stream);
@ -52,20 +58,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
}
// If no layer selected, apply it to a new layer in the selected folder
else if (ProfileEditorService.SelectedProfileElement is Folder folder)
{
var newLayer = new Layer(folder, "New layer");
newLayer.AddLeds(selectedLeds);
ProfileEditorService.ChangeSelectedProfileElement(newLayer);
ProfileEditorService.UpdateSelectedProfileElement();
}
CreateLayer(folder, selectedLeds);
// If no folder selected, apply it to a new layer in the root folder
else
{
var rootFolder = ProfileEditorService.SelectedProfile.GetRootFolder();
var newLayer = new Layer(rootFolder, "New layer");
newLayer.AddLeds(selectedLeds);
ProfileEditorService.ChangeSelectedProfileElement(newLayer);
ProfileEditorService.UpdateSelectedProfileElement();
CreateLayer(rootFolder, selectedLeds);
}
}
@ -89,5 +87,14 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
DragRectangle = selectedRect;
}
private void CreateLayer(Folder folder, List<ArtemisLed> selectedLeds)
{
var newLayer = new Layer(folder, "New layer");
newLayer.ChangeLayerBrush(_layerBrushService.GetDefaultLayerBrush());
newLayer.AddLeds(selectedLeds);
ProfileEditorService.ChangeSelectedProfileElement(newLayer);
ProfileEditorService.UpdateSelectedProfileElement();
}
}
}

View File

@ -6,9 +6,17 @@
xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Tabs.General"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:dataTemplateSelectors="clr-namespace:Artemis.UI.DataTemplateSelectors"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:GeneralSettingsTabViewModel}">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Artemis.UI;component/ResourceDictionaries/LayerBrushDescriptors.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<StackPanel Margin="15" MaxWidth="800">
<!-- General settings -->
@ -187,6 +195,39 @@
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" IsChecked="{Binding ShowDataModelValues}" />
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Default brush</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" TextWrapping="Wrap">
Sets the default brush that is applied to new layers
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ComboBox Width="132"
Margin="0 2"
Padding="0 -1"
Height="15"
materialDesign:ComboBoxAssist.ClassicMode="True"
materialDesign:ValidationAssist.UsePopup="True"
HorizontalAlignment="Left"
ItemsSource="{Binding Path=LayerBrushDescriptors}"
SelectedValue="{Binding Path=SelectedLayerBrushDescriptor}"
ItemTemplateSelector="{dataTemplateSelectors:ComboBoxTemplateSelector
SelectedItemTemplate={StaticResource SimpleLayerBrushDescriptorTemplate},
DropdownItemsTemplate={StaticResource ExtendedLayerBrushDescriptorTemplate}}" />
</StackPanel>
</Grid>
</StackPanel>
</materialDesign:Card>

View File

@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.LayerBrushes;
using Artemis.Core.Services;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared;
@ -22,8 +23,9 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
private List<Tuple<string, double>> _renderScales;
private List<int> _sampleSizes;
private List<Tuple<string, int>> _targetFrameRates;
private readonly PluginSetting<LayerBrushReference> _defaultLayerBrushDescriptor;
public GeneralSettingsTabViewModel(IDialogService dialogService, IDebugService debugService, ISettingsService settingsService)
public GeneralSettingsTabViewModel(IDialogService dialogService, IDebugService debugService, ISettingsService settingsService, IPluginService pluginService)
{
DisplayName = "GENERAL";
@ -43,6 +45,27 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
// Anything else is kinda broken right now
SampleSizes = new List<int> {1, 9};
var layerBrushProviders = pluginService.GetPluginsOfType<LayerBrushProvider>();
LayerBrushDescriptors = new BindableCollection<LayerBrushDescriptor>(layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors));
_defaultLayerBrushDescriptor = _settingsService.GetSetting("ProfileEditor.DefaultLayerBrushDescriptor", new LayerBrushReference
{
BrushPluginGuid = Guid.Parse("92a9d6ba-6f7a-4937-94d5-c1d715b4141a"),
BrushType = "ColorBrush"
});
}
public BindableCollection<LayerBrushDescriptor> LayerBrushDescriptors { get; }
public LayerBrushDescriptor SelectedLayerBrushDescriptor
{
get => LayerBrushDescriptors.FirstOrDefault(d => d.MatchesLayerBrushReference(_defaultLayerBrushDescriptor.Value));
set
{
_defaultLayerBrushDescriptor.Value = new LayerBrushReference(value);
_defaultLayerBrushDescriptor.Save();
}
}
public BindableCollection<ValueDescription> LogLevels { get; }
@ -66,7 +89,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
set => SetAndNotify(ref _sampleSizes, value);
}
public bool StartWithWindows
{
get => _settingsService.GetSetting("UI.AutoRun", false).Value;