Esempio n. 1
0
    private DialogNode GenerateEntryPointNode()
    {
        var node = new DialogNode
        {
            title      = "Start",
            GUID       = System.Guid.NewGuid().ToString(),
            DialogText = "ENTRYPOINT",
            EntryPoint = true
        };

        var generatePort = GeneratePort(node, Direction.Output);

        generatePort.portName = "Next";
        node.outputContainer.Add(generatePort);

        var button = new Button(() =>
        {
            AddChoicePort(node);
        });

        button.text = "New Choice";
        node.titleContainer.Add(button);

        node.RefreshExpandedState();
        node.RefreshPorts();

        node.SetPosition(new Rect(100, 200, 100, 150));
        return(node);
    }
 private void QuestNotAcceptedDialog()
 {
     if (state == State.greet)
     {
         node = new DialogNode("Hey there traveller. Would you be so kind as to find me a vial of cyanide?", "Sure, I'd love to help.", "Maybe later.");
         HandleNode(node);
         state = State.end;
     }
     else if (state == State.accept)
     {
         manager.ST("How wonderful! Be sure to come back with the cyanide.");
         state = State.end;
     }
     else if (state == State.decline)
     {
         manager.ST("Thats too bad. Well, I'm here if you change your mind!");
         state = State.end;
     }
     else if (state == State.end)
     {
         if (!questAccepted)
         {
             slobodansHonorQuest = new SlobodansHonor();
             QuestManager.Instance.AddQuest(slobodansHonorQuest);
             manager.endConvo();
             state         = State.greetAccepted;
             questAccepted = true;
             print("Quest accepted: " + slobodansHonorQuest.GetQuestName());
         }
     }
 }
Esempio n. 3
0
    public void ReturnFromAction(bool useNextNode)
    {
        canContinueDialog = true;

        if (useNextNode)
        {
            currentNode = myDialogDefiniton.nodes[currentNode.child_id];
        }

        if (currentlySpeakingIcon != null)
        {
            currentlySpeakingIcon.gameObject.SetActive(true);
        }

        textBox.SetActive(true);
        if (currentlySpeakingIcon.GetType() == typeof(MultipleDialogIconsManager) &&
            characterName.text != currentNode.speakerName && currentNode.speakerName.Length > 1)//>2 check os for if the field is blank, which it is if the speaker is the same as previous
        {
            Debug.Log("NAMES DONT MATCHx-x-x-x--x-x-x-x-x-x-");
            ((MultipleDialogIconsManager)currentlySpeakingIcon).ChangeSpeaker(currentNode.speakerName);
            characterName.text = currentNode.speakerName;
        }

        StartDisplay();
    }
Esempio n. 4
0
    // -----------------------------------------------------------------------------------
    // Display the dialog node on the UI
    void DisplayDialog(DialogNode node)
    {
        currentNode    = node;
        currentNodeID  = (int)node.id;
        currentPage    = 0;
        image.sprite   = null;
        image.color    = new Color(1.0f, 1.0f, 1.0f, 0.0f);
        responseNodes  = FilterDialogNodes(currentNode.GetResponseNodes());
        textField.text = ReplaceMacros(currentNode.text, false);
        if (scene != null)
        {
            if (log)
            {
                Debug.Log("Set Camera to " + currentNode.speaker);
            }
            scene.SetCamera(mainCam, currentNode.speaker);
        }
        if (responseNodes.Count == 0)
        {
            EndDialog();
        }
        if (image.sprite != null)
        {
            image.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
        }

        DisplayResponses(currentPage);
        if (scriptFragments.CallFragment("action", currentNode.id) == false)
        {
            EndDialog();
            return;
        }
    }
Esempio n. 5
0
        public static Conversation load(String fileName)
        {
            Conversation conv   = new Conversation("");
            XmlDocument  xmlDoc = new XmlDocument();

            xmlDoc.Load(fileName);
            XmlNodeList xmlNL = xmlDoc.GetElementsByTagName("npcName");
            XmlElement  xmlEl;

            xmlEl        = (XmlElement)xmlNL[0];
            conv.npcName = xmlEl.GetAttribute("npcName");
            xmlNL        = xmlDoc.GetElementsByTagName("resetConversation");
            xmlEl        = (XmlElement)xmlNL[0];
            bool resetConv = bool.Parse(xmlEl.GetAttribute("resetConversation"));

            conv.resetConversationOnEnd = resetConv;

            xmlNL = xmlDoc.SelectNodes("/conversation/dialog/dialogNode");
            for (int i = 0; i < xmlNL.Count; i++)
            {
                xmlEl = (XmlElement)xmlNL[i];
                DialogNode node = loadNode(xmlEl, ref conv);
                conv.addRootNode(node);
            }

            return(conv);
        }
Esempio n. 6
0
 public void DisplayConversation(DialogNode node)
 {
     ResetCanvas();
     if (node != null)
     {
         GameObject.FindObjectOfType <GlobalVariables>().dialogueManager.dialogue.transform.parent.gameObject.SetActive(true);
         StartCoroutine(Type(node.message));
         if (node.neighbours != null && node.neighbours.Count > 0)
         {
             int i = 0;
             foreach (int neighbor in node.neighbours)
             {
                 if (simpleDialogGraph.GetNode(neighbor).descriptor.Equals("") || simpleDialogGraph.GetNode(neighbor).descriptor.Equals("shop") || (!simpleDialogGraph.GetNode(neighbor).itemTypeToGive.Equals("") && player.inventory.FindItemByType(simpleDialogGraph.GetNode(neighbor).itemTypeToGive) != null))
                 {
                     GameObject.FindObjectOfType <GlobalVariables>().dialogueManager.playerOptions[i].transform.parent.gameObject.SetActive(true);
                     GameObject.FindObjectOfType <GlobalVariables>().dialogueManager.playerOptions[i].text = simpleDialogGraph.GetNode(neighbor).message;
                     activeNodes.AddLast(simpleDialogGraph.GetNode(neighbor));
                     i++;
                 }
             }
             GameObject.FindObjectOfType <GlobalVariables>().dialogueManager.playerOptions[0].faceColor = Color.green;
             currentNode = activeNodes.First;
         }
     }
 }
