Skip to content

Commit

Permalink
feat: add tooltips for cards Mistah Vistah will recast
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuscechetto committed Oct 28, 2024
1 parent 1bc579d commit ab3ef9d
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Hearthstone Deck Tracker/Hearthstone/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using HSReplay.Requests;
using HSReplay.Responses;
using LiveCharts.Helpers;
using NuGet;
using static HearthDb.CardIds;

#endregion
Expand Down Expand Up @@ -529,6 +530,19 @@ public void Play(Entity entity, int turn)
{
SpellsPlayedInFriendlyCharacters.Add(entity.CardId);
}

var activeMistahVistahs = PlayerEntities.Where(e =>
e.CardId == NonCollectible.Druid.MistahVistah_ScenicVistaToken
&& (e.IsInZone(Zone.PLAY) || e.IsInZone(Zone.SECRET)));

if(!activeMistahVistahs.IsEmpty())
{
foreach(var mistahVistah in activeMistahVistahs)
{
mistahVistah.Info.StoredCardIds.Add(entity.CardId);
}
}

}
if(entity.Tags.TryGetValue(GameTag.SPELL_SCHOOL, out var spellSchoolTag))
PlayedSpellSchools.Add((SpellSchool)spellSchoolTag);
Expand Down
4 changes: 3 additions & 1 deletion Hearthstone Deck Tracker/Windows/DebugWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private async void Update()
}
await Task.Delay(500);
}
}
}

