示例#1
0
        private void ChangeSearch(bool refresh = false)
        {
            if (players.SelectedItem is string name && name.Length > 0 && !name.StartsWith("No ", StringComparison.Ordinal))
            {
                var    channelList = GetSelectedChannels(out bool changed);
                string text        = (textFilter.Text.Length != 0 && textFilter.Text != Properties.Resources.CHAT_TEXT_FILTER) ? textFilter.Text : null;
                string to          = (toFilter.Text.Length != 0 && toFilter.Text != Properties.Resources.CHAT_TO_FILTER) ? toFilter.Text : null;
                string from        = (fromFilter.Text.Length != 0 && fromFilter.Text != Properties.Resources.CHAT_FROM_FILTER) ? fromFilter.Text : null;
                double startDate   = GetStartDate();
                double endDate     = GetEndDate();
                if (refresh || changed || LastPlayerSelection != name || LastTextFilter != text || LastToFilter != to || LastFromFilter != from || LastStartDate != startDate || LastEndDate != endDate)
                {
                    CurrentChatFilter = new ChatFilter(name, channelList, startDate, endDate, to, from, text);
                    CurrentIterator?.Close();
                    CurrentIterator  = new ChatIterator(name, CurrentChatFilter);
                    CurrentLineCount = 0;
                    RefreshTimer.Stop();
                    LastPlayerSelection = name;
                    LastTextFilter      = text;
                    LastToFilter        = to;
                    LastFromFilter      = from;
                    LastStartDate       = startDate;
                    LastEndDate         = endDate;

                    chatScroller.ScrollChanged -= Chat_ScrollChanged;
                    Connected = false;

                    if (changed)
                    {
                        ChatManager.SaveSelectedChannels(name, channelList);
                    }

                    chatBox.Document.Blocks.Clear();
                    DisplayPage(100);
                }
            }
        }
示例#2
0
        public ChatViewer()
        {
            InitializeComponent();

            fontSize.ItemsSource = FontSizeList;
            startDate.Text       = Properties.Resources.CHAT_START_DATE;
            endDate.Text         = Properties.Resources.CHAT_END_DATE;
            textFilter.Text      = Properties.Resources.CHAT_TEXT_FILTER;

            var context = new AutoCompleteText()
            {
                Text = Properties.Resources.CHAT_TO_FILTER
            };

            context.Items.AddRange(PlayerAutoCompleteList);
            toFilter.DataContext = context;

            context = new AutoCompleteText()
            {
                Text = Properties.Resources.CHAT_FROM_FILTER
            };
            context.Items.AddRange(PlayerAutoCompleteList);
            fromFilter.DataContext = context;

            string fgColor = ConfigUtil.GetSetting("ChatFontFgColor");

            if (fontFgColor.ItemsSource is List <ColorItem> colors)
            {
                fontFgColor.SelectedItem = (colors.Find(item => item.Name == fgColor) is ColorItem found) ? found : colors.Find(item => item.Name == "#ffffff");
            }

            string family = ConfigUtil.GetSetting("ChatFontFamily");

            fontFamily.SelectedItem = (family != null) ? new FontFamily(family) : chatBox.FontFamily;

            string size = ConfigUtil.GetSetting("ChatFontSize");

            if (size != null && double.TryParse(size, out double dsize))
            {
                fontSize.SelectedItem = dsize;
            }
            else
            {
                fontSize.SelectedValue = chatBox.FontSize;
            }

            FilterTimer = new DispatcherTimer {
                Interval = new TimeSpan(0, 0, 0, 0, 500)
            };
            FilterTimer.Tick += (sender, e) =>
            {
                FilterTimer.Stop();
                ChangeSearch();
            };

            RefreshTimer = new DispatcherTimer {
                Interval = new TimeSpan(0, 0, 1)
            };
            RefreshTimer.Tick += (sender, e) =>
            {
                ChatIterator newIterator = new ChatIterator(players.SelectedValue as string, CurrentChatFilter);
                var          tempChat    = FirstChat;
                var          tempFilter  = CurrentChatFilter;

                if (tempChat != null)
                {
                    Task.Run(() =>
                    {
                        foreach (var chatType in newIterator.TakeWhile(chatType => chatType.Line != tempChat.Line).Reverse())
                        {
                            Dispatcher.Invoke(() =>
                            {
                                // make sure user didnt start new search
                                if (tempFilter == CurrentChatFilter && RefreshTimer.IsEnabled && tempFilter.PastLiveFilter(chatType))
                                {
                                    if (chatBox.Document.Blocks.Count == 0)
                                    {
                                        MainParagraph = new Paragraph {
                                            Margin = new Thickness(0, 0, 0, 0), Padding = new Thickness(4, 0, 0, 4)
                                        };
                                        chatBox.Document.Blocks.Add(MainParagraph);
                                        MainParagraph.Inlines.Add(new Run());
                                    }

                                    var newItem = new Span(new Run(Environment.NewLine));
                                    newItem.Inlines.Add(new Run(chatType.Line));
                                    MainParagraph.Inlines.InsertAfter(MainParagraph.Inlines.LastInline, newItem);
                                    statusCount.Text = ++CurrentLineCount + " Lines";

                                    FirstChat = chatType;
                                }
                            }, DispatcherPriority.DataBind);
                        }

                        Dispatcher.Invoke(() => RefreshTimer.Stop());
                    });
                }
            };

            LoadPlayers();

            Ready = true;
            ChangeSearch();

            ChatManager.EventsUpdatePlayer += ChatManager_EventsUpdatePlayer;
            ChatManager.EventsNewChannels  += ChatManager_EventsNewChannels;
        }