private IEnumerator AddNewChatMessage(string msg, ChatMessage messageInfo)
        {
            _messageRendering = true;
            CustomText currentMessage = null;

            _testMessage.text = msg;
            _testMessage.cachedTextGenerator.Populate(msg, _testMessage.GetGenerationSettings(_testMessage.rectTransform.rect.size));
            yield return(null);

            for (int i = 0; i < _testMessage.cachedTextGenerator.lineCount; i++)
            {
                int index = Config.Instance.ReverseChatOrder ? _testMessage.cachedTextGenerator.lineCount - 1 - i : i;
                msg = _testMessage.text.Substring(_testMessage.cachedTextGenerator.lines[index].startCharIdx);
                if (index < _testMessage.cachedTextGenerator.lineCount - 1)
                {
                    msg = msg.Substring(0, _testMessage.cachedTextGenerator.lines[index + 1].startCharIdx - _testMessage.cachedTextGenerator.lines[index].startCharIdx);
                }

                // Italicize action messages and make the whole message the color of the users name
                if (messageInfo.isActionMessage)
                {
                    msg = $"<i><color={messageInfo.twitchMessage.user.color}>{msg}</color></i>";
                }

                currentMessage             = _chatMessages.Dequeue();
                currentMessage.hasRendered = false;
                currentMessage.text        = msg;
                currentMessage.messageInfo = messageInfo;
                currentMessage.material    = Drawing.noGlowMaterialUI;
                currentMessage.color       = Config.Instance.TextColor;
                _chatMessages.Enqueue(currentMessage);

                FreeImages(currentMessage);
                UpdateChatUI();
                yield return(null);

                foreach (BadgeInfo b in messageInfo.parsedBadges)
                {
                    Drawing.OverlayImage(currentMessage, b);
                }

                foreach (EmoteInfo e in messageInfo.parsedEmotes)
                {
                    Drawing.OverlayImage(currentMessage, e);
                }

                currentMessage.hasRendered = true;

                _waitForFrames = 5;
                yield return(_delay);
            }
            _testMessage.text = "";

            _messageRendering = false;
        }
Esempio n. 2
0
        private IEnumerator AddNewChatMessage(string origMsg, ChatMessage messageInfo)
        {
            _messageRendering = true;
            CustomText currentMessage = null;

            _testMessage.text = origMsg;
            _testMessage.cachedTextGenerator.Populate(origMsg, _testMessage.GetGenerationSettings(_testMessage.rectTransform.rect.size));
            yield return(null);

            Dictionary <string, string> openTags = new Dictionary <string, string>();

            for (int i = 0; i < _testMessage.cachedTextGenerator.lineCount; i++)
            {
                int index = ChatConfig.instance.ReverseChatOrder ? _testMessage.cachedTextGenerator.lineCount - 1 - i : i;

                string msg;
                if (index < _testMessage.cachedTextGenerator.lineCount - 1)
                {
                    msg = _testMessage.text.Substring(_testMessage.cachedTextGenerator.lines[index].startCharIdx, _testMessage.cachedTextGenerator.lines[index + 1].startCharIdx - _testMessage.cachedTextGenerator.lines[index].startCharIdx);
                }
                else
                {
                    msg = _testMessage.text.Substring(_testMessage.cachedTextGenerator.lines[index].startCharIdx);
                }

                if (msg.IsAllWhitespace())
                {
                    continue;
                }

                if (openTags.Count > 0)
                {
                    foreach (var tag in openTags.ToArray())
                    {
                        msg = msg.Insert(0, $"<{tag.Key}{(tag.Value != null? $"={tag.Value}" : "")}>");
                        var closingTag = $"</{tag.Key}>";
                        if (msg.Contains(closingTag))
                        {
                            openTags.Remove(tag.Key);
                        }
                        else
                        {
                            msg += closingTag;
                        }
                    }
                }

                var matches = _htmlTagRegex.Matches(msg).Cast <Match>().Reverse();
                foreach (Match m in matches)
                {
                    var tag = m.Groups["Tag"].Value;
                    if (openTags.ContainsKey(tag))
                    {
                        continue;
                    }

                    var closingTag = $"</{tag}>";
                    if (msg.Contains(closingTag))
                    {
                        continue;
                    }

                    string value = null;
                    if (m.Groups["Value"].Success)
                    {
                        value = m.Groups["Value"].Value;
                    }
                    openTags.Add(tag, value);
                    msg += closingTag;
                }

                currentMessage             = _chatMessages.Dequeue();
                currentMessage.hasRendered = false;
                currentMessage.text        = msg;
                currentMessage.messageInfo = messageInfo;
                currentMessage.material    = Drawing.noGlowMaterialUI;
                currentMessage.color       = ChatConfig.instance.TextColor;
                _chatMessages.Enqueue(currentMessage);

                FreeImages(currentMessage);
                UpdateChatUI();
                yield return(null);

                foreach (BadgeInfo b in messageInfo.parsedBadges.Values)
                {
                    Drawing.OverlayImage(currentMessage, b);
                }

                foreach (EmoteInfo e in messageInfo.parsedEmotes.Values)
                {
                    Drawing.OverlayImage(currentMessage, e);
                }

                currentMessage.hasRendered = true;

                _waitForFrames = 5;
                yield return(_delay);
            }
            _testMessage.text = "";
            _messageRendering = false;
        }
Esempio n. 3
0
 public static void UpdateTextGenerator(CustomText text)
 {
     text.cachedTextGenerator.Populate(text.text, text.GetGenerationSettings(text.rectTransform.rect.size));
 }