private void UpdateCards()
{
Expand All @@ -71,13 +71,15 @@ private void UpdateCards()
new CollectionItem(_game.Player.Deck, "Player Deck"),
new CollectionItem(_game.Player.Graveyard, "Player Graveyard"),
new CollectionItem(_game.Player.Secrets, "Player Secrets"),
new CollectionItem(_game.Player.Objectives, "Player Objectives"),
new CollectionItem(_game.Player.RevealedEntities, "Player RevealedEntities"),
new CollectionItem(_game.Player.SetAside, "Player SetAside"),
new CollectionItem(_game.Opponent.Hand, "Opponent Hand"),
new CollectionItem(_game.Opponent.Board, "Opponent Board"),
new CollectionItem(_game.Opponent.Deck, "Opponent Deck"),
new CollectionItem(_game.Opponent.Graveyard, "Opponent Graveyard"),
new CollectionItem(_game.Opponent.Secrets, "Opponent Secrets"),
new CollectionItem(_game.Opponent.Objectives, "Opponent Objectives"),
new CollectionItem(_game.Opponent.RevealedEntities, "Opponent RevealedEntities"),
new CollectionItem(_game.Opponent.SetAside, "Opponent SetAside")
};
Expand Down
114 changes: 114 additions & 0 deletions Hearthstone Deck Tracker/Windows/OverlayWindow.Tooltips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Hearthstone_Deck_Tracker.Controls.Overlay;
using Hearthstone_Deck_Tracker.Controls.Overlay.Battlegrounds.Minions;
using Hearthstone_Deck_Tracker.Controls.Overlay.Constructed.ActiveEffects;
using Hearthstone_Deck_Tracker.Enums.Hearthstone;
using Hearthstone_Deck_Tracker.Hearthstone;
using Hearthstone_Deck_Tracker.Hearthstone.Entities;
using Hearthstone_Deck_Tracker.Utility;
Expand Down Expand Up @@ -605,6 +606,119 @@ private void UpdateCardTooltip()
}

}
// player secrets/objective zone
else if(HoveredCard is { ZonePosition: > 0, IsHand: false, Side: (int)PlayerSide.FRIENDLY })
{
List<Hearthstone.Card?> relatedCards = new();
var entity = Core.Game.Player.Objectives.ElementAtOrDefault(HoveredCard.Value.ZonePosition - 1);
if (entity != null && entity.CardId == HoveredCard.Value.CardId)
relatedCards.AddRange(entity.Info.StoredCardIds.Select(Database.GetCardFromId));

if (_tooltipHoverStart == null)
{
_tooltipHoverStart = DateTime.Now;
}

var elapsed = DateTime.Now - _tooltipHoverStart.Value;

if(relatedCards.Count > 0)
{
var nonNullableRelatedCards = relatedCards.Where(c => c != null).Cast<Hearthstone.Card>();

ToolTipGridCards.SetTitle(LocUtil.Get("Related_Cards", useCardLanguage: true));
ToolTipGridCards.SetCardIdsFromCards(nonNullableRelatedCards, 470);
Canvas.SetTop(ToolTipGridCards, (480 - ToolTipGridCards.ActualHeight) * _activeEffectsScale);

// find the left of the card
var baseOffsetX = 0.57;
var leftOffsetXByLayer = new [] { 0.0, 0.037, 0.062 };
var rightOffsetXByLayer = new [] { 0.0, 0.034, 0.059 };
var relativePosition = HoveredCard.Value.ZonePosition - 1;
var isLeftSide = relativePosition % 2 != 0;
var layer = (int)Math.Ceiling(relativePosition / 2.0);
var offsetX = isLeftSide ? baseOffsetX - leftOffsetXByLayer[layer] : baseOffsetX + rightOffsetXByLayer[layer];
var correctedOffsetX = Helper.GetScaledXPos(offsetX, (int)Width, ScreenRatio);

// find the center of the card
var cardHeight = 0.43;
var cardHeightInPixels = cardHeight * Height;
var cardWidth = cardHeightInPixels * 31 / (cardHeight * 100);

Canvas.SetLeft(ToolTipGridCards,
correctedOffsetX + cardWidth / 2 - ToolTipGridCards.ActualWidth / 2 * _activeEffectsScale);

if(elapsed.TotalMilliseconds >= TooltipDelayMilliseconds)
{
ToolTipGridCards.Visibility = Config.Instance.HidePlayerRelatedCards ? Collapsed : Visible;
}
else
{
ToolTipGridCards.Visibility = Hidden;
}
}
else
{
ToolTipGridCards.Visibility = Hidden;
_tooltipHoverStart = null;
}

}
// opponent secrets/objective zone
else if(HoveredCard is { ZonePosition: > 0, IsHand: false } && HoveredCard.Value.Side != (int)PlayerSide.FRIENDLY)
{
List<Hearthstone.Card?> relatedCards = new();
var entity = Core.Game.Opponent.Objectives.ElementAtOrDefault(HoveredCard.Value.ZonePosition - 1);
if (entity != null && entity.CardId == HoveredCard.Value.CardId)
relatedCards.AddRange(entity.Info.StoredCardIds.Select(Database.GetCardFromId));

if (_tooltipHoverStart == null)
{
_tooltipHoverStart = DateTime.Now;
}

var elapsed = DateTime.Now - _tooltipHoverStart.Value;

if(relatedCards.Count > 0)
{
var nonNullableRelatedCards = relatedCards.Where(c => c != null).Cast<Hearthstone.Card>();

ToolTipGridCards.SetTitle(LocUtil.Get("Related_Cards", useCardLanguage: true));
ToolTipGridCards.SetCardIdsFromCards(nonNullableRelatedCards, 470);
Canvas.SetTop(ToolTipGridCards, Height / 2);

// find the left of the card
var baseOffsetX = 0.57;
var leftOffsetXByLayer = new [] { 0.0, 0.037, 0.062 };
var rightOffsetXByLayer = new [] { 0.0, 0.034, 0.059 };
var relativePosition = HoveredCard.Value.ZonePosition - 1;
var isLeftSide = relativePosition % 2 != 0;
var layer = (int)Math.Ceiling(relativePosition / 2.0);
var offsetX = isLeftSide ? baseOffsetX - leftOffsetXByLayer[layer] : baseOffsetX + rightOffsetXByLayer[layer];
var correctedOffsetX = Helper.GetScaledXPos(offsetX, (int)Width, ScreenRatio);

// find the center of the card
var cardHeight = 0.43;
var cardHeightInPixels = cardHeight * Height;
var cardWidth = cardHeightInPixels * 31 / (cardHeight * 100);

Canvas.SetLeft(ToolTipGridCards,
correctedOffsetX + cardWidth / 2 - ToolTipGridCards.ActualWidth / 2 * _activeEffectsScale);

if(elapsed.TotalMilliseconds >= TooltipDelayMilliseconds)
{
ToolTipGridCards.Visibility = Config.Instance.HideOpponentRelatedCards ? Collapsed : Visible;
}
else
{
ToolTipGridCards.Visibility = Hidden;
}
}
else
{
ToolTipGridCards.Visibility = Hidden;
_tooltipHoverStart = null;
}
}
else
{
ToolTipCardBlock.SetCardIdFromCard(null);
Expand Down

0 comments on commit ab3ef9d

Please sign in to comment.