Skip to content

HUD Menus

Before working on HUD, it's recommended to extract <https://noskill.gitbook.io/titanfall2/intro/duction/vpk-packpack>_ the englishclient_frontend.bsp.pak000_dir.vpk vpk. This file contains all vanilla menus and UI logic and will be a very helpful reference!

Registering a menu

In your mod.json, add a Before UI callback like this:

        {
            "Path": "ui/profiles_menu.nut",
            "RunOn": "UI",
            "UICallback": {
                "Before": "InitProfilesMenu",
            }
        }

In the script you referenced, create a global in which you register your menu with the AddMenu like this:

    global function InitProfilesMenu

    void function InitProfilesMenu()
    {
        AddMenu( "MenuName", $"path/to/menu.menu"  )
    }

If you want to, you can add a init to AddMenu like this: AddMenu( "MenuName", $"path/to/menu.menu", func )

The returns void and takes no parameters. It gets called once the menu is initialized.

It's recommended to create a file struct in which you store menu states:

    struct {
        var menu
    } file

    void function MenuInitCallback()
    {
        file.menu = GetMenu( "MenuName" )
    }

Registering a Submenu

Useless functions have been left out. From _menus.nut

UICodeCallback_ActivateMenus

Register Menus

var AddMenu( string blockName, asset resourceFile, void functionref() initFunc = null, string displayName = "" )

Register a normal HUD menu. The init function will be called once all menus are registered and created.

var AddMenu_WithCreateFunc( string blockName, asset resourceFile, void functionref() initFunc, var functionref( ... ) createMenuFunc )

Registers a normal HUD menu with a custom function to create the menu. The create function needs to be native since scripts can't create HUD elements.

var AddPanel( var menu, string panelName, void functionref() initFunc = null )

var AddSubmenu( blockName, asset resourceFile, void functionref() initFunc = null )

Open Menus

void AdvanceMenu( string name )

Push a menu to the stack / open a menu

void OpenSubmenu( var menu, bool updateMenuPos = true )

if updateMenuPos is not null, the menu is required to have a ButtonFrame element that is the main content reference.

Retrieve Menus

var GetMenu( string name )

Get the menu reference

var GetPanel( string name )

var GetActiveMenu()

array GetAllMenuPanels( var menu )

Close Menus

void CloseActiveMenu( bool cancelled = false, bool openStackMenu = true )

void CloseAllMenus()

void CloseAllDialogs()

void CloseAllToTargetMenu( var menu )

Close until the menu is the most recent opened.

void CloseSubmenu( bool openStackMenu = true )

void CleanupInGameMenus()

Callbacks

void AddMenuEventHandler( var menu, int event, void functionref() func )

Accepted events:

  • eUIEvent.MENU_OPEN

  • eUIEvent.MENU_CLOSE

  • eUIEvent.MENU_SHOW

  • eUIEvent.MENU_HIDE

  • eUIEvent.MENU_NAVIGATE_BACK

  • eUIEvent.MENU_TAB_CHANGED

  • eUIEvent.MENU_ENTITLEMENTS_CHANGED

  • eUIEvent.MENU_INPUT_MODE_CHANGED

void AddPanelEventHandler( var panel, int event, void functionref() func )

Accepted events:

  • eUIEvent.PANEL_SHOW

  • eUIEvent.PANEL_HIDE

void AddButtonEventHandler( var button, int event, void functionref( var ) func )

void AddEventHandlerToButton( var menu, string buttonName, int event, void functionref( var ) func )

Add an event handler to an element.

If you have a reference to the element, use Hud_AddEventHandler

void AddEventHandlerToButtonClass( var menu, string classname, int event, void functionref( var ) func )

Add a event handler for every element of a class

var GetTopNonDialogMenu()

Get the last openend menu that isn't a dialog

bool IsDialog( var menu )

Returns true if the menu is a dialog.

Not recommended to use.

CloseAllInGameMenus()

OpenSubmenu( var menu, bool updateMenuPos = true )

CloseSubmenu( bool openStackMenu = true )

Other

void PrintMenuStack()

Debugging

void AddMenuElementsByClassname( var menu, string classname )

void FocusDefaultMenuItem( var menu )

Set the default focus element to be focused

void FocusDefault( var menu )

Like FocusDefaultMenuItem but excludes some menus.

Footers

To use footers, add this element to your menu:

    FooterButtons
    {
        ControlName         CNestedPanel
        InheritProperties   FooterButtons
    }

void AddMenuFooterOption( var menu, int input, string gamepadLabel, string mouseLabel = "", void functionref( var ) activateFunc = null, bool functionref() conditionCheckFunc = null, void functionref( InputDef ) updateFunc = null )

Adds a footer to a menu.

void AddPanelFooterOption( var panel, int input, string gamepadLabel, string mouseLabel = "", void functionref( var ) activateFunc = null, bool functionref() conditionCheckFunc = null, void functionref( InputDef ) updateFunc = null )

Adds a footer to a panel

void UpdateFooterOptions()

Update the footers of the active menu.

void SetFooterText( var menu, int index, string text )

Change the text of a specific footer.