diff --git a/Hearthstone Deck Tracker/Controls/AnimatedCard.xaml b/Hearthstone Deck Tracker/Controls/AnimatedCard.xaml index f0b411ba0..59b1f4a16 100644 --- a/Hearthstone Deck Tracker/Controls/AnimatedCard.xaml +++ b/Hearthstone Deck Tracker/Controls/AnimatedCard.xaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Hearthstone_Deck_Tracker.Controls" + xmlns:hearthstoneDeckTracker="clr-namespace:Hearthstone_Deck_Tracker" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> @@ -28,6 +29,10 @@ + + + + diff --git a/Hearthstone Deck Tracker/Controls/AnimatedCard.xaml.cs b/Hearthstone Deck Tracker/Controls/AnimatedCard.xaml.cs index 00eee4bb3..81947a80e 100644 --- a/Hearthstone Deck Tracker/Controls/AnimatedCard.xaml.cs +++ b/Hearthstone Deck Tracker/Controls/AnimatedCard.xaml.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Threading.Tasks; +using System.Windows; using System.Windows.Media.Animation; +using HearthDb.Enums; namespace Hearthstone_Deck_Tracker.Controls { @@ -13,6 +15,8 @@ public AnimatedCard(Hearthstone.Card card) { InitializeComponent(); DataContext = card; + CoinCost.Visibility = Card.TypeEnum == CardType.BATTLEGROUND_SPELL ? Visibility.Visible : Visibility.Collapsed; + Cost.Text = Card.Cost.ToString(); } public Hearthstone.Card Card => (Hearthstone.Card)DataContext; diff --git a/Hearthstone Deck Tracker/Controls/Overlay/BattlegroundsCardsGroup.xaml.cs b/Hearthstone Deck Tracker/Controls/Overlay/BattlegroundsCardsGroup.xaml.cs index 224651dff..63d25c454 100644 --- a/Hearthstone Deck Tracker/Controls/Overlay/BattlegroundsCardsGroup.xaml.cs +++ b/Hearthstone Deck Tracker/Controls/Overlay/BattlegroundsCardsGroup.xaml.cs @@ -13,9 +13,7 @@ public BattlegroundsCardsGroup() InitializeComponent(); } - public Race Race { get; set; } - - public string Title => HearthDbConverter.GetLocalizedRace(Race) ?? Race.ToString(); + public string Title { get; set; } = ""; public Visibility TitleVisibility => string.IsNullOrEmpty(Title) ? Visibility.Collapsed : Visibility.Visible; diff --git a/Hearthstone Deck Tracker/Controls/Overlay/BattlegroundsMinions.xaml.cs b/Hearthstone Deck Tracker/Controls/Overlay/BattlegroundsMinions.xaml.cs index a58ee607b..49253f140 100644 --- a/Hearthstone Deck Tracker/Controls/Overlay/BattlegroundsMinions.xaml.cs +++ b/Hearthstone Deck Tracker/Controls/Overlay/BattlegroundsMinions.xaml.cs @@ -12,14 +12,16 @@ namespace Hearthstone_Deck_Tracker.Controls.Overlay { public partial class BattlegroundsMinions : UserControl { - private Lazy _db = new Lazy(); - private readonly List _tierIcons = new List(); + private Lazy _db = new(); + private readonly List _tierIcons = new(); //We remove the below cardid from the bg tier list, it appears to have been incorrectly classified as a bg minion by blizzard in patch 20.0.0. //Hopefully it will be fixed soon and can be removed. private const string NonBgMurlocTidehunterCardId = HearthDb.CardIds.Collectible.Neutral.MurlocTidecallerVanilla; public int ActiveTier { get; set; } - public ObservableCollection Groups { get; set; } = new ObservableCollection(); + public ObservableCollection Groups { get; set; } = new(); + private BattlegroundsCardsGroup? _spellGroup; + private Dictionary _groupsByRace = new(); public BattlegroundsMinions() { @@ -67,11 +69,11 @@ public void Reset() private bool AddOrUpdateBgCardGroup(Race race, List cards) { var addedNew = false; - var existing = Groups.FirstOrDefault(x => x.Race == race); - if(existing == null) + if(!_groupsByRace.TryGetValue(race, out var existing)) { - existing = new BattlegroundsCardsGroup() { Race = race }; + existing = new BattlegroundsCardsGroup() { Title = HearthDbConverter.GetLocalizedRace(race) ?? race.ToString()}; Groups.Add(existing); + _groupsByRace.Add(race, existing); addedNew = true; } var sortedCards = cards @@ -81,6 +83,23 @@ private bool AddOrUpdateBgCardGroup(Race race, List cards) return addedNew; } + private bool AddOrUpdateSpellGroup(List cards) + { + var addedNew = false; + if(_spellGroup is null) + { + _spellGroup = new BattlegroundsCardsGroup() { Title = LocUtil.Get("Battlegrounds_Spells", useCardLanguage: true) }; + Groups.Add(_spellGroup); + addedNew = true; + } + var sortedCards = cards + .OrderBy(x => x.Cost) + .ThenBy(x => x.LocalizedName) + .ToList(); + _spellGroup.UpdateCards(sortedCards); + return addedNew; + } + private Dictionary> DifferentTribeClassifiedCards = new Dictionary>() { { Race.QUILBOAR, new List() { HearthDb.CardIds.NonCollectible.Neutral.AgamagganTheGreatBoar } } }; private void Update(int tier, IEnumerable availableRaces) @@ -96,6 +115,8 @@ private void Update(int tier, IEnumerable availableRaces) for(var i = 0; i < 7; i++) _tierIcons[i].SetFaded(false); Groups.Clear(); + _groupsByRace.Clear(); + _spellGroup = null; UnavailableTypes.UnavailableTypesVisibility = System.Windows.Visibility.Collapsed; return; } @@ -119,6 +140,12 @@ private void Update(int tier, IEnumerable availableRaces) UnavailableTypes.UnavailableRacesText = ""; } + var spells = _db.Value.GetSpells(tier); + if(spells.Any()) + resort |= AddOrUpdateSpellGroup(spells); + else + _spellGroup?.Hide(); + foreach(var race in _db.Value.Races) { var cards = _db.Value.GetCards(tier, race).ToList(); @@ -166,7 +193,12 @@ private void Update(int tier, IEnumerable availableRaces) } if(cards.Count == 0) - Groups.FirstOrDefault(x => x.Race == race)?.Hide(); + { + if(_groupsByRace.TryGetValue(race, out var group)) + { + group.Hide(); + } + } else { if(race == Race.ALL || race == Race.INVALID || availableRaces.Contains(race)) @@ -176,8 +208,10 @@ private void Update(int tier, IEnumerable availableRaces) if (resort) { + _groupsByRace.TryGetValue(Race.INVALID, out var invalidGroup); var items = Groups.ToList() - .OrderBy(x => x.Race == Race.INVALID) + .OrderBy(x => x == _spellGroup) + .ThenBy(x => x == invalidGroup) .ThenBy(x => x.Title); foreach(var item in items) { diff --git a/Hearthstone Deck Tracker/Hearthstone/BattlegroundsDb.cs b/Hearthstone Deck Tracker/Hearthstone/BattlegroundsDb.cs index a22829fc7..7056ae50f 100644 --- a/Hearthstone Deck Tracker/Hearthstone/BattlegroundsDb.cs +++ b/Hearthstone Deck Tracker/Hearthstone/BattlegroundsDb.cs @@ -10,6 +10,7 @@ namespace Hearthstone_Deck_Tracker.Hearthstone public class BattlegroundsDb { private Dictionary>> _cardsByTier = new Dictionary>>(); + private Dictionary> _spellsByTier = new Dictionary>(); public HashSet Races { get; } = new HashSet(); @@ -55,6 +56,19 @@ private void Update(List? tagOverrides) _cardsByTier[tier][race].Add(new Card(card, true)); } } + + _spellsByTier.Clear(); + + var baconSpells = Cards.All.Values + .Where(x => getTag(x, GameTag.TECH_LEVEL) > 0 && x.Type == CardType.BATTLEGROUND_SPELL); + foreach(var card in baconSpells) + { + var tier = getTag(card, GameTag.TECH_LEVEL); + if(!_spellsByTier.ContainsKey(tier)) + _spellsByTier[tier] = new List() { new Card(card, true) }; + else + _spellsByTier[tier].Add(new Card(card, true)); + } } private IEnumerable GetRaces(HearthDb.Card card) @@ -84,5 +98,12 @@ public List GetCards(int tier, Race race) return new List(); return cards; } + + public List GetSpells(int tier) + { + if(!_spellsByTier.TryGetValue(tier, out var cards)) + return new List(); + return cards; + } } } diff --git a/Hearthstone Deck Tracker/Hearthstone/Card.cs b/Hearthstone Deck Tracker/Hearthstone/Card.cs index c8b004ce0..dca44c73c 100644 --- a/Hearthstone Deck Tracker/Hearthstone/Card.cs +++ b/Hearthstone Deck Tracker/Hearthstone/Card.cs @@ -263,6 +263,8 @@ private string GetAlternativeText(bool formatted) [XmlIgnore] public string? Type { get; set; } + public CardType? TypeEnum => _dbCard?.Type; + [XmlIgnore] public string? Name { get; set; }