コード例 #1
0
 public void ResetEmphasisSettings()
 {
     emphasisSettings[0] = new EmphasisSetting(Color.white, false, false, false);
     emphasisSettings[1] = new EmphasisSetting(Color.red, false, false, false);
     emphasisSettings[2] = new EmphasisSetting(Color.green, false, false, false);
     emphasisSettings[3] = new EmphasisSetting(Color.blue, false, false, false);
 }
コード例 #2
0
 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' : '-')));
 }
コード例 #3
0
 private static string EmphasisToCmpStyle(EmphasisSetting es)
 {
     return string.Format("{0}{1}{2}", (es.bold ? 'b' : '-'), (es.italic ? 'i' : '-'), (es.underline ? 'u' : '-'));
 }
コード例 #4
0
 private static string EmphasisToCmpStyle(EmphasisSetting es)
 {
     return(string.Format("{0}{1}{2}", (es.bold ? 'b' : '-'), (es.italic ? 'i' : '-'), (es.underline ? 'u' : '-')));
 }
コード例 #5
0
 /// <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];
 }
コード例 #6
0
 /// <summary>
 /// Extracts the emphasis tags.
 /// </summary>
 /// <returns>
 /// An array of emphases.
 /// </returns>
 /// <param name='text'>
 /// Text (returned without the emphasis tags).
 /// </param>
 /// <param name='emphasisSettings'>
 /// Emphasis settings to use when parsing an emphasis tag.
 /// </param>
 /// @todo Apply emphasis to specified substring. Currently returns a max of one emphasis, which covers the whole text.
 private static Emphasis[] ExtractEmphasisTags(ref string text, EmphasisSetting[] emphasisSettings)
 {
     List<Emphasis> emphases = new List<Emphasis>();
     if (text.Contains("[em")) {
         Regex regex = new Regex(@"\[\/?em[1-4]\]");
         text = regex.Replace(text, delegate(Match match) {
             string numString = match.Value.Substring(match.Value.Length - 2, 1); // Get # from "[em#]"
             int num = 1;
             int.TryParse(numString, out num);
             num--;
             if ((emphasisSettings != null) && (0 <= num) && (num < emphasisSettings.Length)) {
                 Emphasis emphasis = new Emphasis(0, int.MaxValue, emphasisSettings[num].color, emphasisSettings[num].bold, emphasisSettings[num].italic, emphasisSettings[num].underline);
                 emphases.Clear();
                 emphases.Add(emphasis);
             }
             return string.Empty;
         });
     }
     return emphases.ToArray();
 }
コード例 #7
0
 /// <summary>
 /// Parses the text from a dialogue entry, which may contain formatting codes, and returns
 /// a FormattedText. The Parse() method handles these tags:
 /// 
 /// - Pipe (|): Replaced with newlines.
 /// - [a]: Italics.
 /// - [f]: Force response menu.
 /// - [position #]: Response button position.
 /// - [em#]...[/em#] (#=1-4, colors defined in dialogue database/Chat Mapper preferences). 
 /// Currently records only one emphasis unless rich text is enabled.
 /// - [var=varName]: Replaces tag with the value of a variable. Example: 
 /// <c>"Hello, [varName=Actor]."</c>.
 /// - [lua(xxx)]: Replaces tag with the result of Lua code xxx. Example: 
 /// <c>"Hello, [lua(Variable['Actor'])]."</c>. Lua tags are processed first, so your Lua
 /// code can return other formatting codes that will then be parsed properly.
 /// </summary>
 /// <param name='rawText'>
 /// The raw text to parse.
 /// </param>
 /// <param name='emphasisSettings'>
 /// The emphasis settings to use (usually from DialogueManager.MasterDatabase) when 
 /// parsing [em#] tags.
 /// </param>
 public static FormattedText Parse(string rawText, EmphasisSetting[] emphasisSettings)
 {
     string text = rawText ?? string.Empty;
     ReplaceLuaTags(ref text);
     string variableInputPrompt = ExtractVariableInputPrompt(ref text);
     ReplaceVarTags(ref text);
     ReplacePipes(ref text); // Was: ExtractTag("|", ref text);
     int pic = FormattedText.NoPicOverride;
     int pica = FormattedText.NoPicOverride;
     int picc = FormattedText.NoPicOverride;
     if (text.Contains("[pic")) {
         //---Was: (only matched numbers)
         //pic = ExtractPicTag(@"\[pic=[0-9]+\]", ref text);
         //pica = ExtractPicTag(@"\[pica=[0-9]+\]", ref text);
         //picc = ExtractPicTag(@"\[picc=[0-9]+\]", ref text);
         pic = ExtractPicTag(@"\[pic=[0-9a-zA-z_]+\]", ref text);
         pica = ExtractPicTag(@"\[pica=[0-9a-zA-z_]+\]", ref text);
         picc = ExtractPicTag(@"\[picc=[0-9a-zA-z_]+\]", ref text);
     }
     bool italic = ExtractTag("[a]", ref text);
     bool forceMenu = ExtractTag("[f]", ref text);
     int position = ExtractPositionTag(ref text);
     Emphasis[] emphases = DialogueManager.Instance.displaySettings.subtitleSettings.richTextEmphases
         ? ReplaceEmphasisTagsWithRichText(ref text, emphasisSettings)
         : ExtractEmphasisTags(ref text, emphasisSettings);
     return new FormattedText(text, emphases, italic, position, forceMenu, pic, pica, picc, variableInputPrompt);
 }