Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit a927b5e

Browse files
committed
1.6.7
* Parameters (in Methods or Properties) with default values will now show these default values in the Inspector, and if you don't provide any input then this default value will be used as the argument. * Removed an unnecessary update of cached members when you open a Reflection Inspector, should be a bit faster now. * When entering arguments, the name of the argument is now white instead of cyan to avoid confusion with the Type name. * A few clean ups
1 parent 642c978 commit a927b5e

File tree

13 files changed

+174
-169
lines changed

13 files changed

+174
-169
lines changed

src/CachedObjects/CacheObjectBase.cs

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ public bool CanWrite
4444
}
4545
}
4646

47-
// ===== Abstract/Virtual Methods ===== //
48-
4947
public virtual void Init() { }
50-
public abstract void DrawValue(Rect window, float width);
5148

52-
// ===== Static Methods ===== //
49+
public abstract void DrawValue(Rect window, float width);
5350

5451
/// <summary>
5552
/// Get CacheObject from only an object instance
@@ -205,11 +202,8 @@ private static CacheObjectBase GetCacheObjectImpl(object obj, MemberInfo memberI
205202
}
206203

207204
holder.m_argumentInput = new string[holder.m_arguments.Length];
208-
209-
if (!holder.HasParameters)
210-
{
211-
holder.UpdateValue();
212-
}
205+
206+
holder.UpdateValue();
213207

214208
holder.Init();
215209

@@ -229,7 +223,18 @@ public static bool CanProcessArgs(ParameterInfo[] parameters)
229223
return true;
230224
}
231225

232-
// ======== Instance Methods =========
226+
public float CalcWhitespace(Rect window)
227+
{
228+
if (!(this is IExpandHeight)) return 0f;
229+
230+
float whitespace = (this as IExpandHeight).WhiteSpace;
231+
if (whitespace > 0)
232+
{
233+
ClampLabelWidth(window, ref whitespace);
234+
}
235+
236+
return whitespace;
237+
}
233238

234239
public object[] ParseArguments()
235240
{
@@ -247,16 +252,20 @@ public object[] ParseArguments()
247252
{
248253
try
249254
{
250-
parsedArgs.Add(type.GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { input }));
255+
parsedArgs.Add(type.GetMethod("Parse", new Type[] { typeof(string) })
256+
.Invoke(null, new object[] { input }));
251257
}
252258
catch
253259
{
254-
//MelonLogger.Log($"Unable to parse '{input}' to type '{type.Name}'");
255-
256-
// try add a null arg i guess
257-
parsedArgs.Add(null);
258-
259-
//break;
260+
if (m_arguments[i].HasDefaultValue)
261+
{
262+
parsedArgs.Add(m_arguments[i].DefaultValue);
263+
}
264+
else
265+
{
266+
// Try add a null arg I guess
267+
parsedArgs.Add(null);
268+
}
260269
}
261270
}
262271
}
@@ -271,6 +280,12 @@ public virtual void UpdateValue()
271280
return;
272281
}
273282

283+
if (HasParameters && !m_isEvaluating)
284+
{
285+
// Need to enter parameters first
286+
return;
287+
}
288+
274289
try
275290
{
276291
if (MemInfo.MemberType == MemberTypes.Field)
@@ -332,7 +347,7 @@ public void SetValue()
332347
}
333348
}
334349

335-
// ========= Instance Gui Draw ==========
350+
// ========= Gui Draw ==========
336351

337352
public const float MAX_LABEL_WIDTH = 400f;
338353
public const string EVALUATE_LABEL = "<color=lime>Evaluate</color>";
@@ -375,10 +390,18 @@ public void Draw(Rect window, float labelWidth = 215f)
375390
var input = m_argumentInput[i];
376391
var type = m_arguments[i].ParameterType.Name;
377392

393+
var label = "<color=#2df7b2>" + type + "</color> <color=#a6e9e9>" + name + "</color>";
394+
if (m_arguments[i].HasDefaultValue)
395+
{
396+
label = $"<i>[{label} = {m_arguments[i].DefaultValue}]</i>";
397+
}
398+
378399
GUILayout.BeginHorizontal(null);
379-
GUILayout.Label(i.ToString(), new GUILayoutOption[] { GUILayout.Width(30) });
400+
401+
GUILayout.Label(i.ToString(), new GUILayoutOption[] { GUILayout.Width(20) });
380402
m_argumentInput[i] = GUILayout.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) });
381-
GUILayout.Label("<color=#2df7b2>" + type + "</color> <color=cyan>" + name + "</color>", null);
403+
GUILayout.Label(label, null);
404+
382405
GUILayout.EndHorizontal();
383406
}
384407

