# Crafting Window

## 🛠️ CraftingWindow Class

Inventool’s crafting window for combining items.

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

***

### 📦 Fields

| Access      | Field                      | Type                    | Description                           |
| ----------- | -------------------------- | ----------------------- | ------------------------------------- |
| `protected` | `craftingTitle`            | `Label`                 | Crafting window title label.          |
| `protected` | `craftingContent`          | `VisualElement`         | Container for crafting UI content.    |
| `protected` | `craftingSlotElements`     | `List<ItemSlotElement>` | List of crafting slot elements.       |
| `protected` | `craftScroll`              | `ScrollView`            | Scroll view for craft list.           |
| `protected` | `craftListElement`         | `VisualElement`         | Container for craft list items.       |
| `protected` | `craftCostIcon`            | `VisualElement`         | Icon for crafting cost.               |
| `protected` | `craftCostLabel`           | `Label`                 | Label for crafting cost text.         |
| `protected` | `craftButton`              | `Button`                | Button to confirm crafting action.    |
| `protected` | `craftResultSlot`          | `ItemSlotElement`       | Slot showing craft result item.       |
| `protected` | `craftEmptyLabel`          | `Label`                 | Label shown when craft list is empty. |
| `protected` | `closeButton`              | `Button`                | Button to close the window.           |
| `protected` | `crafter`                  | `Crafter`               | Crafting logic handler instance.      |
| `protected` | `activeCraftsman`          | `Craftsman`             | Currently interacting craftsman.      |
| `protected` | `useCraftingCost`          | `bool`                  | Flag to display crafting cost.        |
| `protected` | `isPointerInsideCraftList` | `bool`                  | True when pointer is over craft list. |

***

### 🔍 Properties

| Access          | Property            | Type             | Description                  |
| --------------- | ------------------- | ---------------- | ---------------------------- |
| `public`        | `OpenedForMerchant` | `bool`           | True if open for a merchant. |
| `public static` | `Instance`          | `CraftingWindow` | Active singleton instance.   |

***

### 🧰 Methods

| Access               | Method                                | Returns | Description                              |
| -------------------- | ------------------------------------- | ------- | ---------------------------------------- |
| `protected override` | `Awake()`                             | `void`  | Initialize singleton and wire UI events. |
| `protected override` | `Start()`                             | `void`  | Hide window on start.                    |
| `protected virtual`  | `HandleCraftingError(string message)` | `void`  | Show error prompt on craft failure.      |
| `public`             | `LocalizeElements()`                  | `void`  | Localize window UI text.                 |
| `public virtual`     | `Open(Craftsman craftsman)`           | `void`  | Open window for the given craftsman.     |
| `public override`    | `Close()`                             | `void`  | Close window and reset craft state.      |
| `public virtual`     | `UpdateCraftingElements()`            | `void`  | Refresh crafting content and result.     |
| `public virtual`     | `IsPointerInsideCraftingList()`       | `bool`  | Check if pointer is over craft list.     |
| `public virtual`     | `ReloadCraftList()`                   | `void`  | Rebuild the craft list UI.               |
| `public virtual`     | `AddToCraftList(ItemStack itemStack)` | `void`  | Add an item to the craft list.           |
| `public virtual`     | `RemoveFromCraftList(int index)`      | `void`  | Remove an item from the craft list.      |
| `public virtual`     | `ConfirmCraft()`                      | `void`  | Execute the crafting operation.          |

***

## Active Instance

You can get the active `CraftingWindow` instance with `CraftingWindow.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
CraftingWindow.Instance.Open(myCraftsman);
```

## Close

`Close` simply closes the window.

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