public void RaiseEvent(DialogueDataSO dialogue)
 {
     if (OnEventRaised != null)
     {
         OnEventRaised.Invoke(dialogue);
     }
 }
    private VisualElement CreateDialoguePreviewWithBranching(DialogueDataSO dialogueDataSO)
    {
        VisualElement dialoguePreviewVE = new VisualElement();

        dialoguePreviewVE.name = "Dialogue";

        /*foreach (LocalizedString localizedString in dialogueDataSO.DialogueLines)
         * {
         *      Label dialogueLine = new Label();
         *      dialogueLine.name = dialogueDataSO.DialogueType.ToString();
         *      dialogueLine.text = localizedString.GetLocalizedStringImmediateSafe();
         *      dialoguePreviewVE.Add(dialogueLine);
         * }
         * if (dialogueDataSO.Choices != null)
         * {
         *      VisualElement choicesVE = new VisualElement();
         *      choicesVE.name = "Choices";
         *      for (int i = 0; i < dialogueDataSO.Choices.Count; i++)
         *      {
         *              VisualElement choiceVE = new VisualElement();
         *              Choice choice = dialogueDataSO.Choices[i];
         *              Button dialogueButton = new Button();
         *              dialogueButton.name = "Button" + _idQuestlineSelected;
         *              dialogueButton.text = choice.Response.GetLocalizedStringImmediateSafe();
         *              choiceVE.Add(dialogueButton);
         *              if (choice.NextDialogue != null)
         *                      choiceVE.Add(CreateDialoguePreviewWithBranching(choice.NextDialogue));
         *
         *              choiceVE.name = "Choice";
         *              choicesVE.Add(choiceVE);
         *      }
         *      dialoguePreviewVE.Add(choicesVE);
         * }*/
        return(dialoguePreviewVE);
    }
Example #3
0
    private VisualElement CreateDialoguePreviewWithBranching(DialogueDataSO dialogueDataSO)
    {
        VisualElement dialoguePreviewVE = new VisualElement();

        DialogueDataSO currentDialogue = dialogueDataSO;

        foreach (LocalizedString localizedString in currentDialogue.DialogueLines)
        {
            Label dialogueLine = new Label();
            dialogueLine.text = localizedString.GetLocalizedStringImmediateSafe();
            dialoguePreviewVE.Add(dialogueLine);
        }
        if (currentDialogue.Choices != null)
        {
            foreach (Choice choice in currentDialogue.Choices)
            {
                Button dialogueButton = new Button();
                dialogueButton.text = choice.Response.GetLocalizedStringImmediateSafe();
                dialoguePreviewVE.Add(dialogueButton);
                dialoguePreviewVE.Add(CreateDialoguePreviewWithBranching(choice.NextDialogue));
            }
        }


        return(dialoguePreviewVE);
    }