Esempio n. 7
0
        private void afterLabelEdit(object sender, LabelEditEventArgs e)
        {
            if (e.Label == null || e.Label.Length == 0)
            {
                e.CancelEdit = true;
                return;
            }

            if (treeListView.SelectedObject is DialogNode)
            {
                DialogNode node = (DialogNode)treeListView.SelectedObject;
                node.npcDialog = e.Label;
            }
            else
            {
                DialogResponse r = (DialogResponse)treeListView.SelectedObject;
                r.response = e.Label;
            }

            if (!changesMade)
            {
                this.Text = this.Text + "*";
            }
            changesMade = true;
        }
Esempio n. 8
0
    public void AddOption(string text, DialogNode node, DialogNode dest)
    {
        if (!Nodes.Contains(dest))
        {
            AddNode(dest);
        }

        if (!Nodes.Contains(node))
        {
            AddNode(node);
        }

        DialogOption opt;

        if (dest == null)
        {
            opt = new DialogOption(text, -1);
        }
        else
        {
            opt = new DialogOption(text, dest.NodeID);
        }

        node.Options.Add(opt);
    }
Esempio n. 9
0
    public static DialogTextNode Parse(Dictionary <string, object> node)
    {
        long   id      = (long)node["id"];
        string npcName = (string)node["npc"];

        DialogNode[] children = null;
        if (node.ContainsKey("children") && node["children"] != null)
        {
            children = new DialogNode[((List <object>)node["children"]).Count];
        }

        string[] requireItems = null;
        if (node.ContainsKey("require_items") && node["require_items"] != null)
        {
            requireItems = ((List <object>)node["require_items"]).Select(s => (string)s).ToArray();
        }

        string[] addItems = null;
        if (node.ContainsKey("add_items") && node["add_items"] != null)
        {
            addItems = ((List <object>)node["add_items"]).Select(s => (string)s).ToArray();
        }

        string[] dialogs = ((List <object>)node["dialogs"]).Select(s => (string)s).ToArray();

        return(new DialogTextNode(id, npcName, children, requireItems, addItems, dialogs));
    }
Esempio n. 10
0
        private static void saveNode(DialogNode node, ref XmlElement xmlEl,
                                     ref XmlDocument xmlDoc)
        {
            XmlElement xmlChildEl = xmlDoc.CreateElement("dialogNode");

            xmlChildEl.SetAttribute("id", node.id);
            xmlChildEl.SetAttribute("npcPhrase", node.npcDialog);
            xmlChildEl.SetAttribute("voiceFile", node.npcVoiceFile);

            DialogResponse[] responses = node.getResponses();
            for (int j = 0; j < responses.Length; j++)
            {
                DialogResponse response   = responses[j];
                XmlElement     responseXE = xmlDoc.CreateElement("response");
                responseXE.SetAttribute("pcPhrase", response.response);
                responseXE.SetAttribute("link", response.link);
                responseXE.SetAttribute("linkType",
                                        response.linkType.ToString());
                responseXE.SetAttribute("switchConversation",
                                        response.switchConversation);
                responseXE.SetAttribute("onlyAllowOnce",
                                        response.onlyAllowOnce.ToString());
                xmlChildEl.AppendChild(responseXE);
                if (response.childNode != null)
                {
                    saveNode(response.childNode, ref responseXE, ref xmlDoc);
                }
            }
            xmlEl.AppendChild(xmlChildEl);
        }
Esempio n. 11
0
    private void AddLine(List <DialogNode> AddDialogNode, bool Copy = false, bool CopyFromOpening = false)
    {
        Undo.RegisterCompleteObjectUndo(dialog, "DefaultUndo");
        DialogNode EmptyDialogNode = new DialogNode(Copy);

        if (CopyHelper)
        {
            if (CopyFromOpening)
            {
                EmptyDialogNode = new DialogNode(dialog.StartingOptions[CopyInt]);
            }
            else
            {
                EmptyDialogNode = new DialogNode(AddDialogNode[CopyInt]);
            }
            CopyHelper = false;
        }

        // Adding a new dialog node
        if (!Copy)
        {
            AddDialogNode.Add(EmptyDialogNode);
            EditArray()[EditedLine].NextOptionID.Add(AddDialogNode.Count - 1);
        }
        else if (Copy)
        {
            // copying an already existing line
            EditArray()[EditedLine].NextOptionID.Add(CopyInt);
        }

        EditArray()[EditedLine].EditorOpen = true;
    }
Esempio n. 12
0
 public void OnStartNode(DialogNode node)
 {
     if (WalkieTalkieController.Get())
     {
         WalkieTalkieController.Get().OnStartNode(node);
     }
 }
Esempio n. 13
0
    private void SetDialogText(DialogNode dialogTree)
    {
        var responses = dialogTree.responses;

        EnableAllText(); // ensure all the text boxes will be seen

        NPCText.text       = dialogTree.getNPCDialog();
        PlayerTextOne.text = responses.responseOne.getResponse();

        // the next two responses may not exist
        if (responses.responseTwo != null)
        {
            PlayerTextTwo.text = responses.responseTwo.getResponse();
        }
        else
        {
            PlayerTextTwo.enabled = false;
        }

        if (responses.responseThree != null)
        {
            PlayerTextThree.text = responses.responseThree.getResponse();
        }
        else
        {
            PlayerTextThree.enabled = false;
        }
    }
