Example #1
0
    /// <summary>
    /// Gets the label denoted by a {label} at the end of a line, like so
    ///
    /// Anne: Today is a good day {good end}
    /// </summary>
    /// <param name="line"></param>
    /// <returns></returns>
    public static List <ChoiceLineContent> GetChoices(string line, string speaker, int lineNumber)
    {
        List <ChoiceLineContent> dialogueChoices = new List <ChoiceLineContent>();

        MatchCollection matches = Regex.Matches(line, @"(?<=\[).+?(?=\])");

        // Use foreach-loop.
        foreach (Match match in matches)
        {
            foreach (Capture capture in match.Captures)
            {
                string choice = capture.Value;
                if (choice == "choice")
                {
                    continue;
                }

                string choiceLine = choice.Split('|')[0].Trim();
                string jumpLabel  = choice.Split('|')[1].Trim();

                if (string.IsNullOrWhiteSpace(jumpLabel))
                {
                    throw new Exception($"Line {line}: Jump label for choice option '{choiceLine}' is empty");
                }

                ChoiceLineContent content = new ChoiceLineContent(speaker, choiceLine, lineNumber, jumpLabel);

                dialogueChoices.Add(content);
            }
        }

        return(dialogueChoices);
    }
Example #2
0
    internal void InitJumps(Dictionary <string, ScriptLine> labeledLines)
    {
        List <ChoiceLineContent> reInitDialogueChoices = new List <ChoiceLineContent>();

        for (int i = 0; i < dialogueChoices.Count; i++)
        {
            ChoiceLineContent choice = dialogueChoices[i];
            if (labeledLines.TryGetValue(choice.jumpLabel, out ScriptLine jumpline))
            {
                choice.jumpLine = jumpline;
            }
            else
            {
                throw new Exception($"Line {choice.lineNumber}: Choice with text '{choice.lineText}' was unable to find label '{jumpLabel}'");
            }
            reInitDialogueChoices.Add(choice);
        }

        dialogueChoices = reInitDialogueChoices;
    }
    // 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));
    }
Example #4
0
 public void SetChoicePanelContent(ChoiceLineContent content)
 {
     textMesh.text = content.lineText;
 }