示例#1
0
        public void AddDanmu(DanmuModel danmu)
        {
            int        minn     = int.MaxValue;
            int        mini     = 0;
            List <int> miniList = new List <int>();

            for (int i = 0; i < items.Length; i++)
            {
                var item = items[i];
                if (item.Count < minn)
                {
                    minn = item.Count;
                    mini = i;
                    miniList.Clear();
                    miniList.Add(mini);
                }
                else if (item.Count == minn)
                {
                    miniList.Add(i);
                }
            }

            var selectedRow = miniList[new Random().Next(0, miniList.Count)];

            items[selectedRow].Enqueue(danmu);

            DanmuAdded?.Invoke(selectedRow);
        }
示例#2
0
        public DanmuItem(DanmuModel model)
        {
            InitializeComponent();
            avatorImg.Source = new BitmapImage(new Uri(model.AvatorUrl));
            nameText.Text    = model.DisplayName;

            foreach (var item in model.EncodedContent)
            {
                if (item is PlainMessage message)
                {
                    contentText.Inlines.Add(new Run(message.Message));
                }
                else if (item is ImageMessage m)
                {
                    contentText.Inlines.Add(new Image()
                    {
                        Source    = new BitmapImage(new Uri(m.Url)),
                        MaxHeight = 200
                    });
                }
                else if (item is FaceMessage m1)
                {
                    contentText.Inlines.Add(new Run($"[/{m1.Name}]"));
                }
                else if (item is SourceMessage)
                {
                }
                else
                {
                    contentText.Inlines.Add(new Run("[暂不支持的消息类型]"));
                }
            }
        }
示例#3
0
 public void SendDanmu(DanmuModel danmu)
 {
     foreach (var item in Windows)
     {
         if (item is DanmuWindow window)
         {
             window.CurrentManager.AddDanmu(danmu);
         }
     }
 }