Skip to content

Commit

Permalink
feat(BattlegroundsMinions): show spells by tavern tier
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Dec 7, 2023
1 parent dd4553a commit 69859c8
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Hearthstone Deck Tracker/Controls/AnimatedCard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<UserControl.Resources>
Expand All @@ -28,6 +29,10 @@
</UserControl.Resources>
<Grid Name="Grid">
<local:Card HasTooltip="{Binding Path=WindowCardToolTips, Source={StaticResource ConfigWrapper}}"/>
<Grid Name="CoinCost" HorizontalAlignment="Right" Visibility="Collapsed">
<Image Width="25" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center" Source="/HearthstoneDeckTracker;component/Images/coin-cost.png" />
<hearthstoneDeckTracker:HearthstoneTextBlock x:Name="Cost" Width="34" Height="34" FontSize="17" TextAlignment="Center" FontWeight="Bold" />
</Grid>
<Rectangle Name="RectHighlight" Fill="{Binding Highlight}" Height="34" Width="217" RenderOptions.BitmapScalingMode="Fant"
Opacity="0" VerticalAlignment="Center" IsHitTestVisible="False" />
</Grid>
Expand Down
4 changes: 4 additions & 0 deletions Hearthstone Deck Tracker/Controls/AnimatedCard.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ namespace Hearthstone_Deck_Tracker.Controls.Overlay
{
public partial class BattlegroundsMinions : UserControl
{
private Lazy<BattlegroundsDb> _db = new Lazy<BattlegroundsDb>();
private readonly List<BattlegroundsTier> _tierIcons = new List<BattlegroundsTier>();
private Lazy<BattlegroundsDb> _db = new();
private readonly List<BattlegroundsTier> _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<BattlegroundsCardsGroup> Groups { get; set; } = new ObservableCollection<BattlegroundsCardsGroup>();
public ObservableCollection<BattlegroundsCardsGroup> Groups { get; set; } = new();
private BattlegroundsCardsGroup? _spellGroup;
private Dictionary<Race, BattlegroundsCardsGroup> _groupsByRace = new();

public BattlegroundsMinions()
{
Expand Down Expand Up @@ -67,11 +69,11 @@ public void Reset()
private bool AddOrUpdateBgCardGroup(Race race, List<Hearthstone.Card> 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
Expand All @@ -81,6 +83,23 @@ private bool AddOrUpdateBgCardGroup(Race race, List<Hearthstone.Card> cards)
return addedNew;
}

private bool AddOrUpdateSpellGroup(List<Hearthstone.Card> 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<Race, List<string>> DifferentTribeClassifiedCards = new Dictionary<Race, List<string>>() { { Race.QUILBOAR, new List<string>() { HearthDb.CardIds.NonCollectible.Neutral.AgamagganTheGreatBoar } } };

private void Update(int tier, IEnumerable<Race> availableRaces)
Expand All @@ -96,6 +115,8 @@ private void Update(int tier, IEnumerable<Race> 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;
}
Expand All @@ -119,6 +140,12 @@ private void Update(int tier, IEnumerable<Race> 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();
Expand Down Expand Up @@ -166,7 +193,12 @@ private void Update(int tier, IEnumerable<Race> 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))
Expand All @@ -176,8 +208,10 @@ private void Update(int tier, IEnumerable<Race> 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)
{
Expand Down
21 changes: 21 additions & 0 deletions Hearthstone Deck Tracker/Hearthstone/BattlegroundsDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Hearthstone_Deck_Tracker.Hearthstone
public class BattlegroundsDb
{
private Dictionary<int, Dictionary<Race, List<Card>>> _cardsByTier = new Dictionary<int, Dictionary<Race, List<Card>>>();
private Dictionary<int, List<Card>> _spellsByTier = new Dictionary<int, List<Card>>();

public HashSet<Race> Races { get; } = new HashSet<Race>();

Expand Down Expand Up @@ -55,6 +56,19 @@ private void Update(List<RemoteData.TagOverride>? 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<Card>() { new Card(card, true) };
else
_spellsByTier[tier].Add(new Card(card, true));
}
}

private IEnumerable<Race> GetRaces(HearthDb.Card card)
Expand Down Expand Up @@ -84,5 +98,12 @@ public List<Card> GetCards(int tier, Race race)
return new List<Card>();
return cards;
}

public List<Card> GetSpells(int tier)
{
if(!_spellsByTier.TryGetValue(tier, out var cards))
return new List<Card>();
return cards;
}
}
}
2 changes: 2 additions & 0 deletions Hearthstone Deck Tracker/Hearthstone/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down

0 comments on commit 69859c8

Please sign in to comment.