Skip to content

Commit 8a46eeb

Browse files
committed
Example menu cleanup
1 parent 4e4d71d commit 8a46eeb

File tree

2 files changed

+80
-51
lines changed

2 files changed

+80
-51
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
FiveM C# Menu API.
44

5+
[![CodeFactor](https://www.codefactor.io/repository/github/tomgrobbe/menuapi/badge)](https://www.codefactor.io/repository/github/tomgrobbe/menuapi) [![Build status](https://ci.appveyor.com/api/projects/status/8nqoeyg0e9rn10ih/branch/master?svg=true)](https://ci.appveyor.com/project/TomGrobbe/menuapi/branch/master) [![Discord](https://discordapp.com/api/guilds/285424882534187008/widget.png)](https://vespura.com/discord) [![Patreon](https://img.shields.io/badge/donate-Patreon-orange.svg)](https://www.patreon.com/vespura)
6+
57
Designed specifically as a replacement of NativeUI for vMenu with improved performance (somewhat), more features, less bugs, and easier to use functions (somewhat).
68

79
Full safezone scaling supported, both left and right aligned menus supported.

TestMenu/ExampleMenu.cs

Lines changed: 78 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@ public ExampleMenu()
1818
// To test this, checkout one of the checkbox items in this example menu. Clicking it will toggle the menu alignment.
1919
MenuController.MenuAlignment = MenuController.MenuAlignmentOption.Right;
2020
#endif
21-
2221
// Creating the first menu.
2322
Menu menu = new Menu("Main Menu", "Subtitle");
2423
MenuController.AddMenu(menu);
2524

26-
// 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.
27-
menu.AddMenuItem(new MenuItem("Normal Button", "This is a simple button with a simple description. Scroll down for more button types!")
28-
{
29-
Enabled = false,
30-
LeftIcon = MenuItem.Icon.TICK
31-
});
32-
25+
// Adding a new button by directly creating one inline.
26+
// You could also just store it and then add it but we don't need to do that in this example.
27+
menu.AddMenuItem(
28+
new MenuItem(
29+
"Normal Button",
30+
"This is a simple button with a simple description. Scroll down for more button types!"
31+
)
32+
{
33+
Enabled = false,
34+
LeftIcon = MenuItem.Icon.TICK
35+
}
36+
);
3337
#if FIVEM
3438
// Creating 3 sliders, showing off the 3 possible variations and custom colors.
3539
MenuSliderItem slider = new MenuSliderItem("Slider", 0, 10, 5, false);
@@ -38,34 +42,51 @@ public ExampleMenu()
3842
BarColor = System.Drawing.Color.FromArgb(255, 73, 233, 111),
3943
BackgroundColor = System.Drawing.Color.FromArgb(255, 25, 100, 43)
4044
};
41-
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)
45+
MenuSliderItem slider3 = new MenuSliderItem(
46+
"Slider + Bar + Icons",
47+
"The icons are currently male/female because that's probably the most common use. But any icon can be used!",
48+
0,
49+
10,
50+
5,
51+
true
52+
)
4253
{
4354
BarColor = System.Drawing.Color.FromArgb(255, 255, 0, 0),
4455
BackgroundColor = System.Drawing.Color.FromArgb(255, 100, 0, 0),
45-
4656
SliderLeftIcon = MenuItem.Icon.MALE,
4757
SliderRightIcon = MenuItem.Icon.FEMALE
4858
};
59+
4960
// adding the sliders to the menu.
5061
menu.AddMenuItem(slider);
5162
menu.AddMenuItem(slider2);
5263
menu.AddMenuItem(slider3);
53-
5464
#endif
55-
5665
#if FIVEM
5766
// 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).
58-
MenuCheckboxItem box = new MenuCheckboxItem("Checkbox - Style 1 (click me!)", "This checkbox can toggle the menu position! Try it out.", !menu.LeftAligned)
67+
MenuCheckboxItem box = new MenuCheckboxItem(
68+
"Checkbox - Style 1 (click me!)",
69+
"This checkbox can toggle the menu position! Try it out.",
70+
!menu.LeftAligned
71+
)
5972
{
6073
Style = MenuCheckboxItem.CheckboxStyle.Cross
6174
};
6275
#endif
63-
MenuCheckboxItem box2 = new MenuCheckboxItem("Checkbox - Style 2", "This checkbox does nothing right now.", true)
76+
MenuCheckboxItem box2 = new MenuCheckboxItem(
77+
"Checkbox - Style 2",
78+
"This checkbox does nothing right now.",
79+
true
80+
)
6481
{
6582
Style = MenuCheckboxItem.CheckboxStyle.Tick
6683
};
6784

68-
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)
85+
MenuCheckboxItem box3 = new MenuCheckboxItem(
86+
"Checkbox (unchecked + locked)",
87+
"Make this menu right aligned. If you set this to false, then the menu will move to the left.",
88+
false
89+
)
6990
{
7091
Enabled = false,
7192
LeftIcon = MenuItem.Icon.LOCK
@@ -85,7 +106,12 @@ string ChangeCallback(MenuDynamicListItem item, bool left)
85106
return (int.Parse(item.CurrentItem) - 1).ToString();
86107
return (int.Parse(item.CurrentItem) + 1).ToString();
87108
}
88-
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.");
109+
MenuDynamicListItem dynList = new MenuDynamicListItem(
110+
"Dynamic list item.",
111+
"0",
112+
new MenuDynamicListItem.ChangeItemCallback(ChangeCallback),
113+
"Description for this dynamic item. Pressing left will make the value smaller, pressing right will make the value bigger."
114+
);
89115
menu.AddMenuItem(dynList);
90116
#if FIVEM
91117
// List items (first the 3 special variants, then a normal one)
@@ -94,7 +120,12 @@ string ChangeCallback(MenuDynamicListItem item, bool left)
94120
{
95121
colorList.Add($"Color #{i}");
96122
}
97-
MenuListItem hairColors = new MenuListItem("Hair Color", colorList, 0, "Hair color pallete.")
123+
MenuListItem hairColors = new MenuListItem(
124+
"Hair Color",
125+
colorList,
126+
0,
127+
"Hair color pallete."
128+
)
98129
{
99130
ShowColorPanel = true
100131
};
@@ -128,7 +159,12 @@ string ChangeCallback(MenuDynamicListItem item, bool left)
128159
#endif
129160
// Normal
130161
List<string> normalList = new List<string>() { "Item #1", "Item #2", "Item #3" };
131-
MenuListItem normalListItem = new MenuListItem("Normal List Item", normalList, 0, "And another simple description for yet another simple (list) item. Nothing special about this one.");
162+
MenuListItem normalListItem = new MenuListItem(
163+
"Normal List Item",
164+
normalList,
165+
0,
166+
"And another simple description for yet another simple (list) item. Nothing special about this one."
167+
);
132168

133169
// Adding the lists to the menu.
134170
menu.AddMenuItem(normalListItem);
@@ -137,7 +173,10 @@ string ChangeCallback(MenuDynamicListItem item, bool left)
137173
Menu submenu = new Menu("Submenu", "Secondary Menu");
138174
MenuController.AddSubmenu(menu, submenu);
139175

