Created
July 22, 2012 11:29
-
-
Save Bocom/3159377 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private List<DialogueTextChar> constrainText(string message) | |
| { | |
| bool filled = false; | |
| string line = ""; | |
| string returnString = ""; | |
| string[] wordArray = message.Replace("\n", "").Split(' '); | |
| Color currentColor = Color.White; | |
| bool recolor = false; | |
| bool shake = false; | |
| bool stopShake = false; | |
| Vector2 chrPos = StringPosition; | |
| Vector2 spaceChrPos = Fonts.DialogueDefaultFont.MeasureString(" "); | |
| List<DialogueTextChar> returnList = new List<DialogueTextChar>(); | |
| foreach (string word in wordArray) | |
| { | |
| string newWord = word; | |
| newWord = newWord.Replace("{s}", "").Replace("{/s}", ""); | |
| newWord = newWord.Replace("{h}", "").Replace("{/h}", ""); | |
| if (word.Contains("{s}")) | |
| shake = true; | |
| if (word.Contains("{/s}")) | |
| stopShake = true; | |
| if (word.Contains("{h}")) | |
| currentColor = Color.LimeGreen; | |
| if (word.Contains("{/h}")) | |
| recolor = true; | |
| if (Fonts.DialogueDefaultFont.MeasureString(line + newWord).X > 950) | |
| { | |
| if (Fonts.DialogueDefaultFont.MeasureString(returnString + line + "\n").Y < textRectangle.Height) | |
| { | |
| returnString += line + "\n"; | |
| chrPos.X = StringPosition.X; | |
| chrPos.Y += Fonts.DialogueDefaultFont.LineSpacing; | |
| line = ""; | |
| } | |
| else if (!filled) | |
| { | |
| filled = true; | |
| returnString += line; | |
| line = ""; | |
| } | |
| } | |
| if (!filled) | |
| { | |
| foreach (char chr in newWord) | |
| { | |
| returnList.Add(new DialogueTextChar(chr.ToString(), currentColor, chrPos, shake)); | |
| chrPos.X += Fonts.DialogueDefaultFont.MeasureString(chr.ToString()).X; | |
| } | |
| chrPos.X += spaceChrPos.X; | |
| returnList.Add(new DialogueTextChar(" ", currentColor, chrPos, shake)); | |
| } | |
| line += newWord + " "; | |
| if (stopShake) | |
| { | |
| shake = false; | |
| stopShake = false; | |
| } | |
| if (recolor) | |
| { | |
| currentColor = Color.White; | |
| recolor = false; | |
| } | |
| } | |
| if (filled) | |
| { | |
| DialogueLine dialogueLine = dialogueFile.Lines[currentLineIndex]; | |
| dialogueLine.OriginalDialogue = returnString; | |
| DialogueLine newDialogueLine = new DialogueLine(); | |
| newDialogueLine.OriginalDialogue = line; | |
| Dictionary<string, DialogueCharacter> chrDict = new Dictionary<string, DialogueCharacter>(); | |
| foreach (DialogueCharacter chr in dialogueLine.Characters.Values) | |
| { | |
| DialogueCharacter dialogueCharacter = dialogueLine.Characters[chr.Graphic]; | |
| DialogueCharacter newCharacter = new DialogueCharacter(); | |
| if (chr.Graphic == activeCharacter) | |
| newCharacter.Active = true; | |
| newCharacter.Id = dialogueCharacter.Id; | |
| newCharacter.Graphic = dialogueCharacter.Graphic; | |
| newCharacter.Name = dialogueCharacter.Name; | |
| newCharacter.State = dialogueCharacter.State; | |
| newCharacter.Position = dialogueCharacter.Position; | |
| chrDict[chr.Graphic] = newCharacter; | |
| } | |
| newDialogueLine.Characters = chrDict; | |
| dialogueFile.Lines.Insert(currentLineIndex + 1, newDialogueLine); | |
| return returnList; | |
| } | |
| else | |
| { | |
| return returnList; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment