예제 #1
0
    private void hidePrompt()
    {
        if (speechPrompt == null)
        {
            return;
        }

        DialogueUIController.HideSpeechPrompt(speechPrompt);
    }
예제 #2
0
    public void Awake()
    {
        if (DialogueUIController.instance == null)
        {
            instance = this;
        }
        else if (this != instance)
        {
            Destroy(this.gameObject);
        }

        staticSpeechBubblePrefab = speechBubblePrefab;
        staticSpeechPromptPrefab = speechPromptPrefab;
    }
예제 #3
0
    private void DeployBubble(DialogueBubble speechBubble, Vector3 speakerPosition)
    {
        Vector2 speakerScreenPosition = dialogueCamera.WorldToScreenPoint(speakerPosition);

        float   relativeXdisplacment = (Camera.main.pixelWidth / 2.0f - speakerScreenPosition.x) / Camera.main.pixelWidth;
        float   relativeYdisplacment = (Camera.main.pixelHeight / 2.0f - speakerScreenPosition.y) / Camera.main.pixelHeight + 0.1f; // The dialogue should always be in the upper portion of the screen
        Vector2 displacementVector   = new Vector2(relativeXdisplacment, relativeYdisplacment);

        // The speech bubble needs to face in the same direction as the camera,
        // in order for the opaque side to show
        Vector3 awayFromCamera = Camera.main.transform.forward;
        //awayFromCamera.y = 0;
        Quaternion faceCameraRotation = Quaternion.LookRotation(awayFromCamera, Vector3.up);

        DialogueUIController.DeployDialogueBubbleAt(speechBubble, speakerPosition, displacementVector, faceCameraRotation);
    }
예제 #4
0
    //Displays the a speech bubble according to its text and position in the overall dialogue
    public void DisplaySpeechBubble(SpeakingLineContent speakingLineContent, Vector3 speakerPosition, DialogueBubbleType type = DialogueBubbleType.Speech)
    {
        ready = false;

        int lineNumber = speakingLineContent.lineNumber;

        // *(offscreen dialogue we will need to handle seperately)
        SpeechBubble speechBubble = DialogueUIController.GenerateSpeechBubblePrefab(type);

        speechBubble.SetDialogueBubbleContent(speakingLineContent);
        dialogueBubbles.Add(speechBubble);

        DeployBubble(speechBubble, speakerPosition);

        StartCoroutine(animateLogs(lineNumber));
    }
예제 #5
0
    //This hacky implementation is kind of bad but I really don't want to mess with making the animator do this
    public void init(Dialogue dialogue)
    {
        currentLineNumber = dialogue.currentPosition;
        activeDialogue    = dialogue;
        int speakingLineCount = activeDialogue.speakingLineCount;

        speechBubbles = new List <DialogueBubble>(speakingLineCount);
        randomSeedsX  = new List <float>(speakingLineCount);
        randomSeedsY  = new List <float>(speakingLineCount);

        for (int i = 0; i < speakingLineCount; i++)
        {
            DialogueBubble speechBubble = DialogueUIController.GenerateSpeechBubblePrefab();
            speechBubbles.Add(speechBubble);
            randomSeedsX.Add(Random.Range(-1.0f, 1.0f));
            randomSeedsY.Add(Random.Range(0f, 1.0f));
        }
    }
예제 #6
0
    //Displays the a speech bubble according to its text and position in the overall dialogue
    public void DisplaySpeechBubble(SpeakingLineContent speakingLineContent, Vector3 speakerPosition)
    {
        int lineNumber = speakingLineContent.lineNumber;

        ready = false;
        Vector2 speakerScreenPosition = dialogueCamera.WorldToScreenPoint(speakerPosition);

        float relativeXdisplacment = (Camera.main.pixelWidth / 2.0f - speakerScreenPosition.x) / Camera.main.pixelWidth;
        float relativeYdisplacment = (Camera.main.pixelHeight / 2.0f - speakerScreenPosition.y) / Camera.main.pixelHeight + 0.1f; // The dialogue should always be in the upper portion of the screen

        Vector2 displacementVector = new Vector2(relativeXdisplacment, relativeYdisplacment);

        // *(offscreen dialogue we will need to handle seperately)
        DialogueBubble speechBubble = speechBubbles[lineNumber];

        speechBubble.SetDialogueBubbleContent(speakingLineContent);
        DialogueUIController.DeploySpeechBubbleAt(speechBubble, speakerPosition, displacementVector);

        StartCoroutine(animateLogs(lineNumber));
    }
예제 #7
0
    // Kinda hacked together choice system
    internal void DisplayChoices(ChoiceLine line, Vector3 speakerPosition, DialogueBubbleType type = DialogueBubbleType.Thought)
    {
        ready = false;

        List <ChoiceLineContent> choices = line.dialogueChoices;
        int lineNumber = choices[0].lineNumber;

        ChoiceBubble choiceBubble = DialogueUIController.GenerateChoiceBubblePrefab(choices.Count(), type);

        for (int i = 0; i < choices.Count; i++)
        {
            ChoiceLineContent content = choices[i];
            choiceBubble.choicePanels[i].SetChoicePanelContent(content);
        }

        dialogueBubbles.Add(choiceBubble);

        DeployBubble(choiceBubble, speakerPosition);

        choiceBubble.UpdateOption(line.GetOptionIndex());
        StartCoroutine(toggleChoices(line, choiceBubble));
        StartCoroutine(animateLogs(lineNumber));
    }
예제 #8
0
    //Automatically animates the logs to the current state of the underlying dialogue data structure
    public IEnumerator animateLogs(int targetLineNumber)
    {
        // a bunch of the log advance/roll backwards stuff just isn't going to work with the current branching choice system
        // hacking it out so we always are looking at the latest dialogue
        currentLineNumber = dialogueBubbles.Count - 2;
        targetLineNumber  = dialogueBubbles.Count - 1;

        if (currentLineNumber != targetLineNumber)
        {
            int offset = targetLineNumber - currentLineNumber;

            //crappy concurrency lol
            float logTweenTime = 0.2f;
            float delta        = z_offset / logTweenTime * Time.deltaTime;

            while (logTweenTime > 0)
            {
                logTweenTime -= Time.deltaTime;
                for (int i = 0; i < dialogueBubbles.Count; i++)
                {
                    DialogueBubble animatedSpeechBubble = dialogueBubbles[i];
                    if (offset > 0)
                    {
                        if (targetLineNumber - offset <= i && i < targetLineNumber)
                        {
                            animatedSpeechBubble.transform.position += (Vector3.right * randomSeedsX[i] + Vector3.up * randomSeedsY[i]) * delta;
                        }
                    }
                    else
                    {
                        if (targetLineNumber <= i && i < targetLineNumber - offset)
                        {
                            animatedSpeechBubble.transform.position -= (Vector3.right * randomSeedsX[i] + Vector3.up * randomSeedsY[i]) * delta;
                        }
                    }
                    if (targetLineNumber - onScreenSpeechBubbleLimit < i && i <= targetLineNumber)
                    {
                        DialogueUIController.DeployDialogueBubble(animatedSpeechBubble);
                    }
                    // a bunch of the log advance/roll backwards stuff just isn't going to work with the current branching choice system, commenting out for now
                    if (i <= targetLineNumber - onScreenSpeechBubbleLimit)
                    {
                        DialogueUIController.HideDialogueBubble(animatedSpeechBubble);
                    }
                    if (i > targetLineNumber)
                    {
                        DialogueUIController.HideDialogueBubble(animatedSpeechBubble);
                    }
                    if (i == targetLineNumber)
                    {
                        animatedSpeechBubble.Focus();
                    }
                    int currentPosition = Mathf.Clamp(currentLineNumber - i, 0, onScreenSpeechBubbleLimit);
                    int targetPosition  = Mathf.Clamp(targetLineNumber - i, 0, onScreenSpeechBubbleLimit);
                    animatedSpeechBubble.transform.position += (targetPosition - currentPosition) * Vector3.forward * delta;
                }
                yield return(null);
            }
            for (int i = 0; i < dialogueBubbles.Count; i++)
            {
                if (i != targetLineNumber)
                {
                    dialogueBubbles[i].Blur();
                }
            }
            currentLineNumber = targetLineNumber;
        }

        // Audioooo
        AudioMaster.instance.PlayDialogueAdvanceSfx();

        yield return(new WaitForSeconds(0.2f));

        while (!Controls.confirmInputDown())
        {
            yield return(null);
        }

        ready = true;
    }
예제 #9
0
    private void displayPrompt(Vector3 triggerEnteredPosition)
    {
        Vector3 displacementVector = Vector3.Scale(triggerEnteredPosition, -Vector3.one);

        speechPrompt = DialogueUIController.DisplaySpeechPrompt(promptPosition.position, displacementVector, useNewPrompt);
    }
예제 #10
0
    //Automatically animates the logs to the current state of the underlying dialogue data structure
    public IEnumerator animateLogs(int targetLineNumber)
    {
        Debug.Log(targetLineNumber);
        Debug.Log(currentLineNumber);
        if (currentLineNumber != targetLineNumber)
        {
            int offset = targetLineNumber - currentLineNumber;

            //crappy concurrency lol
            float logTweenTime = 0.2f;
            float delta        = z_offset / logTweenTime * Time.deltaTime;

            while (logTweenTime > 0)
            {
                logTweenTime -= Time.deltaTime;
                for (int i = 0; i < speechBubbles.Count; i++)
                {
                    DialogueBubble animatedSpeechBubble = speechBubbles[i];
                    if (offset > 0)
                    {
                        if (targetLineNumber - offset <= i && i < targetLineNumber)
                        {
                            animatedSpeechBubble.transform.position += (Vector3.right * randomSeedsX[i] + Vector3.up * randomSeedsY[i]) * delta;
                        }
                    }
                    else
                    {
                        if (targetLineNumber <= i && i < targetLineNumber - offset)
                        {
                            animatedSpeechBubble.transform.position -= (Vector3.right * randomSeedsX[i] + Vector3.up * randomSeedsY[i]) * delta;
                        }
                    }
                    if (targetLineNumber - onScreenSpeechBubbleLimit < i && i <= targetLineNumber)
                    {
                        DialogueUIController.DeploySpeechBubble(animatedSpeechBubble);
                    }
                    if (i <= targetLineNumber - onScreenSpeechBubbleLimit)
                    {
                        DialogueUIController.HideSpeechBubble(animatedSpeechBubble);
                    }
                    if (i > targetLineNumber)
                    {
                        DialogueUIController.HideSpeechBubble(animatedSpeechBubble);
                    }
                    if (i == targetLineNumber)
                    {
                        animatedSpeechBubble.Focus();
                    }
                    int currentPosition = Mathf.Clamp(currentLineNumber - i, 0, onScreenSpeechBubbleLimit);
                    int targetPosition  = Mathf.Clamp(targetLineNumber - i, 0, onScreenSpeechBubbleLimit);
                    animatedSpeechBubble.transform.position += (targetPosition - currentPosition) * Vector3.forward * delta;
                }
                yield return(null);
            }
            for (int i = 0; i < speechBubbles.Count; i++)
            {
                if (i != targetLineNumber)
                {
                    speechBubbles[i].Blur();
                }
            }
            currentLineNumber = targetLineNumber;
        }
        yield return(new WaitForSeconds(0.2f));

        while (!Controls.confirmInputDown())
        {
            yield return(null);
        }
        ready = true;
    }