Skip to content

Commit 9904fbd

Browse files
authored
Merge pull request #30 from ashblue/feature/fix-add-without-display-name
fix(item creation): no longer crashes when `_displayName` field is mi…
0 parents  commit 9904fbd

File tree

127 files changed

+3244
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+3244
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replaced when project is built from commit logs via Semantic Release.

CHANGELOG.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Documentation beyond README.md goes here.

Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Components.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Components/Atoms.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Collections.Generic;
2+
using UnityEngine.UIElements;
3+
4+
namespace CleverCrow.Fluid.ElasticInventory.Editors {
5+
public class DropdownAdd<T> : ComponentBase {
6+
readonly DropdownField _dropdown;
7+
readonly List<KeyValuePair<string, T>> _choices;
8+
readonly string _addText;
9+
readonly VisualElement _containerParent;
10+
readonly bool _resetOnInteract;
11+
12+
// @TODO Make addText optional so the categories will update on click
13+
public DropdownAdd (
14+
VisualElement containerParent,
15+
string addText,
16+
List<KeyValuePair<string, T>> choices,
17+
bool resetOnInteract = true
18+
) : base(containerParent) {
19+
_containerParent = containerParent;
20+
_choices = choices;
21+
_addText = addText;
22+
_resetOnInteract = resetOnInteract;
23+
24+
var keys = choices.ConvertAll(choice => choice.Key);
25+
keys.Insert(0, addText);
26+
27+
_dropdown = CreateDropdownField(keys);
28+
}
29+
30+
public void BindClick (System.Action<T> callback) {
31+
_dropdown.RegisterCallback<ChangeEvent<string>>(e => {
32+
if (_resetOnInteract) _dropdown.value = _addText;
33+
if (e.newValue == _addText) {
34+
callback(default);
35+
return;
36+
}
37+
38+
var choice = _choices.Find(c => c.Key == e.newValue);
39+
callback(choice.Value);
40+
});
41+
}
42+
43+
private DropdownField CreateDropdownField (List<string> keys) {
44+
var dropdown = new DropdownField() {
45+
choices = keys,
46+
value = _addText
47+
};
48+
49+
_containerParent.Add(dropdown);
50+
51+
return dropdown;
52+
}
53+
54+
public void SetValue (int indexOf) {
55+
if (indexOf < 0 || indexOf >= _choices.Count) return;
56+
_dropdown.value = _choices[indexOf].Key;
57+
}
58+
}
59+
}

Editor/Components/Atoms/DropdownAdd.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Components/Molecules.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Components/Molecules/SearchInput.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using UnityEngine.UIElements;
2+
3+
namespace CleverCrow.Fluid.ElasticInventory.Editors {
4+
public class SearchInput : ComponentBase {
5+
public SearchInput (VisualElement container) : base(container) {
6+
}
7+
8+
public void BindChange (System.Action<string> callback) {
9+
_container
10+
.Q<TextField>("search-input__text")
11+
.RegisterValueChangedCallback(evt => {
12+
callback(evt.newValue);
13+
});
14+
}
15+
}
16+
}

Editor/Components/Molecules/SearchInput/SearchInput.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui:UXML xmlns:ui="UnityEngine.UIElements">
3+
<ui:VisualElement name="search-input" class="search-input" style="flex-direction: row;">
4+
<ui:Label text="Search" style="flex-grow: 0; color: grey;" name="placeholderLabel" />
5+
<ui:TextField class="search-input__text" name="search-input__text" style="width: 100px" />
6+
</ui:VisualElement>
7+
</ui:UXML>
8+
9+

Editor/Components/Molecules/SearchInput/SearchInput.uxml.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Components/Organisms.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Components/Organisms/ItemEntry.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using UnityEditor;
3+
using UnityEditor.UIElements;
4+
using UnityEngine.UIElements;
5+
6+
namespace CleverCrow.Fluid.ElasticInventory.Editors {
7+
public class ItemEntry : ComponentBase {
8+
public ItemEntry (
9+
VisualElement container,
10+
ItemDefinitionBase definition,
11+
Action<ItemDefinitionBase> deleteCallback
12+
) : base(container) {
13+
var title = _container.Q<Label>("item-entry__name");
14+
title.text = definition.DisplayName;
15+
title.bindingPath = "_displayName";
16+
title.Bind(new SerializedObject(definition));
17+
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+
28+
_container.Q<Button>("item-entry__edit").clicked += () => { Selection.activeObject = definition; };
29+
30+
_container.Q<Button>("item-entry__delete").clicked += () => {
31+
var confirm = EditorUtility.DisplayDialog(
32+
"Delete Item Definition",
33+
$"Are you sure you want to delete {definition.DisplayName}?",
34+
"Delete",
35+
"Cancel"
36+
);
37+
if (!confirm) return;
38+
39+
_container.parent.Remove(_container);
40+
deleteCallback(definition);
41+
};
42+
}
43+
}
44+
}

Editor/Components/Organisms/ItemEntry/ItemEntry.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.item-entry {
2+
display: flex;
3+
flex-direction: row;
4+
align-items: center;
5+
justify-content: space-between;
6+
padding: 5px;
7+
border-bottom-color: #000;
8+
border-bottom-width: 1px;
9+
}
10+
11+
.item-entry__section {
12+
flex-direction: row;
13+
align-items: center;
14+
}
15+
16+
.item-entry__image {
17+
width: 20px;
18+
height: 20px;
19+
}

Editor/Components/Organisms/ItemEntry/ItemEntry.uss.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui:UXML xmlns:ui="UnityEngine.UIElements">
3+
<Style src="./ItemEntry.uss" />
4+
5+
<ui:VisualElement name="item-entry" class="item-entry">
6+
<ui:VisualElement class="item-entry__section">
7+
<ui:Label name="item-entry__name" text="Item Name" />
8+
</ui:VisualElement>
9+
10+
<ui:VisualElement class="item-entry__section">
11+
<ui:Label name="item-entry__category" text="Category" />
12+
<ui:Button name="item-entry__edit" text="Edit" />
13+
<ui:Button name="item-entry__delete" text="Delete" />
14+
</ui:VisualElement>
15+
</ui:VisualElement>
16+
</ui:UXML>

Editor/Components/Organisms/ItemEntry/ItemEntry.uxml.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Components/Pages.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)