Esempio n. 1
0
        /// <summary>
        /// Show the next dialogue
        /// </summary>
        private void OnAdvance()
        {
            bool hasOptions = m_CurrentDialogue.Choices.Count > 0;

            if (revealer.IsRevealing && !revealer.IsAllRevealed())
            {
                Skip();
                return;
            }

            if (hasOptions)
            {
                DisplayChoices(m_CurrentDialogue.Choices);
                return;
            }

            // Hide the option when advancing. // TODO this will be helpful for later when we use index instead of next dialogue
            DialogueChoiceEndAndCloseUI();

            if (!ReachedEndOfDialogue)
            {
                m_CurrentDialogue = m_CurrentDialogue.NextDialogue;
                // TODO grab the actor from the node editor.

                DisplayDialogueLine(m_CurrentDialogue, m_CurrentActor);
                return;
            }

            // if we reached the end of the dialogue then close everything.
            StartCoroutine(DialogueEndedAndCloseDialogueUI());
        }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="nextDialogueLineSo"></param>
 public void ShowNextDialogue(IDialogueLine nextDialogueLineSo)
 {
     // TODO make this work with increment only instead of setting the next dialogue.
     // increment to the next dialogue sequence
     DialogueChoiceEndAndCloseUI(true);
     DisplayDialogueLine(nextDialogueLineSo, m_CurrentActor);
 }
Esempio n. 3
0
        //End dialogue
        void EndDialogue(IDialogueLine dialogue, CharacterSO actorSo)
        {
            // depending on the dialogue that ended, do something. The dialogue type can be different from the current dialogue type
            switch (dialogue.DialogueType)
            {
            case DialogueType.StartDialogue:
                // Check the validity of the step
                CheckTaskValidity();
                break;

            case DialogueType.WinDialogue:
                // After playing the win dialogue close Dialogue and end step

                break;

            case DialogueType.LoseDialogue:
                // closeDialogue
                // replay start Dialogue if the lose Dialogue ended
                if (_currentTask.StoryBeforeTask != null)
                {
                    _currentStory = _currentTask.StoryBeforeTask;
                }
                break;

            case DialogueType.DefaultDialogue:
                // close Dialogue
                // nothing happens if it's the default dialogue
                break;
            }
        }
Esempio n. 4
0
 void EndDialogue(IDialogueLine dialogue, CharacterSO actorSo)
 {
     // depending on the dialogue that ended, do something
     switch (dialogue.DialogueType)
     {
     case DialogueType.WinDialogue:
         EndTask();
         break;
     }
 }
