-
Notifications
You must be signed in to change notification settings - Fork 1
/
frmPlayerInfo.cs
319 lines (259 loc) · 13.1 KB
/
frmPlayerInfo.cs
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace SC2Scrapbook
{
public partial class frmPlayerInfo : Form
{
public FormAnimator Animator{get;private set;}
private Models.Player _player;
public static frmPlayerInfo Instance { get; private set; }
public frmPlayerInfo(Models.Player player)
{
if (Instance != null)
{
Instance.Close();
Instance = null;
}
Instance = this;
int baseWidth = 154;
int baseHeight = 113;
int baseX = 252;
int baseY = 594;
double xPercentage = (double)baseX / 1280 * 100;
double yPercentage = (double)baseY / 720 * 100;
double widthPercentage = (double)baseWidth / 1280 * 100;
double heightPercentage = (double)baseHeight / 720 * 100;
double yScale = Program.SC2WindowRect.Height / 720;
double xScale = Program.SC2WindowRect.Width / 1280;
InitializeComponent();
Animator = new FormAnimator(this, FormAnimator.AnimationMethod.Slide, FormAnimator.AnimationDirection.Right, 1000);
this.Left = (int)(Program.SC2WindowRect.Left + ((double)Program.SC2WindowRect.Width / 100 * xPercentage));
this.Top = (int)(Program.SC2WindowRect.Top + ((double)Program.SC2WindowRect.Height / 100 * yPercentage));
this.Height = (int)((double)Program.SC2WindowRect.Height / 100 * heightPercentage);
this.Width = (int)((double)Program.SC2WindowRect.Width / 100 * widthPercentage);
_player = player;
if (Configuration.Instance.OpponentInfoOverlayTimeout > 0)
{
tmrClose.Interval = Configuration.Instance.OpponentInfoOverlayTimeout * 1000;
tmrClose.Start();
}
}
private void frmPlayerInfo_Load(object sender, EventArgs e)
{
}
public void ShowNoActivate()
{
if (InvokeRequired)
{
BeginInvoke(new Action(delegate()
{
ShowNoActivate();
}));
}
else
{
Animator.Direction = FormAnimator.AnimationDirection.Right;
Win32.ShowWindow(this.Handle, Win32.ShowWindowCommands.ShowNoActivate);
}
}
public void HideWindow()
{
if (InvokeRequired)
{
BeginInvoke(new Action(delegate()
{
HideWindow();
}));
}
else
{
Animator.Direction = FormAnimator.AnimationDirection.Left;
Win32.ShowWindow(this.Handle, Win32.ShowWindowCommands.Hide);
}
}
internal static Rectangle DrawLeagueImage(System.Drawing.Graphics g, Models.Player.Leagues league, int place, int size, int x, int y, double xScale, double yScale)
{
int srcHeight = 0;
int srcWidth = 0;
int srcX = 0;
int srcY = 0;
int modifier = 1;
if (size == 1)
{
srcHeight = 25;
srcWidth = 25;
srcX = 145;
}
else if (size == 2)
{
srcHeight = 45;
srcWidth = 45;
srcX = 100;
}
else
{
srcHeight = 100;
srcWidth = 100;
srcX = 0;
}
if (league == Models.Player.Leagues.Grandmaster)
modifier = 2;
if (place <= (8 * modifier))
{
srcY = (srcHeight + 5) * 3;
srcHeight += 5;
}
else if (place <= (25 * modifier))
{
srcY = (srcHeight + 5) * 2;
}
else if (place <= (50 * modifier))
{
srcY = (srcHeight + 5) * 1;
}
else if (place <= (100 * modifier))
{
srcY = 0;
}
Bitmap image = null;
switch (league)
{
case Models.Player.Leagues.Bronze:
image = Properties.Resources.bronze;
break;
case Models.Player.Leagues.Silver:
image = Properties.Resources.silver;
break;
case Models.Player.Leagues.Gold:
image = Properties.Resources.gold;
break;
case Models.Player.Leagues.Platinum:
image = Properties.Resources.platinum;
break;
case Models.Player.Leagues.Diamond:
image = Properties.Resources.diamond;
break;
case Models.Player.Leagues.Master:
image = Properties.Resources.master;
break;
case Models.Player.Leagues.Grandmaster:
image = Properties.Resources.grandmaster;
break;
default:
image = Properties.Resources.none;
break;
}
Rectangle destination = new Rectangle(x, y, (int)((srcWidth * 0.6) * xScale), (int)((srcHeight * 0.6) * yScale));
g.DrawImage(image, destination, srcX, srcY, srcWidth, srcHeight, GraphicsUnit.Pixel);
return destination;
}
internal static Rectangle DrawPortrait(System.Drawing.Graphics g, Models.Player.PortraitData p, int x, int y, double xScale, double yScale)
{
// Creating a full scale image of the portrait in the frame is necessary to avoid a scaling clusterfuck.
Image newPortrait = new Bitmap(105, 101);
Graphics newGraphics = Graphics.FromImage(newPortrait);
if (p == null || !System.IO.File.Exists(p.Filename))
newGraphics.DrawImage(Properties.Resources.defaultportrait, 7, 5);
else
{
try
{
Image image = Bitmap.FromFile(p.Filename);
newGraphics.DrawImage(image, new Rectangle(7, 5, 90, 90), p.Position.X, p.Position.Y, p.Position.Width, p.Position.Height, GraphicsUnit.Pixel);
image.Dispose();
}
catch
{
newGraphics.DrawImage(Properties.Resources.defaultportrait, 7, 5);
}
}
newGraphics.DrawImage(Properties.Resources.portrait_summary, 0, 0);
Rectangle destination = new Rectangle(x, y, (int)((newPortrait.Width * 0.6) * xScale), (int)((newPortrait.Height * 0.6) * yScale));
g.DrawImage(newPortrait, destination, 0, 0, newPortrait.Width, newPortrait.Height, GraphicsUnit.Pixel);
newGraphics.Dispose();
newPortrait.Dispose();
return destination;
}
private void frmPlayerInfo_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
System.Drawing.Imaging.ColorMatrix attrMatrix = new System.Drawing.Imaging.ColorMatrix();
attrMatrix.Matrix33 = 0.5f;
System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
attr.SetColorMatrix(attrMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);
if (_player == null)
{
Image raceSnapshot = Models.Matchup.SnapshotImageFromRace(Models.Matchup.Races.Random);
e.Graphics.DrawImage(raceSnapshot, new Rectangle(0, 0, Width, Height), 0, 0, raceSnapshot.Width, raceSnapshot.Height, GraphicsUnit.Pixel, attr);
e.Graphics.DrawString(string.Format("Custom Game Hero"), new Font("Arial", (float)(12 * Program.yScale), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), 20, 20);
}
else
{
Image raceSnapshot = Models.Matchup.SnapshotImageFromRace(_player.Race);
e.Graphics.DrawImage(raceSnapshot, new Rectangle(0, 0, Width, Height), 0, 0, raceSnapshot.Width, raceSnapshot.Height, GraphicsUnit.Pixel, attr);
Rectangle portrait = DrawPortrait(e.Graphics, _player.Portrait, 0, 0, Program.xScale > 1 ? 1 : Program.xScale, Program.yScale > 1 ? 1 : Program.yScale);
int fontSize = 24;
int availablespace = Width - (portrait.Width + 4);
Font font = new Font("Arial", (float)((fontSize * 0.6) * Program.yScale), FontStyle.Bold, GraphicsUnit.Pixel);
SizeF size;
while ((size = e.Graphics.MeasureString(_player.Name, font)).Width > availablespace)
{
fontSize -= 1;
font = new Font("Arial", (float)((fontSize * 0.6) * Program.yScale), FontStyle.Bold, GraphicsUnit.Pixel);
}
e.Graphics.DrawString(_player.Name, font, new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), portrait.Width + 4, 12);
int verticalSpace = Height - portrait.Height;
Rectangle icon = DrawLeagueImage(e.Graphics, _player.League, _player.Place, 2, portrait.Width + 4, (int)(size.Height + 16 * Program.yScale), Program.xScale, Program.yScale);
if (_player.Place > 0)
{
e.Graphics.DrawString(string.Format("#{0}", _player.Place), new Font("Arial", icon.Height / 2, FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + icon.Width + (int)(4 * Program.xScale), icon.Top + icon.Height - (icon.Height / 2) - 6);
if (_player.Points > -1)
{
e.Graphics.DrawString("P", new Font("Arial", icon.Height / 2, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + (icon.Width / 2), icon.Top + icon.Height);
e.Graphics.DrawString(string.Format("{0}", _player.Points), new Font("Arial", icon.Height / 2, FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + icon.Width + (int)(4 * Program.xScale), icon.Top + icon.Height);
e.Graphics.DrawString("W", new Font("Arial", icon.Height / 2, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + (icon.Width / 2), icon.Top + icon.Height + (icon.Height / 2));
e.Graphics.DrawString(string.Format("{0}", _player.Wins), new Font("Arial", icon.Height / 2, FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + icon.Width + (int)(4 * Program.xScale), icon.Top + icon.Height + (icon.Height / 2));
if (_player.Losses > -1)
{
e.Graphics.DrawString("L", new Font("Arial", icon.Height / 2, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + (icon.Width / 2), icon.Top + icon.Height + ((icon.Height / 2) * 2));
e.Graphics.DrawString(string.Format("{0}", _player.Losses), new Font("Arial", icon.Height / 2, FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(ColorTranslator.FromHtml("#47c5ff")), icon.Left + icon.Width + (int)(4 * Program.xScale), icon.Top + icon.Height + ((icon.Height / 2) * 2));
}
}
}
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams p = base.CreateParams;
p.ExStyle |= (0x08000000 | 8 | Win32.WS_EX_LAYERED);
return p;
}
}
private void frmPlayerInfo_Shown(object sender, EventArgs e)
{
Win32.SetFormTransparency(this, true);
this.TransparencyKey = this.BackColor;
}
private void frmPlayerInfo_FormClosed(object sender, FormClosedEventArgs e)
{
if (Instance == this)
Instance = null;
}
private void tmrClose_Tick(object sender, EventArgs e)
{
tmrClose.Stop();
Close();
}
}
}