Skip to content

Commit

Permalink
ChancesView fix #33
Browse files Browse the repository at this point in the history
  • Loading branch information
batstyx committed Mar 15, 2024
2 parents 810e819 + 40bb732 commit b9d6e8e
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 29 deletions.
39 changes: 27 additions & 12 deletions Graveyard/ChancesTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,47 @@
using Hearthstone_Deck_Tracker;
using Hearthstone_Deck_Tracker.Controls;
using Card = Hearthstone_Deck_Tracker.Hearthstone.Card;
using Hearthstone_Deck_Tracker.Utility.Logging;

namespace HDT.Plugins.Graveyard
{
public class ChancesTracker
{
private Dictionary<Card, HearthstoneTextBlock> _chances = new Dictionary<Card, HearthstoneTextBlock>();
private readonly Dictionary<Card, HearthstoneTextBlock> Chances = new Dictionary<Card, HearthstoneTextBlock>();

public void Update(Card card, List<Card> Cards, AnimatedCardList View)
{
var count = (double)Cards.Aggregate(0, (total, c) => total + c.Count);
for (var i = 0; i < Cards.Count(); i++)
{
if (!_chances.ContainsKey(Cards[i]))
if (!Chances.ContainsKey(Cards[i]))
{
var chance = new HearthstoneTextBlock();
chance.FontSize = 18;
chance.TextAlignment = TextAlignment.Left;
var grid = (View.Items.GetItemAt(i) as UserControl).Content as Grid;
grid.Width = 260;
(grid.Children[0] as Hearthstone_Deck_Tracker.Controls.Card).HorizontalAlignment = HorizontalAlignment.Right;
(grid.Children[1] as Rectangle).Width = 260;
grid.Children.Add(chance);
_chances.Add(Cards[i], chance);
var chance = new HearthstoneTextBlock
{
FontSize = 18,
TextAlignment = TextAlignment.Left
};
if (View.Items.GetItemAt(i) is UserControl control && control.Content is Grid grid)
{
grid.Width = 260;
if (grid.Children[0] is Hearthstone_Deck_Tracker.Controls.Card cardControl)
cardControl.HorizontalAlignment = HorizontalAlignment.Right;
else
Log.Warn("Expected Hearthstone_Deck_Tracker.Controls.Card, check AnimatedCard for layout changes");
if (grid.Children[2] is Rectangle rectangle)
rectangle.Width = 260;
else
Log.Warn("Expected Rectangle, check AnimatedCard for layout changes");
grid.Children.Add(chance);
}
else
{
Log.Warn("Expected UserControl and Grid, check AnimatedCard for layout changes");
}
Chances.Add(Cards[i], chance);
}

_chances[Cards[i]].Text = $"{Math.Round(Cards[i].Count / count * 100)}%";
Chances[Cards[i]].Text = $"{Math.Round(Cards[i].Count / count * 100)}%";
}
}
}
Expand Down
16 changes: 15 additions & 1 deletion Graveyard/ChancesView.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
using Hearthstone_Deck_Tracker.Hearthstone;
using Hearthstone_Deck_Tracker;
using Hearthstone_Deck_Tracker.Hearthstone;
using System.Windows;

namespace HDT.Plugins.Graveyard
{
public class ChancesView : NormalView
{
private readonly ChancesTracker Chances = new ChancesTracker();

public ChancesView() : base()
{
Margin = new Thickness(Margin.Left + Settings.Default.ChancesViewLeft, Margin.Top, Margin.Right, Margin.Right);
}

public override HearthstoneTextBlock AddTitle(string text = "")
{
var label = base.AddTitle(text);
label.Margin = new Thickness(label.Margin.Left - Settings.Default.ChancesViewLeft, label.Margin.Top, label.Margin.Right, label.Margin.Right);
return label;
}

public override bool Update(Card card)
{
if (base.Update(card))
Expand Down
49 changes: 36 additions & 13 deletions Graveyard/Graveyard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public class Graveyard
AzeriteRatView.Config,
};

private readonly StackPanel FriendlyPanel;
private readonly FrameworkElement FriendlyView;
private readonly FrameworkElement EnemyView;

private readonly StackPanel FriendlyPanel;
private readonly StackPanel EnemyPanel;

private StackPanel FirstPanel;
Expand All @@ -92,16 +95,36 @@ public Graveyard()
{
Orientation = Orientation.Vertical
};
Core.OverlayCanvas.Children.Add(EnemyPanel);
#if DEBUGXAML
EnemyView = new Border
{
BorderBrush = Brushes.Green,
BorderThickness = new Thickness(1),
Child = EnemyPanel,
};
#else
EnemyView = EnemyPanel;
#endif
Core.OverlayCanvas.Children.Add(EnemyView);

// Create container
FriendlyPanel = new StackPanel
{
Orientation = Settings.Default.FriendlyOrientation
};
Core.OverlayCanvas.Children.Add(FriendlyPanel);
#if DEBUGXAML
FriendlyView = new Border
{
BorderBrush = Brushes.Green,
BorderThickness = new Thickness(1),
Child = FriendlyPanel,
};
#else
FriendlyView = FriendlyPanel;
#endif
Core.OverlayCanvas.Children.Add(FriendlyView);

Input = new InputManager(FriendlyPanel, EnemyPanel);
Input = new InputManager(FriendlyPanel, EnemyPanel);

Settings.Default.PropertyChanged += SettingsChanged;
SettingsChanged(null, null);
Expand All @@ -111,7 +134,7 @@ public Graveyard()
private void SettingsChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
FriendlyPanel.Orientation = Settings.Default.FriendlyOrientation;
FriendlyPanel.RenderTransform = new ScaleTransform(Settings.Default.FriendlyScale / 100, Settings.Default.FriendlyScale / 100);
FriendlyPanel.RenderTransform = new ScaleTransform(Settings.Default.FriendlyScale / 100, Settings.Default.FriendlyScale / 100);
FriendlyPanel.Opacity = Settings.Default.FriendlyOpacity / 100;
EnemyPanel.RenderTransform = new ScaleTransform(Settings.Default.EnemyScale / 100, Settings.Default.EnemyScale / 100);
EnemyPanel.Opacity = Settings.Default.EnemyOpacity / 100;
Expand All @@ -138,18 +161,18 @@ public void Update()
|| Core.Game.IsBattlegroundsMatch
|| Core.Game.IsMercenariesMatch ? Visibility.Collapsed : Visibility.Visible;

FriendlyPanel.Visibility = visibility;
if (FriendlyPanel.Visibility == Visibility.Visible)
FriendlyView.Visibility = visibility;
if (FriendlyView.Visibility == Visibility.Visible)
{
Canvas.SetTop(FriendlyPanel, Settings.Default.PlayerTop.PercentageToPixels(Core.OverlayWindow.Height));
Canvas.SetLeft(FriendlyPanel, Settings.Default.PlayerLeft.PercentageToPixels(Core.OverlayWindow.Width));
Canvas.SetTop(FriendlyView, Settings.Default.PlayerTop.PercentageToPixels(Core.OverlayWindow.Height));
Canvas.SetLeft(FriendlyView, Settings.Default.PlayerLeft.PercentageToPixels(Core.OverlayWindow.Width));
}

EnemyPanel.Visibility = visibility;
if (EnemyPanel.Visibility == Visibility.Visible)
EnemyView.Visibility = visibility;
if (EnemyView.Visibility == Visibility.Visible)
{
Canvas.SetTop(EnemyPanel, Settings.Default.EnemyTop.PercentageToPixels(Core.OverlayWindow.Height));
Canvas.SetLeft(EnemyPanel, Settings.Default.EnemyLeft.PercentageToPixels(Core.OverlayWindow.Width));
Canvas.SetTop(EnemyView, Settings.Default.EnemyTop.PercentageToPixels(Core.OverlayWindow.Height));
Canvas.SetLeft(EnemyView, Settings.Default.EnemyLeft.PercentageToPixels(Core.OverlayWindow.Width));
}
}

Expand Down
26 changes: 25 additions & 1 deletion Graveyard/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Graveyard/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,11 @@
<Setting Name="MaxLeft" Type="System.Double" Scope="User">
<Value Profile="(Default)">95</Value>
</Setting>
<Setting Name="TyrViewLeft" Type="System.Double" Scope="User">
<Value Profile="(Default)">-14</Value>
</Setting>
<Setting Name="ChancesViewLeft" Type="System.Double" Scope="User">
<Value Profile="(Default)">-42</Value>
</Setting>
</Settings>
</SettingsFile>
2 changes: 1 addition & 1 deletion Graveyard/TyrView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public TitledListView(string name)
VerticalAlignment = VerticalAlignment.Top,
MinHeight = 30,
MinWidth = 30,
Margin = new Thickness(-14,0,0,0),
Margin = new Thickness(Settings.Default.TyrViewLeft, 0, 0, 0),
Text = name,
};
Children.Add(Title);
Expand Down
12 changes: 11 additions & 1 deletion Graveyard/ViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void InitialiseDisplay()
Orientation = Orientation.Vertical;
}

public HearthstoneTextBlock AddTitle(string text = "")
public virtual HearthstoneTextBlock AddTitle(string text = "")
{
var title = new HearthstoneTextBlock
{
Expand All @@ -23,7 +23,17 @@ public HearthstoneTextBlock AddTitle(string text = "")
Text = text,
Margin = new Thickness(0, 20, 0, 0),
};
#if DEBUGXAML
var titleBorder = new Border
{
BorderBrush = System.Windows.Media.Brushes.Red,
BorderThickness = new Thickness(1),
Child = title,
};
Children.Insert(0, titleBorder);
#else
Children.Insert(0, title);
#endif
return title;
}
public string Title
Expand Down
6 changes: 6 additions & 0 deletions Graveyard/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@
<setting name="MaxLeft" serializeAs="String">
<value>95</value>
</setting>
<setting name="TyrViewLeft" serializeAs="String">
<value>-14</value>
</setting>
<setting name="ChancesViewLeft" serializeAs="String">
<value>-42</value>
</setting>
</HDT.Plugins.Graveyard.Settings>
</userSettings>
</configuration>

0 comments on commit b9d6e8e

Please sign in to comment.