NativeUI C# (How It Works For Developers)

NativeUI is an essential framework for C# developers in the Grand Theft Auto (GTA) modding community. It simplifies the creation of an easy painless nested menu system and custom banners, making it a favorite among GTA modders for its user-friendly approach and screen resolutions. Native UI MOD is designed to create fast, Rockstar-like menus, echoing the style and responsiveness of easy nested menus found in Grand Theft Auto (GTA) games. In this tutorial, we'll understand what NativeUI is and how we can integrate IronPDF with it.

Basics of NativeUI

NativeUI excels in creating nested menus easily, a boon for modders who wish to build sophisticated interfaces without having complex code for event-based callbacks and item descriptions. It's also adaptable to various screen resolutions, ensuring that menus are visually appealing across different displays and many old versions. One of NativeUI's strengths is its painless nested menu system, allowing developers to create complex menu structures with custom instructional buttons effortlessly. For beginners, NativeUI's documentation on its wiki is a valuable resource, providing step-by-step guidance in menu creation and versions floating.

Setting Up NativeUI in Visual Studio

Initial setup in Visual Studio involves downloading the NativeUI library and incorporating the .dll file into your mod project. The NativeUI library is a published package available through popular C# repositories, making it easily accessible for integration into your project. The installation is straightforward. When setting up NativeUI, ensure you have compatible versions floating between your development environment and the NativeUI library for optimal performance.

NativeUI C# (How It Works For Developers): Figure 1 - NativeUI

Creating Your First Menu

Creating your first menu with NativeUI is an exciting step. The library's design caters to ease of use, allowing you to add item descriptions, simple buttons, and even custom banners without much hassle. For those starting, it's advisable to begin with a basic script and gradually add more complex features as you become more comfortable with the framework. Here’s a simple example of creating a basic menu with its own textures:

using NativeUI;
public class YourFirstMenu : Script
{
    private MenuPool _menuPool;
    private UIMenu mainMenu;
    public YourFirstMenu()
    {
        _menuPool = new MenuPool();
        var mainMenu = new UIMenu("NativeUI", "SELECT AN OPTION");
        _menuPool.Add(mainMenu);
        AddMenuItems(mainMenu);
        _menuPool.RefreshIndex();
//mouse controls
        Tick += OnTick;
        KeyDown += OnKeyDown;
    }
    private void AddMenuItems(UIMenu menu)
    {
        var item1 = new UIMenuItem("Item 1", "Description for Item 1");
        menu.AddItem(item1);
        menu.OnItemSelect += (sender, item, index) =>
        {
            if (item == item1)
            {
                // Do something when Item 1 is selected
            }
        };
    }
    private void OnTick(object sender, EventArgs e)
    {
        _menuPool.ProcessMenus();
    }
    private void OnKeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.F5 && !_menuPool.IsAnyMenuOpen()) // Our menu on/off switch
            mainMenu.Visible = !mainMenu.Visible;
    }
}
using NativeUI;
public class YourFirstMenu : Script
{
    private MenuPool _menuPool;
    private UIMenu mainMenu;
    public YourFirstMenu()
    {
        _menuPool = new MenuPool();
        var mainMenu = new UIMenu("NativeUI", "SELECT AN OPTION");
        _menuPool.Add(mainMenu);
        AddMenuItems(mainMenu);
        _menuPool.RefreshIndex();
//mouse controls
        Tick += OnTick;
        KeyDown += OnKeyDown;
    }
    private void AddMenuItems(UIMenu menu)
    {
        var item1 = new UIMenuItem("Item 1", "Description for Item 1");
        menu.AddItem(item1);
        menu.OnItemSelect += (sender, item, index) =>
        {
            if (item == item1)
            {
                // Do something when Item 1 is selected
            }
        };
    }
    private void OnTick(object sender, EventArgs e)
    {
        _menuPool.ProcessMenus();
    }
    private void OnKeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.F5 && !_menuPool.IsAnyMenuOpen()) // Our menu on/off switch
            mainMenu.Visible = !mainMenu.Visible;
    }
}
Imports NativeUI
Public Class YourFirstMenu
	Inherits Script

	Private _menuPool As MenuPool
	Private mainMenu As UIMenu
	Public Sub New()
		_menuPool = New MenuPool()
		Dim mainMenu = New UIMenu("NativeUI", "SELECT AN OPTION")
		_menuPool.Add(mainMenu)
		AddMenuItems(mainMenu)
		_menuPool.RefreshIndex()
'mouse controls
		AddHandler Me.Tick, AddressOf OnTick
		AddHandler Me.KeyDown, AddressOf OnKeyDown
	End Sub
	Private Sub AddMenuItems(ByVal menu As UIMenu)
		Dim item1 = New UIMenuItem("Item 1", "Description for Item 1")
		menu.AddItem(item1)
		AddHandler menu.OnItemSelect, Sub(sender, item, index)
			If item = item1 Then
				' Do something when Item 1 is selected
			End If
		End Sub
	End Sub
	Private Sub OnTick(ByVal sender As Object, ByVal e As EventArgs)
		_menuPool.ProcessMenus()
	End Sub
	Private Sub OnKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
		If e.KeyCode = Keys.F5 AndAlso Not _menuPool.IsAnyMenuOpen() Then ' Our menu on/off switch
			mainMenu.Visible = Not mainMenu.Visible
		End If
	End Sub
End Class
VB   C#

This script sets up a basic menu with one item and handles its selection. NativeUI utilizes event-based callbacks, which means actions in your menus will trigger specific events, making your UI interactive and responsive.

Enhancing User Interaction

