diff --git a/Assets/Items/Axe.asset b/Assets/Items/Axe.asset index 7db53a61..0282d003 100644 --- a/Assets/Items/Axe.asset +++ b/Assets/Items/Axe.asset @@ -9,18 +9,18 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 943bb4b7c1123c44fb1cbc048a56a954, type: 3} + m_Script: {fileID: 11500000, guid: a0c176e87b3c91641897c23dc27e92a0, type: 3} m_Name: Axe m_EditorClassIdentifier: - id: 0 - name: Axe_one - description: Lumberjack's Axe + id: 2 + name: Axe + description: Lumberjack axe level: 1 image: {fileID: 21300000, guid: d7a7292796eda0941a6a863b7d66bbcb, type: 3} itemModel: {fileID: 1826809974269949497, guid: 83fa1f81238efb541bd77405dcf33dd1, type: 3} - StrengthBonus: 0 + StrengthBonus: 1 AgilityBonus: 0 - InteligenceBonus: 0 + InteligenceBonus: 5 VitalityBonus: 0 isStackable: 0 EquipmentType: 4 diff --git a/Assets/Items/Gold Ore.asset b/Assets/Items/Gold Ore.asset index 7b5b3312..a2eececd 100644 --- a/Assets/Items/Gold Ore.asset +++ b/Assets/Items/Gold Ore.asset @@ -9,18 +9,12 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 943bb4b7c1123c44fb1cbc048a56a954, type: 3} + m_Script: {fileID: 11500000, guid: 1c6df47a2440e8a49bef89083164fdc1, type: 3} m_Name: Gold Ore m_EditorClassIdentifier: - id: 0 + id: 1 name: Gold Ore description: - level: 0 + level: 1 image: {fileID: 21300000, guid: 83bbd515e788cbd4090c1c6649b76a29, type: 3} itemModel: {fileID: 6960265943931164901, guid: 7aaf1038c5485164ea90044b40c5baa1, type: 3} - StrengthBonus: 0 - AgilityBonus: 0 - InteligenceBonus: 0 - VitalityBonus: 0 - isStackable: 0 - EquipmentType: 9 diff --git a/Assets/Items/Pickaxe.asset b/Assets/Items/Pickaxe.asset index 32c7ca2d..8a3f9d86 100644 --- a/Assets/Items/Pickaxe.asset +++ b/Assets/Items/Pickaxe.asset @@ -9,12 +9,12 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 943bb4b7c1123c44fb1cbc048a56a954, type: 3} + m_Script: {fileID: 11500000, guid: a0c176e87b3c91641897c23dc27e92a0, type: 3} m_Name: Pickaxe m_EditorClassIdentifier: id: 0 - name: pickaxe_test - description: Example pickaxe + name: Pickaxe + description: level: 1 image: {fileID: 8959118705387878318, guid: 25e473b59d2d7534e803be0a2825e0f7, type: 3} itemModel: {fileID: 9081071845930167562, guid: 0bccd32818043074d9785f6d90ebdcb3, type: 3} @@ -23,4 +23,4 @@ MonoBehaviour: InteligenceBonus: 0 VitalityBonus: 0 isStackable: 0 - EquipmentType: 0 + EquipmentType: 4 diff --git a/Assets/Prefarbs/Inventory UI/DraggableItem.prefab b/Assets/Resources/UiPanels/DraggableItem.prefab similarity index 100% rename from Assets/Prefarbs/Inventory UI/DraggableItem.prefab rename to Assets/Resources/UiPanels/DraggableItem.prefab diff --git a/Assets/Prefarbs/Inventory UI/DraggableItem.prefab.meta b/Assets/Resources/UiPanels/DraggableItem.prefab.meta similarity index 100% rename from Assets/Prefarbs/Inventory UI/DraggableItem.prefab.meta rename to Assets/Resources/UiPanels/DraggableItem.prefab.meta diff --git a/Assets/Prefarbs/Inventory UI/inventory_slot.prefab b/Assets/Resources/UiPanels/InventoryBox.prefab similarity index 99% rename from Assets/Prefarbs/Inventory UI/inventory_slot.prefab rename to Assets/Resources/UiPanels/InventoryBox.prefab index 84ce3da7..f40d340a 100644 --- a/Assets/Prefarbs/Inventory UI/inventory_slot.prefab +++ b/Assets/Resources/UiPanels/InventoryBox.prefab @@ -225,7 +225,7 @@ GameObject: - component: {fileID: 7550267750876868091} - component: {fileID: 6531490600091353741} m_Layer: 5 - m_Name: inventory_slot + m_Name: InventoryBox m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/Assets/Prefarbs/Inventory UI/inventory_slot.prefab.meta b/Assets/Resources/UiPanels/InventoryBox.prefab.meta similarity index 100% rename from Assets/Prefarbs/Inventory UI/inventory_slot.prefab.meta rename to Assets/Resources/UiPanels/InventoryBox.prefab.meta diff --git a/Assets/Prefarbs/Inventory UI/inventory_panel.prefab b/Assets/Resources/UiPanels/InventoryPanel.prefab similarity index 79% rename from Assets/Prefarbs/Inventory UI/inventory_panel.prefab rename to Assets/Resources/UiPanels/InventoryPanel.prefab index 3fdcdabb..690a3219 100644 --- a/Assets/Prefarbs/Inventory UI/inventory_panel.prefab +++ b/Assets/Resources/UiPanels/InventoryPanel.prefab @@ -28,6 +28,7 @@ RectTransform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 9124304228607424520} m_RootOrder: 0 @@ -134,126 +135,6 @@ MonoBehaviour: m_hasFontAssetChanged: 0 m_baseMaterial: {fileID: 0} m_maskOffset: {x: 0, y: 0, z: 0, w: 0} ---- !u!1 &9124304227312933332 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 9124304227312933335} - - component: {fileID: 9124304227312933320} - - component: {fileID: 9124304227312933321} - - component: {fileID: 9124304227312933334} - m_Layer: 5 - m_Name: Button - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &9124304227312933335 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 9124304227312933332} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 9124304227729624650} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 232.6, y: 404.2} - m_SizeDelta: {x: 50, y: 50} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!222 &9124304227312933320 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 9124304227312933332} - m_CullTransparentMesh: 1 ---- !u!114 &9124304227312933321 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 9124304227312933332} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 - m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_Sprite: {fileID: 21300000, guid: 11277a3f23988ec47908362d708edaa8, type: 3} - m_Type: 0 - m_PreserveAspect: 0 - m_FillCenter: 1 - m_FillMethod: 4 - m_FillAmount: 1 - m_FillClockwise: 1 - m_FillOrigin: 0 - m_UseSpriteMesh: 0 - m_PixelsPerUnitMultiplier: 1 ---- !u!114 &9124304227312933334 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 9124304227312933332} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Navigation: - m_Mode: 3 - m_WrapAround: 0 - m_SelectOnUp: {fileID: 0} - m_SelectOnDown: {fileID: 0} - m_SelectOnLeft: {fileID: 0} - m_SelectOnRight: {fileID: 0} - m_Transition: 1 - m_Colors: - m_NormalColor: {r: 1, g: 1, b: 1, a: 1} - m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} - m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} - m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} - m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} - m_ColorMultiplier: 1 - m_FadeDuration: 0.1 - m_SpriteState: - m_HighlightedSprite: {fileID: 0} - m_PressedSprite: {fileID: 0} - m_SelectedSprite: {fileID: 0} - m_DisabledSprite: {fileID: 0} - m_AnimationTriggers: - m_NormalTrigger: Normal - m_HighlightedTrigger: Highlighted - m_PressedTrigger: Pressed - m_SelectedTrigger: Selected - m_DisabledTrigger: Disabled - m_Interactable: 1 - m_TargetGraphic: {fileID: 9124304227312933321} - m_OnClick: - m_PersistentCalls: - m_Calls: [] --- !u!1 &9124304227602340161 GameObject: m_ObjectHideFlags: 0 @@ -283,6 +164,7 @@ RectTransform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 9124304227903849263} m_Father: {fileID: 9124304227744546881} @@ -355,9 +237,9 @@ GameObject: - component: {fileID: 9124304227729624650} - component: {fileID: 9124304227729624652} - component: {fileID: 9124304227729624653} - - component: {fileID: 4753590907807807515} + - component: {fileID: 7107743575243314760} m_Layer: 5 - m_Name: inventory_panel + m_Name: InventoryPanel m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -373,10 +255,10 @@ RectTransform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.4, y: 0.4, z: 1} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 9124304228607424520} - {fileID: 9124304227744546881} - - {fileID: 9124304227312933335} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -423,7 +305,7 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 m_PixelsPerUnitMultiplier: 1 ---- !u!114 &4753590907807807515 +--- !u!114 &7107743575243314760 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -432,16 +314,12 @@ MonoBehaviour: m_GameObject: {fileID: 9124304227729624651} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: d0bff20d6fb721a449df16891030739a, type: 3} + m_Script: {fileID: 11500000, guid: b3ae9277a19e5dc49aa607d1d2ec2dc9, type: 3} m_Name: m_EditorClassIdentifier: - _panel: {fileID: 9124304227903849260} - _blankSlot: {fileID: 4202482119828722599, guid: 843626bb28e804c4384ea070e0fead67, type: 3} - _panelCloseButton: {fileID: 9124304227312933334} - _instance: {fileID: 0} - _itemTemplate: {fileID: 6570396142606985298, guid: 1304511dd1dfefc449e87c3d904ab15f, type: 3} - _tmp: {fileID: 0} - MAX_SLOT_CUNT: 48 + _panelContent: {fileID: 9124304227903849260} + ChildBoxTemplate: {fileID: 4202482119828722599, guid: 843626bb28e804c4384ea070e0fead67, type: 3} + ChildBoxList: [] --- !u!1 &9124304227744546894 GameObject: m_ObjectHideFlags: 0 @@ -471,6 +349,7 @@ RectTransform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 9124304227602340160} m_Father: {fileID: 9124304227729624650} @@ -577,6 +456,7 @@ RectTransform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 9124304227602340160} m_RootOrder: 0 @@ -652,6 +532,7 @@ RectTransform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 9124304227092242855} m_Father: {fileID: 9124304227729624650} diff --git a/Assets/Prefarbs/Inventory UI/inventory_panel.prefab.meta b/Assets/Resources/UiPanels/InventoryPanel.prefab.meta similarity index 100% rename from Assets/Prefarbs/Inventory UI/inventory_panel.prefab.meta rename to Assets/Resources/UiPanels/InventoryPanel.prefab.meta diff --git a/Assets/Resources/UiPanels/TaskPanel.prefab b/Assets/Resources/UiPanels/TaskPanel.prefab index 96b120dd..ad0a4d6f 100644 --- a/Assets/Resources/UiPanels/TaskPanel.prefab +++ b/Assets/Resources/UiPanels/TaskPanel.prefab @@ -119,7 +119,7 @@ GameObject: - component: {fileID: 4136979550784496705} - component: {fileID: 4136979550784496711} - component: {fileID: 4136979550784496710} - - component: {fileID: 23121313890645495} + - component: {fileID: 169130841095946002} m_Layer: 5 m_Name: TaskPanel m_TagString: Untagged @@ -187,7 +187,7 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 m_PixelsPerUnitMultiplier: 1 ---- !u!114 &23121313890645495 +--- !u!114 &169130841095946002 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -200,8 +200,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: _panelContent: {fileID: 4136979552221407527} - TaskBoxTemplate: {fileID: 3337243677719157076, guid: 1cd878accdd121744a3a4829d9bc910f, type: 3} - TaskBoxList: [] + ChildBoxTemplate: {fileID: 3337243677719157076, guid: 1cd878accdd121744a3a4829d9bc910f, type: 3} + ChildBoxList: [] --- !u!1 &4136979550912312138 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Equipment/EquipmentManager.cs b/Assets/Scripts/Equipment/EquipmentManager.cs index 10063d5b..c89e2cfa 100644 --- a/Assets/Scripts/Equipment/EquipmentManager.cs +++ b/Assets/Scripts/Equipment/EquipmentManager.cs @@ -94,42 +94,42 @@ public class EquipmentManager : BaseWarehouseController switch(_item.EquipmentType) { - case EquipmentType.Helmet: + case EquipmentTypeEnum.Helmet: { key = 0; break; } - case EquipmentType.Chest: + case EquipmentTypeEnum.Chest: { key = 1; break; } - case EquipmentType.Boots: + case EquipmentTypeEnum.Boots: { key = 2; break; } - case EquipmentType.Weapon: + case EquipmentTypeEnum.Weapon: { key = 3; break; } - case EquipmentType.Potion: + case EquipmentTypeEnum.Potion: { key = 4; break; } - case EquipmentType.Bracelet: + case EquipmentTypeEnum.Bracelet: { key = 5; break; } - case EquipmentType.Necklet: + case EquipmentTypeEnum.Necklet: { key = 6; break; } - case EquipmentType.Ring: + case EquipmentTypeEnum.Ring: { if(!equipment.ContainsKey(7) || equipment[7] == null) { @@ -159,42 +159,42 @@ public class EquipmentManager : BaseWarehouseController { switch(_item.EquipmentType) { - case EquipmentType.Helmet: + case EquipmentTypeEnum.Helmet: { _helmet = put ? _item : null; break; } - case EquipmentType.Chest: + case EquipmentTypeEnum.Chest: { _chest = put ? _item : null; break; } - case EquipmentType.Boots: + case EquipmentTypeEnum.Boots: { _boots = put ? _item : null; break; } - case EquipmentType.Weapon: + case EquipmentTypeEnum.Weapon: { _weapon = put ? _item : null; break; } - case EquipmentType.Potion: + case EquipmentTypeEnum.Potion: { _potion_one = put ? _item : null; break; } - case EquipmentType.Bracelet: + case EquipmentTypeEnum.Bracelet: { _potion_two = put ? _item : null; break; } - case EquipmentType.Necklet: + case EquipmentTypeEnum.Necklet: { _potion_three = put ? _item : null; break; } - case EquipmentType.Ring: + case EquipmentTypeEnum.Ring: { if(!equipment.ContainsKey(7) || equipment[7] == null) { diff --git a/Assets/Scripts/Equipment/EquipmentSlot.cs b/Assets/Scripts/Equipment/EquipmentSlot.cs index 978697f5..55acb73f 100644 --- a/Assets/Scripts/Equipment/EquipmentSlot.cs +++ b/Assets/Scripts/Equipment/EquipmentSlot.cs @@ -4,7 +4,7 @@ using UnityEngine; public class EquipmentSlot : ItemSlot { - public EquipmentType EquipmentType; + public EquipmentTypeEnum EquipmentType; public override bool CanReceiveItem(Item item) { diff --git a/Assets/Scripts/Inventory/InventoryManager.cs b/Assets/Scripts/Inventory/InventoryManager.cs deleted file mode 100644 index 3326f420..00000000 --- a/Assets/Scripts/Inventory/InventoryManager.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -[System.Serializable] -public class InventoryManager : BaseWarehouseController -{ - public static int MAX_ITEMS = 5; - - public static InventoryManager Instance; - - // temporary delegate dragged item to outside static object instance to remember it - [Space] - [SerializeField] - protected ISlot _draggedSlot; - public ISlot DraggedSlot - { - get { return _draggedSlot; } - set - { - _draggedSlot = value; - } - } - - private void Awake() - { - if(Instance == null) - { - Instance = this; - }else if (Instance != this) - { - Destroy(gameObject); - } - } - - public int AddToInventory(EquippableItem pickable) - { - if(this._items.Count <= MAX_ITEMS) - { - for(int slotNumber=0; slotNumber - /// Function for placed item in inventory on SPECYFIC position - /// Used by SceneInventoryManager for load saved items on their positions - /// - public void SetupItemInInventory(int key, EquippableItem pickable) - { - this._items[key] = pickable; - } - - protected override void SetupPanel() - { - if(this.dynamicPanel) - { - this.dynamicPanel.GetComponent().Setup(gameObject, _items); - } - } - - - // public void DropItem() - // { - - // } -} diff --git a/Assets/Scripts/Inventory/InventoryPanelController.cs b/Assets/Scripts/Inventory/InventoryPanelController.cs deleted file mode 100644 index 76f0f153..00000000 --- a/Assets/Scripts/Inventory/InventoryPanelController.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; -using UnityEngine.EventSystems; -using System; - -public class InventoryPanelController : BasePanelController -{ - - public override void CloseOnClick() - { - Destroy(gameObject); // destroy panel - - InventoryManager.Instance.GetComponent().ClosePanel(); - } - - public void Setup(GameObject _inventory, Dictionary _items) - { - _instance = _inventory; - - base.Setup(_items); - } - - protected override ISlot SetupSlot(int key, GameObject _parent) - { - InventorySlot _tmpSlot = Instantiate(_blankSlot, _parent.transform.position, Quaternion.identity).GetComponent(); - _tmpSlot.transform.SetParent(_parent.transform); - - _tmpSlot.SetupSlot(key, null, this); - - return _tmpSlot; - } - - // public void Drop(ItemSlot dropItemSlot) - // { - // if(dropItemSlot.CanReceiveItem(draggedSlot.Item) && draggedSlot.CanReceiveItem(dropItemSlot.Item)) - // { - // EquippableItem dragItem = draggedSlot.Item as EquippableItem; - // EquippableItem dropItem = dropItemSlot.Item as EquippableItem; - - // // for changing chest to evuuipment or onventory panel !!!! - - // if(draggedSlot is EquipmentSlot) - // { - // if(dragItem != null) dragItem.Unequip(this); - // if(dropItem != null) dropItem.Equip(this); - // } - - // if(dropItemSlot is EquipmentSlot) - // { - // if(dragItem != null) dragItem.Equip(this); - // if(dropItem != null) dropItem.Unequip(this); - // } - - // Item draggedItem = draggedSlot.Item; // remember temporary currently dragged item - - // draggedSlot.Item = dropItemSlot.Item; - // dropItemSlot.Item = draggedItem; - - // // update items position in chest slots - // // - after close paned - items dont reset its positions - // _inventory.GetComponent().SetItemOnPosition(draggedSlot.Number, draggedSlot.Item); - // _inventory.GetComponent().SetItemOnPosition(dropItemSlot.Number, dropItemSlot.Item); - // } - // } - -} diff --git a/Assets/Scripts/Item/PickableController.cs b/Assets/Scripts/Item/PickableController.cs index afc99bd4..da379454 100644 --- a/Assets/Scripts/Item/PickableController.cs +++ b/Assets/Scripts/Item/PickableController.cs @@ -39,8 +39,9 @@ public class PickableController : MonoBehaviour { if (Input.GetKeyDown(KeyCode.E)) { - if(InventoryManager.Instance.AddToInventory(this.item) >= 0) + if(InventoryUIManager.Instance.IsFull()) { + InventoryUIManager.Instance.Add(this.item); isPicked = 1; //PlayerPrefs.SetInt(name, isPicked); //gameObject.SetActive(false); @@ -52,12 +53,11 @@ public class PickableController : MonoBehaviour { Debug.LogError("Can't pick item - Your inventory is full"); } - } } } - private void OnTriggerEnter2D(Collider2D collision) + private void OnTrigerEnter2D(Collider2D collision) { if (collision.tag == "Player") { diff --git a/Assets/Scripts/REFACTORING/Application.meta b/Assets/Scripts/REFACTORING/Application.meta new file mode 100644 index 00000000..67e78205 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f7b6c099a5334c44b977899871b4a61a +timeCreated: 1660483312 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Panel.meta b/Assets/Scripts/REFACTORING/Application/Panel.meta new file mode 100644 index 00000000..e8f8afb3 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 925cd94b992c46259a205c12a9a3b969 +timeCreated: 1660171743 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Chest.meta b/Assets/Scripts/REFACTORING/Application/Panel/Chest.meta new file mode 100644 index 00000000..9e36e78e --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Chest.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 546db8cdadd345c6a364ed0e1a58c4b7 +timeCreated: 1660488534 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Chest/ChestDataListManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Chest/ChestDataListManager.cs new file mode 100644 index 00000000..831b245a --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Chest/ChestDataListManager.cs @@ -0,0 +1,23 @@ +using UnityEngine; + +public class ChestDataListManager : SceneDataListManager +{ + public ChestDataListManager(string gameObjectLocalization, string assetLocalization) : base(gameObjectLocalization, assetLocalization) + { + } + + public override void AddElementToList(ChestPrefarbAsset newElement) + { + throw new System.NotImplementedException(); + } + + public override void RemoveElementFromList(ChestPrefarbAsset element) + { + throw new System.NotImplementedException(); + } + + protected override void doBuild(GameObject _object) + { + throw new System.NotImplementedException(); + } +} diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Chest/ChestDataListManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Chest/ChestDataListManager.cs.meta new file mode 100644 index 00000000..eef5e2fb --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Chest/ChestDataListManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8b07ed99c7ae4d07bb7201c51459dce0 +timeCreated: 1660488551 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Inventory.meta b/Assets/Scripts/REFACTORING/Application/Panel/Inventory.meta new file mode 100644 index 00000000..531cc88b --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fe46dc8c381d43eb971d9e24236d16f0 +timeCreated: 1660405143 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/InventoryDataListManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/InventoryDataListManager.cs new file mode 100644 index 00000000..43006db4 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/InventoryDataListManager.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; + +public class InventoryDataListManager : DataListManager> // or maybe EquippableItem - but its get conflicts... +{ + public DataListManager> SetUiManager(ref UIWarehouseManager _uiManager) + { + uiManager = _uiManager; + + return this; + } + + public override void AddElementToList(KeyValuePair newElement) + { + Elements.Add(newElement); + } + + public override void RemoveElementFromList(KeyValuePair element) + { + throw new System.NotImplementedException(); + } + + // public override void Build() + // { + // // pass to InventoryManager singleton + // foreach(KeyValuePair itemEntry in Elements) + // InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.equippableItem); + // + // } +} diff --git a/Assets/Scripts/Inventory/InventoryManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/InventoryDataListManager.cs.meta similarity index 83% rename from Assets/Scripts/Inventory/InventoryManager.cs.meta rename to Assets/Scripts/REFACTORING/Application/Panel/Inventory/InventoryDataListManager.cs.meta index 1f57da92..7e3a750a 100644 --- a/Assets/Scripts/Inventory/InventoryManager.cs.meta +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/InventoryDataListManager.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7610fa3cdda79614e94110dd314fbfed +guid: 6c7ff03e3ec547d39ea36456237d74e5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SaveInventoryManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SaveInventoryManager.cs new file mode 100644 index 00000000..2c9df559 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SaveInventoryManager.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using UnityEngine; + +public class SaveInventoryManager : SaveModelSystem> +{ + public override bool SaveModelItem(KeyValuePair model) + { + return base.SaveModelItem(model); + } + + public override bool SaveModelList(List> list) + { + BinaryFormatter formatter = new BinaryFormatter(); + + Debug.Log("Saved Inventory at " + Path); + + if (!Directory.Exists(Path)) Directory.CreateDirectory(Path); + + /* Main logic of conversion data format */ + var data = ConvertObjectsListToListOfDataModels(list); + + FileStream stream = new FileStream( + Path + GetFileName(ObjectListName), + FileMode.Create + ); + + formatter.Serialize(stream, data); + stream.Close(); + + return true; + } + + public override KeyValuePair LoadModelItem() + { + return base.LoadModelItem(); + } + + public override List> LoadModelList() + { + string path = Path + GetFileName(ObjectListName); + + if (File.Exists(path)) + { + BinaryFormatter formatter = new BinaryFormatter(); + FileStream stream = new FileStream(path, FileMode.Open); + + List> questsList = formatter.Deserialize(stream) as List>; + stream.Close(); + + return ConvertListOfDataModelsToListOfObject(questsList); + } + else + { + Debug.Log("Save file not found in " + path); + } + + return new List>(); + } + + // Support function + + // 1. From model to data format + private KeyValuePair ConvertObjectToDataModel(KeyValuePair model) + { + return new KeyValuePair(model.Key, new EquippableItemPrefabAssetData(model.Value)); + } + + private List> ConvertObjectsListToListOfDataModels(List> modelsList) + { + List> convertedList = new List>(); + + foreach(KeyValuePair model in modelsList) + { + convertedList.Add(ConvertObjectToDataModel(model)); + } + + return convertedList; + } + + // 2. From data to model format + private KeyValuePair ConvertDataModelToObject(KeyValuePair dataModel) + { + return new KeyValuePair(dataModel.Key, (EquippableItemPrefabAsset)dataModel.Value.MapDataToPrefabAssetModel()); + } + + private List> ConvertListOfDataModelsToListOfObject(List> dataModelsList) + { + List> convertedList = new List>(); + + foreach (KeyValuePair dataModel in dataModelsList) + { + convertedList.Add(ConvertDataModelToObject(dataModel)); + } + + return convertedList; + } +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SaveInventoryManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SaveInventoryManager.cs.meta new file mode 100644 index 00000000..e3a25375 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SaveInventoryManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ae3fbd7c37d1aa140a398a84afd9adb4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataLoader.cs b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataLoader.cs new file mode 100644 index 00000000..d738712f --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataLoader.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +public class SceneInventoryDataLoader : SceneBaseDataLoader> +{ + public SceneInventoryDataLoader(string _objectListName, string _objectFolderName) + { + SaveModelSystem = new SaveInventoryManager(); + SaveModelSystem.ObjectFolderName = _objectFolderName; + SaveModelSystem.ObjectListName = _objectListName; + } + + /* + public void LoadInventoryItemsList() + { + string path = SaveSystem.GetSavePath(); + + if (!Directory.Exists(path)) // if not exists thats mean there was nothing saved yet - nothing to load + return; + + FileInfo[] fileInfo = new DirectoryInfo(path).GetFiles(); + + foreach(FileInfo file in fileInfo) + { + if(file.Name != this.ItemsListName + ".fun") + continue; + + Dictionary equippableItemsList = SaveInventorySystem.LoadInventoryItemsList(this.ItemsListName); + + // itemEntry.Value.MapDataToEquippableItem() - map data format to object + + // save object + foreach(KeyValuePair itemEntry in equippableItemsList) + { + InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.MapDataToEquippableItemPrefarbAsset().equippableItem); + } + } + } + + public void SaveInventoryItems() + { + // Case I - if we remember all list + // 1) if after removed item form DynamicList is empty - remove all file + // 2) if after removed item form DynamciList there are another one - save updated list again + if(InventoryManager.Instance._items.Count > 0) { + + // 1. Map From Dictionary' to 'Dictionary' + Dictionary mappedList = new Dictionary(); + + foreach(KeyValuePair itemElement in InventoryManager.Instance._items) + { + mappedList[itemElement.Key] = new EquippableItemPrefabAsset( + itemElement.Value.Name, + itemElement.Value.ItemModel.name, + new Vector3(0,0,0), + (EquippableItem) itemElement.Value + ); + } + + // 2. Save Items + SaveInventorySystem.SaveInventoryItemsList(mappedList, this.ItemsListName); + } else { + string _path = SaveSystem.GetSavePath() + "/" + this.ItemsListName + ".fun"; + + try + { + Debug.Log("File to remove: " + _path); + + if(File.Exists(_path)) + { + File.Delete(_path); + } + } + catch (IOException ioExp) + { + Debug.LogError(ioExp.Message); + } + } + + // Case II - if we rememenber object per file + // 1) remove specyfic file + // + // Unfortunatelly we don't use this way of saving items yet :D + } + */ + + + protected override List> LoadGenericData() + { + SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString(); + + return SaveModelSystem.LoadModelList(); + } + + protected override bool SaveGenericData(List> _elements) + { + SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString(); + + try + { + SaveModelSystem.SaveModelList(_elements); + + return true; + } + catch (Exception e) { Debug.LogError(e.Message); } + + return false; + } + + protected override List> LoadStaticData() { throw new System.NotImplementedException(); } + + protected override List> LoadDynamicData() { throw new System.NotImplementedException(); } + + protected override bool SaveStaticData(List> _elements) { throw new System.NotImplementedException(); } + + protected override bool SaveDynamicData(List> _elements) { throw new System.NotImplementedException(); } +} diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataLoader.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataLoader.cs.meta new file mode 100644 index 00000000..5f32d88b --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: baf283801c6e7974fa09be212719ea78 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataManager.cs new file mode 100644 index 00000000..31ccc153 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataManager.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +[Serializable] +public class SceneInventoryDataManager : SceneBaseDataManager> +{ + protected override string OBJECT_FOLDER_NAME { get { return "Inventory"; } } + protected override string OBJECT_LIST_NAME { get { return "InventoryList"; } } + + protected new SceneBaseDataLoader> DataLoader { get; set; } + + private void Start() + { + Debug.Log("Start SceneInventoryData manager"); + + //TaskUIManager.FindOrCreateInstance(); + var inventoryManager = InventoryUIManager.Instance; + + if (inventoryManager == null) + throw new NullReferenceException("InventoryUIManager not found!!!"); + + StaticDataList = (new InventoryDataListManager()).SetUiManager(ref inventoryManager); + // DynamicDataList = (new TaskDataListManager()).SetUiManager(ref taskManager); + + DataLoader = new SceneInventoryDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME); + + + //SaveData(StaticDataList.GetList(), SceneElementTypeEnum.None); + + LoadData(SceneElementTypeEnum.None, ref StaticDataList); + // LoadDynamicData(); + + inventoryManager.SetList(StaticDataList.GetList()); + + inventoryManager.OpenPanel(); + } + + #region override load & save + protected override bool LoadData(SceneElementTypeEnum type, ref DataListManager> dataListManager) + { + try + { + // 1. Convert EquippableItemPrefabAsset to EquippableItem list + List> convertedList = new List>(); + + foreach(KeyValuePair loadedEquippableItemPrefarbAssetElement in (List>)DataLoader.LoadData(SceneElementTypeEnum.None)) + { + convertedList.Add(new KeyValuePair(loadedEquippableItemPrefarbAssetElement.Key, (EquippableItem)loadedEquippableItemPrefarbAssetElement.Value.EquippableItem)); + } + + // 2. Pass loaded list to InventoryDataManager + dataListManager.SetList(convertedList); + + return true; + } + catch (Exception e) + { + Debug.LogWarning(e.Message); + } + + return false; + } + + protected override bool SaveData(List> _elements, SceneElementTypeEnum type) + { + try + { + // 1. Convert EquippableItem to EquippableItemPrefabAsset list + List> convertedList = new List>(); + + foreach (KeyValuePair itemElement in _elements) + { + convertedList.Add(new KeyValuePair( + itemElement.Key, + new EquippableItemPrefabAsset( + itemElement.Value.Name, + itemElement.Value.ItemModel.name, + new Vector3(0, 0, 0), + (EquippableItem)itemElement.Value + ) + )); + } + + // 2. Pass loaded list to InventoryDataManager + DataLoader.SaveData(convertedList, type); + + return true; + } + catch (Exception e) + { + Debug.LogWarning(e.Message); + } + + return false; + } + #endregion + + protected SceneBaseDataManager> GetObjectType() + { + return GameObject.FindObjectOfType(); + } + + protected SceneBaseDataManager> CreateInstance(ref GameObject managerGameObject) + { + return managerGameObject.AddComponent(); + } + + + // TODO whats with that +/* public int AddToInventory(EquippableItem pickable) + { + if (this._items.Count <= MAX_ITEMS) + { + for (int slotNumber = 0; slotNumber < MAX_ITEMS; slotNumber++) + { + if (!this._items.ContainsKey(slotNumber)) + { + this._items[slotNumber] = pickable; + return slotNumber; + } + + } + } + + return -1; + }*/ +} diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataManager.cs.meta new file mode 100644 index 00000000..ecc7d18c --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2abcc8484cbc4084baa69da81c59fc3d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Panel/SceneChestManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/SceneChestManager.cs new file mode 100644 index 00000000..10de54ba --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/SceneChestManager.cs @@ -0,0 +1,80 @@ +// using Shared.Manager.Scene; +// using System.Collections.Generic; +// using UnityEngine; +// using UnityEditor; +// using UnityEngine.SceneManagement; +// using System.IO; +// using System.Linq; +// using REFACTORING.Shared.Manager.Scene; +// +// namespace REFACTORING.Scene +// { +// public class SceneChestManager : SceneBaseDataManager +// { +// private new const string STATIC_ELEMENT_LOCATION = "/StaticElements/"; +// private new const string ELEMENT_FOLDER_NAME = "Chest"; +// private new const string ITEM_LIST_NAME = "ChestList"; +// +// // [SerializeField] +// // public List StaticElements; +// // +// // [SerializeField] +// // public List DynamicElements; +// +// public override void AddElementToList() +// { +// throw new System.NotImplementedException(); +// } +// +// public override void RemoveElementFromList() +// { +// throw new System.NotImplementedException(); +// } +// +// public override void Build() +// { +// throw new System.NotImplementedException(); +// } +// +// public override void LoadData() +// { +// this.StaticElements = LoadStaticChestsList(); +// } +// +// #region Static list of Chest Loader +// private List LoadStaticChestsList() +// { +// var path = SaveSystem.GetSavePath(this.MapName + STATIC_ELEMENT_LOCATION); +// +// if (!Directory.Exists(path)) +// return new List(); +// +// List chestPrefabAssetList = new List(); +// +// foreach(var file in new DirectoryInfo(path).GetFiles()) +// { +// Debug.Log(file.FullName); +// +// List chestPrefabAssetDataList = SaveChestSystem.LoadChestsList(this.MapName + STATIC_ELEMENT_LOCATION, ITEM_LIST_NAME); +// +// chestPrefabAssetList = chestPrefabAssetDataList.Select(chestPrefabAssetData => chestPrefabAssetData.MapDataToChestPrefarbAsset()).ToList(); +// +// // Debug.Log("---- Load Chest"); +// // +// // foreach(ChestPrefarbAsset chest in chestPrefarbAssetList) +// // { +// // Debug.Log(chest.name); +// // foreach(KeyValuePair equippableItemPrefarbAsset in chest.content) +// // { +// // // Debug.Log("item on position " + equippableItemPrefarbAsset.Key + +// // // " " + equippableItemPrefarbAsset.Value.equippableItem.name); +// // } +// // } +// +// } +// +// return chestPrefabAssetList; +// } +// #endregion +// } +// } \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Panel/SceneChestManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/SceneChestManager.cs.meta new file mode 100644 index 00000000..e7f42125 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/SceneChestManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 03ae14a03c0d4cfb83ddf5c7eb84c528 +timeCreated: 1660171923 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Scene/Task.meta b/Assets/Scripts/REFACTORING/Application/Panel/Task.meta similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Scene/Task.meta rename to Assets/Scripts/REFACTORING/Application/Panel/Task.meta diff --git a/Assets/Scripts/REFACTORING/Application/Scene/Task/SaveTaskManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Task/SaveTaskManager.cs similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Scene/Task/SaveTaskManager.cs rename to Assets/Scripts/REFACTORING/Application/Panel/Task/SaveTaskManager.cs diff --git a/Assets/Scripts/REFACTORING/Application/Scene/Task/SaveTaskManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Task/SaveTaskManager.cs.meta similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Scene/Task/SaveTaskManager.cs.meta rename to Assets/Scripts/REFACTORING/Application/Panel/Task/SaveTaskManager.cs.meta diff --git a/Assets/Scripts/REFACTORING/Application/Scene/Task/SceneTaskDataLoader.cs b/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataLoader.cs similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Scene/Task/SceneTaskDataLoader.cs rename to Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataLoader.cs diff --git a/Assets/Scripts/REFACTORING/Application/Scene/Task/SceneTaskDataLoader.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataLoader.cs.meta similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Scene/Task/SceneTaskDataLoader.cs.meta rename to Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataLoader.cs.meta diff --git a/Assets/Scripts/REFACTORING/Application/Scene/Task/SceneTaskDataManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataManager.cs similarity index 97% rename from Assets/Scripts/REFACTORING/Application/Scene/Task/SceneTaskDataManager.cs rename to Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataManager.cs index 06870e27..f9a6821a 100644 --- a/Assets/Scripts/REFACTORING/Application/Scene/Task/SceneTaskDataManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataManager.cs @@ -26,9 +26,6 @@ public class SceneTaskDataManager : SceneBaseDataManager // LoadDynamicData(); taskManager.SetList(StaticDataList.GetList()); - - taskManager.OpenPanel(); - } protected SceneBaseDataManager GetObjectType() diff --git a/Assets/Scripts/REFACTORING/Application/Scene/Task/SceneTaskDataManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataManager.cs.meta similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Scene/Task/SceneTaskDataManager.cs.meta rename to Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataManager.cs.meta diff --git a/Assets/Scripts/REFACTORING/Application/Scene/Task/TaskDataListManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Task/TaskDataListManager.cs similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Scene/Task/TaskDataListManager.cs rename to Assets/Scripts/REFACTORING/Application/Panel/Task/TaskDataListManager.cs diff --git a/Assets/Scripts/REFACTORING/Application/Scene/Task/TaskDataListManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Task/TaskDataListManager.cs.meta similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Scene/Task/TaskDataListManager.cs.meta rename to Assets/Scripts/REFACTORING/Application/Panel/Task/TaskDataListManager.cs.meta diff --git a/Assets/Scripts/REFACTORING/Application/Shared.meta b/Assets/Scripts/REFACTORING/Application/Shared.meta new file mode 100644 index 00000000..88ea121d --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c947e46e1d604351adf547f0d75360e4 +timeCreated: 1660164696 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/DataListManager.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/DataListManager.cs index fc63bc97..409f1622 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/DataListManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/DataListManager.cs @@ -3,7 +3,7 @@ using UnityEngine; public abstract class DataListManager : SceneDataListManagerInterface { - [SerializeField] protected List Elements; + [SerializeField] protected List Elements = new List(); [SerializeField] protected UIBaseManager uiManager; /// @@ -26,16 +26,10 @@ public abstract class DataListManager : SceneDataListManagerInterface { Elements = _elements; } - - public void AddElementToList(T newElement) - { - throw new System.NotImplementedException(); - } - public void RemoveElementFromList(T element) - { - throw new System.NotImplementedException(); - } + public abstract void AddElementToList(T newElement); + + public abstract void RemoveElementFromList(T element); //public abstract void Build(); } diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel.meta index 495c1c83..43b4af3b 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel.meta +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel.meta @@ -1,3 +1,3 @@ fileFormatVersion: 2 -guid: 5a593b8f8685477295db56223cebd3eb -timeCreated: 1660487127 \ No newline at end of file +guid: 77ed1a571d1643f1993ccef6284861fd +timeCreated: 1660166978 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneBaseDataLoader.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataLoader.cs similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneBaseDataLoader.cs rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataLoader.cs diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneBaseDataLoader.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataLoader.cs.meta similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneBaseDataLoader.cs.meta rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataLoader.cs.meta diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneBaseDataManager.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataManager.cs similarity index 89% rename from Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneBaseDataManager.cs rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataManager.cs index e5b9a3b2..651af7f1 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneBaseDataManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataManager.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using UnityEngine; - -public abstract class SceneBaseDataManager : MonoBehaviour where T : Task +/*where T : Task*/ +public abstract class SceneBaseDataManager : MonoBehaviour { protected virtual string OBJECT_FOLDER_NAME => ""; protected virtual string OBJECT_LIST_NAME => ""; @@ -12,7 +12,7 @@ public abstract class SceneBaseDataManager : MonoBehaviour where T : Task protected DataListManager StaticDataList; protected DataListManager DynamicDataList; - protected SceneDataLoaderInterface DataLoader { get; set; } + protected SceneBaseDataLoader DataLoader { get; set; } public static SceneBaseDataManager Instance; // { get; private set; } @@ -64,12 +64,12 @@ public abstract class SceneBaseDataManager : MonoBehaviour where T : Task // // DynamicDataList.Build(); // } - private bool LoadData(SceneElementTypeEnum type, ref DataListManager dataListManager) + protected virtual bool LoadData(SceneElementTypeEnum type, ref DataListManager dataListManager) { try { dataListManager.SetList( - DataLoader.LoadData(SceneElementTypeEnum.None) + DataLoader.LoadData(SceneElementTypeEnum.None) as List ); return true; @@ -80,8 +80,8 @@ public abstract class SceneBaseDataManager : MonoBehaviour where T : Task return false; } - - private bool SaveData(List _elements, SceneElementTypeEnum type) + + protected virtual bool SaveData(List _elements, SceneElementTypeEnum type) { try { @@ -119,11 +119,12 @@ public abstract class SceneBaseDataManager : MonoBehaviour where T : Task // TODO // how to get list // 1. List in UI manager should be synchronized with list in this manager - + // approach: // 1. get from outside, update local list && us it // 2. Handle list synchronized all the time & pass local list - + + Debug.Log("SaveStaticData"); return SaveData(StaticDataList.GetList(), SceneElementTypeEnum.Static); } diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneBaseDataManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataManager.cs.meta similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneBaseDataManager.cs.meta rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataManager.cs.meta diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataListManager.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManager.cs similarity index 95% rename from Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataListManager.cs rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManager.cs index d7340cd1..bfd6cd6d 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataListManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManager.cs @@ -49,11 +49,11 @@ public abstract class SceneDataListManager : DataListManager // // doBuild(_object); // // // 3. SetUp EqippableItems list - // // Dictionary itemsOfChestList = prefabAsset.content; + // // Dictionary itemsOfChestList = prefabAsset.content; // // // // string[] assetNames = AssetDatabase.FindAssets("t:EquippableItem", new[] { assetLocalization }); // // - // // foreach(KeyValuePair itemsOfChestEntry in itemsOfChestList) + // // foreach(KeyValuePair itemsOfChestEntry in itemsOfChestList) // // { // // // 3.1 find object // // foreach (string SOName in assetNames) diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataListManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManager.cs.meta similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataListManager.cs.meta rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManager.cs.meta diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataListManagerInterface.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManagerInterface.cs similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataListManagerInterface.cs rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManagerInterface.cs diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataListManagerInterface.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManagerInterface.cs.meta similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataListManagerInterface.cs.meta rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManagerInterface.cs.meta diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataLoaderInterface.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataLoaderInterface.cs similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataLoaderInterface.cs rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataLoaderInterface.cs diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataLoaderInterface.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataLoaderInterface.cs.meta similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene/SceneDataLoaderInterface.cs.meta rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataLoaderInterface.cs.meta diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene.meta deleted file mode 100644 index 43b4af3b..00000000 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Scene.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 77ed1a571d1643f1993ccef6284861fd -timeCreated: 1660166978 \ No newline at end of file diff --git a/Assets/Scripts/SceneManager/SaveInventory.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable.meta similarity index 77% rename from Assets/Scripts/SceneManager/SaveInventory.meta rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable.meta index cf5b1f17..ba988928 100644 --- a/Assets/Scripts/SceneManager/SaveInventory.meta +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1fdd6687dd658574da87271e9677e290 +guid: 26415552df60a48448e65ca186d33e97 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelController.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelController.cs new file mode 100644 index 00000000..c8157398 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelController.cs @@ -0,0 +1,106 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; +using UnityEngine.UI; + +public abstract class DraggablePanelController : PanelController>, DraggablePanelInterface +{ + [SerializeField] protected new List ChildBoxList = new List(); + + protected static UIWarehouseManager _uiManager; + + protected new UIWarehouseManager UiManager + { + get + { + if (_uiManager == null) { return FetchUiManager() as UIWarehouseManager; } + + return null; + } + } + + + public ISlot SetupDragAndDropToSlot(ISlot slot) + { + slot.OnBeginDragEvent += BeginDrag; + slot.OnEndDragEvent += EndDrag; + slot.OnDragEvent += Drag; + slot.OnDropEvent += Drop; + + return slot; + } + + public void BeginDrag(ItemSlot itemSlot) + { + if (itemSlot.Item != null) + { + DraggedSlotController.Instance.CreateDraggedSlot(itemSlot, _panelContent.transform.position); + } + } + + public void Drag(ItemSlot itemSlot) + { + DraggedSlotController.Instance.UpdatePosition(Input.mousePosition); + } + + public void EndDrag(ItemSlot itemSlot) + { + if (!DraggedSlotController.Instance.IsDragged()) // if there was nothing dragged - ignore event + return; + + DraggedSlotController.Instance.RemoveDraggedSlot(); + + // Apply list of items + for (int i = 0; i < ChildBoxList.Count; i++) + { + if (ChildBoxList[i].Item != null) + { + UiManager.Add(new KeyValuePair(i, (EquippableItem)ChildBoxList[i].Item)); + } + else + { + UiManager.RemoveByPosition(i); + } + } + } + + public virtual void Drop(ItemSlot dropItemSlot) + { + if (!DraggedSlotController.Instance.IsDragged()) // if there was nothing dragged - ignore event + return; + + var draggedSlot = GetDraggedSlot(); + + if (dropItemSlot.CanReceiveItem(draggedSlot.Item) && draggedSlot.CanReceiveItem(dropItemSlot.Item)) + { + EquippableItem dragItem = draggedSlot.Item as EquippableItem; + EquippableItem dropItem = dropItemSlot.Item as EquippableItem; + + // TODO insert child criterials + + Item _tmpDraggedItem = draggedSlot.Item; // InventoryUIManager.Instance.DraggedSlot.Item; // remember temporary currently dragged item + + + /* + * not sure why but if you change order of assign, something will ovberride dropItemSlot.Item vale accordint to draggedSlot.Item = dropItemSlot.Item; value + * BUG - not sure where + */ + draggedSlot.Item = dropItemSlot.Item; + UiManager.Add(new KeyValuePair(draggedSlot.Number, (EquippableItem)draggedSlot.Item)); + + dropItemSlot.Item = _tmpDraggedItem; + UiManager.Add(new KeyValuePair(dropItemSlot.Number, (EquippableItem)dropItemSlot.Item)); + } + } + + //public ISlot GetDraggedSlotFromManager() => InventoryUIManager.Instance.DraggedSlot; + public ISlot GetDraggedSlot() + { + return DraggedSlotController.Instance.DraggedSlot; + } + + public void SetItemOnPosition() + { + throw new System.NotImplementedException(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelController.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelController.cs.meta new file mode 100644 index 00000000..da75bba0 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 68a2f165c11561a438c59d76adceff30 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelInterface.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelInterface.cs new file mode 100644 index 00000000..483abc54 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelInterface.cs @@ -0,0 +1,25 @@ +using UnityEditor; +using UnityEngine; + +public interface DraggablePanelInterface +{ + /// + /// Function to associate defined Drag&Drop behaviour to passed slot + /// + /// + public ISlot SetupDragAndDropToSlot(ISlot slot); + + + public void BeginDrag(ItemSlot itemSlot); + + public void EndDrag(ItemSlot itemSlot); + + public void Drag(ItemSlot itemSlot); + + public void Drop(ItemSlot dropItemSlot); + + // supports function to use in Drop + public void SetItemOnPosition(); + + public ISlot GetDraggedSlot(); +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelInterface.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelInterface.cs.meta new file mode 100644 index 00000000..ec781a10 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelInterface.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0472eb5aa2400874b98ffa373b72c07e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggedSlotController.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggedSlotController.cs new file mode 100644 index 00000000..51a21c30 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggedSlotController.cs @@ -0,0 +1,96 @@ +using System; +using UnityEditor; +using UnityEngine; +using UnityEngine.UI; + +public class DraggedSlotController : MonoBehaviour +{ + public static DraggedSlotController Instance { get; private set; } + + [Header("Dragged Image")] + [SerializeField] protected Image DraggedSlotImageTemplate; + [SerializeField] protected Image DraggedSlotImage; + + [Space] + [Header("Dragged Slot")] + [SerializeField] protected ISlot _draggedSlot; + public ISlot DraggedSlot // in Drag & Drop functionality for Warehouse set of panels I will temporary delegate dragged item to outside static object instance in order to remember it during dragging object from one slot to anothe one + { + get { return _draggedSlot; } + set + { + _draggedSlot = value; + } + } + + public void Awake() + { + if (Instance == null) + { + Instance = this; + } + else + { + Destroy(gameObject); + } + } + + public bool IsDragged() + { + return DraggedSlot != null; + } + + public void CreateDraggedSlot(ItemSlot itemSlot, Vector3 beginingPosition) + { + DraggedSlot = itemSlot; + + MakeDraggableItem(beginingPosition); + } + private void MakeDraggableItem( Vector3 beginingPosition) + { + if (DraggedSlotImage) + { + DraggedSlotImage.enabled = true; + + return; + } + + GameObject globalGUI = GameObject.FindGameObjectWithTag("GUI"); + + if (globalGUI) + { + DraggedSlotImage = MonoBehaviour.Instantiate(DraggedSlotImageTemplate, DraggedSlotImageTemplate.transform.position, Quaternion.identity, globalGUI.transform); + DraggedSlotImage.transform.localPosition = beginingPosition; + DraggedSlotImage.sprite = DraggedSlot.Item.Image; + DraggedSlotImage.transform.position = Input.mousePosition; + DraggedSlotImage.enabled = true; + } + else + { + Debug.Log("Can't find global GUI object!!!"); + } + } + + public void UpdatePosition(Vector3 newSlotPosition) + { + if(DraggedSlotImage != null) + DraggedSlotImage.transform.position = newSlotPosition; + } + + public bool RemoveDraggedSlot() + { + try + { + DestroyImmediate(DraggedSlotImage.gameObject, true); + DraggedSlotImage = null; + + DraggedSlot = null; + }catch(Exception e) + { + Debug.LogError(e.Message); + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggedSlotController.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggedSlotController.cs.meta new file mode 100644 index 00000000..52cf034e --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggedSlotController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c8081574e3f851e4d9335be93900a94e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/SceneManager/SaveItem/EquippableItemData.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel.meta similarity index 77% rename from Assets/Scripts/SceneManager/SaveItem/EquippableItemData.meta rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel.meta index d19875cb..efe76940 100644 --- a/Assets/Scripts/SceneManager/SaveItem/EquippableItemData.meta +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e39995ada1a75cf4bb0857afc6d14d67 +guid: e3e28c38b9237d74eb9ac2555dea625e folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel/WarehousePanelController.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel/WarehousePanelController.cs new file mode 100644 index 00000000..471c6d23 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel/WarehousePanelController.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +public abstract class WarehousePanelController : DraggablePanelController +{ + public override void BuildPanelContent(List> elements) + { + base.BuildPanelContent(elements); + + ClearSlots(); + } + + public override void ClearSlots() + { + foreach (ItemSlot ChestSlot in ChildBoxList) + { + ChestSlot.ResetSlot(); + } + } + + public abstract override void BuildPanelSlots(); + public abstract override GameObject BuildSlot(int key, GameObject _parent); +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel/WarehousePanelController.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel/WarehousePanelController.cs.meta new file mode 100644 index 00000000..67ceb10c --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel/WarehousePanelController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cba22a871f952fc4ea06e8cfc81628ea +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIWarehouseManager.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIWarehouseManager.cs new file mode 100644 index 00000000..9775980b --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIWarehouseManager.cs @@ -0,0 +1,136 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEngine; + +public abstract class UIWarehouseManager : UIBaseManager> +{ + public virtual int SLOTS_NUMBER => 0; + + public static new UIWarehouseManager Instance { get; private set; } + /* + * not sure why but childrens of this class dont interfere on parents Awake + */ + public void Awake() + { + if (Instance == null) + { + Instance = this; + } + else + { + Destroy(gameObject); + } + } + + /// + /// Function to find item in warehouser by its id, returns list of all slots where item occured + /// + /// + /// + public List> FindItemInWarehouse(int itemId) + { + return Elements.Where(item => item.Value.Id == itemId).ToList(); + } + + /// + /// Function to find item in warehouser by its name, returns list of all slots where item occured + /// + /// + /// + public List> FindItemInWarehouseByName(string itemName) + { + return Elements.Where(item => item.Value.name == itemName).ToList(); + } + + + + /// + /// Function (SetItemOnPosition) to add slot with its number and item to list (which will be mapped with panel content) + /// + /// + public void Add(KeyValuePair itemOnSlot) + { + if (!CheckIfSlotIsInRange(itemOnSlot.Key)) + throw new System.Exception($"Slot number: {itemOnSlot.Key} is out of range, avaiable: {SLOTS_NUMBER} slots"); + + if (CheckIfSlotExists(itemOnSlot.Key) && !CheckIfPositionIsEmpty(itemOnSlot.Key)) + RemoveByPosition(itemOnSlot.Key); + + if(itemOnSlot.Value != null) + { + Debug.Log($" Added {itemOnSlot.Value} on position {itemOnSlot.Key}"); + base.Add(itemOnSlot); + } + } + + /// + /// Function to add item on first empty slot to list (which will be mapped with panel content) + /// + /// + public void Add(Item item) + { + if(IsFull()) + throw new System.Exception($"Warehouse is full!!!"); + + // find first empty position / slot + var max = Elements.Max(itemSlot => itemSlot.Key); + + base.Add(new KeyValuePair(max, item)); + } + + + + public void RemoveByPosition(int keyPosition) + { + if (!CheckIfSlotExists(keyPosition)) + return; // throw new System.Exception($"Slot with number: {keyPosition} don't exist"); + + Debug.Log($"Remove from position: {keyPosition}"); + + Elements.RemoveAll(itemSlot => itemSlot.Key == keyPosition); + } + + public int RemoveByItemId(int itemId) + { + return Elements.RemoveAll(itemSlot => itemSlot.Value.Id == itemId); + } + + public int RemoveByItemName(string itemName) + { + return Elements.RemoveAll(itemSlot => itemSlot.Value.Name == itemName); + } + + + public bool IsFull() + { + return Elements.Count() == SLOTS_NUMBER; + } + + + + + + private bool CheckIfSlotIsInRange(int slotNumber) + { + return slotNumber < SLOTS_NUMBER; + } + + private bool CheckIfSlotExists(int slotNumber) + { + return Elements.Any(itemSlot => itemSlot.Key == slotNumber); + } + + /// + /// Check if slot is empty in local list + /// + /// + private bool CheckIfPositionIsEmpty(int slotNumber) + { + if(CheckIfSlotExists(slotNumber)) { + return Elements.Where(itemSlot => itemSlot.Key == slotNumber).First().Value == null; + } + + return true; + } +} diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIWarehouseManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIWarehouseManager.cs.meta new file mode 100644 index 00000000..3d0168ac --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIWarehouseManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 64ff67a5470895e4d9f186fe4e4ad353 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Shared/SaveSystem/SaveModelSystem.cs b/Assets/Scripts/REFACTORING/Application/Shared/SaveSystem/SaveModelSystem.cs index 78482e91..98443307 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/SaveSystem/SaveModelSystem.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/SaveSystem/SaveModelSystem.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; public abstract class SaveModelSystem { @@ -19,4 +20,5 @@ public abstract class SaveModelSystem public virtual T LoadModelItem() { return (T)Activator.CreateInstance(typeof(T), new object[] { }); } public virtual List LoadModelList() { return new List(); } + } \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/UI.meta b/Assets/Scripts/REFACTORING/Application/UI.meta new file mode 100644 index 00000000..900817c0 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/UI.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e72a7403874a4dd3b9987b033d009bb8 +timeCreated: 1660171754 \ No newline at end of file diff --git a/Assets/Scripts/Inventory.meta b/Assets/Scripts/REFACTORING/Application/UI/Inventory.meta similarity index 77% rename from Assets/Scripts/Inventory.meta rename to Assets/Scripts/REFACTORING/Application/UI/Inventory.meta index c1ef616f..2cb14bb6 100644 --- a/Assets/Scripts/Inventory.meta +++ b/Assets/Scripts/REFACTORING/Application/UI/Inventory.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6ce31190a4475124d929da9d4612aaef +guid: 1042da730845c974598aec17c507491d folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs b/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs new file mode 100644 index 00000000..1ae3bf09 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +[Serializable] +public class InventoryUIManager : UIWarehouseManager +{ + public override int SLOTS_NUMBER { get { return 48; } } + + public const string ITEM_LOCALIZATION = "UiPanels/"; + public const string PANEL_NAME = "InventoryPanel"; + +/* public override void UpdateList() + { + // TODO something like rebuild associated panel content + // depending on which class we use it mayu be Inventory / Chest / Shop Panel Controller + DynamicPanel.GetComponent(); //.Refresh() -- rebuild content + }*/ + + public override void SetupPanel() + { + base.SetupPanel(); + + // setup models list + DynamicPanel.GetComponent().SetUp(Elements); + } + + public override void UpdateList() + { + DynamicPanel.GetComponent().BuildPanelContent(Elements); + } + + protected override GameObject GetTemplatePanel() + { + // Resources = default path - Asset/Resources ... .obj + return Resources.Load(ITEM_LOCALIZATION + PANEL_NAME) as GameObject; + } +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs.meta b/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs.meta new file mode 100644 index 00000000..50bb1d0f --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 79e7954722c69764e9be36961af94d1e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs b/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs new file mode 100644 index 00000000..8ee03b2d --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs @@ -0,0 +1,91 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using System; + + +public class InventoryPanelController : WarehousePanelController +{ + protected override UIBaseManager> FetchUiManager() + { + var uiManager = GameObject.FindObjectOfType(); + + // uiManager.SetPanelController(gameObject); - unnecessary + + return uiManager; + } + + + // build panel sunction + // - setup - main function to build panel on screen + // - setPanelISlots - build slots on panel dependiong on declared amount + // - setPanelItems - invoking building items on slots + + // api for drag and drop + // - set item on position + // - remove item from position + // - find item in warehouse + + + // 1. Prepare empty panel + public override void BuildPanelSlots() + { + if (_panelContent == null) + throw new Exception("Panel content is not attaches"); + + + for (int _position = 0; _position < UiManager.SLOTS_NUMBER; _position++) + { + //ISlot newSlot = SetupSlot(_position, _panel); + GameObject newSlot = BuildSlot(_position, _panelContent); + + // Set new Slot instance + ChildBoxList.Add(newSlot.GetComponent()); + + // Assign events + ChildBoxList[_position] = SetupDragAndDropToSlot(ChildBoxList[_position]); + } + } + + public override GameObject BuildSlot(int key, GameObject _parent) + { + if (ChildBoxTemplate == null) + throw new Exception("itemslotbox_template is empty"); + + GameObject _newItemSlot = MonoBehaviour.Instantiate(ChildBoxTemplate, _parent.transform.position, Quaternion.identity); //.GetComponent(); + + _newItemSlot.transform.SetParent(_parent.transform); + _newItemSlot.transform.localScale = new Vector3(1.15f, 1.15f, 1.15f); + + _newItemSlot.GetComponent().SetupSlot(key, null, this); + + return _newItemSlot; + } + + + // 2. Set up panel additn items to it + public override void SetUp(List> elements) + { + // Build panel content template + BuildPanelSlots(); + + // Fill with items + BuildPanelContent(elements); + } + + + public override void BuildPanelContent(List> elements) + { + + base.BuildPanelContent(elements); + + Debug.Log("Build content"); + foreach (KeyValuePair element in elements) + { + Debug.Log($"key: {element.Key} - value: {element.Value}"); + ChildBoxList[element.Key].SetItem(element.Value); + } + } +} diff --git a/Assets/Scripts/Inventory/InventoryPanelController.cs.meta b/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs.meta similarity index 83% rename from Assets/Scripts/Inventory/InventoryPanelController.cs.meta rename to Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs.meta index 11ac648c..18463b50 100644 --- a/Assets/Scripts/Inventory/InventoryPanelController.cs.meta +++ b/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d0bff20d6fb721a449df16891030739a +guid: b3ae9277a19e5dc49aa607d1d2ec2dc9 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/REFACTORING/Application/UI/Panel/TaskPanelController.cs b/Assets/Scripts/REFACTORING/Application/UI/Panel/TaskPanelController.cs index 18779625..5fafd044 100644 --- a/Assets/Scripts/REFACTORING/Application/UI/Panel/TaskPanelController.cs +++ b/Assets/Scripts/REFACTORING/Application/UI/Panel/TaskPanelController.cs @@ -5,32 +5,9 @@ using UnityEngine.UI; using UnityEngine.EventSystems; using System; -public class TaskPanelController : MonoBehaviour +public class TaskPanelController : PanelController { - [Header("Panel Information")] - [SerializeField] protected GameObject _panelContent; - //[SerializeField] private TaskBox TaskBoxTemplate; - [SerializeField] private GameObject TaskBoxTemplate; - [SerializeField] private List TaskBoxList; - - /// - /// Fetch reference to static instance of UiManager script - /// - private static UIBaseManager _uiManager; - - private UIBaseManager UiManager - { - get - { - if (_uiManager == null) { _uiManager = FetchUiManager(); } - - return _uiManager; - } - } - - // TODO decide whick method use and where bind object with itself - // public abstract void Bind(ManagerInterface manager); - private UIBaseManager FetchUiManager() // check if need return by ref + protected override UIBaseManager FetchUiManager() // check if need return by ref { var uiManager = GameObject.FindObjectOfType(); @@ -38,39 +15,18 @@ public class TaskPanelController : MonoBehaviour return uiManager; } - - public void InitPanelBoxes(List _tasks) - { - if (_panelContent == null) - throw new Exception("Panel content is not attaches"); - for(int i = 0; i < _tasks.Count; i++) + + public override void BuildPanelContent(List elements) + { + base.BuildPanelContent(elements); + + for (int i = 0; i < elements.Count; i++) { - this.AddTask(_tasks[i]); + this.AddTask(elements[i]); } } - protected GameObject SetupTaskBox(Task _task) - { - if (TaskBoxTemplate == null) - throw new Exception("taskbox_template is empty"); - - GameObject _newTaskBox = Instantiate(TaskBoxTemplate, _panelContent.transform.position, Quaternion.identity); //.GetComponent(); - - _newTaskBox.transform.SetParent(_panelContent.transform); - - _newTaskBox.transform.localScale = new Vector3(2.5f, 2.5f, 1.0f); - - _newTaskBox.GetComponent().SetTask(_task); - - return _newTaskBox; - } - - public void Setup(List _tasks) - { - this.InitPanelBoxes(_tasks); - } - public void AddTask(Task _task) { // update TaskManager main list of task @@ -80,6 +36,40 @@ public class TaskPanelController : MonoBehaviour GameObject newTaskBox = SetupTaskBox(_task); // Set new Slot instance - TaskBoxList.Add(newTaskBox); + ChildBoxList.Add(newTaskBox); + } + + protected GameObject SetupTaskBox(Task _task) + { + if (ChildBoxTemplate == null) + throw new Exception("taskbox_template is empty"); + + GameObject _newTaskBox = MonoBehaviour.Instantiate(ChildBoxTemplate, _panelContent.transform.position, Quaternion.identity); //.GetComponent(); + + _newTaskBox.transform.SetParent(_panelContent.transform); + + _newTaskBox.transform.localScale = new Vector3(2.5f, 2.5f, 1.0f); + + _newTaskBox.GetComponent().SetTask(_task); + + return _newTaskBox; + } + + + + // Ignored methods + public override void BuildPanelSlots() + { + return; + } + + public override GameObject BuildSlot(int key, GameObject _parent) + { + throw new NotImplementedException(); + } + + public override void ClearSlots() + { + throw new NotImplementedException(); } } diff --git a/Assets/Scripts/REFACTORING/Domain.meta b/Assets/Scripts/REFACTORING/Domain.meta new file mode 100644 index 00000000..d1cde923 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Domain.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cb4d460084b74e059c3d762bc6e13050 +timeCreated: 1660483299 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Domain/Enum/EquipmentTypeEnum.cs b/Assets/Scripts/REFACTORING/Domain/Enum/EquipmentTypeEnum.cs new file mode 100644 index 00000000..77df1ed8 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Domain/Enum/EquipmentTypeEnum.cs @@ -0,0 +1,14 @@ +[System.Serializable] +public enum EquipmentTypeEnum +{ + Helmet, + Chest, + Gloves, + Boots, + Weapon, + Potion, + Bracelet, + Necklet, + Ring, + Other +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Domain/Enum/EquipmentTypeEnum.cs.meta b/Assets/Scripts/REFACTORING/Domain/Enum/EquipmentTypeEnum.cs.meta new file mode 100644 index 00000000..329d8e5b --- /dev/null +++ b/Assets/Scripts/REFACTORING/Domain/Enum/EquipmentTypeEnum.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 583901b64ccc6d3499f1e4f57390255d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Item.meta b/Assets/Scripts/REFACTORING/Models/Item.meta new file mode 100644 index 00000000..249b4597 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Item.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f614b6829bdb4b289e4e097b4fd17a12 +timeCreated: 1662915893 \ No newline at end of file diff --git a/Assets/Scripts/SceneManager/SaveItem/ItemData.meta b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem.meta similarity index 77% rename from Assets/Scripts/SceneManager/SaveItem/ItemData.meta rename to Assets/Scripts/REFACTORING/Models/Item/EquippableItem.meta index 4796fe35..4046aaf9 100644 --- a/Assets/Scripts/SceneManager/SaveItem/ItemData.meta +++ b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f8f73a42f83f7964fa1578e1dd5b4d61 +guid: 1d9b2ee8ca4dff44e879cfe9ea14c175 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/Item/EquippableItem.cs b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItem.cs similarity index 70% rename from Assets/Scripts/Item/EquippableItem.cs rename to Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItem.cs index da08f7c7..0e61f46a 100644 --- a/Assets/Scripts/Item/EquippableItem.cs +++ b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItem.cs @@ -2,20 +2,6 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public enum EquipmentType -{ - Helmet, - Chest, - Gloves, - Boots, - Weapon, - Potion, - Bracelet, - Necklet, - Ring, - Other -} - [CreateAssetMenu] [System.Serializable] public class EquippableItem : Item @@ -29,13 +15,12 @@ public class EquippableItem : Item public bool isStackable = false; [Space] - public EquipmentType EquipmentType; + public EquipmentTypeEnum EquipmentType; public EquippableItem(){} public EquippableItem(Item _item) : base(_item){} - public EquippableItem(string _name, string _description, int _level, GameObject _itemModel, Sprite _image) : base(_name, _description, _level, _itemModel, _image) - { - } + public EquippableItem(string _name, string _description, int _level, GameObject _itemModel, Sprite _image) : base(_name, _description, _level, _itemModel, _image) { } + } diff --git a/Assets/Scripts/Item/EquippableItem.cs.meta b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItem.cs.meta similarity index 83% rename from Assets/Scripts/Item/EquippableItem.cs.meta rename to Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItem.cs.meta index 96c44311..7be841a6 100644 --- a/Assets/Scripts/Item/EquippableItem.cs.meta +++ b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItem.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 943bb4b7c1123c44fb1cbc048a56a954 +guid: a0c176e87b3c91641897c23dc27e92a0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/SceneManager/SaveItem/EquippableItemData/EquippableItemData.cs b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemData.cs similarity index 94% rename from Assets/Scripts/SceneManager/SaveItem/EquippableItemData/EquippableItemData.cs rename to Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemData.cs index c1608e96..7fedcb3c 100644 --- a/Assets/Scripts/SceneManager/SaveItem/EquippableItemData/EquippableItemData.cs +++ b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemData.cs @@ -16,7 +16,7 @@ public class EquippableItemData : ItemData public bool isStackable; - public EquipmentType equipmentType; + public EquipmentTypeEnum equipmentType; private const string ITEM_LOCALIZATION = "Assets/Items/"; @@ -47,7 +47,7 @@ public class EquippableItemData : ItemData // equippableItem.InteligenceBonus = inteligenceBonus; // equippableItem.VitalityBonus = vitalityBonus; // equippableItem.isStackable = isStackable; - // equippableItem.EquipmentType = equipmentType; + // equippableItem.EquipmentTypeEnum = equipmentType; // Item item = base.MapDataToItem(prefarbAssetName); // equippableItem.Name = item.Name; diff --git a/Assets/Scripts/SceneManager/SaveItem/EquippableItemData/EquippableItemData.cs.meta b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemData.cs.meta similarity index 100% rename from Assets/Scripts/SceneManager/SaveItem/EquippableItemData/EquippableItemData.cs.meta rename to Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemData.cs.meta diff --git a/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAsset.cs b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAsset.cs new file mode 100644 index 00000000..56c9aab7 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAsset.cs @@ -0,0 +1,55 @@ +using UnityEditor; +using UnityEngine; + +[System.Serializable] +public class EquippableItemPrefabAsset : PrefabAssetModel +{ + + [SerializeField] + public EquippableItem EquippableItem = null; + + public EquippableItemPrefabAsset() { } + + public EquippableItemPrefabAsset(string _name, string _prefabAssetName, Vector3 _position, EquippableItem _equippableItem = null) + : base(_name, _prefabAssetName, _position) + { + EquippableItem = _equippableItem; + } + + /// + /// + /// + /// + /// + /// + /// the name by which the system will search for the item + public EquippableItemPrefabAsset(string _name, string _prefabAssetName, Vector3 _position, string _equippableItemName) + : base(_name, _prefabAssetName, _position) + { + + // TODO during build product process, objects are not found - refactor this + string[] assetNames = AssetDatabase.FindAssets("t:EquippableItem", new[] { "Assets/Items/" }); + foreach (string SOName in assetNames) + { + var SoPath = AssetDatabase.GUIDToAssetPath(SOName); + + if(SoPath.Contains(_equippableItemName + ".asset")) + { + // 3.2 set EquippableItem object + EquippableItem = AssetDatabase.LoadAssetAtPath(SoPath); + break; + } + } + } + + /// + /// Function to convert Prefab Asset model to data object + /// + /// + public EquippableItemPrefabAssetData MapPrefabAssetModelToData() + { + return new EquippableItemPrefabAssetData(this); + } +} + + diff --git a/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAsset.cs.meta b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAsset.cs.meta new file mode 100644 index 00000000..6c07acd1 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAsset.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7b7802014e11d9745a1fb90b31553624 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAssetData.cs b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAssetData.cs new file mode 100644 index 00000000..0b40d364 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAssetData.cs @@ -0,0 +1,45 @@ +using UnityEngine; + +[System.Serializable] +public class EquippableItemPrefabAssetData : PrefabAssetModelData +{ + EquippableItemData EquippableItemData; + + public EquippableItemPrefabAssetData(EquippableItemPrefabAsset assetModel) : base(assetModel) + { + EquippableItemData = MapEquippableItemToData(assetModel.EquippableItem); + } + + /// + /// Function to convert equitable item (current object partial variable) object to data format + /// + /// + /// + public EquippableItemData MapEquippableItemToData(EquippableItem equippableItem) + { + return new EquippableItemData(equippableItem); + } + + /// + /// Function to convert EquippableItem Asset format to data format + /// + /// + /// + public override PrefabAssetModelData PrefabAssetModelToData(PrefabAssetModel assetModel) + { + return new EquippableItemPrefabAssetData((EquippableItemPrefabAsset)assetModel); + } + + public override PrefabAssetModel MapDataToPrefabAssetModel() + { + EquippableItemPrefabAsset equippableItemPrefabAsset = new EquippableItemPrefabAsset( + Name, + PrefabAssetName, + new Vector3(Position[0], Position[1], Position[2]) + ); + + equippableItemPrefabAsset.EquippableItem = EquippableItemData.MapDataToEquippableItem(equippableItemPrefabAsset.PrefabAssetName); + + return equippableItemPrefabAsset; + } +} diff --git a/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAssetData.cs.meta b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAssetData.cs.meta new file mode 100644 index 00000000..ba81b967 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAssetData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 637522de5e9c1604b9edb7a21f660d60 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Item/Item.cs b/Assets/Scripts/REFACTORING/Models/Item/Item.cs similarity index 100% rename from Assets/Scripts/Item/Item.cs rename to Assets/Scripts/REFACTORING/Models/Item/Item.cs diff --git a/Assets/Scripts/Item/Item.cs.meta b/Assets/Scripts/REFACTORING/Models/Item/Item.cs.meta similarity index 83% rename from Assets/Scripts/Item/Item.cs.meta rename to Assets/Scripts/REFACTORING/Models/Item/Item.cs.meta index 48866ab6..4930f3eb 100644 --- a/Assets/Scripts/Item/Item.cs.meta +++ b/Assets/Scripts/REFACTORING/Models/Item/Item.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3d5bd84ad69269f4e8a3c4ec655119d5 +guid: 1c6df47a2440e8a49bef89083164fdc1 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/SceneManager/SaveItem/ItemData/ItemData.cs b/Assets/Scripts/REFACTORING/Models/Item/ItemData.cs similarity index 100% rename from Assets/Scripts/SceneManager/SaveItem/ItemData/ItemData.cs rename to Assets/Scripts/REFACTORING/Models/Item/ItemData.cs diff --git a/Assets/Scripts/SceneManager/SaveItem/ItemData/ItemData.cs.meta b/Assets/Scripts/REFACTORING/Models/Item/ItemData.cs.meta similarity index 100% rename from Assets/Scripts/SceneManager/SaveItem/ItemData/ItemData.cs.meta rename to Assets/Scripts/REFACTORING/Models/Item/ItemData.cs.meta diff --git a/Assets/Scripts/REFACTORING/Models/Panel.meta b/Assets/Scripts/REFACTORING/Models/Panel.meta new file mode 100644 index 00000000..09861462 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Panel.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7f794d5910b056443822eaf53a798555 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Panel/Slot.meta b/Assets/Scripts/REFACTORING/Models/Panel/Slot.meta new file mode 100644 index 00000000..288c02d6 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Panel/Slot.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 47f80f9e6ba3c524084bb8d8ad9f30be +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/ISlot.cs b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ISlot.cs similarity index 85% rename from Assets/Scripts/UI/ISlot.cs rename to Assets/Scripts/REFACTORING/Models/Panel/Slot/ISlot.cs index c04275a3..24f4ad15 100644 --- a/Assets/Scripts/UI/ISlot.cs +++ b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ISlot.cs @@ -19,7 +19,7 @@ public interface ISlot event Action OnDropEvent; //(B)Islot // as B - public void SetupSlot(int _number, Item _item, BasePanelController _PanelController); + public void SetupSlot(int _number, Item _item, WarehousePanelController _PanelController); public void SetItem(Item _item); bool CanReceiveItem(Item item); } \ No newline at end of file diff --git a/Assets/Scripts/UI/ISlot.cs.meta b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ISlot.cs.meta similarity index 100% rename from Assets/Scripts/UI/ISlot.cs.meta rename to Assets/Scripts/REFACTORING/Models/Panel/Slot/ISlot.cs.meta diff --git a/Assets/Scripts/Inventory/InventorySlot.cs b/Assets/Scripts/REFACTORING/Models/Panel/Slot/InventorySlot.cs similarity index 100% rename from Assets/Scripts/Inventory/InventorySlot.cs rename to Assets/Scripts/REFACTORING/Models/Panel/Slot/InventorySlot.cs diff --git a/Assets/Scripts/Inventory/InventorySlot.cs.meta b/Assets/Scripts/REFACTORING/Models/Panel/Slot/InventorySlot.cs.meta similarity index 100% rename from Assets/Scripts/Inventory/InventorySlot.cs.meta rename to Assets/Scripts/REFACTORING/Models/Panel/Slot/InventorySlot.cs.meta diff --git a/Assets/Scripts/Item/ItemSlot.cs b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ItemSlot.cs similarity index 89% rename from Assets/Scripts/Item/ItemSlot.cs rename to Assets/Scripts/REFACTORING/Models/Panel/Slot/ItemSlot.cs index c864cfb0..8f357e6c 100644 --- a/Assets/Scripts/Item/ItemSlot.cs +++ b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ItemSlot.cs @@ -12,7 +12,7 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler [SerializeField] private TextMeshProUGUI slotItemNumberText; [SerializeField] private Image itemImage; - public BasePanelController _PanelController; + public WarehousePanelController _PanelController; private Color normalColor = Color.white; private Color disabledColor = new Color(1, 1, 1, 0); // transparency = 0 @@ -48,7 +48,7 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler public event Action OnDragEvent; public event Action OnDropEvent; - public void SetupSlot(int _number, Item _item, BasePanelController _PanelController) + public void SetupSlot(int _number, Item _item, WarehousePanelController _PanelController) { this._PanelController = _PanelController; @@ -71,6 +71,16 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler UpdateItemNumberHolder(); } + public void ResetSlot() + { + Item = null; + + ChangeEnableImageView(false); + + countStackableItems = 0; + + UpdateItemNumberHolder(); + } private void ChangeEnableImageView(bool _flag) { @@ -102,7 +112,9 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler return true; } - // Events methods + + + #region Events methods public void OnBeginDrag(PointerEventData eventData) { if(OnBeginDragEvent != null) @@ -126,4 +138,5 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler if(OnDropEvent != null) OnDropEvent(this); } + #endregion } diff --git a/Assets/Scripts/Item/ItemSlot.cs.meta b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ItemSlot.cs.meta similarity index 100% rename from Assets/Scripts/Item/ItemSlot.cs.meta rename to Assets/Scripts/REFACTORING/Models/Panel/Slot/ItemSlot.cs.meta diff --git a/Assets/Scripts/REFACTORING/Models/Scene.meta b/Assets/Scripts/REFACTORING/Models/Scene.meta new file mode 100644 index 00000000..cdd3ac0d --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Scene.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 08674bb7d06248b8b6174ac07b325ee7 +timeCreated: 1662917411 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Models/Shared.meta b/Assets/Scripts/REFACTORING/Models/Shared.meta new file mode 100644 index 00000000..72f7c47a --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Shared.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4471be66d11d486f85e0cdc004f49bf9 +timeCreated: 1662914940 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModel.cs b/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModel.cs new file mode 100644 index 00000000..51335d4f --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModel.cs @@ -0,0 +1,22 @@ +using System; +using UnityEngine; + +[Serializable] +public class PrefabAssetModel +{ + [SerializeField] + public string Name { get; set; } + [SerializeField] + public string PrefabAssetName { get; set; } + [SerializeField] + public Vector3 Position { get; set; } + + public PrefabAssetModel() {} + + public PrefabAssetModel(string _name, string _prefabAssetName, Vector3 _position) + { + Name = _name; // builded object local name (setuped e.g. by admin) + PrefabAssetName = _prefabAssetName; // builded object name in Assets/ + Position = _position; + } +} diff --git a/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModel.cs.meta b/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModel.cs.meta new file mode 100644 index 00000000..c4bdd6fb --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModel.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ca127a3fffe446ff972f5cdedfd7e33f +timeCreated: 1662914958 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModelData.cs b/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModelData.cs new file mode 100644 index 00000000..482e292d --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModelData.cs @@ -0,0 +1,28 @@ +using System; +using UnityEngine; + +[Serializable] +public abstract class PrefabAssetModelData +{ + [SerializeField] public string Name { get; set; } + + [SerializeField] public string PrefabAssetName { get; set; } + + [SerializeField] public float[] Position { get; set; } + + + public PrefabAssetModelData(PrefabAssetModel assetModel) + { + Name = assetModel.Name; + PrefabAssetName = assetModel.PrefabAssetName; + + Position = new float[3]; + Position[0] = assetModel.Position.x; + Position[1] = assetModel.Position.y; + Position[2] = assetModel.Position.z; + } + + public abstract PrefabAssetModelData PrefabAssetModelToData(PrefabAssetModel assetModel); + + public abstract PrefabAssetModel MapDataToPrefabAssetModel(); +} diff --git a/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModelData.cs.meta b/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModelData.cs.meta new file mode 100644 index 00000000..2aaab2c4 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModelData.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 708416e69f724b48bbdf85684475e295 +timeCreated: 1662914978 \ No newline at end of file diff --git a/Assets/Scripts/SaveController.cs b/Assets/Scripts/SaveController.cs index 2073a688..73b7838e 100644 --- a/Assets/Scripts/SaveController.cs +++ b/Assets/Scripts/SaveController.cs @@ -33,7 +33,7 @@ public class SaveController : MonoBehaviour public void SaveInventory() { - SceneInventoryManager.Instance.SaveInventoryItems(); + SceneInventoryDataManager.Instance.SaveStaticData(); } public void SaveChests() diff --git a/Assets/Scripts/SceneManager/SaveInventory/SaveInventorySystem.cs b/Assets/Scripts/SceneManager/SaveInventory/SaveInventorySystem.cs deleted file mode 100644 index 5c9a3077..00000000 --- a/Assets/Scripts/SceneManager/SaveInventory/SaveInventorySystem.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using System.IO; -using System.Runtime.Serialization.Formatters.Binary; - -public class SaveInventorySystem : MonoBehaviour -{ - public static void SaveInventoryItemsList(Dictionary equitabbleItemList, string ElementName) - { - BinaryFormatter formatter = new BinaryFormatter(); - // todo: add in scene name folder - string path = SaveSystem.GetSavePath(); -Debug.Log("Saved Inventory at " + path); - if (!Directory.Exists(path)) - Directory.CreateDirectory(path); - - path += "/" + ElementName + ".fun"; - - FileStream stream = new FileStream(path, FileMode.Create); - - Dictionary data = new Dictionary(); - - foreach(KeyValuePair equitabbleItemEntry in equitabbleItemList) - { - data[equitabbleItemEntry.Key] = new EquippableItemPrefarbAssetData(equitabbleItemEntry.Value); - } - - formatter.Serialize(stream, data); - stream.Close(); - } - - private static void Save() - { - - } - - public static Dictionary LoadInventoryItemsList(string ElementName) - { - string path = SaveSystem.GetSavePath() + "/" + ElementName + ".fun"; - - if(File.Exists(path)) - { - - BinaryFormatter formatter = new BinaryFormatter(); - FileStream stream = new FileStream(path, FileMode.Open); - - Dictionary equitabbleItemList = formatter.Deserialize(stream) as Dictionary; - stream.Close(); - - return equitabbleItemList; - } else { - Debug.Log("Save file not found in " + path); - return null; - } - } - -} diff --git a/Assets/Scripts/SceneManager/SaveInventory/SaveInventorySystem.cs.meta b/Assets/Scripts/SceneManager/SaveInventory/SaveInventorySystem.cs.meta deleted file mode 100644 index 8465e6b2..00000000 --- a/Assets/Scripts/SceneManager/SaveInventory/SaveInventorySystem.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0a7279a76f3009541b3e4b3f71cdddf0 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAsset.cs b/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAsset.cs deleted file mode 100644 index ef56ed36..00000000 --- a/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAsset.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEditor; - -[System.Serializable] -public class EquippableItemPrefarbAsset -{ - [SerializeField] - public string name; - [SerializeField] - public string prefarbAssetName; - [SerializeField] - public Vector3 position; - [SerializeField] - public EquippableItem equippableItem = null; - - public EquippableItemPrefarbAsset() { } - - public EquippableItemPrefarbAsset(string _name, string _prefarbAssetName, Vector3 _position, EquippableItem _equippableItem) - { - name = _name; - prefarbAssetName = _prefarbAssetName; - position = _position; - equippableItem = _equippableItem; - } - - public EquippableItemPrefarbAsset(string _name, string _prefarbAssetName, Vector3 _position, string _equippableItemName) - { - name = _name; // builded object local name (setuped e.g. by admin) - prefarbAssetName = _prefarbAssetName; // builded object name in Assets/ - position = _position; - - string[] assetNames = AssetDatabase.FindAssets("t:EquippableItem", new[] { "Assets/Items/" }); - foreach (string SOName in assetNames) - { - var SOpath = AssetDatabase.GUIDToAssetPath(SOName); - - if(SOpath.Contains(_equippableItemName + ".asset")) - { - // 3.2 set EquippableItem object - equippableItem = AssetDatabase.LoadAssetAtPath(SOpath); - break; - } - } - } -} - diff --git a/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAsset.cs.meta b/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAsset.cs.meta deleted file mode 100644 index d034a1eb..00000000 --- a/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAsset.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 3954b63bce496d04a9fa9f9f1eac3e76 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAssetData.cs b/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAssetData.cs deleted file mode 100644 index dfb76b92..00000000 --- a/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAssetData.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -[System.Serializable] -public class EquippableItemPrefarbAssetData -{ - public string name; - - public string prefarbAssetName; - - public float[] position; - - EquippableItemData equippableItemData; - - public EquippableItemPrefarbAssetData(EquippableItemPrefarbAsset equippableItemPrefarbAsset) - { - name = equippableItemPrefarbAsset.name; - prefarbAssetName = equippableItemPrefarbAsset.prefarbAssetName; - - position = new float[3]; - position[0] = equippableItemPrefarbAsset.position.x; - position[1] = equippableItemPrefarbAsset.position.y; - position[2] = equippableItemPrefarbAsset.position.z; - - equippableItemData = this.MapEquippableItemToData(equippableItemPrefarbAsset.equippableItem); - } - - public EquippableItemData MapEquippableItemToData(EquippableItem equippableItem) - { - return new EquippableItemData(equippableItem); - } - - public EquippableItemPrefarbAsset MapDataToEquippableItemPrefarbAsset() - { - EquippableItemPrefarbAsset equippableItemPrefarbAsset = new EquippableItemPrefarbAsset(); - equippableItemPrefarbAsset.name = this.name; - equippableItemPrefarbAsset.prefarbAssetName = this.prefarbAssetName; - equippableItemPrefarbAsset.position = new Vector3(this.position[0], this.position[1], this.position[2]); - - equippableItemPrefarbAsset.equippableItem = this.equippableItemData.MapDataToEquippableItem(equippableItemPrefarbAsset.prefarbAssetName); - - return equippableItemPrefarbAsset; - } -} diff --git a/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAssetData.cs.meta b/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAssetData.cs.meta deleted file mode 100644 index 35e74b20..00000000 --- a/Assets/Scripts/SceneManager/SaveItem/EquippableItemPrefarbAssetData.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 835b159a6f9f2b64883442142387b34c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/SceneManager/SaveItem/SaveEquitableItemSystem.cs b/Assets/Scripts/SceneManager/SaveItem/SaveEquitableItemSystem.cs index 05dfd66c..a95e2f65 100644 --- a/Assets/Scripts/SceneManager/SaveItem/SaveEquitableItemSystem.cs +++ b/Assets/Scripts/SceneManager/SaveItem/SaveEquitableItemSystem.cs @@ -9,7 +9,7 @@ public static class SaveEquippableItemSystem private static string map; - public static void SaveEquitableItem(EquippableItemPrefarbAsset equitabbleItem, string ElementFolderName) + public static void SaveEquitableItem(EquippableItemPrefabAsset equitabbleItem, string ElementFolderName) { BinaryFormatter formatter = new BinaryFormatter(); // todo: add in scene name folder @@ -18,17 +18,17 @@ Debug.Log(path); if (!Directory.Exists(path)) Directory.CreateDirectory(path); - path += "/" + equitabbleItem.name + ".fun"; + path += "/" + equitabbleItem.Name + ".fun"; FileStream stream = new FileStream(path, FileMode.Create); - EquippableItemPrefarbAssetData data = new EquippableItemPrefarbAssetData(equitabbleItem); + EquippableItemPrefabAssetData data = new EquippableItemPrefabAssetData(equitabbleItem); formatter.Serialize(stream, data); stream.Close(); } - public static void SaveEquitableItemList(List equitabbleItemList, string _path, string ElementName) + public static void SaveEquitableItemList(List equitabbleItemList, string _path, string ElementName) { BinaryFormatter formatter = new BinaryFormatter(); // todo: add in scene name folder @@ -41,11 +41,11 @@ Debug.Log("Saved EquitableItemList at " + path); FileStream stream = new FileStream(path, FileMode.Create); - List data = new List(); + List data = new List(); - foreach(EquippableItemPrefarbAsset equitabbleItem in equitabbleItemList) + foreach(EquippableItemPrefabAsset equitabbleItem in equitabbleItemList) { - data.Add(new EquippableItemPrefarbAssetData(equitabbleItem)); + data.Add(new EquippableItemPrefabAssetData(equitabbleItem)); } formatter.Serialize(stream, data); @@ -57,7 +57,7 @@ Debug.Log("Saved EquitableItemList at " + path); } - public static EquippableItemPrefarbAssetData LoadEquitableItem(string equitabbleItemName, string ElementFolderName) + public static EquippableItemPrefabAssetData LoadEquitableItem(string equitabbleItemName, string ElementFolderName) { string path = SaveSystem.GetSavePath(ElementFolderName) + "/" + equitabbleItemName;// + ".fun"; @@ -66,7 +66,7 @@ Debug.Log("Saved EquitableItemList at " + path); BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); - EquippableItemPrefarbAssetData equitabbleItem = formatter.Deserialize(stream) as EquippableItemPrefarbAssetData; + EquippableItemPrefabAssetData equitabbleItem = formatter.Deserialize(stream) as EquippableItemPrefabAssetData; stream.Close(); return equitabbleItem; @@ -76,7 +76,7 @@ Debug.Log("Saved EquitableItemList at " + path); } } - public static List LoadEquitableItemList(string _path, string ElementName) + public static List LoadEquitableItemList(string _path, string ElementName) { string path = SaveSystem.GetSavePath(_path) + "/" + ElementName + ".fun"; @@ -86,7 +86,7 @@ Debug.Log("Saved EquitableItemList at " + path); BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); - List equitabbleItemList = formatter.Deserialize(stream) as List; + List equitabbleItemList = formatter.Deserialize(stream) as List; stream.Close(); return equitabbleItemList; diff --git a/Assets/Scripts/SceneManager/SceneInventoryManager.cs b/Assets/Scripts/SceneManager/SceneInventoryManager.cs deleted file mode 100644 index 93ead190..00000000 --- a/Assets/Scripts/SceneManager/SceneInventoryManager.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEditor; -using UnityEngine.SceneManagement; -using System.IO; -using System.Linq; - -public class SceneInventoryManager : MonoBehaviour -{ - private const string DYNAMIC_ELEMENT = "/DynamicElements/"; - private const string STATIC_ELEMENT = "/StaticElements/"; - - [SerializeField] - public Dictionary ItemsElements = new Dictionary(); - - public bool isNewGame = true; - public bool isContinued = false; - public string MapName; - public string ElementFolderName = "InventoryItem"; - public string ItemsListName = "InventoryItemList"; - - public static SceneInventoryManager Instance; - - public void Awake() - { - if(Instance == null) - { - this.MapName = SceneManager.GetActiveScene().name; - - Instance = this; - - - }else if (Instance != this) - { - Destroy(gameObject); - } - } - - public void Start() - { - LoadInventoryItems(); // load user items - - BuildInventoryItems(ItemsElements); // pass them to InventoryManager - } - - /// - /// Pass quest to taskManager after load data - /// - public void BuildInventoryItems(Dictionary itemsList) - { - // pass to InventoryManager singleton - foreach(KeyValuePair itemEntry in itemsList) - InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.equippableItem); - } - - public void RemoveInventoryItems(string _name) - { - // 1. Fetch all matched quests - we search by title which shoudl be unique but who know :D - List itemsList = this.ItemsElements.Where(item => item.Value.name == _name).Select(item => item.Key).ToList(); - - // 2. Remove them - foreach(var item in this.ItemsElements.Where(item => item.Value.name == _name).ToList()) - { - this.ItemsElements.Remove(item.Key); - } - } - - /// - /// Use TaskManaager list to save user quests - TaskManager.Instance.taskList - /// - public void SaveInventoryItems() - { - // Case I - if we remember all list - // 1) if after removed item form DynamicList is empty - remove all file - // 2) if after removed item form DynamciList there are another one - save updated list again - if(InventoryManager.Instance._items.Count > 0) { - - // 1. Map From Dictionary' to 'Dictionary' - Dictionary mappedList = new Dictionary(); - - foreach(KeyValuePair itemElement in InventoryManager.Instance._items) - { - mappedList[itemElement.Key] = new EquippableItemPrefarbAsset( - itemElement.Value.Name, - itemElement.Value.ItemModel.name, - new Vector3(0,0,0), - (EquippableItem) itemElement.Value - ); - } - - // 2. Save Items - SaveInventorySystem.SaveInventoryItemsList(mappedList, this.ItemsListName); - } else { - string _path = SaveSystem.GetSavePath() + "/" + this.ItemsListName + ".fun"; - - try - { - Debug.Log("File to remove: " + _path); - - if(File.Exists(_path)) - { - File.Delete(_path); - } - } - catch (IOException ioExp) - { - Debug.LogError(ioExp.Message); - } - } - - // Case II - if we rememenber object per file - // 1) remove specyfic file - // - // Unfortunatelly we don't use this way of saving items yet :D - } - - /// - /// Load quests to local list - /// Pass this to taskManager in outside method - /// - public void LoadInventoryItems() - { - this.LoadInventoryItemsList(); - } - - public void LoadInventoryItemsList() - { - string path = SaveSystem.GetSavePath(); - - if (!Directory.Exists(path)) // if not exists thats mean there was nothing saved yet - nothing to load - return; - - FileInfo[] fileInfo = new DirectoryInfo(path).GetFiles(); - - foreach(FileInfo file in fileInfo) - { - if(file.Name != this.ItemsListName + ".fun") - continue; - - Dictionary equippableItemsList = SaveInventorySystem.LoadInventoryItemsList(this.ItemsListName); - - // itemEntry.Value.MapDataToEquippableItem() - map data format to object - - // save object - foreach(KeyValuePair itemEntry in equippableItemsList) - { - InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.MapDataToEquippableItemPrefarbAsset().equippableItem); - } - - } - } -} diff --git a/Assets/Scripts/SceneManager/SceneInventoryManager.cs.meta b/Assets/Scripts/SceneManager/SceneInventoryManager.cs.meta deleted file mode 100644 index c8c42e43..00000000 --- a/Assets/Scripts/SceneManager/SceneInventoryManager.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ef71482e4d2df8440a1117e181018706 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/SettingsButton.cs b/Assets/Scripts/SettingsButton.cs index 73c1ac54..ad567c1d 100644 --- a/Assets/Scripts/SettingsButton.cs +++ b/Assets/Scripts/SettingsButton.cs @@ -9,7 +9,7 @@ namespace GUI_Scripts public void manageWindow() { - if(!InventoryManager.Instance.isOpen && !EquipmentManager.Instance.isOpen) + if(!InventoryUIManager.Instance.GetPanelStatus() && !EquipmentManager.Instance.isOpen) this.OpenPlayerPanel(); else this.ClosePlayerPanel(); @@ -17,18 +17,18 @@ namespace GUI_Scripts } public void OpenPlayerPanel() { - if(!InventoryManager.Instance.isOpen || !EquipmentManager.Instance.isOpen) + if(!InventoryUIManager.Instance.GetPanelStatus() || !EquipmentManager.Instance.isOpen) { - InventoryManager.Instance.OpenPanel(); + InventoryUIManager.Instance.OpenPanel(); EquipmentManager.Instance.OpenPanel(); } } public void ClosePlayerPanel() { - if(InventoryManager.Instance.isOpen || EquipmentManager.Instance.isOpen) + if(InventoryUIManager.Instance.GetPanelStatus() || EquipmentManager.Instance.isOpen) { - InventoryManager.Instance.ClosePanel(); + InventoryUIManager.Instance.ClosePanel(); EquipmentManager.Instance.ClosePanel(); } }