@@ -438,7 +461,11 @@ public void Draw(Rect window, float labelWidth = 215f)
438461
{
439462
GUILayout.Label("<color=red>Reflection failed!</color> (" + ReflectionException + ")", null);
440463
}
441-
else if (Value == null && MemInfo?.MemberType != MemberTypes.Method)
464+
else if ((HasParameters || this is CacheMethod) && !m_evaluated)
465+
{
466+
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> (<color=#2df7b2>{ValueTypeName}</color>)", null);
467+
}
468+
else if (Value == null && !(this is CacheMethod))
442469
{
443470
GUILayout.Label("<i>null (" + ValueTypeName + ")</i>", null);
444471
}
@@ -463,7 +490,7 @@ private string GetRichTextName()
463490

464491
m_richTextName = $"<color=#2df7b2>{MemInfo.DeclaringType.Name}</color>.<color={memberColor}>{MemInfo.Name}</color>";
465492

466-
if (m_arguments.Length > 0)
493+
if (m_arguments.Length > 0 || this is CacheMethod)
467494
{
468495
m_richTextName += "(";
469496
var _params = "";

src/Helpers/IExpandHeight.cs renamed to src/CachedObjects/IExpandHeight.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ namespace Explorer
99
interface IExpandHeight
1010
{
1111
bool IsExpanded { get; set; }
12-
13-
float WhiteSpace { get; set; }
14-
float ButtonWidthOffset { get; set; }
12+
float WhiteSpace { get; set; }
1513
}
1614
}

src/CachedObjects/Object/CacheDictionary.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class CacheDictionary : CacheObjectBase, IExpandHeight
1515
{
1616
public bool IsExpanded { get; set; }
1717
public float WhiteSpace { get; set; } = 215f;
18-
public float ButtonWidthOffset { get; set; } = 350f;
1918

2019
public PageHelper Pages = new PageHelper();
2120

@@ -126,6 +125,10 @@ private void GetGenericArguments()
126125
m_keysType = type.GetGenericArguments()[0];
127126
m_valuesType = type.GetGenericArguments()[1];
128127
}
128+
else
129+
{
130+
MelonLogger.Log("TODO? Dictionary is of type: " + Value.GetType().FullName);
131+
}
129132
}
130133
}
131134

@@ -203,11 +206,7 @@ public override void DrawValue(Rect window, float width)
203206
return;
204207
}
205208

206-
float whitespace = WhiteSpace;
207-
if (whitespace > 0)
208-
{
209-
ClampLabelWidth(window, ref whitespace);
210-
}
209+
var whitespace = CalcWhitespace(window);
211210

212211
int count = m_cachedKeys.Length;
213212

src/CachedObjects/Object/CacheList.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class CacheList : CacheObjectBase, IExpandHeight
1212
{
1313
public bool IsExpanded { get; set; }
1414
public float WhiteSpace { get; set; } = 215f;
15-
public float ButtonWidthOffset { get; set; } = 290f;
1615

1716
public PageHelper Pages = new PageHelper();
1817

@@ -245,11 +244,7 @@ public override void DrawValue(Rect window, float width)
245244
return;
246245
}
247246

248-
float whitespace = WhiteSpace;
249-
if (whitespace > 0)
250-
{
251-
ClampLabelWidth(window, ref whitespace);
252-
}
247+
var whitespace = CalcWhitespace(window);
253248

254249
int count = m_cachedEntries.Length;
255250

src/CachedObjects/Other/CacheMethod.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ public void Evaluate()
4444
}
4545
else
4646
{
47-
var parsedArgs = ParseArguments();
48-
4947
try
5048
{
51-
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, parsedArgs.ToArray());
49+
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, ParseArguments());
5250
m_evaluated = true;
5351
}
5452
catch (Exception e)

src/CachedObjects/Struct/CacheColor.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class CacheColor : CacheObjectBase, IExpandHeight
1616

1717
public bool IsExpanded { get; set; }
1818
public float WhiteSpace { get; set; } = 215f;
19-
public float ButtonWidthOffset { get; set; } = 290f;
2019

