-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathPlayerWindow.xaml.cs
More file actions
229 lines (201 loc) · 7.1 KB
/
Copy pathPlayerWindow.xaml.cs
File metadata and controls
229 lines (201 loc) · 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#region
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using Hearthstone_Deck_Tracker.Controls;
using Hearthstone_Deck_Tracker.Enums;
using Hearthstone_Deck_Tracker.Hearthstone;
using Hearthstone_Deck_Tracker.Utility;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
using Panel = System.Windows.Controls.Panel;
using Point = System.Drawing.Point;
#endregion
namespace Hearthstone_Deck_Tracker
{
/// <summary>
/// Interaction logic for PlayerWindow.xaml
/// </summary>
public partial class PlayerWindow
{
private readonly GameV2 _game;
public PlayerWindow(GameV2 game, List<Hearthstone.Card>? forScreenshot = null)
{
InitializeComponent();
_game = game;
Height = Config.Instance.PlayerWindowHeight;
if(Config.Instance.PlayerWindowLeft.HasValue)
Left = Config.Instance.PlayerWindowLeft.Value;
if(Config.Instance.PlayerWindowTop.HasValue)
Top = Config.Instance.PlayerWindowTop.Value;
Topmost = Config.Instance.WindowsTopmost;
var titleBarCorners = new[]
{
new Point((int)Left + 5, (int)Top + 5),
new Point((int)(Left + Width) - 5, (int)Top + 5),
new Point((int)Left + 5, (int)(Top + TitlebarHeight) - 5),
new Point((int)(Left + Width) - 5, (int)(Top + TitlebarHeight) - 5)
};
if(!Screen.AllScreens.Any(s => titleBarCorners.Any(c => s.WorkingArea.Contains(c))))
{
Top = 100;
Left = 100;
}
if(forScreenshot != null)
{
CanvasPlayerChance.Visibility = Visibility.Collapsed;
CanvasPlayerCount.Visibility = Visibility.Collapsed;
LblWins.Visibility = Visibility.Collapsed;
LblDeckTitle.Visibility = Visibility.Collapsed;
ListViewPlayer.Update(forScreenshot, true);
var items = ListViewPlayer.AnimatedCards;
var margins = items.Aggregate(0.0, (c, n) => c + n.Margin.Top + n.Margin.Bottom);
Height = ListViewPlayer.ViewModel.MaxHeightCard * items.Count + margins;
}
DeckList.Instance.ActiveDeckChanged += _ =>
{
ListViewPlayer.ItemsControl.Items.Refresh();
};
{
CanvasPlayerChance.GetBindingExpression(Panel.BackgroundProperty)?.UpdateTarget();
CanvasPlayerCount.GetBindingExpression(Panel.BackgroundProperty)?.UpdateTarget();
};
}
public void Update()
{
CanvasPlayerChance.Visibility = Config.Instance.HideDrawChances ? Visibility.Collapsed : Visibility.Visible;
CanvasPlayerCount.Visibility = Config.Instance.HidePlayerCardCount ? Visibility.Collapsed : Visibility.Visible;
ListViewPlayer.Visibility = Config.Instance.HidePlayerCards ? Visibility.Collapsed : Visibility.Visible;
LblWins.Visibility = Config.Instance.ShowDeckWins && _game.IsUsingPremade ? Visibility.Visible : Visibility.Collapsed;
LblDeckTitle.Visibility = Config.Instance.ShowDeckTitle && _game.IsUsingPremade ? Visibility.Visible : Visibility.Collapsed;
SetDeckTitle();
SetWinRates();
}
private void SetWinRates()
{
var selectedDeck = DeckList.Instance.ActiveDeck;
if(selectedDeck == null)
return;
LblWins.Text = $"{selectedDeck.WinLossString} ({selectedDeck.WinPercentString})";
}
private void SetDeckTitle() => LblDeckTitle.Text = DeckList.Instance.ActiveDeck?.Name ?? string.Empty;
public void UpdatePlayerLayout()
{
StackPanelMain.Children.Clear();
foreach(var item in Config.Instance.DeckPanelOrderLocalPlayer)
{
switch(item)
{
case DeckPanel.Cards:
StackPanelMain.Children.Add(ListViewPlayer);
break;
case DeckPanel.CardsTop:
if(!Config.Instance.HidePlayerCardsTop)
StackPanelMain.Children.Add(PlayerTopDeckLens);
break;
case DeckPanel.CardsBottom:
if(!Config.Instance.HidePlayerCardsBottom)
StackPanelMain.Children.Add(PlayerBottomDeckLens);
break;
case DeckPanel.Sideboards:
if(!Config.Instance.HidePlayerSideboards)
StackPanelMain.Children.Add(PlayerSideboards);
break;
case DeckPanel.CardCounter:
StackPanelMain.Children.Add(CanvasPlayerCount);
break;
case DeckPanel.DrawChances:
StackPanelMain.Children.Add(CanvasPlayerChance);
break;
case DeckPanel.DeckTitle:
StackPanelMain.Children.Add(LblDeckTitle);
break;
case DeckPanel.Wins:
StackPanelMain.Children.Add(LblWins);
break;
}
}
}
public void SetCardCount(int cardCount, int cardsLeftInDeck)
{
LblCardCount.Text = cardCount.ToString();
LblDeckCount.Text = cardsLeftInDeck.ToString();
var fatigueDamage = Math.Max(_game.Player.Fatigue + 1, 1);
if(cardsLeftInDeck <= 0)
{
LblDrawChance2.Text = "0%";
LblDrawChance1.Text = "0%";
return;
}
LblDrawChance2.Text = Math.Round(200.0f / cardsLeftInDeck, 1) + "%";
LblDrawChance1.Text = Math.Round(100.0f / cardsLeftInDeck, 1) + "%";
}
private void PlayerWindow_OnClosing(object sender, CancelEventArgs e)
{
if(Core.IsShuttingDown)
{
if(!double.IsNaN(Left))
Config.Instance.PlayerWindowLeft = (int)Left;
if(!double.IsNaN(Top))
Config.Instance.PlayerWindowTop = (int)Top;
if(!double.IsNaN(Height) && Height > 0)
Config.Instance.PlayerWindowHeight = (int)Height;
}
else
{
e.Cancel = true;
Hide();
}
}
private void PlayerWindow_OnActivated(object sender, EventArgs e) => Topmost = true;
private void PlayerWindow_OnDeactivated(object sender, EventArgs e)
{
if(!Config.Instance.WindowsTopmost)
Topmost = false;
}
public async Task UpdatePlayerCards(List<Hearthstone.Card> cards, bool reset, List<Hearthstone.Card> top, List<Hearthstone.Card> bottom, List<Sideboard> sideboards)
{
var updates = new[]
{
ListViewPlayer.Update(cards, reset),
PlayerTopDeckLens.Update(top, reset),
PlayerBottomDeckLens.Update(bottom, reset),
PlayerSideboards.Update(sideboards, reset),
};
await Task.WhenAll(updates);
}
public void HighlightPlayerDeckCards(string? highlightSourceCardId)
{
if(string.IsNullOrEmpty(highlightSourceCardId) || Config.Instance.HidePlayerHighlightSynergies)
{
ListViewPlayer.ShouldHighlightCard = null;
PlayerTopDeckLens.CardList.ShouldHighlightCard = null;
PlayerBottomDeckLens.CardList.ShouldHighlightCard = null;
return;
}
var highlightSourceCard = _game.RelatedCardsManager.GetCardWithHighlight(highlightSourceCardId!);
ListViewPlayer.ShouldHighlightCard = highlightSourceCard != null ? highlightSourceCard.ShouldHighlight : null;
PlayerTopDeckLens.CardList.ShouldHighlightCard = highlightSourceCard != null ? highlightSourceCard.ShouldHighlight : null;
PlayerBottomDeckLens.CardList.ShouldHighlightCard = highlightSourceCard != null ? highlightSourceCard.ShouldHighlight : null;
}
private void ListViewPlayerCard_OnMouseEnter(object sender, MouseEventArgs mouseEventArgs)
{
if(sender is CardTile { DataContext: CardTileViewModel vm })
{
HighlightPlayerDeckCards(vm.Card.Id);
}
}
private void ListViewPlayerCard_OnMouseLeave(object sender, MouseEventArgs mouseEventArgs)
{
HighlightPlayerDeckCards(null);
}
private void PlayerWindow_OnLoaded(object sender, RoutedEventArgs e)
{
Update();
UpdatePlayerLayout();
}
}
}