mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Nodes - Added type color registration system
Nodes - Generate (stable) type colors for undefined types
This commit is contained in:
parent
5675d1895b
commit
b8077ca589
@ -16,7 +16,7 @@ namespace Artemis.Core
|
||||
/// <returns>The RGB.NET color</returns>
|
||||
public static Color ToRgbColor(this SKColor color)
|
||||
{
|
||||
return new(color.Alpha, color.Red, color.Green, color.Blue);
|
||||
return new Color(color.Alpha, color.Red, color.Green, color.Blue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -49,7 +49,7 @@ namespace Artemis.Core
|
||||
/// <returns>The sum of the two colors</returns>
|
||||
public static SKColor Sum(this SKColor a, SKColor b)
|
||||
{
|
||||
return new(
|
||||
return new SKColor(
|
||||
ClampToByte(a.Red + b.Red),
|
||||
ClampToByte(a.Green + b.Green),
|
||||
ClampToByte(a.Blue + b.Blue),
|
||||
@ -57,6 +57,19 @@ namespace Artemis.Core
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Darkens the color by the specified amount
|
||||
/// </summary>
|
||||
/// <param name="c">The color to darken</param>
|
||||
/// <param name="amount">The brightness of the new color</param>
|
||||
/// <returns>The darkened color</returns>
|
||||
public static SKColor Darken(this SKColor c, float amount)
|
||||
{
|
||||
c.ToHsl(out float h, out float s, out float l);
|
||||
l *= 1f - amount;
|
||||
return SKColor.FromHsl(h, s, l);
|
||||
}
|
||||
|
||||
private static byte ClampToByte(float value)
|
||||
{
|
||||
return (byte) Math.Clamp(value, 0, 255);
|
||||
|
||||
@ -4,24 +4,19 @@ using System.Reflection;
|
||||
using Artemis.Storage.Entities.Profile.Nodes;
|
||||
using Ninject;
|
||||
using Ninject.Parameters;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
internal class NodeService : INodeService
|
||||
{
|
||||
private readonly IKernel _kernel;
|
||||
|
||||
#region Constants
|
||||
|
||||
private static readonly Type TYPE_NODE = typeof(INode);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
public IEnumerable<NodeData> AvailableNodes => NodeTypeStore.GetAll();
|
||||
|
||||
#endregion
|
||||
private readonly IKernel _kernel;
|
||||
|
||||
#region Constructors
|
||||
|
||||
@ -32,8 +27,20 @@ namespace Artemis.Core.Services
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
public IEnumerable<NodeData> AvailableNodes => NodeTypeStore.GetAll();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public TypeColorRegistration? GetTypeColor(Type type)
|
||||
{
|
||||
return NodeTypeStore.GetColor(type);
|
||||
}
|
||||
|
||||
public NodeTypeRegistration RegisterNodeType(Plugin plugin, Type nodeType)
|
||||
{
|
||||
if (plugin == null) throw new ArgumentNullException(nameof(plugin));
|
||||
@ -46,10 +53,18 @@ namespace Artemis.Core.Services
|
||||
string description = nodeAttribute?.Description ?? string.Empty;
|
||||
string category = nodeAttribute?.Category ?? string.Empty;
|
||||
|
||||
NodeData nodeData = new(plugin, nodeType, name, description, category, (e) => CreateNode(e, nodeType));
|
||||
NodeData nodeData = new(plugin, nodeType, name, description, category, e => CreateNode(e, nodeType));
|
||||
return NodeTypeStore.Add(nodeData);
|
||||
}
|
||||
|
||||
public TypeColorRegistration RegisterTypeColor(Plugin plugin, Type type, SKColor color)
|
||||
{
|
||||
if (plugin == null) throw new ArgumentNullException(nameof(plugin));
|
||||
if (type == null) throw new ArgumentNullException(nameof(type));
|
||||
|
||||
return NodeTypeStore.AddColor(type, color, plugin);
|
||||
}
|
||||
|
||||
private INode CreateNode(NodeEntity? entity, Type nodeType)
|
||||
{
|
||||
INode node = _kernel.Get(nodeType) as INode ?? throw new InvalidOperationException($"Node {nodeType} is not an INode");
|
||||
@ -82,10 +97,23 @@ namespace Artemis.Core.Services
|
||||
IEnumerable<NodeData> AvailableNodes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a node of the provided <paramref name="nodeType"/>
|
||||
/// Gets the best matching registration for the provided type
|
||||
/// </summary>
|
||||
TypeColorRegistration? GetTypeColor(Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a node of the provided <paramref name="nodeType" />
|
||||
/// </summary>
|
||||
/// <param name="plugin">The plugin the node belongs to</param>
|
||||
/// <param name="nodeType">The type of node to initialize</param>
|
||||
NodeTypeRegistration RegisterNodeType(Plugin plugin, Type nodeType);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a type with a provided color for use in the node editor
|
||||
/// </summary>
|
||||
/// <param name="plugin">The plugin making the registration</param>
|
||||
/// <param name="type">The type to associate the color with</param>
|
||||
/// <param name="color">The color to display</param>
|
||||
TypeColorRegistration RegisterTypeColor(Plugin plugin, Type type, SKColor color);
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class NodeTypeStore
|
||||
{
|
||||
private static readonly List<NodeTypeRegistration> Registrations = new();
|
||||
private static readonly List<TypeColorRegistration> ColorRegistrations = new();
|
||||
|
||||
public static NodeTypeRegistration Add(NodeData nodeData)
|
||||
{
|
||||
@ -32,7 +34,7 @@ namespace Artemis.Core
|
||||
lock (Registrations)
|
||||
{
|
||||
if (!Registrations.Contains(typeRegistration))
|
||||
throw new ArtemisCoreException($"Data binding modifier type store does not contain modifier type '{typeRegistration.NodeData.Name}'");
|
||||
throw new ArtemisCoreException($"Node type store does not contain modifier type '{typeRegistration.NodeData.Name}'");
|
||||
|
||||
Registrations.Remove(typeRegistration);
|
||||
typeRegistration.IsInStore = false;
|
||||
@ -57,6 +59,51 @@ namespace Artemis.Core
|
||||
}
|
||||
}
|
||||
|
||||
public static Plugin? GetPlugin(INode node)
|
||||
{
|
||||
lock (Registrations)
|
||||
{
|
||||
return Registrations.FirstOrDefault(r => r.Plugin.GetType().Assembly == node.GetType().Assembly)?.Plugin;
|
||||
}
|
||||
}
|
||||
|
||||
public static TypeColorRegistration AddColor(Type type, SKColor color, Plugin plugin)
|
||||
{
|
||||
TypeColorRegistration typeColorRegistration;
|
||||
lock (ColorRegistrations)
|
||||
{
|
||||
if (ColorRegistrations.Any(r => r.Type == type))
|
||||
throw new ArtemisCoreException($"Node color store already contains a color for '{type.Name}'");
|
||||
|
||||
typeColorRegistration = new TypeColorRegistration(type, color, plugin) {IsInStore = true};
|
||||
ColorRegistrations.Add(typeColorRegistration);
|
||||
}
|
||||
|
||||
return typeColorRegistration;
|
||||
}
|
||||
|
||||
public static void RemoveColor(TypeColorRegistration typeColorRegistration)
|
||||
{
|
||||
lock (ColorRegistrations)
|
||||
{
|
||||
if (!ColorRegistrations.Contains(typeColorRegistration))
|
||||
throw new ArtemisCoreException($"Node color store does not contain modifier type '{typeColorRegistration.Type.Name}'");
|
||||
|
||||
ColorRegistrations.Remove(typeColorRegistration);
|
||||
typeColorRegistration.IsInStore = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static TypeColorRegistration? GetColor(Type type)
|
||||
{
|
||||
lock (ColorRegistrations)
|
||||
{
|
||||
return ColorRegistrations
|
||||
.OrderByDescending(r => r.Type.ScoreCastability(type))
|
||||
.FirstOrDefault(r => r.Type.ScoreCastability(type) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
public static event EventHandler<NodeTypeStoreEvent>? NodeTypeAdded;
|
||||
@ -73,13 +120,5 @@ namespace Artemis.Core
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static Plugin? GetPlugin(INode node)
|
||||
{
|
||||
lock (Registrations)
|
||||
{
|
||||
return Registrations.FirstOrDefault(r => r.Plugin.GetType().Assembly == node.GetType().Assembly)?.Plugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@ -15,6 +16,9 @@ namespace Artemis.Core
|
||||
Plugin.Disabled += OnDisabled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node data that was registered
|
||||
/// </summary>
|
||||
public NodeData NodeData { get; }
|
||||
|
||||
/// <summary>
|
||||
@ -34,4 +38,51 @@ namespace Artemis.Core
|
||||
NodeTypeStore.Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a registration for a <see cref="SKColor" /> to associate with a certain <see cref="System.Type" />
|
||||
/// </summary>
|
||||
public class TypeColorRegistration
|
||||
{
|
||||
internal TypeColorRegistration(Type type, SKColor color, Plugin plugin)
|
||||
{
|
||||
Type = type;
|
||||
Color = color;
|
||||
Plugin = plugin;
|
||||
|
||||
Plugin.Disabled += OnDisabled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type
|
||||
/// </summary>
|
||||
public Type Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color
|
||||
/// </summary>
|
||||
public SKColor Color { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a darkened tone of the <see cref="Color" />
|
||||
/// </summary>
|
||||
public SKColor DarkenedColor => Color.Darken(0.35f);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin type color is associated with
|
||||
/// </summary>
|
||||
public Plugin Plugin { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether the registration is in the internal Core store
|
||||
/// </summary>
|
||||
public bool IsInStore { get; internal set; }
|
||||
|
||||
private void OnDisabled(object? sender, EventArgs e)
|
||||
{
|
||||
Plugin.Disabled -= OnDisabled;
|
||||
if (IsInStore)
|
||||
NodeTypeStore.RemoveColor(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -20,10 +20,10 @@ namespace Artemis.UI.Shared.Services
|
||||
{
|
||||
private readonly IKernel _kernel;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IModuleService _moduleService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly List<PropertyInputRegistration> _registeredPropertyEditors;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly IModuleService _moduleService;
|
||||
private readonly object _selectedProfileElementLock = new();
|
||||
private readonly object _selectedProfileLock = new();
|
||||
private TimeSpan _currentTime;
|
||||
@ -31,7 +31,8 @@ namespace Artemis.UI.Shared.Services
|
||||
private int _pixelsPerSecond;
|
||||
private bool _suspendEditing;
|
||||
|
||||
public ProfileEditorService(IKernel kernel, ILogger logger, IProfileService profileService, ICoreService coreService, IRgbService rgbService, IModuleService moduleService)
|
||||
public ProfileEditorService(IKernel kernel, ILogger logger, ICoreService coreService, IProfileService profileService, IRgbService rgbService, IModuleService moduleService,
|
||||
INodeService nodeService)
|
||||
{
|
||||
_kernel = kernel;
|
||||
_logger = logger;
|
||||
@ -40,9 +41,56 @@ namespace Artemis.UI.Shared.Services
|
||||
_moduleService = moduleService;
|
||||
_registeredPropertyEditors = new List<PropertyInputRegistration>();
|
||||
coreService.FrameRendered += CoreServiceOnFrameRendered;
|
||||
|
||||
TypeUtilities.NodeService = nodeService;
|
||||
PixelsPerSecond = 100;
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileChanged(ProfileConfigurationEventArgs e)
|
||||
{
|
||||
SelectedProfileChanged?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileUpdated(ProfileConfigurationEventArgs e)
|
||||
{
|
||||
SelectedProfileSaved?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileElementChanged(RenderProfileElementEventArgs e)
|
||||
{
|
||||
SelectedProfileElementChanged?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileElementUpdated(RenderProfileElementEventArgs e)
|
||||
{
|
||||
SelectedProfileElementSaved?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnCurrentTimeChanged()
|
||||
{
|
||||
CurrentTimeChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnPixelsPerSecondChanged()
|
||||
{
|
||||
PixelsPerSecondChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnSuspendEditingChanged()
|
||||
{
|
||||
SuspendEditingChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnProfilePreviewUpdated()
|
||||
{
|
||||
ProfilePreviewUpdated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedDataBindingChanged()
|
||||
{
|
||||
SelectedDataBindingChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void CoreServiceOnFrameRendered(object? sender, FrameRenderedEventArgs e)
|
||||
{
|
||||
if (!_doTick) return;
|
||||
@ -89,7 +137,9 @@ namespace Artemis.UI.Shared.Services
|
||||
return;
|
||||
|
||||
if (renderElement.Suspended)
|
||||
{
|
||||
renderElement.Disable();
|
||||
}
|
||||
else
|
||||
{
|
||||
renderElement.Enable();
|
||||
@ -104,7 +154,6 @@ namespace Artemis.UI.Shared.Services
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<PropertyInputRegistration> RegisteredPropertyEditors => _registeredPropertyEditors.AsReadOnly();
|
||||
|
||||
public bool Playing { get; set; }
|
||||
|
||||
public bool SuspendEditing
|
||||
@ -319,10 +368,8 @@ namespace Artemis.UI.Shared.Services
|
||||
if (existing != null)
|
||||
{
|
||||
if (existing.Plugin != plugin)
|
||||
{
|
||||
throw new ArtemisSharedUIException($"Cannot register property editor for type {supportedType.Name} because an editor was already " +
|
||||
$"registered by {existing.Plugin}");
|
||||
}
|
||||
|
||||
return existing;
|
||||
}
|
||||
@ -367,10 +414,8 @@ namespace Artemis.UI.Shared.Services
|
||||
|
||||
if (snapToCurrentTime)
|
||||
// Snap to the current time
|
||||
{
|
||||
if (Math.Abs(time.TotalMilliseconds - CurrentTime.TotalMilliseconds) < tolerance.TotalMilliseconds)
|
||||
return CurrentTime;
|
||||
}
|
||||
|
||||
if (snapTimes != null)
|
||||
{
|
||||
@ -406,9 +451,13 @@ namespace Artemis.UI.Shared.Services
|
||||
viewModelType = registration.ViewModelType.MakeGenericType(layerProperty.GetType().GenericTypeArguments);
|
||||
}
|
||||
else if (registration != null)
|
||||
{
|
||||
viewModelType = registration.ViewModelType;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (viewModelType == null)
|
||||
return null;
|
||||
@ -428,6 +477,16 @@ namespace Artemis.UI.Shared.Services
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public event EventHandler<ProfileConfigurationEventArgs>? SelectedProfileChanged;
|
||||
public event EventHandler<ProfileConfigurationEventArgs>? SelectedProfileSaved;
|
||||
public event EventHandler<RenderProfileElementEventArgs>? SelectedProfileElementChanged;
|
||||
public event EventHandler<RenderProfileElementEventArgs>? SelectedProfileElementSaved;
|
||||
public event EventHandler? SelectedDataBindingChanged;
|
||||
public event EventHandler? CurrentTimeChanged;
|
||||
public event EventHandler? PixelsPerSecondChanged;
|
||||
public event EventHandler? SuspendEditingChanged;
|
||||
public event EventHandler? ProfilePreviewUpdated;
|
||||
|
||||
#region Copy/paste
|
||||
|
||||
public ProfileElement? DuplicateProfileElement(ProfileElement profileElement)
|
||||
@ -507,64 +566,5 @@ namespace Artemis.UI.Shared.Services
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler<ProfileConfigurationEventArgs>? SelectedProfileChanged;
|
||||
public event EventHandler<ProfileConfigurationEventArgs>? SelectedProfileSaved;
|
||||
public event EventHandler<RenderProfileElementEventArgs>? SelectedProfileElementChanged;
|
||||
public event EventHandler<RenderProfileElementEventArgs>? SelectedProfileElementSaved;
|
||||
public event EventHandler? SelectedDataBindingChanged;
|
||||
public event EventHandler? CurrentTimeChanged;
|
||||
public event EventHandler? PixelsPerSecondChanged;
|
||||
public event EventHandler? SuspendEditingChanged;
|
||||
public event EventHandler? ProfilePreviewUpdated;
|
||||
|
||||
protected virtual void OnSelectedProfileChanged(ProfileConfigurationEventArgs e)
|
||||
{
|
||||
SelectedProfileChanged?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileUpdated(ProfileConfigurationEventArgs e)
|
||||
{
|
||||
SelectedProfileSaved?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileElementChanged(RenderProfileElementEventArgs e)
|
||||
{
|
||||
SelectedProfileElementChanged?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileElementUpdated(RenderProfileElementEventArgs e)
|
||||
{
|
||||
SelectedProfileElementSaved?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnCurrentTimeChanged()
|
||||
{
|
||||
CurrentTimeChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnPixelsPerSecondChanged()
|
||||
{
|
||||
PixelsPerSecondChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnSuspendEditingChanged()
|
||||
{
|
||||
SuspendEditingChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnProfilePreviewUpdated()
|
||||
{
|
||||
ProfilePreviewUpdated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedDataBindingChanged()
|
||||
{
|
||||
SelectedDataBindingChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
43
src/Artemis.UI.Shared/Utilities/TypeUtilities.cs
Normal file
43
src/Artemis.UI.Shared/Utilities/TypeUtilities.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using SkiaSharp;
|
||||
using SkiaSharp.Views.WPF;
|
||||
|
||||
namespace Artemis.UI.Shared
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides UI-oriented utilities for types
|
||||
/// </summary>
|
||||
public static class TypeUtilities
|
||||
{
|
||||
internal static INodeService? NodeService;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a tuple containing a color and a slightly darkened color for a given type
|
||||
/// </summary>
|
||||
/// <param name="type">The type to create the color for</param>
|
||||
public static (Color, Color) GetTypeColors(Type type)
|
||||
{
|
||||
if (type == typeof(object))
|
||||
return (new SKColor(0xFFFFFF).ToColor(), new SKColor(0xFFFFFF).Darken(0.35f).ToColor());
|
||||
|
||||
TypeColorRegistration? typeColorRegistration = NodeService?.GetTypeColor(type);
|
||||
if (typeColorRegistration != null)
|
||||
return (typeColorRegistration.Color.ToColor(), typeColorRegistration.DarkenedColor.ToColor());
|
||||
|
||||
// Come up with a random color based on the type name that should be the same each time
|
||||
MD5 md5Hasher = MD5.Create();
|
||||
byte[] hashed = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(type.FullName!));
|
||||
int hash = BitConverter.ToInt32(hashed, 0);
|
||||
|
||||
SKColor baseColor = SKColor.FromHsl(hash % 255, 50 + hash % 50, 50);
|
||||
SKColor darkenedColor = baseColor.Darken(0.35f);
|
||||
|
||||
return (baseColor.ToColor(), darkenedColor.ToColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -94,7 +94,8 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
|
||||
|
||||
private void Update(RenderProfileElement renderProfileElement)
|
||||
{
|
||||
if (RenderProfileElement != null) RenderProfileElement.Timeline.PropertyChanged -= TimelineOnPropertyChanged;
|
||||
if (RenderProfileElement != null)
|
||||
RenderProfileElement.Timeline.PropertyChanged -= TimelineOnPropertyChanged;
|
||||
|
||||
RenderProfileElement = renderProfileElement;
|
||||
|
||||
@ -102,6 +103,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
|
||||
NotifyOfPropertyChange(nameof(AlwaysFinishTimeline));
|
||||
NotifyOfPropertyChange(nameof(ConditionBehaviourEnabled));
|
||||
|
||||
if (RenderProfileElement != null)
|
||||
RenderProfileElement.Timeline.PropertyChanged += TimelineOnPropertyChanged;
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
@ -12,6 +13,7 @@ using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.SkiaSharp;
|
||||
using Artemis.VisualScripting.Nodes;
|
||||
using Serilog;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.UI.Services
|
||||
{
|
||||
@ -119,6 +121,13 @@ namespace Artemis.UI.Services
|
||||
|
||||
public void RegisterBuiltInNodeTypes()
|
||||
{
|
||||
_nodeService.RegisterTypeColor(Constants.CorePlugin, typeof(bool), new SKColor(0xFFCD3232));
|
||||
_nodeService.RegisterTypeColor(Constants.CorePlugin, typeof(string), new SKColor(0xFFFFD700));
|
||||
_nodeService.RegisterTypeColor(Constants.CorePlugin, typeof(int), new SKColor(0xFF32CD32));
|
||||
_nodeService.RegisterTypeColor(Constants.CorePlugin, typeof(double), new SKColor(0xFF1E90FF));
|
||||
_nodeService.RegisterTypeColor(Constants.CorePlugin, typeof(float), new SKColor(0xFFFF7C00));
|
||||
_nodeService.RegisterTypeColor(Constants.CorePlugin, typeof(IList), new SKColor(0xFFC842FF));
|
||||
|
||||
foreach (Type nodeType in typeof(SumIntegersNode).Assembly.GetTypes().Where(t => typeof(INode).IsAssignableFrom(t) && t.IsPublic && !t.IsAbstract && !t.IsInterface))
|
||||
_nodeService.RegisterNodeType(Constants.CorePlugin, nodeType);
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.VisualScripting.Editor.Controls.Wrapper;
|
||||
|
||||
namespace Artemis.VisualScripting.Editor.Controls
|
||||
@ -119,8 +120,8 @@ namespace Artemis.VisualScripting.Editor.Controls
|
||||
|
||||
private void UpdateBorderBrush()
|
||||
{
|
||||
// if (Cable.From.Pin.Type.IsAssignableTo(typeof(IList)))
|
||||
// BorderBrush = new SolidColorBrush(Colors.MediumPurple);
|
||||
(Color color, Color _) = TypeUtilities.GetTypeColors(Cable.From.Pin.Type);
|
||||
BorderBrush = new SolidColorBrush(color);
|
||||
}
|
||||
|
||||
private void UpdateValuePosition()
|
||||
|
||||
@ -5,6 +5,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.VisualScripting.Editor.Controls.Wrapper;
|
||||
|
||||
namespace Artemis.VisualScripting.Editor.Controls
|
||||
@ -108,9 +109,17 @@ namespace Artemis.VisualScripting.Editor.Controls
|
||||
if (args.NewValue is VisualScriptPin newPin)
|
||||
newPin.Node.Node.PropertyChanged += OnNodePropertyChanged;
|
||||
|
||||
UpdateBrushes();
|
||||
UpdateAbsoluteLocation();
|
||||
}
|
||||
|
||||
private void UpdateBrushes()
|
||||
{
|
||||
(Color border, Color background) = TypeUtilities.GetTypeColors(Pin.Pin.Type);
|
||||
Background = new SolidColorBrush(background);
|
||||
BorderBrush = new SolidColorBrush(border);
|
||||
}
|
||||
|
||||
private void UpdateAbsoluteLocation()
|
||||
{
|
||||
if ((Pin == null) || (_nodePresenter == null)) return;
|
||||
|
||||
@ -62,26 +62,6 @@
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Thickness" Value="6" />
|
||||
</Trigger>
|
||||
|
||||
<DataTrigger Binding="{Binding Cable.From.Pin.Type, RelativeSource={RelativeSource Self}}" Value="{x:Type system:Boolean}">
|
||||
<Setter Property="BorderBrush" Value="#FFCD3232" />
|
||||
</DataTrigger>
|
||||
|
||||
<DataTrigger Binding="{Binding Cable.From.Pin.Type, RelativeSource={RelativeSource Self}}" Value="{x:Type system:Int32}">
|
||||
<Setter Property="BorderBrush" Value="LimeGreen" />
|
||||
</DataTrigger>
|
||||
|
||||
<DataTrigger Binding="{Binding Cable.From.Pin.Type, RelativeSource={RelativeSource Self}}" Value="{x:Type system:Double}">
|
||||
<Setter Property="BorderBrush" Value="DodgerBlue" />
|
||||
</DataTrigger>
|
||||
|
||||
<DataTrigger Binding="{Binding Cable.From.Pin.Type, RelativeSource={RelativeSource Self}}" Value="{x:Type system:String}">
|
||||
<Setter Property="BorderBrush" Value="Gold" />
|
||||
</DataTrigger>
|
||||
|
||||
<DataTrigger Binding="{Binding Cable.From.Pin.Type, RelativeSource={RelativeSource Self}}" Value="{x:Type collections:IList}">
|
||||
<Setter Property="BorderBrush" Value="MediumPurple" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
|
||||
@ -80,31 +80,6 @@
|
||||
<Setter Property="Padding" Value="6,0,0,0" />
|
||||
<Setter Property="Template" Value="{StaticResource TemplateVisualScriptPinPresenterOutput}" />
|
||||
</DataTrigger>
|
||||
|
||||
<DataTrigger Binding="{Binding Pin.Pin.Type, RelativeSource={RelativeSource Self}}" Value="{x:Type system:Object}">
|
||||
<Setter Property="Background" Value="#FFA0A0A0" />
|
||||
<Setter Property="BorderBrush" Value="White" />
|
||||
</DataTrigger>
|
||||
|
||||
<DataTrigger Binding="{Binding Pin.Pin.Type, RelativeSource={RelativeSource Self}}" Value="{x:Type system:Boolean}">
|
||||
<Setter Property="Background" Value="DarkRed" />
|
||||
<Setter Property="BorderBrush" Value="#FFCD3232" />
|
||||
</DataTrigger>
|
||||
|
||||
<DataTrigger Binding="{Binding Pin.Pin.Type, RelativeSource={RelativeSource Self}}" Value="{x:Type system:Int32}">
|
||||
<Setter Property="Background" Value="DarkGreen" />
|
||||
<Setter Property="BorderBrush" Value="LimeGreen" />
|
||||
</DataTrigger>
|
||||
|
||||
<DataTrigger Binding="{Binding Pin.Pin.Type, RelativeSource={RelativeSource Self}}" Value="{x:Type system:Double}">
|
||||
<Setter Property="Background" Value="Blue" />
|
||||
<Setter Property="BorderBrush" Value="DodgerBlue" />
|
||||
</DataTrigger>
|
||||
|
||||
<DataTrigger Binding="{Binding Pin.Pin.Type, RelativeSource={RelativeSource Self}}" Value="{x:Type system:String}">
|
||||
<Setter Property="Background" Value="DarkGoldenrod" />
|
||||
<Setter Property="BorderBrush" Value="Gold" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user