Adding A SubMenu to Trainer

Adding Our First Sub Menu

In this part 4 of Create Your Own Trainer, we will add a submenu for a category of cars. We start by adding a new menu which we can call anything we want, but to keep things organized we will name it with a submenu prefix like this:
private static readonly NativeMenu submenuCorvettes = new NativeMenu("Vettes", "~g~Chevrolet Corvettes", "");
As second steps we add two new Items to our menu with these lines of code:
private static readonly NativeItem VetteSplitWindow  = new NativeItem("1963 Corvette Split Window", "Really cool car");
 private static readonly NativeItem VetteZ06 = new NativeItem("2023 Corvette Z06", "Hot Performance");

The 3 lines above are for our Menu display. Now we also need to add some more code for these menu items to be added to the menu pool. When we refer to the menu pool, it means the code which tells LemonUI to add an item or a submenu and it also defines the order in which the items will be displayed from top to bottom.

The MaxItems is optional, it sets the maximum number of items you can see on the screen at the same time without scrolling beyond the end of the list.

menu.AddSubMenu(submenuCorvettes, "..."); pool.Add(submenuCorvettes);
submenuCorvettes.MaxItems = 25;
submenuCorvettes.Add(VetteSplitWindow); VetteSplitWindow.Activated += SpawnVetteSplitWindow;
submenuCorvettes.Add(VetteZ06); VetteZ06.Activated += SpawnVetteZ06;

Just as we did with our Motorcycle example in part 3, we will need to write code to spawn both vettes in the example above.

Here are two screenshots showing the Menu when first opened followed by the Menu when Corvettes have been selected. Notice that Chevrolet Corvettes is green because we put ~g~ before the name. 

CLICK PICTURES FOR FULL SIZE AND READABILITY

In the screenshot below, you can see "Hot Performance" under 2023 Corvette Z06. That's an optional description. You can see how it is handled in the code example above. Notice also that the first argument appears at the top of the menu (Vettes, in blue box) while the second argument (Chevrolet Corvettes) appears as the heading for this submenu.

private static readonly NativeMenu submenuCorvettes = new NativeMenu("Vettes", "~g~Chevrolet Corvettes", ""); 

The code for this section can be found on pastebin at this link.