Exemple #1
0
    //Adds the new line, then needs to update the display
    public void UpdateList(DialogueLine line)
    {
        string toAdd = "";

        int linesBetween = 1;

        if (line.LineOfDialogue.Length < MAX_LINE_LENGTH)
        {
            toAdd += line.LineOfDialogue;
        }
        else
        {
            int charsOnThisLine = 0;
            for (int i = 0; i < line.LineOfDialogue.Length; i++)
            {
                if (line.LineOfDialogue[i] == ' ')
                {
                    int charsExtra = 0;

                    while (charsExtra + i < line.LineOfDialogue.Length && line.LineOfDialogue[charsExtra + i] != ' ')
                    {
                        charsExtra++;
                    }

                    if (charsExtra + i > line.LineOfDialogue.Length)
                    {
                        //Do nothing, we'll just get to the end of the line
                        toAdd += line.LineOfDialogue[i];
                        charsOnThisLine++;
                    }
                    else
                    {
                        if (charsExtra + charsOnThisLine > MAX_LINE_LENGTH)
                        {
                            toAdd          += line.LineOfDialogue[i] + "\n";
                            charsOnThisLine = 0;
                            linesBetween++;
                        }
                        else
                        {
                            toAdd += line.LineOfDialogue[i];
                            charsOnThisLine++;
                        }
                    }
                }
                else
                {
                    toAdd += line.LineOfDialogue[i];
                    charsOnThisLine++;
                }
            }
        }

        if (line.IsPlayerLine())        //The Player Said This
        {
            playerText.text += toAdd + "\n";

            //Add spaces where appropriate
            for (int i = 0; i < linesBetween; i++)
            {
                otherText.text += "\n";
            }
        }
        else         //The other character said this
        {
            otherText.text += toAdd + "\n";

            //Add spaces where appropriate
            for (int i = 0; i < linesBetween; i++)
            {
                playerText.text += "\n";
            }
        }
    }