CORE dashboard + a lot of changes
This commit is contained in:
@@ -17,8 +17,7 @@ namespace RPGCoreCommon.Helpers.Editor.Drawers
|
||||
|
||||
private SerializedProperty _property;
|
||||
private SerializedProperty _tempKeyProperty;
|
||||
private SerializedProperty _keysProperty;
|
||||
private SerializedProperty _valuesProperty;
|
||||
private SerializedProperty _pairsProperty;
|
||||
|
||||
private SerializableDictionaryAttribute _sdAttribute;
|
||||
private Type _keyType;
|
||||
@@ -29,12 +28,8 @@ namespace RPGCoreCommon.Helpers.Editor.Drawers
|
||||
_property = property;
|
||||
_sdAttribute = fieldInfo.GetCustomAttribute<SerializableDictionaryAttribute>() ?? new SerializableDictionaryAttribute();
|
||||
_tempKeyProperty = property.FindPropertyRelative("_tempKey");
|
||||
_keysProperty = property.FindPropertyRelative("_keys");
|
||||
_valuesProperty = property.FindPropertyRelative("_values");
|
||||
_pairsProperty = property.FindPropertyRelative("_pairs");
|
||||
|
||||
if (_keysProperty == null || _valuesProperty == null)
|
||||
return new HelpBox("Keys and Values in SerializableDictionary must be serializable!", HelpBoxMessageType.Error);
|
||||
|
||||
var genericTypes = property.boxedValue.GetType().FindGenericDefinitionType(typeof(SerializableDictionary<,>)).GetGenericArguments();
|
||||
_keyType = genericTypes[0];
|
||||
_valueType = genericTypes[1];
|
||||
@@ -52,12 +47,11 @@ namespace RPGCoreCommon.Helpers.Editor.Drawers
|
||||
}
|
||||
|
||||
var list = root.Q<ListView>("sd-list");
|
||||
list.BindProperty(_valuesProperty);
|
||||
list.BindProperty(_pairsProperty);
|
||||
list.makeItem = CreateRow;
|
||||
list.bindItem = BindRow;
|
||||
list.onAdd = OnAdd;
|
||||
list.onRemove = OnRemove;
|
||||
list.itemIndexChanged += OnSwap;
|
||||
|
||||
if (_sdAttribute is not null)
|
||||
{
|
||||
@@ -90,12 +84,6 @@ namespace RPGCoreCommon.Helpers.Editor.Drawers
|
||||
return root;
|
||||
}
|
||||
|
||||
private void OnSwap(int index1, int index2)
|
||||
{
|
||||
_keysProperty.MoveArrayElement(index1, index2);
|
||||
_property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
private void OnAdd(BaseListView list)
|
||||
{
|
||||
var tempKey = _tempKeyProperty.boxedValue;
|
||||
@@ -108,9 +96,10 @@ namespace RPGCoreCommon.Helpers.Editor.Drawers
|
||||
return;
|
||||
}
|
||||
|
||||
var keyExists = Enumerable.Range(0, _keysProperty.arraySize)
|
||||
.Select(i => _keysProperty.GetArrayElementAtIndex(i))
|
||||
.Any(prop => prop.boxedValue.Equals(tempKey));
|
||||
var keyExists = Enumerable.Range(0, _pairsProperty.arraySize)
|
||||
.Select(i => _pairsProperty.GetArrayElementAtIndex(i))
|
||||
.Select(prop => prop.FindPropertyRelative("_key"))
|
||||
.Any(keyProp => keyProp.boxedValue.Equals(tempKey));
|
||||
|
||||
if (keyExists)
|
||||
{
|
||||
@@ -124,13 +113,8 @@ namespace RPGCoreCommon.Helpers.Editor.Drawers
|
||||
_tempKeyProperty.boxedValue = _keyType.IsValueType ? Activator.CreateInstance(_keyType) : null;
|
||||
|
||||
// New Key
|
||||
_keysProperty.arraySize++;
|
||||
_keysProperty.GetArrayElementAtIndex(_keysProperty.arraySize - 1).boxedValue = tempKey;
|
||||
|
||||
// New Value
|
||||
_valuesProperty.arraySize++;
|
||||
_valuesProperty.GetArrayElementAtIndex(_valuesProperty.arraySize - 1).boxedValue =
|
||||
_valueType.IsValueType ? Activator.CreateInstance(_valueType) : null;
|
||||
_pairsProperty.arraySize++;
|
||||
_pairsProperty.GetArrayElementAtIndex(_pairsProperty.arraySize - 1).FindPropertyRelative("_key").boxedValue = tempKey;
|
||||
|
||||
// Update list and property
|
||||
_property.serializedObject.ApplyModifiedProperties();
|
||||
@@ -143,11 +127,7 @@ namespace RPGCoreCommon.Helpers.Editor.Drawers
|
||||
var ids = list.selectedIds.SortDescending().ToList();
|
||||
if (ids.Count < 0) return;
|
||||
|
||||
ids.ForEach(i =>
|
||||
{
|
||||
_keysProperty.DeleteArrayElementAtIndex(i);
|
||||
_valuesProperty.DeleteArrayElementAtIndex(i);
|
||||
});
|
||||
ids.ForEach(i => _pairsProperty.DeleteArrayElementAtIndex(i));
|
||||
|
||||
// Update list and property
|
||||
_property.serializedObject.ApplyModifiedProperties();
|
||||
@@ -179,9 +159,9 @@ namespace RPGCoreCommon.Helpers.Editor.Drawers
|
||||
|
||||
private void BindRow(VisualElement row, int i)
|
||||
{
|
||||
if (i >= _keysProperty.arraySize) return;
|
||||
row.Q<PropertyField>(className: "row-left").BindProperty(_keysProperty.GetArrayElementAtIndex(i));
|
||||
row.Q<PropertyField>(className: "row-right").BindProperty(_valuesProperty.GetArrayElementAtIndex(i));
|
||||
if (i >= _pairsProperty.arraySize) return;
|
||||
row.Q<PropertyField>(className: "row-left").BindProperty(_pairsProperty.GetArrayElementAtIndex(i).FindPropertyRelative("_key"));
|
||||
row.Q<PropertyField>(className: "row-right").BindProperty(_pairsProperty.GetArrayElementAtIndex(i).FindPropertyRelative("_value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace RPGCoreCommon.Helpers.Editor.Drawers
|
||||
|
||||
private void UpdateTypeField(SerializedProperty property, FakeObjectField field)
|
||||
{
|
||||
var typeName = ((SerializableType)property.boxedValue).type?.Name ?? NoTypeSelected;
|
||||
var typeName = ((SerializableType)property.boxedValue)?.type?.Name ?? NoTypeSelected;
|
||||
field.Set(typeName, EditorGUIUtility.FindTexture("cs Script Icon"));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using RPGCoreCommon.Helpers.PropertyAttributeDrawers;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RPGCoreCommon.Helpers.Editor.PropertyAttributeDrawers
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(ObjectPickerAttribute))]
|
||||
public class ObjectPickerDrawer : PropertyDrawer
|
||||
{
|
||||
public override VisualElement CreatePropertyGUI(SerializedProperty property)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d82bc4b9420a4ea58ea10c04b9c2307b
|
||||
timeCreated: 1781877687
|
||||
@@ -53,8 +53,18 @@ namespace RPGCoreCommon.Helpers.Editor.UIElements
|
||||
// ENTER - select first visible
|
||||
_root.RegisterCallback<KeyDownEvent>(ev =>
|
||||
{
|
||||
if (ev.keyCode == KeyCode.Escape) Close();
|
||||
if (ev.keyCode == KeyCode.Return) _scrollView.Query<Button>().Visible().First().Click();
|
||||
switch (ev.keyCode)
|
||||
{
|
||||
case KeyCode.Escape:
|
||||
Close();
|
||||
break;
|
||||
case KeyCode.Return:
|
||||
SelectFirst();
|
||||
break;
|
||||
default:
|
||||
ApplyFilter();
|
||||
break;
|
||||
}
|
||||
}, TrickleDown.TrickleDown);
|
||||
|
||||
return _root;
|
||||
@@ -69,5 +79,16 @@ namespace RPGCoreCommon.Helpers.Editor.UIElements
|
||||
{
|
||||
editorWindow.Close();
|
||||
}
|
||||
|
||||
private void SelectFirst()
|
||||
{
|
||||
_scrollView.Query<Button>().Visible().First().Click();
|
||||
}
|
||||
|
||||
private void ApplyFilter()
|
||||
{
|
||||
_scrollView.Query<Button>()
|
||||
.ForEach(b => b.style.display = b.text.Contains(_searchField.value) ? DisplayStyle.Flex : DisplayStyle.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,26 +8,29 @@ namespace RPGCoreCommon.Helpers.CustomTypes
|
||||
[Serializable]
|
||||
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver
|
||||
{
|
||||
[SerializeField] internal TKey _tempKey;
|
||||
[Serializable]
|
||||
internal class Pair
|
||||
{
|
||||
[SerializeReference] internal TKey _key;
|
||||
[SerializeReference] internal TValue _value;
|
||||
}
|
||||
|
||||
[SerializeReference] internal TKey _tempKey;
|
||||
[SerializeField] internal List<Pair> _pairs;
|
||||
|
||||
[SerializeField] internal List<TKey> _keys = new();
|
||||
[SerializeReference] internal List<TValue> _values = new();
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
_keys = Keys.ToList();
|
||||
_values = Values.ToList();
|
||||
_pairs = this.Select(p => new Pair { _key = p.Key, _value = p.Value }).ToList();
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
Clear();
|
||||
for (var i = 0; i < _keys.Count; i++)
|
||||
{
|
||||
if (_keys[i] != null) Add(_keys[i], _values[i]);
|
||||
}
|
||||
|
||||
_keys.Clear();
|
||||
_values.Clear();
|
||||
_pairs.ForEach(p => TryAdd(p._key, p._value));
|
||||
_pairs.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,10 @@ using UnityEngine;
|
||||
namespace RPGCoreCommon.Helpers.CustomTypes
|
||||
{
|
||||
[Serializable]
|
||||
public class SerializableType : ISerializationCallbackReceiver, ICloneable
|
||||
public class SerializableType : ISerializationCallbackReceiver, ICloneable, IEquatable<SerializableType>
|
||||
{
|
||||
public Type type { get; internal set; }
|
||||
[SerializeField] internal string assemblyQualifiedName;
|
||||
public Type type { get; private set; }
|
||||
[SerializeField] private string assemblyQualifiedName;
|
||||
|
||||
public SerializableType(Type type)
|
||||
{
|
||||
@@ -32,5 +32,9 @@ namespace RPGCoreCommon.Helpers.CustomTypes
|
||||
public static implicit operator Type(SerializableType serializableType) => serializableType.type;
|
||||
|
||||
public static implicit operator SerializableType(Type type) => new(type);
|
||||
|
||||
public override int GetHashCode() => type?.GetHashCode() ?? 0;
|
||||
|
||||
public bool Equals(SerializableType other) => type == other?.type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RPGCoreCommon.Helpers.PropertyAttributeDrawers
|
||||
{
|
||||
public class ObjectPickerAttribute : PropertyAttribute
|
||||
{
|
||||
// TODO: zrobić to + drawer ObjectPickerDrawer
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37be47854eb74f7a8558e9ef3de059b3
|
||||
timeCreated: 1781877714
|
||||
+1
-1
@@ -4,6 +4,6 @@ namespace RPGCoreCommon.Helpers.PropertyAttributeDrawers
|
||||
{
|
||||
public class SerializeReferenceHelperAttribute : PropertyAttribute
|
||||
{
|
||||
|
||||
// TODO: zrobić to + drawer SerializeReferenceHelperDrawer
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class ExampleCustomSettingsSO : CustomSettingsSO
|
||||
private Dictionary<string, Type> _settingsTypeMap;
|
||||
private string _currentKey;
|
||||
|
||||
[MenuItem("TheVVaS/RPGCore/Settings Editor")]
|
||||
[MenuItem("TheVVaS/Settings Editor")]
|
||||
public static void ShowSettingsEditor()
|
||||
{
|
||||
var window = GetWindow<SettingsEditorWindow>();
|
||||
|
||||
Reference in New Issue
Block a user