public void CreateCharactersFromDialogCue(DialogCue dialogCue) { Dictionary<string, string> appliedEffects = TextEffects; Vector2 nextPos = new Vector2(TextArea.X, TextArea.Y); List<string> keysToRemove = new List<string>(); List<Character> wordToAdd = new List<Character>(); List<string> characters = SplitString(dialogCue.Line); int lastCharacter = 0; for (int i = 0; i < characters.Count; i++) if (!characters[i].IsDialogCueTag()) lastCharacter = i; words.Clear(); for (int i = 0; i < characters.Count; i++) { string word = characters[i]; if (word.IsDialogCueOpeningTag()) { int tagStart = word.IndexOf('['); int tagEnd = word.IndexOf(']'); int tagMid = word.IndexOf('='); string key = word.Substring(tagStart + 1, tagMid - tagStart - 1); string value = word.Substring(tagMid + 1, tagEnd - tagMid - 1); if (appliedEffects.ContainsKey(key)) appliedEffects[key] = value; else appliedEffects.Add(key, value); } else if (word.IsDialogCueClosingTag()) { int tagStart = word.IndexOf('['); int tagEnd = word.IndexOf(']'); string key = word.Substring(tagStart + 2, tagEnd - tagStart - 2); if (appliedEffects.ContainsKey(key)) appliedEffects.Remove(key); } else { Character toAdd; if (appliedEffects.ContainsKey("font")) { toAdd = WordFactory.GenerateWord(nextPos, Fonts[appliedEffects["font"]], word, appliedEffects); } else { toAdd = WordFactory.GenerateWord(nextPos, Fonts[dialogCue.FontName], word, appliedEffects); } wordToAdd.Add(toAdd); if (wordToAdd.Last().Text.Equals(" ") || i == lastCharacter) { float wordLength = 0; foreach (Character c in wordToAdd) if (!c.Text.Equals(" ")) wordLength += c.Size.X; if (nextPos.X + wordLength > TextArea.Right) { nextPos = new Vector2(TextArea.X, LineHeight(words.Last().Position.Y)); foreach (Character c in wordToAdd) { c.Position = nextPos; nextPos = new Vector2(c.Right, c.Position.Y); } } else { foreach (Character c in wordToAdd) { c.Position = nextPos; nextPos = new Vector2(c.Right, c.Position.Y); } } words.AddRange(wordToAdd); wordToAdd.Clear(); } } } }
public void SetNextText(DialogCue dialogCue) { textBlock.CreateCharactersFromDialogCue(dialogCue); }
public void CreateCharactersFromDialogCue_Old(DialogCue dialogCue) { Dictionary<string, string> appliedEffects = TextEffects; Vector2 nextPos = new Vector2(TextArea.X, TextArea.Y); List<string> keysToRemove = new List<string>(); int lastSpace = 0; int wordCount = 0; words.Clear(); foreach (string word in SplitString(dialogCue.Line)) { if (word.IsDialogCueOpeningTag()) { int tagStart = word.IndexOf('['); int tagEnd = word.IndexOf(']'); int tagMid = word.IndexOf('='); string key = word.Substring(tagStart + 1, tagMid - tagStart - 1); string value = word.Substring(tagMid + 1, tagEnd - tagMid - 1); if (appliedEffects.ContainsKey(key)) appliedEffects[key] = value; else appliedEffects.Add(key, value); } else if (word.IsDialogCueClosingTag()) { int tagStart = word.IndexOf('['); int tagEnd = word.IndexOf(']'); string key = word.Substring(tagStart + 2, tagEnd - tagStart - 2); if (appliedEffects.ContainsKey(key)) appliedEffects.Remove(key); } else { Character toAdd; if (appliedEffects.ContainsKey("font")) { toAdd = WordFactory.GenerateWord(nextPos, Fonts[appliedEffects["font"]], word, appliedEffects); } else { toAdd = WordFactory.GenerateWord(nextPos, Fonts[dialogCue.FontName], word, appliedEffects); } if (toAdd.Right > TextArea.Right && !toAdd.Text.Equals(" ")) { toAdd.Position = new Vector2(TextArea.X, words.Last().Bottom); } else { if (word.Equals(" ")) lastSpace = wordCount; } nextPos = new Vector2(toAdd.Right, toAdd.Position.Y); words.Add(toAdd); wordCount++; } } }