From b8255c36f3a3086301048330e5143a50731f7486 Mon Sep 17 00:00:00 2001 From: Papiertig0r Date: Wed, 31 Jan 2018 21:19:10 +0100 Subject: [PATCH] Work on inventory submenu, discarding items now possible --- Assets/Scenes/main.unity | 166 +++++++++++++++++- Assets/Scripts/Ingredients/IApplyable.cs | 3 + Assets/Scripts/Ingredients/IApplyable.cs.meta | 13 ++ Assets/Scripts/Inventory/Inventory.cs | 13 ++ Assets/Scripts/StateController.cs | 2 +- Assets/Scripts/Ui/InventorySubmenuUI.cs | 30 +++- Assets/Scripts/Ui/InventoryUI.cs | 11 +- 7 files changed, 226 insertions(+), 12 deletions(-) create mode 100644 Assets/Scripts/Ingredients/IApplyable.cs create mode 100644 Assets/Scripts/Ingredients/IApplyable.cs.meta diff --git a/Assets/Scenes/main.unity b/Assets/Scenes/main.unity index 113139f..11e6abe 100644 --- a/Assets/Scenes/main.unity +++ b/Assets/Scenes/main.unity @@ -399,6 +399,17 @@ RectTransform: m_PrefabParentObject: {fileID: 224944976523579358, guid: d8eb017c190b81948a2cead7d7eda6d4, type: 2} m_PrefabInternal: {fileID: 1681783885} +--- !u!114 &104673196 stripped +MonoBehaviour: + m_PrefabParentObject: {fileID: 114778692295473888, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + m_PrefabInternal: {fileID: 1965836701} + m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3} +--- !u!224 &104673199 stripped +RectTransform: + m_PrefabParentObject: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + m_PrefabInternal: {fileID: 1965836701} --- !u!1 &158280067 GameObject: m_ObjectHideFlags: 0 @@ -1054,7 +1065,7 @@ Prefab: - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, type: 2} propertyPath: m_LocalPosition.y - value: -30 + value: -45 objectReference: {fileID: 0} - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, type: 2} @@ -1084,7 +1095,7 @@ Prefab: - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, type: 2} propertyPath: m_RootOrder - value: 2 + value: 3 objectReference: {fileID: 0} - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, type: 2} @@ -2760,7 +2771,7 @@ Prefab: - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, type: 2} propertyPath: m_LocalPosition.y - value: -15 + value: -30 objectReference: {fileID: 0} - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, type: 2} @@ -3017,7 +3028,7 @@ Prefab: - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, type: 2} propertyPath: m_LocalPosition.y - value: -382 + value: -397 objectReference: {fileID: 0} - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, type: 2} @@ -3584,7 +3595,7 @@ Prefab: - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, type: 2} propertyPath: m_RootOrder - value: 3 + value: 4 objectReference: {fileID: 0} - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, type: 2} @@ -4605,6 +4616,7 @@ RectTransform: m_Children: - {fileID: 793695426} - {fileID: 1526863560} + - {fileID: 104673199} - {fileID: 1421883924} - {fileID: 2011620667} m_Father: {fileID: 290345897} @@ -4628,6 +4640,7 @@ MonoBehaviour: m_EditorClassIdentifier: consume: {fileID: 793695427} mix: {fileID: 1526863561} + apply: {fileID: 104673196} equip: {fileID: 1421883925} discard: {fileID: 2011620668} --- !u!114 &1181607015 @@ -7140,6 +7153,149 @@ Prefab: m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: d8eb017c190b81948a2cead7d7eda6d4, type: 2} m_IsPrefabParent: 0 +--- !u!1001 &1965836701 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 1181607013} + m_Modifications: + - target: {fileID: 114778692295473888, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_LocalPosition.x + value: -384 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_LocalPosition.y + value: -382 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_RootOrder + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_AnchoredPosition.x + value: -434 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_AnchoredPosition.y + value: -367 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_SizeDelta.x + value: 100 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_SizeDelta.y + value: 30 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_AnchorMin.x + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_AnchorMin.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_AnchorMax.x + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_AnchorMax.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_Pivot.x + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 224825329151565412, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_Pivot.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 1903597704318096, guid: 81ac80910f17a704c916302626e69dee, type: 2} + propertyPath: m_Name + value: Apply + objectReference: {fileID: 0} + - target: {fileID: 114864526605423014, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_Text + value: Apply + objectReference: {fileID: 0} + - target: {fileID: 114778692295473888, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 114778692295473888, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_CallState + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 114778692295473888, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target + value: + objectReference: {fileID: 1181607014} + - target: {fileID: 114778692295473888, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName + value: Apply + objectReference: {fileID: 0} + - target: {fileID: 114778692295473888, guid: 81ac80910f17a704c916302626e69dee, + type: 2} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName + value: UnityEngine.Object, UnityEngine + objectReference: {fileID: 0} + - target: {fileID: 1903597704318096, guid: 81ac80910f17a704c916302626e69dee, type: 2} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: 81ac80910f17a704c916302626e69dee, type: 2} + m_IsPrefabParent: 0 --- !u!1001 &1969874952 Prefab: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Ingredients/IApplyable.cs b/Assets/Scripts/Ingredients/IApplyable.cs new file mode 100644 index 0000000..8eb09c2 --- /dev/null +++ b/Assets/Scripts/Ingredients/IApplyable.cs @@ -0,0 +1,3 @@ +public interface IApplyable +{ +} diff --git a/Assets/Scripts/Ingredients/IApplyable.cs.meta b/Assets/Scripts/Ingredients/IApplyable.cs.meta new file mode 100644 index 0000000..2fd2d05 --- /dev/null +++ b/Assets/Scripts/Ingredients/IApplyable.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: a93b249f623d33741a3c911e02f38e55 +timeCreated: 1517429060 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Inventory/Inventory.cs b/Assets/Scripts/Inventory/Inventory.cs index 1e60d72..39f6a0a 100644 --- a/Assets/Scripts/Inventory/Inventory.cs +++ b/Assets/Scripts/Inventory/Inventory.cs @@ -4,6 +4,8 @@ public class Inventory : MonoBehaviour { + public static Inventory instance = null; + public int hotbarSize = 7; public int slotCount = 6; public int slotSize = 20; @@ -16,6 +18,16 @@ public class Inventory : MonoBehaviour private void Awake() { + if(instance == null) + { + instance = this; + } + + if(instance != this) + { + Destroy(this.gameObject); + } + InitItemSlots(); } @@ -90,6 +102,7 @@ public void RemoveItemFromSlot(ItemSlot slot) { DestroyObject(slot.item.gameObject); slot.item = null; + UIManager.inventorySubmenuUi.Leave(); } UpdateUi(); diff --git a/Assets/Scripts/StateController.cs b/Assets/Scripts/StateController.cs index e62dca3..b6a2708 100644 --- a/Assets/Scripts/StateController.cs +++ b/Assets/Scripts/StateController.cs @@ -24,7 +24,7 @@ private void Awake() private void Update() { - if (Input.GetButtonDown("Action")) + if (Input.GetButtonDown("Action") && state == State.WORLD) { Invoke(worldAction); } diff --git a/Assets/Scripts/Ui/InventorySubmenuUI.cs b/Assets/Scripts/Ui/InventorySubmenuUI.cs index a6a37e9..5531aa0 100644 --- a/Assets/Scripts/Ui/InventorySubmenuUI.cs +++ b/Assets/Scripts/Ui/InventorySubmenuUI.cs @@ -2,11 +2,13 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; +using UnityEngine.EventSystems; public class InventorySubmenuUI : MonoBehaviour { public Button consume; public Button mix; + public Button apply; public Button equip; public Button discard; @@ -19,6 +21,7 @@ public void SetUp(Item item) { selectedButton = 0; activeButtons.Clear(); + IConsumable consumable = item.GetComponent(); if(consumable != null) { @@ -33,6 +36,13 @@ public void SetUp(Item item) mix.gameObject.SetActive(true); } + IApplyable applyable = item.GetComponent(); + if(applyable != null) + { + activeButtons.Add(apply); + apply.gameObject.SetActive(true); + } + IEquippable equipment = item.GetComponent(); if(equipment != null) { @@ -40,17 +50,25 @@ public void SetUp(Item item) equip.gameObject.SetActive(true); } + gameObject.SetActive(true); activeButtons.Add(discard); activeButtons[selectedButton].Select(); + + StateController.Transition(State.INVENTORY_SUBMENU); } public void Leave() { item = null; + + EventSystem.current.SetSelectedGameObject(null); + consume.gameObject.SetActive(false); mix.gameObject.SetActive(false); equip.gameObject.SetActive(false); + gameObject.SetActive(false); + StateController.Transition(State.INVENTORY); } @@ -80,7 +98,7 @@ private void Update() activeButtons[selectedButton].onClick.Invoke(); } - if(Input.GetButtonDown("Dodge/Abort")) + if(Input.GetButtonDown("Dodge/Abort") || Input.GetButtonDown("Inventory")) { Leave(); } @@ -104,6 +122,12 @@ public void Mix() Debug.Log("Clicked Mix"); } + public void Apply() + { + // Apply item (e.g. poison to a weapon) + Debug.Log("Clicked Apply"); + } + public void Equip() { //Equip item @@ -112,7 +136,7 @@ public void Equip() public void Discard() { - //Discard item - Debug.Log("Clicked discard"); + //! \todo detect long presses for stackwise discarding + Inventory.instance.RemoveItem(Inventory.instance.inventoryUi.GetSelectedSlot()); } } diff --git a/Assets/Scripts/Ui/InventoryUI.cs b/Assets/Scripts/Ui/InventoryUI.cs index 9986fe0..d44d278 100644 --- a/Assets/Scripts/Ui/InventoryUI.cs +++ b/Assets/Scripts/Ui/InventoryUI.cs @@ -5,7 +5,6 @@ public class InventoryUI : MonoBehaviour { - public GameObject inventorySlotSelector; public GameObject inventorySelector; public HotbarUI hotbar; @@ -73,9 +72,10 @@ private void Update() released = true; } - if (Input.GetButtonDown("Action")) + Item item = inventory[selectedInventorySlot].item; + if (Input.GetButtonDown("Action") && item != null) { - //Open inventory submenu + UIManager.inventorySubmenuUi.SetUp(item); } } @@ -166,4 +166,9 @@ private void HandleExtendedInfoUi(IShowable showable) showable.ShowExtendedInfo(); } } + + public int GetSelectedSlot() + { + return selectedInventorySlot; + } }