Skip to content

Commit

Permalink
feat(inventory window): categories now live display in the item table
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ashblue committed Jan 11, 2025
1 parent 56e69c2 commit 53193c4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 0 additions & 4 deletions Assets/Examples/Shop/Scripts/Definitions/ItemDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
namespace CleverCrow.Fluid.Examples {
[ItemDefinitionDetails("Generic")]
public class ItemDefinition : ItemDefinitionFantasyBase {
[SerializeField]
string _displayName;

[InventoryCategory]
[SerializeField]
int _category;

public override string DisplayName => _displayName;
public override string Category => GetCategoryByIndex(_category);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ Action<ItemDefinitionBase> deleteCallback
title.bindingPath = "_displayName";
title.Bind(new SerializedObject(definition));

var category = _container.Q<Label>("item-entry__category");
category.text = definition.Category;
category.bindingPath = "_category";
category.Bind(new SerializedObject(definition));
category.RegisterValueChangedCallback(
evt => {
category.text = definition.Category;
}
);

_container.Q<Button>("item-entry__edit").clicked += () => { Selection.activeObject = definition; };

_container.Q<Button>("item-entry__delete").clicked += () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</ui:VisualElement>

<ui:VisualElement class="item-entry__section">
<ui:Label name="item-entry__category" text="Category" />
<ui:Button name="item-entry__edit" text="Edit" />
<ui:Button name="item-entry__delete" text="Delete" />
</ui:VisualElement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ public abstract class ItemDefinitionBase : ScriptableObject, IItemDefinition {
string _id;

public string Id => _id;

/// <summary>
/// If you want live bindings to changes in the inventory database window you must have a field called _displayName for field serialization
/// </summary>
public abstract string DisplayName { get; }

/// <summary>
/// If you want live bindings to changes in the inventory database window you must have a field called _category for field serialization
/// </summary>
public abstract string Category { get; }
public virtual bool Unique => false;
public virtual IItemEntryDataResolver DataResolver { get; } = new ItemEntryDataResolver();
Expand Down

0 comments on commit 53193c4

Please sign in to comment.