Panthr75-CustomMenuBarButtons icon

CustomMenuBarButtons

API for Plugin Devs to add buttons to the top menu bar

Last updated 5 months ago
Total downloads 901
Total rating 0 
Categories Libraries
Dependency string Panthr75-CustomMenuBarButtons-0.1.1
Dependants 3 other packages depend on this package

This mod requires the following mods to function

BepInEx-BepInExPack_GTFO-3.2.1 icon
BepInEx-BepInExPack_GTFO

BepInEx pack for GTFO. Preconfigured and includes Unity Base DLLs.

Preferred version: 3.2.1

README

Allows adding custom buttons to the top menubar.

Note: the current implementation is not final and changes could be made

For Plugin Developers

Example:

using UnityEngine;
using CustomMenuBarButtons;
using CellMenu;
using CustomMenuBarButtons;

namespace CrashButtonExample;

public sealed class CrashMenuBarButton(MenuBarHandler handler, CM_MenuBarItem item)
    : MenuBarCustomButton(handler, item, "Crash")
{
    // controls whether or not the menu bar button should be visible.
    // GTFO checks this every ~0.2 seconds
    public sealed override bool ShouldBeVisible
        => RundownManager.ExpeditionIsStarted;
    
    // called when the button is clicked.
    protected sealed override void OnButtonClick(int id)
    {
        Application.ForceCrash(0);
    }
}

Registering:

using BepInEx;
using BepInEx.Unity.IL2CPP;
using CustomMenuBarButtons;

namespace CrashButtonExample;

internal sealed class EntryPoint : BasePlugin
{
    public override void Load()
    {
        // Add listener to MenuBarHandler.
        // This should be done before startup as that's when all of the
        // menu bars GTFO uses are created.
        MenuBarHandler.CreateButtons += CreateCustomButtons;
    }

    // keep in mind the callback is invoked for every
    // menu bar that is created.
    //
    // This allows you to conditionally add your button to
    // (for example) the lobby page only.
    private static void CreateMenuBarButtons(MenuBarHandler menubar)
    {
        // MenuBarHandler has two methods to add buttons:
        //   1. AddLeftButton
        //   2. AddRightButton
        menubar.AddLeftButton(
            // argument 1: factory function that creates the button
            (handler, item) => new StorylineMenuBarButton(handler, item),
            // optional argument 2: the index to insert the button
            insertIndex: int.MaxValue,
            // optional argument 3: The page the button is for. Used for adding custom pages. 
            page: eCM_MenuPage.EMPTY);
    }
}