Esempio n. 14
0
    // public

    public DialogNode CreateDialogNode(string _name)
    {
        var node = new DialogNode {
            title = _name,
            text  = _name,
            GUID  = System.Guid.NewGuid().ToString()
        };

        var input_port = GeneratePort(node, Direction.Input, Port.Capacity.Multi);

        input_port.portName = "Input";
        node.inputContainer.Add(input_port);

        var new_branch_button = new Button(clickEvent: () => {
            AddChoicePort(node);
        });

        new_branch_button.text = "New Branch";
        node.titleButtonContainer.Add(new_branch_button);

        node.RefreshExpandedState();
        node.RefreshPorts();
        node.SetPosition(new Rect(position: Vector2.zero, default_node_size));

        return(node);
    }
    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);
    }
Esempio n. 16
0
    public void ShowDialogScreen(DialogNode dialogTree)
    {
        currentNode          = dialogTree; // this is the root
        dialogScreen.enabled = true;

        SetDialogText(dialogTree);
    }
    void AddNewResponse()
    {
        int        pnodeid    = nodeWindows.FindIndex(x => x.WindowId == resToAdd);
        DialogNode parentNode = nodeWindows[pnodeid].Node;

        resToAdd = -1;

        if (_newDKey == null || _newDKey == "" || _newStrKey == null || _newStrKey == "")
        {
            Debug.Log("Error adding response: missing dialog key and/or string id key");
            return;
        }

        ResponseNode newNode = new ResponseNode(_newDKey, _newStrKey);

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

        dm.Graph.Add(newNode);
        dm.Graph.AddLink(parentNode, newNode);

        LanguageController.Instance.AddWord(_newStrKey, _newdialog);
    }
    internal void addOption(string command, DialogNode node)
    {
        List <string> commands = new List <string>();

        commands.Add(command);
        options.Add(new DialogOption(node, commands));
    }
Esempio n. 19
0
        private void addPCPhraseMiClicked(Object sender, EventArgs e)
        {
            if (!(treeListView.SelectedObject != null &&
                  treeListView.SelectedObject is DialogNode))
            {
                showError("Please select some NPC phrase.", "Error");
                return;
            }

            DialogNode     selectedNode    = (DialogNode)treeListView.SelectedObject;
            DialogResponse pcResponse      = new DialogResponse("", "", false);
            Form           addPCPhraseForm = new AddPCPhrase(ref pcResponse);

            addPCPhraseForm.ShowDialog(this);

            if (pcResponse.response.Equals(""))
            {
                return;
            }

            selectedNode.addResponse(pcResponse);
            treeListView.RefreshObject(selectedNode);
            treeListView.Expand(selectedNode);

            if (!changesMade)
            {
                this.Text = this.Text + "*";
            }
            changesMade = true;
        }
Esempio n. 20
0
    DialogNode NodeToDialogNode(Node _node)
    {
        DialogNode dn = CreateInstance <DialogNode>();

        dn.m_dialogdata = _node.data;
        return(dn);
    }
Esempio n. 21
0
    // -----------------------------------------------------------------------------------
    // Begin a Dialog with the player
    // This is called from a external source to start a dialog happening
    public bool BeginDialog(System.Int64 entryPoint, DialogScene dialogScene)
    {
        if (dialogActive)
        {
            return(false);              // We don't want to start a new dialog while one is active.
        }
        if (log)
        {
            UnityEngine.Debug.Log("Begin Dialog " + entryPoint + " scene " + dialogScene);
        }
        scene = dialogScene;
        story.GenerateRandom();
        currentRootNodeID = (int)entryPoint;
        DialogNode node = new DialogNode(entryPoint, db);

        if (log)
        {
            UnityEngine.Debug.Log("Node Valid " + node.isValid);
        }
        if (node.isValid)
        {
            if (miniMap)
            {
                miniMap.SetActive(false);
            }
            player.BeginDialog();
            dialogActive = true;
            dialogPanel.SetActive(true);
            DisplayDialog(node);
        }
        return(true);
    }
Esempio n. 22
0
    public override void OnInspectorGUI()
    {
        DialogNode myTarget = (DialogNode)target;
        Lang       defaultLanguage;

        DrawDefaultInspector();

        // once the variable name has been filled in provide the option to add text to the default language
        if (myTarget.NPCDialogVariable != null && myTarget.NPCDialogVariable != "")
        {
            defaultLanguage = myTarget.localizationController.defaultLanguage;

            // provides the ability to add a variable to the default messages file automatically
            EditorGUILayout.PrefixLabel("Add a new Variable:");
            EditorGUI.indentLevel++;

            defaultText = EditorGUILayout.TextField("Default Lang Text", defaultText);
            EditorGUILayout.HelpBox(
                "The variable with name: " + myTarget.NPCDialogVariable +
                " and the provided text will be added to the default language: " +
                defaultLanguage.language,
                MessageType.Info
                );
            if (GUILayout.Button("Add"))
            {
                LocalizedTextEditor.addVariableToDefaultLanguageFile(
                    myTarget.localizationController,
                    defaultLanguage,
                    myTarget.NPCDialogVariable,
                    defaultText
                    );
            }
        }
    }
