Files
rqoverlay/src/RQOverlay/Views/MobsSessionView.xaml.cs

52 lines
2.0 KiB
C#

using System.Collections.Specialized;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using RQOverlay.Plugins.Builtin;
namespace RQOverlay.Views;
public partial class MobsSessionView : UserControl
{
ListCollectionView? _view;
public MobsSessionView()
{
InitializeComponent();
// Только мобы, убитые в этой сессии; больше всего убийств — сверху. Всё обновляется на лету.
DataContextChanged += (_, _) =>
{
if (DataContext is not MobStatsPlugin plugin) return;
_view = new ListCollectionView(plugin.Rows) { Filter = o => ((MobStat)o).SessionKills > 0 };
_view.SortDescriptions.Add(new SortDescription(nameof(MobStat.SessionKills), ListSortDirection.Descending));
_view.IsLiveFiltering = true;
_view.LiveFilteringProperties.Add(nameof(MobStat.SessionKills));
_view.IsLiveSorting = true;
_view.LiveSortingProperties.Add(nameof(MobStat.SessionKills));
((INotifyCollectionChanged)_view).CollectionChanged += (_, _) => UpdateEmpty();
MobGrid.ItemsSource = _view;
UpdateEmpty();
};
}
void UpdateEmpty()
{
bool empty = _view is null || _view.Count == 0;
Empty.Visibility = empty ? Visibility.Visible : Visibility.Collapsed;
Table.Visibility = empty ? Visibility.Collapsed : Visibility.Visible;
}
/// <summary>Таблица стоит внутри прокручиваемой страницы — колесо мыши передаём странице.</summary>
void Grid_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
e.Handled = true;
var copy = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta) { RoutedEvent = MouseWheelEvent, Source = sender };
((UIElement)((FrameworkElement)sender).Parent).RaiseEvent(copy);
}
}