mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 14:17:51 +08:00
Make GenericConstructorWidget reusable
This commit is contained in:
parent
6e91f2a792
commit
ecc33927ee
@ -6,53 +6,48 @@ using System.Text;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using UnityExplorer.UI.Panels;
|
using UnityExplorer.UI.Panels;
|
||||||
using UnityExplorer.UI.Widgets;
|
|
||||||
using UniverseLib.UI;
|
using UniverseLib.UI;
|
||||||
using UniverseLib.UI.Models;
|
using UniverseLib.UI.Models;
|
||||||
using UniverseLib.UI.ObjectPool;
|
using UniverseLib.UI.ObjectPool;
|
||||||
using UniverseLib.Utility;
|
using UniverseLib.Utility;
|
||||||
|
|
||||||
namespace UnityExplorer.Hooks
|
namespace UnityExplorer.UI.Widgets
|
||||||
{
|
{
|
||||||
public class GenericHookHandler
|
public class GenericConstructorWidget
|
||||||
{
|
{
|
||||||
static GenericArgumentHandler[] handlers;
|
GenericArgumentHandler[] handlers;
|
||||||
|
|
||||||
static Type[] currentGenericParameters;
|
Type[] currentGenericParameters;
|
||||||
static Action<Type[]> currentOnSubmit;
|
Action<Type[]> currentOnSubmit;
|
||||||
static Action currentOnCancel;
|
Action currentOnCancel;
|
||||||
|
|
||||||
static Text Title;
|
public GameObject UIRoot;
|
||||||
static GameObject ArgsHolder;
|
Text Title;
|
||||||
|
GameObject ArgsHolder;
|
||||||
|
|
||||||
// UI
|
public void Show(Action<Type[]> onSubmit, Action onCancel, Type genericTypeDefinition)
|
||||||
internal static GameObject UIRoot;
|
|
||||||
|
|
||||||
public static void Show(Action<Type[]> onSubmit, Action onCancel, Type genericTypeDefinition)
|
|
||||||
{
|
{
|
||||||
Title.text = $"Setting generic arguments for {SignatureHighlighter.Parse(genericTypeDefinition, false)}...";
|
Title.text = $"Setting generic arguments for {SignatureHighlighter.Parse(genericTypeDefinition, false)}...";
|
||||||
|
|
||||||
OnShow(onSubmit, onCancel, genericTypeDefinition.GetGenericArguments());
|
OnShow(onSubmit, onCancel, genericTypeDefinition.GetGenericArguments());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Show(Action<Type[]> onSubmit, Action onCancel, MethodInfo genericMethodDefinition)
|
public void Show(Action<Type[]> onSubmit, Action onCancel, MethodInfo genericMethodDefinition)
|
||||||
{
|
{
|
||||||
Title.text = $"Setting generic arguments for {SignatureHighlighter.HighlightMethod(genericMethodDefinition)}...";
|
Title.text = $"Setting generic arguments for {SignatureHighlighter.HighlightMethod(genericMethodDefinition)}...";
|
||||||
|
|
||||||
OnShow(onSubmit, onCancel, genericMethodDefinition.GetGenericArguments());
|
OnShow(onSubmit, onCancel, genericMethodDefinition.GetGenericArguments());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnShow(Action<Type[]> onSubmit, Action onCancel, Type[] genericParameters)
|
void OnShow(Action<Type[]> onSubmit, Action onCancel, Type[] genericParameters)
|
||||||
{
|
{
|
||||||
HookManagerPanel.Instance.SetPage(HookManagerPanel.Pages.GenericArgsSelector);
|
|
||||||
|
|
||||||
currentOnSubmit = onSubmit;
|
currentOnSubmit = onSubmit;
|
||||||
currentOnCancel = onCancel;
|
currentOnCancel = onCancel;
|
||||||
|
|
||||||
SetGenericParameters(genericParameters);
|
SetGenericParameters(genericParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetGenericParameters(Type[] genericParameters)
|
void SetGenericParameters(Type[] genericParameters)
|
||||||
{
|
{
|
||||||
currentGenericParameters = genericParameters;
|
currentGenericParameters = genericParameters;
|
||||||
|
|
||||||
@ -67,15 +62,20 @@ namespace UnityExplorer.Hooks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TrySubmit()
|
public void TrySubmit()
|
||||||
{
|
{
|
||||||
Type[] args = new Type[currentGenericParameters.Length];
|
Type[] args = new Type[currentGenericParameters.Length];
|
||||||
|
|
||||||
for (int i = 0; i < args.Length; i++)
|
for (int i = 0; i < args.Length; i++)
|
||||||
{
|
{
|
||||||
GenericArgumentHandler handler = handlers[i];
|
GenericArgumentHandler handler = handlers[i];
|
||||||
Type arg = handler.Evaluate();
|
Type arg;
|
||||||
if (arg == null)
|
try
|
||||||
|
{
|
||||||
|
arg = handler.Evaluate();
|
||||||
|
if (arg == null) throw new Exception();
|
||||||
|
}
|
||||||
|
catch
|
||||||
{
|
{
|
||||||
ExplorerCore.LogWarning($"Generic argument '{handler.inputField.Text}' is not a valid type.");
|
ExplorerCore.LogWarning($"Generic argument '{handler.inputField.Text}' is not a valid type.");
|
||||||
return;
|
return;
|
||||||
@ -87,14 +87,16 @@ namespace UnityExplorer.Hooks
|
|||||||
currentOnSubmit(args);
|
currentOnSubmit(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Cancel()
|
public void Cancel()
|
||||||
{
|
{
|
||||||
OnClose();
|
OnClose();
|
||||||
|
|
||||||
currentOnCancel();
|
currentOnCancel?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnClose()
|
void OnClose()
|
||||||
|
{
|
||||||
|
if (handlers != null)
|
||||||
{
|
{
|
||||||
foreach (GenericArgumentHandler widget in handlers)
|
foreach (GenericArgumentHandler widget in handlers)
|
||||||
{
|
{
|
||||||
@ -103,6 +105,7 @@ namespace UnityExplorer.Hooks
|
|||||||
}
|
}
|
||||||
handlers = null;
|
handlers = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// UI Construction
|
// UI Construction
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user