using System; using System.Linq; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; using Cursor = UnityEngine.Cursor; namespace RPGCoreCommon.DropTable.Editor { internal class DropTableGroupRowElement : VisualElement { // Property data private SerializedProperty _property; private SerializedProperty _propertyInlineGroup; private DropTableGroupRow value => (DropTableGroupRow)_property.boxedValue; // Elements private readonly VisualElement _percentBackground; private readonly Label _percentLabel; private readonly VisualElement _rightElement; private readonly FloatField _chanceField; private readonly IntegerField _countField; private readonly ObjectField _itemField; private readonly ObjectField _groupReferenceField; private readonly DropTableGroupElement _groupInline; private readonly Label _newInlineLabel; private readonly VisualElement _dropHere; internal DropTableGroupRowElement() { DropTableDrawer.rowVisualTreeAsset.CloneTree(this); this.AddManipulator(new ContextualMenuManipulator(null)); RegisterCallback(ev => { ev.StopImmediatePropagation(); ev.menu.InsertAction(0, "Reset row", _ => { SetEditingMode(EditTypeEnum.None); }); ev.menu.InsertAction(1, "Remove row", _ => { var arrayPath = string.Join(".", _property.propertyPath.Split(".").SkipLast(2)); var arrayProperty = _property.serializedObject.FindProperty(arrayPath); var i = int.Parse(_property.propertyPath[_property.propertyPath.LastIndexOf('[')..].Trim('[', ']')); arrayProperty.DeleteArrayElementAtIndex(i); _property.serializedObject.ApplyModifiedProperties(); }); ev.menu.InsertSeparator(null, 2); }); // PERCENTAGE _percentBackground = this.Q("dt-percent-background"); _percentLabel = this.Q