A key aspect of NativeUI is its ability to create menus that are both functional and user-friendly. The library supports mouse controls. In addition to mouse controls, NativeUI boasts comprehensive controller support, ensuring that menus are easily navigable with game controllers. You can further enhance user interaction by adding custom instructional buttons, which guide users through the menu options and controller support.

Customizing Menus

NativeUI allows for a high degree of customization. You can decorate your menus with your own textures and custom banners, giving them a unique look that stands out. Adding these personal touches not only makes your menus more visually appealing but also creates a more immersive experience for users.

private void CustomizeMenu(UIMenu menu)
{
    menu.SetBannerType("texture.png"); // Custom banner texture
    menu.ChangeItemColour("Item 1", System.Drawing.Color.FromArgb(255, 0, 0)); // Red color for Item 1
}
private void CustomizeMenu(UIMenu menu)
{
    menu.SetBannerType("texture.png"); // Custom banner texture
    menu.ChangeItemColour("Item 1", System.Drawing.Color.FromArgb(255, 0, 0)); // Red color for Item 1
}
Private Sub CustomizeMenu(ByVal menu As UIMenu)
	menu.SetBannerType("texture.png") ' Custom banner texture
	menu.ChangeItemColour("Item 1", System.Drawing.Color.FromArgb(255, 0, 0)) ' Red color for Item 1
End Sub
VB   C#

IronPDF: C# PDF Library

NativeUI C# (How It Works For Developers): Figure 2 - IronPDF

IronPDF is a comprehensive library in .NET for working with PDF files. It enables developers to create new PDFs, edit existing ones, and convert HTML to PDF, making it a necessary library for any C# application that needs to handle PDF documents.

Implementing IronPDF in a NativeUI Application

Integrating IronPDF in a C# project with NativeUI requires adding the IronPDF package to your Visual Studio project. This can be done easily via NuGet Package Manager in Visual Studio. Once set up, you can use IronPDF's features alongside the UI elements created with NativeUI.

Consider an application where you need to generate a report based on user input from a NativeUI interface. Here’s how you can achieve this using IronPDF:

using IronPdf;
using NativeUI;
public class ReportGenerator
{
    private MenuPool _menuPool;
    private UIMenu mainMenu;
    public ReportGenerator()
    {
        _menuPool = new MenuPool();
        mainMenu = new UIMenu("Report Generator", "SELECT AN OPTION");
        _menuPool.Add(mainMenu);
        AddPdfGenerationOption(mainMenu);
        _menuPool.RefreshIndex();
        // Event handlers for menu
    }
    private void AddPdfGenerationOption(UIMenu menu)
    {
        var generateReportItem = new UIMenuItem("Generate Report", "Create a PDF report");
        menu.AddItem(generateReportItem);
        menu.OnItemSelect += (sender, item, index) =>
        {
            if (item == generateReportItem)
            {
                CreatePdfReport();
            }
        };
    }
    private void CreatePdfReport()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1><p>Report details...</p>");
        pdf.SaveAs("Report.pdf");
        // Notify user that the PDF report has been generated
    }
}
using IronPdf;
using NativeUI;
public class ReportGenerator
{
    private MenuPool _menuPool;
    private UIMenu mainMenu;
    public ReportGenerator()
    {
        _menuPool = new MenuPool();
        mainMenu = new UIMenu("Report Generator", "SELECT AN OPTION");
        _menuPool.Add(mainMenu);
        AddPdfGenerationOption(mainMenu);
        _menuPool.RefreshIndex();
        // Event handlers for menu
    }
    private void AddPdfGenerationOption(UIMenu menu)
    {
        var generateReportItem = new UIMenuItem("Generate Report", "Create a PDF report");
        menu.AddItem(generateReportItem);
        menu.OnItemSelect += (sender, item, index) =>
        {
            if (item == generateReportItem)
            {
                CreatePdfReport();
            }
        };
    }
    private void CreatePdfReport()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1><p>Report details...</p>");
        pdf.SaveAs("Report.pdf");
        // Notify user that the PDF report has been generated
    }
}
Imports IronPdf
Imports NativeUI
Public Class ReportGenerator
	Private _menuPool As MenuPool
	Private mainMenu As UIMenu
	Public Sub New()
		_menuPool = New MenuPool()
		mainMenu = New UIMenu("Report Generator", "SELECT AN OPTION")
		_menuPool.Add(mainMenu)
		AddPdfGenerationOption(mainMenu)
		_menuPool.RefreshIndex()
		' Event handlers for menu
	End Sub
	Private Sub AddPdfGenerationOption(ByVal menu As UIMenu)
		Dim generateReportItem = New UIMenuItem("Generate Report", "Create a PDF report")
		menu.AddItem(generateReportItem)
		AddHandler menu.OnItemSelect, Sub(sender, item, index)
			If item = generateReportItem Then
				CreatePdfReport()
			End If
		End Sub
	End Sub
	Private Sub CreatePdfReport()
		Dim renderer = New ChromePdfRenderer()
		Dim pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1><p>Report details...</p>")
		pdf.SaveAs("Report.pdf")
		' Notify user that the PDF report has been generated
	End Sub
End Class
VB   C#

Conclusion

NativeUI C# (How It Works For Developers): Figure 3 - License

The integration of IronPDF with NativeUI in C# applications is a powerful combination that can significantly enhance functionality and user experience. Whether it's for creating business reports, educational tools, or comprehensive data forms, this combination provides a robust platform for developers to build sophisticated and high-quality applications. With creativity and thoughtful implementation, the potential applications of this integration are vast and diverse.

Get started with IronPDF's free trial and explore its full potential. When you're ready to commit, licenses begin at just $749 - a small price for such powerful capabilities!