Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function makeLinesOptimized(message:String)
- {
- var currentLine:String = "";
- var currentLineWidth:Int = 0;
- var currentWord:String = "";
- var currentWordWidth:Int = 0;
- for (i in 0...message.length)
- {
- var character:String = message.charAt(i);
- var charWidth:Int = Math.ceil(chatFont.getCharWidth(character.charCodeAt(0)));
- currentWord += character;
- currentWordWidth += charWidth;
- // Word is over! New word starting!
- if (character == " " || i == message.length - 1)
- {
- // Will adding this word to the line exceed the length?
- if (currentLineWidth + currentWordWidth < MAX_LINE)
- {
- currentLine += currentWord;
- currentLineWidth += currentWordWidth;
- currentWordWidth = 0;
- if (widestLine < currentLineWidth)
- {
- widestLine = currentLineWidth;
- }
- }
- else
- {
- if (widestLine < currentLineWidth)
- {
- widestLine = currentLineWidth;
- }
- lines.push(currentLine);
- currentLine = currentWord;
- currentLineWidth = currentWordWidth;
- }
- currentWord = "";
- currentWordWidth = 0;
- continue;
- }
- // We're mid-word; this won't fit.
- else if (currentWordWidth >= MAX_LINE)
- {
- if (currentLine != "")
- {
- lines.push(currentLine);
- }
- lines.push(currentWord);
- currentWord = "";
- currentWordWidth = 0;
- currentLine = "";
- currentLineWidth = 0;
- }
- }
- lines.push(currentLine);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement