private void CraftingGUI() { EditorGUILayout.BeginVertical(CustomStyles.thinBox); EditorGUILayout.LabelField("Crafting", CustomStyles.subHeader); EditorGUILayout.Space(); if (items.Count == 0) { EditorGUILayout.HelpBox("No inventory items defined!", MessageType.Info); return; } foreach (Recipe recipe in recipes) { EditorGUILayout.BeginHorizontal(); string buttonLabel = recipe.label; if (buttonLabel == "") { buttonLabel = "(Untitled)"; } if (GUILayout.Toggle(recipe.isEditing, recipe.id + ": " + buttonLabel, "Button")) { if (selectedRecipe != recipe) { DeactivateAllRecipes(); ActivateRecipe(recipe); } } if (GUILayout.Button("-", GUILayout.Width(20f), GUILayout.Height(15f))) { Undo.RecordObject(this, "Delete recipe"); DeactivateAllRecipes(); recipes.Remove(recipe); AssetDatabase.SaveAssets(); break; } EditorGUILayout.EndHorizontal(); } if (GUILayout.Button("Create new recipe")) { Undo.RecordObject(this, "Create inventory recipe"); Recipe newRecipe = new Recipe(GetIDArrayRecipe()); recipes.Add(newRecipe); DeactivateAllRecipes(); ActivateRecipe(newRecipe); } EditorGUILayout.EndVertical(); if (selectedRecipe != null && recipes.Contains(selectedRecipe)) { string apiPrefix = "AC.KickStarter.inventoryManager.GetRecipe (" + selectedRecipe.id + ")"; EditorGUILayout.Space(); EditorGUILayout.BeginVertical(CustomStyles.thinBox); EditorGUILayout.LabelField("Recipe '" + selectedRecipe.label + "' properties", CustomStyles.subHeader); EditorGUILayout.Space(); selectedRecipe.label = CustomGUILayout.TextField("Name:", selectedRecipe.label, apiPrefix + ".label"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Resulting item:", GUILayout.Width(146f)); int i = GetArraySlot(selectedRecipe.resultID); i = CustomGUILayout.Popup(i, GetLabelList(), apiPrefix + ".resultID"); selectedRecipe.resultID = items[i].id; EditorGUILayout.EndHorizontal(); selectedRecipe.autoCreate = CustomGUILayout.Toggle("Result is automatic?", selectedRecipe.autoCreate, apiPrefix + ".autoCreate"); selectedRecipe.useSpecificSlots = CustomGUILayout.Toggle("Requires specific pattern?", selectedRecipe.useSpecificSlots, apiPrefix + ".useSpecificSlots"); selectedRecipe.actionListOnCreate = ActionListAssetMenu.AssetGUI("ActionList when create:", selectedRecipe.actionListOnCreate, apiPrefix + ".actionListOnCreate"); selectedRecipe.onCreateRecipe = (OnCreateRecipe)CustomGUILayout.EnumPopup("When click on result:", selectedRecipe.onCreateRecipe, apiPrefix + ".onCreateRecipe"); if (selectedRecipe.onCreateRecipe == OnCreateRecipe.RunActionList) { selectedRecipe.invActionList = ActionListAssetMenu.AssetGUI("ActionList when click:", selectedRecipe.invActionList, apiPrefix + ".invActionList"); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Ingredients", CustomStyles.subHeader); foreach (Ingredient ingredient in selectedRecipe.ingredients) { int j = selectedRecipe.ingredients.IndexOf(ingredient); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Ingredient:", GUILayout.Width(70f)); i = GetArraySlot(ingredient.itemID); i = CustomGUILayout.Popup(i, GetLabelList(), apiPrefix + ".ingredients [" + j + "].itemID"); ingredient.itemID = items[i].id; if (items[i].canCarryMultiple) { EditorGUILayout.LabelField("Amount:", GUILayout.Width(50f)); ingredient.amount = EditorGUILayout.IntField(ingredient.amount, GUILayout.Width(30f)); } if (selectedRecipe.useSpecificSlots) { EditorGUILayout.LabelField("Slot:", GUILayout.Width(30f)); ingredient.slotNumber = EditorGUILayout.IntField(ingredient.slotNumber, GUILayout.Width(30f)); } if (GUILayout.Button("-", GUILayout.Width(20f), GUILayout.Height(15f))) { Undo.RecordObject(this, "Delete ingredient"); selectedRecipe.ingredients.Remove(ingredient); AssetDatabase.SaveAssets(); break; } EditorGUILayout.EndHorizontal(); } if (GUILayout.Button("Add new ingredient")) { Undo.RecordObject(this, "Add recipe ingredient"); Ingredient newIngredient = new Ingredient(); selectedRecipe.ingredients.Add(newIngredient); } EditorGUILayout.EndVertical(); } }
private void CraftingGUI () { EditorGUILayout.LabelField ("Crafting", EditorStyles.boldLabel); if (items.Count == 0) { EditorGUILayout.HelpBox ("No inventory items defined!", MessageType.Info); return; } foreach (Recipe recipe in recipes) { EditorGUILayout.BeginHorizontal (); string buttonLabel = recipe.label; if (buttonLabel == "") { buttonLabel = "(Untitled)"; } if (GUILayout.Toggle (recipe.isEditing, recipe.id + ": " + buttonLabel, "Button")) { if (selectedRecipe != recipe) { DeactivateAllRecipes (); ActivateRecipe (recipe); } } if (GUILayout.Button ("-", GUILayout.Width (20f), GUILayout.Height (15f))) { Undo.RecordObject (this, "Delete recipe"); DeactivateAllRecipes (); recipes.Remove (recipe); AssetDatabase.SaveAssets(); break; } EditorGUILayout.EndHorizontal (); } if (GUILayout.Button("Create new recipe")) { Undo.RecordObject (this, "Create inventory recipe"); Recipe newRecipe = new Recipe (GetIDArrayRecipe ()); recipes.Add (newRecipe); DeactivateAllRecipes (); ActivateRecipe (newRecipe); } if (selectedRecipe != null && recipes.Contains (selectedRecipe)) { EditorGUILayout.Space (); EditorGUILayout.LabelField ("Recipe '" + selectedRecipe.label + "' properties", EditorStyles.boldLabel); EditorGUILayout.BeginVertical("Button"); selectedRecipe.label = EditorGUILayout.TextField ("Name:", selectedRecipe.label); EditorGUILayout.BeginHorizontal (); EditorGUILayout.LabelField ("Resulting item:", GUILayout.Width (146f)); int i = GetArraySlot (selectedRecipe.resultID); i = EditorGUILayout.Popup (i, GetLabelList ()); selectedRecipe.resultID = items[i].id; EditorGUILayout.EndHorizontal (); selectedRecipe.autoCreate = EditorGUILayout.Toggle ("Result is automatic?", selectedRecipe.autoCreate); selectedRecipe.useSpecificSlots = EditorGUILayout.Toggle ("Requires specific pattern?", selectedRecipe.useSpecificSlots); selectedRecipe.onCreateRecipe = (OnCreateRecipe) EditorGUILayout.EnumPopup ("When click on result:", selectedRecipe.onCreateRecipe); if (selectedRecipe.onCreateRecipe == OnCreateRecipe.RunActionList) { selectedRecipe.invActionList = (ActionListAsset) EditorGUILayout.ObjectField ("ActionList to run:", selectedRecipe.invActionList, typeof (ActionListAsset), false); } EditorGUILayout.Space (); EditorGUILayout.LabelField ("Ingredients", EditorStyles.boldLabel); foreach (Ingredient ingredient in selectedRecipe.ingredients) { EditorGUILayout.BeginHorizontal (); EditorGUILayout.LabelField ("Ingredient:", GUILayout.Width (70f)); i = GetArraySlot (ingredient.itemID); i = EditorGUILayout.Popup (i, GetLabelList ()); ingredient.itemID = items[i].id; if (items[i].canCarryMultiple) { EditorGUILayout.LabelField ("Amount:", GUILayout.Width (50f)); ingredient.amount = EditorGUILayout.IntField (ingredient.amount, GUILayout.Width (30f)); } if (selectedRecipe.useSpecificSlots) { EditorGUILayout.LabelField ("Slot:", GUILayout.Width (30f)); ingredient.slotNumber = EditorGUILayout.IntField (ingredient.slotNumber, GUILayout.Width (30f)); } if (GUILayout.Button ("-", GUILayout.Width (20f), GUILayout.Height (15f))) { Undo.RecordObject (this, "Delete ingredient"); selectedRecipe.ingredients.Remove (ingredient); AssetDatabase.SaveAssets(); break; } EditorGUILayout.EndHorizontal (); } if (GUILayout.Button("Add new ingredient")) { Undo.RecordObject (this, "Add recipe ingredient"); Ingredient newIngredient = new Ingredient (); selectedRecipe.ingredients.Add (newIngredient); } EditorGUILayout.EndVertical (); } }
/** * <summary>Checks if a collection of inventory item instances has all the items necessary to craft this recipe's item.</summary> * <param name="invCollection">The collection of inventory item instances to check</param> * <returns>True if the collection has all the items necessary to craft the recipe's item</returns> */ public bool CanBeCrafted(InvCollection invCollection) { if (HasInvalidItems(invCollection)) { return(false); } if (useSpecificSlots) { int maxSlot = invCollection.InvInstances.Count - 1; foreach (Ingredient ingredient in ingredients) { if (maxSlot < ingredient.CraftingIndex) { maxSlot = ingredient.CraftingIndex; } } if (maxSlot < 0) { return(false); } for (int i = 0; i <= maxSlot; i++) { Ingredient ingredient = GetIngredientForIndex(i); InvInstance invInstance = invCollection.GetInstanceAtIndex(i); if (InvInstance.IsValid(invInstance)) { // Item in slot if (ingredient == null) { return(false); } if (ingredient.ItemID != invInstance.ItemID) { return(false); } if (ingredient.Amount > invInstance.Count) { return(false); } } else { // Slot is empty if (ingredient != null) { return(false); } } } } else { // Indices don't matter, just check counts are correct foreach (Ingredient ingredient in ingredients) { int ingredientCount = invCollection.GetCount(ingredient.ItemID); if (ingredientCount < ingredient.Amount) { return(false); } } } return(true); }