private void LoadPlayers(string updatedPlayer = null) { _ = Dispatcher.InvokeAsync(() => { if (updatedPlayer == null || (updatedPlayer != null && !players.Items.Contains(updatedPlayer))) { var playerList = ChatManager.GetArchivedPlayers(); if (playerList.Count > 0) { if (players.ItemsSource == null) { players.Items.Clear(); } players.ItemsSource = playerList; string player = ConfigUtil.GetApplicationSetting("ChatSelectedPlayer"); if (string.IsNullOrEmpty(player) && !string.IsNullOrEmpty(ConfigUtil.PlayerName) && !string.IsNullOrEmpty(ConfigUtil.ServerName)) { player = ConfigUtil.PlayerName + "." + ConfigUtil.ServerName; } players.SelectedIndex = (player != null && playerList.IndexOf(player) > -1) ? playerList.IndexOf(player) : 0; } } else { if (!RefreshTimer.IsEnabled) { RefreshTimer.Start(); } } }, DispatcherPriority.DataBind); }
public FightTable() { InitializeComponent(); // fight search box fightSearchBox.FontStyle = FontStyles.Italic; fightSearchBox.Text = Properties.Resources.NPC_SEARCH_TEXT; fightMenuItemClear.IsEnabled = fightMenuItemSelectAll.IsEnabled = fightMenuItemUnselectAll.IsEnabled = fightMenuItemSelectFight.IsEnabled = false; fightMenuItemSetPet.IsEnabled = fightMenuItemSetPlayer.IsEnabled = false; var view = CollectionViewSource.GetDefaultView(Fights); view.Filter = new Predicate <object>(item => { var fightItem = (Fight)item; return(CurrentShowBreaks ? fightItem.GroupId >= -1 : fightItem.GroupId > -1); }); fightDataGrid.ItemsSource = view; SelectionTimer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 800) }; SelectionTimer.Tick += (sender, e) => { EventsSelectionChange(this, fightDataGrid.SelectedItems); SelectionTimer.Stop(); }; SearchTextTimer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 400) }; SearchTextTimer.Tick += (sender, e) => { HandleSearchTextChanged(); SearchTextTimer.Stop(); }; UpdateTimer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 500) }; UpdateTimer.Tick += (sender, e) => { // get state so it can't be modified outside this thread var currentNeedRefresh = NeedRefresh; if (NeedScroll) { (fightDataGrid.ItemsSource as ICollectionView).Refresh(); currentNeedRefresh = false; NeedRefresh = false; var last = Fights.LastOrDefault(fight => fight.GroupId > -1); if (last != null) { fightDataGrid.ScrollIntoView(last); } NeedScroll = false; } if (currentNeedRefresh) { (fightDataGrid.ItemsSource as ICollectionView).Refresh(); NeedRefresh = false; } }; UpdateTimer.Start(); // read show hp setting string showHitPoints = ConfigUtil.GetApplicationSetting("NpcShowHitPoints"); fightShowHitPoints.IsChecked = bool.TryParse(showHitPoints, out bool bValue) && bValue; fightDataGrid.Columns[1].Visibility = bValue ? Visibility.Visible : Visibility.Hidden; // read show breaks setting string showBreaks = ConfigUtil.GetApplicationSetting("NpcShowInactivityBreaks"); fightShowBreaks.IsChecked = CurrentShowBreaks = (showBreaks == null || (bool.TryParse(showBreaks, out bValue) && bValue)); }
public ChatViewer() { InitializeComponent(); ColorItems = typeof(Colors).GetProperties(). Where(prop => prop.Name != "Transparent"). Select(prop => new ColorItem() { Brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(prop.Name)), Name = prop.Name }). OrderBy(item => item.Name).ToList(); ColorItem DefaultForeground = new ColorItem { Name = "Default", Brush = new SolidColorBrush(Colors.White) }; 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; var fgList = new List <ColorItem>(ColorItems); fgList.Insert(0, DefaultForeground); fontFgColor.ItemsSource = fgList; string fgColor = ConfigUtil.GetApplicationSetting("ChatFontFgColor"); fgColor = fgColor ?? "Default"; fontFgColor.SelectedItem = fgList.Find(item => item.Name == fgColor); string family = ConfigUtil.GetApplicationSetting("ChatFontFamily"); if (family != null) { fontFamily.SelectedItem = new FontFamily(family); } else { fontFamily.SelectedItem = chatBox.FontFamily; } string size = ConfigUtil.GetApplicationSetting("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; }
public OverlayWindow(bool configure = false) { InitializeComponent(); string width = ConfigUtil.GetApplicationSetting("OverlayWidth"); string height = ConfigUtil.GetApplicationSetting("OverlayHeight"); string top = ConfigUtil.GetApplicationSetting("OverlayTop"); string left = ConfigUtil.GetApplicationSetting("OverlayLeft"); var margin = SystemParameters.WindowNonClientFrameThickness; bool offsetSize = configure || width == null || height == null || top == null || left == null; if (!offsetSize) { CreateRows(); Title = "Overlay"; MinHeight = 0; UpdateTimer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 1500) }; UpdateTimer.Tick += UpdateTimerTick; AllowsTransparency = true; Style = null; WindowStyle = WindowStyle.None; SetVisible(false); ShowActivated = false; } else { CreateRows(true); MinHeight = 130; AllowsTransparency = false; WindowStyle = WindowStyle.SingleBorderWindow; SetVisible(true); LoadTestData(); } if (width != null && double.TryParse(width, out double dvalue) && !double.IsNaN(dvalue)) { Width = offsetSize ? dvalue + margin.Left + margin.Right : dvalue; } if (height != null && double.TryParse(height, out dvalue) && !double.IsNaN(dvalue)) { Height = offsetSize ? dvalue + margin.Top + margin.Bottom : 0; if (!offsetSize) { CalculatedRowHeight = dvalue / (MAX_ROWS + 1); } } if (top != null && double.TryParse(top, out dvalue) && !double.IsNaN(dvalue)) { var test = offsetSize ? dvalue - margin.Top : dvalue; if (test >= SystemParameters.VirtualScreenTop && test < SystemParameters.VirtualScreenHeight) { Top = test; } } if (left != null && double.TryParse(left, out dvalue) && !double.IsNaN(dvalue)) { var test = offsetSize ? dvalue - margin.Left : dvalue; if (test >= SystemParameters.VirtualScreenLeft && test < SystemParameters.VirtualScreenWidth) { Left = test; } } string value = ConfigUtil.GetApplicationSetting("OverlayFontSize"); bool fontHasBeenSet = false; int currentFontSize = DEFAULT_TEXT_FONT_SIZE; if (value != null && int.TryParse(value, out currentFontSize) && currentFontSize >= 0 && currentFontSize <= 64) { foreach (var item in fontSizeSelection.Items) { if ((item as ComboBoxItem).Content as string == value) { fontSizeSelection.SelectedItem = item; SetFont(currentFontSize); fontHasBeenSet = true; } } } if (!fontHasBeenSet) { SetFont(currentFontSize); } if (!offsetSize) { NpcDamageManager.EventsPlayerAttackProcessed += NpcDamageManager_EventsPlayerAttackProcessed; DataManager.Instance.EventsNewInactiveFight += Instance_EventsNewInactiveFight; Active = true; } else { // remove when configuring NpcDamageManager.EventsPlayerAttackProcessed -= NpcDamageManager_EventsPlayerAttackProcessed; DataManager.Instance.EventsNewInactiveFight -= Instance_EventsNewInactiveFight; } if (!configure) { var settingsButton = CreateButton(); settingsButton.ToolTip = new ToolTip { Content = "Change Settings" }; settingsButton.Margin = new Thickness(8, 1, 0, 0); settingsButton.Content = "\xE713"; settingsButton.FontSize = currentFontSize - 1; settingsButton.Click += (object sender, RoutedEventArgs e) => (Application.Current.MainWindow as MainWindow)?.OpenOverlay(true, false); var copyButton = CreateButton(); copyButton.ToolTip = new ToolTip { Content = "Copy Parse" }; copyButton.Margin = new Thickness(4, 1, 0, 0); copyButton.Content = "\xE8C8"; copyButton.FontSize = currentFontSize - 1; copyButton.Click += (object sender, RoutedEventArgs e) => { lock (Stats) { (Application.Current.MainWindow as MainWindow)?.AddAndCopyDamageParse(Stats, Stats.StatsList); } }; var refreshButton = CreateButton(); refreshButton.ToolTip = new ToolTip { Content = "Cancel Current Parse" }; refreshButton.Margin = new Thickness(4, 1, 0, 0); refreshButton.Content = "\xE8BB"; refreshButton.FontSize = currentFontSize - 2; refreshButton.Click += (object sender, RoutedEventArgs e) => (Application.Current.MainWindow as MainWindow)?.ResetOverlay(); ButtonPopup = new Popup(); StackPanel btns = new StackPanel { Orientation = Orientation.Horizontal }; btns.Children.Add(settingsButton); btns.Children.Add(copyButton); btns.Children.Add(refreshButton); ButtonPopup.Child = btns; ButtonPopup.Height = currentFontSize + 2; ButtonPopup.Width = 80; ButtonPopup.AllowsTransparency = true; ButtonPopup.Opacity = 0.3; ButtonPopup.HorizontalOffset = Width / 2.1; ButtonPopup.VerticalOffset = 2; ButtonPopup.Placement = PlacementMode.RelativePoint; ButtonPopup.PlacementTarget = this; } }