mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Profile editor - Many runtime fixes, UI is back to usable!
This commit is contained in:
parent
db9d9fb4e6
commit
7fff1a593f
@ -1,75 +0,0 @@
|
||||
// Pointers used to auto-update.
|
||||
// NOTE: If you're going to copy paste these for your own application, include a link to https://github.com/SpoinkyNL/Artemis
|
||||
[
|
||||
{
|
||||
"Game":"RocketLeague",
|
||||
"GameVersion":"1.30",
|
||||
"GameAddresses":[
|
||||
{
|
||||
"Description":"Boost",
|
||||
"BasePointer":{
|
||||
"value":23986356
|
||||
},
|
||||
"Offsets":[
|
||||
196,
|
||||
24,
|
||||
904,
|
||||
1852,
|
||||
548
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Game":"WorldOfWarcraft",
|
||||
"GameVersion":"7.0.3.22810",
|
||||
"GameAddresses":[
|
||||
{
|
||||
"Description":"ObjectManager",
|
||||
"BasePointer":{
|
||||
"value":22511728
|
||||
},
|
||||
"Offsets":null
|
||||
},
|
||||
{
|
||||
"Description":"LocalPlayer",
|
||||
"BasePointer":{
|
||||
"value":23715600
|
||||
},
|
||||
"Offsets":null
|
||||
},
|
||||
{
|
||||
"Description":"NameCache",
|
||||
"BasePointer":{
|
||||
"value":22142184
|
||||
},
|
||||
"Offsets":null
|
||||
},
|
||||
{
|
||||
"Description":"TargetGuid",
|
||||
"BasePointer":{
|
||||
"value":24758592
|
||||
},
|
||||
"Offsets":null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Game":"Terraria",
|
||||
"GameVersion":"1.3.4.4",
|
||||
"GameAddresses":[
|
||||
{
|
||||
"Description":"PlayerBase",
|
||||
"BasePointer":{
|
||||
"value":3784824
|
||||
},
|
||||
"Offsets":[
|
||||
640,
|
||||
1728,
|
||||
1652,
|
||||
60
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@ -37,6 +37,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Ben.Demystifier" Version="0.1.6" />
|
||||
<PackageReference Include="HidSharp" Version="2.1.0" />
|
||||
<PackageReference Include="Humanizer.Core" Version="2.8.26" />
|
||||
<PackageReference Include="LiteDB" Version="5.0.8" />
|
||||
<PackageReference Include="McMaster.NETCore.Plugins" Version="1.3.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
|
||||
@ -41,13 +41,13 @@ namespace Artemis.Core
|
||||
if (DataBinding.LayerProperty.PropertyDescription.MinInputValue is float min)
|
||||
value = Math.Max(value, min);
|
||||
|
||||
ValueSetter?.Invoke(value);
|
||||
SetExpression?.Invoke(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override float GetValue()
|
||||
{
|
||||
return ValueGetter?.Invoke() ?? 0f;
|
||||
return GetExpression(DataBinding.LayerProperty.CurrentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -26,13 +26,13 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override void ApplyValue(object value)
|
||||
{
|
||||
ValueSetter?.Invoke(value);
|
||||
SetExpression?.Invoke(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object GetValue()
|
||||
{
|
||||
return ValueGetter?.Invoke();
|
||||
return GetExpression(DataBinding.LayerProperty.CurrentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,12 +3,12 @@
|
||||
namespace Artemis.Core
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class IntDataBindingConverter : FloatDataBindingConverter<int>
|
||||
public class IntDataBindingConverter : IntDataBindingConverter<int>
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public class IntDataBindingConverter<T> : DataBindingConverter<T, int> where T : ILayerProperty
|
||||
public class IntDataBindingConverter<T> : DataBindingConverter<T, int>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="IntDataBindingConverter{T}" /> class
|
||||
@ -41,13 +41,13 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override void ApplyValue(int value)
|
||||
{
|
||||
ValueSetter?.Invoke(value);
|
||||
SetExpression?.Invoke(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetValue()
|
||||
{
|
||||
return ValueGetter?.Invoke() ?? 0;
|
||||
return GetExpression(DataBinding.LayerProperty.CurrentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13,12 +13,12 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// A dynamically compiled getter pointing to the data bound property
|
||||
/// </summary>
|
||||
public Func<TProperty> ValueGetter { get; private set; }
|
||||
public Func<TLayerProperty, TProperty> GetExpression { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// A dynamically compiled setter pointing to the data bound property
|
||||
/// </summary>
|
||||
public Action<TProperty> ValueSetter { get; private set; }
|
||||
public Action<TProperty> SetExpression { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data binding this converter is applied to
|
||||
@ -75,32 +75,12 @@ namespace Artemis.Core
|
||||
internal void Initialize(DataBinding<TLayerProperty, TProperty> dataBinding)
|
||||
{
|
||||
DataBinding = dataBinding;
|
||||
ValueGetter = CreateValueGetter();
|
||||
ValueSetter = CreateValueSetter();
|
||||
GetExpression = dataBinding.Registration.PropertyExpression.Compile();
|
||||
SetExpression = CreateValueSetter();
|
||||
|
||||
OnInitialized();
|
||||
}
|
||||
|
||||
private Func<TProperty> CreateValueGetter()
|
||||
{
|
||||
if (DataBinding.TargetProperty?.DeclaringType == null)
|
||||
return null;
|
||||
|
||||
var getterMethod = DataBinding.TargetProperty.GetGetMethod();
|
||||
if (getterMethod == null)
|
||||
return null;
|
||||
|
||||
var constant = Expression.Constant(DataBinding.LayerProperty);
|
||||
// The path is null if the registration is applied to the root (LayerProperty.CurrentValue)
|
||||
var property = DataBinding.Registration.Path == null
|
||||
? Expression.Property(constant, DataBinding.TargetProperty)
|
||||
: (MemberExpression) DataBinding.Registration.Path.Split('.').Aggregate<string, Expression>(constant, Expression.Property);
|
||||
|
||||
var lambda = Expression.Lambda<Func<TProperty>>(property);
|
||||
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
private Action<TProperty> CreateValueSetter()
|
||||
{
|
||||
if (DataBinding.TargetProperty?.DeclaringType == null)
|
||||
@ -110,10 +90,9 @@ namespace Artemis.Core
|
||||
if (setterMethod == null)
|
||||
return null;
|
||||
|
||||
var constant = Expression.Constant(DataBinding.LayerProperty);
|
||||
var propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
|
||||
|
||||
var body = Expression.Call(constant, setterMethod, propertyValue);
|
||||
var body = DataBinding.Registration.PropertyExpression;
|
||||
var lambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Artemis.Core
|
||||
@ -7,16 +8,13 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public class DataBindingRegistration<TLayerProperty, TProperty> : IDataBindingRegistration
|
||||
{
|
||||
internal DataBindingRegistration(
|
||||
LayerProperty<TLayerProperty> layerProperty,
|
||||
DataBindingConverter<TLayerProperty, TProperty> converter,
|
||||
PropertyInfo property,
|
||||
string path)
|
||||
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));
|
||||
Property = property ?? throw new ArgumentNullException(nameof(property));
|
||||
Path = path ?? throw new ArgumentNullException(nameof(path));
|
||||
PropertyExpression = propertyExpression ?? throw new ArgumentNullException(nameof(propertyExpression));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -24,22 +22,21 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public LayerProperty<TLayerProperty> LayerProperty { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the converter that's used by the data binding
|
||||
/// </summary>
|
||||
public DataBindingConverter<TLayerProperty, TProperty> Converter { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the expression that that accesses the property
|
||||
/// </summary>
|
||||
public Expression<Func<TLayerProperty, TProperty>> PropertyExpression { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the registered property
|
||||
/// </summary>
|
||||
public PropertyInfo Property { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path of the registered property on the layer property
|
||||
/// </summary>
|
||||
public string Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data binding created using this registration
|
||||
/// </summary>
|
||||
@ -51,7 +48,7 @@ namespace Artemis.Core
|
||||
if (DataBinding != null)
|
||||
return DataBinding;
|
||||
|
||||
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetProperty == Path);
|
||||
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetProperty == PropertyExpression.ToString());
|
||||
if (dataBinding == null)
|
||||
return null;
|
||||
|
||||
|
||||
@ -64,8 +64,8 @@ namespace Artemis.Core
|
||||
_leds = new List<ArtemisLed>();
|
||||
_expandedPropertyGroups = new List<string>();
|
||||
|
||||
Initialize();
|
||||
Load();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
internal LayerEntity LayerEntity { get; set; }
|
||||
@ -148,11 +148,22 @@ namespace Artemis.Core
|
||||
LayerBrushStore.LayerBrushRemoved += LayerBrushStoreOnLayerBrushRemoved;
|
||||
|
||||
// Layers have two hardcoded property groups, instantiate them
|
||||
var generalAttribute = Attribute.GetCustomAttribute(
|
||||
GetType().GetProperty(nameof(General)),
|
||||
typeof(PropertyGroupDescriptionAttribute)
|
||||
);
|
||||
var transformAttribute = Attribute.GetCustomAttribute(
|
||||
GetType().GetProperty(nameof(Transform)),
|
||||
typeof(PropertyGroupDescriptionAttribute)
|
||||
);
|
||||
General.GroupDescription = (PropertyGroupDescriptionAttribute) generalAttribute;
|
||||
General.Initialize(this, "General.", Constants.CorePluginInfo);
|
||||
Transform.GroupDescription = (PropertyGroupDescriptionAttribute) transformAttribute;
|
||||
Transform.Initialize(this, "Transform.", Constants.CorePluginInfo);
|
||||
|
||||
General.ShapeType.BaseValueChanged += ShapeTypeOnBaseValueChanged;
|
||||
ApplyShapeType();
|
||||
ActivateLayerBrush();
|
||||
}
|
||||
|
||||
#region Storage
|
||||
@ -165,8 +176,6 @@ namespace Artemis.Core
|
||||
Order = LayerEntity.Order;
|
||||
|
||||
_expandedPropertyGroups.AddRange(LayerEntity.ExpandedPropertyGroups);
|
||||
ActivateLayerBrush();
|
||||
|
||||
LoadRenderElement();
|
||||
}
|
||||
|
||||
@ -710,6 +719,9 @@ namespace Artemis.Core
|
||||
internal void ActivateLayerBrush()
|
||||
{
|
||||
var current = General.BrushReference.CurrentValue;
|
||||
if (current == null)
|
||||
return;
|
||||
|
||||
var descriptor = LayerBrushStore.Get(current.BrushPluginGuid, current.BrushType)?.LayerBrushDescriptor;
|
||||
descriptor?.CreateInstance(this);
|
||||
|
||||
@ -729,7 +741,7 @@ namespace Artemis.Core
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void LayerBrushStoreOnLayerBrushRemoved(object sender, LayerBrushStoreEvent e)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core
|
||||
@ -20,5 +21,15 @@ namespace Artemis.Core
|
||||
/// </para>
|
||||
/// </summary>
|
||||
void Initialize(RenderProfileElement profileElement, LayerPropertyGroup group, PropertyEntity entity, bool fromStorage, PropertyDescriptionAttribute description);
|
||||
|
||||
/// <summary>
|
||||
/// 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; }
|
||||
}
|
||||
}
|
||||
@ -61,9 +61,7 @@ namespace Artemis.Core
|
||||
|
||||
private bool _isHidden;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the property is hidden in the UI
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public bool IsHidden
|
||||
{
|
||||
get => _isHidden;
|
||||
@ -335,36 +333,21 @@ namespace Artemis.Core
|
||||
return _dataBindingRegistrations;
|
||||
}
|
||||
|
||||
public void RegisterDataBindingProperty<TProperty>(Expression<Func<T, TProperty>> propertyLambda, DataBindingConverter<T, TProperty> converter)
|
||||
public void RegisterDataBindingProperty<TProperty>(Expression<Func<T, TProperty>> propertyExpression, DataBindingConverter<T, TProperty> converter)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("LayerProperty");
|
||||
|
||||
// If the lambda references to itself, use the property info of public new T CurrentValue
|
||||
PropertyInfo propertyInfo;
|
||||
string path = null;
|
||||
if (propertyLambda.Parameters[0] == propertyLambda.Body)
|
||||
propertyInfo = GetType().GetProperties().FirstOrDefault(p => p.Name == nameof(CurrentValue) && p.PropertyType == typeof(T));
|
||||
else
|
||||
{
|
||||
propertyInfo = ReflectionUtilities.GetPropertyInfo(CurrentValue, propertyLambda);
|
||||
// Deconstruct the lambda
|
||||
var current = (MemberExpression) propertyLambda.Body;
|
||||
path = current.Member.Name;
|
||||
while (current.Expression is MemberExpression memberExpression)
|
||||
{
|
||||
path = current.Member.Name + "." + path;
|
||||
current = memberExpression;
|
||||
}
|
||||
}
|
||||
if (propertyExpression.Body.NodeType != ExpressionType.MemberAccess && propertyExpression.Body.NodeType != ExpressionType.Parameter)
|
||||
throw new ArtemisCoreException("Provided expression is invalid, it must be 'value => value' or 'value => value.Property'");
|
||||
|
||||
if (converter.SupportedType != propertyInfo.PropertyType)
|
||||
if (converter.SupportedType != propertyExpression.ReturnType)
|
||||
{
|
||||
throw new ArtemisCoreException($"Cannot register data binding property for property {propertyInfo.Name} " +
|
||||
throw new ArtemisCoreException($"Cannot register data binding property for property {PropertyDescription.Name} " +
|
||||
"because the provided converter does not support the property's type");
|
||||
}
|
||||
|
||||
_dataBindingRegistrations.Add(new DataBindingRegistration<T, TProperty>(this, converter, propertyInfo, path));
|
||||
_dataBindingRegistrations.Add(new DataBindingRegistration<T, TProperty>(this, converter, propertyExpression));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -432,7 +415,6 @@ namespace Artemis.Core
|
||||
Entity = entity ?? throw new ArgumentNullException(nameof(entity));
|
||||
PropertyDescription = description ?? throw new ArgumentNullException(nameof(description));
|
||||
IsLoadedFromStorage = fromStorage;
|
||||
|
||||
LayerPropertyGroup.PropertyGroupUpdating += (sender, args) => Update(args.DeltaTime);
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ using Artemis.Core.LayerBrushes;
|
||||
using Artemis.Core.LayerEffects;
|
||||
using Artemis.Core.Properties;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Humanizer;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@ -215,6 +216,10 @@ namespace Artemis.Core
|
||||
if (instance == null)
|
||||
throw new ArtemisPluginException($"Failed to create instance of layer property 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(propertyDescription.Name))
|
||||
propertyDescription.Name = propertyInfo.Name.Humanize();
|
||||
|
||||
var entity = GetPropertyEntity(ProfileElement, path + propertyInfo.Name, out var fromStorage);
|
||||
instance.Initialize(ProfileElement, this, entity, fromStorage, propertyDescription);
|
||||
propertyInfo.SetValue(this, instance);
|
||||
|
||||
@ -35,6 +35,7 @@ namespace Artemis.Core.LayerBrushes
|
||||
internal void InitializeProperties()
|
||||
{
|
||||
Properties = Activator.CreateInstance<T>();
|
||||
Properties.GroupDescription ??= new PropertyGroupDescriptionAttribute {Name = Descriptor.DisplayName, Description = Descriptor.Description};
|
||||
Properties.LayerBrush = this;
|
||||
Properties.Initialize(Layer, "LayerBrush.", PluginInfo);
|
||||
PropertiesInitialized = true;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Artemis.Core.Services;
|
||||
using Ninject;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
@ -43,11 +44,6 @@ namespace Artemis.Core.LayerBrushes
|
||||
/// </summary>
|
||||
public LayerBrushProvider LayerBrushProvider { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the kernel used to instantiate the described layer brush
|
||||
/// </summary>
|
||||
internal IKernel Kernel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the described brush and applies it to the layer
|
||||
/// </summary>
|
||||
@ -56,7 +52,7 @@ namespace Artemis.Core.LayerBrushes
|
||||
if (layer.LayerBrush != null)
|
||||
throw new ArtemisCoreException("Layer already has an instantiated layer brush");
|
||||
|
||||
var brush = (BaseLayerBrush) Kernel.Get(LayerBrushType);
|
||||
var brush = (BaseLayerBrush) CoreService.Kernel.Get(LayerBrushType);
|
||||
brush.Layer = layer;
|
||||
brush.Descriptor = this;
|
||||
brush.Initialize();
|
||||
|
||||
@ -41,11 +41,14 @@ namespace Artemis.Core.LayerBrushes
|
||||
if (!Enabled)
|
||||
throw new ArtemisPluginException(PluginInfo, "Can only add a layer brush descriptor when the plugin is enabled");
|
||||
|
||||
_layerBrushDescriptors.Add(new LayerBrushDescriptor(displayName, description, icon, typeof(T), this));
|
||||
var descriptor = new LayerBrushDescriptor(displayName, description, icon, typeof(T), this);
|
||||
_layerBrushDescriptors.Add(descriptor);
|
||||
LayerBrushStore.Add(descriptor);
|
||||
}
|
||||
|
||||
private void OnPluginDisabled(object sender, EventArgs e)
|
||||
{
|
||||
// The store will clean up the registrations by itself, the plugin just needs to clear its own list
|
||||
_layerBrushDescriptors.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Ninject;
|
||||
|
||||
@ -44,12 +45,7 @@ namespace Artemis.Core.LayerEffects
|
||||
/// The plugin that provided this <see cref="LayerEffectDescriptor" />
|
||||
/// </summary>
|
||||
public LayerEffectProvider LayerEffectProvider { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the kernel used to instantiate the described layer effect
|
||||
/// </summary>
|
||||
internal IKernel Kernel { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating if this descriptor is a placeholder for a missing plugin
|
||||
/// </summary>
|
||||
@ -70,7 +66,7 @@ namespace Artemis.Core.LayerEffects
|
||||
return;
|
||||
}
|
||||
|
||||
var effect = (BaseLayerEffect) Kernel.Get(LayerEffectType);
|
||||
var effect = (BaseLayerEffect)CoreService.Kernel.Get(LayerEffectType);
|
||||
effect.ProfileElement = renderElement;
|
||||
effect.EntityId = entity.Id;
|
||||
effect.Order = entity.Order;
|
||||
|
||||
@ -41,11 +41,14 @@ namespace Artemis.Core.LayerEffects
|
||||
if (!Enabled)
|
||||
throw new ArtemisPluginException(PluginInfo, "Can only add a layer effect descriptor when the plugin is enabled");
|
||||
|
||||
_layerEffectDescriptors.Add(new LayerEffectDescriptor(displayName, description, icon, typeof(T), this));
|
||||
var descriptor = new LayerEffectDescriptor(displayName, description, icon, typeof(T), this);
|
||||
_layerEffectDescriptors.Add(descriptor);
|
||||
LayerEffectStore.Add(descriptor);
|
||||
}
|
||||
|
||||
private void OnPluginDisabled(object sender, EventArgs e)
|
||||
{
|
||||
// The store will clean up the registrations by itself, the plugin just needs to clear its own list
|
||||
_layerEffectDescriptors.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,8 +23,9 @@ namespace Artemis.Core.Services
|
||||
/// </summary>
|
||||
internal class CoreService : ICoreService
|
||||
{
|
||||
internal static IKernel Kernel;
|
||||
|
||||
private readonly Stopwatch _frameStopWatch;
|
||||
private readonly IKernel _kernel;
|
||||
private readonly ILogger _logger;
|
||||
private readonly PluginSetting<LogEventLevel> _loggingLevel;
|
||||
private readonly IPluginService _pluginService;
|
||||
@ -37,9 +38,9 @@ namespace Artemis.Core.Services
|
||||
|
||||
// ReSharper disable once UnusedParameter.Local - Storage migration service is injected early to ensure it runs before anything else
|
||||
public CoreService(IKernel kernel, ILogger logger, StorageMigrationService _, ISettingsService settingsService, IPluginService pluginService,
|
||||
IRgbService rgbService, ISurfaceService surfaceService, IProfileService profileService)
|
||||
IRgbService rgbService, ISurfaceService surfaceService, IProfileService profileService, IModuleService moduleService)
|
||||
{
|
||||
_kernel = kernel;
|
||||
Kernel = kernel;
|
||||
_logger = logger;
|
||||
_pluginService = pluginService;
|
||||
_rgbService = rgbService;
|
||||
@ -80,7 +81,7 @@ namespace Artemis.Core.Services
|
||||
_logger.Information("Initializing Artemis Core version {version}", versionAttribute?.InformationalVersion);
|
||||
ApplyLoggingLevel();
|
||||
|
||||
DeserializationLogger.Initialize(_kernel);
|
||||
DeserializationLogger.Initialize(Kernel);
|
||||
|
||||
// Initialize the services
|
||||
_pluginService.CopyBuiltInPlugins();
|
||||
|
||||
@ -2,24 +2,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.LayerBrushes;
|
||||
using Ninject;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
internal class LayerBrushService : ILayerBrushService
|
||||
{
|
||||
private readonly IKernel _kernel;
|
||||
|
||||
public LayerBrushService(IKernel kernel)
|
||||
{
|
||||
_kernel = kernel;
|
||||
}
|
||||
public LayerBrushRegistration RegisterLayerBrush(LayerBrushDescriptor descriptor)
|
||||
{
|
||||
if (descriptor == null)
|
||||
throw new ArgumentNullException(nameof(descriptor));
|
||||
|
||||
descriptor.Kernel = _kernel;
|
||||
return LayerBrushStore.Add(descriptor);
|
||||
}
|
||||
|
||||
@ -35,4 +27,4 @@ namespace Artemis.Core.Services
|
||||
return LayerBrushStore.GetAll().Select(r => r.LayerBrushDescriptor).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,25 +2,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.LayerEffects;
|
||||
using Ninject;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
internal class LayerEffectService : ILayerEffectService
|
||||
{
|
||||
private readonly IKernel _kernel;
|
||||
|
||||
public LayerEffectService(IKernel kernel)
|
||||
{
|
||||
_kernel = kernel;
|
||||
}
|
||||
|
||||
public LayerEffectRegistration RegisterLayerEffect(LayerEffectDescriptor descriptor)
|
||||
{
|
||||
if (descriptor == null)
|
||||
throw new ArgumentNullException(nameof(descriptor));
|
||||
|
||||
descriptor.Kernel = _kernel;
|
||||
return LayerEffectStore.Add(descriptor);
|
||||
}
|
||||
|
||||
|
||||
@ -74,6 +74,16 @@ namespace Artemis.UI.Shared.Services
|
||||
/// <returns></returns>
|
||||
PropertyInputRegistration RegisterPropertyInput<T>(PluginInfo pluginInfo) where T : PropertyInputViewModel;
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new property input view model used in the profile editor for the generic type defined in
|
||||
/// <see cref="PropertyInputViewModel{T}" />
|
||||
/// <para>Note: Registration will remove itself on plugin disable so you don't have to</para>
|
||||
/// </summary>
|
||||
/// <param name="viewModelType"></param>
|
||||
/// <param name="pluginInfo"></param>
|
||||
/// <returns></returns>
|
||||
PropertyInputRegistration RegisterPropertyInput(Type viewModelType, PluginInfo pluginInfo);
|
||||
|
||||
void RemovePropertyInput(PropertyInputRegistration registration);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -196,10 +196,25 @@ namespace Artemis.UI.Shared.Services
|
||||
|
||||
public PropertyInputRegistration RegisterPropertyInput<T>(PluginInfo pluginInfo) where T : PropertyInputViewModel
|
||||
{
|
||||
var viewModelType = typeof(T);
|
||||
return RegisterPropertyInput(typeof(T), pluginInfo);
|
||||
}
|
||||
|
||||
public PropertyInputRegistration RegisterPropertyInput(Type viewModelType, PluginInfo pluginInfo)
|
||||
{
|
||||
if (!typeof(PropertyInputViewModel).IsAssignableFrom(viewModelType))
|
||||
throw new ArtemisSharedUIException($"Property input VM type must implement {nameof(PropertyInputViewModel)}");
|
||||
|
||||
lock (_registeredPropertyEditors)
|
||||
{
|
||||
var supportedType = viewModelType.BaseType.GetGenericArguments()[0];
|
||||
// If the supported type is a generic, assume there is a base type
|
||||
if (supportedType.IsGenericParameter)
|
||||
{
|
||||
if (supportedType.BaseType == null)
|
||||
throw new ArtemisSharedUIException($"Generic property input VM type must have a type constraint");
|
||||
supportedType = supportedType.BaseType;
|
||||
}
|
||||
|
||||
var existing = _registeredPropertyEditors.FirstOrDefault(r => r.SupportedType == supportedType);
|
||||
if (existing != null)
|
||||
{
|
||||
@ -267,12 +282,24 @@ namespace Artemis.UI.Shared.Services
|
||||
|
||||
public PropertyInputViewModel<T> CreatePropertyInputViewModel<T>(LayerProperty<T> layerProperty)
|
||||
{
|
||||
Type viewModelType = null;
|
||||
var registration = RegisteredPropertyEditors.FirstOrDefault(r => r.SupportedType == typeof(T));
|
||||
if (registration == null)
|
||||
|
||||
// Check for enums if no supported type was found
|
||||
if (registration == null && typeof(T).IsEnum)
|
||||
{
|
||||
// The enum VM will likely be a generic, that requires creating a generic type matching the layer property
|
||||
registration = RegisteredPropertyEditors.FirstOrDefault(r => r.SupportedType == typeof(Enum));
|
||||
if (registration != null && registration.ViewModelType.IsGenericType)
|
||||
viewModelType = registration.ViewModelType.MakeGenericType(layerProperty.GetType().GenericTypeArguments);
|
||||
}
|
||||
else if (registration != null)
|
||||
viewModelType = registration.ViewModelType;
|
||||
else
|
||||
return null;
|
||||
|
||||
var parameter = new ConstructorArgument("layerProperty", layerProperty);
|
||||
return (PropertyInputViewModel<T>) Kernel.Get(registration.ViewModelType, parameter);
|
||||
return (PropertyInputViewModel<T>) Kernel.Get(viewModelType, parameter);
|
||||
}
|
||||
|
||||
public ProfileModule GetCurrentModule()
|
||||
|
||||
@ -82,10 +82,16 @@ namespace Artemis.UI.Ninject.Factories
|
||||
LayerPropertyGroupViewModel LayerPropertyGroupViewModel(LayerPropertyGroup layerPropertyGroup);
|
||||
TreeGroupViewModel TreeGroupViewModel(LayerPropertyGroupViewModel layerPropertyGroupViewModel);
|
||||
TimelineGroupViewModel TimelineGroupViewModel(LayerPropertyGroupViewModel layerPropertyGroupViewModel);
|
||||
|
||||
|
||||
TreeViewModel TreeViewModel(LayerPropertiesViewModel layerPropertiesViewModel, BindableCollection<LayerPropertyGroupViewModel> layerPropertyGroups);
|
||||
EffectsViewModel EffectsViewModel(LayerPropertiesViewModel layerPropertiesViewModel);
|
||||
TimelineViewModel TimelineViewModel(LayerPropertiesViewModel layerPropertiesViewModel, BindableCollection<LayerPropertyGroupViewModel> layerPropertyGroups);
|
||||
TimelineSegmentViewModel TimelineSegmentViewModel(SegmentViewModelType segment, BindableCollection<LayerPropertyGroupViewModel> layerPropertyGroups);
|
||||
}
|
||||
|
||||
public interface IPropertyVmFactory
|
||||
{
|
||||
ITreePropertyViewModel TreePropertyViewModel(ILayerProperty layerProperty, LayerPropertyViewModel layerPropertyViewModel);
|
||||
ITimelinePropertyViewModel TimelinePropertyViewModel(ILayerProperty layerProperty, LayerPropertyViewModel layerPropertyViewModel);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree;
|
||||
using Ninject.Extensions.Factory;
|
||||
|
||||
namespace Artemis.UI.Ninject.InstanceProviders
|
||||
{
|
||||
public class LayerPropertyViewModelInstanceProvider : StandardInstanceProvider
|
||||
{
|
||||
protected override Type GetType(MethodInfo methodInfo, object[] arguments)
|
||||
{
|
||||
if (methodInfo.ReturnType != typeof(ITreePropertyViewModel) && methodInfo.ReturnType != typeof(ITimelinePropertyViewModel))
|
||||
return base.GetType(methodInfo, arguments);
|
||||
|
||||
// Find LayerProperty type
|
||||
var layerPropertyType = arguments[0].GetType();
|
||||
while (layerPropertyType != null && (!layerPropertyType.IsGenericType || layerPropertyType.GetGenericTypeDefinition() != typeof(LayerProperty<>)))
|
||||
layerPropertyType = layerPropertyType.BaseType;
|
||||
if (layerPropertyType == null)
|
||||
return base.GetType(methodInfo, arguments);
|
||||
|
||||
if (methodInfo.ReturnType == typeof(ITreePropertyViewModel))
|
||||
return typeof(TreePropertyViewModel<>).MakeGenericType(layerPropertyType.GetGenericArguments());
|
||||
if (methodInfo.ReturnType == typeof(ITimelinePropertyViewModel))
|
||||
return typeof(TimelinePropertyViewModel<>).MakeGenericType(layerPropertyType.GetGenericArguments());
|
||||
|
||||
return base.GetType(methodInfo, arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Ninject.InstanceProviders;
|
||||
using Artemis.UI.Screens;
|
||||
using Artemis.UI.Screens.ProfileEditor;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
@ -7,6 +8,7 @@ using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Stylet;
|
||||
using FluentValidation;
|
||||
using Ninject.Extensions.Conventions;
|
||||
using Ninject.Extensions.Factory;
|
||||
using Ninject.Modules;
|
||||
using Stylet;
|
||||
|
||||
@ -48,6 +50,8 @@ namespace Artemis.UI.Ninject
|
||||
.BindToFactory();
|
||||
});
|
||||
|
||||
Kernel.Bind<IPropertyVmFactory>().ToFactory(() => new LayerPropertyViewModelInstanceProvider());
|
||||
|
||||
// Bind profile editor VMs
|
||||
Kernel.Bind(x =>
|
||||
{
|
||||
|
||||
@ -1,32 +1,49 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
public class DataBindingsViewModel<T> : Conductor<IDataBindingViewModel>.Collection.AllActive
|
||||
public class DataBindingsViewModel : Conductor<IDataBindingViewModel>.Collection.AllActive
|
||||
{
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
|
||||
public DataBindingsViewModel(LayerProperty<T> layerProperty, IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
|
||||
public DataBindingsViewModel(IProfileEditorService profileEditorService, IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||
LayerProperty = layerProperty;
|
||||
Initialise();
|
||||
|
||||
_profileEditorService.SelectedDataBindingChanged += ProfileEditorServiceOnSelectedDataBindingChanged;
|
||||
CreateDataBindingViewModels();
|
||||
}
|
||||
|
||||
public LayerProperty<T> LayerProperty { get; }
|
||||
|
||||
private void Initialise()
|
||||
private void CreateDataBindingViewModels()
|
||||
{
|
||||
var registrations = LayerProperty.GetAllDataBindingRegistrations();
|
||||
Items.Clear();
|
||||
|
||||
var layerProperty = _profileEditorService.SelectedDataBinding;
|
||||
if (layerProperty == null)
|
||||
return;
|
||||
|
||||
var registrations = layerProperty.GetAllDataBindingRegistrations();
|
||||
|
||||
// Create a data binding VM for each data bindable property. These VMs will be responsible for retrieving
|
||||
// and creating the actual data bindings
|
||||
foreach (var registration in registrations)
|
||||
ActivateItem(_dataBindingsVmFactory.DataBindingViewModel(registration));
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
_profileEditorService.SelectedDataBindingChanged -= ProfileEditorServiceOnSelectedDataBindingChanged;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
private void ProfileEditorServiceOnSelectedDataBindingChanged(object? sender, EventArgs e)
|
||||
{
|
||||
CreateDataBindingViewModels();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,42 +23,62 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
public class LayerPropertiesViewModel : Conductor<IScreen>.Collection.AllActive, IProfileEditorPanelViewModel, IDropTarget
|
||||
{
|
||||
private readonly ILayerPropertyVmFactory _layerPropertyVmFactory;
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private LayerPropertyGroupViewModel _brushPropertyGroup;
|
||||
private DataBindingsViewModel _dataBindingsViewModel;
|
||||
private EffectsViewModel _effectsViewModel;
|
||||
private TimelineSegmentViewModel _endTimelineSegmentViewModel;
|
||||
private BindableCollection<LayerPropertyGroupViewModel> _layerPropertyGroups;
|
||||
private TimelineSegmentViewModel _mainTimelineSegmentViewModel;
|
||||
private bool _playing;
|
||||
private int _propertyTreeIndex;
|
||||
private bool _repeatAfterLastKeyframe;
|
||||
private int _rightSideIndex;
|
||||
private RenderProfileElement _selectedProfileElement;
|
||||
private TimelineSegmentViewModel _startTimelineSegmentViewModel;
|
||||
private TimelineViewModel _timelineViewModel;
|
||||
private TreeViewModel _treeViewModel;
|
||||
|
||||
public LayerPropertiesViewModel(IProfileEditorService profileEditorService,
|
||||
ICoreService coreService,
|
||||
ISettingsService settingsService,
|
||||
ILayerPropertyVmFactory layerPropertyVmFactory,
|
||||
IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
DataBindingsViewModel dataBindingsViewModel)
|
||||
{
|
||||
_layerPropertyVmFactory = layerPropertyVmFactory;
|
||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||
|
||||
ProfileEditorService = profileEditorService;
|
||||
CoreService = coreService;
|
||||
SettingsService = settingsService;
|
||||
|
||||
EffectsViewModel = _layerPropertyVmFactory.EffectsViewModel(this);
|
||||
Items.Add(EffectsViewModel);
|
||||
|
||||
LayerPropertyGroups = new BindableCollection<LayerPropertyGroupViewModel>();
|
||||
PropertyChanged += HandlePropertyTreeIndexChanged;
|
||||
|
||||
// Left side
|
||||
TreeViewModel = _layerPropertyVmFactory.TreeViewModel(this, LayerPropertyGroups);
|
||||
EffectsViewModel = _layerPropertyVmFactory.EffectsViewModel(this);
|
||||
Items.Add(TreeViewModel);
|
||||
Items.Add(EffectsViewModel);
|
||||
|
||||
// Right side
|
||||
StartTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.Start, LayerPropertyGroups);
|
||||
MainTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.Main, LayerPropertyGroups);
|
||||
EndTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.End, LayerPropertyGroups);
|
||||
TimelineViewModel = _layerPropertyVmFactory.TimelineViewModel(this, LayerPropertyGroups);
|
||||
DataBindingsViewModel = dataBindingsViewModel;
|
||||
Items.Add(StartTimelineSegmentViewModel);
|
||||
Items.Add(MainTimelineSegmentViewModel);
|
||||
Items.Add(EndTimelineSegmentViewModel);
|
||||
Items.Add(TimelineViewModel);
|
||||
Items.Add(DataBindingsViewModel);
|
||||
}
|
||||
|
||||
public BindableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
|
||||
|
||||
|
||||
#region Child VMs
|
||||
|
||||
public TreeViewModel TreeViewModel { get; }
|
||||
public EffectsViewModel EffectsViewModel { get; }
|
||||
public TimelineSegmentViewModel StartTimelineSegmentViewModel { get; }
|
||||
public TimelineSegmentViewModel MainTimelineSegmentViewModel { get; }
|
||||
public TimelineSegmentViewModel EndTimelineSegmentViewModel { get; }
|
||||
public TimelineViewModel TimelineViewModel { get; }
|
||||
public DataBindingsViewModel DataBindingsViewModel { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
public IProfileEditorService ProfileEditorService { get; }
|
||||
public ICoreService CoreService { get; }
|
||||
public ISettingsService SettingsService { get; }
|
||||
@ -115,53 +135,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
public Layer SelectedLayer => SelectedProfileElement as Layer;
|
||||
public Folder SelectedFolder => SelectedProfileElement as Folder;
|
||||
|
||||
public BindableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups
|
||||
{
|
||||
get => _layerPropertyGroups;
|
||||
set => SetAndNotify(ref _layerPropertyGroups, value);
|
||||
}
|
||||
|
||||
public TreeViewModel TreeViewModel
|
||||
{
|
||||
get => _treeViewModel;
|
||||
set => SetAndNotify(ref _treeViewModel, value);
|
||||
}
|
||||
|
||||
public EffectsViewModel EffectsViewModel
|
||||
{
|
||||
get => _effectsViewModel;
|
||||
set => SetAndNotify(ref _effectsViewModel, value);
|
||||
}
|
||||
|
||||
public DataBindingsViewModel DataBindingsViewModel
|
||||
{
|
||||
get => _dataBindingsViewModel;
|
||||
set => SetAndNotify(ref _dataBindingsViewModel, value);
|
||||
}
|
||||
|
||||
public TimelineViewModel TimelineViewModel
|
||||
{
|
||||
get => _timelineViewModel;
|
||||
set => SetAndNotify(ref _timelineViewModel, value);
|
||||
}
|
||||
|
||||
public TimelineSegmentViewModel StartTimelineSegmentViewModel
|
||||
{
|
||||
get => _startTimelineSegmentViewModel;
|
||||
set => SetAndNotify(ref _startTimelineSegmentViewModel, value);
|
||||
}
|
||||
|
||||
public TimelineSegmentViewModel MainTimelineSegmentViewModel
|
||||
{
|
||||
get => _mainTimelineSegmentViewModel;
|
||||
set => SetAndNotify(ref _mainTimelineSegmentViewModel, value);
|
||||
}
|
||||
|
||||
public TimelineSegmentViewModel EndTimelineSegmentViewModel
|
||||
{
|
||||
get => _endTimelineSegmentViewModel;
|
||||
set => SetAndNotify(ref _endTimelineSegmentViewModel, value);
|
||||
}
|
||||
|
||||
#region Segments
|
||||
|
||||
@ -197,18 +170,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
ProfileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
|
||||
|
||||
PopulateProperties(null);
|
||||
|
||||
TimelineViewModel?.Dispose();
|
||||
TimelineViewModel = null;
|
||||
StartTimelineSegmentViewModel?.Dispose();
|
||||
StartTimelineSegmentViewModel = null;
|
||||
MainTimelineSegmentViewModel?.Dispose();
|
||||
MainTimelineSegmentViewModel = null;
|
||||
EndTimelineSegmentViewModel?.Dispose();
|
||||
EndTimelineSegmentViewModel = null;
|
||||
DataBindingsViewModel?.Dispose();
|
||||
DataBindingsViewModel = null;
|
||||
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
@ -242,15 +203,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
|
||||
private void ProfileEditorServiceOnSelectedDataBindingChanged(object? sender, EventArgs e)
|
||||
{
|
||||
if (ProfileEditorService.SelectedDataBinding != null)
|
||||
{
|
||||
RightSideIndex = 1;
|
||||
DataBindingsViewModel?.Dispose();
|
||||
// TODO
|
||||
// DataBindingsViewModel = _dataBindingsVmFactory.DataBindingsViewModel(ProfileEditorService.SelectedDataBinding);
|
||||
}
|
||||
else
|
||||
RightSideIndex = 0;
|
||||
RightSideIndex = ProfileEditorService.SelectedDataBinding != null ? 1 : 0;
|
||||
}
|
||||
|
||||
#region View model managament
|
||||
@ -293,23 +246,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
LayerPropertyGroups.Add(_layerPropertyVmFactory.LayerPropertyGroupViewModel(SelectedLayer.Transform));
|
||||
}
|
||||
|
||||
TreeViewModel = _layerPropertyVmFactory.TreeViewModel(this, LayerPropertyGroups);
|
||||
|
||||
DeactivateItem(TimelineViewModel);
|
||||
DeactivateItem(StartTimelineSegmentViewModel);
|
||||
DeactivateItem(MainTimelineSegmentViewModel);
|
||||
DeactivateItem(EndTimelineSegmentViewModel);
|
||||
|
||||
TimelineViewModel = _layerPropertyVmFactory.TimelineViewModel(this, LayerPropertyGroups);
|
||||
ActivateItem(TimelineViewModel);
|
||||
|
||||
StartTimelineSegmentViewModel?.Dispose();
|
||||
StartTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.Start, LayerPropertyGroups);
|
||||
MainTimelineSegmentViewModel?.Dispose();
|
||||
MainTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.Main, LayerPropertyGroups);
|
||||
EndTimelineSegmentViewModel?.Dispose();
|
||||
EndTimelineSegmentViewModel = _layerPropertyVmFactory.TimelineSegmentViewModel(SegmentViewModelType.End, LayerPropertyGroups);
|
||||
|
||||
ApplyLayerBrush();
|
||||
ApplyEffects();
|
||||
}
|
||||
@ -361,21 +297,18 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
|
||||
private void ApplyEffects()
|
||||
{
|
||||
RenderProfileElement renderElement;
|
||||
if (SelectedLayer != null)
|
||||
renderElement = SelectedLayer;
|
||||
else if (SelectedFolder != null)
|
||||
renderElement = SelectedFolder;
|
||||
else
|
||||
if (SelectedProfileElement == null)
|
||||
return;
|
||||
|
||||
// Remove VMs of effects no longer applied on the layer
|
||||
var toRemove = LayerPropertyGroups.Where(l => l.LayerPropertyGroup.LayerEffect != null && !renderElement.LayerEffects.Contains(l.LayerPropertyGroup.LayerEffect)).ToList();
|
||||
var toRemove = LayerPropertyGroups
|
||||
.Where(l => l.LayerPropertyGroup.LayerEffect != null && !SelectedProfileElement.LayerEffects.Contains(l.LayerPropertyGroup.LayerEffect))
|
||||
.ToList();
|
||||
LayerPropertyGroups.RemoveRange(toRemove);
|
||||
foreach (var layerPropertyGroupViewModel in toRemove)
|
||||
layerPropertyGroupViewModel.Dispose();
|
||||
|
||||
foreach (var layerEffect in renderElement.LayerEffects)
|
||||
foreach (var layerEffect in SelectedProfileElement.LayerEffects)
|
||||
{
|
||||
if (LayerPropertyGroups.Any(l => l.LayerPropertyGroup.LayerEffect == layerEffect))
|
||||
continue;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree;
|
||||
using Ninject;
|
||||
@ -10,25 +11,20 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
{
|
||||
public class LayerPropertyViewModel : PropertyChangedBase, IDisposable
|
||||
{
|
||||
public LayerPropertyViewModel(ILayerProperty layerProperty, IKernel kernel)
|
||||
public LayerPropertyViewModel(ILayerProperty layerProperty, IPropertyVmFactory propertyVmFactory)
|
||||
{
|
||||
LayerProperty = layerProperty;
|
||||
|
||||
var parameter = new ConstructorArgument("layerProperty", LayerProperty);
|
||||
var treeViewModelType = typeof(TreePropertyViewModel<>).MakeGenericType(layerProperty.GetType().GetGenericArguments());
|
||||
var timelineViewModelType = typeof(TimelinePropertyViewModel<>).MakeGenericType(layerProperty.GetType().GetGenericArguments());
|
||||
|
||||
TreePropertyViewModel = (ITreePropertyViewModel) kernel.Get(treeViewModelType, parameter);
|
||||
TimelinePropertyViewModel = (ITimelinePropertyViewModel) kernel.Get(timelineViewModelType, parameter);
|
||||
TreePropertyViewModel = propertyVmFactory.TreePropertyViewModel(layerProperty, this);
|
||||
TimelinePropertyViewModel = propertyVmFactory.TimelinePropertyViewModel(layerProperty, this);
|
||||
}
|
||||
|
||||
public ILayerProperty LayerProperty { get; }
|
||||
public ITreePropertyViewModel TreePropertyViewModel { get; }
|
||||
public ITimelinePropertyViewModel TimelinePropertyViewModel { get; }
|
||||
|
||||
public bool IsVisible { get; set; }
|
||||
public bool IsExpanded { get; set; }
|
||||
|
||||
public bool IsVisible => !LayerProperty.IsHidden;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
TreePropertyViewModel?.Dispose();
|
||||
|
||||
@ -60,10 +60,16 @@
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.Resources>
|
||||
<DataTemplate DataType="{x:Type layerProperties:LayerPropertyGroupViewModel}">
|
||||
<ContentControl s:View.Model="{Binding TimelineGroupViewModel}" IsTabStop="False" HorizontalAlignment="Stretch" />
|
||||
<ContentControl s:View.Model="{Binding TimelineGroupViewModel}"
|
||||
IsTabStop="False"
|
||||
HorizontalAlignment="Stretch"
|
||||
Visibility="{Binding IsVisible, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type layerProperties:LayerPropertyViewModel}">
|
||||
<ContentControl s:View.Model="{Binding TimelinePropertyViewModel}" IsTabStop="False" HorizontalAlignment="Stretch" />
|
||||
<ContentControl s:View.Model="{Binding TimelinePropertyViewModel}"
|
||||
IsTabStop="False"
|
||||
HorizontalAlignment="Stretch"
|
||||
Visibility="{Binding IsVisible, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.Resources>
|
||||
</ItemsControl>
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
xmlns:timeline="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
Visibility="{Binding LayerPropertyBaseViewModel.IsVisible, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"
|
||||
MinWidth="{Binding Width}"
|
||||
HorizontalAlignment="Stretch">
|
||||
<Border Height="25" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource MaterialDesignDivider}">
|
||||
|
||||
@ -19,6 +19,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
|
||||
LayerProperty = layerProperty;
|
||||
LayerPropertyViewModel = layerPropertyViewModel;
|
||||
UpdateKeyframes();
|
||||
}
|
||||
|
||||
public List<ITimelineKeyframeViewModel> GetAllKeyframeViewModels()
|
||||
|
||||
@ -11,7 +11,7 @@ using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
{
|
||||
public class TimelineSegmentViewModel : PropertyChangedBase, IDisposable
|
||||
public class TimelineSegmentViewModel : Screen, IDisposable
|
||||
{
|
||||
private bool _draggingSegment;
|
||||
private bool _showDisableButton;
|
||||
@ -43,7 +43,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
|
||||
UpdateDisplay();
|
||||
ProfileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
|
||||
SelectedProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
|
||||
ProfileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
|
||||
if (ProfileEditorService.SelectedProfileElement != null)
|
||||
ProfileEditorService.SelectedProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
|
||||
}
|
||||
|
||||
public RenderProfileElement SelectedProfileElement { get; }
|
||||
@ -97,6 +99,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SelectedProfileElement == null)
|
||||
return 0;
|
||||
|
||||
return Segment switch
|
||||
{
|
||||
SegmentViewModelType.Start => 0,
|
||||
@ -128,7 +133,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
public void Dispose()
|
||||
{
|
||||
ProfileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
|
||||
SelectedProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
|
||||
ProfileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected;
|
||||
if (SelectedProfileElement != null)
|
||||
SelectedProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
|
||||
}
|
||||
|
||||
public void DisableSegment()
|
||||
@ -260,6 +267,13 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
UpdateDisplay();
|
||||
}
|
||||
|
||||
private void ProfileEditorServiceOnProfileElementSelected(object? sender, RenderProfileElementEventArgs e)
|
||||
{
|
||||
if (e.PreviousRenderProfileElement != null)
|
||||
e.PreviousRenderProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
|
||||
e.RenderProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
|
||||
}
|
||||
|
||||
private void SelectedProfileElementOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(RenderProfileElement.StartSegmentLength) ||
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
HorizontalAlignment="Left">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding TimelinePropertyGroupViewModel}" HorizontalContentAlignment="Left" />
|
||||
<ContentControl s:View.Model="{Binding TimelineGroupViewModel}" HorizontalContentAlignment="Left" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
@ -27,13 +26,14 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
|
||||
LayerPropertyGroups = layerPropertyGroups;
|
||||
SelectionRectangle = new RectangleGeometry();
|
||||
SelectedProfileElement = layerPropertiesViewModel.SelectedProfileElement;
|
||||
|
||||
SelectedProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
|
||||
_profileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged;
|
||||
_profileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
|
||||
if (_profileEditorService.SelectedProfileElement != null)
|
||||
_profileEditorService.SelectedProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
|
||||
}
|
||||
|
||||
public RenderProfileElement SelectedProfileElement { get; set; }
|
||||
public RenderProfileElement SelectedProfileElement => _profileEditorService.SelectedProfileElement;
|
||||
|
||||
public BindableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
|
||||
|
||||
@ -43,23 +43,25 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
set => SetAndNotify(ref _selectionRectangle, value);
|
||||
}
|
||||
|
||||
public double StartSegmentWidth => _profileEditorService.PixelsPerSecond * SelectedProfileElement.StartSegmentLength.TotalSeconds;
|
||||
public double StartSegmentWidth => _profileEditorService.PixelsPerSecond * (SelectedProfileElement?.StartSegmentLength.TotalSeconds ?? 0);
|
||||
public double StartSegmentEndPosition => StartSegmentWidth;
|
||||
public double MainSegmentWidth => _profileEditorService.PixelsPerSecond * SelectedProfileElement.MainSegmentLength.TotalSeconds;
|
||||
public double MainSegmentWidth => _profileEditorService.PixelsPerSecond * (SelectedProfileElement?.MainSegmentLength.TotalSeconds ?? 0);
|
||||
public double MainSegmentEndPosition => StartSegmentWidth + MainSegmentWidth;
|
||||
public double EndSegmentWidth => _profileEditorService.PixelsPerSecond * SelectedProfileElement.EndSegmentLength.TotalSeconds;
|
||||
public double EndSegmentWidth => _profileEditorService.PixelsPerSecond * (SelectedProfileElement?.EndSegmentLength.TotalSeconds ?? 0);
|
||||
public double EndSegmentEndPosition => StartSegmentWidth + MainSegmentWidth + EndSegmentWidth;
|
||||
public double TotalTimelineWidth => _profileEditorService.PixelsPerSecond * SelectedProfileElement.TimelineLength.TotalSeconds;
|
||||
public double TotalTimelineWidth => _profileEditorService.PixelsPerSecond * (SelectedProfileElement?.TimelineLength.TotalSeconds ?? 0);
|
||||
|
||||
public bool StartSegmentEnabled => SelectedProfileElement.StartSegmentLength != TimeSpan.Zero;
|
||||
public bool EndSegmentEnabled => SelectedProfileElement.EndSegmentLength != TimeSpan.Zero;
|
||||
public bool StartSegmentEnabled => SelectedProfileElement?.StartSegmentLength != TimeSpan.Zero;
|
||||
public bool EndSegmentEnabled => SelectedProfileElement?.EndSegmentLength != TimeSpan.Zero;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_profileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged;
|
||||
SelectedProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
|
||||
_profileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected;
|
||||
if (_profileEditorService.SelectedProfileElement != null)
|
||||
_profileEditorService.SelectedProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
|
||||
}
|
||||
|
||||
|
||||
private void SelectedProfileElementOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(_profileEditorService.SelectedProfileElement.StartSegmentLength))
|
||||
@ -98,6 +100,13 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
NotifyOfPropertyChange(nameof(TotalTimelineWidth));
|
||||
}
|
||||
|
||||
private void ProfileEditorServiceOnProfileElementSelected(object? sender, RenderProfileElementEventArgs e)
|
||||
{
|
||||
if (e.PreviousRenderProfileElement != null)
|
||||
e.PreviousRenderProfileElement.PropertyChanged -= SelectedProfileElementOnPropertyChanged;
|
||||
e.RenderProfileElement.PropertyChanged += SelectedProfileElementOnPropertyChanged;
|
||||
}
|
||||
|
||||
#region Command handlers
|
||||
|
||||
public void KeyframeMouseDown(object sender, MouseButtonEventArgs e)
|
||||
@ -321,7 +330,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
var viewModels = new List<ITimelineKeyframeViewModel>();
|
||||
foreach (var layerPropertyGroupViewModel in LayerPropertyGroups)
|
||||
viewModels.AddRange(layerPropertyGroupViewModel.GetAllKeyframeViewModels(false));
|
||||
|
||||
|
||||
return viewModels;
|
||||
}
|
||||
|
||||
|
||||
@ -35,6 +35,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
|
||||
|
||||
LayerPropertyGroupViewModel = layerPropertyGroupViewModel;
|
||||
LayerPropertyGroup = LayerPropertyGroupViewModel.LayerPropertyGroup;
|
||||
|
||||
DetermineGroupType();
|
||||
}
|
||||
|
||||
public LayerPropertyGroupViewModel LayerPropertyGroupViewModel { get; }
|
||||
|
||||
@ -98,7 +98,7 @@
|
||||
</Style>
|
||||
</TreeView.ItemContainerStyle>
|
||||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type local:LayerPropertyGroupViewModel}" ItemsSource="{Binding Items}">
|
||||
<HierarchicalDataTemplate DataType="{x:Type local:LayerPropertyGroupViewModel}" ItemsSource="{Binding Children}">
|
||||
<ContentControl s:View.Model="{Binding TreeGroupViewModel}" />
|
||||
</HierarchicalDataTemplate>
|
||||
<DataTemplate DataType="{x:Type local:LayerPropertyViewModel}">
|
||||
|
||||
@ -36,7 +36,10 @@ namespace Artemis.UI.Screens.ProfileEditor
|
||||
private PluginSetting<GridLength> _sidePanelsWidth;
|
||||
|
||||
public ProfileEditorViewModel(ProfileModule module,
|
||||
ICollection<IProfileEditorPanelViewModel> viewModels,
|
||||
ProfileViewModel profileViewModel,
|
||||
ProfileTreeViewModel profileTreeViewModel,
|
||||
DisplayConditionsViewModel displayConditionsViewModel,
|
||||
LayerPropertiesViewModel layerPropertiesViewModel,
|
||||
IProfileEditorService profileEditorService,
|
||||
IProfileService profileService,
|
||||
IDialogService dialogService,
|
||||
@ -55,15 +58,17 @@ namespace Artemis.UI.Screens.ProfileEditor
|
||||
DialogService = dialogService;
|
||||
|
||||
Profiles = new BindableCollection<ProfileDescriptor>();
|
||||
|
||||
// Run this first to let VMs activate without causing constant UI updates
|
||||
Items.AddRange(viewModels);
|
||||
|
||||
|
||||
// Populate the panels
|
||||
ProfileViewModel = (ProfileViewModel) viewModels.First(vm => vm is ProfileViewModel);
|
||||
ProfileTreeViewModel = (ProfileTreeViewModel) viewModels.First(vm => vm is ProfileTreeViewModel);
|
||||
DisplayConditionsViewModel = (DisplayConditionsViewModel) viewModels.First(vm => vm is DisplayConditionsViewModel);
|
||||
LayerPropertiesViewModel = (LayerPropertiesViewModel) viewModels.First(vm => vm is LayerPropertiesViewModel);
|
||||
ProfileViewModel = profileViewModel;
|
||||
ProfileTreeViewModel = profileTreeViewModel;
|
||||
DisplayConditionsViewModel = displayConditionsViewModel;
|
||||
LayerPropertiesViewModel = layerPropertiesViewModel;
|
||||
|
||||
Items.Add(ProfileViewModel);
|
||||
Items.Add(ProfileTreeViewModel);
|
||||
Items.Add(DisplayConditionsViewModel);
|
||||
Items.Add(LayerPropertiesViewModel);
|
||||
}
|
||||
|
||||
public ProfileModule Module { get; }
|
||||
|
||||
@ -99,7 +99,7 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
private void GetDataModel()
|
||||
{
|
||||
MainDataModel = SelectedModule != null
|
||||
? _dataModelUIService.GetPluginDataModelVisualization(SelectedModule)
|
||||
? _dataModelUIService.GetPluginDataModelVisualization(SelectedModule, false)
|
||||
: _dataModelUIService.GetMainDataModelVisualization();
|
||||
}
|
||||
|
||||
|
||||
@ -55,6 +55,7 @@ namespace Artemis.UI.Services
|
||||
_profileEditorService.RegisterPropertyInput<SKColorPropertyInputViewModel>(Constants.CorePluginInfo);
|
||||
_profileEditorService.RegisterPropertyInput<SKPointPropertyInputViewModel>(Constants.CorePluginInfo);
|
||||
_profileEditorService.RegisterPropertyInput<SKSizePropertyInputViewModel>(Constants.CorePluginInfo);
|
||||
_profileEditorService.RegisterPropertyInput(typeof(EnumPropertyInputViewModel<>), Constants.CorePluginInfo);
|
||||
|
||||
_registeredBuiltInPropertyEditors = true;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user