diff --git a/Assets/Inventory System/Prefabs/Inventory System.prefab b/Assets/Inventory System/Prefabs/Inventory System.prefab index 6e0e064b..a2054324 100644 --- a/Assets/Inventory System/Prefabs/Inventory System.prefab +++ b/Assets/Inventory System/Prefabs/Inventory System.prefab @@ -684,8 +684,8 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1165938063523323413} m_HandleRect: {fileID: 2233503621217788993} m_Direction: 0 - m_Value: 0.0000007665326 - m_Size: 0.47786885 + m_Value: 0.000001053982 + m_Size: 0.4778688 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -856,7 +856,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2108268662488080482} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} m_Name: @@ -2115,7 +2115,7 @@ GameObject: - component: {fileID: 2770326604769037616} - component: {fileID: 2770326604769037583} m_Layer: 5 - m_Name: Slot + m_Name: Pocket Slot A m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -2825,7 +2825,7 @@ GameObject: - component: {fileID: 2770326604921404284} - component: {fileID: 2770326604921404283} m_Layer: 5 - m_Name: Slot + m_Name: Pocket Slot D m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -3407,7 +3407,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0.00024414062, y: 0} + m_AnchoredPosition: {x: 0.00012207031, y: 0} m_SizeDelta: {x: 0, y: 2250} m_Pivot: {x: 0, y: 1} --- !u!114 &2770326604978625766 @@ -3450,7 +3450,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2770326604978625764} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} m_Name: @@ -9018,7 +9018,7 @@ GameObject: - component: {fileID: 2770326605689845840} - component: {fileID: 2770326605689845841} m_Layer: 5 - m_Name: Grid (1) + m_Name: Pockets Grid m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -9933,42 +9933,88 @@ MonoBehaviour: TagSlotPairings: - itemTag: 12 slot: {fileID: 8600850533622123873} + prioritizeItemStoreFirst: 0 - itemTag: 1 slot: {fileID: 2770326606581535715} + prioritizeItemStoreFirst: 0 - itemTag: 2 slot: {fileID: 2770326606075084494} + prioritizeItemStoreFirst: 0 - itemTag: 5 slot: {fileID: 2770326606094932650} + prioritizeItemStoreFirst: 0 - itemTag: 5 slot: {fileID: 2770326605248660894} + prioritizeItemStoreFirst: 0 - itemTag: 6 slot: {fileID: 2770326606217848658} + prioritizeItemStoreFirst: 0 - itemTag: 6 slot: {fileID: 2770326605161289228} + prioritizeItemStoreFirst: 0 - itemTag: 7 slot: {fileID: 2770326605798828943} + prioritizeItemStoreFirst: 0 - itemTag: 8 slot: {fileID: 2770326604706167503} + prioritizeItemStoreFirst: 0 - itemTag: 9 slot: {fileID: 2770326606194450705} + prioritizeItemStoreFirst: 0 - itemTag: 13 slot: {fileID: 2770326605039798017} + prioritizeItemStoreFirst: 0 - itemTag: 14 slot: {fileID: 2770326605069652580} + prioritizeItemStoreFirst: 0 - itemTag: 15 slot: {fileID: 2770326605604029972} + prioritizeItemStoreFirst: 0 - itemTag: 16 slot: {fileID: 2770326606725301634} - - itemTag: 9 - slot: {fileID: 2770326606194450705} + prioritizeItemStoreFirst: 0 - itemTag: 18 slot: {fileID: 2770326606194450705} + prioritizeItemStoreFirst: 0 - itemTag: 17 slot: {fileID: 2770326606302022802} + prioritizeItemStoreFirst: 0 TagSlotGridPairings: - itemTag: 0 + referenceType: 2 + ReferencedGrid: {fileID: 2770326605902186952} slot: {fileID: 8600850533622123873} grid: {fileID: 0} + - itemTag: 0 + referenceType: 3 + ReferencedGrid: {fileID: 0} + slot: {fileID: 0} + grid: {fileID: 2770326605807543574} + - itemTag: 0 + referenceType: 0 + ReferencedGrid: {fileID: 2770326604769037581} + slot: {fileID: 0} + grid: {fileID: 2770326605807543574} + - itemTag: 0 + referenceType: 0 + ReferencedGrid: {fileID: 2770326606686766473} + slot: {fileID: 0} + grid: {fileID: 2770326605807543574} + - itemTag: 0 + referenceType: 0 + ReferencedGrid: {fileID: 2770326605995264619} + slot: {fileID: 0} + grid: {fileID: 2770326605807543574} + - itemTag: 0 + referenceType: 0 + ReferencedGrid: {fileID: 2770326604921404281} + slot: {fileID: 0} + grid: {fileID: 2770326605807543574} + - itemTag: 0 + referenceType: 1 + ReferencedGrid: {fileID: 2770326605807543572} + slot: {fileID: 0} + grid: {fileID: 2770326605807543574} raritiesList: - rarityType: 0 color: {r: 0.6, g: 0.6, b: 0.6, a: 0} @@ -10355,6 +10401,7 @@ MonoBehaviour: - {fileID: 0} - {fileID: 0} - {fileID: 0} + itemsOnGrid: [] --- !u!222 &2770326605807543577 CanvasRenderer: m_ObjectHideFlags: 0 @@ -11599,7 +11646,7 @@ GameObject: - component: {fileID: 2770326605995264622} - component: {fileID: 2770326605995264621} m_Layer: 5 - m_Name: Slot + m_Name: Pocket Slot C m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -12942,7 +12989,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: -0.0004272461, y: -0.0009530247} + m_AnchoredPosition: {x: -0.0005689588, y: -0.00016524519} m_SizeDelta: {x: 1220, y: 1200} m_Pivot: {x: 0, y: 1} --- !u!114 &2770326606141421693 @@ -18184,7 +18231,7 @@ GameObject: - component: {fileID: 2770326606686766476} - component: {fileID: 2770326606686766475} m_Layer: 5 - m_Name: Slot + m_Name: Pocket Slot B m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -20201,7 +20248,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 8873855520739210168} m_HandleRect: {fileID: 52681282418728116} m_Direction: 2 - m_Value: 1.0000024 + m_Value: 1.0000002 m_Size: 0.6525 m_NumberOfSteps: 0 m_OnValueChanged: diff --git a/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_1x1.prefab b/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_1x1.prefab index c5172ace..f1aa29b7 100644 --- a/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_1x1.prefab +++ b/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_1x1.prefab @@ -11,6 +11,7 @@ GameObject: - component: {fileID: 4440658733661691366} - component: {fileID: 2813530617427812674} - component: {fileID: 2772551615480428293} + - component: {fileID: 4972946875524611880} m_Layer: 5 m_Name: Pouch_Cells_1x1 m_TagString: Untagged @@ -78,11 +79,26 @@ MonoBehaviour: type: 3} generateCells: 0 slots: [] + associatedItemUI: {fileID: 0} gridSize: Width: 1 Height: 1 testItem: {fileID: 0} testItems: [] +--- !u!114 &4972946875524611880 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4961555904879958529} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1ed269bdb4294dc429d767fed43a92aa, type: 3} + m_Name: + m_EditorClassIdentifier: + AllowedItemTags: + DisallowedItemTags: 0d0000000e0000000f00000010000000 --- !u!1001 &2797168179609513955 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_2x1.prefab b/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_2x1.prefab index a0481a5d..4fdb2ce6 100644 --- a/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_2x1.prefab +++ b/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_2x1.prefab @@ -11,6 +11,7 @@ GameObject: - component: {fileID: 4440658733661691366} - component: {fileID: 2813530617427812674} - component: {fileID: 2772551615480428293} + - component: {fileID: 5669249702482988909} m_Layer: 5 m_Name: Pouch_Cells_2x1 m_TagString: Untagged @@ -79,11 +80,26 @@ MonoBehaviour: type: 3} generateCells: 0 slots: [] + associatedItemUI: {fileID: 0} gridSize: Width: 1 Height: 2 testItem: {fileID: 0} testItems: [] +--- !u!114 &5669249702482988909 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4961555904879958529} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1ed269bdb4294dc429d767fed43a92aa, type: 3} + m_Name: + m_EditorClassIdentifier: + AllowedItemTags: + DisallowedItemTags: 0d0000000e0000000f00000010000000 --- !u!1001 &2654960344705592353 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_2x2.prefab b/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_2x2.prefab index a1c4a51b..16113160 100644 --- a/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_2x2.prefab +++ b/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_2x2.prefab @@ -11,6 +11,7 @@ GameObject: - component: {fileID: 4440658733661691366} - component: {fileID: 2813530617427812674} - component: {fileID: 2772551615480428293} + - component: {fileID: 1471210313782040237} m_Layer: 5 m_Name: Pouch_Cells_2x2 m_TagString: Untagged @@ -81,11 +82,26 @@ MonoBehaviour: type: 3} generateCells: 0 slots: [] + associatedItemUI: {fileID: 0} gridSize: Width: 2 Height: 2 testItem: {fileID: 0} testItems: [] +--- !u!114 &1471210313782040237 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4961555904879958529} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1ed269bdb4294dc429d767fed43a92aa, type: 3} + m_Name: + m_EditorClassIdentifier: + AllowedItemTags: + DisallowedItemTags: 0d0000000e0000000f00000010000000 --- !u!1001 &2654960344705592353 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_3x1.prefab b/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_3x1.prefab index 8af9f3e7..ddbf9f45 100644 --- a/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_3x1.prefab +++ b/Assets/Inventory System/Prefabs/UI Elements/Cells/Pouch_Cells_3x1.prefab @@ -11,8 +11,9 @@ GameObject: - component: {fileID: 4440658733661691366} - component: {fileID: 2813530617427812674} - component: {fileID: 2772551615480428293} + - component: {fileID: 5726478664858734726} m_Layer: 5 - m_Name: Pouch_Cells_1x3 + m_Name: Pouch_Cells_3x1 m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -80,11 +81,26 @@ MonoBehaviour: type: 3} generateCells: 0 slots: [] + associatedItemUI: {fileID: 0} gridSize: Width: 1 Height: 3 testItem: {fileID: 0} testItems: [] +--- !u!114 &5726478664858734726 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4961555904879958529} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1ed269bdb4294dc429d767fed43a92aa, type: 3} + m_Name: + m_EditorClassIdentifier: + AllowedItemTags: + DisallowedItemTags: 0d0000000e0000000f00000010000000 --- !u!1001 &1541749983105574545 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Inventory System/Scripts/Inventory/InventorySystem.cs b/Assets/Inventory System/Scripts/Inventory/InventorySystem.cs index fcee2d71..82e8d0ab 100644 --- a/Assets/Inventory System/Scripts/Inventory/InventorySystem.cs +++ b/Assets/Inventory System/Scripts/Inventory/InventorySystem.cs @@ -72,6 +72,7 @@ namespace SimpleInventorySystem { public ItemTags itemTag; public SlotUI slot; + public bool prioritizeItemStoreFirst; public bool HasSlotOccupied() { @@ -93,32 +94,156 @@ namespace SimpleInventorySystem public class TagSlotGridPairing { public ItemTags itemTag; - public SlotUI slot; + public enum ReferenceTypes { SlotUI, GridUI, GridUIFromSlot, TagSlotGridPairUI } + public ReferenceTypes referenceType = ReferenceTypes.SlotUI; + public GameObject ReferencedGrid; + [HideInInspector] public SlotUI slot; [HideInInspector] public GridUI grid; + public TagSlotGridPairing() + { + Debug.Log("this should be called"); + SetSlotsOrGrid(); + /*if (tagSlotGridPairUI == null && slot == null && tagSlotGridPairUI == null) + { + Debug.LogWarning($"TagSlotGridPairing: This TagSlotGridPairing will not work for {itemTag} on type {referenceType}."); + }*/ + } + + public void SetSlotsOrGrid() + { + switch (referenceType) + { + case ReferenceTypes.SlotUI: + { + if (ReferencedGrid != null) + slot = ReferencedGrid.GetComponent(); + else + { + Debug.LogWarning($"TagSlotGridPairing: ReferencedGrid missing."); + } + break; + } + case ReferenceTypes.GridUI: + { + if (ReferencedGrid != null) + grid = ReferencedGrid.GetComponent(); + else + { + Debug.LogWarning($"TagSlotGridPairing: ReferencedGrid missing."); + } + break; + } + case ReferenceTypes.GridUIFromSlot: + { + if (ReferencedGrid != null) + { + slot = ReferencedGrid.GetComponent(); + } + else + { + Debug.LogWarning($"TagSlotGridPairing: ReferencedGrid missing."); + } + break; + } + case ReferenceTypes.TagSlotGridPairUI: + { + if (ReferencedGrid != null) + { + Debug.LogWarning($"TagSlotGridPairing: This TagSlotGridPairing may not use {ReferencedGrid.name} as a Referenced Grid because reference type {referenceType} will search for most available slot based on Heiarchy order."); + } + break; + } + } + } + public bool IsSlotOccupied() { return slot.GetItemUI() != null; } - public bool DropOntoGrid(ItemUI item) + protected bool DropOntoGrid(ItemUI item) { //List cells = new List(); //bool canMoveInCells = grid.CanMoveInCells(item, slot, cells); bool dropped = CanStore(item) && grid.DropItemOnGrid(item.gameObject); - //Debug.Log("IS:" + dropped); + Debug.Log("IS:Dropped:" + dropped); + return dropped; + } + protected bool DropOntoSlot(ItemUI item) + { + bool dropped = CanStore(item) && slot.DropOntoSlot(item.gameObject); + Debug.Log("IS:Dropped:" + dropped); + return dropped; + } + + public bool Drop(ItemUI item) + { + bool dropped = (referenceType == ReferenceTypes.SlotUI) ? DropOntoSlot(item) : DropOntoGrid(item); return dropped; } public bool CanStore(ItemUI item) { - bool preliminaryCheck = item != null && (item.ItemTag == itemTag || itemTag == ItemTags.Any) && slot != null && IsSlotOccupied() && slot.GetItemUI().container != null; - bool slotCheck = preliminaryCheck && slot != null && slot.GetItemUI() != null && slot.GetItemUI().container != null; - if (!slotCheck) - return slotCheck; - grid = slot.GetItemUI().container.GetComponent(); - bool gridCheck = grid != null; - //Debug.Log("IS:" + gridCheck); + SetSlotsOrGrid(); + + bool preliminaryCheck = item != null && (item.ItemTag == itemTag || itemTag == ItemTags.Any) && slot != null; + //Debug.Log("IS:CanStore" + (preliminaryCheck)); + //Debug.Log("IS:CanStore" + (slot != null)); + bool slotCheck = false; + bool gridCheck = false; + + if (slot != null && (referenceType == ReferenceTypes.GridUIFromSlot || referenceType == ReferenceTypes.SlotUI)) + { + if(referenceType == ReferenceTypes.GridUIFromSlot) + { + slotCheck = preliminaryCheck && IsSlotOccupied() && slot.GetItemUI().container != null && slot != null && slot.GetItemUI() != null && slot.GetItemUI().container != null; + if (slotCheck) + { + grid = slot.GetItemUI().container.GetComponent(); + } + gridCheck = grid != null && !grid.IsAssociatedItem(item) && !grid.ContainsItemFromGrid(item); // TODO: improve on this for stacking + //Debug.Log($"Contains Item From Grid: {gridCheck}"); + //TODO: create function to check if item is inside grid. + } + else + { + slotCheck = preliminaryCheck && (!IsSlotOccupied() || slot.GetItemUI().Stackable) && slot != item.GetSlotUI(); + //Debug.Log(slotCheck); + gridCheck = true; + } + } + else if (referenceType == ReferenceTypes.GridUI) + { + slotCheck = true; + gridCheck = grid != null && !grid.ContainsItemFromGrid(item); + } + else if (referenceType == ReferenceTypes.TagSlotGridPairUI) + { + slotCheck = true; + TagSlotGridPairUI[] gridPairs = InventorySystem.instance.inventoryUI.GetComponentsInChildren(); + foreach (TagSlotGridPairUI gp in gridPairs) + { + if (gp.IsAllowed(item.ItemTag)) + { + grid = gp.GetComponent(); + if (grid != null) + { + //Debug.Log($"TagSlotGridPairing: {grid.gameObject.name}"); + if (grid.slots != null && grid.slots.Length > 0 && grid.slots[0] != null) + gridCheck = grid.CanMoveInCells(item, grid.slots[0]) && !grid.ContainsItemFromGrid(item);// && grid.associatedItemUI.ContainedItems != null && !grid.associatedItemUI.ContainedItems.Contains(item); + // TODO: improve on this for stacking + + if (gridCheck) + { + break; + } + } + } + } + } + + //Debug.Log("IS:CanStore" + (slotCheck && gridCheck)); return slotCheck && gridCheck; } } diff --git a/Assets/Inventory System/Scripts/Inventory/TargetAttachment.cs b/Assets/Inventory System/Scripts/Inventory/TargetAttachment.cs index dc410bb5..7afd342e 100644 --- a/Assets/Inventory System/Scripts/Inventory/TargetAttachment.cs +++ b/Assets/Inventory System/Scripts/Inventory/TargetAttachment.cs @@ -50,7 +50,14 @@ namespace SimpleInventorySystem { if (hideGameObject) { - itemGameObject.SetActive(true); + if (itemGameObject == null) + { + Debug.LogError($"TargetAttachment: Item Game Object is null, please correctly set up your Item with a PickUp. Game Object name: {itemGameObject.name}"); + } + else + { + itemGameObject.SetActive(true); + } } itemGameObject = null; // TODO: Most likely, implement drop here. diff --git a/Assets/Inventory System/Scripts/UI/AttachTo.cs b/Assets/Inventory System/Scripts/UI/AttachTo.cs index 1397acc6..41c178b3 100644 --- a/Assets/Inventory System/Scripts/UI/AttachTo.cs +++ b/Assets/Inventory System/Scripts/UI/AttachTo.cs @@ -6,16 +6,5 @@ namespace SimpleInventorySystem { public class AttachTo : MonoBehaviour { - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } } } \ No newline at end of file diff --git a/Assets/Inventory System/Scripts/UI/GridUI.cs b/Assets/Inventory System/Scripts/UI/GridUI.cs index 6cf5623a..831612b2 100644 --- a/Assets/Inventory System/Scripts/UI/GridUI.cs +++ b/Assets/Inventory System/Scripts/UI/GridUI.cs @@ -28,6 +28,7 @@ namespace SimpleInventorySystem private Cell[,] cells; [HideInInspector] public GameObject testItem; [HideInInspector] public GameObject[] testItems; + [HideInInspector] public List itemsOnGrid; private Size cellSize; public Size CellSize { get { return cellSize; } } private Vector2 nextAvailableCellCoords; @@ -277,11 +278,32 @@ namespace SimpleInventorySystem } else { - Debug.LogWarning("GridUI: Could not add item to grid."); + //Debug.LogWarning("GridUI: Could not add item to grid."); return false; } } + public void AddItemToGrid(ItemUI item) + { + if (!itemsOnGrid.Contains(item)) + { + itemsOnGrid.Add(item.GetComponent()); + } + } + + public bool ContainsItemFromGrid(ItemUI item) + { + return itemsOnGrid.Contains(item); + } + + public void RemoveItemFromGrid(ItemUI item) + { + if (itemsOnGrid.Contains(item)) + { + itemsOnGrid.Remove(item.GetComponent()); + } + } + // Start is called before the first frame update void Start() { diff --git a/Assets/Inventory System/Scripts/UI/ItemUI.cs b/Assets/Inventory System/Scripts/UI/ItemUI.cs index e17ac028..08b19d8b 100644 --- a/Assets/Inventory System/Scripts/UI/ItemUI.cs +++ b/Assets/Inventory System/Scripts/UI/ItemUI.cs @@ -228,38 +228,68 @@ namespace SimpleInventorySystem //rectTransform.localPosition = new Vector3(0, 0); } + public bool QuickMove() + { + bool moved = false; + if (Equip()) + { + //Debug.Log("Equipped"); + moved = true; + } + else if (Store()) + { + //Debug.Log("Stored"); + moved = true; + } + return moved; + } + public bool Equip() { + bool equipped = false; foreach (TagSlotPairing tsp in InventorySystem.instance.TagSlotPairings) { + //Debug.Log($"Equip: {tsp.itemTag}, {tsp.slot.gameObject.name}"); + if (tsp.slot == slot) + { + //Debug.Log("Could not equip, storing"); + continue; + } + if (tsp.CanEquip(this)) { UnsetSlot(); + + equipped = tsp.DropOntoSlot(this); + //Debug.Log(tsp.slot.gameObject.name); - bool value = tsp.DropOntoSlot(this); - if (!value) + if (equipped) { - ReturnToSlot(); + break; } else { - return true; + //Debug.Log("Returning to slot"); + ReturnToSlot(); } } } - return false; + return equipped; } public bool Store() { - foreach (TagSlotGridPairing tsgp in InventorySystem.instance.TagSlotGridPairings) + bool stored = false; + foreach (TagSlotGridPairing tsgp in InventorySystem.instance.TagSlotGridPairings) { + //Debug.Log($"Store: {tsgp.itemTag}, {tsgp.ReferencedGrid}"); if (tsgp.CanStore(this)) { - UnsetSlot(); - bool value = tsgp.DropOntoGrid(this); - if (!value) + GrabAndDragItem(); // TODO: See if this conflicts with anything + //UnsetSlot(); + stored = tsgp.Drop(this); + if (!stored) { ReturnToSlot(); } @@ -268,12 +298,12 @@ namespace SimpleInventorySystem // TODO: see if this is needed if(container != null) container.SetActive(false); - return true; + break; } } } - return false; + return stored; } public bool DropItemInStorageContainer(ItemUI droppedItem) @@ -352,45 +382,56 @@ namespace SimpleInventorySystem //Debug.Log("OnPointerDown"); //Debug.Log("OnBeginDrag"); - canvasGroup.alpha = .7f; - canvasGroup.blocksRaycasts = false; - transform.SetParent(canvas.transform); - - rectTransform.anchorMin = new Vector2(0, 1); - rectTransform.anchorMax = new Vector2(0, 1); - rectTransform.pivot = new Vector2(0, 1); - - image.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, oldImageSizeDelta.x); - image.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, oldImageSizeDelta.y); - rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, oldSizeDelta.x); - rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, oldSizeDelta.y); - emptyGridContainer.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, oldSizeDelta.x); - emptyGridContainer.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, oldSizeDelta.y); - backdropImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, oldSizeDelta.x); - backdropImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, oldSizeDelta.y); - - UnsetSlot(); - - HideEmptyGrid(); + RemoveItemFromSlot(); isDragging = true; InventorySystem.instance.DraggedItem = this; PickedUpOnFrame = true; - - // Destroy each associated window, since we won't rely on windows if we are moving this item - for(int i = ContextWindows.Count - 1; i >= 0; i--) - { - ContextWindows[i].SetActive(true); - } - ContextWindows.Clear(); } } + public void RemoveItemFromSlot() + { + canvasGroup.alpha = .7f; + canvasGroup.blocksRaycasts = false; + + transform.SetParent(canvas.transform); + + rectTransform.anchorMin = new Vector2(0, 1); + rectTransform.anchorMax = new Vector2(0, 1); + rectTransform.pivot = new Vector2(0, 1); + + image.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, oldImageSizeDelta.x); + image.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, oldImageSizeDelta.y); + rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, oldSizeDelta.x); + rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, oldSizeDelta.y); + emptyGridContainer.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, oldSizeDelta.x); + emptyGridContainer.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, oldSizeDelta.y); + backdropImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, oldSizeDelta.x); + backdropImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, oldSizeDelta.y); + + UnsetSlot(); + + HideEmptyGrid(); + + // Destroy each associated window, since we won't rely on windows if we are moving this item + for (int i = ContextWindows.Count - 1; i >= 0; i--) + { + ContextWindows[i].SetActive(true); + } + ContextWindows.Clear(); + } + public void UnsetSlot() { if (slot != null) { + if(slot.grid != null) + { + slot.grid.RemoveItemFromGrid(this); + } + previousSlot = slot; slot.RemoveDragDropItem(); slot = null; @@ -649,7 +690,7 @@ namespace SimpleInventorySystem if (PointerIsHoveredOver && InventorySystem.instance.PressedEquipItemKey(false)) { - Equip(); + QuickMove(); // TODO: see if more needs to be implemented here. return; } diff --git a/Assets/Inventory System/Scripts/UI/SlotUI.cs b/Assets/Inventory System/Scripts/UI/SlotUI.cs index 98d54440..ada72ca9 100644 --- a/Assets/Inventory System/Scripts/UI/SlotUI.cs +++ b/Assets/Inventory System/Scripts/UI/SlotUI.cs @@ -32,7 +32,7 @@ namespace SimpleInventorySystem [HideInInspector] public LimitStackSlot limitStackSlot; [HideInInspector] public LimitStackSlotManager limitStackSlotManager; [HideInInspector] public bool DroppedOnFrame; - [HideInInspector] public List groupSlots; + public List groupSlots; [HideInInspector] public GridUI grid; [HideInInspector] public GridUI.Cell cell; [HideInInspector] public ChangeSlotTitle changeSlotTitle; @@ -78,7 +78,7 @@ namespace SimpleInventorySystem ItemTags itemTag = itemDrop.ItemTag; bool allowed = AllowedItemTags == null || AllowedItemTags.Count == 0 || AllowedItemTags.Contains(ItemTags.Any) || AllowedItemTags.Contains(itemTag); - bool disallowed = DisallowedItemTags.Contains(itemTag); + bool disallowed = DisallowedItemTags == null || DisallowedItemTags.Contains(itemTag); if (!allowed || disallowed) { @@ -149,7 +149,7 @@ namespace SimpleInventorySystem // Debug.Log(grid); bool dropCheck = (grid != null && grid.CanMoveInCells(itemDrop, this, occupiedCells)) || - (grid == null && !cell.inUse && (IgnoreItemSize || (cell.slot.width >= itemDrop.SizeAfterOrientation().Width && !cell.inUse && cell.slot.height >= itemDrop.SizeAfterOrientation().Height))); + (grid == null && cell != null && !cell.inUse && (IgnoreItemSize || (cell.slot.width >= itemDrop.SizeAfterOrientation().Width && !cell.inUse && cell.slot.height >= itemDrop.SizeAfterOrientation().Height))); // Debug.Log("Drop Check: " + dropCheck); @@ -172,9 +172,11 @@ namespace SimpleInventorySystem CellInUse = cell.inUse; } + Debug.Log($"Using Image as Slot Holder: {useImageAsSlotHolder}"); Transform parent = transform; if (useImageAsSlotHolder && image != null) { + //Debug.Log("Using Image as Slot Holder"); parent = image.gameObject.transform; } item.GetComponent().SetParent(parent); @@ -200,6 +202,8 @@ namespace SimpleInventorySystem if (grid != null) { grid.HideSlotsOfItem(itemDrop); + //Debug.Log("Grid is not null"); + grid.AddItemToGrid(item.GetComponent()); } if (!useImageAsSlotHolder) @@ -272,7 +276,7 @@ namespace SimpleInventorySystem else { //Debug.LogWarning("SlotUI: Failed to drop. dropCheck: " + dropCheck + ", allowed: " + allowed); - Debug.LogError("SlotUI: Something wrong has happened."); + //Debug.LogError("SlotUI: Something wrong has happened."); return false; } } @@ -323,10 +327,19 @@ namespace SimpleInventorySystem limitStackSlot.Increment(); } + //DropOntoSlot(item.gameObject); + stackedItems.Push(item); - item.transform.SetParent(transform, false); + if(useImageAsSlotHolder && image != null) + { + item.transform.SetParent(image.transform, false); + } + else + { + item.transform.SetParent(transform, false); + } item.gameObject.SetActive(true); - /* + /* foreach(ItemUI item in ) { itemUI.transform.SetParent(itemUI.ParentContainer.transform, false); @@ -426,7 +439,7 @@ namespace SimpleInventorySystem public bool CanDropOntoSlot() { - bool groupSlotsCheck = false; + /*bool groupSlotsCheck = false; if (groupSlots.Count == 0) groupSlotsCheck = true; else @@ -439,10 +452,10 @@ namespace SimpleInventorySystem break; } } - } + }*/ // TODO: add check for Limit Slot Stack here - return (GetItemUI() == null || IsStacking()) && groupSlotsCheck; + return (GetItemUI() == null || IsStacking());// && groupSlotsCheck; } public bool IsSingleCellSlot() diff --git a/Assets/Inventory System/Scripts/UI/TagSlotGridPairUI.cs b/Assets/Inventory System/Scripts/UI/TagSlotGridPairUI.cs new file mode 100644 index 00000000..0c221e18 --- /dev/null +++ b/Assets/Inventory System/Scripts/UI/TagSlotGridPairUI.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace SimpleInventorySystem +{ + public class TagSlotGridPairUI : MonoBehaviour + { + public List AllowedItemTags; + public List DisallowedItemTags; + + public bool IsAllowed(ItemTags itemTag) + { + bool allowed = AllowedItemTags == null || AllowedItemTags.Count == 0 || AllowedItemTags.Contains(ItemTags.Any) || AllowedItemTags.Contains(itemTag); + bool disallowed = DisallowedItemTags == null || DisallowedItemTags.Contains(itemTag); + + return allowed && !disallowed; + } + } +} \ No newline at end of file diff --git a/Assets/Inventory System/Scripts/UI/TagSlotGridPairUI.cs.meta b/Assets/Inventory System/Scripts/UI/TagSlotGridPairUI.cs.meta new file mode 100644 index 00000000..2fc88621 --- /dev/null +++ b/Assets/Inventory System/Scripts/UI/TagSlotGridPairUI.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1ed269bdb4294dc429d767fed43a92aa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Test Scene Tony.unity b/Assets/Scenes/Test Scene Tony.unity index 2a7a5ce3..73cb7c09 100644 --- a/Assets/Scenes/Test Scene Tony.unity +++ b/Assets/Scenes/Test Scene Tony.unity @@ -49547,6 +49547,8 @@ MonoBehaviour: - {fileID: 1241596305986958, guid: 7f0652b80b458c74b9383ea6a02ea96e, type: 3} - {fileID: 8053794548077495502, guid: 3e5ad4148935cf44f8f502719c58ac30, type: 3} - {fileID: 1360962833793172, guid: e3c3fc737aaecec47998dbddc1dc85f6, type: 3} + - {fileID: 1241596305986958, guid: 5ddf4d2d41dcd3c46893e4b8cd1fc142, type: 3} + - {fileID: 1360962833793172, guid: e3c3fc737aaecec47998dbddc1dc85f6, type: 3} itemUIs: [] --- !u!4 &1937331975 stripped Transform: