using DominionBase.Enums; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; namespace Dominion.NET_WPF { /// /// Interaction logic for wCardViewer.xaml /// public partial class wCardViewer : Window { private readonly List _allCards; public wCardViewer() { InitializeComponent(); _allCards = new List(DominionBase.Cards.CardCollection.GetAllCards(c => c.Location != Location.Invisible, WMain.Settings.EditionUsage)); _allCards.Sort(delegate (DominionBase.IDisplayable c1, DominionBase.IDisplayable c2) { var ret = c1.Name.CompareTo(c2.Name); if (ret == 0) ret = c1.Edition.CompareTo(c2.Edition); return ret; }); cbCards.ItemsSource = _allCards; var sources = new SourceContainerList(_allCards.Select(c => c.Source).Distinct().OrderBy(s => s.ToString())); cbSets.ItemsSource = sources; } private void Window_Close_Click(object sender, RoutedEventArgs e) { Close(); } private void cbCards_SelectionChanged(object sender, SelectionChangedEventArgs e) { var comboBox = sender as ComboBox; if (comboBox != null) { var card = (DominionBase.IDisplayable)comboBox.SelectedItem; ttdCard.Card = card; ttdCard.Visibility = card == null ? Visibility.Hidden : Visibility.Visible; } ttdCard.InvalidateVisual(); } private void cbSets_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (((ComboBox)sender).SelectedItem == null) { cbCards.ItemsSource = null; return; } var selectedSource = (SourceContainer)((ComboBox)sender).SelectedItem; cbCards.ItemsSource = _allCards.Where(c => selectedSource.Source == Source.All || c.Source == selectedSource.Source); cbCards_SelectionChanged(cbCards, null); } } public class SourceContainer { public BitmapImage Image { get; set; } public Source Source { get; set; } public SourceContainer(Source source) { Source = source; var repo = Caching.ImageRepository.Acquire(); Image = repo.GetBitmapImage(Source.ToString(), "set"); Caching.ImageRepository.Release(); } } public class SourceContainerList : List { public SourceContainerList(IEnumerable elements) { foreach (var element in elements) Add(new SourceContainer(element)); } } }