Beispiel #1
0
        public void BindServer(ITorchServer server)
        {
            _server      = (TorchBase)server;
            _multiplayer = (MultiplayerManager)server.Multiplayer;
            DataContext  = _multiplayer;

            ChatItems.Inlines.Clear();
            _multiplayer.ChatHistory.ForEach(InsertMessage);
            if (_multiplayer.ChatHistory is INotifyCollectionChanged ncc)
            {
                ncc.CollectionChanged += ChatHistory_CollectionChanged;
            }
            ChatScroller.ScrollToBottom();
        }
Beispiel #2
0
        private void InsertMessage(IChatMessage msg)
        {
            bool atBottom = ChatScroller.VerticalOffset + 8 > ChatScroller.ScrollableHeight;
            var  span     = new Span();

            span.Inlines.Add($"{msg.Timestamp} ");
            span.Inlines.Add(new Run(msg.Name)
            {
                Foreground = msg.Name == "Server" ? Brushes.DarkBlue : Brushes.Blue
            });
            span.Inlines.Add($": {msg.Message}");
            span.Inlines.Add(new LineBreak());
            ChatItems.Inlines.Add(span);
            if (atBottom)
            {
                ChatScroller.ScrollToBottom();
            }
        }
Beispiel #3
0
        private void InsertMessage(TorchChatMessage msg)
        {
            if (Dispatcher.CheckAccess())
            {
                bool atBottom = ChatScroller.VerticalOffset + 8 > ChatScroller.ScrollableHeight;
                var  span     = new Span();
                span.Inlines.Add($"{msg.Timestamp} ");
                switch (msg.Channel)
                {
                case ChatChannel.Faction:
                    span.Inlines.Add(new Run($"[{MySession.Static.Factions.TryGetFactionById(msg.Target)?.Tag ?? "???"}] ")
                    {
                        Foreground = Brushes.Green
                    });
                    break;

                case ChatChannel.Private:
                    span.Inlines.Add(new Run($"[to {MySession.Static.Players.TryGetIdentity(msg.Target)?.DisplayName ?? "???"}] ")
                    {
                        Foreground = Brushes.DeepPink
                    });
                    break;
                }
                span.Inlines.Add(new Run(msg.Author)
                {
                    Foreground = LookupBrush(msg.Font)
                });
                span.Inlines.Add($": {msg.Message}");
                span.Inlines.Add(new LineBreak());
                ChatItems.Inlines.Add(span);
                if (atBottom)
                {
                    ChatScroller.ScrollToBottom();
                }
            }
            else
            {
                Dispatcher.InvokeAsync(() => InsertMessage(msg));
            }
        }
Beispiel #4
0
 private void InsertMessage(TorchChatMessage msg)
 {
     if (Dispatcher.CheckAccess())
     {
         bool atBottom = ChatScroller.VerticalOffset + 8 > ChatScroller.ScrollableHeight;
         var  span     = new Span();
         span.Inlines.Add($"{msg.Timestamp} ");
         span.Inlines.Add(new Run(msg.Author)
         {
             Foreground = LookupBrush(msg.Font)
         });
         span.Inlines.Add($": {msg.Message}");
         span.Inlines.Add(new LineBreak());
         ChatItems.Inlines.Add(span);
         if (atBottom)
         {
             ChatScroller.ScrollToBottom();
         }
     }
     else
     {
         Dispatcher.InvokeAsync(() => InsertMessage(msg));
     }
 }
Beispiel #5
0
        private void DealPackage(TransPackage recvPackage)
        {
            if (recvPackage.PackageType != ConstDef.HeartPackage)
            {
                switch (recvPackage.PackageType)
                {
                case ConstDef.NormalMessage:
                    if (recvPackage.ClientGuid == WindowParent.ClientGuid)
                    {
                        AppendTextMessage(recvPackage.Name, recvPackage.Content, HorizontalAlignment.Right);
                    }
                    else
                    {
                        AppendTextMessage(recvPackage.Name, recvPackage.Content, HorizontalAlignment.Left);
                    }
                    App.Current.Dispatcher.Invoke(() => { ChatScroller.ScrollToBottom(); });
                    break;

                case ConstDef.Verification:
                    AppendAnnouncement(recvPackage.Content);
                    App.Current.Dispatcher.Invoke(() => { ChatScroller.ScrollToBottom(); });
                    break;

                case ConstDef.ImageMessage:
                    if (recvPackage.ClientGuid == WindowParent.ClientGuid)
                    {
                        AppendImageMessage(recvPackage.Name, recvPackage.Content, HorizontalAlignment.Right);
                    }
                    else
                    {
                        AppendImageMessage(recvPackage.Name, recvPackage.Content, HorizontalAlignment.Left);
                    }
                    break;

                case ConstDef.DrawAttention:
                    if (recvPackage.ClientGuid == WindowParent.ClientGuid)
                    {
                        AppendAnnouncement($"Your try to draw others' attention.");
                    }
                    else
                    {
                        AppendAnnouncement($"{recvPackage.Name} try to draw your attention.");
                    }
                    break;

                case ConstDef.ChangeChannelName:
                    SetCurrentChannelName(recvPackage.Content);
                    App.Current.Dispatcher.Invoke(() => { ChatScroller.ScrollToBottom(); });
                    break;

                case ConstDef.ReportChannelOnline:
                    AppendAnnouncement(recvPackage.Content);
                    App.Current.Dispatcher.Invoke(() => { ChatScroller.ScrollToBottom(); });
                    break;

                case ConstDef.Login:
                    WindowParent.ClientGuid = recvPackage.Content;
                    break;

                default:
                    // ( 在规定之外的消息 ) 以后再弄详细处理
                    break;
                }
            }
        }