Exemple #1
0
    public void NextNode(int i)
    {
        if (tree == null)
        {
            return;
        }

        OCRootNode rootNode = tree.rootNodes[tree.currentRoot];
        OCNode     node     = rootNode.GetNode(currentNode);

        // Force output 0 on smalltalk nodes, just in case
        if (node.speak != null && node.speak.smalltalk)
        {
            i = 0;
        }

        // Check for range
        if (i < node.connectedTo.Length)
        {
            currentNode = node.connectedTo[i];
            DisplayNode();
        }
        else
        {
            Debug.LogError("OCManager | Node index '" + i + "' out of range (0-" + (node.connectedTo.Length - 1) + ")");
            EndConversation();
        }
    }
Exemple #2
0
    public void MoveRoot(int from, int to)
    {
        if (to >= 0 && to < rootNodes.Length)
        {
            OCRootNode fromRootNode = rootNodes[from];
            OCRootNode toRootNode   = rootNodes[to];

            rootNodes[to]   = fromRootNode;
            rootNodes[from] = toRootNode;
        }
    }
Exemple #3
0
    public void NextNode()
    {
        OCRootNode rootNode = tree.rootNodes[tree.currentRoot];
        OCNode     node     = rootNode.GetNode(currentNode);

        if (node.speak != null && node.speak.choice)
        {
            NextNode(node.speak.index);
        }
        else
        {
            NextNode(0);
        }
    }
