# Crafting Window UGUI

## 🛠️ CraftingWindowUGUI Class

Inventool’s crafting window for uGUI.

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

***

### 📦 Fields

| Access      | Field                  | Type                        | Description                                    |
| ----------- | ---------------------- | --------------------------- | ---------------------------------------------- |
| `protected` | `itemSlotPrefab`       | `ItemSlotElementUGUI`       | The item slot prefab.                          |
| `protected` | `plusSignPrefab`       | `GameObject`                | The plus sign prefab.                          |
| `protected` | `craftingTitleLabel`   | `TextMeshProUGUI`           | The crafting title label.                      |
| `protected` | `craftingSlotElements` | `List<ItemSlotElementUGUI>` | A list of all crafting slots.                  |
| `protected` | `plusSignElements`     | `List<GameObject>`          | A list of all plus sign elements.              |
| `protected` | `craftScroll`          | `ScrollRect`                | The scroll rect containing craftable items.    |
| `protected` | `contentLayout`        | `HorizontalLayoutGroup`     | The scroll rect content layout group.          |
| `protected` | `currencyElement`      | `CurrencyElementUGUI`       | The result cost currency element.              |
| `protected` | `craftButton`          | `Button`                    | The button that confirms the craft.            |
| `protected` | `craftButtonLabel`     | `TextMeshProUGUI`           | The label that displays the craft button text. |
| `protected` | `craftResultSlot`      | `ItemSlotElementUGUI`       | The craft result item slot.                    |
| `protected` | `craftEmptyLabel`      | `TextMeshProUGUI`           | The label shown when the craft list is empty.  |
| `protected` | `closeButton`          | `Button`                    | The close button.                              |
| `protected` | `crafter`              | `Crafter`                   | Crafting logic handler.                        |
| `protected` | `activeCraftsman`      | `Craftsman`                 | The craftsman currently being interacted with. |
| `protected` | `useCraftingCost`      | `bool`                      | True if crafting cost should be used.          |

***

### 🔍 Properties

| Access   | Property            | Type                 | Description                                |
| -------- | ------------------- | -------------------- | ------------------------------------------ |
| `public` | `OpenedForMerchant` | `bool`               | True if the window is open for a merchant. |
| `public` | `Instance`          | `CraftingWindowUGUI` | The active instance.                       |

***

### 🧰 Methods

| Access               | Method                                     | Returns | Description                                                                   |
| -------------------- | ------------------------------------------ | ------- | ----------------------------------------------------------------------------- |
| `protected override` | `Awake()`                                  | `void`  | Initializes singleton, registers buttons, sets up UI, and localizes elements. |
| `protected override` | `Start()`                                  | `void`  | Hides content on start.                                                       |
| `protected virtual`  | `HandleCraftingError(string message)`      | `void`  | Handles crafting errors and opens a confirm prompt.                           |
| `public`             | `LocalizeElements()`                       | `void`  | Localizes UI elements.                                                        |
| `public virtual`     | `Open(Craftsman craftsman)`                | `void`  | Opens the window for a craftsman.                                             |
| `public override`    | `Close()`                                  | `void`  | Closes the window, clears items, reloads craft list.                          |
| `public virtual`     | `UpdateCraftingElements()`                 | `void`  | Updates crafting slots, result slot, and cost display.                        |
| `public virtual`     | `IsPointInsideCraftingList(Vector2 point)` | `bool`  | Checks if a point is inside the crafting list element.                        |
| `public virtual`     | `ReloadCraftList()`                        | `void`  | Reloads the craft list UI.                                                    |
| `public virtual`     | `AddToCraftList(ItemStack itemStack)`      | `void`  | Adds an item stack to the craft list.                                         |
| `public virtual`     | `RemoveFromCraftList(int index)`           | `void`  | Removes an item stack from the craft list.                                    |
| `public virtual`     | `ConfirmCraft()`                           | `void`  | Confirms the craft, clears items if successful, updates UI.                   |

## Active Instance

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

## Open

Call the `Open` method when the crafting window should be opened. This method accepts a `Craftsman` parameter. Use null to open without a craftsman reference.

```csharp
CraftingWindowUGUI.Instance.Open(myCraftsman);
```

## Close

`Close` simply closes the window.

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