private void ProcessContextMenu(Vector2 mousePosition) { GenericMenu genericMenu = new GenericMenu(); genericMenu.AddItem(new GUIContent("Add Node"), false, () => NodeManager.AddNodeAt(mousePosition, NodeType.Nothing)); genericMenu.ShowAsContext(); }
private void ProcessEvents(Event e) { drag = Vector2.zero; switch (e.type) { // check for selection or context menu case EventType.MouseDown: if (e.button == 0 && ClickManager.IsDoubleClick((float)EditorApplication.timeSinceStartup, e.mousePosition, SDEComponentType.Nothing)) { Vector2 creationOffset = CreationOffset(e.mousePosition); NodeManager.AddNodeAt(e.mousePosition - creationOffset, NodeType.Nothing); } if (e.button == 1 && SelectionManager.SelectedComponentType() == SDEComponentType.Nothing) { ProcessContextMenu(e.mousePosition); } break; // check for window dragging case EventType.MouseDrag: if (e.button == 0) { OnDrag(e.delta); } break; // listen for key commands case EventType.KeyDown: // NOTE: Unity editor is broken, so both a tab KeyCode AND a '\t' character // gets parsed on key press. The '\t' character is what the editor uses // internally for it's default tab cycling (which we want to override). if (e.character == '\t') { e.Use(); } //eat the input if (SelectionManager.SelectedComponentType() != SDEComponentType.TextArea) { if (ProcessKeyboardInput(e.keyCode)) { e.Use(); } } break; } }
/* * ConnectInterruptNode() creates/splices an Interrupt node to the DialogBox's * output ConnectionPoint. */ private Node ConnectInterruptNode() { // if no Interrupt Node is connected, check if there's a connection to // splice one between ConnectionPoint destinationPoint = null; List <Connection> connections = outPoint.connections; // TODO: only one connection can be paired with an output, when that is // refactored, fix this! if (connections.Count > 0) { destinationPoint = connections[0].inPoint; } // create a new Interrupt Node and connect them Vector2 nodeRect = new Vector2(Mathf.RoundToInt(rect.x + (rect.width * 1.2f)), rect.y + 5f); Vector2 creationOffset = NodeManager.mainEditor.CreationOffset(nodeRect); Node interruptNode = NodeManager.AddNodeAt(nodeRect - creationOffset, NodeType.Interrupt, markHistory: false); ConnectionManager.selectedInPoint = interruptNode.inPoint; ConnectionManager.selectedOutPoint = outPoint; ConnectionManager.CreateConnection(false, markHistory: false); // do the splicing if (destinationPoint != null) { ConnectionManager.RemoveConnection(connections[0]); ConnectionManager.selectedInPoint = destinationPoint; ConnectionManager.selectedOutPoint = interruptNode.outPoint; ConnectionManager.CreateConnection(true, markHistory: false); } ConnectionManager.ClearConnectionSelection(); return(interruptNode); }
/* * InitializeNodes() is a helper function for loading Story Dialog Editor data. * * Returns the mapping of input connection points and their associated output connection points */ private static Dictionary <int, List <int> > InitializeNodes(EditorStoryNodeEntry storyEntry, Dictionary <int, ConnectionPoint> connectionPointMap) { // the map of input points and their associated output points Dictionary <int, List <int> > connectionMap = new Dictionary <int, List <int> >(); // generate nodes and data from entries Node tempNode; foreach (EditorNodeEntry entry in storyEntry.nodes) { tempNode = NodeManager.AddNodeAt(new Vector2(entry.rect.x, entry.rect.y), entry.nodeType, markHistory: false, center: false); connectionPointMap[entry.inPoint.CPEID] = tempNode.inPoint; connectionMap[entry.inPoint.CPEID] = entry.inPoint.linkedCPEIDs; // add flag data if set local/global if (entry.nodeType == NodeType.SetLocalFlag || entry.nodeType == NodeType.CheckLocalFlag) { tempNode.localFlagDropdown.selectedItem = mainEditor.localFlagsMenu.GetTextArea(entry.selectedFlag); } else if (entry.nodeType == NodeType.SetGlobalFlag || entry.nodeType == NodeType.CheckGlobalFlag) { tempNode.globalItemDropdown.selectedItem = entry.selectedFlag; } else if (entry.nodeType == NodeType.SetGlobalVariable || entry.nodeType == NodeType.CheckGlobalVariable) { tempNode.globalItemDropdown.selectedItem = entry.selectedFlag; tempNode.globalVariableField.text = entry.globalVariableValue; } // map Node outpoint/splitter depending on NodeType if (entry.nodeType == NodeType.SetLocalFlag || entry.nodeType == NodeType.SetGlobalFlag || entry.nodeType == NodeType.SetGlobalVariable || entry.nodeType == NodeType.Interrupt) { // add outpoint entry if available if (tempNode.outPoint != null && entry.outPoint != null) { connectionPointMap[entry.outPoint.CPEID] = tempNode.outPoint; } } else if (entry.nodeType == NodeType.CheckLocalFlag || entry.nodeType == NodeType.CheckGlobalFlag || entry.nodeType == NodeType.CheckGlobalVariable) { // add splitter entries if available if (tempNode.splitter != null && entry.outPos != null && entry.outNeg != null) { connectionPointMap[entry.outPos.CPEID] = tempNode.splitter.positiveOutpoint; connectionPointMap[entry.outNeg.CPEID] = tempNode.splitter.negativeOutpoint; } } // record child container outpoints depending on NodeType and populate fields if (entry.nodeType == NodeType.Dialog || entry.nodeType == NodeType.Decision) { DBox child = tempNode.childContainer as DBox; SDEContainerEntry childEntry = entry.childContainer; while (childEntry != null) { // set text and outpoint mapping for the child container child.textArea.text = childEntry.text; connectionPointMap[childEntry.outPoint.CPEID] = child.outPoint; childEntry = childEntry.child; // generate the child's child if there needs to be one if (childEntry != null) { switch (entry.nodeType) { case NodeType.Dialog: child.child = ScriptableObject.CreateInstance <DialogBox>(); ((DialogBox)child.child).Init(child, ""); break; case NodeType.Decision: child.child = ScriptableObject.CreateInstance <DecisionBox>(); ((DecisionBox)child.child).Init(child, ""); break; } } child = child.child as DBox; } } else if (entry.nodeType == NodeType.Interrupt) { tempNode.SetBottomLevelInterrupt(entry.bottomLevel); DialogInterrupt child; SDEContainerEntry childEntry = entry.childContainer; if (childEntry != null) { // create the first child of the parent node tempNode.childContainer = ScriptableObject.CreateInstance <DialogInterrupt>(); tempNode.childContainer.Init(tempNode); ((DialogInterrupt)tempNode.childContainer).label.text = childEntry.text; // record the connection point connectionPointMap[childEntry.outPoint.CPEID] = tempNode.childContainer.outPoint; child = tempNode.childContainer as DialogInterrupt; childEntry = childEntry.child; while (childEntry != null) { // generate the child interrupt and populate it child.child = ScriptableObject.CreateInstance <DialogInterrupt>(); ((DialogInterrupt)child.child).Init(child); ((DialogInterrupt)child.child).label.text = childEntry.text; // record the connection point connectionPointMap[childEntry.outPoint.CPEID] = child.child.outPoint; child = child.child as DialogInterrupt; childEntry = childEntry.child; } } } } return(connectionMap); }