Exemple #4
0
    public void OnGUI()
    {
        placedInputs.Clear();

        title = "Tree Editor";

        distance.x = 220;
        distance.y = 100;

        List <string>     tmpStr   = new List <string> ();
        List <OCRootNode> tmpRoot  = new List <OCRootNode> ();
        OCRootNode        thisRoot = null;
        OCRootNode        thatRoot = null;

        if (!target)
        {
            EditorGUI.LabelField(new Rect(position.width / 2 - 42, position.height / 2 - 10, 84, 20), "No target tree!", EditorStyles.boldLabel);
            return;
        }

        if (target.rootNodes.Length < 1)
        {
            target.AddRootNode();
        }

        if (currentRoot > target.rootNodes.Length - 1)
        {
            currentRoot = target.rootNodes.Length - 1;
        }

        // Inspector
        Rect inspectorRect      = new Rect(position.width - 300, 0, 300, position.height);
        Rect innerInspectorRect = new Rect(inspectorRect.x + 10, inspectorRect.y + 10, inspectorRect.width - 20, inspectorRect.height - 20);

        GUILayout.BeginArea(innerInspectorRect);

        int i;

        GUILayout.Label("Tree (" + target.gameObject.name + ")", EditorStyles.largeLabel);
        GUILayout.Box("", GUILayout.Height(1), GUILayout.Width(270));

        // ^ Speaker names
        if (target.speakers.Length < 1)
        {
            tmpStr = new List <string> (target.speakers);
            tmpStr.Add("Speaker");
            target.speakers = tmpStr.ToArray();
        }

        GUILayout.Label("Speaker names", EditorStyles.boldLabel);
        for (i = 0; i < target.speakers.Length; i++)
        {
            GUILayout.BeginHorizontal();

            GUI.backgroundColor = speakerColors[i];
            target.speakers[i]  = GUILayout.TextField(target.speakers[i]);
            GUI.backgroundColor = Color.white;

            GUI.color = Color.red;
            if (target.speakers.Length > 1 && GUILayout.Button("x", GUILayout.Height(16), GUILayout.Width(32)))
            {
                tmpStr = new List <string> (target.speakers);
                tmpStr.RemoveAt(i);
                target.speakers = tmpStr.ToArray();
                return;
            }
            GUI.color = Color.white;

            GUILayout.EndHorizontal();
        }

        GUI.color = Color.green;
        if (target.speakers.Length < 10 && GUILayout.Button("+", GUILayout.Height(16), GUILayout.Width(32)))
        {
            tmpStr = new List <string> (target.speakers);
            tmpStr.Add("Speaker");
            target.speakers = tmpStr.ToArray();
        }
        GUI.color = Color.white;

        GUILayout.Space(20);

        GUILayout.Label("Root", EditorStyles.largeLabel);
        GUILayout.Box("", GUILayout.Height(1), GUILayout.Width(270));

        // ^ Tags
        string[] tags      = target.rootNodes[currentRoot].tags;
        string   tagString = "";

        for (i = 0; i < tags.Length; i++)
        {
            tagString += tags[i];

            if (i < tags.Length - 1)
            {
                tagString += ",";
            }
        }

        GUILayout.Label("Tags", EditorStyles.boldLabel);
        tagString = GUILayout.TextField(tagString);

        target.rootNodes[currentRoot].tags = tagString.Split(","[0]);

        GUILayout.Space(20);

        // ^ Node
        GUILayout.Label("Node", EditorStyles.largeLabel);
        GUILayout.Box("", GUILayout.Height(1), GUILayout.Width(270));

        inspectorScrollPosition = GUILayout.BeginScrollView(inspectorScrollPosition);

        if (node != null)
        {
            DrawInspector();
        }

        GUILayout.EndScrollView();

        GUILayout.EndArea();

        scrollRect = new Rect(0, 0, position.width - inspectorRect.width, position.height);

        GUI.Box(scrollRect, "");

        // Tree editor
        scrollPosition = GUI.BeginScrollView(scrollRect, scrollPosition, innerScrollRect);

        Vector2 center = scrollRect.center;
        float   right  = center.x - ((target.rootNodes.Length * 1.0f) / 2f) * 32f;

        // ^ Root navigation
        if (currentRoot > 0 && GUI.Button(new Rect(right + (currentRoot - 1) * 32 - 16, 8, 32, 16), "<"))
        {
            tmpRoot  = new List <OCRootNode> (target.rootNodes);
            thisRoot = tmpRoot [currentRoot];
            thatRoot = tmpRoot [currentRoot - 1];
            tmpRoot [currentRoot]     = thatRoot;
            tmpRoot [currentRoot - 1] = thisRoot;
            target.rootNodes          = tmpRoot.ToArray();
            currentRoot--;
        }

        GUI.color = Color.red;
        if (GUI.Button(new Rect(right + currentRoot * 32 - 16, 8, 32, 16), "x"))
        {
            target.RemoveRootNode(currentRoot);
            return;
        }
        GUI.color = Color.white;

        if (currentRoot < target.rootNodes.Length - 1 && GUI.Button(new Rect(right + (currentRoot + 1) * 32 - 16, 8, 32, 16), ">"))
        {
            tmpRoot  = new List <OCRootNode> (target.rootNodes);
            thisRoot = tmpRoot [currentRoot];
            thatRoot = tmpRoot [currentRoot + 1];
            tmpRoot [currentRoot]     = thatRoot;
            tmpRoot [currentRoot + 1] = thisRoot;
            target.rootNodes          = tmpRoot.ToArray();
            currentRoot++;
        }

        // ^ Root display
        for (i = 0; i < target.rootNodes.Length; i++)
        {
            if (i == currentRoot)
            {
                GUI.color = Color.white;
            }
            else
            {
                GUI.color = Color.grey;
            }

            if (GUI.Button(new Rect(right + i * 32 - 16, 32, 32, 16), i.ToString()))
            {
                currentRoot            = i;
                innerScrollRect.width  = scrollRect.width;
                innerScrollRect.height = scrollRect.height;
                innerScrollRect.x      = 0;
                innerScrollRect.y      = 0;
            }

            GUI.color = Color.white;
        }

        // ^ Add root node
        GUI.color = Color.green;
        if (GUI.Button(new Rect(right + i * 32 - 16, 32, 32, 16), "+"))
        {
            target.AddRootNode();
        }
        GUI.color = Color.white;

        // ^ Node display
        GUI.color = Color.green;
        if (GUI.Button(new Rect(right + currentRoot * 32 - 12, 56, 24, 12), "+"))
        {
            OCNode newNode   = target.rootNodes [currentRoot].AddNode();
            OCNode firstNode = target.rootNodes [currentRoot].GetFirstNode();

            if (firstNode.connectedTo [i] > 0)
            {
                newNode.connectedTo [0] = firstNode.connectedTo [i];
            }

            firstNode.connectedTo [i] = newNode.id;

            node = newNode;
        }

        GUI.color = Color.white;
        if (target.rootNodes[currentRoot].nodes.Length < 1)
        {
            target.rootNodes[currentRoot].AddFirstNode();
        }

        DrawLine(new Vector2(right + currentRoot * 32, 48), new Vector2(center.x, 96));
        DrawNode(target.rootNodes[currentRoot].GetNode(target.rootNodes[currentRoot].firstNode), center.x, 96);

        GUI.EndScrollView();

        if (Event.current.type == EventType.MouseDown)
        {
            OCNode cNode = target.rootNodes [currentRoot].GetNode(connectingNode);

            if (cNode != null)
            {
                cNode.connectedTo[connectingOutput] = 0;
            }

            connectingNode   = 0;
            connectingOutput = 0;
        }

        if (connectingNode > 0)
        {
            Repaint();
        }

        if (innerScrollRect.width < scrollRect.width)
        {
            innerScrollRect.width = scrollRect.width;
        }

        if (innerScrollRect.height < scrollRect.height)
        {
            innerScrollRect.height = scrollRect.height;
        }

        if (GUI.changed)
        {
            target.CleanUp();
        }
    }