-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathExampleMenu.cs
More file actions
337 lines (292 loc) · 14.8 KB
/
ExampleMenu.cs
File metadata and controls
337 lines (292 loc) · 14.8 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
using static CitizenFX.Core.Native.API;
using MenuAPI;
namespace TestMenu
{
public class ExampleMenu : BaseScript
{
public ExampleMenu()
{
#if FIVEM
// Setting the menu alignment to be right aligned. This can be changed at any time and it'll update instantly.
// To test this, checkout one of the checkbox items in this example menu. Clicking it will toggle the menu alignment.
MenuController.MenuAlignment = MenuController.MenuAlignmentOption.Right;
#endif
// Creating the first menu.
Menu menu = new Menu("Main Menu", "Subtitle");
MenuController.AddMenu(menu);
// Adding a new button by directly creating one inline. You could also just store it and then add it but we don't need to do that in this example.
menu.AddMenuItem(new MenuItem("Normal Button", "This is a simple button with a simple description. Scroll down for more button types!")
{
Enabled = false,
LeftIcon = MenuItem.Icon.TICK
});
#if FIVEM
// Creating 3 sliders, showing off the 3 possible variations and custom colors.
MenuSliderItem slider = new MenuSliderItem("Slider", 0, 10, 5, false);
MenuSliderItem slider2 = new MenuSliderItem("Slider + Bar", 0, 10, 5, true)
{
BarColor = System.Drawing.Color.FromArgb(255, 73, 233, 111),
BackgroundColor = System.Drawing.Color.FromArgb(255, 25, 100, 43)
};
MenuSliderItem slider3 = new MenuSliderItem("Slider + Bar + Icons", "The icons are currently male/female because that's probably the most common use. But any icon can be used!", 0, 10, 5, true)
{
BarColor = System.Drawing.Color.FromArgb(255, 255, 0, 0),
BackgroundColor = System.Drawing.Color.FromArgb(255, 100, 0, 0),
SliderLeftIcon = MenuItem.Icon.MALE,
SliderRightIcon = MenuItem.Icon.FEMALE
};
// adding the sliders to the menu.
menu.AddMenuItem(slider);
menu.AddMenuItem(slider2);
menu.AddMenuItem(slider3);
#endif
#if FIVEM
// Creating 3 checkboxs, 2 different styles and one has a locked icon and it's 'not enabled' (not enabled meaning you can't toggle it).
MenuCheckboxItem box = new MenuCheckboxItem("Checkbox - Style 1 (click me!)", "This checkbox can toggle the menu position! Try it out.", !menu.LeftAligned)
{
Style = MenuCheckboxItem.CheckboxStyle.Cross
};
#endif
MenuCheckboxItem box2 = new MenuCheckboxItem("Checkbox - Style 2", "This checkbox does nothing right now.", true)
{
Style = MenuCheckboxItem.CheckboxStyle.Tick
};
MenuCheckboxItem box3 = new MenuCheckboxItem("Checkbox (unchecked + locked)", "Make this menu right aligned. If you set this to false, then the menu will move to the left.", false)
{
Enabled = false,
LeftIcon = MenuItem.Icon.LOCK
};
// Adding the checkboxes to the menu.
#if FIVEM
menu.AddMenuItem(box);
#endif
menu.AddMenuItem(box2);
menu.AddMenuItem(box3);
// Dynamic list item
string ChangeCallback(MenuDynamicListItem item, bool left)
{
if (left)
return (int.Parse(item.CurrentItem) - 1).ToString();
return (int.Parse(item.CurrentItem) + 1).ToString();
}
MenuDynamicListItem dynList = new MenuDynamicListItem("Dynamic list item.", "0", new MenuDynamicListItem.ChangeItemCallback(ChangeCallback), "Description for this dynamic item. Pressing left will make the value smaller, pressing right will make the value bigger.");
menu.AddMenuItem(dynList);
#if FIVEM
// List items (first the 3 special variants, then a normal one)
List<string> colorList = new List<string>();
for (var i = 0; i < 64; i++)
{
colorList.Add($"Color #{i}");
}
MenuListItem hairColors = new MenuListItem("Hair Color", colorList, 0, "Hair color pallete.")
{
ShowColorPanel = true
};
// Also special
List<string> makeupColorList = new List<string>();
for (var i = 0; i < 64; i++)
{
makeupColorList.Add($"Color #{i}");
}
MenuListItem makeupColors = new MenuListItem("Makeup Color", makeupColorList, 0, "Makeup color pallete.")
{
ShowColorPanel = true,
ColorPanelColorType = MenuListItem.ColorPanelType.Makeup
};
// Also special
List<string> opacityList = new List<string>();
for (var i = 0; i < 11; i++)
{
opacityList.Add($"Opacity {i * 10}%");
}
MenuListItem opacity = new MenuListItem("Opacity Panel", opacityList, 0, "Set an opacity for something.")
{
ShowOpacityPanel = true
};
menu.AddMenuItem(hairColors);
menu.AddMenuItem(makeupColors);
menu.AddMenuItem(opacity);
#endif
// Normal
List<string> normalList = new List<string>() { "Item #1", "Item #2", "Item #3" };
MenuListItem normalListItem = new MenuListItem("Normal List Item", normalList, 0, "And another simple description for yet another simple (list) item. Nothing special about this one.");
// Adding the lists to the menu.
menu.AddMenuItem(normalListItem);
// Creating a submenu, adding it to the menus list, and creating and binding a button for it.
Menu submenu = new Menu("Submenu", "Secondary Menu");
MenuController.AddSubmenu(menu, submenu);
MenuItem menuButton = new MenuItem("Submenu", "This button is bound to a submenu. Clicking it will take you to the submenu.")
{
#if FIVEM
Label = "→→→"
#endif
#if REDM
RightIcon = MenuItem.Icon.ARROW_RIGHT
#endif
};
menu.AddMenuItem(menuButton);
MenuController.BindMenuItem(menu, submenu, menuButton);
#if FIVEM
var herritageMenu = new HerritageMenu("Herritage");
herritageMenu.AddMenuItem(new MenuListItem("Father", ((Dad[])Enum.GetValues(typeof(Dad))).Select(c => c.ToString()).ToList(), 0, "Choose the father of your character."));
herritageMenu.AddMenuItem(new MenuListItem("Mother", ((Mum[])Enum.GetValues(typeof(Mum))).Select(c => c.ToString()).ToList(), 0, "Choose the mother of your character."));
menu.OnListIndexChange += (_menu, _listItem, _oldIndex, _newIndex, _itemIndex) =>
{
if (_listItem.Text == "Father")
{
(menu as HerritageMenu).CurrentDad = ((Dad)_itemIndex);
}
else if (_listItem.Text == "Mother")
{
(menu as HerritageMenu).CurrentMum = ((Mum)_itemIndex);
}
};
var bindmenu = new MenuItem("Héritage");
menu.AddMenuItem(bindmenu);
MenuController.BindMenuItem(menu, herritageMenu, bindmenu);
#endif
// Adding items with sprites left & right to the submenu.
for (var i = 0; i < Enum.GetValues(typeof(MenuItem.Icon)).Length; i++)
{
var tmpItem = new MenuItem($"Icon.{Enum.GetName(typeof(MenuItem.Icon), ((MenuItem.Icon)i))}", "This menu item has a left and right sprite. Press ~r~HOME~s~ to toggle the 'enabled' state on these items.")
{
Label = $"(#{i})",
#if FIVEM
#endif
RightIcon = (MenuItem.Icon)i,
LeftIcon = (MenuItem.Icon)i
};
//var tmpItem2 = new MenuItem($"Icon.{Enum.GetName(typeof(MenuItem.Icon), ((MenuItem.Icon)i))}", "This menu item has a left and right sprite, and it's ~h~disabled~h~.");
//tmpItem2.LeftIcon = (MenuItem.Icon)i;
//tmpItem2.RightIcon = (MenuItem.Icon)i;
//tmpItem2.Enabled = false;
submenu.AddMenuItem(tmpItem);
//submenu.AddMenuItem(tmpItem2);
}
submenu.ButtonPressHandlers.Add(new Menu.ButtonPressHandler(Control.FrontendSocialClubSecondary, Menu.ControlPressCheckType.JUST_RELEASED, new Action<Menu, Control>((m, c) =>
{
m.GetMenuItems().ForEach(a => a.Enabled = !a.Enabled);
}), true));
#if FIVEM
// Instructional buttons setup for the second (submenu) menu.
submenu.InstructionalButtons.Add(Control.CharacterWheel, "Right?!");
submenu.InstructionalButtons.Add(Control.CursorScrollDown, "Cool");
submenu.InstructionalButtons.Add(Control.CreatorDelete, "Out!");
submenu.InstructionalButtons.Add(Control.Cover, "This");
submenu.InstructionalButtons.Add(Control.Context, "Check");
#endif
// Create a third menu without a banner.
Menu menu3 = new Menu(null, "Only a subtitle, no banner.");
// you can use AddSubmenu or AddMenu, both will work but if you want to link this menu from another menu,
// you should use AddSubmenu.
MenuController.AddSubmenu(menu, menu3);
MenuItem thirdSubmenuBtn = new MenuItem("Another submenu", "This is just a submenu without a banner. No big deal. This also has a very long description to test multiple lines and see if they work properly. Let's find out if it works as intended.")
{
#if FIVEM
Label = "→→→"
#endif
#if REDM
RightIcon = MenuItem.Icon.ARROW_RIGHT
#endif
};
menu.AddMenuItem(thirdSubmenuBtn);
MenuController.BindMenuItem(menu, menu3, thirdSubmenuBtn);
menu3.AddMenuItem(new MenuItem("Nothing here!"));
menu3.AddMenuItem(new MenuItem("Nothing here!"));
menu3.AddMenuItem(new MenuItem("Nothing here!"));
menu3.AddMenuItem(new MenuItem("Nothing here!") { LeftIcon = MenuItem.Icon.TICK });
for (var i = 0; i < 10; i++)
{
menu.AddMenuItem(new MenuItem($"Item #{i + 1}.", "With an invisible description."));
}
/*
########################################################
Event handlers
########################################################
*/
menu.OnCheckboxChange += (_menu, _item, _index, _checked) =>
{
// Code in here gets executed whenever a checkbox is toggled.
Debug.WriteLine($"OnCheckboxChange: [{_menu}, {_item}, {_index}, {_checked}]");
#if FIVEM
// If the align-menu checkbox is toggled, toggle the menu alignment.
if (_item == box)
{
if (_checked)
{
MenuController.MenuAlignment = MenuController.MenuAlignmentOption.Right;
}
else
{
MenuController.MenuAlignment = MenuController.MenuAlignmentOption.Left;
}
}
#endif
};
menu.OnItemSelect += (_menu, _item, _index) =>
{
// Code in here would get executed whenever an item is pressed.
Debug.WriteLine($"OnItemSelect: [{_menu}, {_item}, {_index}]");
};
menu.OnIndexChange += (_menu, _oldItem, _newItem, _oldIndex, _newIndex) =>
{
// Code in here would get executed whenever the up or down key is pressed and the index of the menu is changed.
Debug.WriteLine($"OnIndexChange: [{_menu}, {_oldItem}, {_newItem}, {_oldIndex}, {_newIndex}]");
};
menu.OnListIndexChange += (_menu, _listItem, _oldIndex, _newIndex, _itemIndex) =>
{
// Code in here would get executed whenever the selected value of a list item changes (when left/right key is pressed).
Debug.WriteLine($"OnListIndexChange: [{_menu}, {_listItem}, {_oldIndex}, {_newIndex}, {_itemIndex}]");
};
menu.OnListItemSelect += (_menu, _listItem, _listIndex, _itemIndex) =>
{
// Code in here would get executed whenever a list item is pressed.
Debug.WriteLine($"OnListItemSelect: [{_menu}, {_listItem}, {_listIndex}, {_itemIndex}]");
};
#if FIVEM
menu.OnSliderPositionChange += (_menu, _sliderItem, _oldPosition, _newPosition, _itemIndex) =>
{
// Code in here would get executed whenever the position of a slider is changed (when left/right key is pressed).
Debug.WriteLine($"OnSliderPositionChange: [{_menu}, {_sliderItem}, {_oldPosition}, {_newPosition}, {_itemIndex}]");
};
menu.OnSliderItemSelect += (_menu, _sliderItem, _sliderPosition, _itemIndex) =>
{
// Code in here would get executed whenever a slider item is pressed.
Debug.WriteLine($"OnSliderItemSelect: [{_menu}, {_sliderItem}, {_sliderPosition}, {_itemIndex}]");
};
#endif
menu.OnMenuClose += (_menu) =>
{
// Code in here gets triggered whenever the menu is closed.
Debug.WriteLine($"OnMenuClose: [{_menu}]");
};
menu.OnMenuOpen += (_menu) =>
{
// Code in here gets triggered whenever the menu is opened.
Debug.WriteLine($"OnMenuOpen: [{_menu}]");
};
menu.OnDynamicListItemCurrentItemChange += (_menu, _dynamicListItem, _oldCurrentItem, _newCurrentItem) =>
{
// Code in here would get executed whenever the value of the current item of a dynamic list item changes.
Debug.WriteLine($"OnDynamicListItemCurrentItemChange: [{_menu}, {_dynamicListItem}, {_oldCurrentItem}, {_newCurrentItem}]");
};
menu.OnDynamicListItemSelect += (_menu, _dynamicListItem, _currentItem) =>
{
// Code in here would get executed whenever a dynamic list item is pressed.
Debug.WriteLine($"OnDynamicListItemSelect: [{_menu}, {_dynamicListItem}, {_currentItem}]");
};
//DelayedConstructor();
}
//private async void DelayedConstructor()
//{
// await Delay(1000);
// MenuController.MainMenu.OpenMenu();
//}
}
}