Ejemplo n.º 1
0
 void ChangeConversation(Conversation newConversation)
 {
     selectedConnector = null;
     selectedNode      = null;
     if (nodes != null)
     {
         nodes.Clear();
     }
     else
     {
         nodes = new List <EditorNode>();
     }
     if (newConversation != null)
     {
         conversation           = newConversation;
         serializedConversation = new SerializedObject(conversation);
         foreach (DialogueEntry entry in conversation.Entries)
         {
             AddNode(entry);
         }
         foreach (DialogueEntry entry in conversation.Entries)
         {
             SetupNodeConnections(entry);
         }
     }
 }
Ejemplo n.º 2
0
        DialogueEntryEditorNode AddNode(DialogueEntry entry)
        {
            DialogueEntryEditorNode node = new DialogueEntryEditorNode(entry.position, NODE_WIDTH, NODE_HEIGHT, dialogueNodeStyle, dialogueSelectedNodeStyle);
            Response        response;
            EditorConnector connector;

            node.conversation = conversation;
            node.entryID      = entry.ID;
            node.entry        = entry;
            SetupNodeActions(node);
            nodes.Add(node);

            // Setup response nodes for node
            for (int i = 0; i < entry.Responses.Count; ++i)
            {
                response = entry.Responses[i];
                ResponseEditorNode responseNode = new ResponseEditorNode(response.Position, NODE_WIDTH, NODE_HEIGHT, responseNodeStyle, responseSelectedNodeStyle);
                responseNode.conversation = conversation;
                responseNode.entryID      = entry.ID;
                responseNode.index        = i;
                responseNode.response     = response;
                SetupNodeActions(responseNode);
                nodes.Add(responseNode);
                connector        = new EditorConnector();
                connector.Parent = node;
                connector.Target = responseNode;
                node.Connections.Add(connector);
            }
            return(node);
        }
Ejemplo n.º 3
0
 void OnCancelMakeTransition()
 {
     if (selectedConnector != null)
     {
         selectedConnector = null;
     }
 }
 protected override void OnClickAsTarget(DialogueEditorWindow window, EditorConnector connector)
 {
     // DialogueEntry can be connected to, so ask connector's parent to try it and if so make connection
     if (connector.Parent.ConnectObjectToDialogueEntry(window, entryID))
     {
         connector.Parent.Connections.Add(connector);
         connector.Target = this;
     }
 }
 protected void OnClickNewTransition()
 {
     if (OnStartMakeTransition != null)
     {
         EditorConnector newConnection = new EditorConnector();
         newConnection.Parent = this;
         OnStartMakeTransition(newConnection);
     }
 }
Ejemplo n.º 6
0
        DialogueEntryEditorNode SetupNodeConnections(DialogueEntry entry)
        {
            // Find corresponding node
            DialogueEntryEditorNode startNode = FindDialogueNode(entry.ID);

            if (startNode != null)
            {
                foreach (TransitionOption o in entry.transitions.transitions)
                {
                    DialogueEntryEditorNode endNode = FindDialogueNode(o.transition.TargetID);
                    if (endNode != null)
                    {
                        EditorConnector connector = new EditorConnector();
                        connector.Parent = startNode;
                        connector.Target = endNode;
                        startNode.Connections.Add(connector);
                    }
                }

                for (int i = 0; i < entry.Responses.Count; ++i)
                {
                    Response           response     = entry.Responses[i];
                    ResponseEditorNode responseNode = FindResponseNode(entry.ID, i);
                    foreach (TransitionOption o in response.transitions.transitions)
                    {
                        DialogueEntryEditorNode endNode = FindDialogueNode(o.transition.TargetID);
                        if (endNode != null)
                        {
                            EditorConnector connector = new EditorConnector();
                            connector.Parent = responseNode;
                            connector.Target = endNode;
                            responseNode.Connections.Add(connector);
                        }
                    }
                }
            }
            return(startNode);
        }
 protected abstract void OnClickAsTarget(DialogueEditorWindow window, EditorConnector connector);
