/// <summary> /// Called to notify the graph that a node wants to get selected /// </summary> /// <param name="selectedNode"></param> public void NotifySelected(CScriptNodeViewmodel selectedNode) { if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { int index = m_selectedNodes.IndexOf(selectedNode); if (index >= 0) { selectedNode.IsSelected = false; m_selectedNodes.RemoveAt(index); return; } } else { if (m_selectedNodes.Contains(selectedNode)) { return; } DeselectAll(); } selectedNode.IsSelected = true; m_selectedNodes.Add(selectedNode); }
public void LoadGraph(CGraph graph) { CGraph oldGraph = ScriptGraph; ScriptGraph = graph; GraphName = ScriptGraph.Name; Dictionary <CNode, CScriptNodeViewmodel> nodeToViewModel = new Dictionary <CNode, CScriptNodeViewmodel>(); List <CScriptNodeViewmodel> newNodes = new List <CScriptNodeViewmodel>(); foreach (CNode graphNode in ScriptGraph.m_nodes) { CScriptNodeViewmodel viewmodel = new CScriptNodeViewmodel(graphNode, this); nodeToViewModel.Add(graphNode, viewmodel); newNodes.Add(viewmodel); } m_selectedNodes.Clear(); Nodes = new ObservableCollection <CScriptNodeViewmodel>(newNodes); Connections.Clear(); ResolveScriptNodeConnections(ScriptGraph.m_nodes, nodeToViewModel); UndoRedoUtility.Purge(null); OnGraphChanged?.Invoke(this, oldGraph, ScriptGraph); }
private void ResolveScriptNodeConnections(IEnumerable <CNode> nodes, Dictionary <CNode, CScriptNodeViewmodel> nodeToViewModel) { foreach (CNode graphNode in nodes) { CScriptNodeViewmodel sourceViewModel = nodeToViewModel[graphNode]; for (int i = 0; i < graphNode.OutExecutionPins.Count; i++) { CExecutionPin inExecutionPin = graphNode.OutExecutionPins[i]; if (inExecutionPin.TargetNode == null) { continue; } CScriptNodeViewmodel targetViewModel = nodeToViewModel[inExecutionPin.TargetNode]; if (targetViewModel.InExecutionPins.Count > 0) { CNodeConnectionViewModel newConnection = new CNodeConnectionViewModel(sourceViewModel.OutExecutionPins[i], targetViewModel.InExecutionPins[inExecutionPin.TargetPinIndex], this); newConnection.Connect(); } else { inExecutionPin.TargetNode = null; LogUtility.Log("[ScriptLoadError] node {0} tried to connect to {1} but the target does not have an in execution pin", sourceViewModel.Name, targetViewModel.Name); } } for (int i = 0; i < graphNode.InputPins.Count; i++) { CInputPin inputPin = graphNode.InputPins[i]; if (inputPin.SourceNode == null) { continue; } CScriptNodeViewmodel inputSourceVm = nodeToViewModel[inputPin.SourceNode]; if (inputSourceVm.OutputPins.Count > inputPin.SourceParameterIndex) { COutputPinViewModel sourcePinVM = inputSourceVm.OutputPins[inputPin.SourceParameterIndex]; if (inputPin.Type.IsAssignableFrom(sourcePinVM.ValueType)) { CNodeConnectionViewModel newConnection = new CNodeConnectionViewModel(sourcePinVM, sourceViewModel.InputPins[i], this); newConnection.Connect(); } else { inputPin.SourceNode = null; inputPin.SourceParameterIndex = -1; LogUtility.Log("[ScriptLoadWarning] Node {0} tried to connect to {1} at output pin index {2} but the pin types are not compatible, connection removed", sourceViewModel.Name, inputSourceVm.Name, inputPin.SourceParameterIndex); } } else { inputPin.SourceNode = null; inputPin.SourceParameterIndex = -1; LogUtility.Log("[ScriptLoadError] node {0} tried to connect to {1} at output pin index {2} but there are not enough pins", sourceViewModel.Name, inputSourceVm.Name, inputPin.SourceParameterIndex); } } } }
public CExecutionPinViewModel(CExecutionPin executionPin, CScriptNodeViewmodel nodeViewModel, int pinIndex, bool isIn) : base(nodeViewModel, pinIndex) { m_pin = executionPin; Name = executionPin.Name; Tooltip = "Execution Path"; m_pinColor = PinColorHelpers.GetExecutionPinColor(); IsIn = isIn; }
public CInputPinViewModel(CInputPin inputPin, CScriptNodeViewmodel nodeViewModel, int pinIndex) : base(nodeViewModel, pinIndex) { m_pin = inputPin; Name = inputPin.Name; Tooltip = EditorKlaxScriptUtility.GetTypeName(inputPin.Type); m_pinColor = PinColorHelpers.GetColorForType(inputPin.Type); m_nodeViewmodel = nodeViewModel; m_literal = inputPin.Literal; m_valueType = inputPin.Type; m_bIsLiteralOnly = inputPin.bIsLiteralOnly; }
internal void NodeClicked(CScriptNodeViewmodel clickedNode) { AddNodeViewModel.IsOpen = false; m_clickedNode = clickedNode; var cursorPoint = System.Windows.Forms.Cursor.Position; m_mouseStartPoint = new Point(cursorPoint.X, cursorPoint.Y); MouseHook.OnMouseMove += OnMouseMoveNode; MouseHook.OnMouseUp += OnMouseUpNode; }
private void DeleteNode(CScriptNodeViewmodel nodeToDelete, bool bRecordUndo = true) { if (!nodeToDelete.ScriptNode.AllowDelete) { return; } List <CNodeConnectionViewModel> deletedConnections = new List <CNodeConnectionViewModel>(); nodeToDelete.GetConnections(deletedConnections); void Redo() { foreach (var connection in deletedConnections) { connection.Disconnect(); } ScriptGraph.m_nodes.Remove(nodeToDelete.ScriptNode); Nodes.Remove(nodeToDelete); DeselectAll(); } void Undo() { ScriptGraph.m_nodes.Add(nodeToDelete.ScriptNode); Nodes.Add(nodeToDelete); foreach (var connection in deletedConnections) { connection.Connect(); } } Redo(); if (bRecordUndo) { UndoRedoUtility.Record(new CRelayUndoItem(Undo, Redo)); } }
private void OnNodeAddNodePopupSelected(CNodeEntryViewModel addNodeEntry) { CNode scriptNode = addNodeEntry.NodeFactory.CreateNode(); scriptNode.NodePosX = m_addNodePoint.X; scriptNode.NodePosY = m_addNodePoint.Y; CScriptNodeViewmodel newNode = AddNode(scriptNode); if (m_addNodeContextPin != null) { CPinViewModel possibleTarget = newNode.GetPossibleTargetPin(m_addNodeContextPin); if (possibleTarget != null) { ConnectPins(m_addNodeContextPin, possibleTarget); } } m_addNodeContextPin = null; AddNodeViewModel.IsOpen = false; }
public CScriptNodeViewmodel AddNode(CNode node, bool bRecordUndo = true) { CScriptNodeViewmodel nodeViewModel = new CScriptNodeViewmodel(node, this); void Redo() { Nodes.Add(nodeViewModel); ScriptGraph.m_nodes.Add(nodeViewModel.ScriptNode); } void Undo() { DeleteNode(nodeViewModel, false); } Redo(); if (bRecordUndo) { UndoRedoUtility.Record(new CRelayUndoItem(Undo, Redo)); } return(nodeViewModel); }
protected CPinViewModel(CScriptNodeViewmodel nodeViewModel, int pinIndex) { NodeViewModel = nodeViewModel; MouseDownCommand = new CRelayCommand(OnMouseDown); PinIndex = pinIndex; }
public CSwitchExecutionPinViewModel(CExecutionPin executionPin, CScriptNodeViewmodel nodeViewModel, int pinIndex, bool isIn, Type controlType, object controlValue) : base(executionPin, nodeViewModel, pinIndex, isIn) { m_controlType = controlType; m_controlValue = controlValue; }
public COutputPinViewModel(COutputPin outputPin, CScriptNodeViewmodel nodeViewModel, int pinIndex) : base(nodeViewModel, pinIndex) { m_pin = outputPin; Name = outputPin.Name; ValueType = outputPin.Type; }
private void AddNodesToGraph(IList <CNode> nodes, Point referencePoint, bool bSelectNewNodes, bool bRecordUndo = true) { Dictionary <CNode, CScriptNodeViewmodel> nodeToViewModel = new Dictionary <CNode, CScriptNodeViewmodel>(); List <CScriptNodeViewmodel> addedNodes = new List <CScriptNodeViewmodel>(nodes.Count()); Point nodesMin = new Point(double.MaxValue, double.MaxValue); Point nodesMax = new Point(double.MinValue, double.MinValue); foreach (CNode scriptNode in nodes) { CScriptNodeViewmodel viewmodel = AddNode(scriptNode, false); nodeToViewModel.Add(scriptNode, viewmodel); addedNodes.Add(viewmodel); if (viewmodel.PosX < nodesMin.X) { nodesMin.X = viewmodel.PosX; } if (viewmodel.PosY < nodesMin.Y) { nodesMin.Y = viewmodel.PosY; } if (viewmodel.PosX > nodesMax.X) { nodesMax.X = viewmodel.PosX; } if (viewmodel.PosY > nodesMax.Y) { nodesMax.Y = viewmodel.PosY; } } Point nodesMid = new Point((nodesMin.X + nodesMax.X) / 2, (nodesMin.Y + nodesMax.Y) / 2); foreach (CScriptNodeViewmodel nodeViewmodel in addedNodes) { Vector toMid = new Point(nodeViewmodel.PosX, nodeViewmodel.PosY) - nodesMid; Point newPos = referencePoint + toMid; nodeViewmodel.PosX = newPos.X; nodeViewmodel.PosY = newPos.Y; } if (bSelectNewNodes) { SelectNodes(addedNodes); } ResolveScriptNodeConnections(nodes, nodeToViewModel); if (bRecordUndo) { void Redo() { foreach (CScriptNodeViewmodel nodeViewmodel in addedNodes) { Nodes.Add(nodeViewmodel); ScriptGraph.m_nodes.Add(nodeViewmodel.ScriptNode); Vector toMid = new Point(nodeViewmodel.PosX, nodeViewmodel.PosY) - nodesMid; Point newPos = referencePoint + toMid; nodeViewmodel.PosX = newPos.X; nodeViewmodel.PosY = newPos.Y; if (bSelectNewNodes) { SelectNodes(addedNodes); } ResolveScriptNodeConnections(nodes, nodeToViewModel); } } void Undo() { DeleteSelectedNodes(addedNodes, false); } UndoRedoUtility.Record(new CRelayUndoItem(Undo, Redo)); } }