-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathHUDInfo.cs
621 lines (540 loc) · 19.3 KB
/
HUDInfo.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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
// <copyright file="HUDInfo.cs" company="EnsageSharp">
// Copyright (c) 2017 EnsageSharp.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/
// </copyright>
namespace Ensage.Common
{
using System;
using System.Collections.Generic;
using Ensage.Common.Menu;
using Ensage.Common.Objects.UtilityObjects;
using SharpDX;
using Rectangle = Ensage.Common.Objects.RenderObjects.Rectangle;
/// <summary>
/// Class used for locating several HUD positions
/// </summary>
public static class HUDInfo
{
#region Constants
/// <summary>
/// The map bottom.
/// </summary>
private const float MapBottom = -7521;
/// <summary>
/// The map left.
/// </summary>
private const float MapLeft = -8068;
/// <summary>
/// The map right.
/// </summary>
private const float MapRight = 7933;
/// <summary>
/// The map top.
/// </summary>
private const float MapTop = 7679;
#endregion
#region Static Fields
/// <summary>
/// The dire compare.
/// </summary>
private static readonly double DireCompare;
/// <summary>
/// The health bar height.
/// </summary>
private static readonly double HpBarHeight;
/// <summary>
/// The health bar width.
/// </summary>
private static readonly double HpBarWidth;
/// <summary>
/// The player id dictionary.
/// </summary>
private static readonly Dictionary<float, int> PlayerIdDictionary = new Dictionary<float, int>();
/// <summary>
/// The radiant compare.
/// </summary>
private static readonly double RadiantCompare;
/// <summary>
/// The rate.
/// </summary>
private static readonly float Rate;
/// <summary>
/// The screen size.
/// </summary>
private static readonly Vector2 ScreenSize;
/// <summary>
/// The x.
/// </summary>
private static readonly double X;
/// <summary>
/// The map height.
/// </summary>
private static float mapHeight = Math.Abs(MapBottom - MapTop);
/// <summary>
/// The map width.
/// </summary>
private static float mapWidth = Math.Abs(MapLeft - MapRight);
/// <summary>
/// The current minimap.
/// </summary>
private static Minimap minimap;
private static bool minimapIsOnRight1;
private static float minimapMapScaleX;
private static float minimapMapScaleY;
private static Rectangle rectangle;
/// <summary>
/// The y.
/// </summary>
private static double y;
#endregion
#region Constructors and Destructors
/// <summary>
/// Initializes static members of the <see cref="HUDInfo" /> class.
/// </summary>
static HUDInfo()
{
double tinfoHeroDown;
double panelHeroSizeX;
float compareWidth;
ScreenSize = new Vector2(Drawing.Width, Drawing.Height);
if (ScreenSize.X == 0)
{
Console.WriteLine("Ensage couldnt determine your resolution, try to launch in window mode");
return;
}
minimap = new Minimap(new Vector2(-2, 1), new Vector2(0));
var ratio = Math.Floor((decimal)(ScreenSize.X / ScreenSize.Y * 100));
var largeMinimap = Game.GetConsoleVar("dota_hud_extra_large_minimap").GetInt() == 1;
// Console.WriteLine("Your screen ratio is " + ratio);
if (ratio == 213)
{
compareWidth = 1600;
panelHeroSizeX = 45.28;
tinfoHeroDown = 25.714;
DireCompare = 2.402;
RadiantCompare = 3.08;
HpBarHeight = 7;
HpBarWidth = 69;
HpBarX = 36;
HpBarY = 23;
minimap.Size = new Vector2(0.1070833333333333f * ScreenSize.X, 0.2240740740740741f * ScreenSize.Y);
minimapMapScaleX = minimap.Size.X / mapWidth;
minimapMapScaleY = minimap.Size.Y / mapHeight;
}
else if (ratio == 177)
{
compareWidth = 1600;
panelHeroSizeX = 52.8900000000004;
tinfoHeroDown = 25.714;
DireCompare = 2.5001;
RadiantCompare = 3.409;
HpBarHeight = 10;
HpBarWidth = 86.5;
HpBarX = 44;
HpBarY = 27;
minimap.Size = new Vector2(0.1280833333333333f * ScreenSize.X, 0.2240740740740741f * ScreenSize.Y);
minimapMapScaleX = minimap.Size.X / mapWidth;
minimapMapScaleY = minimap.Size.Y / mapHeight;
}
else if (ratio == 166)
{
compareWidth = 1280;
panelHeroSizeX = 47.19;
tinfoHeroDown = 25.714;
DireCompare = 2.59;
RadiantCompare = 3.64;
HpBarHeight = 7.4;
HpBarWidth = 71;
HpBarX = 37;
HpBarY = 22;
minimap.Size = new Vector2(0.1370833333333333f * ScreenSize.X, 0.2240740740740741f * ScreenSize.Y);
minimapMapScaleX = minimap.Size.X / mapWidth;
minimapMapScaleY = minimap.Size.Y / mapHeight;
}
else if (ratio == 160)
{
compareWidth = 1280;
panelHeroSizeX = 48.95;
tinfoHeroDown = 25.714;
DireCompare = 2.609;
RadiantCompare = 3.78;
HpBarHeight = 9;
HpBarWidth = 75;
HpBarX = 38.3;
HpBarY = 25;
minimap.Size = new Vector2(0.1425833333333333f * ScreenSize.X, 0.2240740740740741f * ScreenSize.Y);
minimapMapScaleX = minimap.Size.X / mapWidth;
minimapMapScaleY = minimap.Size.Y / mapHeight;
}
else if (ratio == 150)
{
compareWidth = 1024;
panelHeroSizeX = 47.21;
tinfoHeroDown = 25.714;
DireCompare = 2.775;
RadiantCompare = 4.57;
HpBarHeight = 8;
HpBarWidth = 79.2;
HpBarX = 40.2;
HpBarY = 24;
minimap.Size = new Vector2(0.1500233333333333f * ScreenSize.X, 0.2200940740740741f * ScreenSize.Y);
minimapMapScaleX = minimap.Size.X / mapWidth;
minimapMapScaleY = minimap.Size.Y / mapHeight;
}
else if (ratio == 133)
{
compareWidth = 1280;
panelHeroSizeX = 58.3;
tinfoHeroDown = 25.714;
DireCompare = 2.78;
RadiantCompare = 4.65;
HpBarHeight = 8;
HpBarWidth = 71;
HpBarX = 36.6;
HpBarY = 23;
minimap.Size = new Vector2(0.1690833333333333f * ScreenSize.X, 0.2225740740740741f * ScreenSize.Y);
minimapMapScaleX = minimap.Size.X / mapWidth;
minimapMapScaleY = minimap.Size.Y / mapHeight;
}
else if (ratio == 125)
{
compareWidth = 1280;
panelHeroSizeX = 58.3;
tinfoHeroDown = 25.714;
DireCompare = 2.78;
RadiantCompare = 4.65;
HpBarHeight = 11;
HpBarWidth = 96.5;
HpBarX = 49;
HpBarY = 32;
minimap.Size = new Vector2(0.1850833333333333f * ScreenSize.X, 0.2240740740740741f * ScreenSize.Y);
minimapMapScaleX = minimap.Size.X / mapWidth;
minimapMapScaleY = minimap.Size.Y / mapHeight;
}
else
{
Console.WriteLine(
@"Your screen resolution is not supported and drawings might have wrong size/position, (" + ratio
+ ")");
compareWidth = 1600;
panelHeroSizeX = 65;
tinfoHeroDown = 25.714;
DireCompare = 2.655;
RadiantCompare = 5.985;
HpBarHeight = 10;
HpBarWidth = 83.5;
HpBarX = 43;
HpBarY = 28;
minimap.Size = new Vector2(0.1270833333333333f * ScreenSize.X, 0.2240740740740741f * ScreenSize.Y);
minimapMapScaleX = minimap.Size.X / mapWidth;
minimapMapScaleY = minimap.Size.Y / mapHeight;
}
if (largeMinimap)
{
const float LargeMinimapConstant = 1.1470833333333333f; // © Moones 2017
minimap.Size *= LargeMinimapConstant;
minimapMapScaleX = minimap.Size.X / mapWidth;
minimapMapScaleY = minimap.Size.Y / mapHeight;
}
Monitor = ScreenSize.X / compareWidth;
Rate = Math.Max(Monitor, 1);
X = panelHeroSizeX * Monitor;
y = ScreenSize.Y / tinfoHeroDown;
var menu = new Menu.Menu("HUDInfo", nameof(HUDInfo));
var minimapOnRight = menu.AddItem(
new MenuItem(menu.Name + "minimapRight", "Minimap is on the right").SetValue(false).SetTooltip("Enable this if you have minimap on the right"));
minimapOnRight.ValueChanged += (sender, args) => { MinimapIsOnRight = args.GetNewValue<bool>(); };
MinimapIsOnRight = minimapOnRight.GetValue<bool>();
DelayAction.Add(200, () => Menu.Menu.Root.AddSubMenu(menu));
}
#endregion
#region Public Properties
/// <summary>
/// The health bar x.
/// </summary>
public static double HpBarX { get; set; }
/// <summary>
/// The health bar y.
/// </summary>
public static float HpBarY { get; set; }
/// <summary>
/// The current minimap.
/// </summary>
public static Minimap Minimap
{
get
{
return minimap;
}
set
{
minimap = value;
}
}
/// <summary>The minimap is on right.</summary>
public static bool MinimapIsOnRight
{
get
{
return minimapIsOnRight1;
}
set
{
minimapIsOnRight1 = value;
if (rectangle != null)
{
rectangle.Position = new Vector3(MapLeft, MapTop, 0).WorldToMinimap();
}
}
}
/// <summary>
/// The monitor.
/// </summary>
public static float Monitor { get; set; }
/// <summary>
/// Gets the mouse position from minimap.
/// </summary>
public static Vector2 MousePositionFromMinimap
{
get
{
var mouse = Game.MouseScreenPosition;
var scaledX = mouse.X - minimap.Position.X;
var scaledY = ScreenSize.Y - mouse.Y - minimap.Position.Y;
var x = scaledX / minimapMapScaleX + MapLeft;
var y = scaledY / minimapMapScaleY + MapBottom;
if (Math.Abs(x) > 7900 || Math.Abs(y) > 7200)
{
return Vector2.Zero;
}
return new Vector2(x, y);
}
}
#endregion
#region Public Methods and Operators
/// <summary>
/// Returns HealthBar position for given unit
/// </summary>
/// <param name="unit">
/// The unit.
/// </param>
/// <returns>
/// The <see cref="Vector2" />.
/// </returns>
public static Vector2 GetHPbarPosition(Unit unit)
{
var pos = unit.Position + new Vector3(0, 0, unit.HealthBarOffset);
Vector2 screenPos;
if (!Drawing.WorldToScreen(pos, out screenPos))
{
return Vector2.Zero;
}
var localHero = ObjectManager.LocalHero;
if (localHero != null && Equals(unit, localHero))
{
if (unit.NetworkName == "CDOTA_Unit_Hero_Meepo")
{
return screenPos + new Vector2((float)(-HpBarX * 1.05 * Monitor), (float)(-HpBarY * 1.3 * Monitor));
}
return screenPos + new Vector2((float)(-HpBarX * 1.05 * Monitor), (float)(-HpBarY * 1.38 * Monitor));
}
return screenPos + new Vector2((float)(-HpBarX * Monitor), -HpBarY * Monitor);
}
/// <summary>
/// Returns HealthBar X position for given unit
/// </summary>
/// <param name="unit">
/// The unit.
/// </param>
/// <returns>
/// The <see cref="float" />.
/// </returns>
public static float GetHPBarSizeX(Unit unit = null)
{
var hero = ObjectManager.LocalHero;
if (unit != null && hero != null && Equals(unit.Handle, hero.Handle))
{
return (float)((float)HpBarWidth * Monitor * 1.08);
}
return (float)HpBarWidth * Monitor;
}
/// <summary>
/// Returns HealthBar Y position for given unit
/// </summary>
/// <param name="unit">
/// The unit.
/// </param>
/// <returns>
/// The <see cref="float" />.
/// </returns>
public static float GetHpBarSizeY(Unit unit = null)
{
var hero = ObjectManager.LocalHero;
if (unit != null && hero != null && Equals(unit, hero))
{
return (float)(HpBarHeight * Monitor * 1.05);
}
return (float)(HpBarHeight * Monitor);
}
/// <summary>
/// Returns top panel position for given hero
/// </summary>
/// <param name="hero">
/// The hero.
/// </param>
/// <returns>
/// The <see cref="Vector2" />.
/// </returns>
public static Vector2 GetTopPanelPosition(Hero hero)
{
int id;
if (hero.Player == null)
{
if (PlayerIdDictionary.ContainsKey(hero.Handle))
{
id = PlayerIdDictionary[hero.Handle];
}
else
{
return Vector2.Zero;
}
}
else
{
id = hero.Player.Id;
}
if (!PlayerIdDictionary.ContainsKey(hero.Handle))
{
PlayerIdDictionary.Add(hero.Handle, id);
}
else
{
PlayerIdDictionary[hero.Handle] = id;
}
return new Vector2((float)(GetXX(hero) - 20 * Monitor + X * id), 0);
}
/// <summary>
/// Returns top panel hero icon width
/// </summary>
/// <param name="hero">
/// The hero.
/// </param>
/// <returns>
/// The <see cref="double" />.
/// </returns>
public static double GetTopPanelSizeX(Hero hero = null)
{
return X;
}
/// <summary>
/// Returns top panel hero icon height
/// </summary>
/// <param name="hero">
/// The hero.
/// </param>
/// <returns>
/// The <see cref="double" />.
/// </returns>
public static double GetTopPanelSizeY(Hero hero = null)
{
return 35 * Rate;
}
/// <summary>
/// The ratio percentage.
/// </summary>
/// <returns>
/// The <see cref="float" />.
/// </returns>
public static float RatioPercentage()
{
return Monitor;
}
/// <summary>
/// Returns screen width
/// </summary>
/// <returns>
/// The <see cref="float" />.
/// </returns>
public static float ScreenSizeX()
{
return ScreenSize.X;
}
/// <summary>
/// Returns screen height
/// </summary>
/// <returns>
/// The <see cref="float" />.
/// </returns>
public static float ScreenSizeY()
{
return ScreenSize.Y;
}
/// <summary>
/// The world to minimap.
/// </summary>
/// <param name="mapPosition">
/// The map position.
/// </param>
/// <returns>
/// The <see cref="Vector2" />.
/// </returns>
public static Vector2 WorldToMinimap(this Vector3 mapPosition)
{
var x = mapPosition.X - MapLeft;
var y = mapPosition.Y - MapBottom;
var scaledX = Math.Min(Math.Max(x * minimapMapScaleX, 0), minimap.Size.X);
var scaledY = Math.Min(Math.Max(y * minimapMapScaleY, 0), minimap.Size.Y);
float screenX;
if (!MinimapIsOnRight)
{
screenX = minimap.Position.X + scaledX;
}
else
{
screenX = ScreenSize.X - minimap.Position.X + scaledX - minimap.Size.X;
}
var screenY = ScreenSize.Y - scaledY - minimap.Position.Y;
return new Vector2((float)Math.Floor(screenX), (float)Math.Floor(screenY));
}
#endregion
#region Methods
private static void Drawing_OnDraw(EventArgs args)
{
var mousePos = Game.MousePosition;
if (Utils.SleepCheck("mouse"))
{
Console.WriteLine(mousePos);
Utils.Sleep(500, "mouse");
}
Drawing.DrawRect(mousePos.WorldToMinimap(), new Vector2(5, 5), Color.White);
}
/// <summary>
/// The get xx.
/// </summary>
/// <param name="hero">
/// The hero.
/// </param>
/// <returns>
/// The <see cref="double" />.
/// </returns>
private static double GetXX(Entity hero)
{
var screenSize = new Vector2(Drawing.Width, Drawing.Height);
if (hero.Team == Team.Radiant)
{
return screenSize.X / RadiantCompare + 1;
}
return screenSize.X / DireCompare + 1;
}
#endregion
}
}