diff --git a/src/Artemis.Core/Extensions/SKColorExtensions.cs b/src/Artemis.Core/Extensions/SKColorExtensions.cs
index dbc14239f..f1e9297ec 100644
--- a/src/Artemis.Core/Extensions/SKColorExtensions.cs
+++ b/src/Artemis.Core/Extensions/SKColorExtensions.cs
@@ -16,7 +16,7 @@ namespace Artemis.Core
/// The RGB.NET color
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);
}
///
@@ -49,7 +49,7 @@ namespace Artemis.Core
/// The sum of the two colors
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
);
}
+ ///
+ /// Darkens the color by the specified amount
+ ///
+ /// The color to darken
+ /// The brightness of the new color
+ /// The darkened color
+ 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);
diff --git a/src/Artemis.Core/Services/NodeService.cs b/src/Artemis.Core/Services/NodeService.cs
index 74d856f51..66ffd7804 100644
--- a/src/Artemis.Core/Services/NodeService.cs
+++ b/src/Artemis.Core/Services/NodeService.cs
@@ -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 AvailableNodes => NodeTypeStore.GetAll();
-
- #endregion
+ private readonly IKernel _kernel;
#region Constructors
@@ -32,8 +27,20 @@ namespace Artemis.Core.Services
#endregion
+ #region Properties & Fields
+
+ public IEnumerable AvailableNodes => NodeTypeStore.GetAll();
+
+ #endregion
+
#region Methods
+ ///
+ 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");
@@ -72,20 +87,33 @@ namespace Artemis.Core.Services
}
///
- /// A service that provides access to the node system
+ /// A service that provides access to the node system
///
public interface INodeService : IArtemisService
{
///
- /// Gets all available nodes
+ /// Gets all available nodes
///
IEnumerable AvailableNodes { get; }
///
- /// Initializes a node of the provided
+ /// Gets the best matching registration for the provided type
+ ///
+ TypeColorRegistration? GetTypeColor(Type type);
+
+ ///
+ /// Registers a node of the provided
///
/// The plugin the node belongs to
/// The type of node to initialize
NodeTypeRegistration RegisterNodeType(Plugin plugin, Type nodeType);
+
+ ///
+ /// Registers a type with a provided color for use in the node editor
+ ///
+ /// The plugin making the registration
+ /// The type to associate the color with
+ /// The color to display
+ TypeColorRegistration RegisterTypeColor(Plugin plugin, Type type, SKColor color);
}
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Stores/NodeTypeStore.cs b/src/Artemis.Core/Stores/NodeTypeStore.cs
index 705a4d223..aee2896e3 100644
--- a/src/Artemis.Core/Stores/NodeTypeStore.cs
+++ b/src/Artemis.Core/Stores/NodeTypeStore.cs
@@ -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 Registrations = new();
+ private static readonly List ColorRegistrations = new();
public static NodeTypeRegistration Add(NodeData nodeData)
{
@@ -19,7 +21,7 @@ namespace Artemis.Core
if (Registrations.Any(r => r.NodeData == nodeData))
throw new ArtemisCoreException($"Data binding modifier type store already contains modifier '{nodeData.Name}'");
- typeRegistration = new NodeTypeRegistration(nodeData, nodeData.Plugin) { IsInStore = true };
+ typeRegistration = new NodeTypeRegistration(nodeData, nodeData.Plugin) {IsInStore = true};
Registrations.Add(typeRegistration);
}
@@ -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? 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;
- }
- }
}
-}
+}
\ No newline at end of file
diff --git a/src/Artemis.Core/Stores/Registrations/NodeTypeRegistration.cs b/src/Artemis.Core/Stores/Registrations/NodeTypeRegistration.cs
index a9b8e4873..799bee80e 100644
--- a/src/Artemis.Core/Stores/Registrations/NodeTypeRegistration.cs
+++ b/src/Artemis.Core/Stores/Registrations/NodeTypeRegistration.cs
@@ -1,9 +1,10 @@
using System;
+using SkiaSharp;
namespace Artemis.Core
{
///
- /// Represents a registration for a type of
+ /// Represents a registration for a type of
///
public class NodeTypeRegistration
{
@@ -15,13 +16,16 @@ namespace Artemis.Core
Plugin.Disabled += OnDisabled;
}
+ ///
+ /// Gets the node data that was registered
+ ///
public NodeData NodeData { get; }
///
/// Gets the plugin the node is associated with
///
public Plugin Plugin { get; }
-
+
///
/// Gets a boolean indicating whether the registration is in the internal Core store
///
@@ -34,4 +38,51 @@ namespace Artemis.Core
NodeTypeStore.Remove(this);
}
}
+
+ ///
+ /// Represents a registration for a to associate with a certain
+ ///
+ public class TypeColorRegistration
+ {
+ internal TypeColorRegistration(Type type, SKColor color, Plugin plugin)
+ {
+ Type = type;
+ Color = color;
+ Plugin = plugin;
+
+ Plugin.Disabled += OnDisabled;
+ }
+
+ ///
+ /// Gets the type
+ ///
+ public Type Type { get; }
+
+ ///
+ /// Gets the color
+ ///
+ public SKColor Color { get; }
+
+ ///
+ /// Gets a darkened tone of the
+ ///
+ public SKColor DarkenedColor => Color.Darken(0.35f);
+
+ ///
+ /// Gets the plugin type color is associated with
+ ///
+ public Plugin Plugin { get; }
+
+ ///
+ /// Gets a boolean indicating whether the registration is in the internal Core store
+ ///
+ public bool IsInStore { get; internal set; }
+
+ private void OnDisabled(object? sender, EventArgs e)
+ {
+ Plugin.Disabled -= OnDisabled;
+ if (IsInStore)
+ NodeTypeStore.RemoveColor(this);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/Artemis.UI.Shared/Services/ProfileEditorService.cs b/src/Artemis.UI.Shared/Services/ProfileEditorService.cs
index f3f3626ea..37cccd627 100644
--- a/src/Artemis.UI.Shared/Services/ProfileEditorService.cs
+++ b/src/Artemis.UI.Shared/Services/ProfileEditorService.cs
@@ -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 _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();
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 RegisteredPropertyEditors => _registeredPropertyEditors.AsReadOnly();
-
public bool Playing { get; set; }
public bool SuspendEditing
@@ -183,10 +232,10 @@ namespace Artemis.UI.Shared.Services
// No need to deactivate the profile, if needed it will be deactivated next update
if (SelectedProfileConfiguration != null)
SelectedProfileConfiguration.IsBeingEdited = false;
-
+
PreviousSelectedProfileConfiguration = SelectedProfileConfiguration;
SelectedProfileConfiguration = profileConfiguration;
-
+
// The new profile may need activation
if (SelectedProfileConfiguration != null)
{
@@ -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? SelectedProfileChanged;
+ public event EventHandler? SelectedProfileSaved;
+ public event EventHandler? SelectedProfileElementChanged;
+ public event EventHandler? 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? SelectedProfileChanged;
- public event EventHandler? SelectedProfileSaved;
- public event EventHandler? SelectedProfileElementChanged;
- public event EventHandler? 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
}
}
\ No newline at end of file
diff --git a/src/Artemis.UI.Shared/Utilities/TypeUtilities.cs b/src/Artemis.UI.Shared/Utilities/TypeUtilities.cs
new file mode 100644
index 000000000..b979006e4
--- /dev/null
+++ b/src/Artemis.UI.Shared/Utilities/TypeUtilities.cs
@@ -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
+{
+ ///
+ /// Provides UI-oriented utilities for types
+ ///
+ public static class TypeUtilities
+ {
+ internal static INodeService? NodeService;
+
+ ///
+ /// Creates a tuple containing a color and a slightly darkened color for a given type
+ ///
+ /// The type to create the color for
+ 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());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs
index a587da7cc..08f3659e9 100644
--- a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs
+++ b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs
@@ -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,7 +103,8 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
NotifyOfPropertyChange(nameof(AlwaysFinishTimeline));
NotifyOfPropertyChange(nameof(ConditionBehaviourEnabled));
- RenderProfileElement.Timeline.PropertyChanged += TimelineOnPropertyChanged;
+ if (RenderProfileElement != null)
+ RenderProfileElement.Timeline.PropertyChanged += TimelineOnPropertyChanged;
}
#region Event handlers
diff --git a/src/Artemis.UI/Services/RegistrationService.cs b/src/Artemis.UI/Services/RegistrationService.cs
index ec5633647..5adbd456b 100644
--- a/src/Artemis.UI/Services/RegistrationService.cs
+++ b/src/Artemis.UI/Services/RegistrationService.cs
@@ -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);
}
diff --git a/src/Artemis.VisualScripting/Editor/Controls/VisualScriptCablePresenter.cs b/src/Artemis.VisualScripting/Editor/Controls/VisualScriptCablePresenter.cs
index 85f6a8a7c..22bfdcf07 100644
--- a/src/Artemis.VisualScripting/Editor/Controls/VisualScriptCablePresenter.cs
+++ b/src/Artemis.VisualScripting/Editor/Controls/VisualScriptCablePresenter.cs
@@ -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
@@ -51,7 +52,7 @@ namespace Artemis.VisualScripting.Editor.Controls
public Point ValuePosition
{
- get => (Point)GetValue(ValuePositionProperty);
+ get => (Point) GetValue(ValuePositionProperty);
set => SetValue(ValuePositionProperty, value);
}
@@ -63,7 +64,7 @@ namespace Artemis.VisualScripting.Editor.Controls
{
_path = GetTemplateChild(PART_PATH) as Path ?? throw new NullReferenceException($"The Path '{PART_PATH}' is missing.");
_path.MouseDown += OnPathMouseDown;
-
+
Unloaded += OnUnloaded;
}
@@ -110,7 +111,7 @@ namespace Artemis.VisualScripting.Editor.Controls
UpdateBorderBrush();
UpdateValuePosition();
}
-
+
private void OnPinPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(VisualScriptPin.AbsolutePosition))
@@ -119,15 +120,15 @@ 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()
{
if (Cable.From == null || Cable.To == null)
return;
-
+
ValuePosition = new Point(
Cable.From.AbsolutePosition.X + ((Cable.To.AbsolutePosition.X - Cable.From.AbsolutePosition.X) / 2),
Cable.From.AbsolutePosition.Y + ((Cable.To.AbsolutePosition.Y - Cable.From.AbsolutePosition.Y) / 2)
diff --git a/src/Artemis.VisualScripting/Editor/Controls/VisualScriptPinPresenter.cs b/src/Artemis.VisualScripting/Editor/Controls/VisualScriptPinPresenter.cs
index 76c15b45c..88154da03 100644
--- a/src/Artemis.VisualScripting/Editor/Controls/VisualScriptPinPresenter.cs
+++ b/src/Artemis.VisualScripting/Editor/Controls/VisualScriptPinPresenter.cs
@@ -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;
diff --git a/src/Artemis.VisualScripting/Editor/Styles/VisualScriptCablePresenter.xaml b/src/Artemis.VisualScripting/Editor/Styles/VisualScriptCablePresenter.xaml
index 0a507021d..223a2b870 100644
--- a/src/Artemis.VisualScripting/Editor/Styles/VisualScriptCablePresenter.xaml
+++ b/src/Artemis.VisualScripting/Editor/Styles/VisualScriptCablePresenter.xaml
@@ -62,26 +62,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Artemis.VisualScripting/Editor/Styles/VisualScriptPinPresenter.xaml b/src/Artemis.VisualScripting/Editor/Styles/VisualScriptPinPresenter.xaml
index 2a6deed99..f485928e1 100644
--- a/src/Artemis.VisualScripting/Editor/Styles/VisualScriptPinPresenter.xaml
+++ b/src/Artemis.VisualScripting/Editor/Styles/VisualScriptPinPresenter.xaml
@@ -80,31 +80,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-