/// <summary> /// Represents one item in a chat output. /// </summary> /// <param name="Type">Type of chat record.</param> /// <param name="Message">Message</param> /// <param name="Markdown">Markdown, if available, or null if plain text.</param> /// <param name="FormattedMessage">Formatted message.</param> /// <param name="Data">Optional binary data.</param> /// <param name="ForegroundColor">Foreground Color</param> /// <param name="BackgroundColor">Background Color</param> public ChatItem(ChatItemType Type, string Message, MarkdownDocument Markdown, Color ForegroundColor, Color BackgroundColor) : base(ForegroundColor, BackgroundColor) { this.type = Type; this.timestamp = this.lastUpdated = DateTime.Now; this.message = Message; if (Markdown == null) { XamlSettings Settings = new XamlSettings(); this.formattedMessage = new TextBlock() { TextWrapping = TextWrapping.Wrap, Margin = new Thickness(Settings.ParagraphMarginLeft, Settings.ParagraphMarginTop, Settings.ParagraphMarginRight, Settings.ParagraphMarginBottom), Text = Message }; if (this.formattedMessage is DependencyObject Root) { this.AddEventHandlers(Root); } this.lastIsTable = false; } else { this.ParseMarkdown(Markdown); foreach (MarkdownElement E in Markdown) { this.lastIsTable = (E is Waher.Content.Markdown.Model.BlockElements.Table); } } }
public void AddChatItem(ChatItemType type, object param) { if ((int)type >= objChatItemProfabs.Length) { return; } ChatItem objSelf = null; for (int i = 0; i < listAllObject.Count; ++i) { ChatItem obj = listAllObject[i]; if ((!obj.gameObject.activeSelf) && obj.GetChatItemType() == type) { objSelf = obj; break; } } if (objSelf == null) { objSelf = Object.Instantiate(objChatItemProfabs[(int)type].gameObject).GetComponent <ChatItem>(); listAllObject.Add(objSelf); } objSelf.gameObject.SetActive(true); objSelf.transform.parent = scrollContent.transform; lastChatItem = objSelf; objSelf.ShowItem(param); scrollToBottom(); }
public void Init(uint senderID, uint teamID, uint roleId, int chatItemType, uint transferLv, GameObject wnd, uint photoFrameId = 0, uint chatBubbleId = 0) { // 不把InitComponent放在Awake函数中,是由于大量使用GameObject的SetActive函数很耗gc if (!bInitComponent) { InitComponent(); } float scaleFactor = GetScaleFactor(wnd); mCurrentChatItemComp = null; mType = (ChatItemType)chatItemType; mMyChatItemComp.SetScaleFactor(scaleFactor); mOtherChatItemComp.SetScaleFactor(scaleFactor); mSystemChatItemComp.SetScaleFactor(scaleFactor); mMyChatItemComp.SetChatContent(""); mOtherChatItemComp.SetChatContent(""); mSystemChatItemComp.SetChatContent(""); switch (chatItemType) { case (int)ChatItemType.My: mMyChatItemComp.SetActive(true); mOtherChatItemComp.SetActive(false); mSystemChatItemComp.SetActive(false); mCurrentChatItemComp = mMyChatItemComp; break; case (int)ChatItemType.Other: mMyChatItemComp.SetActive(false); mOtherChatItemComp.SetActive(true); mSystemChatItemComp.SetActive(false); mCurrentChatItemComp = mOtherChatItemComp; break; case (int)ChatItemType.System: mMyChatItemComp.SetActive(false); mOtherChatItemComp.SetActive(false); mSystemChatItemComp.SetActive(true); mCurrentChatItemComp = mSystemChatItemComp; break; default: break; } if (mCurrentChatItemComp != null) { mCurrentChatItemComp.SetSenderID(senderID); mCurrentChatItemComp.SetTeamID(teamID); mCurrentChatItemComp.SetRoleID(roleId, transferLv); mCurrentChatItemComp.SetPhotoFrame(photoFrameId); mCurrentChatItemComp.SetChatBubble(chatBubbleId); } }
public ResNode GetChatItemPrefabByObjType(ChatItemType type) { switch (type) { case ChatItemType.ObjType_Text: return(m_chatItemTextRes); case ChatItemType.ObjType_Image: return(m_chatItemImageRes); default: break; } Debug.LogWarning("ChatMessageManager GetChatItemPrefabByObjType unknown infotype" + type); return(null); }
/// <summary> /// Represents one item in a chat output. /// </summary> /// <param name="Type">Type of chat record.</param> /// <param name="Message">Message</param> /// <param name="From">From where the message came.</param> /// <param name="Markdown">Markdown, if available, or null if plain text.</param> /// <param name="ThreadId">Thread ID</param> /// <param name="FormattedMessage">Formatted message.</param> /// <param name="Data">Optional binary data.</param> /// <param name="ForegroundColor">Foreground Color</param> /// <param name="BackgroundColor">Background Color</param> public ChatItem(ChatItemType Type, DateTime Timestamp, string Message, string From, MarkdownDocument Markdown, string ThreadId, Color ForegroundColor, Color BackgroundColor) : base(ForegroundColor, BackgroundColor) { this.type = Type; this.timestamp = this.lastUpdated = Timestamp; this.message = Message; this.from = From; this.fromStr = GetShortFrom(From); this.threadId = ThreadId; if (Markdown is null) { XamlSettings Settings = ChatView.GetMarkdownSettings().XamlSettings; this.formattedMessage = new TextBlock() { TextWrapping = TextWrapping.Wrap, Margin = new Thickness(Settings.ParagraphMarginLeft, Settings.ParagraphMarginTop, Settings.ParagraphMarginRight, Settings.ParagraphMarginBottom), Text = Message }; if (this.formattedMessage is DependencyObject Root) { this.AddEventHandlers(Root); } this.lastIsTable = false; } else { this.ParseMarkdown(Markdown); foreach (MarkdownElement E in Markdown) { this.lastIsTable = (E is Content.Markdown.Model.BlockElements.Table); } } }
private async Task MucClient_RoomOccupantMessage(object Sender, RoomOccupantMessageEventArgs e) { RoomNode RoomNode = await this.GetRoomNode(e.RoomId, e.Domain); string NickName = XmppClient.GetResource(e.From); ChatItemType Type = ChatItemType.Received; if (!string.IsNullOrEmpty(NickName) && RoomNode.NickName == NickName) { bool HasDelay = false; foreach (XmlNode N in e.Message.ChildNodes) { if (N is XmlElement E && E.LocalName == "delay") { HasDelay = true; break; } } if (!HasDelay) { return; } Type = ChatItemType.Transmitted; } RoomNode.EnterIfNotAlready(true); MainWindow.UpdateGui(() => { MainWindow.ParseChatMessage(e, out string Message, out bool IsMarkdown, out DateTime Timestamp); MainWindow.currentInstance.MucGroupChatMessage(e.From, XmppClient.GetBareJID(e.To), Message, e.ThreadID, IsMarkdown, Timestamp, Type, RoomNode, RoomNode.Header); }); }