private void UpdateSelectEvent(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorStyles constellationEditorStyles) { var sizeX = Event.current.mousePosition.x - mouseClickStartPosition.x; var sizeY = Event.current.mousePosition.y - mouseClickStartPosition.y; var SelectionSize = FixNegativeSize(new Rect(mouseClickStartPosition.x, mouseClickStartPosition.y, sizeX, sizeY)); GUI.Box(SelectionSize, "", constellationEditorStyles.SelectionAreaStyle); if (Event.current.type == EventType.MouseUp) { if (!Event.current.control) { ClearSelectedNodes(); } foreach (var node in Nodes) { if (SelectionSize.Contains(new Vector2(node.GetPositionX() + (node.GetSizeX() * 0.5f), node.GetPositionY() + (node.GetSizeY() * 0.5f)))) { node.SelectedNode(); SelectedNodes.Add(node); } } } requestRepaint(); }
private void UpdateDragEvents(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorEvents.EditorEvents editorEvents, Event e) { editorEvents(ConstellationEditorEvents.EditorEventType.NodeMoved, ""); for (var i = 0; i < SelectedNodes.Count; i++) { SelectedNodes[i].SetPosition((e.mousePosition.x - mouseClickStartPosition.x) + SelectedNodes[i].GetPreviousNodePositionX(), (e.mousePosition.y - mouseClickStartPosition.y) + SelectedNodes[i].GetPreviousNodePositionY()); } requestRepaint(); }
private void UpdateResizeEvents(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorEvents.EditorEvents editorEvents, Event e) { editorEvents(ConstellationEditorEvents.EditorEventType.NodeResized, ""); for (var i = 0; i < SelectedNodes.Count; i++) { SelectedNodes[i].UpdateNodeSize((e.mousePosition.x - mouseClickStartPosition.x) + SelectedNodes[i].GetPreviousNodeSizeX(), (e.mousePosition.y - mouseClickStartPosition.y) + SelectedNodes[i].GetPreviousNodeSizeY(), EditorData.GetConstellationEditorConfig()); } requestRepaint(); }
private void DrawIncompleteLink(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorStyles styles) { if (selectedInput != null || selectedOutput != null) { var e = Event.current; if (selectedInput != null) { DrawNodeCurve(new Rect(e.mousePosition.x, e.mousePosition.y, 0, 0), InputPosition(selectedInput, styles)); requestRepaint(); } else if (selectedOutput != null) { DrawNodeCurve(OutputPosition(selectedOutput, styles), new Rect(e.mousePosition.x, e.mousePosition.y, 0, 0)); requestRepaint(); } if (e.button == 1) { selectedInput = null; selectedOutput = null; } } }
public void DrawLinks(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorEvents.EditorEvents editorEvents, ConstellationEditorStyles styles) { DrawIncompleteLink(requestRepaint, styles); foreach (LinkData link in constellationScript.GetLinks()) { Rect startLink = Rect.zero; Rect endLink = Rect.zero; foreach (NodeData node in constellationScript.GetNodes()) { var i = 0; foreach (InputData input in node.GetInputs()) { if (link.Input.Guid == input.Guid) { endLink = InputPosition(input, styles); break; } i++; } var j = 0; foreach (OutputData output in node.GetOutputs()) { if (link.Output.Guid == output.Guid) { var width = node.SizeX; startLink = OutputPosition(output, styles); break; } j++; } } if (startLink == Rect.zero || endLink == Rect.zero) { editorEvents(ConstellationEditorEvents.EditorEventType.AddToUndo, "Delete Link"); editorEvents(ConstellationEditorEvents.EditorEventType.LinkDeleted, link.GUID); constellationScript.RemoveLink(link); } DrawNodeCurve(startLink, endLink, GetConnectionColor(link.Input.IsBright, link.Output.Type, styles)); if (MouseOverCurve(startLink.position, endLink.position)) { var linkCenter = new Rect((startLink.x + (endLink.x - startLink.x) / 2) - (deleteButtonSize * 0.5f), (startLink.y + (endLink.y - startLink.y) / 2) - (deleteButtonSize * 0.5f), deleteButtonSize, deleteButtonSize); var deleteButtonStyle = styles.GenericDeleteStyle; if (GUI.Button(linkCenter, "", deleteButtonStyle)) { dragging = true; if (linkCenter.Contains(Event.current.mousePosition)) { editorEvents(ConstellationEditorEvents.EditorEventType.LinkDeleted, link.GUID); constellationScript.RemoveLink(link); } } } } requestRepaint(); }
private void UpdateGenericEvents(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorEvents.EditorEvents editorEvents, Event e) { if (e.type == EventType.Repaint) { mousePosition = e.mousePosition; } if (Event.current.keyCode == KeyCode.Delete) { for (var i = 0; i < SelectedNodes.Count; i++) { RemoveNode(SelectedNodes[SelectedNodes.Count - 1].NodeData, editorEvents); } } for (var i = 0; i < Nodes.Count; i++) { var nodeRect = Nodes[i].GetNodeRect(out float positionOffsetX, out float positionOffsetY); var deleteRect = Nodes[i].GetDeleteRect(EditorData.GetConstellationEditorConfig()); var questionRect = Nodes[i].GetQuestionRect(EditorData.GetConstellationEditorConfig()); var resizeRect = Nodes[i].GetResizeRect(EditorData.GetConstellationEditorConfig()); if (nodeRect.Contains(mousePosition)) { if (mousePressed) { requestRepaint(); if (e.control || SelectedNodes.Count == 0) { SelectedNodes.Add(Nodes[i]); Nodes[i].SelectedNode(); } else if (SelectedNodes.Count <= 1) { foreach (var selectedNodes in SelectedNodes) { selectedNodes.UnselectNode(); } SelectedNodes.Clear(); SelectedNodes.Add(Nodes[i]); Nodes[i].SelectedNode(); } for (var j = 0; j < Nodes[i].GetInputs().Length; j++) { var inputRect = Nodes[i].GetInputRect(j, EditorData.GetConstellationEditorConfig()); if (inputRect.Contains(mousePosition)) { Links.AddLinkFromInput(Nodes[i].GetInputs()[j], (ConstellationEditorEvents.EditorEventType editorEventType, string message) => { editorEvents(editorEventType, message); if (editorEventType == ConstellationEditorEvents.EditorEventType.LinkAdded) { UpdateGenericNodeByLinkGUID(message); } }); } } for (var j = 0; j < Nodes[i].GetOutputs().Length; j++) { var outputRect = Nodes[i].GetOuptputRect(j, EditorData.GetConstellationEditorConfig()); if (outputRect.Contains(mousePosition)) { Links.AddLinkFromOutput(Nodes[i].GetOutputs()[j], (ConstellationEditorEvents.EditorEventType editorEventType, string message) => { editorEvents(editorEventType, message); if (editorEventType == ConstellationEditorEvents.EditorEventType.LinkAdded) { UpdateGenericNodeByLinkGUID(message); } }); } } if (deleteRect.Contains(mousePosition) && mouseButtonDown) { RemoveNode(Nodes[i].NodeData, editorEvents); return; } if (questionRect.Contains(mousePosition) && mouseButtonDown) { editorEvents(ConstellationEditorEvents.EditorEventType.HelpClicked, Nodes[i].GetName()); return; } for (var j = 0; j < Nodes[i].GetAttributeDatas().Length; j++) { var attributeRect = Nodes[i].GetParameterRect(j, EditorData.GetConstellationEditorConfig()); if (attributeRect.Contains(mousePosition)) { editorEvents(ConstellationEditorEvents.EditorEventType.AddToUndo, "Attribute edited"); currentEventScope = EventsScope.EditingAttributes; return; } } if (mouseButtonDown) { if (resizeRect.Contains(mousePosition)) { currentEventScope = EventsScope.Resizing; return; } editorEvents(ConstellationEditorEvents.EditorEventType.AddToUndo, "Node moved"); SetNodeToFirst(Nodes[i]); currentEventScope = EventsScope.Dragging; return; } } } else if (mousePressed && e.mousePosition.x != mouseClickStartPosition.x && e.mousePosition.y != mouseClickStartPosition.y) { currentEventScope = EventsScope.Selecting; } } if (e.MouseUp() && e.button != 2) { foreach (var node in SelectedNodes) { node.UnselectNode(); } SelectedNodes.Clear(); } }
public void Draw(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorEvents.EditorEvents callback, ConstellationEditorStyles constellationEditorStyles, out Vector2 windowSize, out Vector2 scrollPosition) { mouseButtonDown = false; //scroll bar ScrollPosition = EditorGUILayout.BeginScrollView(ScrollPosition, GUILayout.Width(windowSizeX), GUILayout.Height(windowSizeY)); GUILayoutOption[] options = { GUILayout.Width(editorScrollSize.x), GUILayout.Height(editorScrollSize.y) }; editorScrollSize = new Vector2(farNodeX + 400, farNodeY + 400); windowSize = editorScrollSize; scrollPosition = ScrollPosition; EditorGUILayout.LabelField("", options); var backgroundTint = Color.white; if (ConstellationScript.IsInstance && ConstellationScript.IsDifferentThanSource) { backgroundTint = Color.yellow; } background.DrawBackgroundGrid(windowSizeX, windowSizeY, ScrollPosition.x, ScrollPosition.y, backgroundTint); Event e = Event.current; var mouseJustRelease = false; if (e.type == EventType.MouseUp && Event.current.button == 0 && mousePressed == true) { mouseJustRelease = true; mousePressed = false; } else if (e.type == EventType.MouseDown && Event.current.button == 0) { mouseClickStartPosition = e.mousePosition; mousePressed = true; mouseButtonDown = true; } switch (currentEventScope) { case EventsScope.Generic: UpdateGenericEvents(requestRepaint, callback, e); break; case EventsScope.Resizing: UpdateResizeEvents(requestRepaint, callback, e); break; case EventsScope.Dragging: UpdateDragEvents(requestRepaint, callback, e); break; case EventsScope.EditingAttributes: break; case EventsScope.Selecting: UpdateSelectEvent(requestRepaint, constellationEditorStyles); break; } //Needs to be called after the event scope otherwise quit button event is overriden by the node drag event if (mouseJustRelease) { currentEventScope = EventsScope.Generic; for (var i = 0; i < Nodes.Count; i++) { Nodes[i].LockNodeSize(); Nodes[i].LockNodePosition(); } } DrawNodes(e); Links.DrawLinks(requestRepaint, callback, constellationEditorStyles); DrawDescriptions(e); EditorGUILayout.EndScrollView(); if (Event.current.button == 2) { ScrollPosition -= Event.current.delta * 0.5f; requestRepaint(); } var script = ConstellationScript.script; if (script.Nodes != null) { script.Nodes = script.Nodes.OrderBy(x => x.YPosition).ToList(); } if (script.Links != null) { script.Links = script.Links.OrderBy(x => x.outputPositionY).ToList(); } }
private void UpdateGenericEvents(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorEvents.EditorEvents editorEvents, Event e) { for (var i = 0; i < Nodes.Count; i++) { var nodeRect = Nodes[i].GetNodeRect(out float positionOffsetX, out float positionOffsetY); var deleteRect = Nodes[i].GetDeleteRect(); var questionRect = Nodes[i].GetQuestionRect(); var resizeRect = Nodes[i].GetResizeRect(); if (nodeRect.Contains(e.mousePosition)) { if (mousePressed) { requestRepaint(); if (e.control) { SelectedNodes.Add(Nodes[i]); SetNodeToFirst(Nodes[i]); } else { SelectedNodes.Clear(); SelectedNodes.Add(Nodes[i]); } for (var j = 0; j < Nodes[i].GetInputs().Length; j++) { var inputRect = Nodes[i].GetInputRect(j); if (inputRect.Contains(e.mousePosition)) { Links.AddLinkFromInput(Nodes[i].GetInputs()[j], editorEvents); } } for (var j = 0; j < Nodes[i].GetOutputs().Length; j++) { var outputRect = Nodes[i].GetOuptputRect(j); if (outputRect.Contains(e.mousePosition)) { Links.AddLinkFromOutput(Nodes[i].GetOutputs()[j], editorEvents); } } if (deleteRect.Contains(e.mousePosition) && mouseButtonDown) { RemoveNode(Nodes[i].NodeData, editorEvents); return; } if (questionRect.Contains(e.mousePosition) && mouseButtonDown) { editorEvents(ConstellationEditorEvents.EditorEventType.HelpClicked, Nodes[i].GetName()); return; } for (var j = 0; j < Nodes[i].GetAttributeDatas().Length; j++) { var attributeRect = Nodes[i].GetAttributeRect(j); if (attributeRect.Contains(e.mousePosition)) { currentEventScope = EventsScope.EditingAttributes; return; } } if (mouseButtonDown) { if (resizeRect.Contains(e.mousePosition)) { currentEventScope = EventsScope.Resizing; return; } SetNodeToFirst(Nodes[i]); currentEventScope = EventsScope.Dragging; return; } } } } if (mousePressed) { SelectedNodes.Clear(); } }