Example #4
0
 void PlayDefaultDialogue()
 {
     if (_defaultDialogue != null)
     {
         _currentDialogue = _defaultDialogue;
         StartDialogue();
     }
 }
    private void LoadAllQuestsData()
    {
        //Load all questlines
        FindAllSOByType(out QuestlineSO[] questLineSOs);
        RefreshListView(out ListView allQuestlinesListView, "questlines-list", questLineSOs);
        ClearElements(SelectionType.Questline);
        allQuestlinesListView.onSelectionChange += (questlineEnumerable) =>
        {
            _currentSelectedQuestLine = GetDataFromListViewItem <QuestlineSO>(questlineEnumerable);
            ClearElements(SelectionType.Questline);
            _idQuestlineSelected = allQuestlinesListView.selectedIndex;

            if (_currentSelectedQuestLine.Quests != null)
            {
                RefreshListView(out ListView allQuestsListView, "quests-list", _currentSelectedQuestLine.Quests.ToArray());

                allQuestsListView.onSelectionChange += (questEnumerable) =>
                {
                    _idQuestSelected = allQuestsListView.selectedIndex;

                    _currentSeletedQuest = GetDataFromListViewItem <QuestSO>(questEnumerable);
                    ClearElements(SelectionType.Quest);
                    if (_currentSeletedQuest != null && _currentSeletedQuest.Steps != null)
                    {
                        RefreshListView(out ListView allStepsListView, "steps-list", _currentSeletedQuest.Steps.ToArray());

                        SetUpQuestPreview(_currentSeletedQuest);

                        allStepsListView.onSelectionChange += (stepEnumerable) =>
                        {
                            _idStepSelected      = allStepsListView.selectedIndex;
                            _currentSelectedStep = GetDataFromListViewItem <StepSO>(stepEnumerable);
                            DisplayAllProperties(_currentSelectedStep, "step-info-scroll");
                            ClearElements(SelectionType.Step);
                            //Find all DialogueDataSOs in the same folder of the StepSO
                            FindAllDialogueInStep(_currentSelectedStep, out DialogueDataSO[] dialogueDataSOs);
                            if (dialogueDataSOs != null)
                            {
                                RefreshListView(out ListView dialoguesListView, "dialogues-list", dialogueDataSOs);

                                dialoguesListView.onSelectionChange += (dialogueEnumerable) =>
                                {
                                    DialogueDataSO dialogueData = GetDataFromListViewItem <DialogueDataSO>(dialogueEnumerable);
                                    DisplayAllProperties(dialogueData, "dialogue-info-scroll");
                                };
                            }
                            VisualElement DialogueList = rootVisualElement.Q <VisualElement>("dialogues-list");
                            SetAddDialogueButtonsForStep(out VisualElement ButtonsPanel);
                            //DialogueList.Q<VisualElement>("buttons-panel").Clear();
                            DialogueList.Add(ButtonsPanel);
                        };
                    }
                };
            }
        };
    }
    private void LoadAndInitStepUXML(StepSO step)
    {
        //Clear actor conversations area
        ScrollView actorConversationsVE = rootVisualElement.Q <ScrollView>("actor-conversations");
        // Import UXML
        var           stepVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Scripts/Quests/Editor/StepDetail.uxml");
        VisualElement stepVE         = stepVisualTree.CloneTree();
        VisualElement dialogueAreaVE = stepVE.Q <VisualElement>("dialogue-area");

        //Title
        if (step != null)
        {
            stepVE.Q <Label>("step-title-label").text = "Step" + step.name[1];
        }

        //IsDone
        Toggle isDoneToggle = stepVE.Q <Toggle>("step-done-toggle");

        isDoneToggle.value = step.IsDone;
        isDoneToggle.SetEnabled(false);

        DialogueDataSO dialogueToPreview = default;

        dialogueToPreview = step.StepToDialogue();
        if (dialogueToPreview != null)
        {
            //setPreview Actor for each step
            if (step.Actor != null)
            {
                Image actorPreview = LoadActorImage(step.Actor.name);
                //Add Image
                VisualElement preview = stepVE.Q <VisualElement>("actor-preview");
                preview.Add(actorPreview);
            }
            VisualElement VE = CreateDialoguePreviewWithBranching(dialogueToPreview);
            dialogueAreaVE.Add(VE);
        }

        //Type (Check Item etc)
        if (step.Type == StepType.Dialogue)
        {
            VisualElement itemValidateVE = stepVE.Q <VisualElement>("item-validate");
            itemValidateVE.style.display = DisplayStyle.None;
        }
        else
        {
            stepVE.Q <Label>("step-type").text = step.Type + ":";
            if (step.Item != null)
            {
                stepVE.Q <Label>("item-to-validate").text = step.Item.ToString();
            }
        }

        actorConversationsVE.Add(stepVE);
    }
    private void LoadAllQuestsData()
    {
        Debug.Log("LoadAllQuestsData");
        //Load all questlines
        FindAllSOByType(out QuestlineSO[] questLineSOs);
        RefreshListView(out ListView allQuestlinesListView, "questlines-list", questLineSOs);

        allQuestlinesListView.onSelectionChange += (questlineEnumerable) =>
        {
            selectedQuestLine = GetDataFromListViewItem <QuestlineSO>(questlineEnumerable);
            ClearElements(selectionType.Questline);
            idQuestlineSelected = allQuestlinesListView.selectedIndex;

            if (selectedQuestLine.Quests != null)
            {
                RefreshListView(out ListView allQuestsListView, "quests-list", selectedQuestLine.Quests.ToArray());



                allQuestsListView.onSelectionChange += (questEnumerable) =>
                {
                    idQuestSelected = allQuestsListView.selectedIndex;

                    currentSeletedQuest = GetDataFromListViewItem <QuestSO>(questEnumerable);
                    ClearElements(selectionType.Quest);
                    if (currentSeletedQuest != null && currentSeletedQuest.Steps != null)
                    {
                        RefreshListView(out ListView allStepsListView, "steps-list", currentSeletedQuest.Steps.ToArray());

                        SetUpQuestPreview(currentSeletedQuest);

                        allStepsListView.onSelectionChange += (stepEnumerable) =>
                        {
                            StepSO step = GetDataFromListViewItem <StepSO>(stepEnumerable);
                            DisplayAllProperties(step, "step-info-scroll");
                            ClearElements(selectionType.Step);
                            //Find all DialogueDataSOs in the same folder of the StepSO
                            FindAllDialogueInStep(step, out DialogueDataSO[] dialogueDataSOs);
                            if (dialogueDataSOs != null)
                            {
                                RefreshListView(out ListView dialoguesListView, "dialogues-list", dialogueDataSOs);

                                dialoguesListView.onSelectionChange += (dialogueEnumerable) =>
                                {
                                    DialogueDataSO dialogueData = GetDataFromListViewItem <DialogueDataSO>(dialogueEnumerable);

                                    DisplayAllProperties(dialogueData, "dialogue-info-scroll");
                                };
                            }
                        };
                    }
                };
            }
        };
    }
