コード例 #1
0
            public LinkConversationNodeTool(ConversationDataControl conversation, ConversationNodeDataControl father, int nodeType, int index)
            {
                this.father = father;
                ConversationNode childNode = null;

                if (nodeType == DIALOG_NODE)
                {
                    childNode = new DialogueConversationNode();
                }
                else if (nodeType == OPTION_NODE)
                {
                    childNode = new OptionConversationNode();
                }
                else
                {
                    throw new Exception("Not valid node type!");
                }
                var parentRect = this.father.getEditorRect();

                childNode.setEditorX(parentRect.x + parentRect.width + 35);
                childNode.setEditorY(parentRect.y);

                child = this.father.conversation.getNodeDataControl(childNode);

                this.father     = father;
                this.controller = Controller.Instance;
                this.index      = index;
            }
コード例 #2
0
            public InsertNodeTool(ConversationDataControl content, ConversationNodeDataControl parent, int nodeType, int index)
            {
                this.content    = content;
                this.isRootNode = parent == null;
                this.parent     = isRootNode ? content.getRootNode() : parent;
                ConversationNode node = null;

                switch (nodeType)
                {
                case DIALOG_NODE: node = new DialogueConversationNode(); break;

                case OPTION_NODE: node = new OptionConversationNode(); break;
                }


                this.index = index;
                var parentRect = isRootNode ? new RectInt(0, 25, 0, 0) : parent.getEditorRect();
                var childRect  = isRootNode ? content.getRootNode().getEditorRect() : parent.getChilds()[index].getEditorRect();

                var center = (parentRect.center + childRect.center) / 2f;

                node.setEditorX((int)(center.x - node.getEditorWidth() / 2f));
                node.setEditorY((int)(center.y - node.getEditorHeight() / 2f));

                this.newNode  = ConversationNodeDataControlFactory.Instance.CreateDataControlFor(content, node);
                this.subTools = CreateTools();
            }
コード例 #3
0
        /**
         * Returns if the given father has a direct line of dialogue nodes to get to
         * the child node.
         *
         * @param fatherView
         *            Father node
         * @param childView
         *            Child node
         * @return True if the father is related to child following only dialogue
         *         nodes, false otherwise
         */
        private bool isDirectFather(ConversationNodeDataControl fatherView, ConversationNodeDataControl childView)
        {
            bool isDirectFatherL = false;

            // Check if both nodes are dialogue nodes

            /*if (fatherView.getType() == ConversationNodeViewEnum.DIALOGUE && childView.getType() == ConversationNodeViewEnum.DIALOGUE)
             * {
             *
             *  // Check if the father is not a terminal node
             *  if (!fatherView.isTerminal())
             *  {
             *
             *      // If the only child of the father equals the child, there is a direct line
             *      if (fatherView.getChildView(0) == childView)
             *          isDirectFatherL = true;
             *
             *      // If not, keep searching with the only child of the father
             *      else
             *          isDirectFatherL = isDirectFather(fatherView.getChildView(0), childView);
             *  }
             * }*/

            return(isDirectFatherL);
        }
コード例 #4
0
            public AddRemoveConversationNodeTool(int nodeType, ConversationNodeDataControl parent, int index)
            {
                this.parent = parent;

                ConversationNode child = null;

                if (nodeType == DIALOG_NODE)
                {
                    child = new DialogueConversationNode();
                }
                else if (nodeType == OPTION_NODE)
                {
                    child = new OptionConversationNode();
                }

                if (child != null)
                {
                    var parentRect = parent.getEditorRect();
                    child.setEditorX(parentRect.x + parentRect.width + 35);
                    child.setEditorY(parentRect.y);

                    this.childDataControl = parent.conversation.getNodeDataControl(child);
                    this.index            = index; // Insert at last
                    this.add = true;
                }
            }
        protected override bool addChild(int index, ConversationNodeDataControl child, ref object data)
        {
            bool added = false;

            if (index == 0 && canLinkNode(child))
            {
                added = true;
                if (getChildCount() < 1)
                {
                    dialogConversationNode.addChild(child.getContent() as ConversationNode);
                }
                else
                {
                    var grandchild = conversationNode.getChild(0);
                    var newChild   = child.getContent() as ConversationNode;
                    dialogConversationNode.replaceChild(index, newChild);
                    if (newChild.getChildCount() > 0)
                    {
                        newChild.replaceChild(0, grandchild);
                    }
                    else
                    {
                        newChild.addChild(grandchild);
                        UnityEngine.Debug.Log("A child was added without checking consistence");
                    }
                }
            }
            return(added);
        }
コード例 #6
0
 public AddRemoveConversationNodeTool(ConversationNodeDataControl parent, ConversationNodeDataControl child, int index)
 {
     this.parent           = parent;
     this.childDataControl = child;
     this.index            = index;
     this.add = true;
 }
コード例 #7
0
 public ReplaceNodeTool(ConversationDataControl content, ConversationNodeDataControl oldNode, ConversationNodeDataControl newNode)
 {
     this.content  = content;
     this.oldNode  = oldNode;
     this.newNode  = newNode;
     this.subTools = CreateTools();
 }
コード例 #8
0
 public LinkConversationNodeTool(ConversationDataControl conversation, ConversationNodeDataControl father, ConversationNodeDataControl child, int index)
 {
     this.father     = father;
     this.child      = child;
     this.controller = Controller.Instance;
     this.index      = index;
 }
コード例 #9
0
 public DeleteNodeLinkTool(ConversationNodeDataControl parent, int index)
 {
     this.parent       = parent;
     this.linkIndex    = index;
     this.confirmTitle = TC.get("Conversation.OperationDeleteLink");
     this.confirmText  = TC.get("Conversation.ConfirmationDeleteLink");
     this.child        = parent.getChilds()[linkIndex];
 }
コード例 #10
0
 public virtual bool replaceNode(ConversationNodeDataControl oldNode, ConversationNodeDataControl newNode)
 {
     if (newNode != null && oldNode != null && oldNode != newNode)
     {
         return(controller.AddTool(new ReplaceNodeTool(this, oldNode, newNode)));
     }
     return(false);
 }
コード例 #11
0
            public AddRemoveLineTool(ConversationNodeDataControl node, string name, string text)
            {
                this.isAdd = true;
                this.node  = node;
                var newLine = new ConversationLine(name, text);

                newLine.addResources(new ResourcesUni());
                this.line = new ConversationLineDataControl(newLine);
            }
        protected override bool addChild(int index, ConversationNodeDataControl child, ref object data)
        {
            var line = data as ConversationLineDataControl;

            // If i receive a line its because I removed a line before, so I have to put the line making a new slot for the child
            if (line != null)
            {
                optionConversationNode.addLine(index, line.getContent() as ConversationLine);
                conversationLines.Insert(index, line);
                optionConversationNode.addChild(index, child.getContent() as ConversationNode);
            }
            // Otherwise push the current child to grandchild preserving the current line, except when adding in the end
            else
            {
                var timeout = data != null ? (float)data : 0f;
                if (timeout > 0)
                {
                    // Reinsert the timeout child
                    optionConversationNode.Timeout = timeout;
                    optionConversationNode.addChild(child.getContent() as ConversationNode);
                }
                else
                {
                    if (optionConversationNode.getChildCount() == index)
                    {
                        // We have to add brand new content
                        var newLine = new ConversationLine(ConversationLine.PLAYER, "");
                        optionConversationNode.addLine(newLine);
                        conversationLines.Add(new ConversationLineDataControl(newLine));
                        optionConversationNode.addChild(child.getContent() as ConversationNode);
                    }
                    else
                    {
                        // I have to push the current child to a grandchild position
                        var grandChild = optionConversationNode.getChild(index);
                        var newChild   = child.getContent() as ConversationNode;
                        // Set the child
                        optionConversationNode.replaceChild(index, newChild);

                        // Set the grandchild (if the node contains other childs, these will be preserved)
                        if (newChild.getChildCount() == 0)
                        {
                            newChild.addChild(grandChild);
                        }
                        else
                        {
                            newChild.replaceChild(0, grandChild);
                        }
                    }
                }
            }
            return(true);
        }
コード例 #13
0
        public override bool canAddChild(ConversationNodeDataControl node, int nodeType)
        {
            bool canAddChild = false;

            /*
             * // A dialogue node only accepts nodes if it is terminal
             * if (node.getType() == ConversationNodeViewEnum.DIALOGUE && node.isTerminal())
             *  canAddChild = true;
             *
             * // An option node only accepts dialogue nodes
             * if (node.getType() == ConversationNodeViewEnum.OPTION && nodeType == (int)ConversationNodeViewEnum.DIALOGUE)
             *  canAddChild = true;
             */
            return(canAddChild);
        }
