/// <summary> /// Wraps a string in rich text color codes. Properly handles nested /// rich text codes. /// </summary> /// <param name="text">Original text to be wrapped.</param> /// <param name="color">Color to wrap around text.</param> public static string WrapTextInColor(string text, Color color) { if (string.IsNullOrEmpty(text)) { return(string.Empty); } var colorCode = "<color=" + Tools.ToWebColor(color) + ">"; // If text definitely has no other rich text codes, it's easy; just put a color code around the whole thing: if (!text.Contains("<")) { return(colorCode + text + "</color>"); } // Otherwise put color codes only around substrings that aren't already in existing rich text codes: var result = string.Empty; int index = 0; foreach (Match match in Regex.Matches(text, @"<i><color=^(?!.*</color>)</color></i>|<b><color=^(?!.*</color>)</color></b>|<i><b><color=^(?!.*</color>)</color></b></i>|<color=^(?!.*</color>)</color>")) { result += colorCode + text.Substring(index, match.Index) + "</color>" + match.Value; index = match.Index + match.Value.Length; } if (index < text.Length) { result += colorCode + text.Substring(index) + "</color>"; } return(result); }
private static string EmField(EmphasisSetting em) { return(string.Format("{0} {1}{2}{3}", Tools.ToWebColor(em.color), (em.bold ? 'b' : '-'), (em.italic ? 'i' : '-'), (em.underline ? 'u' : '-'))); }
private string GetActorColor(Subtitle subtitle) { if (subtitle == null | subtitle.speakerInfo == null) { return("white"); } return(Tools.ToWebColor(subtitle.speakerInfo.isPlayer ? playerColor : npcColor)); }
/// <summary> /// Replaces the emphasis tags with rich text, and returns an empty set of emphases. /// </summary> /// <returns> /// An empty set of emphases, since the rich text codes are embedded in the text itself. /// </returns> /// <param name='text'> /// The text, with emphasis tags replaced by rich text codes. /// </param> /// <param name='emphasisSettings'> /// Emphasis settings. /// </param> private static Emphasis[] ReplaceEmphasisTagsWithRichText(ref string text, EmphasisSetting[] emphasisSettings) { if (text.Contains("[em")) { for (int i = 0; i < DialogueDatabase.NumEmphasisSettings; i++) { string openTag = string.Format("[em{0}]", new System.Object[] { i + 1 }); string closeTag = string.Format("[/em{0}]", new System.Object[] { i + 1 }); if (text.Contains(openTag)) { string openRichText = string.Format("{0}{1}<color={2}>", new System.Object[] { emphasisSettings[i].bold ? "<b>" : string.Empty, emphasisSettings[i].italic ? "<i>" : string.Empty, Tools.ToWebColor(emphasisSettings[i].color) }); string closeRichText = string.Format("</color>{0}{1}", new System.Object[] { emphasisSettings[i].italic ? "</i>" : string.Empty, emphasisSettings[i].bold ? "</b>" : string.Empty }); text = text.Replace(openTag, openRichText).Replace(closeTag, closeRichText); } } } return(new Emphasis[0]); }
private static string ColorToCmpStyle(Color color) { return(Tools.ToWebColor(color).Substring(0, 7)); }