Getting Started - Guad/NativeUI GitHub Wiki

Requirements

How to install Native UI

  1. Install ScriptHookV and ScriptHookVDotNet
  2. Download the latest stable release of NativeUI and place it in your scripts/ folder.
  3. Add it to your references in your Visual Studio project.

Creating a basic menu

You can create a menu by using the UIMenu class. This class provides 6 events: OnIndexChange, OnListChange, OnCheckboxChange, OnItemSelect, OnMenuClose and OnMenuChange.

UIMenu has 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.

var myMenu = new UIMenu("Banner Title", "~b~SUBTITLE");

Now you can start adding elements to your menu by using the AddItem(UIMenuItem item) method.

myMenu.AddItem(new UIMenuItem("Simple Button"));
myMenu.AddItem(new UIMenuCheckboxItem("Simple Checkbox", false));
myMenu.AddItem(new UIMenuListItem("Simple List", new List<dynamic> {"Item 1", "Item 2", "Item 3"}, 0));
myMenu.AddItem(new UIMenuItem("Another Button", "Items can have descriptions too!"));
myMenu.RefreshIndex();

After you have done adding items, you will have to set the index at 0 by using the RefreshIndex() method.

By using events, you can easily check when something has been changed.

myMenu.OnItemSelect += ItemSelectHandler;
 
public void ItemSelectHandler(UIMenu sender, UIMenuItem selectedItem, int index)
{
    UI.Notify("You have selected: ~b~" + selectedItem.Text);
}

Finally, you will have to implement an open/close trigger for your menu by using the Visible property, and some other final touches like the Draw method in your Tick event handler, and ProcessKey method in your KeyDown handler.

You can also use the MenuPool helper class. You'll have to initialise it and add your menu to it. Then you can call myMenuPool.ProcessMenus() and it will do all the work for you.

private MenuPool _myMenuPool = new MenuPool();

_myMenuPool.Add(myMenu);

public void OnTick(object o, EventArgs e)
{
    _myMenuPool.ProcessMenus();
}
public void OnKeyDown(object o, KeyEventArgs e)
{
    //myMenu.ProcessKey(e.KeyCode); // We are using controls instead of keys, so we comment it out.
    if (e.KeyCode == Keys.F5) // Our menu on/off switch
    {
        myMenu.Visible = !myMenu.Visible;
    }
}

Example Script

You can view the example script here.

⚠️ **GitHub.com Fallback** ⚠️