//-----------------------------------------------------------------------------
        // Constructor
        //-----------------------------------------------------------------------------
        // Constructs a text reader with the specified message
        public RoomStateTextReader(Message message, int linesPerWindow = 2)
        {
            this.updateRoom			= false;
            this.animateRoom		= true;

            this.message			= message;
            this.wrappedString		= GameData.FONT_LARGE.WrapString(message.Text, 128);
            this.timer				= 0;
            this.arrowTimer			= 0;

            this.linesPerWindow		= linesPerWindow;
            this.windowLinesLeft	= this.linesPerWindow;
            this.windowLine			= 0;
            this.currentLine		= 0;
            this.currentChar		= 0;
            this.state				= TextReaderState.WritingLine;
        }
예제 #2
0
 // Draws a formatted wrapped game string at the specified position
 public void DrawWrappedLetterString(GameFont font, WrappedLetterString wrappedString, int width, Point2I position, Color color, float depth = 0.0f)
 {
     for (int i = 0; i < wrappedString.Lines.Length; i++) {
     DrawLetterString(font, wrappedString.Lines[i], position + new Point2I(0, font.LineSpacing * i), color, depth);
     }
 }
예제 #3
0
        //-----------------------------------------------------------------------------
        // Strings
        //-----------------------------------------------------------------------------
        // Returns the wrapped and formatted string of the text.
        public WrappedLetterString WrapString(string text, int width)
        {
            List<LetterString> lines = new List<LetterString>();
            List<int> lineLengths = new List<int>();
            int currentLine = 0;
            int currentCharacter = 0;

            LetterString word = new LetterString();
            int wordStart = 0;
            int wordLength = 0;
            int wordLineCount = 0;
            bool firstChar = true;

            LetterString letterString = FormatCodes.FormatString(text);

            while (currentCharacter < letterString.Length) {
                lines.Add(new LetterString());
                lineLengths.Add(0);

                // Remove starting spaces in the line.
                while (letterString[currentCharacter].Char == ' ') {
                    currentCharacter++;
                }

                wordStart = currentCharacter;
                word.Clear();
                wordLength = 0;
                wordLineCount = 0;
                firstChar = true;

                do {
                    if (currentCharacter >= letterString.Length || letterString[currentCharacter].Char == ' ' ||
                        letterString[currentCharacter].Char == FormatCodes.ParagraphCharacter || letterString[currentCharacter].Char == '\n')
                    {
                        if (wordLineCount > 0)
                            lines[currentLine].Add(' ');
                        lines[currentLine].AddRange(word);
                        lineLengths[currentLine] += (wordLineCount > 0 ? (characterSpacing + spriteSheet.CellSize.X) : 0) + wordLength;

                        wordLineCount++;
                        wordLength = 0;
                        wordStart = currentCharacter + 1;
                        word.Clear();
                        if (currentCharacter < letterString.Length &&
                            (letterString[currentCharacter].Char == FormatCodes.ParagraphCharacter || letterString[currentCharacter].Char == '\n'))
                        {
                            if (letterString[currentCharacter].Char == FormatCodes.ParagraphCharacter)
                                lines[currentLine].Add(letterString[currentCharacter]);
                            currentCharacter++;
                            break;
                        }
                    }
                    else {
                        word.Add(letterString[currentCharacter]);
                        wordLength += (firstChar ? 0 : characterSpacing) + spriteSheet.CellSize.X;
                        firstChar = false;
                    }
                    currentCharacter++;
                } while (lineLengths[currentLine] + wordLength + characterSpacing + spriteSheet.CellSize.X <= width);

                currentCharacter = wordStart;
                currentLine++;
            }

            WrappedLetterString wrappedString = new WrappedLetterString();
            wrappedString.Lines = lines.ToArray();
            wrappedString.LineLengths = lineLengths.ToArray();
            wrappedString.Bounds = new Rectangle2I(width, (lines.Count - 1) * lineSpacing + spriteSheet.CellSize.Y);
            return wrappedString;
        }