Esempio n. 23
0
    private static DialogNode loadNode(XmlElement xmlEl,
                                       ref Conversation conversation,
                                       ref List <DialogResponse> respWithoutChildren,
                                       ref List <DialogResponse> respThatSwitchConv)
    {
        string id        = xmlEl.GetAttribute("id");
        string npcPhrase = xmlEl.GetAttribute("npcPhrase");
        //string voiceFile = xmlEl.GetAttribute("voiceFile");
        DialogNode node = new DialogNode(id, npcPhrase);

        XmlNodeList responsesXNL = xmlEl.ChildNodes;

        for (int j = 0; j < responsesXNL.Count; j++)
        {
            XmlElement       responseXE = (XmlElement)responsesXNL[j];
            string           pcPhrase   = responseXE.GetAttribute("pcPhrase");
            string           link       = responseXE.GetAttribute("link");
            ResponseLinkType linkType   = ResponseLinkType.dialogNode;
            if (responseXE.GetAttribute("linkType").
                Equals("dialogNode"))
            {
                linkType = ResponseLinkType.dialogNode;
            }
            else if (responseXE.GetAttribute("linkType").
                     Equals("endConversation"))
            {
                linkType = ResponseLinkType.endConversation;
            }
            else
            {
                linkType = ResponseLinkType.endAndChangeConversation;
            }

            string switchConv = responseXE.
                                GetAttribute("switchConversation");
            bool onlyAllowOnce = bool.Parse(responseXE.
                                            GetAttribute("onlyAllowOnce"));

            DialogResponse response = new DialogResponse(pcPhrase, link,
                                                         onlyAllowOnce, linkType, switchConv);
            node.addResponse(response);
            if (responseXE.HasChildNodes)
            {
                XmlElement childNode = (XmlElement)responseXE.FirstChild;
                DialogNode dn        = loadNode(childNode, ref conversation,
                                                ref respWithoutChildren, ref respThatSwitchConv);
                response.childNode = dn;
                conversation.addDialogNode(dn);
            }
            else if (linkType == ResponseLinkType.dialogNode)
            {
                respWithoutChildren.Add(response);
            }
            if (linkType == ResponseLinkType.endAndChangeConversation)
            {
                respThatSwitchConv.Add(response);
            }
        }
        return(node);
    }
Esempio n. 24
0
 public void OnSelectNode(DialogNode node)
 {
     if (this.m_CurrentDialog != null)
     {
         this.m_CurrentDialog.OnSelectNode(node);
     }
 }
Esempio n. 25
0
    // -----------------------------------------------------------------------------------
    // A response was selected by either clicking, or one of the dialog buttons.
    public void ResponseClicked(int responseID)
    {
        int resID = responseID;

        if (currentPage > 0)
        {
            resID += (currentPage - 1); // subtract one for the previous entry.
        }
        DialogNode node = null;

        try
        {
            node = responseNodes[resID];
        } catch (System.Exception)
        {
            Debug.LogError(" Could not find " + resID);
        }
        if (scriptFragments.CallFragment("action", node.id) == false)
        {
            EndDialog();
            return;
        }
        List <DialogNode> counterResponses = FilterDialogNodes(responseNodes[resID].GetResponseNodes());

        if (counterResponses.Count == 0)
        {
            EndDialog();
            return;
        }

        DisplayDialog(counterResponses[0]); // always choose the first if there happens to be multiple
    }
Esempio n. 26
0
    //!Tworzy nowy węzeł.
    public void createNode()
    {
        DialogNode node = new DialogNode();

        node.SetPosition(new Rect(200, 200, 200, 200));
        AddElement(node);
    }
Esempio n. 27
0
    private void OnClickRemoveNode(DialogNode node)
    {
        if (connections != null)
        {
            Debug.Log("Clicking on click remove node");

            List <Connections> connectionsToRemove = new List <Connections>();

            Debug.Log(connections.Count);
            for (int i = 0; i < connections.Count; i++)
            {
                if (connections[i].inPoint == node.inPoint || connections[i].outPoint == node.outPoint)
                {
                    connectionsToRemove.Add(connections[i]);

                    connections[i].inPoint.node.inPointNode   = null;
                    connections[i].outPoint.node.outPointNode = null;
                }
            }

            for (int i = 0; i < connectionsToRemove.Count; i++)
            {
                connections.Remove(connectionsToRemove[i]);
            }

            connectionsToRemove = null;
        }

        nodes.Remove(node);

        nodes = RecalculateNodePos();
    }
Esempio n. 28
0
    public static DialogOptionNode Parse(Dictionary <string, object> node)
    {
        long   id      = (long)node["id"];
        string npcName = (string)node["npc"];

        DialogNode[] children = null;
        if (node.ContainsKey("children") && node["children"] != null)
        {
            children = new DialogNode[((List <object>)node["children"]).Count];
        }

        List <object> optionNodes = (List <object>)node["options"];

        DialogOption[] options = new DialogOption[optionNodes.Count];
        for (int i = 0; i < options.Length; i++)
        {
            Dictionary <string, object> optinoNode = (Dictionary <string, object>)optionNodes[i];

            string[] requireItems = null;
            if (optinoNode.ContainsKey("require_items") && optinoNode["require_items"] != null)
            {
                requireItems = ((List <object>)optinoNode["require_items"]).Select(s => (string)s).ToArray();
            }

            string text = (string)optinoNode["text"];

            options[i] = new DialogOption(requireItems, text);
        }

        return(new DialogOptionNode(id, npcName, children, options));
    }
