# Inventool Action Menu UGUI

## 🧭 InventoolActionMenuUGUI Class

A pop‑up menu for custom actions.

> **Namespace:** `Esper.Inventool.UI.UGUI`\
> **Access:** `public`\
> **Type:** `class`\
> **Inherits:** `CrossInputSupportedWindowUGUI`

***

### 📦 Fields

| Access          | Field             | Type                         | Description                                  |
| --------------- | ----------------- | ---------------------------- | -------------------------------------------- |
| `protected`     | `optionPrefab`    | `ActionMenuOptionUGUI`       | The action menu option prefab.               |
| `protected`     | `optionContainer` | `RectTransform`              | RectTransform that will contain all options. |
| `protected`     | `closeButton`     | `Button`                     | Full‑screen invisible close button.          |
| `protected`     | `canvasGroup`     | `CanvasGroup`                | Canvas group component.                      |
| `protected`     | `loadedOptions`   | `List<ActionMenuOptionUGUI>` | List of loaded action menu options.          |
| `public static` | `Instance`        | `InventoolActionMenuUGUI`    | The active instance.                         |

***

### 🧰 Methods

| Access               | Method                                                          | Returns                | Description                                                                  |
| -------------------- | --------------------------------------------------------------- | ---------------------- | ---------------------------------------------------------------------------- |
| `protected override` | `Awake()`                                                       | `void`                 | Initializes singleton, sets up UI, wires close button, and closes initially. |
| `protected virtual`  | `CreateMenuOption(ActionMenuOption actionMenuOption)`           | `ActionMenuOptionUGUI` | Instantiates and configures a menu option UI element.                        |
| `public virtual`     | `Open(RectTransform target, params ActionMenuOption[] options)` | `void`                 | Opens the action menu at target; orders, creates, and displays options.      |
| `public virtual`     | `Open(RectTransform target, List<ActionMenuOption> options)`    | `void`                 | Overload that accepts a list; delegates to params overload.                  |
| `public virtual`     | `Close()`                                                       | `void`                 | Closes the action menu and invokes `onClosed`.                               |
| `protected`          | `ForceInsideView(RectTransform target)`                         | `IEnumerator`          | Positions content near target or mouse and clamps inside viewport.           |

## Active Instance

You can get the active `InventoolActionMenuUGUI` instance with `InventoolActionMenuUGUI.Instance`. Ensure there's an instance of it in your scene before using this field.

## Opening

Opening the action menu requires a `RectTransform` target and a list of [action-menu-option](https://stylishesper.gitbook.io/inventool/inventool-v1/scripting/api/ui/action-menu-option "mention")s.

```csharp
InventoolActionMenuUGUI.Instance.Open(targetElement, myMenuOptions);
```

## Closing

```csharp
InventoolActionMenuUGUI.Instance.Close();
```

## Customizations

The options displayed on the action menu are customizable through scripting.

### Customize For Inventory Item Stacks

To customize the action menu options displayed when an item stack in the inventory is clicked, edit the `ItemStack.actionMenuOptionsGetter` field.

```csharp
using Esper.Inventool.Items;
using Esper.Inventool.UI;
using System.Collections.Generic;
using UnityEngine;

public class ActionMenuCustomizer : MonoBehaviour
{
    public Sprite myIcon;

    private void Awake()
    {
        // Apply the customization on awake
        ItemStack.actionMenuOptionsGetter = MyActionMenuOptionsGetter;
    }

    /// <summary>
    /// Creates and returns the action menu options.
    /// </summary>
    /// <param name="itemStack">The item stack target to create the options for.</param>
    /// <returns>A list of action menu options.</returns>
    private List<ActionMenuOption> MyActionMenuOptionsGetter(ItemStack itemStack)
    {
        // Create a list that will contain the options
        var options = ItemStack.GetDefaultActionMenuOptions(itemStack);

        // Add an option
        var myOption = new ActionMenuOption()
        {
            // Set the button text (smallcaps is generally used for styling purposes)
            text = $"<smallcaps>My Option</smallcaps>",

            // Set the button color
            backgroundColor = new Color(0.3f, 0.3f, 0.3f),

            // Set its order in the menu (lower numbers appear at the top)
            sortingOrder = 0,

            // Create an on-click action
            action = () => Debug.Log("Do something"),
            
            // Display a small icon beside the text
            icon = myIcon
        };

        options.Add(myOption);

        return options;
    }
}
```

If you'd like a reference, you can find the original in the `ItemStack.actionMenuOptionsGetter` field in the ItemStack.cs script.

### Customize For Equipment Slots

To customize the action menu options displayed when an equipment slot in the inventory is clicked, edit the `EquipmentSlot.actionMenuOptionsGetter` field.

```csharp
using Esper.Inventool;
using Esper.Inventool.UI;
using System.Collections.Generic;
using UnityEngine;

public class ActionMenuCustomizer : MonoBehaviour
{
    private void Awake()
    {
        // Apply the customization on awake
        EquipmentSlot.actionMenuOptionsGetter = MyActionMenuOptionsGetter;
    }

    /// <summary>
    /// Creates and returns the action menu options.
    /// </summary>
    /// <param name="slot">The equipment slot target to create the options for.</param>
    /// <returns>A list of action menu options.</returns>
    private List<ActionMenuOption> MyActionMenuOptionsGetter(EquipmentSlot slot)
    {
        // Create a list that will contain the options
        var options = EquipmentSlot.GetDefaultActionMenuOptions(slot);

        // Add an option
        var myOption = new ActionMenuOption()
        {
            // Set the button text (smallcaps is generally used for styling purposes)
            text = $"<smallcaps>My Option</smallcaps>",

            // Set the button color
            backgroundColor = new Color(0.3f, 0.3f, 0.3f),

            // Set its order in the menu (lower numbers appear at the top)
            sortingOrder = 0,

            // Create an on-click action
            action = () => Debug.Log("Do something")
        };

        options.Add(myOption);

        return options;
    }
}
```

If you'd like a reference, you can find the original in the `EquipmentSlot.actionMenuOptionsGetter` field in the EquipmentSlot.cs script.
