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

Commit

Permalink
1.6.7
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sinai-dev committed Sep 10, 2020
1 parent 642c978 commit a927b5e
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 169 deletions.
71 changes: 49 additions & 22 deletions src/CachedObjects/CacheObjectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ public bool CanWrite
}
}

// ===== Abstract/Virtual Methods ===== //

public virtual void Init() { }
public abstract void DrawValue(Rect window, float width);

// ===== Static Methods ===== //
public abstract void DrawValue(Rect window, float width);

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

holder.m_argumentInput = new string[holder.m_arguments.Length];

if (!holder.HasParameters)
{
holder.UpdateValue();
}

holder.UpdateValue();

holder.Init();

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

// ======== Instance Methods =========
public float CalcWhitespace(Rect window)
{
if (!(this is IExpandHeight)) return 0f;

float whitespace = (this as IExpandHeight).WhiteSpace;
if (whitespace > 0)
{
ClampLabelWidth(window, ref whitespace);
}

return whitespace;
}

public object[] ParseArguments()
{
Expand All @@ -247,16 +252,20 @@ public object[] ParseArguments()
{
try
{
parsedArgs.Add(type.GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { input }));
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;
if (m_arguments[i].HasDefaultValue)
{
parsedArgs.Add(m_arguments[i].DefaultValue);
}
else
{
// Try add a null arg I guess
parsedArgs.Add(null);
}
}
}
}
Expand All @@ -271,6 +280,12 @@ public virtual void UpdateValue()
return;
}

if (HasParameters && !m_isEvaluating)
{
// Need to enter parameters first
return;
}

try
{
if (MemInfo.MemberType == MemberTypes.Field)
Expand Down Expand Up @@ -332,7 +347,7 @@ public void SetValue()
}
}

// ========= Instance Gui Draw ==========
// ========= Gui Draw ==========

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

var label = "<color=#2df7b2>" + type + "</color> <color=#a6e9e9>" + name + "</color>";
if (m_arguments[i].HasDefaultValue)
{
label = $"<i>[{label} = {m_arguments[i].DefaultValue}]</i>";
}

GUILayout.BeginHorizontal(null);
GUILayout.Label(i.ToString(), new GUILayoutOption[] { GUILayout.Width(30) });

GUILayout.Label(i.ToString(), new GUILayoutOption[] { GUILayout.Width(20) });
m_argumentInput[i] = GUILayout.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) });
GUILayout.Label("<color=#2df7b2>" + type + "</color> <color=cyan>" + name + "</color>", null);
GUILayout.Label(label, null);

GUILayout.EndHorizontal();
}

Expand Down Expand Up @@ -438,7 +461,11 @@ public void Draw(Rect window, float labelWidth = 215f)
{
GUILayout.Label("<color=red>Reflection failed!</color> (" + ReflectionException + ")", null);
}
else if (Value == null && MemInfo?.MemberType != MemberTypes.Method)
else if ((HasParameters || this is CacheMethod) && !m_evaluated)
{
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> (<color=#2df7b2>{ValueTypeName}</color>)", null);
}
else if (Value == null && !(this is CacheMethod))
{
GUILayout.Label("<i>null (" + ValueTypeName + ")</i>", null);
}
Expand All @@ -463,7 +490,7 @@ private string GetRichTextName()

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

if (m_arguments.Length > 0)
if (m_arguments.Length > 0 || this is CacheMethod)
{
m_richTextName += "(";
var _params = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace Explorer
interface IExpandHeight
{
bool IsExpanded { get; set; }

float WhiteSpace { get; set; }
float ButtonWidthOffset { get; set; }
float WhiteSpace { get; set; }
}
}
11 changes: 5 additions & 6 deletions src/CachedObjects/Object/CacheDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class CacheDictionary : CacheObjectBase, IExpandHeight
{
public bool IsExpanded { get; set; }
public float WhiteSpace { get; set; } = 215f;
public float ButtonWidthOffset { get; set; } = 350f;

public PageHelper Pages = new PageHelper();

Expand Down Expand Up @@ -126,6 +125,10 @@ private void GetGenericArguments()
m_keysType = type.GetGenericArguments()[0];
m_valuesType = type.GetGenericArguments()[1];
}
else
{
MelonLogger.Log("TODO? Dictionary is of type: " + Value.GetType().FullName);
}
}
}

Expand Down Expand Up @@ -203,11 +206,7 @@ public override void DrawValue(Rect window, float width)
return;
}

float whitespace = WhiteSpace;
if (whitespace > 0)
{
ClampLabelWidth(window, ref whitespace);
}
var whitespace = CalcWhitespace(window);

int count = m_cachedKeys.Length;

Expand Down
7 changes: 1 addition & 6 deletions src/CachedObjects/Object/CacheList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class CacheList : CacheObjectBase, IExpandHeight
{
public bool IsExpanded { get; set; }
public float WhiteSpace { get; set; } = 215f;
public float ButtonWidthOffset { get; set; } = 290f;

public PageHelper Pages = new PageHelper();

Expand Down Expand Up @@ -245,11 +244,7 @@ public override void DrawValue(Rect window, float width)
return;
}

