Skip to content

Commit

Permalink
Work on inventory submenu, discarding items now possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Papiertig0r committed Jan 31, 2018
1 parent 6e4bd9d commit b8255c3
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 12 deletions.
166 changes: 161 additions & 5 deletions Assets/Scenes/main.unity
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -4605,6 +4616,7 @@ RectTransform:
m_Children:
- {fileID: 793695426}
- {fileID: 1526863560}
- {fileID: 104673199}
- {fileID: 1421883924}
- {fileID: 2011620667}
m_Father: {fileID: 290345897}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Ingredients/IApplyable.cs
@@ -0,0 +1,3 @@
public interface IApplyable
{
}
13 changes: 13 additions & 0 deletions Assets/Scripts/Ingredients/IApplyable.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Assets/Scripts/Inventory/Inventory.cs
Expand Up @@ -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;
Expand All @@ -16,6 +18,16 @@ public class Inventory : MonoBehaviour

private void Awake()
{
if(instance == null)
{
instance = this;
}

if(instance != this)
{
Destroy(this.gameObject);
}

InitItemSlots();
}

Expand Down Expand Up @@ -90,6 +102,7 @@ public void RemoveItemFromSlot(ItemSlot slot)
{
DestroyObject(slot.item.gameObject);
slot.item = null;
UIManager.inventorySubmenuUi.Leave();
}

UpdateUi();
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/StateController.cs
Expand Up @@ -24,7 +24,7 @@ private void Awake()

private void Update()
{
if (Input.GetButtonDown("Action"))
if (Input.GetButtonDown("Action") && state == State.WORLD)
{
Invoke(worldAction);
}
Expand Down
30 changes: 27 additions & 3 deletions Assets/Scripts/Ui/InventorySubmenuUI.cs
Expand Up @@ -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;

Expand All @@ -19,6 +21,7 @@ public void SetUp(Item item)
{
selectedButton = 0;
activeButtons.Clear();

IConsumable consumable = item.GetComponent<IConsumable>();
if(consumable != null)
{
Expand All @@ -33,24 +36,39 @@ public void SetUp(Item item)
mix.gameObject.SetActive(true);
}

IApplyable applyable = item.GetComponent<IApplyable>();
if(applyable != null)
{
activeButtons.Add(apply);
apply.gameObject.SetActive(true);
}

IEquippable equipment = item.GetComponent<IEquippable>();
if(equipment != null)
{
activeButtons.Add(equip);
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);
}

Expand Down Expand Up @@ -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();
}
Expand All @@ -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
Expand All @@ -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());
}
}

0 comments on commit b8255c3

Please sign in to comment.