public void SetOutput(MenuSource source, bool autoCreate) { items = new List<InvItem>(); activeRecipe = KickStarter.runtimeInventory.CalculateRecipe (autoCreate); if (activeRecipe != null) { foreach (InvItem assetItem in AdvGame.GetReferences ().inventoryManager.items) { if (assetItem.id == activeRecipe.resultID) { InvItem newItem = new InvItem (assetItem); newItem.count = 1; items.Add (newItem); } } } if (!autoCreate) { base.RecalculateSize (source); } }
private void DeactivateAllRecipes () { foreach (Recipe recipe in recipes) { recipe.isEditing = false; } selectedRecipe = null; }
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 (); } }
private void ActivateRecipe (Recipe recipe) { recipe.isEditing = true; selectedRecipe = recipe; }
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 ActivateRecipe(Recipe recipe) { recipe.isEditing = true; selectedRecipe = recipe; }
/** * <summary>Crafts a new inventory item, and removes the relevent ingredients, according to a Recipe.</summary> * <param name = "recipe">The Recipe to perform</param> * <param name = "selectAfter">If True, then the resulting inventory item will be selected once the crafting is complete</param> */ public void PerformCrafting(Recipe recipe, bool selectAfter) { foreach (Ingredient ingredient in recipe.ingredients) { for (int i=0; i<craftingItems.Count; i++) { if (craftingItems [i].id == ingredient.itemID) { if (craftingItems [i].canCarryMultiple && ingredient.amount > 0) { craftingItems [i].count -= ingredient.amount; if (craftingItems [i].count < 1) { craftingItems.RemoveAt (i); } } else { craftingItems.RemoveAt (i); } } } } RemoveEmptyCraftingSlots (); Add (recipe.resultID, 1, selectAfter, -1); }
private bool IsRecipeInvalid(Recipe recipe) { // Are any invalid ingredients present? foreach (InvItem item in craftingItems) { bool found = false; foreach (Ingredient ingredient in recipe.ingredients) { if (ingredient.itemID == item.id) { found = true; } } if (!found) { // Not present in recipe return true; } } return false; }