/// <summary> /// 显示一条弹幕 /// </summary> public void ShowBulletChat(BulletChatModel Bullet, Direction FromDirection, Direction ToDirection) { if (!Topmost) { Topmost = true; } TextBulletChat text = new TextBulletChat(FromDirection, ToDirection, Bullet, (sss) => { Dispatcher.Invoke(() => { CANVAS_Map.Children.Remove(sss); }); }); CANVAS_Map.Children.Add(text); }
public BulletBase(BulletChatModel msg, Direction From = Direction.Right, Direction To = Direction.Left, bool IsShowAuto = true) { String msgContent = msg.SendUser + ":" + msg.Message; this.Foreground = new BrushConverter().ConvertFromString(msg.Foreground) as Brush; this.FontSize = msg.FontSize; this.Content = msgContent; this.FromDirection = From; this.ToDirection = To; //Width = FontSize * (Encoding.UTF8.GetBytes(msg.Message).Length); ShowAuto(); }
public TextBulletChat(Direction FromDirection, Direction ToDirection, BulletChatModel Bullet, Action <TextBulletChat> RemoveCallBack) { Visibility = Visibility.Collapsed; this.FromDirection = FromDirection; this.ToDirection = ToDirection; Content = $"{Bullet.SendUser}:{Bullet.Message}"; Foreground = (Brush) new BrushConverter().ConvertFromString(Bullet.Foreground); FontSize = Bullet.FontSize; this.RemoveCallBack = RemoveCallBack; BulletSource = Bullet; MoveStart(); }
private void Server_GetNewMessage(byte[] Content, MessageBase Message, System.Net.EndPoint FromIP) { if (Message.MessageType == SocketMessageType.BulletChat) { BulletChatModel msg = BulletChatModel.ToModel <BulletChatModel>(Content); ThreadPool.QueueUserWorkItem(a => { Dispatcher.Invoke(() => { //BulletBase form = new BulletBase(msg); BulletChatsForm.MainBulletChatsForm.ShowBulletChat(msg, TextBulletChat.Direction.Right, TextBulletChat.Direction.Left); }); }); } }
private void Server_GetNewMessage(byte[] Content, MessageBase Message, System.Net.EndPoint FromIP) { if (BlackMembers.Where(ip => FromIP == ip).Count() > 0) { return; //如果是黑名单就拒收 } String TagMessage = ""; if (Message.MessageType == SocketMessageType.IsOnLine) { IsOnLine onlin = IsOnLine.ToModel <IsOnLine>(Content); if (OnLineUsers.Keys.Where(k => k.Equals(FromIP)).Count() > 0) { OnLineUsers[FromIP] = DateTime.Now; } else { OnLineUsers.Add(FromIP, DateTime.Now); Dispatcher.Invoke(() => { LIST_OnlineUsers.Items.Add(new { IpAddress = FromIP, Content = onlin, }); }); } TagMessage = "在线确认消息"; } else if (Message.MessageType == SocketMessageType.SelectServer) { Server.SendTo(SelectServer.Server_Return(StaticResource.IPV4Address + ":" + StaticResource.ServerPort).ToByte(), FromIP); } else if (Message.MessageType == SocketMessageType.BulletChat) { BulletChatModel bullet = BulletChatModel.ToModel <BulletChatModel>(Content); TagMessage = $"{bullet.SendUser}发送的弹幕:{bullet.Message}"; foreach (EndPoint user in OnLineUsers.Keys) { if (BlackMembers.Where(ip => ip.Equals(user)).Count() > 0) { continue; } Server.SendTo(Content, user); } } Dispatcher.Invoke(() => { if (LIST_Messages.Items.Count >= 10) { LIST_Messages.Items.Clear(); } LIST_Messages.Items.Add(new { Tag = TagMessage, IpAddress = FromIP, MessageType = Message.MessageType, Length = Content.Length, }); }); }