Skip to content

Commit 53193c4

Browse files
committed
feat(inventory window): categories now live display in the item table
You must have a field called _category to detect live changes in the window via dynamic binding. Not required if you don't want live binding support to serialized changes. close #21
1 parent 56e69c2 commit 53193c4

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

Assets/Examples/Shop/Scripts/Definitions/ItemDefinition.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
namespace CleverCrow.Fluid.Examples {
55
[ItemDefinitionDetails("Generic")]
66
public class ItemDefinition : ItemDefinitionFantasyBase {
7-
[SerializeField]
8-
string _displayName;
9-
107
[InventoryCategory]
118
[SerializeField]
129
int _category;
1310

14-
public override string DisplayName => _displayName;
1511
public override string Category => GetCategoryByIndex(_category);
1612
}
1713
}

Assets/com.fluid.elastic-inventory/Editor/Components/Organisms/ItemEntry/ItemEntry.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ Action<ItemDefinitionBase> deleteCallback
1515
title.bindingPath = "_displayName";
1616
title.Bind(new SerializedObject(definition));
1717

18+
var category = _container.Q<Label>("item-entry__category");
19+
category.text = definition.Category;
20+
category.bindingPath = "_category";
21+
category.Bind(new SerializedObject(definition));
22+
category.RegisterValueChangedCallback(
23+
evt => {
24+
category.text = definition.Category;
25+
}
26+
);
27+
1828
_container.Q<Button>("item-entry__edit").clicked += () => { Selection.activeObject = definition; };
1929

2030
_container.Q<Button>("item-entry__delete").clicked += () => {

Assets/com.fluid.elastic-inventory/Editor/Components/Organisms/ItemEntry/ItemEntry.uxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</ui:VisualElement>
99

1010
<ui:VisualElement class="item-entry__section">
11+
<ui:Label name="item-entry__category" text="Category" />
1112
<ui:Button name="item-entry__edit" text="Edit" />
1213
<ui:Button name="item-entry__delete" text="Delete" />
1314
</ui:VisualElement>

Assets/com.fluid.elastic-inventory/Runtime/Items/ItemDefinitionBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ public abstract class ItemDefinitionBase : ScriptableObject, IItemDefinition {
66
string _id;
77

88
public string Id => _id;
9+
10+
/// <summary>
11+
/// If you want live bindings to changes in the inventory database window you must have a field called _displayName for field serialization
12+
/// </summary>
913
public abstract string DisplayName { get; }
14+
15+
/// <summary>
16+
/// If you want live bindings to changes in the inventory database window you must have a field called _category for field serialization
17+
/// </summary>
1018
public abstract string Category { get; }
1119
public virtual bool Unique => false;
1220
public virtual IItemEntryDataResolver DataResolver { get; } = new ItemEntryDataResolver();

0 commit comments

Comments
 (0)