Esempio n. 29
0
        public void OneOfParamIsNull_Should_Throw(
            bool contetIsNull,
            bool nextNodeIsNull
            )
        {
            // Arrange
            TestContent content = new TestContent();
            DialogNode <TestContent> nextDialogNode = DialogNode <TestContent> .CreateNew(content : new TestContent(), dialogOptions : new List <DialogOptionNext <TestContent> > {
            });

            if (contetIsNull)
            {
                content = null;
            }
            if (nextNodeIsNull)
            {
                nextDialogNode = null;
            }

            // Act
            Action action = () => new DialogOptionNext <TestContent>(content: content, nextNode: nextDialogNode);

            // Assert
            Assert.Throws <ArgumentNullException>(action);
        }
Esempio n. 30
0
    public override void OnCreateConnection(NodePort from, NodePort to)
    {
        DialogNode dN  = from.node as DialogNode;
        DialogNode dN2 = to.node as DialogNode;

        System.Type portType = from.ValueType;
        //string tooltip = "";
        //tooltip = portType.PrettyName();
        if (from.IsOutput)
        {
            object obj = from.node.GetValue(from);
            Debug.Log(obj);
            if (from.node is DialogNode && to.node is DialogNode)
            {
                (from.node as DialogNode).SetResponse((int)obj, (to.node as DialogNode).dialogID);
            }
            else if (from.node is DialogEventNode && to.node is DialogNode)
            {
                (from.node as DialogEventNode).dialogEvent.nextDialogID = (to.node as DialogNode).dialogID;
            }
            else if (to.node is DialogEventNode && from.node is DialogNode)
            {
                (from.node as DialogNode).SetEvent((int)obj, (to.node as DialogEventNode).dialogEventID);
            }
        }
        base.OnCreateConnection(from, to);
    }
Esempio n. 31
0
File: Dialog.cs Progetto: mxgmn/GENW
    public override void Load(XmlNode xnode)
    {
        name = MyXml.GetString(xnode, "name");
        isUnique = MyXml.GetBool(xnode, "unique");
        picture = MyXml.GetString(xnode, "picture");

        XmlNode node = xnode.FirstChild;
        while (node != null)
        {
            DialogNode temp = new DialogNode(node);
            nodes.Add(temp.name, temp);
            node = node.NextSibling;
        }
    }
Esempio n. 32
0
    private static DialogNode loadNode(XmlElement xmlEl,
        ref Conversation conversation, 
        ref List<DialogResponse> respWithoutChildren,
        ref List<DialogResponse> respThatSwitchConv)
    {
        string id = xmlEl.GetAttribute("id");
        string npcPhrase = xmlEl.GetAttribute("npcPhrase");
        //string voiceFile = xmlEl.GetAttribute("voiceFile");
        DialogNode node = new DialogNode(id, npcPhrase);

        XmlNodeList responsesXNL = xmlEl.ChildNodes;
        for (int j = 0; j < responsesXNL.Count; j++)
        {
            XmlElement responseXE = (XmlElement)responsesXNL[j];
            string pcPhrase = responseXE.GetAttribute("pcPhrase");
            string link = responseXE.GetAttribute("link");
            ResponseLinkType linkType = ResponseLinkType.dialogNode;
            if (responseXE.GetAttribute("linkType").
                Equals("dialogNode"))
                linkType = ResponseLinkType.dialogNode;
            else if (responseXE.GetAttribute("linkType").
                Equals("endConversation"))
                linkType = ResponseLinkType.endConversation;
            else
                linkType = ResponseLinkType.endAndChangeConversation;

            string switchConv = responseXE.
                GetAttribute("switchConversation");
            bool onlyAllowOnce = bool.Parse(responseXE.
                GetAttribute("onlyAllowOnce"));

            DialogResponse response = new DialogResponse(pcPhrase, link,
                onlyAllowOnce, linkType, switchConv);
            node.addResponse(response);
            if (responseXE.HasChildNodes)
            {
                XmlElement childNode = (XmlElement)responseXE.FirstChild;
                DialogNode dn = loadNode(childNode, ref conversation,
                    ref respWithoutChildren, ref respThatSwitchConv);
                response.childNode = dn;
                conversation.addDialogNode(dn);
            }
            else if (linkType == ResponseLinkType.dialogNode)
                respWithoutChildren.Add(response);
            if (linkType == ResponseLinkType.endAndChangeConversation)
                respThatSwitchConv.Add(response);
        }
        return node;
    }
Esempio n. 33
0
    public void Press(DialogResponse r)
    {
        if (r.action == "FIGHT") World.Instance.battlefield.StartBattle(global);
        else if (r.action == "TRADE") P.barter = global;

        if (dialog.name == "The First Dialog")
        {
            if (r.action == "Boo-Boo") P.party.Add(new LocalObject(LocalShape.Get("Krokar"), "Boo-Boo"));
            else if (r.action == "escherian shard") { }
        }

        /*else if (dialog.name == "Wild Dogs Encounter")
        {
            int threshold = global.Name == "Wild Dogs Large Pack" ? 6 : 1;
            if (r.name == "condition1") nextNode = P.party.Count <= threshold ? "1positive" : "1negative";
            else if (r.name == "condition2") nextNode = P.party.Count <= threshold + 1 ? "2positive" : "2negative";
        }*/

        string nextNode = r.jump;
        bool condition = false;

        int advantage = global.party.Count - P.party.Count;

        if (r.condition == "STRONGER") condition = advantage >= 2;
        else if (r.condition == "SAMESTRENGTH") condition = advantage < 2 && advantage > -2;

        if (r.condition != "") nextNode = nextNode + "_" + condition.ToString();

        if (nextNode != "") dialogNode = dialog.nodes[nextNode];
        else MyGame.Instance.dialog = false;

        MouseTriggerKeyword.Clear("dialog");
    }
