-
Notifications
You must be signed in to change notification settings - Fork 244
/
Copy pathMenuWrapper.cs
399 lines (317 loc) · 11.2 KB
/
MenuWrapper.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
#region LICENSE
/*
Copyright 2014 - 2014 LeagueSharp
MenuWrapper.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.Drawing;
using System.Text.RegularExpressions;
#endregion
namespace LeagueSharp.Common
{
public class MenuWrapper
{
private readonly SubMenu _mainMenu;
private readonly Menu _menu;
private readonly Orbwalking.Orbwalker _orbwalker;
private readonly Menu _orbwalkerMenu;
private readonly Menu _targetSelectorMenu;
public MenuWrapper(string menuName, bool addTargetSelector = true, bool addOrbwalker = true)
{
// Create menu
_menu = new Menu(menuName, Regex.Replace(menuName.ToLower(), @"\s+", ""), true);
if (addTargetSelector)
{
// Target selector
_targetSelectorMenu = new Menu("Target Selector", "ts");
TargetSelector.AddToMenu(_targetSelectorMenu);
_menu.AddSubMenu(_targetSelectorMenu);
}
if (addOrbwalker)
{
// Orbwalker
_orbwalkerMenu = new Menu("Orbwalker", "orbwalker");
_orbwalker = new Orbwalking.Orbwalker(_orbwalkerMenu);
_menu.AddSubMenu(_orbwalkerMenu);
}
// Create main menu wrapper
_mainMenu = new SubMenu(_menu);
// Finalize menu
_menu.AddToMainMenu();
}
public SubMenu MainMenu
{
get { return _mainMenu; }
}
public Menu MenuHandle
{
get { return _menu; }
}
public Menu TargetSelectorMenu
{
get { return _targetSelectorMenu; }
}
public Menu OrbwalkerMenu
{
get { return _orbwalkerMenu; }
}
public Orbwalking.Orbwalker Orbwalker
{
get { return _orbwalker; }
}
public class SubMenu
{
public SubMenu Parent { get; private set; }
private readonly Menu _subMenu;
public SubMenu(Menu current)
{
// This initializer is only for existing menus
_subMenu = current;
}
public SubMenu(SubMenu parent, string name)
{
// Initialize this submenu
Parent = parent;
_subMenu = new Menu(name, GetName(name));
// Add submenu to the parent menu
parent.MenuHandle.AddSubMenu(_subMenu);
}
#region SubMenu
public SubMenu AddSubMenu(string name)
{
return new SubMenu(this, name);
}
public SubMenu GetSubMenu(string name)
{
return new SubMenu(_subMenu.SubMenu(GetName(name)));
}
#endregion
#region Boolean
public SubMenu AddBool(string name, bool defaultValue = true)
{
_subMenu.AddItem(new MenuItem(GetName(name), name).SetValue(defaultValue));
return this;
}
public BoolLink AddLinkedBool(string name, bool defaultValue = true)
{
AddBool(name, defaultValue);
return CreateBoolLink(name);
}
public bool GetBool(string name)
{
return _subMenu.Item(GetName(name)).GetValue<bool>();
}
public BoolLink CreateBoolLink(string name)
{
return new BoolLink(this, name);
}
#endregion
#region Circle
public SubMenu AddCircle(string name, bool enabled, Color color, float radius = 100)
{
_subMenu.AddItem(new MenuItem(GetName(name), name).SetValue(new Circle(enabled, color, radius)));
return this;
}
public CircleLink AddLinkedCircle(string name, bool enabled, Color color, float radius = 100)
{
AddCircle(name, enabled, color, radius);
return CreateCircleLink(name);
}
public Circle GetCircle(string name)
{
return _subMenu.Item(GetName(name)).GetValue<Circle>();
}
public CircleLink CreateCircleLink(string name)
{
return new CircleLink(this, name);
}
#endregion
#region KeyBind
public SubMenu AddKeyBind(string name, uint key, KeyBindType type, bool defaultValue = false)
{
_subMenu.AddItem(new MenuItem(GetName(name), name).SetValue(new KeyBind(key, type, defaultValue)));
return this;
}
public KeyBindLink AddLinkedKeyBind(string name, uint key, KeyBindType type, bool defaultValue = false)
{
AddKeyBind(name, key, type, defaultValue);
return CreateKeyBindLink(name);
}
public KeyBind GetKeyBind(string name)
{
return _subMenu.Item(GetName(name)).GetValue<KeyBind>();
}
public KeyBindLink CreateKeyBindLink(string name)
{
return new KeyBindLink(this, name);
}
#endregion
#region Slider
public SubMenu AddSlider(string name, int value, int minValue = 0, int maxValue = 100)
{
_subMenu.AddItem(new MenuItem(GetName(name), name).SetValue(new Slider(value, minValue, maxValue)));
return this;
}
public SliderLink AddLinkedSlider(string name, int value, int minValue = 0, int maxValue = 100)
{
AddSlider(name, value, minValue, maxValue);
return CreateSliderLink(name);
}
public Slider GetSlider(string name)
{
return _subMenu.Item(GetName(name)).GetValue<Slider>();
}
public SliderLink CreateSliderLink(string name)
{
return new SliderLink(this, name);
}
#endregion
#region StringList
public SubMenu AddStringList(string name, string[] sList, int defaultSelectedIndex = 0)
{
_subMenu.AddItem(new MenuItem(GetName(name), name).SetValue(new StringList(sList, defaultSelectedIndex)));
return this;
}
public StringListLink AddLinkedStringList(string name, string[] sList, int defaultSelectedIndex = 0)
{
AddStringList(name, sList, defaultSelectedIndex);
return CreateStringListLink(name);
}
public StringList GetStringList(string name)
{
return _subMenu.Item(GetName(name)).GetValue<StringList>();
}
public StringListLink CreateStringListLink(string name)
{
return new StringListLink(this, name);
}
#endregion
public Menu MenuHandle
{
get { return _subMenu; }
}
private string GetName(string name, bool fullName = true)
{
var prefix = "";
if (fullName)
{
var currentSubMenu = Parent;
while (currentSubMenu != null)
{
prefix = currentSubMenu.MenuHandle.Name + prefix;
currentSubMenu = currentSubMenu.Parent;
}
}
return Regex.Replace(prefix + name.ToLower(), @"\s+", "");
}
}
#region MenuItemLinks
public class BoolLink
{
private readonly SubMenu menu;
private readonly string name;
public BoolLink(SubMenu menu, string name)
{
this.menu = menu;
this.name = name;
}
public bool Value
{
get { return menu.GetBool(name); }
set { menu.MenuHandle.Item(name).SetValue(value); }
}
public SubMenu SubMenu
{
get { return menu; }
}
}
public class CircleLink
{
private readonly SubMenu menu;
private readonly string name;
public CircleLink(SubMenu menu, string name)
{
this.menu = menu;
this.name = name;
}
public Circle Value
{
get { return menu.GetCircle(name); }
set { menu.MenuHandle.Item(name).SetValue(value); }
}
public SubMenu SubMenu
{
get { return menu; }
}
}
public class KeyBindLink
{
private readonly SubMenu menu;
private readonly string name;
public KeyBindLink(SubMenu menu, string name)
{
this.menu = menu;
this.name = name;
}
public KeyBind Value
{
get { return menu.GetKeyBind(name); }
set { menu.MenuHandle.Item(name).SetValue(value); }
}
public SubMenu SubMenu
{
get { return menu; }
}
}
public class SliderLink
{
private readonly SubMenu menu;
private readonly string name;
public SliderLink(SubMenu menu, string name)
{
this.menu = menu;
this.name = name;
}
public Slider Value
{
get { return menu.GetSlider(name); }
set { menu.MenuHandle.Item(name).SetValue(value); }
}
public SubMenu SubMenu
{
get { return menu; }
}
}
public class StringListLink
{
private readonly SubMenu menu;
private readonly string name;
public StringListLink(SubMenu menu, string name)
{
this.menu = menu;
this.name = name;
}
public StringList Value
{
get { return menu.GetStringList(name); }
set { menu.MenuHandle.Item(name).SetValue(value); }
}
public SubMenu SubMenu
{
get { return menu; }
}
}
#endregion
}
}