Skip to content

Commit

Permalink
Merge pull request #14 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.5
  • Loading branch information
uurha committed Jan 5, 2025
1 parent 44a4547 commit 826784f
Show file tree
Hide file tree
Showing 46 changed files with 113 additions and 319 deletions.
1 change: 1 addition & 0 deletions Editor/Drawers/DrawInspector/DrawInspectorHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Better.Attributes.Runtime.DrawInspector;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Drawers.Handlers;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.EditorAddons.Utility;
Expand Down
119 changes: 79 additions & 40 deletions Editor/Drawers/EditorButton/EditorButtonDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Better.Attributes.EditorAddons.Drawers.Parameters;
using Better.Commons.EditorAddons.Drawers.Proxies;
using Better.Attributes.EditorAddons.Utilities;
using Better.Attributes.Runtime;
using Better.Commons.EditorAddons.Enums;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.EditorAddons.Utility;
using Better.Commons.Runtime.Extensions;
using Better.Commons.Runtime.UIElements;
using Better.Commons.Runtime.Utility;
using UnityEditor;
using UnityEngine.UIElements;
Expand Down Expand Up @@ -82,7 +79,7 @@ private VisualElement CreateFromMethodInfo(MethodInfo methodInfo, EditorButtonAt
var parameters = methodInfo.GetParameters();
foreach (var parameterInfo in parameters)
{
if (!ParameterFieldProvider.IsSupported(parameterInfo.ParameterType) || parameterInfo.IsOut)
if (!ProxyProvider.IsSupported(parameterInfo.ParameterType) || parameterInfo.IsOut)
{
return CreateNotSupportedHelpBox(methodInfo, parameterInfo);
}
Expand Down Expand Up @@ -112,59 +109,101 @@ private VisualElement CreateButton(MethodInfo methodInfo, EditorButtonAttribute
{
var prettyMemberName = methodInfo.PrettyMemberName();

var verticalGroup = VisualElementUtility.CreateVerticalGroup();
verticalGroup.name = $"{prettyMemberName}__{nameof(verticalGroup)}";
verticalGroup.style
.FlexGrow(StyleDefinition.OneStyleFloat)
.FlexBasis(0.5f);

var horizontalGroup = VisualElementUtility.CreateHorizontalGroup();
horizontalGroup.name = $"{prettyMemberName}__{nameof(horizontalGroup)}";
horizontalGroup.style
.FlexGrow(StyleDefinition.OneStyleFloat)
.MaxHeight(StyleDefinition.ButtonHeight);

verticalGroup.Add(horizontalGroup);

var button = new Button
{
text = attribute.GetDisplayName(prettyMemberName),
name = prettyMemberName
};

var parameters = methodInfo.GetParameters();
var datas = parameters.Select(info => new Parameter(info)).ToArray();
button.style.FlexGrow(StyleDefinition.OneStyleFloat);

var parametersElement = new ParametersElementDrawer(datas);
verticalGroup.Add(parametersElement);
var parameters = methodInfo.GetParameters();

if (!datas.IsNullOrEmpty())
if (parameters.IsNullOrEmpty())
{
var toggle = new ToggleButton(value => parametersElement.style.SetVisible(value));
toggle.AddIcon(IconType.GrayDropdown);
toggle.style.Padding(1f);

toggle.text = string.Empty;
horizontalGroup.Add(toggle);
button.RegisterCallback<ClickEvent, MethodInfo>(OnClick, methodInfo);
return button;
}
else

var datas = parameters.Select(info => new ParameterProxy(info));

var foldout = SetupFoldout(prettyMemberName);

var views = CreateViews(datas, foldout);

SetupFoldoutToggle(foldout, button);

var group = views.Select(view => view.style).AsGroup();

foldout.RegisterCallback<ChangeEvent<bool>, IStyle>(OnFoldout, group);
button.RegisterCallback<ClickEvent, MethodInfo, List<ProxyView<object>>>(OnClick, methodInfo, views);

return foldout;
}

private Foldout SetupFoldout(string prettyMemberName)
{
var foldout = new Foldout();
foldout.name = $"{prettyMemberName}__{nameof(foldout)}";
foldout.style
.FlexGrow(StyleDefinition.OneStyleFloat)
.FlexBasis(0.5f)
.FlexDirection(FlexDirection.Column);

foldout.contentContainer.AddToClassList(HelpBox.ussClassName);
foldout.contentContainer.style
.FlexDirection(FlexDirection.Column)
.AlignItems(Align.Stretch);
return foldout;
}

private List<ProxyView<object>> CreateViews(IEnumerable<ParameterProxy> datas, Foldout foldout)
{
var views = new List<ProxyView<object>>();
foreach (var parameterProxy in datas)
{
parametersElement.style.SetVisible(false);
var parametersElement = new ProxyView<ParameterProxy, object>(parameterProxy);
parametersElement.style.FlexGrow(StyleDefinition.OneStyleFloat);
views.Add(parametersElement);
foldout.contentContainer.Add(parametersElement);
}

horizontalGroup.Add(button);
button.style.FlexGrow(StyleDefinition.OneStyleFloat);
button.RegisterCallback<ClickEvent, MethodInfo, ParametersElementDrawer>(OnClick, methodInfo, parametersElement);
return verticalGroup;
return views;
}

private void SetupFoldoutToggle(Foldout foldout, Button button)
{
var foldoutToggle = foldout.Q<Toggle>();
foldoutToggle.Add(button);
foldoutToggle.style.Margin(StyleDefinition.ZeroStyleLength);

var toggleCheckmark = foldout.Q<VisualElement>(className: Toggle.inputUssClassName);
toggleCheckmark.AddToClassList(Button.ussClassName);
toggleCheckmark.style.FlexGrow(StyleDefinition.ZeroStyleFloat);
toggleCheckmark.Children().Select(child => child.style).AsGroup().Margin(StyleDefinition.OneStyleLength);
}

private void OnFoldout(ChangeEvent<bool> evt, IStyle styleGroup)
{
var value = evt.newValue;
styleGroup.SetVisible(value);
}

private void OnClick(ClickEvent clickEvent, (MethodInfo methodInfo, List<ProxyView<object>> views) data)
{
_serializedObject.Update();

var parameters = data.views.Select(view => view.value).ToArray();
data.methodInfo.Invoke(_target, parameters);
EditorUtility.SetDirty(_serializedObject.targetObject);
_serializedObject.ApplyModifiedProperties();
}

private void OnClick(ClickEvent clickEvent, (MethodInfo methodInfo, ParametersElementDrawer parameters) data)
private void OnClick(ClickEvent clickEvent, MethodInfo methodInfo)
{
_serializedObject.Update();
var parameters = data.parameters;

//TODO: Validate parameters count and types
data.methodInfo.Invoke(_target, parameters.GetData());
methodInfo.Invoke(_target, null);
EditorUtility.SetDirty(_serializedObject.targetObject);
_serializedObject.ApplyModifiedProperties();
}
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Gizmo/LocalHandlers/BoundsLocalHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Better.Attributes.Runtime.Gizmo;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.Runtime.Utility;
using UnityEditor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Better.Attributes.Runtime.Gizmo;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.Runtime.Extensions;
using UnityEditor;
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Gizmo/LocalHandlers/Vector2LocalHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Better.Attributes.Runtime.Gizmo;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.Runtime.Extensions;
using UnityEditor;
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Gizmo/LocalHandlers/Vector3LocalHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Better.Attributes.Runtime.Gizmo;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.Runtime.Extensions;
using UnityEditor;
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Gizmo/WorldHandlers/BoundsHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Better.Attributes.Runtime.Gizmo;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.Runtime.Extensions;
using UnityEditor;
using UnityEngine;
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Gizmo/WorldHandlers/QuaternionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Better.Attributes.Runtime.Gizmo;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.Runtime.Extensions;
using UnityEditor;
using UnityEngine;
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Gizmo/WorldHandlers/Vector2Handler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Better.Attributes.Runtime.Gizmo;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.Runtime.Extensions;
using UnityEditor;
using UnityEngine;
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Gizmo/WorldHandlers/Vector3Handler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Better.Attributes.Runtime.Gizmo;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.Runtime.Extensions;
using UnityEditor;
using UnityEngine;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Better.Attributes.Runtime.Manipulation;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using UnityEditor;

namespace Better.Attributes.EditorAddons.Drawers.Manipulation
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Manipulation/Handlers/InPlayModeHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Better.Attributes.Runtime.Manipulation;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using UnityEditor;

namespace Better.Attributes.EditorAddons.Drawers.Manipulation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Reflection;
using Better.Attributes.Runtime.Manipulation;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.Runtime.Extensions;
using Better.Internal.Core.Runtime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Better.Attributes.Runtime.Manipulation;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;

namespace Better.Attributes.EditorAddons.Drawers.Manipulation
{
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Misc/Handlers/CustomToolTipHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Better.Attributes.Runtime.Misc;
using Better.Attributes.Runtime.Utilities;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Helpers;

namespace Better.Attributes.EditorAddons.Drawers.Misc
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Misc/Handlers/DetailedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Better.Attributes.Runtime.Misc;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.Container;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.EditorAddons.Helpers;
using Better.Commons.EditorAddons.Utility;
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Misc/Handlers/EnumButtonsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Reflection;
using Better.Attributes.Runtime.Misc;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.EditorAddons.Utility;
using Better.Commons.Runtime.Extensions;
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Misc/Handlers/HelpBoxHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Better.Attributes.Runtime.Misc;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.EditorAddons.Utility;
using UnityEngine.UIElements;
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Misc/Handlers/HideLabelHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Better.Attributes.Runtime.Misc;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.Container;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.EditorAddons.Helpers;
using Better.Commons.Runtime.Extensions;
Expand Down
1 change: 1 addition & 0 deletions Editor/Drawers/Misc/Handlers/RenameFieldHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Better.Attributes.Runtime.Misc;
using Better.Commons.EditorAddons.Drawers;
using Better.Commons.EditorAddons.Drawers.HandlerBinding;
using Better.Commons.EditorAddons.Helpers;

namespace Better.Attributes.EditorAddons.Drawers.Misc
Expand Down
3 changes: 0 additions & 3 deletions Editor/Drawers/Parameters.meta

This file was deleted.

17 changes: 0 additions & 17 deletions Editor/Drawers/Parameters/FieldFactory.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Editor/Drawers/Parameters/FieldFactory.cs.meta

This file was deleted.

15 changes: 0 additions & 15 deletions Editor/Drawers/Parameters/FieldFactoryExtensions.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Editor/Drawers/Parameters/FieldFactoryExtensions.cs.meta

This file was deleted.

25 changes: 0 additions & 25 deletions Editor/Drawers/Parameters/Parameter.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Editor/Drawers/Parameters/Parameter.cs.meta

This file was deleted.

Loading

0 comments on commit 826784f

Please sign in to comment.