# Storage Window UGUI

## 🗄️ StorageWindowUGUI Class

Inventool's in-game storage window for uGUI.

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

***

### 📦 Fields

| Access          | Field                       | Type                                          | Description                         |
| --------------- | --------------------------- | --------------------------------------------- | ----------------------------------- |
| `public`        | `storage`                   | `Storage`                                     | Active storage reference.           |
| `protected`     | `itemStackElementPrefab`    | `ItemStackElementUGUI`                        | Item stack element prefab.          |
| `protected`     | `currencyElementPrefab`     | `StorageCurrencyElementUGUI`                  | Storage currency element prefab.    |
| `protected`     | `filterPrefab`              | `InventoryFilterUGUI`                         | Inventory filter prefab.            |
| `protected`     | `slotPrefab`                | `InventorySlotUGUI`                           | Empty slot prefab.                  |
| `protected`     | `closeButton`               | `Button`                                      | Close button.                       |
| `protected`     | `currenciesContainer`       | `RectTransform`                               | Container for currency elements.    |
| `protected`     | `titleLabel`                | `TextMeshProUGUI`                             | Storage title label.                |
| `protected`     | `originalStorageTitle`      | `string`                                      | Cached default title.               |
| `protected`     | `storageArea`               | `RectTransform`                               | Storage area rect.                  |
| `protected`     | `filterTitleLabel`          | `TextMeshProUGUI`                             | Filter title label.                 |
| `protected`     | `filterScroll`              | `ScrollRect`                                  | Filter scroll rect.                 |
| `protected`     | `storageScroll`             | `ScrollRect`                                  | Storage content scroll rect.        |
| `protected`     | `gridLayoutGroup`           | `GridLayoutGroup`                             | Grid layout for slots.              |
| `protected`     | `storageContentFitter`      | `ContentSizeFitter`                           | Content size fitter.                |
| `protected`     | `pagesArea`                 | `RectTransform`                               | Pagination area.                    |
| `protected`     | `pagesLabel`                | `TextMeshProUGUI`                             | Pages label.                        |
| `protected`     | `pageLeftButton`            | `Button`                                      | Previous page button.               |
| `protected`     | `pageRightButton`           | `Button`                                      | Next page button.                   |
| `protected`     | `storageCanvasGroup`        | `CanvasGroup`                                 | Canvas group used during reload.    |
| `protected`     | `storageScrollbar`          | `Scrollbar`                                   | Scrollbar reference.                |
| `protected`     | `currencyElements`          | `List<StorageCurrencyElementUGUI>`            | Instantiated currency elements.     |
| `protected`     | `filters`                   | `List<InventoryFilterUGUI>`                   | Instantiated filter buttons.        |
| `protected`     | `selectedFilter`            | `InventoryFilterUGUI`                         | Currently selected filter.          |
| `protected`     | `loadedSlots`               | `List<InventorySlotUGUI>`                     | Instantiated slot elements.         |
| `protected`     | `loadedItemElements`        | `Dictionary<ItemStack, ItemStackElementUGUI>` | Instantiated item elements.         |
| `protected`     | `storageRequiresReload`     | `bool`                                        | True if layout must be rebuilt.     |
| `protected`     | `originalStorageAreaHeight` | `float`                                       | Cached storage area height.         |
| `public`        | `Loaded`                    | `bool`                                        | True when UI loaded (`!firstOpen`). |
| `public static` | `Instance`                  | `StorageWindowUGUI`                           | Singleton instance.                 |

***

### 🔍 Properties

| Access          | Property   | Type                | Description                           |
| --------------- | ---------- | ------------------- | ------------------------------------- |
| `public`        | `Loaded`   | `bool`              | True if UI elements have been loaded. |
| `public static` | `Instance` | `StorageWindowUGUI` | Active instance.                      |

***

### 🧰 Methods

| Access               | Method                                                       | Returns                | Description                                                    |
| -------------------- | ------------------------------------------------------------ | ---------------------- | -------------------------------------------------------------- |
| `protected override` | `Awake()`                                                    | `void`                 | Singleton setup, register buttons and storage event listeners. |
| `protected override` | `Start()`                                                    | `void`                 | Cache layout values and hide content.                          |
| `protected virtual`  | `HandleStorageUpdated(ItemStack itemStack, Storage storage)` | `void`                 | Called when items change; reload current page.                 |
| `protected virtual`  | `HandleStorageUpdated(Currency currency, Storage storage)`   | `void`                 | Called when currency changes; update currency texts.           |
| `public virtual`     | `Open(Storage storage)`                                      | `void`                 | Open window for given storage and initialize UI.               |
| `public virtual`     | `UpdateStorageTitle()`                                       | `void`                 | Update title from storage custom/localized value.              |
| `private`            | `LateReload()`                                               | `IEnumerator`          | Deferred init: reload filters and slots.                       |
| `private`            | `ReloadStorageCoroutine()`                                   | `IEnumerator`          | Rebuild slots layout then reload page.                         |
| `public override`    | `Close()`                                                    | `void`                 | Close window and raise storage closed event.                   |
| `public virtual`     | `IsPointInsideStorage(Vector2 point)`                        | `bool`                 | Returns true if point lies inside storage scroll area.         |
| `public`             | `ReloadCurrencyElements()`                                   | `void`                 | Rebuild currency UI and wire withdraw/deposit actions.         |
| `public`             | `UpdateCurrenciesText()`                                     | `void`                 | Refresh currency amount labels.                                |
| `public`             | `UpdatePagesText()`                                          | `void`                 | Update pages label.                                            |
| `public`             | `NextPage()` / `PreviousPage()`                              | `void`                 | Change pages and reload.                                       |
| `public`             | `ReloadCurrentPage()`                                        | `void`                 | Recreate item elements for current page.                       |
| `public`             | `GetItemElement(ItemStack itemStack)`                        | `ItemStackElementUGUI` | Retrieve UI element for ItemStack or null.                     |
| `public`             | `ResetLoadedSlots()`                                         | `void`                 | Mark all slots available.                                      |
| `protected`          | `SetSlotInUse(InventorySlotUGUI slot)`                       | `void`                 | Mark slot visual as in-use.                                    |
| `protected`          | `SetSlotAvailable(InventorySlotUGUI slot)`                   | `void`                 | Mark slot visual as available.                                 |
| `public`             | `CreateItemStackElement(ItemStack itemStack)`                | `ItemStackElementUGUI` | Instantiate and size an item element.                          |
| `public virtual`     | `ReloadSlots()`                                              | `void`                 | Recreate slot grid according to navigation mode.               |
| `public virtual`     | `ReloadFilters()`                                            | `void`                 | Rebuild filter list and wire actions.                          |
| `public virtual`     | `SelectFirstFilter()`                                        | `void`                 | Select the first filter button.                                |
| `public virtual`     | `SelectFilter(InventoryFilterUGUI filter)`                   | `void`                 | Select a filter and update title.                              |
| `public virtual`     | `DeselectFilter()`                                           | `void`                 | Deselect active filter.                                        |

## Active Instance

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

## Open

Call the `Open` method when the storage window should be opened. This method requires a `StorageKeeper` reference as a parameter.

```csharp
StorageWindowUGUI.Instance.Open(myStorageKeeper);
```

## Close

`Close` simply closes the window.

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