(Feat) add crafting discovery + notification + inventory tool tips
This commit is contained in:
@@ -42,6 +42,8 @@ namespace Ashwild.Crafting
|
||||
private Func<CraftingRecipe, int, bool> canCraftQuery;
|
||||
private Func<ItemData, int> countItemQuery;
|
||||
private Func<CraftingRecipe, int, bool> craftRequest;
|
||||
private Func<ItemData, bool> isDiscoveredQuery;
|
||||
private Func<CraftingRecipe, bool> isRecipeVisibleQuery;
|
||||
private readonly List<RecipeButtonUI> recipeButtons = new List<RecipeButtonUI>();
|
||||
private readonly List<GameObject> ingredientInstances = new List<GameObject>();
|
||||
private RecipeButtonUI selectedButton;
|
||||
@@ -55,12 +57,15 @@ namespace Ashwild.Crafting
|
||||
/// <summary>
|
||||
/// Builds the recipe buttons (once) and wires the manager-owned queries/action. Safe to
|
||||
/// call again later to re-point the delegates; it then simply refreshes the display.
|
||||
/// The discovery queries decide which recipes are shown and which ingredients are still a mystery.
|
||||
/// </summary>
|
||||
public void Build(CraftingRecipe[] recipes, Func<CraftingRecipe, int, bool> canCraft, Func<ItemData, int> countItem, Func<CraftingRecipe, int, bool> craft)
|
||||
public void Build(CraftingRecipe[] recipes, Func<CraftingRecipe, int, bool> canCraft, Func<ItemData, int> countItem, Func<CraftingRecipe, int, bool> craft, Func<ItemData, bool> isDiscovered, Func<CraftingRecipe, bool> isRecipeVisible)
|
||||
{
|
||||
canCraftQuery = canCraft;
|
||||
countItemQuery = countItem;
|
||||
craftRequest = craft;
|
||||
isDiscoveredQuery = isDiscovered;
|
||||
isRecipeVisibleQuery = isRecipeVisible;
|
||||
|
||||
if (!built)
|
||||
{
|
||||
@@ -81,8 +86,9 @@ namespace Ashwild.Crafting
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recomputes craftability for every recipe button and refreshes the open detail.
|
||||
/// Called by the manager whenever the local player's inventory changes.
|
||||
/// Recomputes each recipe button's visibility (revealed once an ingredient is discovered) and
|
||||
/// its craftability, then refreshes the open detail. Called by the manager whenever the local
|
||||
/// player's inventory changes or a new item is discovered.
|
||||
/// </summary>
|
||||
public void Refresh()
|
||||
{
|
||||
@@ -91,6 +97,9 @@ namespace Ashwild.Crafting
|
||||
for (int i = 0; i < recipeButtons.Count; i++)
|
||||
{
|
||||
RecipeButtonUI btn = recipeButtons[i];
|
||||
bool visible = isRecipeVisibleQuery == null || isRecipeVisibleQuery(btn.Recipe);
|
||||
btn.gameObject.SetActive(visible);
|
||||
|
||||
bool canCraft = canCraftQuery != null && canCraftQuery(btn.Recipe, btn.CraftCount);
|
||||
btn.UpdateCraftability(canCraft);
|
||||
}
|
||||
@@ -193,12 +202,21 @@ namespace Ashwild.Crafting
|
||||
GameObject slotGO = Instantiate(ingredientSlotPrefab, ingredientContainer);
|
||||
IngredientSlotUI slotUI = slotGO.GetComponent<IngredientSlotUI>();
|
||||
|
||||
int required = ingredients[i].quantity * count;
|
||||
int playerHas = countItemQuery != null ? countItemQuery(ingredients[i].item) : 0;
|
||||
slotUI.Setup(ingredients[i].item, required, playerHas);
|
||||
|
||||
if (playerHas < required)
|
||||
bool discovered = isDiscoveredQuery == null || isDiscoveredQuery(ingredients[i].item);
|
||||
if (!discovered)
|
||||
{
|
||||
slotUI.SetupMystery();
|
||||
canCraft = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
int required = ingredients[i].quantity * count;
|
||||
int playerHas = countItemQuery != null ? countItemQuery(ingredients[i].item) : 0;
|
||||
slotUI.Setup(ingredients[i].item, required, playerHas);
|
||||
|
||||
if (playerHas < required)
|
||||
canCraft = false;
|
||||
}
|
||||
|
||||
ingredientInstances.Add(slotGO);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user