void ThanksForPlayingDialogue()
    {
        playerThanked = true;

        // Open panels
        NamePanel.SetActive(true);
        DialoguePanel.SetActive(true);

        activeSpeaker = DialogueSource.Business_Man;
        NPC_PortraitPanel.SetActive(false);
        PC_PortraitPanel.SetActive(true);

        string nameString = DialogueSource.Business_Man.ToString();

        nameString = nameString.Replace('_', ' ');
        NamePanel.GetComponentInChildren <Text>().text = nameString;

        string textToType = "Thanks for playing!";

        if (typingText)
        {
            StopCoroutine(typeRoutine);
            boxText.text = textToType;
            typingText   = false;
        }
        else
        {
            typeRoutine = TypeText(textToType);
            StartCoroutine(typeRoutine);
        }
    }
Esempio n. 2
0
    public DialogueSource ActivateNearestTalkable(Vector3 position, float talkingRange)
    {
        DialogueSource bestTarget = null;
        // Defines the maximum range at which a talkable may be talked to.
        float closestDistance = talkingRange;

        foreach (DialogueSource talkable in _talkables)
        {
            Vector3 directionToTarget = talkable.transform.root.position - position;
            //Debug.Log(directionToTarget);
            float squaredDistanceToTarget = directionToTarget.sqrMagnitude;
            if (squaredDistanceToTarget < closestDistance)
            {
                closestDistance = squaredDistanceToTarget;
                bestTarget      = talkable;
            }
        }
        if (bestTarget == null)
        {
            _currentlyActivatedTalkable?.SetTalkable(false);
            _currentlyActivatedTalkable = null;
        }
        else
        {
            if (_currentlyActivatedTalkable != bestTarget)
            {
                _currentlyActivatedTalkable?.SetTalkable(false);
            }
            bestTarget.SetTalkable(true);
            _currentlyActivatedTalkable = bestTarget;
        }
        // Uncomment to see where the selected talkable is in relation to the given position
        //Debug.Log($"Talkables count: {_talkables.Count}, Best target distance: {closestDistance}, Current Talkable: {_currentlyActivatedTalkable?.transform?.position}");
        return(_currentlyActivatedTalkable);
    }
Esempio n. 3
0
    private void OnShowClosedCaption(DialogueSource source, Dialogue.Snippet snippet)
    {
        if (source != null)
        {
            Debug.Log("Source: " + source.Name);
        }

        Debug.Log("Closed Caption: " + snippet.Text);
    }
Esempio n. 4
0
    public void Clear()
    {
        if (OnClearText != null)
        {
            OnClearText.Invoke();
        }

        lastSource = null;
    }
Esempio n. 5
0
    public void OnShowText(DialogueSource source, Dialogue.Snippet snippet)
    {
        if (source != null)
        {
            Label.color = source.SubtitleColor;
        }

        Label.SetText(snippet.Render(source));
        Label.gameObject.SetActive(true);
    }
Esempio n. 6
0
 void Speak()
 {
     if (_inSpeechCooldown)
     {
         return;
     }
     if (!IsTalking)
     {
         _currentBubble = _dialogue.ActivateNearestTalkable(transform.position, TalkingRange);
         if (_currentBubble != null && Input.GetButtonUp(InputConstants.SUBMIT_AXIS))
         {
             IsTalking = true;
             _currentBubble.InitiateDialogue(this);
         }
     }
 }
Esempio n. 7
0
    /// <summary>
    /// Update the current source and color (if applicable).
    /// </summary>
    private DialogueSource SetSource(DialogueSource source)
    {
        DialogueSource newSource = null;

        if (source == null)
        {
            source = DefaultSource;
        }

        if (lastSource != source)
        {
            lastSource = source;
            newSource  = source;
        }

        return(newSource);
    }
