/// <summary> /// 在一个聊天窗口中显示一个字符串 /// </summary> /// <param name="text">字符串</param> public void Show(ChatDataItem chatDataItem) { _chatDataItem = chatDataItem; string text = chatDataItem.chatBody; SetUserItemData(); _imageEmotionBubble.gameObject.SetActive(false); _imageChatBubble.gameObject.SetActive(false); if (chatDataItem.chatType == ChatDataItem.ChatType.TEXT) { _imageChatBubble.gameObject.SetActive(true); SetIsSend(_imageChatBubble.transform); int lines = 0; float maxCharNumInOneLine = 0; SetTextParam(ref text, ref lines, ref maxCharNumInOneLine); _textChat.text = text; _imageChatBubble.sizeDelta = new Vector2( IMAGE_BUBBLE_WIDTH_BASE + WIDTH_INCREMENT * (maxCharNumInOneLine - 1), IMAGE_BUBBLE_HEIGHT_BASE + HEIGHT_INCREMENT * (lines - 1) ); _frameChatBubble.sizeDelta = new Vector2( GlobalVars.DEFAULT_SCREEN_WIDTH, FRAME_BUBBLE_HEIGHT_BASE + HEIGHT_INCREMENT * (lines - 1) ); _frameChatBubble.GetComponent<LayoutElement>().preferredHeight = _frameChatBubble.sizeDelta.y; } else if (chatDataItem.chatType == ChatDataItem.ChatType.IMAGE) { _imageEmotionBubble.gameObject.SetActive(true); SetIsSend(_imageEmotionBubble.transform); _imageEmotionBubble.GetComponent<UniGifTexture>().gifTextAsset = Resources.Load<TextAsset>(string.Format("Raw/Gif/Emotion/00{0}", chatDataItem.chatBody)); _frameChatBubble.sizeDelta = new Vector2(GlobalVars.DEFAULT_SCREEN_WIDTH, IMAGE_EMOTION_HEIGHT); _frameChatBubble.GetComponent<LayoutElement>().preferredHeight = _frameChatBubble.sizeDelta.y; } if (_imageHead.GetComponent<Button>() && _userItem != null) { _imageHead.GetComponent<Button>().onClick.AddListener(OnClickHeadIcon); } if (_imageChatBubble.GetComponent<MiniButton>()) { _imageChatBubble.GetComponent<MiniButton>().onLongPress.AddListener(OnLongPressChatBubble); } if (_imageEmotionBubble.GetComponent<MiniButton>()) { _imageEmotionBubble.GetComponent<MiniButton>().onLongPress.AddListener(OnLongPressChatBubble); } }
public override void OnClickSendButton() { if (_inputChat.text == "") { return; } ChatDataItem chatDataItem = new ChatDataItem { sendUserId = GlobalUser.GetInstance().UserId, receiveUserId = _groupItem.groupId, date = System.DateTime.Now.Ticks, chatType = ChatDataItem.ChatType.TEXT, chatBody = _inputChat.text, targetType = ChatDataItem.TargetType.GROUP, }; GlobalChat.GetInstance().SendChatReq(chatDataItem); AddBubbleFrame(chatDataItem); UpdateChatBubbleGrid(); _inputChat.text = ""; }
/// <summary> /// 在一个聊天窗口中显示一个字符串 /// </summary> /// <param name="text">字符串</param> public void Show(ChatDataItem chatDataItem) { _chatDataItem = chatDataItem; string text = chatDataItem.chatBody; SetUserItemData(); _imageEmotionBubble.gameObject.SetActive(false); _imageChatBubble.gameObject.SetActive(false); if (chatDataItem.chatType == ChatDataItem.ChatType.TEXT) { _imageChatBubble.gameObject.SetActive(true); SetIsSend(_imageChatBubble.transform); int lines = 0; float maxCharNumInOneLine = 0; SetTextParam(ref text, ref lines, ref maxCharNumInOneLine); _textChat.text = text; _imageChatBubble.sizeDelta = new Vector2( IMAGE_BUBBLE_WIDTH_BASE + WIDTH_INCREMENT * (maxCharNumInOneLine - 1), IMAGE_BUBBLE_HEIGHT_BASE + HEIGHT_INCREMENT * (lines - 1) ); _frameChatBubble.sizeDelta = new Vector2( GlobalVars.DEFAULT_SCREEN_WIDTH, FRAME_BUBBLE_HEIGHT_BASE + HEIGHT_INCREMENT * (lines - 1) ); _frameChatBubble.GetComponent <LayoutElement>().preferredHeight = _frameChatBubble.sizeDelta.y; } else if (chatDataItem.chatType == ChatDataItem.ChatType.IMAGE) { _imageEmotionBubble.gameObject.SetActive(true); SetIsSend(_imageEmotionBubble.transform); _imageEmotionBubble.GetComponent <UniGifTexture>().gifTextAsset = Resources.Load <TextAsset>(string.Format("Raw/Gif/Emotion/00{0}", chatDataItem.chatBody)); _frameChatBubble.sizeDelta = new Vector2(GlobalVars.DEFAULT_SCREEN_WIDTH, IMAGE_EMOTION_HEIGHT); _frameChatBubble.GetComponent <LayoutElement>().preferredHeight = _frameChatBubble.sizeDelta.y; } if (_imageHead.GetComponent <Button>() && _userItem != null) { _imageHead.GetComponent <Button>().onClick.AddListener(OnClickHeadIcon); } if (_imageChatBubble.GetComponent <MiniButton>()) { _imageChatBubble.GetComponent <MiniButton>().onLongPress.AddListener(OnLongPressChatBubble); } if (_imageEmotionBubble.GetComponent <MiniButton>()) { _imageEmotionBubble.GetComponent <MiniButton>().onLongPress.AddListener(OnLongPressChatBubble); } }
protected void AddBubbleFrame(ChatDataItem chatDataItem) { EUIType uiType = (chatDataItem.sendUserId == GlobalUser.GetInstance().UserId) ? EUIType.PersonalChatBubbleFrame : EUIType.FriendChatBubbleFrame; GameObject bubbleFrame = UIManager.GetInstance().AddChild(_gridChatBubble.gameObject, uiType); bubbleFrame.GetComponent <ChatBubbleFrame>().Show(chatDataItem); _chatBubbleList.Add(bubbleFrame.GetComponent <ChatBubbleFrame>()); }
public static ChatItem ChatDataItemToItem(ChatDataItem chatDataItem) { return new ChatItem { sendUserId = chatDataItem.sendUserId, receiveUserId = chatDataItem.receiveUserId, chatType = ((ChatItem.ChatType)(uint)chatDataItem.chatType), chatBody = chatDataItem.chatBody, date = chatDataItem.date, targetType = (ChatItem.TargetType)(uint)chatDataItem.targetType, }; }
public virtual void Show(ChatLog chatLog) { _chatLog = chatLog; // Set UserItem // UserItem userItem = GlobalContacts.GetInstance().GetUserItemById(chatLog.chatID); if (userItem != null && chatLog.targetType == ChatDataItem.TargetType.INDIVIDUAL) { if (_imageHead) { UIManager.GetInstance().SetImage(_imageHead, EAtlasName.Head, "00" + userItem.headIndex); } if (_labelUserName) { _labelUserName.text = userItem.userName; } } // Set ChatItem // if (_labelLastChat) { _labelLastChat.text = ""; ChatDataItem lastChat = GlobalChat.GetInstance().GetLastChat(chatLog.chatID); if (lastChat != null) { if (lastChat.chatType == ChatDataItem.ChatType.TEXT) { _labelLastChat.text = lastChat.chatBody; } else if (lastChat.chatType == ChatDataItem.ChatType.IMAGE) { _labelLastChat.text = "[表情]"; } } } if (_labelDate) { _labelDate.text = DateFormatTool.GetChatFrameTimeStr(_chatLog.date); } if (_imageUnRead) { int num = GlobalChat.GetInstance().GetUnReadNum(_chatLog.chatID); num = (num > 99) ? 99 : num; _imageUnRead.gameObject.SetActive(num != 0); _labelUnReadNum.text = num.ToString(); } }
public static ChatItem ChatDataItemToItem(ChatDataItem chatDataItem) { return(new ChatItem { sendUserId = chatDataItem.sendUserId, receiveUserId = chatDataItem.receiveUserId, chatType = ((ChatItem.ChatType)(uint) chatDataItem.chatType), chatBody = chatDataItem.chatBody, date = chatDataItem.date, targetType = (ChatItem.TargetType)(uint) chatDataItem.targetType, }); }
public void SendChatReq(ChatDataItem chatDataItem) { SendChatReq req = new SendChatReq { chatData = MiniConverter.ChatDataItemToItem(chatDataItem), }; AddChatDataItem(chatDataItem); string msgID = NetworkManager.GetInstance().SendPacket <SendChatReq>(ENetworkMessage.SEND_CHAT_REQ, req, (uint)EModelMessage.SEND_CHAT_TIMEOUT); _waitSendChatDict.Add(msgID, chatDataItem); }
public override void OnClickSendEmotionButton(int index) { ChatDataItem chatDataItem = new ChatDataItem { sendUserId = GlobalUser.GetInstance().UserId, receiveUserId = _groupItem.groupId, date = System.DateTime.Now.Ticks, chatType = ChatDataItem.ChatType.IMAGE, chatBody = index.ToString(), targetType = ChatDataItem.TargetType.GROUP, }; GlobalChat.GetInstance().SendChatReq(chatDataItem); AddBubbleFrame(chatDataItem); UpdateChatBubbleGrid(); }
private void AddChatDataItem(ChatDataItem chatDataItem) { string chatID = null; if (chatDataItem.targetType == ChatDataItem.TargetType.INDIVIDUAL) { if (chatDataItem.sendUserId == GlobalUser.GetInstance().UserId) { chatID = chatDataItem.receiveUserId; } else { chatID = chatDataItem.sendUserId; } } else { chatID = chatDataItem.receiveUserId; } if (!_chatLogDict.ContainsKey(chatID)) { ChatLog chatLog = new ChatLog { chatID = chatID, }; _chatLogDict.Add(chatID, chatLog); } if (chatDataItem.sendUserId == GlobalUser.GetInstance().UserId) { chatDataItem.isRead = true; } _chatLogDict[chatID].itemList.Remove(chatDataItem); _chatLogDict[chatID].date = chatDataItem.date; _chatLogDict[chatID].targetType = chatDataItem.targetType; _chatLogDict[chatID].itemList.Add(chatDataItem); }
public bool IsChatDataItemSending(ChatDataItem chatDataItem) { return(_waitSendChatDict.ContainsValue(chatDataItem)); }
protected void AddBubbleFrame(ChatDataItem chatDataItem) { EUIType uiType = (chatDataItem.sendUserId == GlobalUser.GetInstance().UserId) ? EUIType.PersonalChatBubbleFrame : EUIType.FriendChatBubbleFrame; GameObject bubbleFrame = UIManager.GetInstance().AddChild(_gridChatBubble.gameObject, uiType); bubbleFrame.GetComponent<ChatBubbleFrame>().Show(chatDataItem); _chatBubbleList.Add(bubbleFrame.GetComponent<ChatBubbleFrame>()); }