Nodes - Added option to hide cable values until mouseover

Nodes - Only show cable value on first connection
This commit is contained in:
Robert committed 2021-08-26 00:20:57 +02:00
1 parent 4fbd229846
commit 73794591bc
11 files changed
+81 -12

No files matched your search

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@@ -24,6 +25,7 @@ namespace Artemis.VisualScripting.Editor.Controls
#region Properties & Fields
private Path _path;
private Border _valueBorder;
#endregion
@@ -56,6 +58,15 @@ namespace Artemis.VisualScripting.Editor.Controls
set => SetValue(ValuePositionProperty, value);
}
public static readonly DependencyProperty AlwaysShowValuesProperty = DependencyProperty.Register(
"AlwaysShowValues", typeof(bool), typeof(VisualScriptCablePresenter), new PropertyMetadata(default(bool), AlwaysShowValuesChanged));
public bool AlwaysShowValues
{
get => (bool) GetValue(AlwaysShowValuesProperty);
set => SetValue(AlwaysShowValuesProperty, value);
}
#endregion
#region Methods
@@ -63,9 +74,15 @@ namespace Artemis.VisualScripting.Editor.Controls
public override void OnApplyTemplate()
{
_path = GetTemplateChild(PART_PATH) as Path ?? throw new NullReferenceException($"The Path '{PART_PATH}' is missing.");
_path.MouseDown += OnPathMouseDown;
_valueBorder = GetTemplateChild("PART_ValueDisplay") as Border ?? throw new NullReferenceException("The Border 'PART_ValueDisplay' is missing.");
_path.MouseEnter += (_, _) => UpdateValueVisibility();
_path.MouseLeave += (_, _) => UpdateValueVisibility();
_valueBorder.MouseEnter += (_, _) => UpdateValueVisibility();
_valueBorder.MouseLeave += (_, _) => UpdateValueVisibility();
Unloaded += OnUnloaded;
UpdateValueVisibility();
}
private void OnUnloaded(object sender, RoutedEventArgs e)
@@ -112,6 +129,26 @@ namespace Artemis.VisualScripting.Editor.Controls
UpdateValuePosition();
}
private static void AlwaysShowValuesChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
{
if (d is not VisualScriptCablePresenter presenter) return;
presenter.UpdateValueVisibility();
}
private void UpdateValueVisibility()
{
if (_valueBorder == null)
return;
if (AlwaysShowValues && Cable.From.Connections.LastOrDefault() == Cable)
_valueBorder.Visibility = Visibility.Visible;
else if (_valueBorder.IsMouseOver || _path.IsMouseOver)
_valueBorder.Visibility = Visibility.Visible;
else
_valueBorder.Visibility = Visibility.Collapsed;
}
private void OnPinPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(VisualScriptPin.AbsolutePosition))
@@ -27,6 +27,15 @@ namespace Artemis.VisualScripting.Editor.Controls
set => SetValue(AvailableNodesProperty, value);
}
public static readonly DependencyProperty AlwaysShowValuesProperty = DependencyProperty.Register(
"AlwaysShowValues", typeof(bool), typeof(VisualScriptEditor), new PropertyMetadata(default(bool)));
public bool AlwaysShowValues
{
get => (bool)GetValue(AlwaysShowValuesProperty);
set => SetValue(AlwaysShowValuesProperty, value);
}
#endregion
}
}
@@ -114,6 +114,15 @@ namespace Artemis.VisualScripting.Editor.Controls
set => SetValue(AvailableNodesProperty, value);
}
public static readonly DependencyProperty AlwaysShowValuesProperty = DependencyProperty.Register(
"AlwaysShowValues", typeof(bool), typeof(VisualScriptPresenter), new PropertyMetadata(default(bool)));
public bool AlwaysShowValues
{
get => (bool)GetValue(AlwaysShowValuesProperty);
set => SetValue(AlwaysShowValuesProperty, value);
}
public static readonly DependencyProperty CreateNodeCommandProperty = DependencyProperty.Register(
"CreateNodeCommand", typeof(ICommand), typeof(VisualScriptPresenter), new PropertyMetadata(default(ICommand)));
@@ -8,7 +8,8 @@
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<controls:VisualScriptPresenter Script="{TemplateBinding Script}"
AvailableNodes="{TemplateBinding AvailableNodes}" />
AvailableNodes="{TemplateBinding AvailableNodes}"
AlwaysShowValues="{TemplateBinding AlwaysShowValues}"/>
</Border>
</ControlTemplate>
@@ -70,7 +70,7 @@
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:VisualScriptCablePresenter Cable="{Binding .}" />
<controls:VisualScriptCablePresenter Cable="{Binding .}" AlwaysShowValues="{Binding AlwaysShowValues, RelativeSource={RelativeSource AncestorType=controls:VisualScriptPresenter}}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
@@ -11,12 +11,10 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
private readonly DataModelNode _node;
private BindableCollection<Module> _modules;
public DataModelNodeCustomViewModel(DataModelNode node, ISettingsService settingsService, IPluginManagementService test) : base(node)
public DataModelNodeCustomViewModel(DataModelNode node, ISettingsService settingsService) : base(node)
{
_node = node;
var tessst = test.GetFeaturesOfType<Module>();
ShowFullPaths = settingsService.GetSetting("ProfileEditor.ShowFullPaths", true);
ShowDataModelValues = settingsService.GetSetting("ProfileEditor.ShowDataModelValues", false);
}
@@ -38,7 +36,7 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
if (ReferenceEquals(_node.DataModelPath, value))
return;
_node.DataModelPath.Dispose();
_node.DataModelPath?.Dispose();
_node.DataModelPath = value;
_node.DataModelPath.Save();
@@ -45,7 +45,9 @@ namespace Artemis.VisualScripting.Nodes
if (Output == null)
UpdateOutputPin(false);
Output.Value = DataModelPath.GetValue() ?? Output.Type.GetDefault();
object pathValue = DataModelPath.GetValue();
if (pathValue != null)
Output.Value = pathValue;
}
}