Example #8
0
 void PlayLoseDialogue()
 {
     if (_questData != null)
     {
         DialogueDataSO displayDialogue = _questData.InteractWithCharacter(_actor, true, false);
         if (displayDialogue != null)
         {
             _currentDialogue = displayDialogue;
             StartDialogue();
         }
     }
 }
Example #9
0
 void PlayWinDialogue()
 {
     if (_questAnchor != null)
     {
         DialogueDataSO displayDialogue = _questAnchor.InteractWithCharacter(_actor, true, true);
         if (displayDialogue != null)
         {
             _currentDialogue = displayDialogue;
             StartDialogue();
         }
     }
 }
Example #10
0
 public DialogueDataSO(DialogueDataSO dialogue)
 {
     _actor              = dialogue.Actor;
     _dialogueLines      = new List <LocalizedString>(dialogue.DialogueLines);
     _choices            = new List <Choice>();
     _endOfDialogueEvent = dialogue.EndOfDialogueEvent;
     if (dialogue.Choices != null)
     {
         for (int i = 0; i < dialogue.Choices.Count; i++)
         {
             _choices.Add(new Choice(dialogue.Choices[i]));
         }
     }
     _dialogueType = dialogue.DialogueType;
 }
Example #11
0
    //start a dialogue when interaction
    //some Steps need to be instantanious. And do not need the interact button.
    //when interaction again, restart same dialogue.
    public void InteractWithCharacter()
    {
        DialogueDataSO displayDialogue = _questData.InteractWithCharacter(_actor, false, false);

        //Debug.Log("dialogue " + displayDialogue + "actor" + _actor);
        if (displayDialogue != null)
        {
            _currentDialogue = displayDialogue;
            StartDialogue();
        }
        else
        {
            PlayDefaultDialogue();
        }
    }
 public DialogueDataSO(DialogueDataSO dialogue)
 {
     /*	_actor = dialogue.Actor;
      *      _dialogueLines = new List<LocalizedString>(dialogue.DialogueLines);
      *      _choices = new List<Choice>();
      *      _endOfDialogueEvent = dialogue.EndOfDialogueEvent;
      *      if (dialogue.Choices != null)
      *              for (int i = 0; i < dialogue.Choices.Count; i++)
      *              {
      *
      *                      _choices.Add(new Choice(dialogue.Choices[i]));
      *
      *              }
      *      _dialogueType = dialogue.DialogueType;
      */
 }