Esempio n. 34
0
 public Conversation(String npcName, DialogNode[] dialogNodes): 
     this(npcName)
 {
     rootNodes.AddRange(dialogNodes);
 }
Esempio n. 35
0
    //******************************************************************
    private void Talk(DialogNode d)
    {
        jumped = false;
        //if (d.speaker == Speakers.Player)
        //{
        //    Talking = false;
        //    branching = true;
        //}
        //if (d.speaker == Speakers.NPC)
        //{
        //    branching = false;
        //    Talking = true;
        //}
        //check thos
        if(currentPlayingClip != null)Destroy(currentPlayingClip);
        focusedNode = d;
        //Debug.Log("Talking");
        //RunNodeAction(d, NodeActionType.OnDialogFocused);
        //float WaitTime = 0f;

        //if(d.is_branch)return;
        switch (d.wait)
        {
            case Waits.Audio:
                currentPlayingClip = SoundManager.Play3DSoundWithCallback(gameObject, d.spoken, new SoundCallBack(IncrementNode)); ;
                break;
            case Waits.Time:
                WaitTimer.StartTimer(d.waitTime);
                break;

        }
    }
Esempio n. 36
0
 public void addRootNode(DialogNode dialogNode)
 {
     rootNodes.Add(dialogNode);
     dialog.Add(dialogNode);
 }
Esempio n. 37
0
 public void addDialogNode(DialogNode dialogNode)
 {
     dialog.Add(dialogNode);
 }
Esempio n. 38
0
 public void removeRootNode(DialogNode dialogNode)
 {
     rootNodes.Remove(dialogNode);
     dialog.Remove(dialogNode);
 }
Esempio n. 39
0
 public void removeNode(DialogNode dialogNode)
 {
     dialog.Remove(dialogNode);
 }
Esempio n. 40
0
    public void StartDialog(Dialog d, GlobalObject g)
    {
        dialog = d;
        if (d.isUnique && d.happened) return;

        dialogNode = d.nodes["entry"];
        global = g;
        d.happened = true;
        MyGame.Instance.dialog = true;
    }
Esempio n. 41
0
    public static void PlayConversation(string id)
    {
        if (xmld == null)
        {
            Init();
        }
        string query = string.Format("//*[@id='{0}']", id);
        XmlElement conv = (XmlElement)xmld.SelectSingleNode(query);

        XmlNodeList nodes = conv.SelectNodes("*");

        Conversation convModel = new Conversation();
        convModel.nodes = new Node[nodes.Count];

        for (int i = 0; i < nodes.Count; ++i)
        {
            XmlNode node = nodes[i];
            string name = node.Name;
            Node nodeModel = null;
            if (name == "dialogue-node")
            {
                DialogNode dialogNodeModel = new DialogNode();

                XmlNodeList dialogSpeaks = node.SelectNodes("*");

                dialogNodeModel.speaks = new Speak[node.SelectNodes("speak-player").Count
                     + node.SelectNodes("speak-char").Count];
                int z = 0;

                for (int j = 0; j < dialogSpeaks.Count; ++j)
                {
                    XmlNode speakNode = dialogSpeaks[j];

                    string speakName = speakNode.Name;

                    if (speakName == "speak-player")
                    {
                        Speak speakModel = new Speak();
                        speakModel.text = speakNode.InnerText;
                        dialogNodeModel.speaks[z] = speakModel;
                        ++z;
                    }
                    else if (speakName == "speak-char")
                    {
                        Speak speakModel = new Speak();
                        speakModel.text = speakNode.InnerText;
                        speakModel.isPhone = true;
                        dialogNodeModel.speaks[z] = speakModel;
                        ++z;
                    }
                    else if (speakName == "condition")
                    {
                        Condition conditionModel = new Condition();

                        XmlNodeList activesList = speakNode.SelectNodes("active");
                        conditionModel.actives = new string[activesList.Count];
                        for (int y = 0; y < activesList.Count; y++)
                        {
                            conditionModel.actives[y] = activesList[y].Attributes["flag"].Value;
                        }

                        XmlNodeList inactivesList = speakNode.SelectNodes("inactive");
                        conditionModel.inactives = new string[inactivesList.Count];
                        for (int y = 0; y < inactivesList.Count; y++)
                        {
                            conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value;
                        }

                        dialogNodeModel.speaks[z - 1].condition = conditionModel;
                    }
                    else if (speakName == "child")
                    {
                        dialogNodeModel.nextIndex = Utils.IntParseFast(speakNode.Attributes["nodeindex"].Value);
                    }
                    else if (speakName == "end-conversation")
                    {
                        XmlNode effect = speakNode.SelectSingleNode("effect");
                        if (effect != null)
                        {
                            XmlNodeList effectsList = effect.SelectNodes("*");

                            dialogNodeModel.effects = new EndConvEffect[
                                effectsList.Count - effect.SelectNodes("condition").Count];
                            int m = 0;
                            for (int x = 0; x < effectsList.Count; ++x)
                            {
                                XmlNode effectNode = effectsList[x];

                                string effectNodeName = effectNode.Name;
                                if (effectNodeName == "activate")
                                {
                                    ActivateFlagEffect activateFlageffect = new ActivateFlagEffect();
                                    activateFlageffect.flag = effectNode.Attributes["flag"].Value;
                                    dialogNodeModel.effects[m] = activateFlageffect;
                                    ++m;
                                }
                                else if (effectNodeName == "deactivate")
                                {
                                    DeactivateFlagEffect deactivateFlageffect = new DeactivateFlagEffect();
                                    deactivateFlageffect.flag = effectNode.Attributes["flag"].Value;
                                    dialogNodeModel.effects[m] = deactivateFlageffect;
                                    ++m;
                                }
                                else if (effectNodeName == "increment")
                                {
                                    IncrementFlagEffect eff = new IncrementFlagEffect();
                                    eff.val = Utils.IntParseFast(
                                        effectNode.Attributes["value"].Value);
                                    eff.var = effectNode.Attributes["var"].Value;
                                    dialogNodeModel.effects[m] = eff;
                                    ++m;
                                }
                                else if (effectNodeName == "decrement")
                                {
                                    DecrementFlagEffect eff = new DecrementFlagEffect();
                                    eff.val = Utils.IntParseFast(
                                        effectNode.Attributes["value"].Value);
                                    eff.var = effectNode.Attributes["var"].Value;
                                    dialogNodeModel.effects[m] = eff;
                                    ++m;

                                }
                                else if (effectNodeName == "trigger-conversation")
                                {
                                    TriggerConvEffect eff = new TriggerConvEffect();
                                    eff.idTarget = effectNode.Attributes["idTarget"].Value;
                                    dialogNodeModel.effects[m] = eff;
                                    ++m;
                                }
                                else if (effectNodeName == "trigger-scene")
                                {
                                    TriggerSceneEffect eff = new TriggerSceneEffect();
                                    eff.idTarget = effectNode.Attributes["idTarget"].Value;
                                    dialogNodeModel.effects[m] = eff;
                                    ++m;
                                }
                                else if (effectNodeName == "trigger-cutscene")
                                {
                                    TriggerCutSceneEffect eff = new TriggerCutSceneEffect();
                                    eff.idTarget = effectNode.Attributes["idTarget"].Value;
                                    dialogNodeModel.effects[m] = eff;
                                    ++m;

                                }
                                else if (effectNodeName == "condition")
                                {
                                    Condition conditionModel = new Condition();

                                    XmlNodeList activesList = effectNode.SelectNodes("active");
                                    conditionModel.actives = new string[activesList.Count];
                                    for (int y = 0; y < activesList.Count; y++)
                                    {
                                        conditionModel.actives[y] = activesList[y].Attributes["flag"].Value;
                                    }

                                    XmlNodeList inactivesList = effectNode.SelectNodes("inactive");
                                    conditionModel.inactives = new string[inactivesList.Count];
                                    for (int y = 0; y < inactivesList.Count; y++)
                                    {
                                        conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value;
                                    }

                                    dialogNodeModel.effects[m - 1].condition = conditionModel;
                                }
                            }

                        }
                    }
                    else if (speakName == "effect")
                    {
                        XmlNodeList effectsList = speakNode.SelectNodes("*");

                        dialogNodeModel.effects = new EndConvEffect[
                            effectsList.Count - speakNode.SelectNodes("condition").Count];
                        int m = 0;
                        for (int x = 0; x < effectsList.Count; ++x)
                        {
                            XmlNode effectNode = effectsList[x];

                            string effectNodeName = effectNode.Name;
                            if (effectNodeName == "activate")
                            {
                                ActivateFlagEffect activateFlageffect = new ActivateFlagEffect();
                                activateFlageffect.flag = effectNode.Attributes["flag"].Value;
                                dialogNodeModel.effects[m] = activateFlageffect;
                                ++m;
                            }
                            else if (effectNodeName == "deactivate")
                            {
                                DeactivateFlagEffect deactivateFlageffect = new DeactivateFlagEffect();
                                deactivateFlageffect.flag = effectNode.Attributes["flag"].Value;
                                dialogNodeModel.effects[m] = deactivateFlageffect;
                                ++m;
                            }
                            else if (effectNodeName == "increment")
                            {
                                IncrementFlagEffect eff = new IncrementFlagEffect();
                                eff.val = Utils.IntParseFast(
                                    effectNode.Attributes["value"].Value);
                                eff.var = effectNode.Attributes["var"].Value;
                                dialogNodeModel.effects[m] = eff;
                                ++m;
                            }
                            else if (effectNodeName == "decrement")
                            {
                                DecrementFlagEffect eff = new DecrementFlagEffect();
                                eff.val = Utils.IntParseFast(
                                    effectNode.Attributes["value"].Value);
                                eff.var = effectNode.Attributes["var"].Value;
                                dialogNodeModel.effects[m] = eff;
                                ++m;

                            }
                            else if (effectNodeName == "trigger-conversation")
                            {
                                TriggerConvEffect eff = new TriggerConvEffect();
                                eff.idTarget = effectNode.Attributes["idTarget"].Value;
                                dialogNodeModel.effects[m] = eff;
                                ++m;
                            }
                            else if (effectNodeName == "trigger-scene")
                            {
                                TriggerSceneEffect eff = new TriggerSceneEffect();
                                eff.idTarget = effectNode.Attributes["idTarget"].Value;
                                dialogNodeModel.effects[m] = eff;
                                ++m;
                            }
                            else if (effectNodeName == "trigger-cutscene")
                            {
                                TriggerCutSceneEffect eff = new TriggerCutSceneEffect();
                                eff.idTarget = effectNode.Attributes["idTarget"].Value;
                                dialogNodeModel.effects[m] = eff;
                                ++m;

                            }
                            else if (effectNodeName == "condition")
                            {
                                Condition conditionModel = new Condition();

                                XmlNodeList activesList = effectNode.SelectNodes("active");
                                conditionModel.actives = new string[activesList.Count];
                                for (int y = 0; y < activesList.Count; y++)
                                {
                                    conditionModel.actives[y] = activesList[y].Attributes["flag"].Value;
                                }

                                XmlNodeList inactivesList = effectNode.SelectNodes("inactive");
                                conditionModel.inactives = new string[inactivesList.Count];
                                for (int y = 0; y < inactivesList.Count; y++)
                                {
                                    conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value;
                                }

                                dialogNodeModel.effects[m - 1].condition = conditionModel;
                            }
                        }

                    }
                }

                nodeModel = dialogNodeModel;
            }
            else if (name == "option-node")
            {
                OptionNode optionNodeModel = new OptionNode();
                XmlAttribute randomAttr = node.Attributes["random"];
                if (randomAttr != null && randomAttr.Value == "yes")
                {
                    optionNodeModel.isRandom = true;
                }
                XmlNodeList optionSpeaks = node.SelectNodes("*");

                optionNodeModel.options = new Option[node.SelectNodes("speak-player").Count];
                int z = 0;

                for (int j = 0; j < optionSpeaks.Count; ++j)
                {
                    XmlNode optionNode = optionSpeaks[j];
                    string optionName = optionNode.Name;
                    if (optionName == "speak-player")
                    {
                        Option speakModel = new Option();
                        speakModel.text = optionNode.InnerText;
                        optionNodeModel.options[z] = speakModel;
                        ++z;
                    }
                    else if (optionName == "condition")
                    {
                        Condition conditionModel = new Condition();

                        XmlNodeList activesList = optionNode.SelectNodes("active");
                        conditionModel.actives = new string[activesList.Count];
                        for (int y = 0; y < activesList.Count; y++)
                        {
                            conditionModel.actives[y] = activesList[y].Attributes["flag"].Value;
                        }

                        XmlNodeList inactivesList = optionNode.SelectNodes("inactive");
                        conditionModel.inactives = new string[inactivesList.Count];
                        for (int y = 0; y < inactivesList.Count; y++)
                        {
                            conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value;
                        }

                        optionNodeModel.options[z - 1].condition = conditionModel;
                    }
                    else if (optionName == "child")
                    {
                        optionNodeModel.options[z - 1].nextIndex = Utils.IntParseFast(optionNode.Attributes["nodeindex"].Value);
                    }
                }

                nodeModel = optionNodeModel;
            }

            convModel.nodes[i] = nodeModel;
        }
        convModel.exec();
    }