Esempio n. 5
0
 public void SetDialogue(IDialogueLine dialogueLine, CharacterSO character)
 {
     // TODO see class LocalizeStringEvent for the reference variables
     sentence.StringReference = dialogueLine.Sentence;
     // User can optionally show the name of the character.
     if (character)
     {
         actorName.StringReference = character.CharacterName;
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Displays a line of dialogue in the UI, by requesting it to the <c>DialogueManager</c>.
        /// This function is also called by <c>DialogueBehaviour</c> from clips on Timeline during cutscenes.
        /// </summary>
        /// <param name="dialogueLine"></param>
        /// <param name="character"></param>
        public void DisplayDialogueLine(IDialogueLine dialogueLine, CharacterSO character)
        {
            Debug.Log(dialogueLine);
            Debug.Log(character);
            if (openUIDialogueEvent != null)
            {
                // send event out before the dialogue starts
                // InitEvents();
                // CallEvents(true);

                openUIDialogueEvent.RaiseEvent(dialogueLine, character);
            }
            ToggleContinueBtn(false);

            // Call event when the dialogue begins
            if (dialogueEvent != null && dialogueLine.DialogueEvent.EventName != String.Empty)
            {
                dialogueEvent.RaiseEvent(dialogueLine.DialogueEvent.EventName, dialogueLine.DialogueEvent.Value);
            }

            m_CurrentActor = character;

            SetActiveDialogue(dialogueLine);
        }
Esempio n. 7
0
 private void SetActiveDialogue(IDialogueLine dialogue)
 {
     m_CurrentDialogue = dialogue;
 }
Esempio n. 8
0
 public void OpenUIDialogue(IDialogueLine dialogueLine, CharacterSO character)
 {
     dialogueController.SetDialogue(dialogueLine, character);
     dialogueController.gameObject.SetActive(true);
 }
Esempio n. 9
0
            /// <summary>
            /// Grab the next dialogue
            /// nextDialogue = ConvertRow(TableDatabase.Get.GetRow("dialogues", nextDialogueID));
            /// Set the dialogue options associated to the dialogue.
            /// CheckDialogueOptions(nextDialogue);
            /// so input has a connection member that consists of three values
            /// node -> reference to the other node.
            /// output -> reference to the key that consist of the value
            /// so in order to grab the data go to the node
            /// fetch the data
            /// if it is an option take options[$`optionOut-key`] and then the value
            /// if it is a dialogue take data["dialogueId"] -> can be Number.MAX_SAFE_INTEGER
            /// so output has a connection member that consists of three values
            /// node -> reference to the other node.
            /// input -> reference to the key that consist of the value
            /// so in order to grab the data go to the node
            /// fetch the data
            /// if it is an option take options[$`optionOut-key`] and then the value
            /// if it is a dialogue take data["dialogueId"] -> can be Number.MAX_SAFE_INTEGER
            /// </summary>
            /// <param name="currentDialogue"></param>
            /// <param name="story"></param>
            /// <param name="node"></param>
            /// <param name="nodes"></param>
            private static void ParseNextNodeData(StorySO story, IDialogueLine currentDialogue, JObject node, JObject nodes)
            {
                if (node["data"] == null)
                {
                    return;
                }

                var data = node["data"].ToObject <JObject>();

                // check what is inside the node
                if (data != null)
                {
                    // get the outputs
                    var outputs = node["outputs"].ToObject <JObject>();

                    // loop through the outputs
                    // Outputs can be
                    // Dialogue to dialogue
                    // option to dialogue
                    foreach (var outputToken in outputs)
                    {
                        var output      = outputToken.Value.ToObject <JObject>();
                        var connections = output["connections"].ToArray();
                        var emptyObj    = new JObject();

                        string  nodeId;
                        JObject otherNode;
                        JObject otherData;
                        if (outputToken.Key.Contains("Exec") && connections.Length > 0)
                        {
                            foreach (var con in connections)
                            {
                                // grab the other node id.
                                nodeId = con["node"]?.ToObject <int>().ToString() ?? String.Empty;
                                // grab the other node object.
                                otherNode = nodeId != String.Empty ? nodes[nodeId].Value <JObject>() : emptyObj;
                                // grab the data from the other node.
                                otherData = otherNode["data"]?.ToObject <JObject>() ?? emptyObj;

                                if (currentDialogue != null)
                                {
                                    // fetch the event name
                                    var eventId   = otherData["eventId"]?.ToObject <uint>() ?? UInt32.MaxValue;
                                    var eventName = "";
                                    if (eventId != UInt32.MaxValue)
                                    {
                                        var row = TableDatabase.Get.GetRow("events", eventId);

                                        // validate the data
                                        if (row.Fields.Count > 0)
                                        {
                                            var field = row.Find("name");
                                            if (field != null)
                                            {
                                                eventName = (string)field.Data;
                                            }
                                        }
                                        // fetch the parameters
                                        //  TODO mark event value as dynamic to support multiple parameters
                                        JObject events = otherData["events"]?.ToObject <JObject>() ?? emptyObj;
                                        foreach (var @event in events)
                                        {
                                            // int value = @event.Value["value"]["value"].ToObject<int>();
                                            currentDialogue.DialogueEvent = new DialogueEventSO(eventName, story);
                                        }
                                    }
                                }
                            }
                        }

                        // see if we have a connection
                        // if (connections.Length == 0)
                        // continue;

                        // See if we are dealing with an option
                        bool containsOption = outputToken.Key.Contains("option");

                        var connection = connections.Length > 0 ? connections[0] : emptyObj;
                        // grab the other node id.
                        nodeId = connection["node"]?.ToObject <int>().ToString() ?? String.Empty;
                        // grab the other node object.
                        otherNode = nodeId != String.Empty ? nodes[nodeId].Value <JObject>() : emptyObj;
                        // grab the data from the other node.
                        otherData = otherNode["data"]?.ToObject <JObject>() ?? emptyObj;

                        if (currentDialogue != null)
                        {
                            // Fetch the other dialogueId
                            var nextId = otherData["dialogueId"]?.ToObject <uint>() ?? UInt32.MaxValue;

                            // if this node does not consist of any choices
                            // go this way
                            if (!containsOption)
                            {
                                // validate the data
                                currentDialogue.NextDialogue = nextId != UInt32.MaxValue ?
                                                               DialogueLine.ConvertRow(TableDatabase.Get.GetRow("dialogues", nextId),
                                                                                       story.overrideTable ? story.collection : LocalizationEditorSettings.GetStringTableCollection("Dialogues"))
                                                                        : null;

                                // Debug.Log(" Next: " + currentDialogue.NextDialogue);

                                // now we have the next id check if we have a node that comes after.
                                ParseNextNodeData(story, currentDialogue.NextDialogue, otherNode, nodes);
                            }
                            else
                            {
                                // grab the choice id from the current node.
                                var optionId = data["options"][outputToken.Key]["value"].ToObject <uint>();

                                // Grab the choice
                                DialogueChoiceSO choice = DialogueChoiceSO.ConvertRow(TableDatabase.Get.GetRow("dialogueOptions", optionId),
                                                                                      story.overrideDialogueOptionsTable ? story.dialogueOptionsCollection : LocalizationEditorSettings.GetStringTableCollection("DialogueOptions")
                                                                                      );

                                // find the next dialogue of this choice.
                                choice.NextDialogue = nextId != UInt32.MaxValue ?
                                                      DialogueLine.ConvertRow(TableDatabase.Get.GetRow("dialogues", nextId),
                                                                              story.overrideTable ? story.collection : LocalizationEditorSettings.GetStringTableCollection("Dialogues"))
                                                                        : null;

                                // Debug.Log(" Choice: " + choice);

                                // add the choices to the currentDialogue
                                currentDialogue.Choices.Add(choice);

                                // Set the nextDialogue to null because we are dealing with a choice
                                currentDialogue.NextDialogue = null;

                                // Find the next dialogue for the choice
                                ParseNextNodeData(story, choice.NextDialogue, otherNode, nodes);
                            }
                        }
                    }
                }
            }