private void Platform_ChannelActivity(IActionUser user) { // Combination Callback MainThreadInvoker.Invoke(() => { ChannelActivity?.Invoke(user); }); }
public async Task OnTextMessageReceived(IESCChatMessage msg, DateTime dateTime) { var main = await this._chatMessageBuilder.BuildMessage(msg, this._fontManager.FontInfo, BuildMessageTarget.Main); var sub = await this._chatMessageBuilder.BuildMessage(msg, this._fontManager.FontInfo, BuildMessageTarget.Sub); _ = MainThreadInvoker.Invoke(() => this.CreateMessage(msg, dateTime, main, sub)); }
private bool SetProperty <T>(ref T oldValue, T newValue, [CallerMemberName] string name = null) { if (EqualityComparer <T> .Default.Equals(oldValue, newValue)) { return(false); } oldValue = newValue; MainThreadInvoker.Invoke(() => this.OnPropertyChanged(new PropertyChangedEventArgs(name))); return(true); }
public void OnJoinChannel(IChatService svc, IChatChannel channel) { MainThreadInvoker.Invoke(() => { var newMsg = TextPool.Alloc(); newMsg.Text.text = $"<color=#bbbbbbbb>[{svc.DisplayName}] Success joining {channel.Id}</color>"; newMsg.HighlightEnabled = true; newMsg.HighlightColor = Color.gray.ColorWithAlpha(0.05f); AddMessage(newMsg); }); }
public void OnChatCleared(string userId) { if (string.IsNullOrEmpty(userId)) { return; } MainThreadInvoker.Invoke(() => { foreach (var msg in this._messages.Where(x => x.Text.ChatMessage?.Sender?.Id == userId)) { this.ClearMessage(msg); } }); }
public void OnChatCleared(string userId) { MainThreadInvoker.Invoke(() => { foreach (var msg in _messages) { if (msg.Text.ChatMessage == null) { continue; } if (userId == null || msg.Text.ChatMessage.Sender.Id == userId) { ClearMessage(msg); } } }); }
public void OnMessageCleared(string messageId) { if (messageId != null) { MainThreadInvoker.Invoke(() => { foreach (var msg in _messages) { if (msg.Text.ChatMessage == null) { continue; } if (msg.Text.ChatMessage.Id == messageId) { ClearMessage(msg); } } }); } }
public void OnChannelResourceDataCached(IChatChannel channel, Dictionary <string, IChatResourceData> resources) { MainThreadInvoker.Invoke(() => { int count = 0; if (_chatConfig.PreCacheAnimatedEmotes) { foreach (var emote in resources) { if (emote.Value.IsAnimated) { StartCoroutine(ChatImageProvider.instance.PrecacheAnimatedImage(emote.Value.Uri, emote.Key, 110)); count++; } } Logger.log.Info($"Pre-cached {count} animated emotes."); } else { Logger.log.Warn("Pre-caching of animated emotes disabled by the user. If you're experiencing lag, re-enable emote precaching."); } }); }
public async void OnTextMessageReceived(IChatMessage msg) { string parsedMessage = await ChatMessageBuilder.BuildMessage(msg, _chatFont); MainThreadInvoker.Invoke(() => { if (_lastMessage != null && !msg.IsSystemMessage && _lastMessage.Text.ChatMessage.Id == msg.Id) { // If the last message received had the same id and isn't a system message, then this was a sub-message of the original and may need to be highlighted along with the original message _lastMessage.SubText.text = parsedMessage; _lastMessage.SubText.ChatMessage = msg; _lastMessage.SubTextEnabled = true; UpdateMessage(_lastMessage); } else { var newMsg = TextPool.Alloc(); newMsg.Text.ChatMessage = msg; newMsg.Text.text = parsedMessage; AddMessage(newMsg); _lastMessage = newMsg; } }); }
public override void Rebuild(CanvasUpdate update) { if (update == CanvasUpdate.LatePreRender) { MainThreadInvoker.Invoke(() => { ClearImages(); }); for (int i = 0; i < textInfo.characterCount; i++) { TMP_CharacterInfo c = textInfo.characterInfo[i]; if (!c.isVisible || string.IsNullOrEmpty(text) || c.index >= text.Length) { // Skip invisible/empty/out of range chars continue; } uint character = text[c.index]; if (c.index + 1 < text.Length && char.IsSurrogatePair(text[c.index], text[c.index + 1])) { // If it's a surrogate pair, convert the character character = (uint)char.ConvertToUtf32(text[c.index], text[c.index + 1]); } if (FontInfo == null || !FontInfo.TryGetImageInfo(character, out var imageInfo) || imageInfo is null) { // Skip characters that have no imageInfo registered continue; } MainThreadInvoker.Invoke(() => { var img = _imagePool.Alloc(); try { if (imageInfo.AnimControllerData != null) { img.animStateUpdater.controllerData = imageInfo.AnimControllerData; img.sprite = imageInfo.AnimControllerData.sprites[imageInfo.AnimControllerData.uvIndex]; } else { img.sprite = imageInfo.Sprite; } img.material = BeatSaberUtils.UINoGlowMaterial; img.rectTransform.localScale = new Vector3(fontScale * 1.08f, fontScale * 1.08f, fontScale * 1.08f); img.rectTransform.sizeDelta = new Vector2(imageInfo.Width, imageInfo.Height); img.rectTransform.SetParent(rectTransform, false); img.rectTransform.localPosition = c.topLeft - new Vector3(0, imageInfo.Height * fontScale * 0.558f / 2); img.rectTransform.localRotation = Quaternion.identity; img.gameObject.SetActive(true); _currentImages.Add(img); } catch (Exception ex) { Logger.log.Error($"Exception while trying to overlay sprite. {ex.ToString()}"); _imagePool.Free(img); } }); } } base.Rebuild(update); if (update == CanvasUpdate.LatePreRender) { MainThreadInvoker.Invoke(OnLatePreRenderRebuildComplete); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /// <summary> /// Rebuild the text /// </summary> /// <param name="p_UpdateType">Update type</param> public override void Rebuild(CanvasUpdate p_UpdateType) { if (p_UpdateType == CanvasUpdate.LatePreRender) { MainThreadInvoker.Invoke(() => ClearImages()); for (int l_I = 0; l_I < textInfo.characterCount; l_I++) { /// Skip invisible/empty/out of range chars TMP_CharacterInfo l_CharacterInfo = textInfo.characterInfo[l_I]; if (!l_CharacterInfo.isVisible || string.IsNullOrEmpty(text) || l_CharacterInfo.index >= text.Length) { continue; } /// If it's a surrogate pair, convert the character uint l_Character = text[l_CharacterInfo.index]; if (l_CharacterInfo.index + 1 < text.Length && char.IsSurrogatePair(text[l_CharacterInfo.index], text[l_CharacterInfo.index + 1])) { l_Character = (uint)char.ConvertToUtf32(text[l_CharacterInfo.index], text[l_CharacterInfo.index + 1]); } /// Skip characters that have no imageInfo registered if (FontInfo == null || !FontInfo.TryGetImageInfo(l_Character, out var l_ImageInfo) || l_ImageInfo is null) { continue; } MainThreadInvoker.Invoke(() => { var l_Image = m_ImagePool.Alloc(); try { if (l_ImageInfo.AnimControllerData != null) { l_Image.AnimStateUpdater.controllerData = l_ImageInfo.AnimControllerData; l_Image.sprite = l_ImageInfo.AnimControllerData.sprites[l_ImageInfo.AnimControllerData.uvIndex]; } else { l_Image.sprite = l_ImageInfo.Sprite; } l_Image.material = BeatSaberPlus.Utils.UnityMaterial.UINoGlowMaterial; l_Image.rectTransform.localScale = new Vector3(fontScale * 1.08f, fontScale * 1.08f, fontScale * 1.08f); l_Image.rectTransform.sizeDelta = new Vector2(l_ImageInfo.Width, l_ImageInfo.Height); l_Image.rectTransform.SetParent(rectTransform, false); l_Image.rectTransform.localPosition = l_CharacterInfo.topLeft - new Vector3(0, l_ImageInfo.Height * fontScale * 0.558f / 2); l_Image.rectTransform.localRotation = Quaternion.identity; l_Image.gameObject.SetActive(true); m_CurrentImages.Add(l_Image); } catch (Exception p_Exception) { Logger.Instance?.Error("Exception while trying to overlay sprite"); Logger.Instance?.Error(p_Exception); m_ImagePool.Free(l_Image); } }); } } base.Rebuild(p_UpdateType); if (p_UpdateType == CanvasUpdate.LatePreRender) { MainThreadInvoker.Invoke(OnLatePreRenderRebuildComplete); } }