From 774930c876d3a714ad6ebcc86021b4af7eccb27a Mon Sep 17 00:00:00 2001 From: kabix09 Date: Mon, 20 Jun 2022 18:23:22 +0200 Subject: [PATCH] Extends warehouse api --- Assembly-CSharp.csproj | 2 + Assets/Items/Axe.asset | 2 +- Assets/Scripts/NPCs' Scripts/NPCQuest.cs | 2 +- Assets/Scripts/UI/BaseWarehouseController.cs | 6 +++ Documentation/Warehouse.md | 43 ++++++++++++++++++++ UserSettings/EditorUserSettings.asset | 4 +- 6 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 Documentation/Warehouse.md diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index d0272706..7e8935d7 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -64,6 +64,7 @@ + @@ -101,6 +102,7 @@ + diff --git a/Assets/Items/Axe.asset b/Assets/Items/Axe.asset index 7db53a61..ae0271d2 100644 --- a/Assets/Items/Axe.asset +++ b/Assets/Items/Axe.asset @@ -13,7 +13,7 @@ MonoBehaviour: m_Name: Axe m_EditorClassIdentifier: id: 0 - name: Axe_one + name: lumberjack axe description: Lumberjack's Axe level: 1 image: {fileID: 21300000, guid: d7a7292796eda0941a6a863b7d66bbcb, type: 3} diff --git a/Assets/Scripts/NPCs' Scripts/NPCQuest.cs b/Assets/Scripts/NPCs' Scripts/NPCQuest.cs index 75c29d96..ef1022c9 100644 --- a/Assets/Scripts/NPCs' Scripts/NPCQuest.cs +++ b/Assets/Scripts/NPCs' Scripts/NPCQuest.cs @@ -47,7 +47,7 @@ public class NPCQuest : MonoBehaviour // 1. Drop item on map GameObject _axe = Instantiate(axe, new Vector3(37.1f, -31.7f, 0), Quaternion.identity, globalGUI.transform); // 1.2 Fix names (prevent add "(Clone)" postfix) - _axe.name = axe.name; + _axe.name = axe.GetComponent().item.Name; _axe.GetComponent().item.name = axe.name; // 2. Add object to DynamicList in LocalSceneManager diff --git a/Assets/Scripts/UI/BaseWarehouseController.cs b/Assets/Scripts/UI/BaseWarehouseController.cs index 1f26c8ac..0fdc6378 100644 --- a/Assets/Scripts/UI/BaseWarehouseController.cs +++ b/Assets/Scripts/UI/BaseWarehouseController.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using System.Linq; // T will be type panel: inventory, equipment, chest abstract public class BaseWarehouseController : MonoBehaviour @@ -40,6 +41,11 @@ abstract public class BaseWarehouseController : MonoBehaviour isOpen = false; } + public KeyValuePair FindItemInWarehouse(string itemName) + { + return this._items.Where(item => item.Value.name == itemName).FirstOrDefault(); + } + protected abstract void SetupPanel(); public virtual void SetItemOnPosition(int _keyPosition, Item _item) diff --git a/Documentation/Warehouse.md b/Documentation/Warehouse.md new file mode 100644 index 00000000..185342fb --- /dev/null +++ b/Documentation/Warehouse.md @@ -0,0 +1,43 @@ +# Warehouse +It's the core mechanism on which the entire set of panels available in the game is working. + +On the basis of it work modules such as: +* Inventory +* Equippment +* Chest system + +## API + +### Open Panel +```c# +BaseWarehouseController.Instance.OpenPanel(); +``` + +### Close Panel +```c# +BaseWarehouseController.Instance.OpenPanel(); +``` + +### Find Item +Check if class extending base warehouse structure has the item you are looking for +```c# +var questItem = InventoryManager.Instance.FindItemInWarehouse("lumberjack axe"); + +if(!questItem.Equals(new KeyValuePair())) +{ + // TODO code if item has been found +} else { + // TODO code if item was not found +} +``` + +### Remove Item +To delete the item, pass its position in the warehouse. You can use result of function above `questItem.Key` +```c# +BaseWarehouseController.Instance.RemoveItemFromPosition(int itemPosition); +``` + +Insteda of `BaseWarehouseController` you can use one of: +* `InventoryManager` +* `EquipmentManager` +* `ChestController` diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index 54041df8..2965118b 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -30,10 +30,10 @@ EditorUserSettings: value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb flags: 0 RecentlyUsedScenePath-8: - value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021 + value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d flags: 0 RecentlyUsedScenePath-9: - value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d + value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021 flags: 0 vcSharedLogLevel: value: 0d5e400f0650