140-
MenuItem menuButton = new MenuItem("Submenu", "This button is bound to a submenu. Clicking it will take you to the submenu.")
176+
MenuItem menuButton = new MenuItem(
177+
"Submenu",
178+
"This button is bound to a submenu. Clicking it will take you to the submenu."
179+
)
141180
{
142181
#if FIVEM
143182
Label = "→→→"
@@ -152,7 +191,10 @@ string ChangeCallback(MenuDynamicListItem item, bool left)
152191
// Adding items with sprites left & right to the submenu.
153192
for (var i = 0; i < Enum.GetValues(typeof(MenuItem.Icon)).Length; i++)
154193
{
155-
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.")
194+
var tmpItem = new MenuItem(
195+
$"Icon.{Enum.GetName(typeof(MenuItem.Icon), ((MenuItem.Icon)i))}",
196+
"This menu item has a left and right sprite. Press ~r~HOME~s~ to toggle the 'enabled' state on these items."
197+
)
156198
{
157199
Label = $"(#{i})",
158200
#if FIVEM
@@ -161,19 +203,16 @@ string ChangeCallback(MenuDynamicListItem item, bool left)
161203
LeftIcon = (MenuItem.Icon)i
162204
};
163205

164-
//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~.");
165-
//tmpItem2.LeftIcon = (MenuItem.Icon)i;
166-
//tmpItem2.RightIcon = (MenuItem.Icon)i;
167-
//tmpItem2.Enabled = false;
168-
169206
submenu.AddMenuItem(tmpItem);
170-
//submenu.AddMenuItem(tmpItem2);
171207
}
172-
submenu.ButtonPressHandlers.Add(new Menu.ButtonPressHandler(Control.FrontendSocialClubSecondary, Menu.ControlPressCheckType.JUST_RELEASED, new Action<Menu, Control>((m, c) =>
173-
{
174-
m.GetMenuItems().ForEach(a => a.Enabled = !a.Enabled);
175-
}), true));
176-
208+
submenu.ButtonPressHandlers.Add(
209+
new Menu.ButtonPressHandler(Control.FrontendSocialClubSecondary,
210+
Menu.ControlPressCheckType.JUST_RELEASED,
211+
new Action<Menu, Control>((m, c) =>
212+
{
213+
m.GetMenuItems().ForEach(a => a.Enabled = !a.Enabled);
214+
}), true)
215+
);
177216
#if FIVEM
178217
// Instructional buttons setup for the second (submenu) menu.
179218
submenu.InstructionalButtons.Add(Control.CharacterWheel, "Right?!");
@@ -182,19 +221,21 @@ string ChangeCallback(MenuDynamicListItem item, bool left)
182221
submenu.InstructionalButtons.Add(Control.Cover, "This");
183222
submenu.InstructionalButtons.Add(Control.Context, "Check");
184223
#endif
185-
186224
// Create a third menu without a banner.
187225
Menu menu3 = new Menu(null, "Only a subtitle, no banner.");
188226

189227
// you can use AddSubmenu or AddMenu, both will work but if you want to link this menu from another menu,
190228
// you should use AddSubmenu.
191229
MenuController.AddSubmenu(menu, menu3);
192-
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.")
230+
MenuItem thirdSubmenuBtn = new MenuItem(
231+
"Another submenu",
232+
"This is just a submenu without a banner. No big deal. This also has a very long description to test multiple " +
233+
"lines and see if they work properly. Let's find out if it works as intended."
234+
)
193235
{
194236
#if FIVEM
195237
Label = "→→→"
196238
#endif
197-
198239
#if REDM
199240
RightIcon = MenuItem.Icon.ARROW_RIGHT
200241
#endif
@@ -211,7 +252,6 @@ string ChangeCallback(MenuDynamicListItem item, bool left)
211252
menu.AddMenuItem(new MenuItem($"Item #{i + 1}.", "With an invisible description."));
212253
}
213254

214-
215255
#if FIVEM
216256
// Create menu with weapon stats panel
217257
Menu menu4 = new Menu("Weapon Stats", "Weapon Stats Panel") { ShowWeaponStatsPanel = true };
@@ -233,13 +273,9 @@ string ChangeCallback(MenuDynamicListItem item, bool left)
233273
menu.AddMenuItem(vehicleStats);
234274
MenuController.BindMenuItem(menu, menu5, vehicleStats);
235275
#endif
236-
237-
/*
238-
########################################################
239-
Event handlers
240-
########################################################
241-
*/
242-
276+
/*--------------
277+
Event handlers
278+
--------------*/
243279

244280
menu.OnCheckboxChange += (_menu, _item, _index, _checked) =>
245281
{
@@ -322,15 +358,6 @@ Event handlers
322358
// Code in here would get executed whenever a dynamic list item is pressed.
323359
Debug.WriteLine($"OnDynamicListItemSelect: [{_menu}, {_dynamicListItem}, {_currentItem}]");
324360
};
325-
326-
//DelayedConstructor();
327361
}
328-
329-
//private async void DelayedConstructor()
330-
//{
331-
// await Delay(1000);
332-
// MenuController.MainMenu.OpenMenu();
333-
//}
334-
335362
}
336363
}

0 commit comments

Comments
 (0)