2120
public override void UpdateValue()
2221
{
@@ -59,11 +58,7 @@ public override void DrawValue(Rect window, float width)
5958
{
6059
GUILayout.EndHorizontal();
6160

62-
float whitespace = WhiteSpace;
63-
if (whitespace > 0)
64-
{
65-
ClampLabelWidth(window, ref whitespace);
66-
}
61+
var whitespace = CalcWhitespace(window);
6762

6863
GUILayout.BeginHorizontal(null);
6964
GUILayout.Space(whitespace);

src/CachedObjects/Struct/CacheQuaternion.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class CacheQuaternion : CacheObjectBase, IExpandHeight
1515

1616
public bool IsExpanded { get; set; }
1717
public float WhiteSpace { get; set; } = 215f;
18-
public float ButtonWidthOffset { get; set; } = 290f;
1918

2019
public override void UpdateValue()
2120
{
@@ -54,11 +53,7 @@ public override void DrawValue(Rect window, float width)
5453
{
5554
GUILayout.EndHorizontal();
5655

57-
float whitespace = WhiteSpace;
58-
if (whitespace > 0)
59-
{
60-
ClampLabelWidth(window, ref whitespace);
61-
}
56+
var whitespace = CalcWhitespace(window);
6257

6358
GUILayout.BeginHorizontal(null);
6459
GUILayout.Space(whitespace);

src/CachedObjects/Struct/CacheRect.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class CacheRect : CacheObjectBase, IExpandHeight
1616

1717
public bool IsExpanded { get; set; }
1818
public float WhiteSpace { get; set; } = 215f;
19-
public float ButtonWidthOffset { get; set; } = 290f;
2019

2120
public override void UpdateValue()
2221
{
@@ -56,11 +55,7 @@ public override void DrawValue(Rect window, float width)
5655
{
5756
GUILayout.EndHorizontal();
5857

59-
float whitespace = WhiteSpace;
60-
if (whitespace > 0)
61-
{
62-
ClampLabelWidth(window, ref whitespace);
63-
}
58+
var whitespace = CalcWhitespace(window);
6459

6560
GUILayout.BeginHorizontal(null);
6661
GUILayout.Space(whitespace);

src/CachedObjects/Struct/CacheVector.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public class CacheVector : CacheObjectBase, IExpandHeight
2121

2222
public bool IsExpanded { get; set; }
2323
public float WhiteSpace { get; set; } = 215f;
24-
public float ButtonWidthOffset { get; set; } = 290f;
2524

2625
public override void Init()
2726
{
@@ -90,11 +89,8 @@ public override void DrawValue(Rect window, float width)
9089
if (CanWrite && IsExpanded)
9190
{
9291
GUILayout.EndHorizontal();
93-
float whitespace = WhiteSpace;
94-
if (whitespace > 0)
95-
{
96-
ClampLabelWidth(window, ref whitespace);
97-
}
92+
93+
var whitespace = CalcWhitespace(window);
9894

9995
// always draw x and y
10096
GUILayout.BeginHorizontal(null);

src/CppExplorer.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Explorer
1313
public class CppExplorer : MelonMod
1414
{
1515
public const string NAME = "CppExplorer";
16-
public const string VERSION = "1.6.5";
16+
public const string VERSION = "1.6.7";
1717
public const string AUTHOR = "Sinai";
1818
public const string GUID = "com.sinai.cppexplorer";
1919

@@ -44,7 +44,11 @@ private static void SetShowMenu(bool show)
4444
UpdateCursorControl();
4545
}
4646

47-
// ========== MonoBehaviour methods ==========
47+
private static void SetForceUnlock(bool unlock)
48+
{
49+
m_forceUnlock = unlock;
50+
UpdateCursorControl();
51+
}
4852

4953
public override void OnApplicationStart()
5054
{
@@ -60,9 +64,9 @@ public override void OnApplicationStart()
6064
m_lastVisibleState = Cursor.visible;
6165

6266
// Enable ShowMenu and ForceUnlockMouse
63-
// (set m_showMenu to not call UpdateCursorState twice)
67+
// (set m_showMenu directly to not call UpdateCursorState twice)
6468
m_showMenu = true;
65-
SetForceUnlock(true);
69+
ForceUnlockMouse = true;
6670

6771
MelonLogger.Log($"CppExplorer {VERSION} initialized.");
6872
}
@@ -104,14 +108,6 @@ public override void OnGUI()
104108
InspectUnderMouse.OnGUI();
105109
}
106110

107-
// =========== Cursor control ===========
108-
109-
private static void SetForceUnlock(bool unlock)
110-
{
111-
m_forceUnlock = unlock;
112-
UpdateCursorControl();
113-
}
114-
115111
private static void UpdateCursorControl()
116112
{
117113
m_currentlySettingCursor = true;

0 commit comments

Comments
 (0)