Esempio n. 8
0
        /// <summary>
        /// Render the snippet with the given source if present.
        /// </summary>
        public string Render(DialogueSource source)
        {
            var t = Text;

            if (ClosedCaption)
            {
                t = "[" + t + "]";
            }
            else
            {
                t = "\"" + t + "\"";
            }

            if (source != null && source.Name != "")
            {
                t = source.Name + ": " + t;
            }

            return(t);
        }
    void CycleEndDialogue()
    {
        if (playerThanked)
        {
            //If we are running in a standalone build of the game
#if UNITY_STANDALONE
            //Quit the application
            Application.Quit();
#endif

            //If we are running in the editor
#if UNITY_EDITOR
            //Stop playing the scene
            UnityEditor.EditorApplication.isPlaying = false;
#endif
            return;
        }


        if (peopleSpokenTo.Count < 1)
        {
            playerThanked = true;
            activeSpeaker = DialogueSource.Business_Man;
            NPC_PortraitPanel.SetActive(false);
            PC_PortraitPanel.SetActive(true);

            string nameString = DialogueSource.Business_Man.ToString();
            nameString = nameString.Replace('_', ' ');
            NamePanel.GetComponentInChildren <Text>().text = nameString;

            string textToType = "Wow... No one came to my funeral. Maybe I'll change my ways in the next playthrough...";

            if (typingText)
            {
                StopCoroutine(typeRoutine);
                boxText.text = textToType;
                typingText   = false;
            }
            else
            {
                typeRoutine = TypeText(textToType);
                StartCoroutine(typeRoutine);
            }
        }
        else
        {
            if (dialogueLineIndex < peopleSpokenTo.Count)
            {
                activeSpeaker = peopleSpokenTo[dialogueLineIndex].source;
                NPC_PortraitPanel.SetActive(true);
                NPC_Image.sprite = peopleSpokenTo[dialogueLineIndex].characterPortrait;
                PC_PortraitPanel.SetActive(false);

                string nameString = peopleSpokenTo[dialogueLineIndex].source.ToString();
                nameString = nameString.Replace('_', ' ');
                NamePanel.GetComponentInChildren <Text>().text = nameString;

                string textToType = peopleSpokenTo[dialogueLineIndex].line;

                if (typingText)
                {
                    StopCoroutine(typeRoutine);
                    boxText.text = textToType;
                    typingText   = false;
                    dialogueLineIndex++;
                }
                else
                {
                    typeRoutine = TypeText(textToType);
                    StartCoroutine(typeRoutine);
                }
            }
            else
            {
                inFinalDialogue = false;
                ThanksForPlayingDialogue();
                //GameManager.Instance.RestartGame();
                peopleSpokenTo = new List <DialogueData.DialoguePiece>();
            }
        }
    }
    void CycleDialogue()
    {
        if (dialogueLineIndex < activeDialogue.dialogueLines.Count)
        {
            activeSpeaker = activeDialogue.dialogueLines[dialogueLineIndex].source;
            if (activeDialogue.dialogueLines[dialogueLineIndex].source != DialogueSource.Business_Man)
            {
                PC_PortraitPanel.SetActive(false);
                NPC_PortraitPanel.SetActive(true);
                NPC_Image.sprite = activeDialogue.dialogueLines[dialogueLineIndex].characterPortrait;
            }
            else
            {
                NPC_PortraitPanel.SetActive(false);
                PC_PortraitPanel.SetActive(true);
            }
            string nameString = activeDialogue.dialogueLines[dialogueLineIndex].source.ToString();
            nameString = nameString.Replace('_', ' ');
            NamePanel.GetComponentInChildren <Text>().text = nameString;
            string textToType = activeDialogue.dialogueLines[dialogueLineIndex].line;

            if (typingText)
            {
                StopCoroutine(typeRoutine);
                boxText.text = textToType;
                typingText   = false;
                dialogueLineIndex++;
            }
            else
            {
                typeRoutine = TypeText(textToType);
                StartCoroutine(typeRoutine);
            }
        }
        else
        {
            // Out of dialogue in sequence, check if there are choices to be made
            // Asserts that there is text for player choice
            if (typingText)
            {
                StopCoroutine(typeRoutine);
                boxText.text = activeDialogue.playerChoice;
                typingText   = false;
            }
            else
            {
                if (activeDialogue.isRoot)
                {
                    // TODO, set dialogue source images

                    typeRoutine = TypeText(activeDialogue.playerChoice);
                    StartCoroutine(typeRoutine);
                    // TODO, make choice buttons
                    OffsetButtonsOnChoice();
                    for (int iChoice = 0; iChoice < activeDialogue.choices.Count; ++iChoice)
                    {
                        optionButtons[iChoice].GetComponentInChildren <Text>().text = activeDialogue.choices[iChoice].playerChoice;
                        DialogueData choiceData = activeDialogue.choices[iChoice];
                        optionButtons[iChoice].onClick.AddListener(delegate {
                            ChoiceAction(choiceData);
                        });
                        optionButtons[iChoice].gameObject.SetActive(true);
                    }
                }
                else
                {
                    // Check if NPC asked for coins
                    if (activeDialogue.dialogueLines[dialogueLineIndex - 1].moneyCost > 0)
                    {
                        GameManager.Instance.NumCoins -= activeDialogue.dialogueLines[dialogueLineIndex - 1].moneyCost;
                    }

                    // No choices, end dialogue!
                    EndConversation();

                    int index = activeDialogue.dialogueLines.Count - 1;
                    if (index < 1)
                    {
                        index = 0;
                    }

                    if (activeDialogue.dialogueLines[index].positiveChoice)
                    {
                        SetEndData();
                    }

                    activeDialogue = null;
                }
            }
        }
    }
Esempio n. 11
0
 private void OnShowText(DialogueSource source, Dialogue.Snippet snippet)
 {
     Debug.Log(snippet.Render(source));
 }
Esempio n. 12
0
 public void UnregisterTalkable(DialogueSource talkable)
 {
     _talkables.Remove(talkable);
 }
Esempio n. 13
0
 public void RegisterTalkable(DialogueSource talkable)
 {
     _talkables.Add(talkable);
 }