Esempio n. 1
0
        protected void drawTransitionEdge(Pair <int, int> indices)
        {
            Rect    toRect;
            Vector2 from, to;
            Vector2 arrowPosition;
            bool    fromIntent, toIntent;
            int     metaIndex;

            metaIndex  = graph.edges.IndexOf(indices);
            fromIntent = graph.nodes[indices.key] is MoronIntent;
            toIntent   = graph.nodes[indices.value] is MoronIntent;

            Handles.color = Color.white;

            // if it's intent-to-intent, this is a default "next" transition and should be called out that way.
            if (fromIntent && toIntent)
            {
                Handles.color = NEXT_TRANSITION_COLOR;
            }

            if (!fromIntent)
            {
                // "yes" choices are green, "no" choices are red.
                // if this index is less than all other neighbors, it's a "yes". Otherwise it's a "no".
                Handles.color = YES_TRANSITION_COLOR;

                foreach (int index in findNeighborsFrom(indices.key))
                {
                    if (metaIndex > index)
                    {
                        Handles.color = NO_TRANSITION_COLOR;
                        break;
                    }
                }
            }

            // finally, if this is the selected edge, color it purple.
            if (selectedEdge >= 0 && indices.Equals(graph.edges[selectedEdge]))
            {
                Handles.color = SELECTED_TRANSITION_COLOR;
            }

            from = graph.nodes[indices.key].position;
            to   = graph.nodes[indices.value].position;

            toRect        = makeNodeRect(graph.nodes[indices.value]);
            arrowPosition = VectorHandling.findPointAroundRect(from, toRect);

            Handles.DrawLine(from, to);
            drawArrow(arrowPosition, Quaternion.Euler(0f, 0f, VectorHandling.angleBetween(from, to)), 5, 12);
        }
Esempio n. 2
0
        protected Rect findMaxArea()
        {
            Vector2 max;

            max = Vector2.zero;

            foreach (MoronIONode node in graph.nodes)
            {
                max = VectorHandling.findAllMax(node.position, max);
            }

            max = VectorHandling.add(max, 200f);
            return(new Rect(0f, 0f, max.x, max.y));
        }
Esempio n. 3
0
        protected override bool evaluate()
        {
            Vector3 difference;

            if (relative)
            {
                difference = (thinker.gameObject.transform.position - center.transform.position).normalized;
                result     = VectorHandling.multiply(difference, offset) + center.transform.position;
            }
            else
            {
                result = center.transform.position + offset;
            }

            return(true);
        }
Esempio n. 4
0
        protected int findEdgeForPosition(Vector2 position)
        {
            Pair <int, int> edge;
            float           distance;

            for (int i = 0; i < graph.edges.Count; i++)
            {
                edge     = graph.edges[i];
                distance = VectorHandling.lineSegmentDistance(position, graph.nodes[edge.key].position, graph.nodes[edge.value].position);

                if (distance < 5)
                {
                    return(i);
                }
            }

            return(-1);
        }
Esempio n. 5
0
        public void updateInput(Event current)
        {
            MoronIONode currentNode;
            Vector2     position;

            position = current.mousePosition + scrollPosition;

            switch (current.type)
            {
            case EventType.MouseDown:

                if (!checkStatemapWidth(position.x))
                {
                    break;
                }

                lastClicked = position;

                switch (current.button)
                {
                case 0:

                    selectedEdge = -1;
                    currentNode  = findNodeForPosition(position);

                    if (transitionLine)
                    {
                        m0 = false;

                        if (currentNode != null)
                        {
                            makeTransition(selected, currentNode);
                        }
                        break;
                    }

                    selected = currentNode;

                    if (selected != null)
                    {
                        selectionOffset = VectorHandling.convXY(selected.position) - position;
                        m0 = true;
                    }
                    else
                    {
                        deselectNode();
                        selectionOffset = Vector3.zero;
                        selectedEdge    = findEdgeForPosition(position);
                    }

                    break;

                case 1:

                    selected = findNodeForPosition(position);
                    if (selected == null)
                    {
                        selectedEdge = findEdgeForPosition(position);
                    }

                    rightClick();
                    break;
                }

                transitionLine = false;
                GUI.FocusControl("");
                break;

            case EventType.MouseUp:

                transitionLine = false;

                if (current.button != 0)
                {
                    break;
                }

                m0 = false;

                if (!checkStatemapWidth(position.x))
                {
                    break;
                }

                if (findNodeForPosition(position) != selected)
                {
                    deselectNode();
                }
                break;

            case EventType.MouseDrag:

                lastDragged = position;
                if (!m0 || selected == null)
                {
                    break;
                }

                selected.position = VectorHandling.gridsnap(lastDragged + selectionOffset, GRIDSNAP_SIZE);
                markDirty();
                break;

            case EventType.KeyDown:

                if (!checkStatemapWidth(current.mousePosition.x))
                {
                    break;
                }

                switch (current.keyCode)
                {
                case KeyCode.X:
                case KeyCode.Delete:

                    deleteSelected();
                    break;

                case KeyCode.T:

                    MoronTransitionCondition condition;

                    if (selected == null || transitionLine)
                    {
                        break;
                    }

                    condition = MoronTransitionCondition.INTENT;

                    if (selected is MoronChoice)
                    {
                        condition = MoronTransitionCondition.YES;
                    }

                    startTransition(condition);
                    break;

                case KeyCode.A:

                    showAddMenu();
                    break;
                }
                break;
            }
        }