diff --git a/img.png b/img.png index 1164d20..ba83d23 100644 Binary files a/img.png and b/img.png differ diff --git a/src/CachedObjects/CacheObjectBase.cs b/src/CachedObjects/CacheObjectBase.cs index cea0613..61f6118 100644 --- a/src/CachedObjects/CacheObjectBase.cs +++ b/src/CachedObjects/CacheObjectBase.cs @@ -19,8 +19,12 @@ namespace Explorer public MemberInfo MemInfo { get; set; } public Type DeclaringType { get; set; } public object DeclaringInstance { get; set; } - public int PropertyIndex { get; private set; } - private string m_propertyIndexInput = "0"; + + public bool HasParameters => m_arguments != null && m_arguments.Length > 0; + public bool m_evaluated = false; + public bool m_isEvaluating; + public ParameterInfo[] m_arguments = new ParameterInfo[0]; + public string[] m_argumentInput = new string[0]; public string ReflectionException { get; set; } @@ -43,7 +47,6 @@ namespace Explorer // ===== Abstract/Virtual Methods ===== // public virtual void Init() { } - public abstract void DrawValue(Rect window, float width); // ===== Static Methods ===== // @@ -114,12 +117,21 @@ namespace Explorer { CacheObjectBase holder; + var pi = memberInfo as PropertyInfo; + var mi = memberInfo as MethodInfo; + + // if PropertyInfo, check if can process args + if (pi != null && !CanProcessArgs(pi.GetIndexParameters())) + { + return null; + } + // This is pretty ugly, could probably make a cleaner implementation. // However, the only cleaner ways I can think of are slower and probably not worth it. // Note: the order is somewhat important. - if (memberInfo is MethodInfo mi) + if (mi != null) { if (CacheMethod.CanEvaluate(mi)) { @@ -181,7 +193,21 @@ namespace Explorer holder.MemInfo = memberInfo; holder.DeclaringType = memberInfo.DeclaringType; holder.DeclaringInstance = declaringInstance; + } + if (pi != null) + { + holder.m_arguments = pi.GetIndexParameters(); + } + else if (mi != null) + { + holder.m_arguments = mi.GetParameters(); + } + + holder.m_argumentInput = new string[holder.m_arguments.Length]; + + if (!holder.HasParameters) + { holder.UpdateValue(); } @@ -190,11 +216,57 @@ namespace Explorer return holder; } + public static bool CanProcessArgs(ParameterInfo[] parameters) + { + foreach (var param in parameters) + { + if (!param.ParameterType.IsPrimitive && param.ParameterType != typeof(string)) + { + return false; + } + } + + return true; + } + // ======== Instance Methods ========= + public object[] ParseArguments() + { + var parsedArgs = new List(); + for (int i = 0; i < m_arguments.Length; i++) + { + var input = m_argumentInput[i]; + var type = m_arguments[i].ParameterType; + + if (type == typeof(string)) + { + parsedArgs.Add(input); + } + else + { + try + { + parsedArgs.Add(type.GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { input })); + } + catch + { + //MelonLogger.Log($"Unable to parse '{input}' to type '{type.Name}'"); + + // try add a null arg i guess + parsedArgs.Add(null); + + //break; + } + } + } + + return parsedArgs.ToArray(); + } + public virtual void UpdateValue() { - if (MemInfo == null || !string.IsNullOrEmpty(ReflectionException)) + if (MemInfo == null) { return; } @@ -209,13 +281,11 @@ namespace Explorer else if (MemInfo.MemberType == MemberTypes.Property) { var pi = MemInfo as PropertyInfo; - bool isStatic = pi.GetAccessors()[0].IsStatic; - var target = isStatic ? null : DeclaringInstance; + var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance; - if (pi.GetIndexParameters().Length > 0) + if (HasParameters) { - var indexes = new object[] { PropertyIndex }; - Value = pi.GetValue(target, indexes); + Value = pi.GetValue(target, ParseArguments()); } else { @@ -224,6 +294,8 @@ namespace Explorer } ReflectionException = null; + m_evaluated = true; + m_isEvaluating = false; } catch (Exception e) { @@ -244,10 +316,9 @@ namespace Explorer { var pi = MemInfo as PropertyInfo; - if (pi.GetIndexParameters().Length > 0) + if (HasParameters) { - var indexes = new object[] { PropertyIndex }; - pi.SetValue(pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance, Value, indexes); + pi.SetValue(pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance, Value, ParseArguments()); } else { @@ -264,6 +335,7 @@ namespace Explorer // ========= Instance Gui Draw ========== public const float MAX_LABEL_WIDTH = 400f; + public const string EVALUATE_LABEL = "Evaluate"; public static void ClampLabelWidth(Rect window, ref float labelWidth) { @@ -282,19 +354,86 @@ namespace Explorer if (MemInfo != null) { - var name = RichTextName; - if (MemInfo is PropertyInfo pi && pi.GetIndexParameters().Length > 0) - { - name += $"[{PropertyIndex}]"; - } - - GUILayout.Label(name, new GUILayoutOption[] { GUILayout.Width(labelWidth) }); + GUILayout.Label(RichTextName, new GUILayoutOption[] { GUILayout.Width(labelWidth) }); } else { GUILayout.Space(labelWidth); } + var cm = this as CacheMethod; + + if (HasParameters) + { + GUILayout.BeginVertical(null); + + if (m_isEvaluating) + { + for (int i = 0; i < m_arguments.Length; i++) + { + var name = m_arguments[i].Name; + var input = m_argumentInput[i]; + var type = m_arguments[i].ParameterType.Name; + + GUILayout.BeginHorizontal(null); + GUILayout.Label(i.ToString(), new GUILayoutOption[] { GUILayout.Width(30) }); + m_argumentInput[i] = GUILayout.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) }); + GUILayout.Label("" + type + " " + name + "", null); + GUILayout.EndHorizontal(); + } + + GUILayout.BeginHorizontal(null); + if (cm != null) + { + if (GUILayout.Button(EVALUATE_LABEL, new GUILayoutOption[] { GUILayout.Width(70) })) + { + cm.Evaluate(); + } + } + else + { + if (GUILayout.Button(EVALUATE_LABEL, new GUILayoutOption[] { GUILayout.Width(70) })) + { + UpdateValue(); + } + } + + if (GUILayout.Button("Cancel", new GUILayoutOption[] { GUILayout.Width(70) })) + { + m_isEvaluating = false; + } + GUILayout.EndHorizontal(); + } + else + { + if (GUILayout.Button($"Evaluate ({m_arguments.Length} params)", new GUILayoutOption[] { GUILayout.Width(150) })) + { + m_isEvaluating = true; + } + } + + GUILayout.EndVertical(); + + // new line and space + GUILayout.EndHorizontal(); + GUILayout.BeginHorizontal(null); + GUILayout.Space(labelWidth); + } + else if (cm != null) + { + //GUILayout.BeginHorizontal(null); + + if (GUILayout.Button(EVALUATE_LABEL, new GUILayoutOption[] { GUILayout.Width(70) })) + { + cm.Evaluate(); + } + + // new line and space + GUILayout.EndHorizontal(); + GUILayout.BeginHorizontal(null); + GUILayout.Space(labelWidth); + } + if (!string.IsNullOrEmpty(ReflectionException)) { GUILayout.Label("Reflection failed! (" + ReflectionException + ")", null); @@ -305,30 +444,6 @@ namespace Explorer } else { - if (MemInfo is PropertyInfo pi && pi.GetIndexParameters().Length > 0) - { - GUILayout.Label("index:", new GUILayoutOption[] { GUILayout.Width(50) }); - - m_propertyIndexInput = GUILayout.TextField(m_propertyIndexInput, new GUILayoutOption[] { GUILayout.Width(100) }); - if (GUILayout.Button("Set", new GUILayoutOption[] { GUILayout.Width(60) })) - { - if (int.TryParse(m_propertyIndexInput, out int i)) - { - PropertyIndex = i; - UpdateValue(); - } - else - { - MelonLogger.Log($"Could not parse '{m_propertyIndexInput}' to an int!"); - } - } - - // new line and space - GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); - GUILayout.Space(labelWidth); - } - DrawValue(window, window.width - labelWidth - 90); } } @@ -348,15 +463,15 @@ namespace Explorer m_richTextName = $"{MemInfo.DeclaringType.Name}.{MemInfo.Name}"; - if (MemInfo is MethodInfo mi) + if (m_arguments.Length > 0) { m_richTextName += "("; var _params = ""; - foreach (var param in mi.GetParameters()) + foreach (var param in m_arguments) { if (_params != "") _params += ", "; - _params += $"{param.Name}"; + _params += $"{param.ParameterType.Name} {param.Name}"; } m_richTextName += _params; m_richTextName += ")"; diff --git a/src/CachedObjects/Object/CacheDictionary.cs b/src/CachedObjects/Object/CacheDictionary.cs index 4f13897..e6c9bce 100644 --- a/src/CachedObjects/Object/CacheDictionary.cs +++ b/src/CachedObjects/Object/CacheDictionary.cs @@ -15,7 +15,7 @@ namespace Explorer { public bool IsExpanded { get; set; } public float WhiteSpace { get; set; } = 215f; - public float ButtonWidthOffset { get; set; } = 290f; + public float ButtonWidthOffset { get; set; } = 350f; public PageHelper Pages = new PageHelper(); @@ -152,7 +152,6 @@ namespace Explorer foreach (var key in IDict.Keys) { var cache = GetCacheObject(key, TypeOfKeys); - cache.UpdateValue(); keys.Add(cache); } @@ -160,7 +159,6 @@ namespace Explorer foreach (var val in IDict.Values) { var cache = GetCacheObject(val, TypeOfValues); - cache.UpdateValue(); values.Add(cache); } @@ -170,6 +168,11 @@ namespace Explorer private bool EnsureDictionaryIsSupported() { + if (typeof(IDictionary).IsAssignableFrom(ValueType)) + { + return true; + } + try { return Check(TypeOfKeys) && Check(TypeOfValues); @@ -200,6 +203,12 @@ namespace Explorer return; } + float whitespace = WhiteSpace; + if (whitespace > 0) + { + ClampLabelWidth(window, ref whitespace); + } + int count = m_cachedKeys.Length; if (!IsExpanded) @@ -217,9 +226,11 @@ namespace Explorer } } + var negativeWhitespace = window.width - (whitespace + 100f); + GUI.skin.button.alignment = TextAnchor.MiddleLeft; - string btnLabel = $"[{count}] Dictionary<{TypeOfKeys.FullName}, {TypeOfValues.FullName}>"; - if (GUILayout.Button(btnLabel, new GUILayoutOption[] { GUILayout.MaxWidth(window.width - ButtonWidthOffset) })) + string btnLabel = $"[{count}] Dictionary<{TypeOfKeys.FullName}, {TypeOfValues.FullName}>"; + if (GUILayout.Button(btnLabel, new GUILayoutOption[] { GUILayout.Width(negativeWhitespace) })) { WindowManager.InspectObject(Value, out bool _); } @@ -229,12 +240,6 @@ namespace Explorer if (IsExpanded) { - float whitespace = WhiteSpace; - if (whitespace > 0) - { - ClampLabelWidth(window, ref whitespace); - } - Pages.ItemCount = count; if (count > Pages.ItemsPerPage) diff --git a/src/CachedObjects/Object/CacheList.cs b/src/CachedObjects/Object/CacheList.cs index d334573..bc5b963 100644 --- a/src/CachedObjects/Object/CacheList.cs +++ b/src/CachedObjects/Object/CacheList.cs @@ -219,7 +219,6 @@ namespace Explorer if (GetCacheObject(obj, t) is CacheObjectBase cached) { - cached.UpdateValue(); list.Add(cached); } else @@ -246,6 +245,12 @@ namespace Explorer return; } + float whitespace = WhiteSpace; + if (whitespace > 0) + { + ClampLabelWidth(window, ref whitespace); + } + int count = m_cachedEntries.Length; if (!IsExpanded) @@ -263,9 +268,11 @@ namespace Explorer } } + var negativeWhitespace = window.width - (whitespace + 100f); + GUI.skin.button.alignment = TextAnchor.MiddleLeft; - string btnLabel = "[" + count + "] " + EntryType.FullName + ""; - if (GUILayout.Button(btnLabel, new GUILayoutOption[] { GUILayout.MaxWidth(window.width - ButtonWidthOffset) })) + string btnLabel = $"[{count}] {EntryType.FullName}"; + if (GUILayout.Button(btnLabel, new GUILayoutOption[] { GUILayout.MaxWidth(negativeWhitespace) })) { WindowManager.InspectObject(Value, out bool _); } @@ -275,12 +282,6 @@ namespace Explorer if (IsExpanded) { - float whitespace = WhiteSpace; - if (whitespace > 0) - { - ClampLabelWidth(window, ref whitespace); - } - Pages.ItemCount = count; if (count > Pages.ItemsPerPage) diff --git a/src/CachedObjects/Other/CacheMethod.cs b/src/CachedObjects/Other/CacheMethod.cs index 4f70a33..a182c66 100644 --- a/src/CachedObjects/Other/CacheMethod.cs +++ b/src/CachedObjects/Other/CacheMethod.cs @@ -11,15 +11,8 @@ namespace Explorer { public class CacheMethod : CacheObjectBase { - private bool m_evaluated = false; private CacheObjectBase m_cachedReturnValue; - private bool m_isEvaluating; - private ParameterInfo[] m_arguments; - private string[] m_argumentInput; - - public bool HasParameters => m_arguments != null && m_arguments.Length > 0; - public static bool CanEvaluate(MethodInfo mi) { // TODO generic args @@ -29,25 +22,7 @@ namespace Explorer } // primitive and string args supported - foreach (var param in mi.GetParameters()) - { - if (!param.ParameterType.IsPrimitive && param.ParameterType != typeof(string)) - { - return false; - } - } - - return true; - } - - public override void Init() - { - base.Init(); - - var mi = MemInfo as MethodInfo; - - m_arguments = mi.GetParameters(); - m_argumentInput = new string[m_arguments.Length]; + return CanProcessArgs(mi.GetParameters()); } public override void UpdateValue() @@ -55,10 +30,11 @@ namespace Explorer //base.UpdateValue(); } - private void Evaluate() + public void Evaluate() { - var mi = MemInfo as MethodInfo; + m_isEvaluating = false; + var mi = MemInfo as MethodInfo; object ret = null; if (!HasParameters) @@ -68,38 +44,7 @@ namespace Explorer } else { - var parsedArgs = new List(); - for (int i = 0; i < m_arguments.Length; i++) - { - var input = m_argumentInput[i]; - var type = m_arguments[i].ParameterType; - - if (type == typeof(string)) - { - parsedArgs.Add(input); - } - else - { - try - { - if (type.GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { input }) is object parsed) - { - parsedArgs.Add(parsed); - } - else - { - // try add a null arg i guess - parsedArgs.Add(null); - } - - } - catch - { - MelonLogger.Log($"Unable to parse '{input}' to type '{type.Name}'"); - break; - } - } - } + var parsedArgs = ParseArguments(); try { @@ -115,13 +60,6 @@ namespace Explorer if (ret != null) { m_cachedReturnValue = GetCacheObject(ret); - - if (m_cachedReturnValue is IExpandHeight expander) - { - expander.WhiteSpace = 0f; - expander.ButtonWidthOffset += 70f; - } - m_cachedReturnValue.UpdateValue(); } else @@ -134,58 +72,6 @@ namespace Explorer public override void DrawValue(Rect window, float width) { - GUILayout.BeginVertical(null); - - string evaluateLabel = "Evaluate"; - if (HasParameters) - { - if (m_isEvaluating) - { - for (int i = 0; i < m_arguments.Length; i++) - { - var name = m_arguments[i].Name; - var input = m_argumentInput[i]; - var type = m_arguments[i].ParameterType.Name; - - GUILayout.BeginHorizontal(null); - m_argumentInput[i] = GUILayout.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) }); - GUILayout.Label(i + ": " + name + " (" + type + ")", null); - - GUILayout.EndHorizontal(); - } - - GUILayout.BeginHorizontal(null); - if (GUILayout.Button(evaluateLabel, new GUILayoutOption[] { GUILayout.Width(70) })) - { - Evaluate(); - m_isEvaluating = false; - } - if (GUILayout.Button("Cancel", new GUILayoutOption[] { GUILayout.Width(70) })) - { - m_isEvaluating = false; - } - } - else - { - GUILayout.BeginHorizontal(null); - if (GUILayout.Button($"Evaluate ({m_arguments.Length} params)", new GUILayoutOption[] { GUILayout.Width(150) })) - { - m_isEvaluating = true; - } - } - } - else - { - GUILayout.BeginHorizontal(null); - if (GUILayout.Button(evaluateLabel, new GUILayoutOption[] { GUILayout.Width(70) })) - { - Evaluate(); - } - } - - GUILayout.EndHorizontal(); - - GUILayout.BeginHorizontal(null); if (m_evaluated) { if (m_cachedReturnValue != null) @@ -194,16 +80,13 @@ namespace Explorer } else { - GUILayout.Label($"null ({ValueTypeName})", null); + GUILayout.Label($"null ({ValueTypeName})", null); } } else { - GUILayout.Label($"Not yet evaluated ({ValueTypeName})", null); + GUILayout.Label($"Not yet evaluated ({ValueTypeName})", null); } - GUILayout.EndHorizontal(); - - GUILayout.EndVertical(); } } } diff --git a/src/CachedObjects/Other/CacheOther.cs b/src/CachedObjects/Other/CacheOther.cs index 58aceb9..97ce07b 100644 --- a/src/CachedObjects/Other/CacheOther.cs +++ b/src/CachedObjects/Other/CacheOther.cs @@ -42,15 +42,20 @@ namespace Explorer if (!label.Contains(ValueTypeName)) { - label += $" ({ValueTypeName})"; + label += $" ({ValueTypeName})"; } + else + { + label = label.Replace(ValueTypeName, $"{ValueTypeName}"); + } + if (Value is UnityEngine.Object unityObj && !label.Contains(unityObj.name)) { label = unityObj.name + " | " + label; } GUI.skin.button.alignment = TextAnchor.MiddleLeft; - if (GUILayout.Button("" + label + "", new GUILayoutOption[] { GUILayout.Width(width - 15) })) + if (GUILayout.Button(label, new GUILayoutOption[] { GUILayout.Width(width - 15) })) { WindowManager.InspectObject(Value, out bool _); } diff --git a/src/CachedObjects/Struct/CacheColor.cs b/src/CachedObjects/Struct/CacheColor.cs index 936d2d2..ca56db3 100644 --- a/src/CachedObjects/Struct/CacheColor.cs +++ b/src/CachedObjects/Struct/CacheColor.cs @@ -7,15 +7,17 @@ using UnityEngine; namespace Explorer { - public class CacheColor : CacheObjectBase + public class CacheColor : CacheObjectBase, IExpandHeight { - private bool IsExpanded; - private string r = "0"; private string g = "0"; private string b = "0"; private string a = "0"; + public bool IsExpanded { get; set; } + public float WhiteSpace { get; set; } = 215f; + public float ButtonWidthOffset { get; set; } = 290f; + public override void UpdateValue() { base.UpdateValue(); @@ -50,13 +52,18 @@ namespace Explorer var c = (Color)Value; GUI.color = c; - GUILayout.Label($"Color: {c.ToString()}", null); + GUILayout.Label($"Color: {c.ToString()}", null); GUI.color = Color.white; if (CanWrite && IsExpanded) { GUILayout.EndHorizontal(); - var whitespace = window.width - width - 90; + + float whitespace = WhiteSpace; + if (whitespace > 0) + { + ClampLabelWidth(window, ref whitespace); + } GUILayout.BeginHorizontal(null); GUILayout.Space(whitespace); diff --git a/src/CachedObjects/Struct/CacheEnum.cs b/src/CachedObjects/Struct/CacheEnum.cs index 50cf834..f90d8f7 100644 --- a/src/CachedObjects/Struct/CacheEnum.cs +++ b/src/CachedObjects/Struct/CacheEnum.cs @@ -51,7 +51,7 @@ namespace Explorer } } - GUILayout.Label(Value.ToString() + " (" + ValueType + ")", null); + GUILayout.Label(Value.ToString() + " (" + ValueType + ")", null); } public void SetEnum(ref object value, int change) diff --git a/src/CachedObjects/Struct/CachePrimitive.cs b/src/CachedObjects/Struct/CachePrimitive.cs index 61cefbe..3130c79 100644 --- a/src/CachedObjects/Struct/CachePrimitive.cs +++ b/src/CachedObjects/Struct/CachePrimitive.cs @@ -69,10 +69,10 @@ namespace Explorer else { // using ValueType.Name instead of ValueTypeName, because we only want the short name. - GUILayout.Label("" + ValueType.Name + "", new GUILayoutOption[] { GUILayout.Width(50) }); + GUILayout.Label("" + ValueType.Name + "", new GUILayoutOption[] { GUILayout.Width(50) }); int dynSize = 25 + (m_valueToString.Length * 15); - var maxwidth = window.width - 300f; + var maxwidth = window.width - 310f; if (CanWrite) maxwidth -= 60; if (dynSize > maxwidth) @@ -92,7 +92,7 @@ namespace Explorer } } - GUILayout.Space(5); + GUILayout.Space(10); } } diff --git a/src/CachedObjects/Struct/CacheQuaternion.cs b/src/CachedObjects/Struct/CacheQuaternion.cs index 37b7fee..b739a61 100644 --- a/src/CachedObjects/Struct/CacheQuaternion.cs +++ b/src/CachedObjects/Struct/CacheQuaternion.cs @@ -7,14 +7,16 @@ using UnityEngine; namespace Explorer { - public class CacheQuaternion : CacheObjectBase + public class CacheQuaternion : CacheObjectBase, IExpandHeight { - private bool IsExpanded; - private string x = "0"; private string y = "0"; private string z = "0"; + public bool IsExpanded { get; set; } + public float WhiteSpace { get; set; } = 215f; + public float ButtonWidthOffset { get; set; } = 290f; + public override void UpdateValue() { base.UpdateValue(); @@ -46,12 +48,17 @@ namespace Explorer } } - GUILayout.Label($"Quaternion: {((Quaternion)Value).eulerAngles.ToString()}", null); + GUILayout.Label($"Quaternion: {((Quaternion)Value).eulerAngles.ToString()}", null); if (CanWrite && IsExpanded) { GUILayout.EndHorizontal(); - var whitespace = window.width - width - 90; + + float whitespace = WhiteSpace; + if (whitespace > 0) + { + ClampLabelWidth(window, ref whitespace); + } GUILayout.BeginHorizontal(null); GUILayout.Space(whitespace); diff --git a/src/CachedObjects/Struct/CacheRect.cs b/src/CachedObjects/Struct/CacheRect.cs index cbb2a46..a89bc53 100644 --- a/src/CachedObjects/Struct/CacheRect.cs +++ b/src/CachedObjects/Struct/CacheRect.cs @@ -7,15 +7,17 @@ using UnityEngine; namespace Explorer { - public class CacheRect : CacheObjectBase + public class CacheRect : CacheObjectBase, IExpandHeight { - private bool IsExpanded; - private string x = "0"; private string y = "0"; private string w = "0"; private string h = "0"; + public bool IsExpanded { get; set; } + public float WhiteSpace { get; set; } = 215f; + public float ButtonWidthOffset { get; set; } = 290f; + public override void UpdateValue() { base.UpdateValue(); @@ -48,12 +50,17 @@ namespace Explorer } } - GUILayout.Label($"Rect: {((Rect)Value).ToString()}", null); + GUILayout.Label($"Rect: {((Rect)Value).ToString()}", null); if (CanWrite && IsExpanded) { GUILayout.EndHorizontal(); - var whitespace = window.width - width - 90; + + float whitespace = WhiteSpace; + if (whitespace > 0) + { + ClampLabelWidth(window, ref whitespace); + } GUILayout.BeginHorizontal(null); GUILayout.Space(whitespace); diff --git a/src/CachedObjects/Struct/CacheVector.cs b/src/CachedObjects/Struct/CacheVector.cs index 9c4e781..083f55b 100644 --- a/src/CachedObjects/Struct/CacheVector.cs +++ b/src/CachedObjects/Struct/CacheVector.cs @@ -8,10 +8,8 @@ using UnityEngine; namespace Explorer { - public class CacheVector : CacheObjectBase + public class CacheVector : CacheObjectBase, IExpandHeight { - private bool IsExpanded; - public int VectorSize = 2; private string x = "0"; @@ -21,6 +19,10 @@ namespace Explorer private MethodInfo m_toStringMethod; + public bool IsExpanded { get; set; } + public float WhiteSpace { get; set; } = 215f; + public float ButtonWidthOffset { get; set; } = 290f; + public override void Init() { if (Value is Vector2) @@ -83,12 +85,16 @@ namespace Explorer } } - GUILayout.Label($"Vector{VectorSize}: {(string)m_toStringMethod.Invoke(Value, new object[0])}", null); + GUILayout.Label($"Vector{VectorSize}: {(string)m_toStringMethod.Invoke(Value, new object[0])}", null); if (CanWrite && IsExpanded) { GUILayout.EndHorizontal(); - var whitespace = window.width - width - 90; + float whitespace = WhiteSpace; + if (whitespace > 0) + { + ClampLabelWidth(window, ref whitespace); + } // always draw x and y GUILayout.BeginHorizontal(null); diff --git a/src/CppExplorer.csproj b/src/CppExplorer.csproj index 62262cd..8e0cba1 100644 --- a/src/CppExplorer.csproj +++ b/src/CppExplorer.csproj @@ -88,6 +88,7 @@ + diff --git a/src/Tests/TestClass.cs b/src/Tests/TestClass.cs new file mode 100644 index 0000000..0f9dc0f --- /dev/null +++ b/src/Tests/TestClass.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MelonLoader; +using UnityEngine; + +namespace Explorer.Tests +{ + public class TestClass + { + public static TestClass Instance => m_instance ?? (m_instance = new TestClass()); + private static TestClass m_instance; + + public string this[int index] + { + get + { + return $"int indexer: {index}"; + } + } + + public string this[string stringIndex] + { + get + { + return $"string indexer: {stringIndex}"; + } + } + + public string this[int arg0, string arg1] + { + get + { + return $"arg0: {arg0}, arg1: {arg1}"; + } + } + + public static List TestList = new List + { + "1", + "2", + "3", + "etc..." + }; + + public static Dictionary> NestedDictionary = new Dictionary> + { + { + 123, + new List + { + "One", + "Two" + } + }, + { + 567, + new List + { + "One", + "Two" + } + }, + }; + + public static Color TestMethod(float r, float g, float b, float a) + { + return new Color(r, g, b, a); + } + } +} diff --git a/src/Windows/ReflectionWindow.cs b/src/Windows/ReflectionWindow.cs index 827dc6f..e616fad 100644 --- a/src/Windows/ReflectionWindow.cs +++ b/src/Windows/ReflectionWindow.cs @@ -162,10 +162,20 @@ namespace Explorer name += " ("; foreach (var param in mi.GetParameters()) { - name += param.ParameterType.Name + ", "; + name += $"{param.ParameterType.Name} {param.Name}, "; } name += ")"; } + else if (member is PropertyInfo pi) + { + name += " ("; + foreach (var param in pi.GetIndexParameters()) + { + name += $"{param.ParameterType.Name} {param.Name}, "; + } + name += ")"; + } + if (names.Contains(name)) { continue;