mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Nodes - Rewrote storage
This commit is contained in:
parent
3dfc25b092
commit
5b183d3010
@ -13,7 +13,7 @@ public class EventCondition : CorePropertyChanged, INodeScriptCondition
|
||||
{
|
||||
private readonly string _displayName;
|
||||
private readonly EventConditionEntity _entity;
|
||||
private readonly EventDefaultNode _eventNode;
|
||||
private EventDefaultNode _eventNode;
|
||||
private DataModelPath? _eventPath;
|
||||
private DateTime _lastProcessedTrigger;
|
||||
private EventOverlapMode _overlapMode;
|
||||
@ -199,6 +199,7 @@ public class EventCondition : CorePropertyChanged, INodeScriptCondition
|
||||
Script = _entity.Script != null
|
||||
? new NodeScript<bool>($"Activate {_displayName}", $"Whether or not the event should activate the {_displayName}", _entity.Script, ProfileElement.Profile)
|
||||
: new NodeScript<bool>($"Activate {_displayName}", $"Whether or not the event should activate the {_displayName}", ProfileElement.Profile);
|
||||
UpdateEventNode();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -219,8 +220,15 @@ public class EventCondition : CorePropertyChanged, INodeScriptCondition
|
||||
public void LoadNodeScript()
|
||||
{
|
||||
Script.Load();
|
||||
|
||||
// The load action may have created an event node, use that one over the one we have here
|
||||
INode? existingEventNode = Script.Nodes.FirstOrDefault(n => n.Id == EventDefaultNode.NodeId);
|
||||
if (existingEventNode != null)
|
||||
_eventNode = (EventDefaultNode) existingEventNode;
|
||||
|
||||
UpdateEventNode();
|
||||
Script.LoadConnections();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -253,13 +261,13 @@ public enum EventOverlapMode
|
||||
/// </summary>
|
||||
Restart,
|
||||
|
||||
/// <summary>
|
||||
/// Ignore subsequent event fires until the timeline finishes
|
||||
/// </summary>
|
||||
Ignore,
|
||||
|
||||
/// <summary>
|
||||
/// Play another copy of the timeline on top of the current run
|
||||
/// </summary>
|
||||
Copy
|
||||
Copy,
|
||||
|
||||
/// <summary>
|
||||
/// Ignore subsequent event fires until the timeline finishes
|
||||
/// </summary>
|
||||
Ignore
|
||||
}
|
||||
@ -72,6 +72,30 @@ namespace Artemis.Core
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="Layer" /> class by copying the provided <paramref name="source"/>.
|
||||
/// </summary>
|
||||
/// <param name="source">The layer to copy</param>
|
||||
/// <param name="parent">The parent of the layer</param>
|
||||
public Layer(Layer source, ProfileElement parent) : base(parent, parent.Profile)
|
||||
{
|
||||
LayerEntity = CoreJson.DeserializeObject<LayerEntity>(CoreJson.SerializeObject(source.LayerEntity, true), true) ?? new LayerEntity();
|
||||
LayerEntity.Id = Guid.NewGuid();
|
||||
|
||||
Profile = source.Profile;
|
||||
Parent = parent;
|
||||
|
||||
_general = new LayerGeneralProperties();
|
||||
_transform = new LayerTransformProperties();
|
||||
|
||||
_leds = new List<ArtemisLed>();
|
||||
Leds = new ReadOnlyCollection<ArtemisLed>(_leds);
|
||||
|
||||
Adapter = new LayerAdapter(this);
|
||||
Load();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A collection of all the LEDs this layer is assigned to.
|
||||
/// </summary>
|
||||
@ -349,7 +373,7 @@ namespace Artemis.Core
|
||||
|
||||
if (ShouldBeEnabled)
|
||||
Enable();
|
||||
else if (Timeline.IsFinished)
|
||||
else if (Timeline.IsFinished && !Children.Any())
|
||||
Disable();
|
||||
|
||||
if (Timeline.Delta == TimeSpan.Zero)
|
||||
@ -365,15 +389,16 @@ namespace Artemis.Core
|
||||
// Remove children that finished their timeline and update the rest
|
||||
for (int index = 0; index < Children.Count; index++)
|
||||
{
|
||||
ProfileElement profileElement = Children[index];
|
||||
if (((Layer) profileElement).Timeline.IsFinished)
|
||||
Layer child = (Layer) Children[index];
|
||||
if (!child.Timeline.IsFinished)
|
||||
{
|
||||
RemoveChild(profileElement);
|
||||
profileElement.Dispose();
|
||||
index--;
|
||||
child.Update(deltaTime);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
profileElement.Update(deltaTime);
|
||||
|
||||
RemoveChild(child);
|
||||
child.Dispose();
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,6 +408,12 @@ namespace Artemis.Core
|
||||
if (Disposed)
|
||||
throw new ObjectDisposedException("Layer");
|
||||
|
||||
RenderSelf(canvas, basePosition);
|
||||
RenderChildren(canvas, basePosition);
|
||||
}
|
||||
|
||||
private void RenderSelf(SKCanvas canvas, SKPointI basePosition)
|
||||
{
|
||||
// Ensure the layer is ready
|
||||
if (!Enabled || Path == null || LayerShape?.Path == null || !General.PropertiesInitialized || !Transform.PropertiesInitialized || !Leds.Any())
|
||||
return;
|
||||
@ -454,6 +485,13 @@ namespace Artemis.Core
|
||||
Timeline.ClearDelta();
|
||||
}
|
||||
|
||||
private void RenderChildren(SKCanvas canvas, SKPointI basePosition)
|
||||
{
|
||||
// Render children first so they go below
|
||||
for (int i = Children.Count - 1; i >= 0; i--)
|
||||
Children[i].Render(canvas, basePosition);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Enable()
|
||||
{
|
||||
@ -523,11 +561,11 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public void CreateCopyAsChild()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
// Create a copy of the layer and it's properties
|
||||
|
||||
// Add to children
|
||||
Layer copy = new(this, this);
|
||||
copy.AddLeds(Leds);
|
||||
copy.Enable();
|
||||
copy.Timeline.JumpToStart();
|
||||
AddChild(copy);
|
||||
}
|
||||
|
||||
internal void CalculateRenderProperties()
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Profile.Nodes;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core
|
||||
@ -51,11 +52,11 @@ namespace Artemis.Core
|
||||
}
|
||||
}
|
||||
|
||||
public static NodeTypeRegistration? Get(Guid pluginGuid, string type)
|
||||
public static NodeTypeRegistration? Get(NodeEntity entity)
|
||||
{
|
||||
lock (Registrations)
|
||||
{
|
||||
return Registrations.FirstOrDefault(r => r.Plugin.Guid == pluginGuid && r.NodeData.Type.Name == type);
|
||||
return Registrations.FirstOrDefault(r => r.MatchesEntity(entity));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Artemis.Storage.Entities.Profile.Nodes;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core
|
||||
@ -37,6 +38,16 @@ namespace Artemis.Core
|
||||
if (IsInStore)
|
||||
NodeTypeStore.Remove(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the provided entity matches this node type registration.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to check.</param>
|
||||
/// <returns><see langword="true"/> if the entity matches this registration; otherwise <see langword="false"/>.</returns>
|
||||
public bool MatchesEntity(NodeEntity entity)
|
||||
{
|
||||
return Plugin.Guid == entity.PluginId && NodeData.Type.Name == entity.Type;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -9,6 +9,11 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public interface INode : INotifyPropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the ID of the node.
|
||||
/// </summary>
|
||||
Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the node
|
||||
/// </summary>
|
||||
|
||||
@ -59,6 +59,9 @@ namespace Artemis.Core
|
||||
|
||||
/// <summary>
|
||||
/// Removes a node from the script
|
||||
/// <para>
|
||||
/// Note: If the node is <see cref="IDisposable"/> you must dispose it yourself, unless you plan to reuse the node.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="node">The node to remove</param>
|
||||
void RemoveNode(INode node);
|
||||
|
||||
36
src/Artemis.Core/VisualScripting/Internal/DefaultNode.cs
Normal file
36
src/Artemis.Core/VisualScripting/Internal/DefaultNode.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a kind of node that cannot be deleted inside a <see cref="INode" />.
|
||||
/// </summary>
|
||||
public interface IDefaultNode : INode
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a kind of node that cannot be deleted inside a <see cref="NodeScript" />.
|
||||
/// </summary>
|
||||
public abstract class DefaultNode : Node, IDefaultNode
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsDefaultNode => true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
protected DefaultNode(Guid id, string name, string description = "") : base(name, description)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -7,19 +7,18 @@ using Humanizer;
|
||||
|
||||
namespace Artemis.Core.Internal
|
||||
{
|
||||
internal class EventDefaultNode : Node
|
||||
internal class EventDefaultNode : DefaultNode
|
||||
{
|
||||
internal static readonly Guid NodeId = new("278735FE-69E9-4A73-A6B8-59E83EE19305");
|
||||
private readonly Dictionary<PropertyInfo, OutputPin> _propertyPins;
|
||||
private readonly List<OutputPin> _pinBucket = new();
|
||||
private IDataModelEvent? _dataModelEvent;
|
||||
|
||||
public EventDefaultNode() : base("Event Arguments", "Contains the event arguments that triggered the evaluation")
|
||||
public EventDefaultNode() : base(NodeId, "Event Arguments", "Contains the event arguments that triggered the evaluation")
|
||||
{
|
||||
_propertyPins = new Dictionary<PropertyInfo, OutputPin>();
|
||||
}
|
||||
|
||||
public override bool IsDefaultNode => true;
|
||||
|
||||
public void CreatePins(IDataModelEvent? dataModelEvent)
|
||||
{
|
||||
if (_dataModelEvent == dataModelEvent)
|
||||
@ -33,10 +32,13 @@ namespace Artemis.Core.Internal
|
||||
if (dataModelEvent == null)
|
||||
return;
|
||||
|
||||
foreach (PropertyInfo propertyInfo in dataModelEvent.ArgumentsType.GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
foreach (PropertyInfo propertyInfo in dataModelEvent.ArgumentsType
|
||||
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
.Where(p => p.CustomAttributes.All(a => a.AttributeType != typeof(DataModelIgnoreAttribute))))
|
||||
{
|
||||
_propertyPins.Add(propertyInfo, CreateOrAddOutputPin(propertyInfo.PropertyType, propertyInfo.Name.Humanize()));
|
||||
}
|
||||
}
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
namespace Artemis.Core.Internal
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Internal
|
||||
{
|
||||
internal interface IExitNode : INode
|
||||
{ }
|
||||
{
|
||||
protected static readonly Guid NodeId = new("410C824D-C5E3-4E3A-8080-D50F6C8B83B8");
|
||||
}
|
||||
|
||||
internal class ExitNode<T> : Node, IExitNode
|
||||
{
|
||||
@ -19,6 +23,7 @@
|
||||
|
||||
public ExitNode(string name, string description = "")
|
||||
{
|
||||
Id = IExitNode.NodeId;
|
||||
Name = name;
|
||||
Description = description;
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Artemis.Core.Properties;
|
||||
using Ninject;
|
||||
using Ninject.Parameters;
|
||||
|
||||
@ -17,6 +16,15 @@ public abstract class Node : CorePropertyChanged, INode
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
private Guid _id;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Guid Id
|
||||
{
|
||||
get => _id;
|
||||
set => SetAndNotify(ref _id , value);
|
||||
}
|
||||
|
||||
private string _name;
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -16,6 +16,8 @@ namespace Artemis.Core
|
||||
{
|
||||
private void NodeTypeStoreOnNodeTypeChanged(object? sender, NodeTypeStoreEvent e)
|
||||
{
|
||||
// Only respond to node changes applicable to the current script
|
||||
if (Entity.Nodes.Any(n => e.TypeRegistration.MatchesEntity(n)))
|
||||
Load();
|
||||
}
|
||||
|
||||
@ -153,41 +155,38 @@ namespace Artemis.Core
|
||||
{
|
||||
lock (_nodes)
|
||||
{
|
||||
List<INode> removeNodes = _nodes.Where(n => !n.IsExitNode).ToList();
|
||||
// Remove nodes no longer on the entity
|
||||
List<INode> removeNodes = _nodes.Where(n => Entity.Nodes.All(e => e.Id != n.Id)).ToList();
|
||||
foreach (INode removeNode in removeNodes)
|
||||
{
|
||||
RemoveNode(removeNode);
|
||||
if (removeNode is IDisposable disposable)
|
||||
disposable.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// Create nodes
|
||||
foreach (NodeEntity entityNode in Entity.Nodes)
|
||||
// Create missing nodes nodes
|
||||
foreach (NodeEntity nodeEntity in Entity.Nodes)
|
||||
{
|
||||
INode? node = LoadNode(entityNode, entityNode.IsExitNode ? ExitNode : null);
|
||||
if (node == null)
|
||||
continue;
|
||||
|
||||
if (!entityNode.IsExitNode)
|
||||
AddNode(node);
|
||||
INode? node = Nodes.FirstOrDefault(n => n.Id == nodeEntity.Id);
|
||||
// If the node already exists, apply the entity to it
|
||||
if (node != null)
|
||||
LoadExistingNode(node, nodeEntity);
|
||||
else
|
||||
{
|
||||
INode? loaded = LoadNode(nodeEntity);
|
||||
if (loaded != null)
|
||||
AddNode(loaded);
|
||||
}
|
||||
}
|
||||
|
||||
LoadConnections();
|
||||
}
|
||||
|
||||
private INode? LoadNode(NodeEntity nodeEntity, INode? node)
|
||||
{
|
||||
if (node == null)
|
||||
{
|
||||
NodeTypeRegistration? nodeTypeRegistration = NodeTypeStore.Get(nodeEntity.PluginId, nodeEntity.Type);
|
||||
if (nodeTypeRegistration == null)
|
||||
return null;
|
||||
|
||||
// Create the node
|
||||
node = nodeTypeRegistration.NodeData.CreateNode(this, nodeEntity);
|
||||
}
|
||||
else
|
||||
private void LoadExistingNode(INode node, NodeEntity nodeEntity)
|
||||
{
|
||||
node.X = nodeEntity.X;
|
||||
node.Y = nodeEntity.Y;
|
||||
}
|
||||
|
||||
// Restore pin collections
|
||||
foreach (NodePinCollectionEntity entityNodePinCollection in nodeEntity.PinCollections)
|
||||
@ -201,7 +200,17 @@ namespace Artemis.Core
|
||||
while (collection.Count() < entityNodePinCollection.Amount)
|
||||
collection.Add(collection.CreatePin());
|
||||
}
|
||||
}
|
||||
|
||||
private INode? LoadNode(NodeEntity nodeEntity)
|
||||
{
|
||||
NodeTypeRegistration? nodeTypeRegistration = NodeTypeStore.Get(nodeEntity);
|
||||
if (nodeTypeRegistration == null)
|
||||
return null;
|
||||
|
||||
// Create the node
|
||||
INode node = nodeTypeRegistration.NodeData.CreateNode(this, nodeEntity);
|
||||
LoadExistingNode(node, nodeEntity);
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -213,10 +222,10 @@ namespace Artemis.Core
|
||||
List<INode> nodes = Nodes.ToList();
|
||||
foreach (NodeConnectionEntity nodeConnectionEntity in Entity.Connections.OrderBy(p => p.SourcePinCollectionId))
|
||||
{
|
||||
INode? source = nodes.ElementAtOrDefault(nodeConnectionEntity.SourceNode);
|
||||
INode? source = nodes.FirstOrDefault(n => n.Id == nodeConnectionEntity.SourceNode);
|
||||
if (source == null)
|
||||
continue;
|
||||
INode? target = nodes.ElementAtOrDefault(nodeConnectionEntity.TargetNode);
|
||||
INode? target = nodes.FirstOrDefault(n => n.Id == nodeConnectionEntity.TargetNode);
|
||||
if (target == null)
|
||||
continue;
|
||||
|
||||
@ -263,12 +272,11 @@ namespace Artemis.Core
|
||||
if (Nodes.Count() == 1)
|
||||
return;
|
||||
|
||||
int id = 0;
|
||||
foreach (INode node in Nodes)
|
||||
{
|
||||
NodeEntity nodeEntity = new()
|
||||
{
|
||||
Id = id,
|
||||
Id = node.Id,
|
||||
PluginId = NodeTypeStore.GetPlugin(node)?.Guid ?? Constants.CorePlugin.Guid,
|
||||
Type = node.GetType().Name,
|
||||
X = node.X,
|
||||
@ -294,7 +302,6 @@ namespace Artemis.Core
|
||||
}
|
||||
|
||||
Entity.Nodes.Add(nodeEntity);
|
||||
id++;
|
||||
}
|
||||
|
||||
// Store connections
|
||||
@ -315,7 +322,6 @@ namespace Artemis.Core
|
||||
private void SavePins(INode node, int collectionId, IEnumerable<IPin> pins)
|
||||
{
|
||||
int sourcePinId = 0;
|
||||
List<INode> nodes = Nodes.ToList();
|
||||
foreach (IPin sourcePin in pins.Where(p => p.Direction == PinDirection.Input))
|
||||
{
|
||||
foreach (IPin targetPin in sourcePin.ConnectedTo)
|
||||
@ -337,11 +343,11 @@ namespace Artemis.Core
|
||||
Entity.Connections.Add(new NodeConnectionEntity
|
||||
{
|
||||
SourceType = sourcePin.Type.Name,
|
||||
SourceNode = nodes.IndexOf(node),
|
||||
SourceNode = node.Id,
|
||||
SourcePinCollectionId = collectionId,
|
||||
SourcePinId = sourcePinId,
|
||||
TargetType = targetPin.Type.Name,
|
||||
TargetNode = nodes.IndexOf(targetPin.Node),
|
||||
TargetNode = targetPin.Node.Id,
|
||||
TargetPinCollectionId = targetPinCollectionId,
|
||||
TargetPinId = targetPinId
|
||||
});
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
namespace Artemis.Storage.Entities.Profile.Nodes
|
||||
using System;
|
||||
|
||||
namespace Artemis.Storage.Entities.Profile.Nodes
|
||||
{
|
||||
public class NodeConnectionEntity
|
||||
{
|
||||
public string SourceType { get; set; }
|
||||
public int SourceNode { get; set; }
|
||||
public int TargetNode { get; set; }
|
||||
public Guid SourceNode { get; set; }
|
||||
public Guid TargetNode { get; set; }
|
||||
public int SourcePinCollectionId { get; set; }
|
||||
public int SourcePinId { get; set; }
|
||||
public string TargetType { get; set; }
|
||||
|
||||
@ -10,7 +10,7 @@ namespace Artemis.Storage.Entities.Profile.Nodes
|
||||
PinCollections = new List<NodePinCollectionEntity>();
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
public string Type { get; set; }
|
||||
public Guid PluginId { get; set; }
|
||||
|
||||
|
||||
@ -39,7 +39,8 @@
|
||||
<TextBlock Name="MainButtonLabel"
|
||||
Grid.Column="0"
|
||||
VerticalAlignment="Center"
|
||||
TextAlignment="Left" />
|
||||
TextAlignment="Left"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
<TextBlock Name="ChevronTextBlock"
|
||||
Grid.Column="1"
|
||||
FontFamily="{DynamicResource SymbolThemeFontFamily}"
|
||||
|
||||
@ -18,7 +18,8 @@
|
||||
DockPanel.Dock="Top"
|
||||
HorizontalAlignment="Stretch"
|
||||
FilterTypes="{CompiledBinding FilterTypes}"
|
||||
DataModelPath="{CompiledBinding EventPath}"/>
|
||||
DataModelPath="{CompiledBinding EventPath}"
|
||||
ShowFullPath="{CompiledBinding ShowFullPaths.Value}"/>
|
||||
|
||||
<TextBlock DockPanel.Dock="Top">When the event fires..</TextBlock>
|
||||
<ComboBox PlaceholderText="Select a play mode" HorizontalAlignment="Stretch" DockPanel.Dock="Top" SelectedIndex="{CompiledBinding SelectedTriggerMode}">
|
||||
|
||||
@ -4,6 +4,7 @@ using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Screens.VisualScripting;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
@ -20,15 +21,17 @@ public class EventConditionViewModel : ActivatableViewModelBase
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly ObservableAsPropertyHelper<bool> _showOverlapOptions;
|
||||
private readonly IWindowService _windowService;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private ObservableAsPropertyHelper<DataModelPath?>? _eventPath;
|
||||
private ObservableAsPropertyHelper<int>? _selectedOverlapMode;
|
||||
private ObservableAsPropertyHelper<int>? _selectedTriggerMode;
|
||||
|
||||
public EventConditionViewModel(EventCondition eventCondition, IProfileEditorService profileEditorService, IWindowService windowService)
|
||||
public EventConditionViewModel(EventCondition eventCondition, IProfileEditorService profileEditorService, IWindowService windowService, ISettingsService settingsService)
|
||||
{
|
||||
_eventCondition = eventCondition;
|
||||
_profileEditorService = profileEditorService;
|
||||
_windowService = windowService;
|
||||
_settingsService = settingsService;
|
||||
_showOverlapOptions = this.WhenAnyValue(vm => vm.SelectedTriggerMode)
|
||||
.Select(m => m == 0)
|
||||
.ToProperty(this, vm => vm.ShowOverlapOptions);
|
||||
@ -47,6 +50,7 @@ public class EventConditionViewModel : ActivatableViewModelBase
|
||||
public ReactiveCommand<Unit, Unit> OpenEditor { get; }
|
||||
public bool ShowOverlapOptions => _showOverlapOptions.Value;
|
||||
public bool IsConditionForLayer => _eventCondition.ProfileElement is Layer;
|
||||
public PluginSetting<bool> ShowFullPaths => _settingsService.GetSetting("ProfileEditor.ShowFullPaths", false);
|
||||
|
||||
public DataModelPath? EventPath
|
||||
{
|
||||
|
||||
@ -128,39 +128,40 @@
|
||||
<MenuItem Header="_Options">
|
||||
<MenuItem Header="Focus Selected Layer"
|
||||
ToolTip.Tip="If enabled, displays only the layer you currently have selected"
|
||||
IsEnabled="False">
|
||||
Command="{CompiledBinding ToggleBooleanSetting}"
|
||||
CommandParameter="{CompiledBinding FocusSelectedLayer}">
|
||||
<MenuItem.Icon>
|
||||
<CheckBox BorderThickness="0"
|
||||
IsHitTestVisible="False"
|
||||
IsChecked="{Binding FocusSelectedLayer.Value}" />
|
||||
<avalonia:MaterialIcon Kind="Check" IsVisible="{CompiledBinding FocusSelectedLayer.Value}"></avalonia:MaterialIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Display Data Model Values">
|
||||
<MenuItem Header="Display Data Model Values"
|
||||
Command="{CompiledBinding ToggleBooleanSetting}"
|
||||
CommandParameter="{CompiledBinding ShowDataModelValues}">
|
||||
<MenuItem.Icon>
|
||||
<CheckBox BorderThickness="0"
|
||||
IsHitTestVisible="False"
|
||||
IsChecked="{Binding ShowDataModelValues.Value}" />
|
||||
<avalonia:MaterialIcon Kind="Check" IsVisible="{CompiledBinding ShowDataModelValues.Value}"></avalonia:MaterialIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Display Full Condition Paths">
|
||||
<MenuItem Header="Display Full Condition Paths"
|
||||
Command="{CompiledBinding ToggleBooleanSetting}"
|
||||
CommandParameter="{CompiledBinding ShowFullPaths}">
|
||||
<MenuItem.Icon>
|
||||
<CheckBox BorderThickness="0"
|
||||
IsHitTestVisible="False"
|
||||
IsChecked="{Binding ShowFullPaths.Value}" />
|
||||
<avalonia:MaterialIcon Kind="Check" IsVisible="{CompiledBinding ShowFullPaths.Value}"></avalonia:MaterialIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Always Display Cable Values" ToolTip.Tip="If enabled, cable values are always shown instead of only on hover">
|
||||
<MenuItem Header="Always Display Cable Values"
|
||||
ToolTip.Tip="If enabled, cable values are always shown instead of only on hover"
|
||||
Command="{CompiledBinding ToggleBooleanSetting}"
|
||||
CommandParameter="{CompiledBinding AlwaysShowValues}">
|
||||
<MenuItem.Icon>
|
||||
<CheckBox BorderThickness="0"
|
||||
IsHitTestVisible="False"
|
||||
IsChecked="{Binding AlwaysShowValues.Value}" />
|
||||
<avalonia:MaterialIcon Kind="Check" IsVisible="{CompiledBinding AlwaysShowValues.Value}"></avalonia:MaterialIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Apply All Data Bindings During Edit" ToolTip.Tip="If enabled, updates all data bindings instead of only the one you are editing">
|
||||
<MenuItem Header="Apply All Data Bindings During Edit"
|
||||
ToolTip.Tip="If enabled, updates all data bindings instead of only the one you are editing"
|
||||
Command="{CompiledBinding ToggleBooleanSetting}"
|
||||
CommandParameter="{CompiledBinding AlwaysApplyDataBindings}">
|
||||
<MenuItem.Icon>
|
||||
<CheckBox BorderThickness="0"
|
||||
IsHitTestVisible="False"
|
||||
IsChecked="{Binding AlwaysApplyDataBindings.Value}" />
|
||||
<avalonia:MaterialIcon Kind="Check" IsVisible="{CompiledBinding AlwaysApplyDataBindings.Value}"></avalonia:MaterialIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</MenuItem>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using Artemis.Core;
|
||||
@ -12,13 +13,15 @@ namespace Artemis.UI.Screens.ProfileEditor.MenuBar;
|
||||
public class MenuBarViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private ProfileEditorHistory? _history;
|
||||
private ObservableAsPropertyHelper<ProfileConfiguration?>? _profileConfiguration;
|
||||
private ObservableAsPropertyHelper<bool>? _isSuspended;
|
||||
|
||||
public MenuBarViewModel(IProfileEditorService profileEditorService, IProfileService profileService)
|
||||
public MenuBarViewModel(IProfileEditorService profileEditorService, IProfileService profileService, ISettingsService settingsService)
|
||||
{
|
||||
_profileService = profileService;
|
||||
_settingsService = settingsService;
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
profileEditorService.History.Subscribe(history => History = history).DisposeWith(d);
|
||||
@ -29,16 +32,30 @@ public class MenuBarViewModel : ActivatableViewModelBase
|
||||
.ToProperty(this, vm => vm.IsSuspended)
|
||||
.DisposeWith(d);
|
||||
});
|
||||
|
||||
ToggleBooleanSetting = ReactiveCommand.Create<PluginSetting<bool>>(ExecuteToggleBooleanSetting);
|
||||
}
|
||||
|
||||
private void ExecuteToggleBooleanSetting(PluginSetting<bool> setting)
|
||||
{
|
||||
setting.Value = !setting.Value;
|
||||
setting.Save();
|
||||
}
|
||||
|
||||
public ReactiveCommand<PluginSetting<bool>, Unit> ToggleBooleanSetting { get; }
|
||||
public ProfileConfiguration? ProfileConfiguration => _profileConfiguration?.Value;
|
||||
public PluginSetting<bool> FocusSelectedLayer => _settingsService.GetSetting("ProfileEditor.FocusSelectedLayer", false);
|
||||
public PluginSetting<bool> ShowDataModelValues => _settingsService.GetSetting("ProfileEditor.ShowDataModelValues", false);
|
||||
public PluginSetting<bool> ShowFullPaths => _settingsService.GetSetting("ProfileEditor.ShowFullPaths", false);
|
||||
public PluginSetting<bool> AlwaysShowValues => _settingsService.GetSetting("ProfileEditor.AlwaysShowValues", false);
|
||||
public PluginSetting<bool> AlwaysApplyDataBindings => _settingsService.GetSetting("ProfileEditor.AlwaysApplyDataBindings", false);
|
||||
|
||||
public ProfileEditorHistory? History
|
||||
{
|
||||
get => _history;
|
||||
set => RaiseAndSetIfChanged(ref _history, value);
|
||||
}
|
||||
|
||||
public ProfileConfiguration? ProfileConfiguration => _profileConfiguration?.Value;
|
||||
|
||||
public bool IsSuspended
|
||||
{
|
||||
get => _isSuspended?.Value ?? false;
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
</TreeView.Styles>
|
||||
<TreeView.DataTemplates>
|
||||
<TreeDataTemplate DataType="{x:Type core:NodeData}">
|
||||
<StackPanel Margin="-15 1 0 1">
|
||||
<StackPanel Margin="-15 1 0 1" Background="Transparent" PointerReleased="InputElement_OnPointerReleased">
|
||||
<TextBlock Classes="BodyStrongTextBlockStyle" Text="{Binding Name}"></TextBlock>
|
||||
<TextBlock Foreground="{DynamicResource TextFillColorSecondary}" Text="{Binding Description}"></TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
using Artemis.Core;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Mixins;
|
||||
using Avalonia.Controls.PanAndZoom;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.LogicalTree;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
@ -26,4 +29,13 @@ public class NodePickerView : ReactiveUserControl<NodePickerViewModel>
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
private void InputElement_OnPointerReleased(object? sender, PointerReleasedEventArgs e)
|
||||
{
|
||||
if (sender is not IDataContextProvider {DataContext: NodeData nodeData} || ViewModel == null)
|
||||
return;
|
||||
|
||||
ViewModel.CreateNode(nodeData);
|
||||
ViewModel.IsVisible = false;
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,6 @@ public class NodePickerViewModel : ActivatableViewModelBase
|
||||
|
||||
private bool _isVisible;
|
||||
private Point _position;
|
||||
private DateTime _closed;
|
||||
private string? _searchText;
|
||||
private object? _selectedNode;
|
||||
private IPin? _targetPin;
|
||||
@ -43,7 +42,6 @@ public class NodePickerViewModel : ActivatableViewModelBase
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
if (DateTime.Now - _closed > TimeSpan.FromSeconds(10))
|
||||
SearchText = null;
|
||||
TargetPin = null;
|
||||
|
||||
@ -54,23 +52,7 @@ public class NodePickerViewModel : ActivatableViewModelBase
|
||||
});
|
||||
|
||||
IsVisible = true;
|
||||
|
||||
Disposable.Create(() =>
|
||||
{
|
||||
_closed = DateTime.Now;
|
||||
IsVisible = false;
|
||||
}).DisposeWith(d);
|
||||
});
|
||||
|
||||
this.WhenAnyValue(vm => vm.SelectedNode)
|
||||
.WhereNotNull()
|
||||
.Where(o => o is NodeData)
|
||||
.Throttle(TimeSpan.FromMilliseconds(200), RxApp.MainThreadScheduler)
|
||||
.Subscribe(data =>
|
||||
{
|
||||
CreateNode((NodeData) data);
|
||||
IsVisible = false;
|
||||
SelectedNode = null;
|
||||
Disposable.Create(() => IsVisible = false).DisposeWith(d);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -10,5 +10,6 @@
|
||||
<dataModelPicker:DataModelPickerButton Classes="condensed"
|
||||
DataModelPath="{CompiledBinding DataModelPath}"
|
||||
Modules="{CompiledBinding Modules}"
|
||||
ShowDataModelValues="{CompiledBinding ShowDataModelValues.Value}" />
|
||||
ShowDataModelValues="{CompiledBinding ShowDataModelValues.Value}"
|
||||
ShowFullPath="{CompiledBinding ShowFullPaths.Value}"/>
|
||||
</UserControl>
|
||||
@ -1,5 +1,4 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.VisualScripting.Nodes.Operators.Screens;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Operators;
|
||||
@ -11,13 +10,6 @@ public class EnumEqualsNode : Node<int, EnumEqualsNodeCustomViewModel>
|
||||
{
|
||||
InputPin = CreateInputPin<Enum>();
|
||||
OutputPin = CreateOutputPin<bool>();
|
||||
|
||||
InputPin.PinConnected += InputPinOnPinConnected;
|
||||
}
|
||||
|
||||
private void InputPinOnPinConnected(object? sender, SingleValueEventArgs<IPin> e)
|
||||
{
|
||||
Storage = 0;
|
||||
}
|
||||
|
||||
public InputPin<Enum> InputPin { get; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user