private bool ClickOutput(AC.Menu _menu, MouseState _mouseState) { if (invInstances.Count > 0) { if (_mouseState == MouseState.SingleClick && !InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance)) { // Pick up created item switch (activeRecipe.onCreateRecipe) { case OnCreateRecipe.SelectItem: KickStarter.runtimeInventory.PerformCrafting(activeRecipe, true); break; case OnCreateRecipe.JustMoveToInventory: KickStarter.runtimeInventory.PerformCrafting(activeRecipe, false); break; case OnCreateRecipe.RunActionList: KickStarter.runtimeInventory.PerformCrafting(activeRecipe, false); if (activeRecipe.invActionList) { AdvGame.RunActionListAsset(activeRecipe.invActionList); } break; default: break; } return(true); } } return(false); }
/** Selects the associated item */ public void Select(SelectItemMode _selectItemMode = SelectItemMode.Use) { if (InvInstance.IsValid(this)) { KickStarter.runtimeInventory.SelectItem(this, _selectItemMode); } }
protected override void AutoSize() { if (invInstances.Count > 0) { foreach (InvInstance invInstance in invInstances) { if (InvInstance.IsValid(invInstance)) { switch (displayType) { case ConversationDisplayType.IconOnly: AutoSize(new GUIContent(invInstance.InvItem.tex)); break; case ConversationDisplayType.TextOnly: AutoSize(new GUIContent(invInstance.InvItem.label)); break; default: break; } return; } } } else { AutoSize(GUIContent.none); } }
/** * <summary>Generates data to save about an item instance in a single string.</summary> * <param name = "invInstance">The inventory item instance to save</param> * <returns>Save data for the instance as a single string</returns> */ public static string GetSaveData(InvInstance invInstance) { string dataString = string.Empty; if (IsValid(invInstance)) { dataString += invInstance.itemID.ToString(); dataString += SaveSystem.colon; dataString += invInstance.count.ToString(); dataString += SaveSystem.colon; dataString += invInstance.GetPropertySaveData(); dataString += SaveSystem.pipe; } else if (KickStarter.settingsManager.canReorderItems) { dataString += "-1"; dataString += SaveSystem.colon; dataString += "0"; dataString += SaveSystem.colon; dataString += "_"; dataString += SaveSystem.pipe; } return(dataString); }
/** * <summary>Deletes all item instances that make up a recipe's ingredients</summary> * <param name="recipe">The recipe to delete ingredients from</param> */ public void DeleteRecipeIngredients(Recipe recipe) { if (recipe.useSpecificSlots) { for (int i = 0; i < recipe.ingredients.Count; i++) { int numToRemove = recipe.ingredients[i].Amount; if (i >= 0 && i < invInstances.Count && InvInstance.IsValid(invInstances[i])) { invInstances[i].Count -= numToRemove; } } Clean(); PlayerMenus.ResetInventoryBoxes(); } else { foreach (Ingredient ingredient in recipe.ingredients) { int itemIDToRemove = ingredient.ItemID; int numToRemove = ingredient.Amount; Delete(itemIDToRemove, numToRemove); } } }
/** * <summary>Deletes all inventory item instances associated with a given inventory item</summary> * <param name="itemID">The ID of the inventory item to delete</param> */ public void DeleteAllOfType(int itemID) { if (KickStarter.inventoryManager == null) { return; } InvItem itemToRemove = KickStarter.inventoryManager.GetItem(itemID); if (itemToRemove == null) { return; } for (int i = 0; i < invInstances.Count; i++) { if (InvInstance.IsValid(invInstances[i]) && invInstances[i].ItemID == itemID) { invInstances[i].Clear(); } } Clean(); PlayerMenus.ResetInventoryBoxes(); }
protected void DrawInventoryCursor() { InvInstance invInstance = KickStarter.runtimeInventory.SelectedInstance; if (!InvInstance.IsValid(invInstance)) { return; } if (invInstance.CursorIcon.texture) { if (KickStarter.settingsManager.inventoryActiveEffect != InventoryActiveEffect.None) { // Only animate when active DrawIcon(invInstance.CursorIcon, false, false); } else { DrawIcon(invInstance.CursorIcon, false, true); } } else { DrawIcon(AdvGame.GUIBox(KickStarter.playerInput.GetMousePosition(), KickStarter.cursorManager.inventoryCursorSize), invInstance.InvItem.tex); } pulseDirection = 0; }
public MatchingInvInteractionData(Hotspot hotspot) { invInstances = new List <InvInstance> (); invInteractionIndices = new List <int>(); selectItemModes = new List <SelectItemMode>(); for (int i = 0; i < hotspot.invButtons.Count; i++) { Button button = hotspot.invButtons[i]; if (button.isDisabled) { continue; } foreach (InvInstance invInstance in KickStarter.runtimeInventory.PlayerInvCollection.InvInstances) { if (InvInstance.IsValid(invInstance) && invInstance.ItemID == button.invID && !button.isDisabled) { invInteractionIndices.Add(i); selectItemModes.Add(button.selectItemMode); invInstances.Add(invInstance); break; } } } }
private bool ListItems(InvCollection invCollection) { bool isCarrying = false; foreach (InvInstance invInstance in invCollection.InvInstances) { if (InvInstance.IsValid(invInstance)) { isCarrying = true; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Item:", GUILayout.Width(80f)); if (invInstance.InvItem.canCarryMultiple) { EditorGUILayout.LabelField(invInstance.InvItem.label, EditorStyles.boldLabel, GUILayout.Width(135f)); EditorGUILayout.LabelField("Count:", GUILayout.Width(50f)); EditorGUILayout.LabelField(invInstance.InvItem.count.ToString(), GUILayout.Width(44f)); } else { EditorGUILayout.LabelField(invInstance.InvItem.label, EditorStyles.boldLabel); } EditorGUILayout.EndHorizontal(); } } return(isCarrying); }
private void Clean() { // Limit max slots if (maxSlots > 0 && maxSlots < invInstances.Count) { invInstances.RemoveRange(maxSlots, invInstances.Count - maxSlots); } // Convert invalid to empty for (int i = 0; i < invInstances.Count; i++) { if (!InvInstance.IsValid(invInstances[i])) { invInstances[i] = null; } } // Remove empty slots on end for (int i = invInstances.Count - 1; i >= 0; i--) { if (!InvInstance.IsValid(invInstances[i])) { invInstances.RemoveAt(i); } else { break; } } // Remove empty slots inside, if re-ordering is disallowed if (!CanReorder()) { for (int i = 0; i < invInstances.Count; i++) { if (invInstances[i] == null) { invInstances.RemoveAt(i); i--; } } } // Separate by max count /*for (int i=0; i< invInstances.Count; i++) * { * if (InvInstance.IsValid (invInstances[i]) && invInstances[i].InvItem.canCarryMultiple && invInstances[i].Count > invInstances[i].InvItem.maxCount) * { * while (invInstances[i].Count > invInstances[i].InvItem.maxCount) * { * int surplus = invInstances[i].Count - invInstances[i].InvItem.maxCount; * invInstances[i].TransferCount = Mathf.Clamp (surplus, 0, invInstances[i].InvItem.maxCount); * * * Insert (invInstances[i], i+1); * } * } * }*/ }
/** * <summary>Runs the item's default 'Use' interactions. This is the first defined 'Standard Interaction' in the item's properties.</summary> */ public void RunDefaultInteraction() { if (interactions != null && interactions.Count > 0) { InvInstance newInstance = new InvInstance(this); newInstance.Use(interactions[0].icon.id); } }
/** * <summary>Checks if the instance is both non-null, and references an item</summary> * <param name="invInstance">The instance to check</param> * <returns>True if the instance is non-null and references an item</returns> */ public static bool IsValid(InvInstance invInstance) { if (invInstance != null) { return(invInstance.count > 0 && invInstance.itemID >= 0 && invInstance.invItem != null); } return(false); }
protected void DrawActiveInventoryCursor() { InvInstance invInstance = KickStarter.runtimeInventory.SelectedInstance; if (!InvInstance.IsValid(invInstance)) { return; } if (invInstance.CursorIcon.texture) { DrawIcon(invInstance.CursorIcon, false, true); } else if (invInstance.InvItem.activeTex == null) { DrawInventoryCursor(); } else if (KickStarter.settingsManager.inventoryActiveEffect == InventoryActiveEffect.Simple) { DrawIcon(AdvGame.GUIBox(KickStarter.playerInput.GetMousePosition(), KickStarter.cursorManager.inventoryCursorSize), invInstance.InvItem.activeTex); } else if (KickStarter.settingsManager.inventoryActiveEffect == InventoryActiveEffect.Pulse && invInstance.InvItem.tex) { if (pulseDirection == 0) { pulse = 0f; pulseDirection = 1; } else if (pulse > 1f) { pulse = 1f; pulseDirection = -1; } else if (pulse < 0f) { pulse = 0f; pulseDirection = 1; } else if (pulseDirection == 1) { pulse += KickStarter.settingsManager.inventoryPulseSpeed * Time.deltaTime; } else if (pulseDirection == -1) { pulse -= KickStarter.settingsManager.inventoryPulseSpeed * Time.deltaTime; } Color backupColor = GUI.color; Color tempColor = GUI.color; tempColor.a = pulse; GUI.color = tempColor; DrawIcon(AdvGame.GUIBox(KickStarter.playerInput.GetMousePosition(), KickStarter.cursorManager.inventoryCursorSize), invInstance.InvItem.activeTex); GUI.color = backupColor; DrawIcon(AdvGame.GUIBox(KickStarter.playerInput.GetMousePosition(), KickStarter.cursorManager.inventoryCursorSize), invInstance.InvItem.tex); } }
/** * <summary>Deletes a given inventory item instance, provided it is a part of this collection</summary> * <param name="invInstance">The inventory item instance to delete</param> * <param name="amount">The amount to delete</param> */ public void Delete(InvInstance invInstance, int amount) { if (invInstances.Contains(invInstance)) { invInstance.Clear(amount); Clean(); PlayerMenus.ResetInventoryBoxes(); } }
/** * <summary>Deletes a set number of inventory item instances at a given index</summary> * <param name="index">The index to delete from</param> * <param name="amount">The amount to delete</param> */ public void DeleteAtIndex(int index, int amount) { if (index > 0 && index < invInstances.Count && InvInstance.IsValid(invInstances[index])) { invInstances[index].Clear(amount); Clean(); PlayerMenus.ResetInventoryBoxes(); } }
/** * <summary>Adds an inventory item to the Container's contents, at a particular index.</summary> * <param name = "itemInstance">The instance of the item to place within the Container</param> * <param name = "_index">The index number within the Container's current contents to insert the new item</param> * <param name = "count">If >0, the quantity of the item to be added. Otherwise, the same quantity as _item will be added</param> */ public void InsertAt(InvInstance itemInstance, int index, int amountOverride = 0) { if (!InvInstance.IsValid(itemInstance)) { return; } itemInstance.TransferCount = (amountOverride > 0) ? amountOverride : 0; invCollection.Insert(itemInstance, index); }
/** * <summary>Gets the inventory item instance in the collection at a given index</summary> * <param name="index">The index to get</param> * <returns>The inventory item instance at the index</returns> */ public InvInstance GetInstanceAtIndex(int index) { if (index >= 0 && index < invInstances.Count) { if (InvInstance.IsValid(invInstances[index])) { return(invInstances[index]); } } return(null); }
/** * <summary>Gets the slot index number that a given InvItem (inventory item) appears in.</summary> * <param name = "invInstance">The instance of the InvItem to search for</param> * <returns>The slot index number that the inventory item appears in</returns> */ public int GetItemSlot(InvInstance invInstance) { for (int i = 0; i < invInstances.Count; i++) { if (InvInstance.IsValid(invInstances[i]) && invInstances[i] == invInstance) { return(i - offset); } } return(0); }
/** Checks if the collection contains an inventory instance associated with a given inventory item */ public bool Contains(int invID) { foreach (InvInstance invInstance in invInstances) { if (InvInstance.IsValid(invInstance) && invInstance.ItemID == invID) { return(true); } } return(false); }
/** * <summary>Gets the first-found inventory item instance in the collection that's associated with a specific inventory item</summary> * <param name="invID">The ID number of the inventory item</param> * <returns>The first-found inventory item instance</returns> */ public InvInstance GetFirstInstance(int invID) { foreach (InvInstance invInstance in invInstances) { if (InvInstance.IsValid(invInstance) && invInstance.ItemID == invID) { return(invInstance); } } return(null); }
/** * <summary>Gets the first-found inventory item instance in the collection that's associated with a specific inventory item</summary> * <param name="invName">The name of the inventory item</param> * <returns>The first-found inventory item instance</returns> */ public InvInstance GetFirstInstance(string invName) { foreach (InvInstance invInstance in invInstances) { if (InvInstance.IsValid(invInstance) && invInstance.InvItem.label == invName) { return(invInstance); } } return(null); }
/** * <summary>Deletes all item instances in a specific category</summary> * <param name="categoryID">The ID of the category to remove items from</param> */ public void DeleteAllInCategory(int categoryID) { for (int i = 0; i < invInstances.Count; i++) { if (InvInstance.IsValid(invInstances[i]) && invInstances[i].InvItem.binID == categoryID) { invInstances[i] = null; i = -1; } } Clean(); }
protected void CycleCursors() { if (KickStarter.playerInteraction.GetActiveHotspot() && KickStarter.playerInteraction.GetActiveHotspot().IsSingleInteraction()) { return; } int newSelectedCursor = selectedCursor; if (KickStarter.cursorManager.cursorIcons.Count > 0) { newSelectedCursor++; if (newSelectedCursor >= KickStarter.cursorManager.cursorIcons.Count) { newSelectedCursor = -1; } else if (newSelectedCursor >= 0 && newSelectedCursor < KickStarter.cursorManager.cursorIcons.Count && KickStarter.cursorManager.cursorIcons [newSelectedCursor].dontCycle) { while (KickStarter.cursorManager.cursorIcons [newSelectedCursor].dontCycle) { newSelectedCursor++; if (newSelectedCursor >= KickStarter.cursorManager.cursorIcons.Count) { newSelectedCursor = -1; break; } } } } else { // Pointer newSelectedCursor = -1; } if (newSelectedCursor == -1 && selectedCursor >= 0) { // Ended icon cycle if (KickStarter.settingsManager.cycleInventoryCursors) { KickStarter.runtimeInventory.ReselectLastItem(); if (InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance)) { KickStarter.playerInput.ResetMouseClick(); return; } } } SelectedCursor = newSelectedCursor; }
/** * <summary>Gets all inventory item instance in the collection that are associated with a specific inventory item</summary> * <param name="invName">The nameof the inventory item</param> * <returns>An array of inventory item instance</returns> */ public InvInstance[] GetAllInstances(string invName) { List <InvInstance> foundInstances = new List <InvInstance> (); foreach (InvInstance invInstance in invInstances) { if (InvInstance.IsValid(invInstance) && invInstance.InvItem.label == invName) { foundInstances.Add(invInstance); } } return(foundInstances.ToArray()); }
private bool ItemIsSelected(int index) { if (!InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance)) { return(false); } if (index > 0 && index < invInstances.Count && (!KickStarter.settingsManager.InventoryDragDrop || KickStarter.playerInput.GetDragState() == DragState.Inventory)) { return(invInstances[index] == KickStarter.runtimeInventory.SelectedInstance); } return(false); }
/** * <summary>Gets all inventory item instance in the collection that are associated with a specific inventory item</summary> * <param name="invID">The ID of the inventory item</param> * <returns>An array of inventory item instance</returns> */ public InvInstance[] GetAllInstances(int invID) { List <InvInstance> foundInstances = new List <InvInstance>(); foreach (InvInstance invInstance in invInstances) { if (InvInstance.IsValid(invInstance) && invInstance.ItemID == invID) { foundInstances.Add(invInstance); } } return(foundInstances.ToArray()); }
/** * <summary>Runs one of the item's 'Use' interactions.</summary> * <param name = "iconID">The ID number of the CursorIcon associated with the use interaction. If no number is supplied, the default use interaction will be run.</param> */ public void RunUseInteraction(int iconID = -1) { InvInstance newInstance = new InvInstance(this); if (iconID < 0) { newInstance.Use(); } else { newInstance.Use(iconID); } }
public override bool CheckCondition() { if (KickStarter.runtimeInventory) { switch (selectedCheckMethod) { case SelectedCheckMethod.NoneSelected: if (!InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance)) { return(true); } break; case SelectedCheckMethod.SpecificItem: if (includeLast) { if (InvInstance.IsValid(KickStarter.runtimeInventory.LastSelectedInstance) && KickStarter.runtimeInventory.LastSelectedInstance.ItemID == invID) { return(true); } } else { if (InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance) && KickStarter.runtimeInventory.SelectedInstance.ItemID == invID) { return(true); } } break; case SelectedCheckMethod.InSpecificCategory: if (includeLast) { if (InvInstance.IsValid(KickStarter.runtimeInventory.LastSelectedInstance) && KickStarter.runtimeInventory.LastSelectedInstance.InvItem.binID == binID) { return(true); } } else { if (InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance) && KickStarter.runtimeInventory.SelectedInstance.InvItem.binID == binID) { return(true); } } break; } } return(false); }
/** * <summary>Deletes a set number of inventory item instances</summary> * <param name="itemID">The ID of the inventory item to delete</param> * <param name="amount">The amount to delete</param> */ public void Delete(int itemID, int amount) { if (KickStarter.inventoryManager == null) { return; } InvItem itemToRemove = KickStarter.inventoryManager.GetItem(itemID); if (itemToRemove == null) { return; } for (int i = 0; i < invInstances.Count; i++) { if (InvInstance.IsValid(invInstances[i]) && invInstances[i].ItemID == itemID) { // Count check if (itemToRemove.canCarryMultiple) { int diff = invInstances[i].Count - amount; if (diff >= 0) { invInstances[i].Clear(amount); amount = 0; } else { amount -= invInstances[i].Count; invInstances[i].Clear(); } } if (!itemToRemove.canCarryMultiple || invInstances[i].Count <= 0) { invInstances[i].Clear(); } if (!itemToRemove.canCarryMultiple || amount <= 0) { break; } } } Clean(); PlayerMenus.ResetInventoryBoxes(); }
public override float Run() { if (KickStarter.runtimeInventory == null) { return(0f); } Upgrade(); if (selectType == InventorySelectType.DeselectActive) { KickStarter.runtimeInventory.SetNull(); } else { if (!KickStarter.settingsManager.CanSelectItems(true)) { return(0f); } switch (carryCondition) { case CarryCondition.OnlyIfCarrying: if (KickStarter.runtimeInventory.PlayerInvCollection.Contains(invID)) { KickStarter.runtimeInventory.SelectItemByID(invID, selectItemMode); } break; case CarryCondition.AddIfNotCarrying: if (!KickStarter.runtimeInventory.PlayerInvCollection.Contains(invID)) { InvInstance newInstance = KickStarter.runtimeInventory.PlayerInvCollection.AddToEnd(new InvInstance(invID, 1)); KickStarter.runtimeInventory.SelectItem(newInstance); } else { KickStarter.runtimeInventory.SelectItemByID(invID, selectItemMode); } break; case CarryCondition.IgnoreCurrentInventory: KickStarter.runtimeInventory.SelectItemByID(invID, selectItemMode, true); break; } } return(0f); }