void AddNewNode()
    {
        if (_newDKey == null || _newDKey == "" || _newStrKey == null || _newStrKey == "")
        {
            Debug.Log("Can't add new node. Invalid dialog ID key and/or string ID key.");
            return;
        }

        DialogNode newNode = new DialogNode(_newDKey, _newStrKey);

        if (dm.Graph.Contains(newNode))
        {
            Debug.Log("Dialog ID key already exist! Please enter another key.");
            return;
        }

        dm.Graph.Add(newNode);

        LanguageController.Instance.AddWord(_newStrKey, _newdialog);

        DialogNodeGUI newNodeWindow = CreateInstance <DialogNodeGUI>();

        int newWindowId = nodeWindows[nodeWindows.Count - 1].WindowId + 1;

        newNodeWindow.init(newNode, newWindowId, new Vector2(100, 100));
        windows.Add(newNodeWindow.Shape);
        nodeWindows.Add(newNodeWindow);

        windows[windows.Count - 1] = GUILayout.Window(newNodeWindow.WindowId, windows[windows.Count - 1], newNodeWindow.DrawNodeWindow, newNodeWindow.Node.StrKey);
    }
    void DrawLinks()
    {
        int numNodes = windows.Count;

        for (int i = 0; i < numNodes; ++i)
        {
            Rect          parentNodeShape  = windows[i];
            DialogNodeGUI parentNodeWindow = nodeWindows[i];

            AdjacencyList adjLinks = parentNodeWindow.Node.Neighbors;

            int resIndex = 0;

            while (resIndex < adjLinks.Count)
            {
                ResponseNode resNode = (ResponseNode)adjLinks[resIndex].Neighbor;

                // Remove this link if linking node is removed
                if (!dm.Graph.Contains(resNode))
                {
                    adjLinks.RemoveAt(resIndex);
                    continue;
                }

                // skip current node if this response node does not connect to any dialog
                if (resNode.Neighbor == null)
                {
                    ++resIndex;
                    continue;
                }
                else if (!dm.Graph.Contains(resNode.Neighbor.Neighbor))
                {// if the node to link with does not exist, then remove the link and move to next response node
                    dm.Graph.RemoveLink(resNode, resNode.Neighbor.Neighbor);
                    ++resIndex;
                    continue;
                }

                int nextNodeIndex = nodeWindows.FindIndex(x => x.Node == resNode.Neighbor.Neighbor);

                if (nextNodeIndex < 0)
                {
                    Debug.Log("Cannot find the node to link with. Are you trying to link a response dialog with another response?");
                    dm.Graph.RemoveLink(resNode, resNode.Neighbor.Neighbor);
                    ++resIndex;
                    continue;
                }

                DrawNodeCurve(parentNodeShape, windows[nextNodeIndex], adjLinks.Count, resIndex);

                ++resIndex;
            }
        }
    }
    void BuildNodeWindows()
    {
        int nodeId = 0;

        foreach (KeyValuePair <string, DialogNode> n in dm.Graph.Nodes)
        {
            DialogNode node = n.Value;

            // don't build a window for a response dialog because it's included in a dialog node window
            if (node.GetType() == typeof(ResponseNode))
            {
                continue;
            }

            DialogNodeGUI dngui = CreateInstance <DialogNodeGUI>();
            dngui.init(node, nodeId, new Vector2(nodeId % ((1000 - sideWindowWidth) / 220) * 220, nodeId / ((1000 - sideWindowWidth) / 220) * 120));
            nodeWindows.Add(dngui);
            windows.Add(dngui.Shape);

            ++nodeId;
        }
    }