Esempio n. 42
0
	void drawDialog()
	{
		GUI.Box(boxDimensions, "");
        GUILayout.BeginArea(contentDimensions);

        if (justStarted)
        {
            curNode = conversation.curNode;
            npcPhraseStyle = new GUIStyle("label");
            npcPhraseStyle.wordWrap = true;

            pcPhraseStyle = new GUIStyle("button");
            pcPhraseStyle.wordWrap = true;

            responses = curNode.getResponses();
            responseHeight = 0;

            foreach (DialogResponse response in responses)
            {
                string msg = response.response;
                responseHeight += pcPhraseStyle.CalcHeight(new GUIContent(msg),
                    boxDimensions.width);
                responseHeight += pcPhraseStyle.padding.top * 2;
            }

            availableSpace = boxDimensions.height - responseHeight;
            actualNPCHeight = npcPhraseStyle.CalcHeight(new GUIContent(
                curNode.npcDialog), contentDimensions.width);
            actualNPCHeight += npcPhraseStyle.padding.top +
                npcPhraseStyle.padding.bottom;

            if (availableSpace > maxNpcPhraseHeight)
                availableSpace = maxNpcPhraseHeight;
            ratio = availableSpace / actualNPCHeight;

            if (ratio < 1f)
                npcPhrasePieces = Helper.cutPhrase(availableSpace,
                    contentDimensions.width, curNode.npcDialog, 
                    npcPhraseStyle);
            else
                npcPhrasePieces[0] = curNode.npcDialog;

            justStarted = false;
        }

        if (GUILayout.Button(npcPhrasePieces[curPiece], npcPhraseStyle,
            GUILayout.MaxWidth(contentDimensions.width)))
        {
            curPiece++;
            curPiece = curPiece % npcPhrasePieces.Length;
        }
		
        for (int i = 0; i < responses.Length; i++)
		{
            DialogResponse response = responses[i];
			if (response.enabled)
			{
                if (GUILayout.Button(response.response, pcPhraseStyle, 
                    GUILayout.ExpandWidth(false)))
				{
					if (response.onlyAllowOnce)
						response.enabled = false;
					linkToNode(response);
                    curNode = conversation.curNode;
                    responses = curNode.getResponses();

                    responseHeight = 0;

                    foreach (DialogResponse r in responses)
                    {
                        string msg = r.response;
                        responseHeight += pcPhraseStyle.
                            CalcHeight(new GUIContent(msg), boxDimensions.width);
                        responseHeight += pcPhraseStyle.padding.top * 2;
                    }

                    availableSpace = boxDimensions.height - responseHeight;
                    actualNPCHeight = npcPhraseStyle.
                        CalcHeight(new GUIContent(curNode.npcDialog), 
                        contentDimensions.width);
                    actualNPCHeight += npcPhraseStyle.padding.top +
                        npcPhraseStyle.padding.bottom;

                    if (availableSpace > maxNpcPhraseHeight)
                        availableSpace = maxNpcPhraseHeight;
                    ratio = availableSpace / actualNPCHeight;

                    if (ratio < 1f)
                        npcPhrasePieces = Helper.cutPhrase(availableSpace,
                        contentDimensions.width, curNode.npcDialog, 
                        npcPhraseStyle);
                    else
                        npcPhrasePieces = new string[] { curNode.npcDialog };
                    curPiece = 0;
				}
			}
		}
        GUILayout.EndArea();
	}