-
Notifications
You must be signed in to change notification settings - Fork 39
Menus Overview
You can create a menu using the UIMenu
class. This class two basic parameters: the banner title and the subtitle. It also has an overload with a third Point parameter which determines the offset, and an overload for a custom sprites.
UIMenu myMenu = new UIMenu("Banner Title", "~b~SUBTITLE");
Now you can start adding elements to your menu using the UIMenu.AddItem(UIMenuItem item)
or UIMenu.AddItems(params UIMenuItem[] items)
methods.
var button = new UIMenuItem("Simple Button");
var checkbox = new UIMenuCheckboxItem("Simple Checkbox", false);
var list = new UIMenuListScrollerItem<string>("Simple List", "", new[] { "Item 1", "Item 2", "Item 3" }));
var numericList = new UIMenuNumericScrollerItem<int>("Simple Numeric List", "", -100, 100, 5));
var anotherButton = new UIMenuItem("Another Button", "Items can have descriptions too!");
myMenu.AddItems(button,
checkbox,
list,
numericList,
anotherButton);
By using events, you can easily check when something has been changed.
myMenu.OnItemSelect += ItemSelectHandler;
// ...
private static void ItemSelectHandler(UIMenu sender, UIMenuItem selectedItem, int index)
{
Game.DisplaySubtitle("You have selected: ~b~" + selectedItem.Text, 1000);
}
Then, you will have to implement an open/close trigger for your menu by using the UIMenu.Visible
property.
Finally, handle the menu updates and rendering by calling UIMenu.ProcessControl()
, UIMenu.ProcessMouse()
and UIMenu.Draw()
. This can be simplified with the MenuPool
helper class. You will have to create an instance and add your menus to it. Then you can call MenuPool.ProcessMenus()
each tick and it will do all the work for you.
static MenuPool myMenuPool = new MenuPool();
// ...
myMenuPool.Add(myMenu);
// start the fiber which will handle drawing and processing the menus
GameFiber.StartNew(ProcessMenus);
// ...
private static void ProcessMenus()
{
// draw the menu banners (only needed if UIMenu.SetBannerType(Rage.Texture) is used)
// Game.RawFrameRender += (s, e) => pool.DrawBanners(e.Graphics);
while (true)
{
GameFiber.Yield();
myMenuPool.ProcessMenus();
if (Game.IsKeyDown(Keys.F5)) // the open/close trigger
{
if (myMenu.Visible)
{
// close the menu
myMenu.Visible = false;
}
else if (!UIMenu.IsAnyMenuVisible && !TabView.IsAnyPauseMenuVisible) // check that no menus are visible
{
// open the menu
myMenu.Visible = true;
}
}
}
}