diff --git a/src/Artemis.Core/VisualScripting/InputPin.cs b/src/Artemis.Core/VisualScripting/InputPin.cs index dc88e37b0..0244b6da3 100644 --- a/src/Artemis.Core/VisualScripting/InputPin.cs +++ b/src/Artemis.Core/VisualScripting/InputPin.cs @@ -26,6 +26,7 @@ namespace Artemis.Core { _value = value; IsEvaluated = true; + OnPropertyChanged(nameof(PinValue)); } } @@ -75,6 +76,7 @@ namespace Artemis.Core _value = value; IsEvaluated = true; + OnPropertyChanged(nameof(PinValue)); } } diff --git a/src/Artemis.Core/VisualScripting/OutputPin.cs b/src/Artemis.Core/VisualScripting/OutputPin.cs index 0aec65d05..ce80e3574 100644 --- a/src/Artemis.Core/VisualScripting/OutputPin.cs +++ b/src/Artemis.Core/VisualScripting/OutputPin.cs @@ -25,6 +25,8 @@ namespace Artemis.Core { _value = value; IsEvaluated = true; + + OnPropertyChanged(nameof(PinValue)); } } @@ -64,6 +66,7 @@ namespace Artemis.Core _value = value; IsEvaluated = true; + OnPropertyChanged(nameof(PinValue)); } } diff --git a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs index ae26c1933..4fe3a8c9b 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs @@ -118,6 +118,8 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions { if (e.ChangedButton != MouseButton.Left) return; + if (RenderProfileElement == null) + return; RenderProfileElement.DisplayCondition ??= new NodeScript("End Result", ""); diff --git a/src/Artemis.UI/Screens/ProfileEditor/Windows/NodeScriptWindowView.xaml b/src/Artemis.UI/Screens/ProfileEditor/Windows/NodeScriptWindowView.xaml index 5076ff482..ffa9fb687 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Windows/NodeScriptWindowView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Windows/NodeScriptWindowView.xaml @@ -1,26 +1,35 @@  - - - - + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:mde="https://spiegelp.github.io/MaterialDesignExtensions/winfx/xaml" + xmlns:svgc="http://sharpvectors.codeplex.com/svgc/" + xmlns:controls="clr-namespace:Artemis.VisualScripting.Editor.Controls;assembly=Artemis.VisualScripting" + xmlns:windows="clr-namespace:Artemis.UI.Screens.ProfileEditor.Windows" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + mc:Ignorable="d" + Title="Node Script | Artemis" + TitleBarIcon="{svgc:SvgImage Source=/Resources/Images/Logo/bow-white.svg}" + Foreground="{DynamicResource MaterialDesignBody}" + Background="{DynamicResource MaterialDesignPaper}" + FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto" + UseLayoutRounding="True" + FadeContentIfInactive="False" + Width="1200" + Height="1000" + d:DesignHeight="800" d:DesignWidth="800" + d:DataContext="{d:DesignInstance windows:NodeScriptWindowViewModel}" + Icon="/Resources/Images/Logo/bow.ico"> + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Debug/DebugView.xaml b/src/Artemis.UI/Screens/Settings/Debug/DebugView.xaml index 1c70ff37c..0ab64af07 100644 --- a/src/Artemis.UI/Screens/Settings/Debug/DebugView.xaml +++ b/src/Artemis.UI/Screens/Settings/Debug/DebugView.xaml @@ -21,15 +21,9 @@ d:DesignHeight="800" d:DesignWidth="800" d:DataContext="{d:DesignInstance debug:DebugViewModel}" Icon="/Resources/Images/Logo/bow.ico" Topmost="{Binding StayOnTopSetting.Value}"> - + - + diff --git a/src/Artemis.VisualScripting/Converters/CenterTranslateConverter.cs b/src/Artemis.VisualScripting/Converters/CenterTranslateConverter.cs new file mode 100644 index 000000000..5834a1a7c --- /dev/null +++ b/src/Artemis.VisualScripting/Converters/CenterTranslateConverter.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace Artemis.VisualScripting.Converters +{ + internal class CenterTranslateConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is not double doubleValue) + return value; + + return doubleValue / 2 * -1; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is not double doubleValue) + return value; + + return doubleValue * -1 * 2; + } + } +} \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Editor/Controls/VisualScriptCablePresenter.cs b/src/Artemis.VisualScripting/Editor/Controls/VisualScriptCablePresenter.cs index 32de5d316..4487ba42c 100644 --- a/src/Artemis.VisualScripting/Editor/Controls/VisualScriptCablePresenter.cs +++ b/src/Artemis.VisualScripting/Editor/Controls/VisualScriptCablePresenter.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -25,11 +26,11 @@ namespace Artemis.VisualScripting.Editor.Controls #region Dependency Properties public static readonly DependencyProperty CableProperty = DependencyProperty.Register( - "Cable", typeof(VisualScriptCable), typeof(VisualScriptCablePresenter), new PropertyMetadata(default(VisualScriptCable))); + "Cable", typeof(VisualScriptCable), typeof(VisualScriptCablePresenter), new PropertyMetadata(default(VisualScriptCable), CableChanged)); public VisualScriptCable Cable { - get => (VisualScriptCable)GetValue(CableProperty); + get => (VisualScriptCable) GetValue(CableProperty); set => SetValue(CableProperty, value); } @@ -38,18 +39,37 @@ namespace Artemis.VisualScripting.Editor.Controls public double Thickness { - get => (double)GetValue(ThicknessProperty); + get => (double) GetValue(ThicknessProperty); set => SetValue(ThicknessProperty, value); } + public static readonly DependencyProperty ValuePositionProperty = DependencyProperty.Register( + "ValuePosition", typeof(Point), typeof(VisualScriptCablePresenter), new PropertyMetadata(default(Point))); + + public Point ValuePosition + { + get => (Point) GetValue(ValuePositionProperty); + set => SetValue(ValuePositionProperty, value); + } + #endregion - + #region Methods public override void OnApplyTemplate() { _path = GetTemplateChild(PART_PATH) as Path ?? throw new NullReferenceException($"The Path '{PART_PATH}' is missing."); _path.MouseDown += OnPathMouseDown; + + Unloaded += OnUnloaded; + } + + private void OnUnloaded(object sender, RoutedEventArgs e) + { + if (Cable?.From != null) + Cable.From.PropertyChanged += OnPinPropertyChanged; + if (Cable?.To != null) + Cable.To.PropertyChanged += OnPinPropertyChanged; } private void OnPathMouseDown(object sender, MouseButtonEventArgs args) @@ -63,6 +83,48 @@ namespace Artemis.VisualScripting.Editor.Controls Cable.Disconnect(); } + private static void CableChanged(DependencyObject d, DependencyPropertyChangedEventArgs args) + { + if (d is not VisualScriptCablePresenter presenter) return; + + presenter.CableChanged(args); + } + + private void CableChanged(DependencyPropertyChangedEventArgs args) + { + if (args.OldValue is VisualScriptCable oldCable) + { + oldCable.From.PropertyChanged -= OnPinPropertyChanged; + oldCable.To.PropertyChanged -= OnPinPropertyChanged; + } + + if (args.NewValue is VisualScriptCable newCable) + { + newCable.From.PropertyChanged += OnPinPropertyChanged; + newCable.To.PropertyChanged += OnPinPropertyChanged; + } + + UpdateValuePosition(); + } + + private void OnPinPropertyChanged(object sender, PropertyChangedEventArgs e) + { + UpdateValuePosition(); + } + + private void UpdateValuePosition() + { + if (Cable.From == null || Cable.To == null) + ValuePosition = new Point(); + else + { + 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) + ); + } + } + #endregion } -} +} \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Editor/Styles/VisualScriptCablePresenter.xaml b/src/Artemis.VisualScripting/Editor/Styles/VisualScriptCablePresenter.xaml index d51f0cfa3..e5cb83c06 100644 --- a/src/Artemis.VisualScripting/Editor/Styles/VisualScriptCablePresenter.xaml +++ b/src/Artemis.VisualScripting/Editor/Styles/VisualScriptCablePresenter.xaml @@ -1,33 +1,53 @@  + xmlns:controls="clr-namespace:Artemis.VisualScripting.Editor.Controls" + xmlns:converters="clr-namespace:Artemis.VisualScripting.Converters"> + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + +