Exemplo n.º 1
0
        public static bool IsPointerNearConnection(List <UINode> uiNodes, Vector2 mousePos, out EditableConnection connection)
        {
            EditableConversationNode parent = null;
            EditableConversationNode child  = null;

            if (IsPointerNearConnection(uiNodes, mousePos, out parent, out child))
            {
                EditableConversationNode.eNodeType type = child.NodeType;
                for (int i = 0; i < parent.Connections.Count; i++)
                {
                    if (type == EditableConversationNode.eNodeType.Speech)
                    {
                        EditableSpeechConnection con = parent.Connections[i] as EditableSpeechConnection;
                        if (con.Speech == child)
                        {
                            connection = parent.Connections[i];
                            return(true);
                        }
                    }
                    else if (type == EditableConversationNode.eNodeType.Option)
                    {
                        EditableOptionConnection con = parent.Connections[i] as EditableOptionConnection;
                        if (con.Option == child)
                        {
                            connection = parent.Connections[i];
                            return(true);
                        }
                    }
                }
            }

            connection = null;
            return(false);
        }
Exemplo n.º 2
0
        public static bool IsPointerNearConnection(List <UINode> uiNodes, Vector2 mousePos,
                                                   out EditableConversationNode par, out EditableConversationNode child)
        {
            par   = null;
            child = null;
            Vector2     start, end;
            float       minDistance = float.MaxValue;
            const float MIN_DIST    = 6;

            for (int i = 0; i < uiNodes.Count; i++)
            {
                List <EditableConnection> connections = uiNodes[i].Info.Connections;

                for (int j = 0; j < connections.Count; j++)
                {
                    if (connections[j] is EditableSpeechConnection)
                    {
                        EditableSpeechConnection speechCon = connections[j] as EditableSpeechConnection;
                        GetConnectionDrawInfo(uiNodes[i].rect, speechCon.Speech, out start, out end);

                        float distance = MinimumDistanceBetweenPointAndLine(start, end, mousePos);
                        if (distance < minDistance)
                        {
                            minDistance = distance;
                            par         = uiNodes[i].Info;
                            child       = speechCon.Speech;
                        }
                    }
                    else if (connections[j] is EditableOptionConnection)
                    {
                        EditableOptionConnection optionCon = connections[j] as EditableOptionConnection;
                        GetConnectionDrawInfo(uiNodes[i].rect, optionCon.Option, out start, out end);

                        float distance = MinimumDistanceBetweenPointAndLine(start, end, mousePos);
                        if (distance < minDistance)
                        {
                            minDistance = distance;
                            par         = uiNodes[i].Info;
                            child       = optionCon.Option;
                        }
                    }
                }
            }

            if (minDistance < MIN_DIST)
            {
                return(true);
            }
            else
            {
                par   = null;
                child = null;
                return(false);
            }
        }
        public void DrawConnections(EditableConnection currentlySelected)
        {
            Vector2 start = Vector2.zero;
            Vector2 end   = Vector2.zero;
            float   xPos  = 0;
            float   yPos  = 0;

            for (int i = 0; i < Info.Connections.Count; i++)
            {
                bool connectingToOption = false;

                if (Info.Connections[i].ConnectionType == EditableConnection.eConnectiontype.Speech)
                {
                    EditableSpeechConnection connection = Info.Connections[i] as EditableSpeechConnection;

                    DialogueEditorUtil.GetConnectionDrawInfo(rect, connection.Speech, out start, out end);
                    xPos = connection.Speech.EditorInfo.xPos;
                    yPos = connection.Speech.EditorInfo.yPos;
                }
                else if (Info.Connections[i].ConnectionType == EditableConnection.eConnectiontype.Option)
                {
                    EditableOptionConnection connection = Info.Connections[i] as EditableOptionConnection;

                    DialogueEditorUtil.GetConnectionDrawInfo(rect, connection.Option, out start, out end);
                    xPos = connection.Option.EditorInfo.xPos;
                    yPos = connection.Option.EditorInfo.yPos;

                    connectingToOption = true;
                }

                bool selected = (currentlySelected != null && currentlySelected == Info.Connections[i]);


                Vector2 toStart = (start - end).normalized;
                Vector2 toEnd   = (end - start).normalized;
                if (selected)
                {
                    Handles.DrawBezier(start, end, start + toStart, end + toEnd, SelectedColor, null, LINE_WIDTH * 3);
                }
                Handles.DrawBezier(start, end, start + toStart, end + toEnd, DefaultColor, null, LINE_WIDTH);

                Vector2 intersection;
                Vector2 boxPos = new Vector2(xPos, yPos);
                if (DialogueEditorUtil.DoesLineIntersectWithBox(start, end, boxPos, connectingToOption, out intersection))
                {
                    if (selected)
                    {
                        DialogueEditorUtil.DrawArrowTip(intersection, toEnd, SelectedColor, LINE_WIDTH * 3);
                    }
                    DialogueEditorUtil.DrawArrowTip(intersection, toEnd, DefaultColor);
                }
            }
        }
Exemplo n.º 4
0
        public void RemoveSelfFromTree()
        {
            // This speech is no longer the parent of any children
            for (int i = 0; i < Connections.Count; i++)
            {
                if (Connections[i] is EditableSpeechConnection)
                {
                    EditableSpeechConnection speechCon = Connections[i] as EditableSpeechConnection;
                    speechCon.Speech.parents.Remove(this);
                }
                else if (Connections[i] is EditableOptionConnection)
                {
                    EditableOptionConnection optionCon = Connections[i] as EditableOptionConnection;
                    optionCon.Option.parents.Remove(this);
                }
            }

            // This speech is no longer any of my parents child speech
            for (int i = 0; i < parents.Count; i++)
            {
                parents[i].DeleteConnectionChild(this);
            }
        }
Exemplo n.º 5
0
        public void DeleteConnectionChild(EditableConversationNode node)
        {
            if (Connections.Count == 0)
            {
                return;
            }

            if (node.NodeType == eNodeType.Speech && Connections[0] is EditableSpeechConnection)
            {
                EditableSpeechNode toRemove = node as EditableSpeechNode;

                for (int i = 0; i < Connections.Count; i++)
                {
                    EditableSpeechConnection con = Connections[i] as EditableSpeechConnection;
                    if (con.Speech == toRemove)
                    {
                        Connections.RemoveAt(i);
                        return;
                    }
                }
            }
            else if (node is EditableOptionNode && Connections[0] is EditableOptionConnection)
            {
                EditableOptionNode toRemove = node as EditableOptionNode;

                for (int i = 0; i < Connections.Count; i++)
                {
                    EditableOptionConnection con = Connections[i] as EditableOptionConnection;
                    if (con.Option == toRemove)
                    {
                        Connections.RemoveAt(i);
                        return;
                    }
                }
            }
        }