Nodes - Added type color registration system

Nodes - Generate (stable) type colors for undefined types
This commit is contained in:
Robert committed 2021-08-19 11:40:50 +02:00
1 parent 5675d1895b
commit b8077ca589
12 files changed
+297 -147

No files matched your search

@@ -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)
@@ -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>