Example #13
0
    void EndDialogue(DialogueDataSO dialogue)
    {
        //depending on the dialogue that ended, do something
        switch (dialogue.DialogueType)
        {
        case DialogueType.winDialogue:
            EndStep();
            break;

        case DialogueType.startDialogue:
            CheckStepValidity();
            break;

        default:
            break;
        }
    }
    private void LoadAndInitStartDialogueLineUXML(DialogueDataSO startDialogue, VisualElement parent)
    {
        // Import UXML
        var dialogueVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Scripts/Quests/Editor/DialogueLine.uxml");

        // Set line
        foreach (LocalizedString line in startDialogue.DialogueLines)
        {
            VisualElement dialogueVE = dialogueVisualTree.CloneTree();

            Label leftLineLabel = dialogueVE.Q <Label>("left-line-label");
            leftLineLabel.text = line.GetLocalizedStringImmediateSafe();

            Label rightLineLabel = dialogueVE.Q <Label>("right-line-label");
            rightLineLabel.style.display = DisplayStyle.None;

            // Set options
            VisualElement buttonArea = dialogueVE.Q <VisualElement>("buttons");
            if (startDialogue.Choices.Count == 0)
            {
                buttonArea.style.display = DisplayStyle.None;
            }
            else if (startDialogue.Choices.Count <= 2)
            {
                for (int i = 0; i < 2; i++)
                {
                    Button btn = buttonArea.Q <Button>($"btn-{i}");
                    if (i < startDialogue.Choices.Count)
                    {
                        btn.text = startDialogue.Choices[i].Response.GetLocalizedStringImmediateSafe();
                    }
                    else
                    {
                        btn.style.display = DisplayStyle.None;
                    }
                }
            }
            parent.Add(dialogueVE);
        }
    }
    private void LoadAndInitOptionsDialogueLineUXML(DialogueDataSO completeDialogue, DialogueDataSO incompleteDialogue, VisualElement parent)
    {
        // Import UXML
        var           dialogueVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Scripts/Quests/Editor/DialogueLine.uxml");
        VisualElement dialogueVE         = dialogueVisualTree.CloneTree();

        // Set line
        Label leftLineLabel  = dialogueVE.Q <Label>("left-line-label");
        Label rightLineLabel = dialogueVE.Q <Label>("right-line-label");


        //	leftLineLabel.text = completeDialogue.DialogueLines[0].GetLocalizedStringImmediateSafe();
        //	if (incompleteDialogue != null)
        //rightLineLabel.text = incompleteDialogue.DialogueLines[0].GetLocalizedStringImmediateSafe();

        // hide options
        VisualElement buttonArea = dialogueVE.Q <VisualElement>("buttons");

        buttonArea.style.display = DisplayStyle.None;

        parent.Add(dialogueVE);
    }
    private void AddDialogueBeforeStep()
    {
        DialogueDataSO asset       = ScriptableObject.CreateInstance <DialogueDataSO>();
        int            questlineId = 0;

        questlineId = _currentSelectedQuestLine.IdQuestline;
        int questId = 0;

        questId = _currentSeletedQuest.IdQuest;
        int stepId = 0;

        stepId = _currentSeletedQuest.Steps.FindIndex(o => o == _currentSelectedStep) + 1;
        AssetDatabase.CreateAsset(asset, "Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId + "/Step" + stepId + "/SD-S" + stepId + "-Q" + questId + "-QL" + questlineId + ".asset");

        EditorUtility.SetDirty(asset);
        EditorUtility.SetDirty(_currentSeletedQuest);
        AssetDatabase.SaveAssets();
        _currentSelectedStep.DialogueBeforeStep = asset;
        asset.DialogueType = DialogueType.StartDialogue;
        //	asset.CreateLine();
        rootVisualElement.Q <VisualElement>("steps-list").Q <ListView>().SetSelection(_idStepSelected);
    }
Example #17
0
 private void OnDialogueEnd(DialogueDataSO dialogue)
 {
     _isDialogueActive = false;
 }
Example #18
0
 public void SetNextDialogue(DialogueDataSO dialogue)
 {
     _nextDialogue = dialogue;
 }
Example #19
0
 public Choice(Choice choice)
 {
     _response     = choice.Response;
     _nextDialogue = choice.NextDialogue;
     _actionType   = ActionType;
 }
 private void LoadAndInitStartDialogueLineUXML(DialogueDataSO startDialogue, VisualElement parent)
 {
 }
 private void OnDialogueStart(DialogueDataSO dialogue)
 {
     _isDialogueActive = true;
 }
 void RemoveDialogue(DialogueDataSO dialogueToRemove)
 {
     //	dialogueToRemove.RemoveLineFromSharedTable();
     AssetDatabase.DeleteAsset(dialogueToRemove.GetPath());
 }