mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-01-10 10:59:36 +08:00
Cleanup and improve syntax highlighting
* Static class members are now displayed in Italics and in a darker color, making them easier to distinguish. * Cleaned up some issues related to syntax highlighting and refactored it into a global class. * Methods and properties no longer display their arguments as part of the member name, they are only displayed when "Evaluate" is pressed.
This commit is contained in:
parent
5d58993b07
commit
db91968519
@ -400,10 +400,11 @@ namespace Explorer
|
|||||||
var input = m_argumentInput[i];
|
var input = m_argumentInput[i];
|
||||||
var type = m_arguments[i].ParameterType.Name;
|
var type = m_arguments[i].ParameterType.Name;
|
||||||
|
|
||||||
var label = "<color=#2df7b2>" + type + "</color> <color=#a6e9e9>" + name + "</color>";
|
var label = $"<color={UIStyles.Syntax.Class_Instance}>{type}</color> ";
|
||||||
|
label += $"<color={UIStyles.Syntax.Local}>{name}</color>";
|
||||||
if (m_arguments[i].HasDefaultValue)
|
if (m_arguments[i].HasDefaultValue)
|
||||||
{
|
{
|
||||||
label = $"<i>[{label} = {m_arguments[i].DefaultValue}]</i>";
|
label = $"<i>[{label} = {m_arguments[i].DefaultValue ?? "null"}]</i>";
|
||||||
}
|
}
|
||||||
|
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
@ -469,7 +470,7 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
else if ((HasParameters || this is CacheMethod) && !m_evaluated)
|
else if ((HasParameters || this is CacheMethod) && !m_evaluated)
|
||||||
{
|
{
|
||||||
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> (<color=#2df7b2>{ValueTypeName}</color>)", null);
|
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> (<color={UIStyles.Syntax.Class_Instance}>{ValueTypeName}</color>)", null);
|
||||||
}
|
}
|
||||||
else if (Value == null && !(this is CacheMethod))
|
else if (Value == null && !(this is CacheMethod))
|
||||||
{
|
{
|
||||||
@ -484,31 +485,62 @@ namespace Explorer
|
|||||||
private string GetRichTextName()
|
private string GetRichTextName()
|
||||||
{
|
{
|
||||||
string memberColor = "";
|
string memberColor = "";
|
||||||
switch (MemInfo.MemberType)
|
bool isStatic = false;
|
||||||
{
|
|
||||||
case MemberTypes.Field:
|
|
||||||
memberColor = "#c266ff"; break;
|
|
||||||
case MemberTypes.Property:
|
|
||||||
memberColor = "#72a6a6"; break;
|
|
||||||
case MemberTypes.Method:
|
|
||||||
memberColor = "#ff8000"; break;
|
|
||||||
};
|
|
||||||
|
|
||||||
m_richTextName = $"<color=#2df7b2>{MemInfo.DeclaringType.Name}</color>.<color={memberColor}>{MemInfo.Name}</color>";
|
if (MemInfo is FieldInfo fi)
|
||||||
|
|
||||||
if (m_arguments.Length > 0 || this is CacheMethod)
|
|
||||||
{
|
{
|
||||||
m_richTextName += "(";
|
if (fi.IsStatic)
|
||||||
var _params = "";
|
|
||||||
foreach (var param in m_arguments)
|
|
||||||
{
|
{
|
||||||
if (_params != "") _params += ", ";
|
isStatic = true;
|
||||||
|
memberColor = UIStyles.Syntax.Field_Static;
|
||||||
_params += $"<color=#2df7b2>{param.ParameterType.Name}</color> <color=#a6e9e9>{param.Name}</color>";
|
|
||||||
}
|
}
|
||||||
m_richTextName += _params;
|
else
|
||||||
m_richTextName += ")";
|
memberColor = UIStyles.Syntax.Field_Instance;
|
||||||
}
|
}
|
||||||
|
else if (MemInfo is MethodInfo mi)
|
||||||
|
{
|
||||||
|
if (mi.IsStatic)
|
||||||
|
{
|
||||||
|
isStatic = true;
|
||||||
|
memberColor = UIStyles.Syntax.Method_Static;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
memberColor = UIStyles.Syntax.Method_Instance;
|
||||||
|
}
|
||||||
|
else if (MemInfo is PropertyInfo pi)
|
||||||
|
{
|
||||||
|
if (pi.GetAccessors()[0].IsStatic)
|
||||||
|
{
|
||||||
|
isStatic = true;
|
||||||
|
memberColor = UIStyles.Syntax.Prop_Static;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
memberColor = UIStyles.Syntax.Prop_Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
string classColor = MemInfo.DeclaringType.IsAbstract && MemInfo.DeclaringType.IsSealed
|
||||||
|
? UIStyles.Syntax.Class_Static
|
||||||
|
: UIStyles.Syntax.Class_Instance;
|
||||||
|
|
||||||
|
m_richTextName = $"<color={classColor}>{MemInfo.DeclaringType.Name}</color>.";
|
||||||
|
if (isStatic) m_richTextName += "<i>";
|
||||||
|
m_richTextName += $"<color={memberColor}>{MemInfo.Name}</color>";
|
||||||
|
if (isStatic) m_richTextName += "</i>";
|
||||||
|
|
||||||
|
//if (m_arguments.Length > 0 || this is CacheMethod)
|
||||||
|
//{
|
||||||
|
// m_richTextName += "(";
|
||||||
|
// var args = "";
|
||||||
|
// foreach (var param in m_arguments)
|
||||||
|
// {
|
||||||
|
// if (args != "") args += ", ";
|
||||||
|
|
||||||
|
// args += $"<color={classColor}>{param.ParameterType.Name}</color> ";
|
||||||
|
// args += $"<color={UIStyles.Syntax.Local}>{param.Name}</color>";
|
||||||
|
// }
|
||||||
|
// m_richTextName += args;
|
||||||
|
// m_richTextName += ")";
|
||||||
|
//}
|
||||||
|
|
||||||
return m_richTextName;
|
return m_richTextName;
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,8 @@ namespace Explorer
|
|||||||
|
|
||||||
public override void DrawValue(Rect window, float width)
|
public override void DrawValue(Rect window, float width)
|
||||||
{
|
{
|
||||||
|
string typeLabel = $"<color={UIStyles.Syntax.Class_Instance}>{ValueTypeName}</color>";
|
||||||
|
|
||||||
if (m_evaluated)
|
if (m_evaluated)
|
||||||
{
|
{
|
||||||
if (m_cachedReturnValue != null)
|
if (m_cachedReturnValue != null)
|
||||||
@ -78,12 +80,12 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GUILayout.Label($"null (<color=#2df7b2>{ValueTypeName}</color>)", null);
|
GUILayout.Label($"null ({typeLabel})", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> (<color=#2df7b2>{ValueTypeName}</color>)", null);
|
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> ({typeLabel})", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,23 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
public class CacheOther : CacheObjectBase
|
public class CacheOther : CacheObjectBase
|
||||||
{
|
{
|
||||||
|
public string ButtonLabel => m_btnLabel ?? GetButtonLabel();
|
||||||
|
private string m_btnLabel;
|
||||||
|
|
||||||
|
public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod();
|
||||||
private MethodInfo m_toStringMethod;
|
private MethodInfo m_toStringMethod;
|
||||||
|
|
||||||
public MethodInfo ToStringMethod
|
public override void DrawValue(Rect window, float width)
|
||||||
{
|
{
|
||||||
get
|
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||||
|
if (GUILayout.Button(ButtonLabel, new GUILayoutOption[] { GUILayout.Width(width - 15) }))
|
||||||
{
|
{
|
||||||
if (m_toStringMethod == null)
|
WindowManager.InspectObject(Value, out bool _);
|
||||||
|
}
|
||||||
|
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MethodInfo GetToStringMethod()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -31,35 +41,42 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
m_toStringMethod = typeof(object).GetMethod("ToString", new Type[0]);
|
m_toStringMethod = typeof(object).GetMethod("ToString", new Type[0]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return m_toStringMethod;
|
return m_toStringMethod;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public override void DrawValue(Rect window, float width)
|
private string GetButtonLabel()
|
||||||
{
|
{
|
||||||
string label = (string)ToStringMethod?.Invoke(Value, null) ?? Value.ToString();
|
string label = (string)ToStringMethod?.Invoke(Value, null) ?? Value.ToString();
|
||||||
|
|
||||||
if (!label.Contains(ValueTypeName))
|
var classColor = ValueType.IsAbstract && ValueType.IsSealed
|
||||||
|
? UIStyles.Syntax.Class_Static
|
||||||
|
: UIStyles.Syntax.Class_Instance;
|
||||||
|
|
||||||
|
if (Value is UnityEngine.Object)
|
||||||
{
|
{
|
||||||
label += $" (<color=#2df7b2>{ValueTypeName}</color>)";
|
int typeStart = label.LastIndexOf("("); // get where the '(Type)' starts
|
||||||
|
var newLabel = label.Substring(0, typeStart + 1); // get just the name and first '('
|
||||||
|
newLabel += $"<color={classColor}>"; // add color tag
|
||||||
|
newLabel += label.Substring(typeStart + 1); // add the TypeName back in
|
||||||
|
newLabel = newLabel.Substring(0, newLabel.Length - 1); // remove the ending ')'
|
||||||
|
newLabel += "</color>)"; // close color tag and put the ')' back.
|
||||||
|
label = newLabel;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
label = label.Replace(ValueTypeName, $"<color=#2df7b2>{ValueTypeName}</color>");
|
string classLabel = $"<color={classColor}>{ValueTypeName}</color>";
|
||||||
|
|
||||||
|
if (!label.Contains(ValueTypeName))
|
||||||
|
{
|
||||||
|
label += $" ({classLabel})";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
label = label.Replace(ValueTypeName, $"<color={classColor}>{ValueTypeName}</color>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Value is UnityEngine.Object unityObj && !label.Contains(unityObj.name))
|
return m_btnLabel = label;
|
||||||
{
|
|
||||||
label = unityObj.name + " | " + label;
|
|
||||||
}
|
|
||||||
|
|
||||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
|
||||||
if (GUILayout.Button(label, new GUILayoutOption[] { GUILayout.Width(width - 15) }))
|
|
||||||
{
|
|
||||||
WindowManager.InspectObject(Value, out bool _);
|
|
||||||
}
|
|
||||||
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ namespace Explorer
|
|||||||
public class CppExplorer : MelonMod
|
public class CppExplorer : MelonMod
|
||||||
{
|
{
|
||||||
public const string NAME = "CppExplorer";
|
public const string NAME = "CppExplorer";
|
||||||
public const string VERSION = "1.7.31";
|
public const string VERSION = "1.7.4";
|
||||||
public const string AUTHOR = "Sinai";
|
public const string AUTHOR = "Sinai";
|
||||||
public const string GUID = "com.sinai.cppexplorer";
|
public const string GUID = "com.sinai.cppexplorer";
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ namespace Explorer
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MethodInput = @"// This is a basic C# REPL console.
|
MethodInput = @"// This is a basic C# console.
|
||||||
// Some common using directives are added by default, you can add more below.
|
// Some common using directives are added by default, you can add more below.
|
||||||
// If you want to return some output, MelonLogger.Log() it.
|
// If you want to return some output, MelonLogger.Log() it.
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ MelonLogger.Log(""hello world"");";
|
|||||||
|
|
||||||
public override void DrawWindow()
|
public override void DrawWindow()
|
||||||
{
|
{
|
||||||
GUILayout.Label("<b><size=15><color=cyan>C# REPL Console</color></size></b>", null);
|
GUILayout.Label("<b><size=15><color=cyan>C# Console</color></size></b>", null);
|
||||||
|
|
||||||
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||||
|
|
||||||
|
@ -11,6 +11,23 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
public class UIStyles
|
public class UIStyles
|
||||||
{
|
{
|
||||||
|
public class Syntax
|
||||||
|
{
|
||||||
|
public const string Field_Static = "#8d8dc6";
|
||||||
|
public const string Field_Instance = "#c266ff";
|
||||||
|
|
||||||
|
public const string Method_Static = "#b55b02";
|
||||||
|
public const string Method_Instance = "#ff8000";
|
||||||
|
|
||||||
|
public const string Prop_Static = "#588075";
|
||||||
|
public const string Prop_Instance = "#55a38e";
|
||||||
|
|
||||||
|
public const string Class_Static = "#3a8d71";
|
||||||
|
public const string Class_Instance = "#2df7b2";
|
||||||
|
|
||||||
|
public const string Local = "#a6e9e9";
|
||||||
|
}
|
||||||
|
|
||||||
public static Color LightGreen = new Color(Color.green.r - 0.3f, Color.green.g - 0.3f, Color.green.b - 0.3f);
|
public static Color LightGreen = new Color(Color.green.r - 0.3f, Color.green.g - 0.3f, Color.green.b - 0.3f);
|
||||||
|
|
||||||
public static GUISkin WindowSkin
|
public static GUISkin WindowSkin
|
||||||
|
@ -363,7 +363,8 @@ namespace Explorer
|
|||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
m_addComponentInput = GUILayout.TextField(m_addComponentInput, new GUILayoutOption[] { GUILayout.Width(130) });
|
var width = m_rect.width / 2 - 115f;
|
||||||
|
m_addComponentInput = GUILayout.TextField(m_addComponentInput, new GUILayoutOption[] { GUILayout.Width(width) });
|
||||||
if (GUILayout.Button("Add Comp", null))
|
if (GUILayout.Button("Add Comp", null))
|
||||||
{
|
{
|
||||||
if (ReflectionHelpers.GetTypeByName(m_addComponentInput) is Type compType)
|
if (ReflectionHelpers.GetTypeByName(m_addComponentInput) is Type compType)
|
||||||
|
@ -22,6 +22,10 @@ namespace Explorer.Tests
|
|||||||
ILHashSetTest.Add("3");
|
ILHashSetTest.Add("3");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int StaticProperty => 5;
|
||||||
|
public static int StaticField = 5;
|
||||||
|
public int NonStaticField;
|
||||||
|
|
||||||
// test a non-generic dictionary
|
// test a non-generic dictionary
|
||||||
|
|
||||||
public Hashtable TestNonGenericDict()
|
public Hashtable TestNonGenericDict()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user