Ejemplo n.º 8
0
        void UpdateNodes()
        {
            HashSet <int>     seenIDs   = new HashSet <int>();
            List <EditorNode> toRemove  = new List <EditorNode>();
            List <EditorNode> nodeToAdd = new List <EditorNode>();

            foreach (EditorNode node in nodes)
            {
                DialogueEntryEditorNode dialogueNode = node as DialogueEntryEditorNode;
                ResponseEditorNode      responseNode = node as ResponseEditorNode;
                if (dialogueNode != null)
                {
                    // Check if node is removed from conversation
                    seenIDs.Add(dialogueNode.entryID);
                    DialogueEntry entry = conversation.FindEntry(dialogueNode.entryID);
                    if (entry == null)
                    {
                        toRemove.Add(node);
                        // Remove any responses from destroyed node
                        foreach (EditorConnector connection in dialogueNode.Connections)
                        {
                            if (connection.Target as ResponseEditorNode != null)
                            {
                                toRemove.Add(connection.Target);
                            }
                        }
                    }
                    else
                    {
                        // Check responses on node
                        dialogueNode.entry = entry;
                        int maxIndexSeen = -1;
                        foreach (EditorConnector connection in dialogueNode.Connections)
                        {
                            //check if there's responses to remove
                            ResponseEditorNode childNode = connection.Target as ResponseEditorNode;
                            if (childNode != null)
                            {
                                if (childNode.index < entry.Responses.Count)
                                {
                                    maxIndexSeen       = Mathf.Max(maxIndexSeen, childNode.index);
                                    childNode.response = entry.Responses[childNode.index];
                                }
                                else
                                {
                                    // Node has out of range index
                                    toRemove.Add(childNode);
                                }
                            }
                        }
                        // Add any needed responses
                        for (int i = maxIndexSeen + 1; i < entry.Responses.Count(); ++i)
                        {
                            Response           response = entry.Responses[i];
                            ResponseEditorNode newNode  = new ResponseEditorNode(response.Position, NODE_WIDTH, NODE_HEIGHT, responseNodeStyle, responseSelectedNodeStyle);
                            newNode.response = response;
                            newNode.entryID  = entry.ID;
                            newNode.index    = i;
                            SetupNodeActions(newNode);
                            EditorConnector connector = new EditorConnector();
                            connector.Parent = dialogueNode;
                            connector.Target = newNode;
                            dialogueNode.Connections.Add(connector);
                            nodeToAdd.Add(newNode);
                        }
                    }
                }
            }
            // Remove nodes and any connections to them
            nodes.RemoveAll(n => toRemove.Contains(n));
            if (selectedConnector != null && toRemove.Contains(selectedConnector.Parent))
            {
                selectedConnector = null;
            }
            if (toRemove.Contains(selectedNode))
            {
                selectedNode = null;
            }
            foreach (EditorNode node in nodes)
            {
                node.Connections.RemoveAll(c => toRemove.Contains(c.Target));
            }
            // Create new nodes for any dialogue entries not already seen
            List <DialogueEntry> toAdd = conversation.Entries.Where(e => !seenIDs.Contains(e.ID)).ToList();

            foreach (DialogueEntry entry in toAdd)
            {
                AddNode(entry);
            }
            // Add new response nodes to list
            nodes.AddRange(nodeToAdd);
            // Now all nodes exist (or don't) check all transitions
            foreach (EditorNode node in nodes)
            {
                DialogueEntryEditorNode dialogueNode = node as DialogueEntryEditorNode;
                ResponseEditorNode      responseNode = node as ResponseEditorNode;
                List <int>             targetsRequired;
                List <EditorConnector> connectorToRemove = new List <EditorConnector>();
                if (dialogueNode != null)
                {
                    targetsRequired = dialogueNode.entry.transitions.transitions.Select(o => o.transition.TargetID).ToList();
                }
                else if (responseNode != null)
                {
                    targetsRequired = responseNode.response.transitions.transitions.Select(o => o.transition.TargetID).ToList();
                }
                else
                {
                    targetsRequired = new List <int>();
                }


                foreach (EditorConnector connection in node.Connections)
                {
                    DialogueEntryEditorNode targetDialogue = connection.Target as DialogueEntryEditorNode;
                    if (targetDialogue != null)
                    {
                        if (targetsRequired.Contains(targetDialogue.entryID))
                        {
                            targetsRequired.Remove(targetDialogue.entryID);
                        }
                        else
                        {
                            connectorToRemove.Add(connection);
                        }
                    }
                }
                node.Connections.RemoveAll(c => connectorToRemove.Contains(c));
                // Create required connections
                foreach (int targetID in targetsRequired)
                {
                    DialogueEntryEditorNode targetNode = FindDialogueNode(targetID);
                    if (targetNode != null)
                    {
                        EditorConnector newConnector = new EditorConnector();
                        newConnector.Parent = node;
                        newConnector.Target = targetNode;
                        node.Connections.Add(newConnector);
                    }
                }
            }
        }
Ejemplo n.º 9
0
 public void OnFinishMakeTransition()
 {
     selectedConnector = null;
 }
Ejemplo n.º 10
0
 void OnStartMakeTransition(EditorConnector connector)
 {
     selectedConnector = connector;
 }
Ejemplo n.º 11
0
 protected override void OnClickAsTarget(DialogueEditorWindow window, EditorConnector connector)
 {
     // Response can't be made a target as it belongs to its dialogue entry
 }