Exemple #1
0
 //implementation without RegularExpressions
 public static void ParseText(string text, ref MyGuiControlMultilineText label)
 {
     try
     {
         var substrings = text.Split(']');
         foreach (var substring in substrings)
         {
             var textAndMarkup = substring.Split('[');
             if (textAndMarkup.Length == 2)
             {
                 label.AppendText(textAndMarkup[0]);
                 var indexOfSpace = textAndMarkup[1].IndexOf(' ');
                 if (indexOfSpace != -1)
                 {
                     label.AppendLink(textAndMarkup[1].Substring(0, indexOfSpace), textAndMarkup[1].Substring(indexOfSpace + 1));
                 }
                 else
                 {
                     System.Diagnostics.Debug.Assert(false);
                     label.AppendText(textAndMarkup[1]);
                 }
             }
             else
             {
                 label.AppendText(substring);
             }
         }
     }
     catch
     {
     }
 }
Exemple #2
0
        private static void ParseMarkup(MyGuiControlMultilineText label, string markup)
        {
            var s = m_markupRegex.Match(markup);

            if (s.Value.Contains('|'))
            {
                var sub = s.Value.Substring(5);
                var split = sub.Split('|');
                var match = m_digitsRegex.Matches(split[1]);
                int width, height;
                if (int.TryParse(match[0].Value, out width) && int.TryParse(match[1].Value, out height))
                {
                    label.AppendImage(split[0], MyGuiManager.GetNormalizedSizeFromScreenSize(new VRageMath.Vector2(width, height)), Vector4.One);
                }
            }
            else
            {
                label.AppendLink(s.Value.Substring(0, s.Value.IndexOf(' ')), s.Value.Substring(s.Value.IndexOf(' ') + 1));
            }
        }
        public virtual void GetDescriptionText(MyGuiControlMultilineText textbox)
        {
            textbox.Visible = true;
            textbox.Clear();
            if (string.IsNullOrEmpty(Description))
            {
                if (string.IsNullOrEmpty(Tooltip))
                {
                    textbox.AppendText("No description");
                }
                else
                {
                    textbox.AppendText(CapLength(Tooltip, 1000));
                }
                return;
            }
            else
            {
                string text      = CapLength(Description, 1000);
                int    textStart = 0;
                foreach (Match m in Regex.Matches(text, @"https?:\/\/(www\.)?[\w-.]{2,256}\.[a-z]{2,4}\b[\w-.@:%\+~#?&//=]*"))
                {
                    int textLen = m.Index - textStart;
                    if (textLen > 0)
                    {
                        textbox.AppendText(text.Substring(textStart, textLen));
                    }

                    textbox.AppendLink(m.Value, m.Value);
                    textStart = m.Index + m.Length;
                }

                if (textStart < text.Length)
                {
                    textbox.AppendText(text.Substring(textStart));
                }
            }
        }