-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.cs
3267 lines (2864 loc) · 103 KB
/
Menu.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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region LICENSE
/*
Copyright 2014 - 2014 LeagueSharp
Menu.cs is part of LeagueSharp.Common.
LeagueSharp.Common 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.
LeagueSharp.Common 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 LeagueSharp.Common. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
#region
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using LeagueSharp.Common.Properties;
using SharpDX;
using SharpDX.Direct3D9;
using Color = System.Drawing.Color;
using Font = SharpDX.Direct3D9.Font;
using Rectangle = SharpDX.Rectangle;
#endregion
namespace LeagueSharp.Common
{
/// <summary>
/// The LeagueSharp.Common Menu
/// </summary>
internal class CommonMenu
{
/// <summary>
/// The configuration
/// </summary>
internal static Menu Config = new Menu("LeagueSharp.Common", "LeagueSharp.Common", true);
/// <summary>
/// Initializes static members of the <see cref="CommonMenu"/> class.
/// </summary>
static CommonMenu()
{
TargetSelector.Initialize();
Prediction.Initialize();
Hacks.Initialize();
FakeClicks.Initialize();
Spell.Initialize();
Config.AddToMainMenu();
}
}
/// <summary>
/// A color picker with an on/off switch.
/// </summary>
[Serializable]
public struct Circle
{
/// <summary>
/// Whether the circle is enabled or not.
/// </summary>
public bool Active;
/// <summary>
/// The color
/// </summary>
public Color Color;
/// <summary>
/// The radius
/// </summary>
public float Radius;
/// <summary>
/// Initializes a new instance of the <see cref="Circle"/> struct.
/// </summary>
/// <param name="enabled">if set to <c>true</c>, the circle is enabled.</param>
/// <param name="color">The color.</param>
/// <param name="radius">The radius.</param>
public Circle(bool enabled, Color color, float radius = 100)
{
Active = enabled;
Color = color;
Radius = radius;
}
}
/// <summary>
/// A slider.
/// </summary>
[Serializable]
public struct Slider
{
/// <summary>
/// The value
/// </summary>
private int _value;
/// <summary>
/// The maximum value
/// </summary>
public int MaxValue;
/// <summary>
/// The minimum value
/// </summary>
public int MinValue;
/// <summary>
/// Initializes a new instance of the <see cref="Slider"/> struct.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="minValue">The minimum value.</param>
/// <param name="maxValue">The maximum value.</param>
public Slider(int value = 0, int minValue = 0, int maxValue = 100)
{
MaxValue = Math.Max(maxValue, minValue);
MinValue = Math.Min(maxValue, minValue);
_value = value;
}
/// <summary>
/// Gets or sets the value.
/// </summary>
/// <value>The value.</value>
public int Value
{
get { return _value; }
set { _value = Math.Min(Math.Max(value, MinValue), MaxValue); }
}
}
/// <summary>
/// A list of strings.
/// </summary>
[Serializable]
public struct StringList
{
/// <summary>
/// The selected index
/// </summary>
public int SelectedIndex;
/// <summary>
/// The string list.
/// </summary>
public string[] SList;
/// <summary>
/// Initializes a new instance of the <see cref="StringList"/> struct.
/// </summary>
/// <param name="sList">The string list.</param>
/// <param name="defaultSelectedIndex">The index of the default option.</param>
public StringList(string[] sList, int defaultSelectedIndex = 0)
{
SList = sList;
SelectedIndex = defaultSelectedIndex;
}
/// <summary>
/// Gets the selected value.
/// </summary>
/// <value>The selected value.</value>
public string SelectedValue
{
get { return SList[SelectedIndex]; }
}
}
/// <summary>
/// Represents the type of keybind.
/// </summary>
public enum KeyBindType
{
/// <summary>
/// The keybind toggles itself on and off.
/// </summary>
Toggle,
/// <summary>
/// The keybind must be pressed to be enabled.
/// </summary>
Press
}
/// <summary>
/// Struct KeyBind
/// </summary>
[Serializable]
public struct KeyBind
{
/// <summary>
/// <c>true</c> if the user is holding the current key down.
/// </summary>
public bool Active;
/// <summary>
/// The key
/// </summary>
public uint Key;
/// <summary>
/// The key bind type
/// </summary>
public KeyBindType Type;
/// <summary>
/// Initializes a new instance of the <see cref="KeyBind"/> struct.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="type">The type.</param>
/// <param name="defaultValue">if set to <c>true</c> [default value].</param>
public KeyBind(uint key, KeyBindType type, bool defaultValue = false)
{
Key = key;
Active = defaultValue;
Type = type;
}
}
/// <summary>
/// Serializes menu settings.
/// </summary>
[Serializable]
internal static class SavedSettings
{
/// <summary>
/// The loaded files
/// </summary>
public static Dictionary<string, Dictionary<string, byte[]>> LoadedFiles =
new Dictionary<string, Dictionary<string, byte[]>>();
/// <summary>
/// Gets the saved data.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="key">The key.</param>
/// <returns>System.Byte[].</returns>
public static byte[] GetSavedData(string name, string key)
{
Dictionary<string, byte[]> dic = null;
dic = LoadedFiles.ContainsKey(name) ? LoadedFiles[name] : Load(name);
if (dic == null)
{
return null;
}
return dic.ContainsKey(key) ? dic[key] : null;
}
/// <summary>
/// Loads the specified name.
/// </summary>
/// <param name="name">The name.</param>
/// <returns>Dictionary<System.String, System.Byte[]>.</returns>
public static Dictionary<string, byte[]> Load(string name)
{
try
{
var fileName = Path.Combine(MenuSettings.MenuConfigPath, name + ".bin");
if (File.Exists(fileName))
{
return Utils.Deserialize<Dictionary<string, byte[]>>(File.ReadAllBytes(fileName));
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
return null;
}
/// <summary>
/// Saves the specified name.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="entries">The entries.</param>
public static void Save(string name, Dictionary<string, byte[]> entries)
{
try
{
Directory.CreateDirectory(MenuSettings.MenuConfigPath);
var fileName = Path.Combine(MenuSettings.MenuConfigPath, name + ".bin");
File.WriteAllBytes(fileName, Utils.Serialize(entries));
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
/// <summary>
/// Global values regarding the menu.
/// </summary>
public static class MenuGlobals
{
/// <summary>
/// <c>true</c> to draw the menu.
/// </summary>
public static bool DrawMenu;
/// <summary>
/// The menu state
/// </summary>
public static List<string> MenuState = new List<string>();
}
/// <summary>
/// The menu settings.
/// </summary>
internal static class MenuSettings
{
/// <summary>
/// The base position
/// </summary>
public static Vector2 BasePosition = new Vector2(10, 10);
/// <summary>
/// If <c>true</c>, draws the menu.
/// </summary>
private static bool _drawTheMenu;
/// <summary>
/// Initializes static members of the <see cref="MenuSettings"/> class.
/// </summary>
static MenuSettings()
{
Game.OnWndProc += Game_OnWndProc;
_drawTheMenu = MenuGlobals.DrawMenu;
}
/// <summary>
/// Gets or sets a value indicating whether to draw the menu.
/// </summary>
/// <value><c>true</c> if we should draw the menu; otherwise, <c>false</c>.</value>
internal static bool DrawMenu
{
get { return _drawTheMenu; }
set
{
_drawTheMenu = value;
MenuGlobals.DrawMenu = value;
}
}
/// <summary>
/// Gets the menu configuration path.
/// </summary>
/// <value>The menu configuration path.</value>
public static string MenuConfigPath
{
get { return Path.Combine(Config.AppDataDirectory, "MenuConfig"); }
}
/// <summary>
/// Gets the width of the menu item.
/// </summary>
/// <value>The width of the menu item.</value>
public static int MenuItemWidth
{
get { return 160; }
}
/// <summary>
/// Gets or sets the size of the menu font.
/// </summary>
/// <value>The size of the menu font.</value>
public static int MenuFontSize { get; set; }
/// <summary>
/// Gets the height of the menu item.
/// </summary>
/// <value>The height of the menu item.</value>
public static int MenuItemHeight
{
get { return 32; }
}
/// <summary>
/// Gets the color of the background.
/// </summary>
/// <value>The color of the background.</value>
public static Color BackgroundColor
{
get { return Color.FromArgb(Menu.root.Item("BackgroundAlpha").GetValue<Slider>().Value, Color.Black); }
}
/// <summary>
/// Gets the color of the active background.
/// </summary>
/// <value>The color of the active background.</value>
public static Color ActiveBackgroundColor
{
get { return Color.FromArgb(0, 37, 53); }
}
/// <summary>
/// Fired when the game receives a window event.
/// </summary>
/// <param name="args">The <see cref="WndEventArgs"/> instance containing the event data.</param>
private static void Game_OnWndProc(WndEventArgs args)
{
if ((args.Msg == (uint)WindowsMessages.WM_KEYUP || args.Msg == (uint)WindowsMessages.WM_KEYDOWN) &&
args.WParam == Config.ShowMenuPressKey)
{
DrawMenu = args.Msg == (uint)WindowsMessages.WM_KEYDOWN;
}
if (args.Msg == (uint)WindowsMessages.WM_KEYUP && args.WParam == Config.ShowMenuToggleKey)
{
DrawMenu = !DrawMenu;
}
}
}
/// <summary>
/// Contains methods to help draw the menu.
/// </summary>
internal static class MenuDrawHelper
{
/// <summary>
/// The fonts.
/// </summary>
internal static Font Font, FontBold;
/// <summary>
/// Initializes static members of the <see cref="MenuDrawHelper"/> class.
/// </summary>
static MenuDrawHelper()
{
Font = new Font(
Drawing.Direct3DDevice,
new FontDescription
{
FaceName = Menu.root.Item("FontName").GetValue<StringList>().SelectedValue,
Height = Menu.root.Item("FontSize").GetValue<Slider>().Value,
OutputPrecision = FontPrecision.Default,
Quality =
(FontQuality)
Enum.Parse(
typeof(FontQuality), Menu.root.Item("FontQuality").GetValue<StringList>().SelectedValue,
true)
});
FontBold = new Font(
Drawing.Direct3DDevice,
new FontDescription
{
FaceName = Menu.root.Item("FontName").GetValue<StringList>().SelectedValue,
Height = Menu.root.Item("FontSize").GetValue<Slider>().Value,
OutputPrecision = FontPrecision.Default,
Weight = FontWeight.Bold,
Quality =
(FontQuality)
Enum.Parse(
typeof(FontQuality), Menu.root.Item("FontQuality").GetValue<StringList>().SelectedValue,
true)
});
Drawing.OnPreReset += Drawing_OnPreReset;
Drawing.OnPostReset += DrawingOnOnPostReset;
AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
}
/// <summary>
/// Fired when the AppDomain is unloaded.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="eventArgs">The <see cref="EventArgs"/> instance containing the event data.</param>
private static void CurrentDomainOnDomainUnload(object sender, EventArgs eventArgs)
{
if (Font != null)
{
Font.Dispose();
Font = null;
}
if (FontBold != null)
{
FontBold.Dispose();
FontBold = null;
}
}
/// <summary>
/// Fired when the DirectX device is reset.
/// </summary>
/// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param>
private static void DrawingOnOnPostReset(EventArgs args)
{
Font.OnResetDevice();
FontBold.OnResetDevice();
}
/// <summary>
/// Fired before the DirectX device is reset.
/// </summary>
/// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param>
private static void Drawing_OnPreReset(EventArgs args)
{
Font.OnLostDevice();
FontBold.OnLostDevice();
}
/// <summary>
/// Draws a box.
/// </summary>
/// <param name="position">The position.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="color">The color.</param>
/// <param name="borderwidth">The border width.</param>
/// <param name="borderColor">Color of the border.</param>
internal static void DrawBox(Vector2 position,
int width,
int height,
Color color,
int borderwidth,
Color borderColor)
{
Drawing.DrawLine(position.X, position.Y, position.X + width, position.Y, height, color);
if (borderwidth > 0)
{
Drawing.DrawLine(position.X, position.Y, position.X + width, position.Y, borderwidth, borderColor);
Drawing.DrawLine(
position.X, position.Y + height, position.X + width, position.Y + height, borderwidth, borderColor);
Drawing.DrawLine(position.X, position.Y, position.X, position.Y + height, borderwidth, borderColor);
Drawing.DrawLine(
position.X + width, position.Y, position.X + width, position.Y + height, borderwidth, borderColor);
}
}
/// <summary>
/// Draws the on off toggle switch.
/// </summary>
/// <param name="on">if set to <c>true</c> draws the switch as on.</param>
/// <param name="position">The position.</param>
/// <param name="item">The item.</param>
internal static void DrawOnOff(bool on, Vector2 position, MenuItem item)
{
DrawBox(position, item.Height, item.Height, on ? Color.FromArgb(1, 169, 234) : Color.FromArgb(37, 37, 37), 1, Color.Black);
var s = on ? "ON" : "OFF";
Font.DrawText(
null, s,
new Rectangle(
(int)(item.Position.X + item.Width - item.Height), (int)item.Position.Y, item.Height, item.Height),
FontDrawFlags.VerticalCenter | FontDrawFlags.Center, new ColorBGRA(255, 255, 255, 255));
}
/// <summary>
/// Draws an arrow.
/// </summary>
/// <param name="s">The string.</param>
/// <param name="position">The position.</param>
/// <param name="item">The item.</param>
/// <param name="color">The color.</param>
internal static void DrawArrow(string s, Vector2 position, MenuItem item, Color color)
{
DrawBox(position, item.Height, item.Height, Color.FromArgb(0, 37, 53), 1, color);
Font.DrawText(
null, s, new Rectangle((int)(position.X), (int)item.Position.Y, item.Height, item.Height),
FontDrawFlags.VerticalCenter | FontDrawFlags.Center, new ColorBGRA(255, 255, 255, 255));
}
/// <summary>
/// Draws a slider.
/// </summary>
/// <param name="position">The position.</param>
/// <param name="item">The item.</param>
/// <param name="width">The width.</param>
/// <param name="drawText">if set to <c>true</c> draws the text.</param>
internal static void DrawSlider(Vector2 position, MenuItem item, int width = -1, bool drawText = true)
{
var val = item.GetValue<Slider>();
DrawSlider(position, item, val.MinValue, val.MaxValue, val.Value, width, drawText);
}
/// <summary>
/// Draws a slider.
/// </summary>
/// <param name="position">The position.</param>
/// <param name="item">The item.</param>
/// <param name="min">The minimum.</param>
/// <param name="max">The maximum.</param>
/// <param name="value">The value.</param>
/// <param name="width">The width.</param>
/// <param name="drawText">if set to <c>true</c> draws the text.</param>
internal static void DrawSlider(Vector2 position,
MenuItem item,
int min,
int max,
int value,
int width,
bool drawText)
{
width = (width > 0 ? width : item.Width);
var percentage = 100 * (value - min) / (max - min);
var x = position.X + 3 + (percentage * (width - 3)) / 100;
var x2D = 3 + (percentage * (width - 3)) / 100;
Drawing.DrawLine(x, position.Y + 2, x, position.Y + item.Height, 2, Color.FromArgb(0, 74, 103));
DrawBox(new Vector2(position.X, position.Y), x2D - 2, item.Height, Color.FromArgb(0, 37, 53), 0, Color.Black);
if (drawText)
{
Font.DrawText(
null, value.ToString(),
new Rectangle((int)position.X - 5, (int)position.Y, item.Width, item.Height),
FontDrawFlags.VerticalCenter | FontDrawFlags.Right, new ColorBGRA(255, 255, 255, 255));
}
}
/// <summary>
/// Draws a tool tip button.
/// </summary>
/// <param name="position">The position.</param>
/// <param name="item">The item.</param>
internal static void DrawToolTip_Button(Vector2 position, MenuItem item)
{
if (item.ValueType == MenuValueType.StringList)
{
return;
}
var s = "[?]";
int x = (int) item.Position.X + item.Width - item.Height - Font.MeasureText(s).Width - 7;
Font.DrawText(null, s,
new Rectangle(x, (int)item.Position.Y, item.Width, item.Height),
FontDrawFlags.VerticalCenter,
new ColorBGRA(255, 255, 255, 255));
}
/// <summary>
/// Draws the tool tip text.
/// </summary>
/// <param name="position">The position.</param>
/// <param name="item">The item.</param>
/// <param name="TextColor">Color of the text.</param>
internal static void DrawToolTip_Text(Vector2 position, MenuItem item, SharpDX.Color? TextColor = null)
{
if (item.ValueType == MenuValueType.StringList)
{
return;
}
DrawBox(new Vector2(position.X + item.Height - 28, position.Y + 1),
(int) Font.MeasureText(item.Tooltip).Width + 8, item.Height, MenuSettings.BackgroundColor, 1, Color.Black);
var s = item.Tooltip;
Font.DrawText(
null, s,
new Rectangle(
(int) (item.Position.X + item.Width - 33 + item.Height + 8), (int) item.Position.Y - 3,
Font.MeasureText(item.Tooltip).Width + 8, item.Height + 8),
FontDrawFlags.VerticalCenter, TextColor ?? SharpDX.Color.White);
}
}
/// <summary>
/// A menu.
/// </summary>
public class Menu
{
/// <summary>
/// The root menus
/// </summary>
public static Dictionary<string, Menu> RootMenus = new Dictionary<string, Menu>();
/// <summary>
/// The root menu
/// </summary>
public static readonly Menu root = new Menu("Menu Settings", "Menu Settings");
/// <summary>
/// The cached menu count
/// </summary>
private int _cachedMenuCount = 2;
/// <summary>
/// The cached menu count tick
/// </summary>
private int _cachedMenuCountT;
/// <summary>
/// If the menu is visible
/// </summary>
private bool _visible;
/// <summary>
/// The children
/// </summary>
public List<Menu> Children = new List<Menu>();
/// <summary>
/// The color
/// </summary>
public SharpDX.Color Color;
/// <summary>
/// The display name
/// </summary>
public string DisplayName;
/// <summary>
/// Whether this instance is a root menu.
/// </summary>
public bool IsRootMenu;
/// <summary>
/// The menu items
/// </summary>
public List<MenuItem> Items = new List<MenuItem>();
/// <summary>
/// The name
/// </summary>
public string Name;
/// <summary>
/// The parent menu
/// </summary>
public Menu Parent;
/// <summary>
/// The font style
/// </summary>
public FontStyle Style;
/// <summary>
/// The unique identifier
/// </summary>
private string uniqueId;
/// <summary>
/// Initializes static members of the <see cref="Menu"/> class.
/// </summary>
static Menu()
{
root.AddItem(new MenuItem("BackgroundAlpha", "Background Opacity")).SetValue(new Slider(165, 55, 255));
root.AddItem(
new MenuItem("FontName", "Font Name:").SetValue(
new StringList(new[] { "Tahoma", "Calibri", "Segoe UI" }, 0)));
root.AddItem(new MenuItem("FontSize", "Font Size:").SetValue(new Slider(13, 12, 20)));
var qualities = Enum.GetValues(typeof(FontQuality)).Cast<FontQuality>().Select(v => v.ToString()).ToArray();
root.AddItem(new MenuItem("FontQuality", "Font Quality").SetValue(new StringList(qualities, 4)));
root.AddItem(
new MenuItem("LeagueSharp.Common.TooltipDuration", "Tooltip Notification Duration").SetValue(
new Slider(1500, 0, 5000)));
root.AddItem(
new MenuItem("FontInfo", "Press F5 after your change").SetFontStyle(FontStyle.Bold, SharpDX.Color.Yellow));
CommonMenu.Config.AddSubMenu(root);
}
/// <summary>
/// Initializes a new instance of the <see cref="Menu"/> class.
/// </summary>
/// <param name="displayName">The display name.</param>
/// <param name="name">The name.</param>
/// <param name="isRootMenu">if set to <c>true</c> [is root menu].</param>
public Menu(string displayName,
string name,
bool isRootMenu = false)
{
DisplayName = displayName;
Name = name;
IsRootMenu = isRootMenu;
Style = FontStyle.Regular;
Color = SharpDX.Color.White;
if (isRootMenu)
{
CustomEvents.Game.OnGameEnd += delegate { SaveAll(); };
Game.OnEnd += delegate { SaveAll(); };
AppDomain.CurrentDomain.DomainUnload += delegate { SaveAll(); };
AppDomain.CurrentDomain.ProcessExit += delegate { SaveAll(); };
var rootName = Assembly.GetCallingAssembly().GetName().Name + "." + name;
if (RootMenus.ContainsKey(rootName))
{
throw new ArgumentException("Root Menu [" + rootName + "] with the same name exists", "name");
}
RootMenus.Add(rootName, this);
}
}
/// <summary>
/// Sets the font style.
/// </summary>
/// <param name="fontStyle">The font style.</param>
/// <param name="fontColor">Color of the font.</param>
/// <returns>Menu.</returns>
public Menu SetFontStyle(FontStyle fontStyle = FontStyle.Regular, SharpDX.Color? fontColor = null)
{
Style = fontStyle;
Color = fontColor ?? SharpDX.Color.White;
return this;
}
/// <summary>
/// Gets the x level.
/// </summary>
/// <value>The x level.</value>
internal int XLevel
{
get
{
var result = 0;
var m = this;
while (m.Parent != null)
{
m = m.Parent;
result++;
}
return result;
}
}
/// <summary>
/// Gets the y level.
/// </summary>
/// <value>The y level.</value>
internal int YLevel
{
get
{
if (IsRootMenu || Parent == null)
{
return 0;
}
return Parent.YLevel + Parent.Children.TakeWhile(test => test.Name != Name).Count();
}
}
/// <summary>
/// Gets the menu count.
/// </summary>
/// <value>The menu count.</value>
internal int MenuCount
{
get
{
if (Utils.TickCount - _cachedMenuCountT < 500)
{
return _cachedMenuCount;
}
var globalMenuList = MenuGlobals.MenuState;
var i = 0;
var result = 0;
foreach (var item in globalMenuList)
{
if (item == uniqueId)
{
result = i;
break;
}
i++;
}
_cachedMenuCount = result;
_cachedMenuCountT = Utils.TickCount;
return result;
}
}
/// <summary>
/// Gets the base position.
/// </summary>
/// <value>The base position.</value>
internal Vector2 MyBasePosition
{
get
{
if (IsRootMenu || Parent == null)
{
return MenuSettings.BasePosition + MenuCount * new Vector2(0, MenuSettings.MenuItemHeight);
}
return Parent.MyBasePosition;
}
}
/// <summary>
/// Gets the position.
/// </summary>
/// <value>The position.</value>
internal Vector2 Position
{
get
{
var xOffset = 0;
if (Parent != null)
{
xOffset = (int)(Parent.Position.X + Parent.Width);
}
else
{
xOffset = (int)MyBasePosition.X;
}
return new Vector2(0, MyBasePosition.Y) + new Vector2(xOffset, 0) +
YLevel * new Vector2(0, MenuSettings.MenuItemHeight);
}
}
/// <summary>
/// Gets the width of the children menu.
/// </summary>
/// <value>The width of the children menu.</value>
internal int ChildrenMenuWidth
{
get
{
var result = Children.Select(item => item.NeededWidth).Concat(new[] { 0 }).Max();
return Items.Select(item => item.NeededWidth).Concat(new[] { result }).Max();
}
}
/// <summary>
/// Gets the width.
/// </summary>
/// <value>The width.</value>
internal int Width
{
get { return Parent != null ? Parent.ChildrenMenuWidth : MenuSettings.MenuItemWidth; }
}
/// <summary>
/// Gets the needed width
/// </summary>
/// <value>The needed width</value>
internal int NeededWidth
{
get { return MenuDrawHelper.Font.MeasureText(MultiLanguage._(DisplayName)).Width + 25; }
}
/// <summary>
/// Gets the height.
/// </summary>
/// <value>The height.</value>
internal int Height
{
get { return MenuSettings.MenuItemHeight; }
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Menu"/> is visible.
/// </summary>
/// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
internal bool Visible
{
get
{
if (!MenuSettings.DrawMenu)
{
return false;
}
return IsRootMenu || _visible;
}
set
{
_visible = value;
//Hide all the children
if (!_visible)
{
foreach (var schild in Children)
{
schild.Visible = false;
}
foreach (var sitem in Items)
{
sitem.Visible = false;
}
}