コード例 #14
0
        private static int countNodeReferences(ConversationNodeDataControl actual, ConversationNodeDataControl lookup, List <ConversationNodeDataControl> visited)
        {
            var i = 0;

            if (!visited.Contains(actual))
            {
                visited.Add(actual);
                foreach (var child in actual.getChilds())
                {
                    if (child == lookup || child.getContent() == lookup.getContent())
                    {
                        i++;
                    }

                    i += countNodeReferences(child, lookup, visited);
                }
            }
            return(i);
        }
        protected override bool removeChild(int index, ConversationNodeDataControl child, ref object data)
        {
            bool removed = false;

            if (index == 0 && conversationNode.getChildCount() > 0)
            {
                if (conversationNode.getChild(index).getChildCount() > 0 && canLinkNode(child.getChilds()[0]))
                {
                    // We set the niece as child
                    data = conversationNode.replaceChild(index, conversationNode.getChild(index).getChild(0));
                }
                else
                {
                    data = conversationNode.removeChild(index);
                }
                removed = true;
            }

            return(removed);
        }
            public ChangeTimeoutTool(OptionNodeDataControl optionNode, float newValue)
            {
                this.optionNode        = optionNode;
                this.oldValue          = optionNode.Timeout;
                this.newValue          = newValue;
                this.isOnlyValueChange = oldValue > 0 && newValue > 0;

                if (oldValue > 0)
                {
                    child = optionNode.getChilds().Last();
                }
                else
                {
                    var newChild = new DialogueConversationNode();
                    var childPos = optionNode.GetNewChildPosition();
                    newChild.setEditorX(childPos.x);
                    newChild.setEditorY(childPos.y);
                    child = optionNode.conversation.getNodeDataControl(newChild);
                }
            }
        protected override bool removeChild(int index, ConversationNodeDataControl child, ref object data)
        {
            // Add the child to the given
            if (child.getChildCount() > 0 && canLinkNode(child.getChilds()[0]))
            {
                // We set the niece as child
                optionConversationNode.replaceChild(index, child.getChilds()[0].getContent() as ConversationNode);
            }
            else
            {
                if (optionConversationNode.Timeout > 0 && index == optionConversationNode.getChildCount() - 1)
                {
                    data = optionConversationNode.Timeout;

                    // We remove the timeout child
                    optionConversationNode.removeChild(index);
                    optionConversationNode.Timeout = -1;
                }
                else
                {
                    var line = data as ConversationLineDataControl;
                    if (line != null && line != conversationLines[index])
                    {
                        UnityEngine.Debug.Log("The line your're trying to remove is not in the same position as the child.");
                    }

                    data = conversationLines[index];
                    conversationLines.RemoveAt(index);
                    optionConversationNode.removeLine(index);

                    // We remove the option
                    optionConversationNode.removeChild(index);
                }
            }

            return(true);
        }
コード例 #18
0
 public AddRemoveLineTool(ConversationNodeDataControl node, ConversationLineDataControl toRemove)
 {
     this.isAdd = false;
     this.node  = node;
     this.line  = toRemove;
 }
コード例 #19
0
 public bool manages(ConversationNodeDataControl c)
 {
     return(c is DialogNodeDataControl);
 }
 protected override bool canLinkNode(ConversationNodeDataControl child)
 {
     return(child != this);
 }
コード例 #21
0
 public MoveLineTool(bool isUp, ConversationNodeDataControl node, ConversationLineDataControl line)
 {
     this.isUp = isUp;
     this.node = node;
     this.line = line;
 }
コード例 #22
0
 public override bool canMoveNode(ConversationNodeDataControl node)
 {
     // No node moving is allowed in graph conversations
     return(false);
 }
コード例 #23
0
 public override bool moveNode(ConversationNodeDataControl node, ConversationNodeDataControl hostNodeView)
 {
     // No node moving is allowed in graph conversations
     return(false);
 }
コード例 #24
0
 public AddRemoveConversationNodeTool(int nodeType, ConversationNodeDataControl parent) : this(nodeType, parent, parent.getChildCount())
 {
 }
コード例 #25
0
 public override bool canDeleteNode(ConversationNodeDataControl node)
 {
     // Any node can be deleted, if it is not the start node
     return(node.getContent() != graphConversation.getRootNode());
 }
コード例 #26
0
 public override int[] getAddableNodes(ConversationNodeDataControl node)
 {
     return(node.getAddableNodes());
 }
コード例 #27
0
 public override bool linkNode(ConversationNodeDataControl fatherView, ConversationNodeDataControl childView, int position)
 {
     return(Controller.Instance.AddTool(new ConversationNodeDataControl.LinkConversationNodeTool(this, fatherView, childView, position)));
 }
コード例 #28
0
 public AddRemoveConversationNodeTool(ConversationNodeDataControl parent, ConversationNodeDataControl childDataControl)
 {
     this.parent           = parent;
     this.childDataControl = childDataControl;
     this.index            = parent.getChilds().IndexOf(childDataControl); // Remove at index
 }
コード例 #29
0
 public AddRemoveConversationNodeTool(ConversationNodeDataControl parent, int index)
 {
     this.parent           = parent;
     this.childDataControl = parent.getChilds()[index];
     this.index            = index; // Remove at index
 }
コード例 #30
0
 public DeleteNodeLinkTool(ConversationNodeDataControl parent) : this(parent, 0)
 {
 }