Esempio n. 1
0
        // used internally for playtest preview
        public static string SaveAllNodesAsString(int onlyWithParentID = -1)
        {
            var treeNodes = onlyWithParentID >= 0 ? MerinoData.GetAllCachedChildren(onlyWithParentID) : MerinoData.TreeElements;

            if (MerinoPrefs.validateNodeTitles)
            {
                ValidateNodeTitles(treeNodes);
            }

            var nodeInfo = new List <YarnSpinnerLoader.NodeInfo>();

            foreach (var treeNode in treeNodes)
            {
                if (treeNode.depth == -1 || treeNode.leafType != MerinoTreeElement.LeafType.Node)
                {
                    continue;
                }

                nodeInfo.Add(TreeNodeToYarnNode(treeNode));
            }

            return(YarnSpinnerFileFormatConverter.ConvertNodesToYarnText(nodeInfo));
        }
        void DrawToolbar(Event e)
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);

            if (validDialogue)
            {
                GUILayout.Space(2);                 //small space to mimic unity editor

                // jump to node button
                var jumpOptions      = dialogue.allNodes.ToList();
                int currentJumpIndex = jumpOptions.IndexOf(dialogue.currentNode);
                if (!IsDialogueRunning)
                {
                    // if there is no current node, then inform the user that
                    currentJumpIndex = 0;
                    jumpOptions.Insert(0, "<Stopped> Jump to Node?...");
                }
                GUI.SetNextControlName(popupControl);
                int newJumpIndex = EditorGUILayout.Popup(
                    new GUIContent("", "The node you're currently playing; you can also jump to any other node."),
                    currentJumpIndex,
                    jumpOptions.Select(x => x.StartsWith("<Stopped>") ? new GUIContent(x) : new GUIContent("Node: " + x)).ToArray(),
                    EditorStyles.toolbarDropDown,
                    GUILayout.Width(160));
                if (currentJumpIndex != newJumpIndex)
                {
                    if (IsDialogueRunning || newJumpIndex > 0)
                    {
                        PlaytestFrom_Internal(jumpOptions[newJumpIndex], false);
                    }
                }
                GUILayout.Space(6);

                GUI.enabled = IsDialogueRunning;                 // disable if dialogue isn't running
                // attempt to get current node
                var matchingNode = MerinoData.GetNode(dialogue.currentNode);
                if (lastFileParent > 0)                     // if we know the file where the playtest started, we can be more specific
                {
                    matchingNode = MerinoData.GetAllCachedChildren(lastFileParent).Find(node => node.name == dialogue.currentNode);
                    // ok if that search failed for some reason, then just give up and fallback
                    if (matchingNode == null)
                    {
                        matchingNode = MerinoData.GetNode(dialogue.currentNode);
                    }
                }
                var content = new GUIContent(" View Node Source", MerinoEditorResources.TextAsset, "Click to see Yarn script code for this node.");
                if (GUILayout.Button(content, EditorStyles.toolbarButton, GUILayout.Width(EditorStyles.toolbarButton.CalcSize(content).x - 40)))
                {
                    if (matchingNode != null)
                    {
                        // display in yarn editor window
                        GetWindow <MerinoEditorWindow>(MerinoEditorWindow.windowTitle, true).
                        SelectNodeAndZoomToLine(matchingNode.id, GuessLineNumber(matchingNode.id, displayStringFull));
                    }
                    else
                    {
                        MerinoDebug.LogFormat(LoggingLevel.Warning, "Merino culdn't find any node called {0}. It might've been deleted or the Yarn file is corrupted.", dialogue.currentNode);
                    }
                }
                if (GUILayout.Button(new GUIContent(" View in Node Map", MerinoEditorResources.Nodemap, "Click to see this node in the node map window."), EditorStyles.toolbarButton))
                {
                    if (matchingNode != null)
                    {
                        MerinoNodemapWindow.GetNodemapWindow().FocusNode(matchingNode.id);
                    }
                    else
                    {
                        MerinoDebug.LogFormat(LoggingLevel.Warning, "Merino couldn't find any node called {0}. It might've been deleted or the Yarn file is corrupted.", dialogue.currentNode);
                    }
                }
                GUI.enabled = true;
            }

            GUILayout.FlexibleSpace();

            // playtesting preferences popup
            if (GUILayout.Button(new GUIContent("Preferences"), EditorStyles.toolbarDropDown))
            {
                PopupWindow.Show(prefButtonRect, new PlaytestPrefsPopup(IsDocked()));
            }
            //grab popup button's rect do determine the height of the toolbar
            if (e.type == EventType.Repaint)
            {
                prefButtonRect = GUILayoutUtility.GetLastRect();
            }

            GUILayout.Space(2);             //small space to mimic unity editor

            EditorGUILayout.EndHorizontal();

            // eat clicks
            if (e.type == EventType.MouseDown)
            {
                // clicked on toolbar
                if (e.mousePosition.y < prefButtonRect.height)
                {
                    e.Use();
                }

                // clicked out of popup
                if (GUI.GetNameOfFocusedControl() == popupControl)
                {
                    e.Use();
                    GUI.FocusControl(null);
                }
            }
        }