float whitespace = WhiteSpace;
if (whitespace > 0)
{
ClampLabelWidth(window, ref whitespace);
}
var whitespace = CalcWhitespace(window);

int count = m_cachedEntries.Length;

Expand Down
4 changes: 1 addition & 3 deletions src/CachedObjects/Other/CacheMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ public void Evaluate()
}
else
{
var parsedArgs = ParseArguments();

try
{
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, parsedArgs.ToArray());
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, ParseArguments());
m_evaluated = true;
}
catch (Exception e)
Expand Down
7 changes: 1 addition & 6 deletions src/CachedObjects/Struct/CacheColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class CacheColor : CacheObjectBase, IExpandHeight

public bool IsExpanded { get; set; }
public float WhiteSpace { get; set; } = 215f;
public float ButtonWidthOffset { get; set; } = 290f;

public override void UpdateValue()
{
Expand Down Expand Up @@ -59,11 +58,7 @@ public override void DrawValue(Rect window, float width)
{
GUILayout.EndHorizontal();

float whitespace = WhiteSpace;
if (whitespace > 0)
{
ClampLabelWidth(window, ref whitespace);
}
var whitespace = CalcWhitespace(window);

GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
Expand Down
7 changes: 1 addition & 6 deletions src/CachedObjects/Struct/CacheQuaternion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class CacheQuaternion : CacheObjectBase, IExpandHeight

public bool IsExpanded { get; set; }
public float WhiteSpace { get; set; } = 215f;
public float ButtonWidthOffset { get; set; } = 290f;

public override void UpdateValue()
{
Expand Down Expand Up @@ -54,11 +53,7 @@ public override void DrawValue(Rect window, float width)
{
GUILayout.EndHorizontal();

float whitespace = WhiteSpace;
if (whitespace > 0)
{
ClampLabelWidth(window, ref whitespace);
}
var whitespace = CalcWhitespace(window);

GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
Expand Down
7 changes: 1 addition & 6 deletions src/CachedObjects/Struct/CacheRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class CacheRect : CacheObjectBase, IExpandHeight

public bool IsExpanded { get; set; }
public float WhiteSpace { get; set; } = 215f;
public float ButtonWidthOffset { get; set; } = 290f;

public override void UpdateValue()
{
Expand Down Expand Up @@ -56,11 +55,7 @@ public override void DrawValue(Rect window, float width)
{
GUILayout.EndHorizontal();

float whitespace = WhiteSpace;
if (whitespace > 0)
{
ClampLabelWidth(window, ref whitespace);
}
var whitespace = CalcWhitespace(window);

GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
Expand Down
8 changes: 2 additions & 6 deletions src/CachedObjects/Struct/CacheVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class CacheVector : CacheObjectBase, IExpandHeight

public bool IsExpanded { get; set; }
public float WhiteSpace { get; set; } = 215f;
public float ButtonWidthOffset { get; set; } = 290f;

public override void Init()
{
Expand Down Expand Up @@ -90,11 +89,8 @@ public override void DrawValue(Rect window, float width)
if (CanWrite && IsExpanded)
{
GUILayout.EndHorizontal();
float whitespace = WhiteSpace;
if (whitespace > 0)
{
ClampLabelWidth(window, ref whitespace);
}

var whitespace = CalcWhitespace(window);

// always draw x and y
GUILayout.BeginHorizontal(null);
Expand Down
20 changes: 8 additions & 12 deletions src/CppExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Explorer
public class CppExplorer : MelonMod
{
public const string NAME = "CppExplorer";
public const string VERSION = "1.6.5";
public const string VERSION = "1.6.7";
public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.cppexplorer";

Expand Down Expand Up @@ -44,7 +44,11 @@ private static void SetShowMenu(bool show)
UpdateCursorControl();
}

// ========== MonoBehaviour methods ==========
private static void SetForceUnlock(bool unlock)
{
m_forceUnlock = unlock;
UpdateCursorControl();
}

public override void OnApplicationStart()
{
Expand All @@ -60,9 +64,9 @@ public override void OnApplicationStart()
m_lastVisibleState = Cursor.visible;

// Enable ShowMenu and ForceUnlockMouse
// (set m_showMenu to not call UpdateCursorState twice)
// (set m_showMenu directly to not call UpdateCursorState twice)
m_showMenu = true;
SetForceUnlock(true);
ForceUnlockMouse = true;

MelonLogger.Log($"CppExplorer {VERSION} initialized.");
}
Expand Down Expand Up @@ -104,14 +108,6 @@ public override void OnGUI()
InspectUnderMouse.OnGUI();
}

// =========== Cursor control ===========

private static void SetForceUnlock(bool unlock)
{
m_forceUnlock = unlock;
UpdateCursorControl();
}

private static void UpdateCursorControl()
{
m_currentlySettingCursor = true;
Expand Down
2 changes: 1 addition & 1 deletion src/CppExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Helpers\IExpandHeight.cs" />
<Compile Include="CachedObjects\IExpandHeight.cs" />
<Compile Include="CachedObjects\Struct\CacheColor.cs" />
<Compile Include="CachedObjects\Object\CacheDictionary.cs" />
<Compile Include="CachedObjects\Struct\CacheEnum.cs" />
Expand Down
Loading

0 comments on commit a927b5e

Please sign in to comment.