* Fix for GuiLayout.Space unstrip
* Cleanups
This commit is contained in:
sinaioutlander 2020-09-12 00:59:59 +10:00
parent 8d648fec43
commit de663f34b2
19 changed files with 185 additions and 125 deletions

View File

@ -384,7 +384,7 @@ namespace Explorer
}
else
{
GUILayout.Space(labelWidth);
GUIUnstrip.Space(labelWidth);
}
var cm = this as CacheMethod;
@ -451,7 +451,7 @@ namespace Explorer
// new line and space
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(labelWidth);
GUIUnstrip.Space(labelWidth);
}
else if (cm != null)
{
@ -465,7 +465,7 @@ namespace Explorer
// new line and space
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(labelWidth);
GUIUnstrip.Space(labelWidth);
}
if (!string.IsNullOrEmpty(ReflectionException))

View File

@ -235,7 +235,7 @@ namespace Explorer
}
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
GUILayout.Space(5);
GUIUnstrip.Space(5);
if (IsExpanded)
{
@ -246,7 +246,7 @@ namespace Explorer
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
Pages.CurrentPageLabel();
@ -262,7 +262,7 @@ namespace Explorer
Pages.DrawLimitInputArea();
GUILayout.Space(5);
GUIUnstrip.Space(5);
}
int offset = Pages.CalculateOffsetIndex();
@ -276,7 +276,7 @@ namespace Explorer
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
//GUILayout.Space(whitespace);
//GUIUnstrip.Space(whitespace);
if (key == null || val == null)
{

View File

@ -297,7 +297,7 @@ namespace Explorer
}
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
GUILayout.Space(5);
GUIUnstrip.Space(5);
if (IsExpanded)
{
@ -308,7 +308,7 @@ namespace Explorer
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
Pages.CurrentPageLabel();
@ -324,7 +324,7 @@ namespace Explorer
Pages.DrawLimitInputArea();
GUILayout.Space(5);
GUIUnstrip.Space(5);
}
int offset = Pages.CalculateOffsetIndex();
@ -337,7 +337,7 @@ namespace Explorer
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
if (entry == null || entry.Value == null)
{

View File

@ -61,32 +61,32 @@ namespace Explorer
var whitespace = CalcWhitespace(window);
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("R:", new GUILayoutOption[] { GUILayout.Width(30) });
r = GUILayout.TextField(r, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("G:", new GUILayoutOption[] { GUILayout.Width(30) });
g = GUILayout.TextField(g, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("B:", new GUILayoutOption[] { GUILayout.Width(30) });
b = GUILayout.TextField(b, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("A:", new GUILayoutOption[] { GUILayout.Width(30) });
a = GUILayout.TextField(a, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
// draw set value button
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
if (GUILayout.Button("<color=lime>Apply</color>", new GUILayoutOption[] { GUILayout.Width(155) }))
{
SetValueFromInput();

View File

@ -92,7 +92,7 @@ namespace Explorer
}
}
GUILayout.Space(10);
GUIUnstrip.Space(10);
}
}

View File

@ -56,26 +56,26 @@ namespace Explorer
var whitespace = CalcWhitespace(window);
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) });
x = GUILayout.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) });
y = GUILayout.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("Z:", new GUILayoutOption[] { GUILayout.Width(30) });
z = GUILayout.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
// draw set value button
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
if (GUILayout.Button("<color=lime>Apply</color>", new GUILayoutOption[] { GUILayout.Width(155) }))
{
SetValueFromInput();

View File

@ -58,32 +58,32 @@ namespace Explorer
var whitespace = CalcWhitespace(window);
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) });
x = GUILayout.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) });
y = GUILayout.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("W:", new GUILayoutOption[] { GUILayout.Width(30) });
w = GUILayout.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("H:", new GUILayoutOption[] { GUILayout.Width(30) });
h = GUILayout.TextField(h, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
// draw set value button
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
if (GUILayout.Button("<color=lime>Apply</color>", new GUILayoutOption[] { GUILayout.Width(155) }))
{
SetValueFromInput();

View File

@ -94,13 +94,13 @@ namespace Explorer
// always draw x and y
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) });
x = GUILayout.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) });
y = GUILayout.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
@ -109,7 +109,7 @@ namespace Explorer
{
// draw z
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("Z:", new GUILayoutOption[] { GUILayout.Width(30) });
z = GUILayout.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
@ -118,7 +118,7 @@ namespace Explorer
{
// draw w
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
GUILayout.Label("W:", new GUILayoutOption[] { GUILayout.Width(30) });
w = GUILayout.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) });
GUILayout.EndHorizontal();
@ -126,7 +126,7 @@ namespace Explorer
// draw set value button
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
GUIUnstrip.Space(whitespace);
if (GUILayout.Button("<color=lime>Apply</color>", new GUILayoutOption[] { GUILayout.Width(155) }))
{
SetValueFromInput();

View File

@ -13,7 +13,7 @@ namespace Explorer
public class CppExplorer : MelonMod
{
public const string NAME = "CppExplorer";
public const string VERSION = "1.6.9";
public const string VERSION = "1.7.0";
public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.cppexplorer";

View File

@ -96,13 +96,14 @@
<Compile Include="Menu\CursorControl.cs" />
<Compile Include="Tests\TestClass.cs" />
<Compile Include="UnstripFixes\GUIUnstrip.cs" />
<Compile Include="UnstripFixes\LayoutUtilityUnstrip.cs" />
<Compile Include="UnstripFixes\ScrollViewStateUnstrip.cs" />
<Compile Include="Extensions\UnityExtensions.cs" />
<Compile Include="Helpers\PageHelper.cs" />
<Compile Include="Helpers\ReflectionHelpers.cs" />
<Compile Include="Helpers\UIHelpers.cs" />
<Compile Include="Helpers\UnityHelpers.cs" />
<Compile Include="Menu\MainMenu\InspectUnderMouse.cs" />
<Compile Include="Menu\InspectUnderMouse.cs" />
<Compile Include="CachedObjects\CacheObjectBase.cs" />
<Compile Include="UnstripFixes\SliderHandlerUnstrip.cs" />
<Compile Include="UnstripFixes\UnstripExtensions.cs" />

View File

@ -24,16 +24,19 @@ namespace Explorer
public static bool ShouldForceMouse => CppExplorer.ShowMenu && ForceUnlockMouse;
private static Type CursorType => m_cursorType ?? (m_cursorType = ReflectionHelpers.GetTypeByName("UnityEngine.Cursor"));
private static Type m_cursorType;
public static void Init()
{
try
{
// Check if Cursor class is loaded
if (ReflectionHelpers.GetTypeByName("UnityEngine.Cursor") == null)
if (CursorType == null)
{
MelonLogger.Log("Trying to manually load Cursor module...");
if (ReflectionHelpers.LoadModule("UnityEngine.CoreModule"))
if (ReflectionHelpers.LoadModule("UnityEngine.CoreModule") && CursorType != null)
{
MelonLogger.Log("Ok!");
}
@ -47,11 +50,12 @@ namespace Explorer
m_lastLockMode = Cursor.lockState;
m_lastVisibleState = Cursor.visible;
TryPatch("lockState", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Prefix_set_lockState))), false, false);
TryPatch("visible", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Prefix_set_visible))), false, false);
// Setup Harmony Patches
TryPatch("lockState", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Prefix_set_lockState))), true);
TryPatch("lockState", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Postfix_get_lockState))), false);
TryPatch("lockState", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Postfix_get_lockState))), true, true);
TryPatch("visible", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Postfix_get_visible))), true, true);
TryPatch("visible", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Prefix_set_visible))), true);
TryPatch("visible", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Postfix_get_visible))), false);
}
catch (Exception e)
{
@ -64,18 +68,23 @@ namespace Explorer
ForceUnlockMouse = true;
}
private static void TryPatch(string property, HarmonyMethod patch, bool getter = true, bool postfix = false)
private static void TryPatch(string property, HarmonyMethod patch, bool setter)
{
// Setup Harmony Patches
try
{
var harmony = CppExplorer.Instance.harmonyInstance;
var prop = typeof(Cursor).GetProperty(property);
harmony.Patch(getter ? prop.GetGetMethod() : prop.GetSetMethod(),
postfix ? null : patch,
postfix ? patch : null);
if (setter)
{
// setter is prefix
harmony.Patch(prop.GetSetMethod(), patch);
}
else
{
// getter is postfix
harmony.Patch(prop.GetGetMethod(), null, patch);
}
}
catch (Exception e)
{
@ -170,69 +179,5 @@ namespace Explorer
__result = m_lastVisibleState;
}
}
//[HarmonyPatch(typeof(Cursor), nameof(Cursor.lockState), MethodType.Setter)]
//public class Cursor_set_lockState
//{
// [HarmonyPrefix]
// public static void Prefix(ref CursorLockMode value)
// {
// if (!m_currentlySettingCursor)
// {
// m_lastLockMode = value;
// if (ShouldForceMouse)
// {
// value = CursorLockMode.None;
// }
// }
// }
//}
//[HarmonyPatch(typeof(Cursor), nameof(Cursor.visible), MethodType.Setter)]
//public class Cursor_set_visible
//{
// [HarmonyPrefix]
// public static void Prefix(ref bool value)
// {
// if (!m_currentlySettingCursor)
// {
// m_lastVisibleState = value;
// if (ShouldForceMouse)
// {
// value = true;
// }
// }
// }
//}
//// Make it appear as though UnlockMouse is disabled to the rest of the application.
//[HarmonyPatch(typeof(Cursor), nameof(Cursor.lockState), MethodType.Getter)]
//public class Cursor_get_lockState
//{
// [HarmonyPostfix]
// public static void Postfix(ref CursorLockMode __result)
// {
// if (ShouldForceMouse)
// {
// __result = m_lastLockMode;
// }
// }
//}
//[HarmonyPatch(typeof(Cursor), nameof(Cursor.visible), MethodType.Getter)]
//public class Cursor_get_visible
//{
// [HarmonyPostfix]
// public static void Postfix(ref bool __result)
// {
// if (ShouldForceMouse)
// {
// __result = m_lastVisibleState;
// }
// }
//}
}
}

View File

@ -110,7 +110,9 @@ namespace Explorer
WindowManager.TabView = GUILayout.Toggle(WindowManager.TabView, "Tab View", null);
GUILayout.EndHorizontal();
GUILayout.Space(10);
//GUIUnstrip.Space(10);
GUIUnstrip.Space(10);
GUI.color = Color.white;
}
}

View File

@ -244,7 +244,7 @@ namespace Explorer
}
GUILayout.EndHorizontal();
GUILayout.Space(5);
GUIUnstrip.Space(5);
}
private void SceneChangeButtons()

View File

@ -385,7 +385,7 @@ namespace Explorer
}
else
{
GUILayout.Space(26);
GUIUnstrip.Space(26);
}
if (GUILayout.Button("<color=cyan>" + ilType.Name + "</color>", new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 100) }))
{

View File

@ -288,7 +288,7 @@ namespace Explorer
GUI.color = Color.white;
GUILayout.EndHorizontal();
GUILayout.Space(10);
GUIUnstrip.Space(10);
Pages.ItemCount = m_cachedMembersFiltered.Length;
@ -317,7 +317,7 @@ namespace Explorer
scroll = GUIUnstrip.BeginScrollView(scroll);
GUILayout.Space(10);
GUIUnstrip.Space(10);
UIStyles.HorizontalLine(Color.grey);

View File

@ -32,7 +32,7 @@ namespace Explorer
GUILayout.Button(gcDrag, GUI.skin.label, new GUILayoutOption[] { GUILayout.Height(15) });
//var r = GUILayoutUtility.GetLastRect();
var r = GUIUnstrip.GetLastRect();
var r = LayoutUtilityUnstrip.GetLastRect();
var mousePos = InputHelper.mousePosition;

View File

@ -42,20 +42,20 @@ namespace Explorer
}
private static PropertyInfo m_scrollViewStatesInfo;
public static Rect GetLastRect()
public static void Space(float pixels)
{
EventType type = Event.current.type;
Rect last;
if (type != EventType.Layout && type != EventType.Used)
{
last = GUILayoutUtility.current.topLevel.GetLastUnstripped();
}
GUIUtility.CheckOnGUI();
if (GUILayoutUtility.current.topLevel.isVertical)
LayoutUtilityUnstrip.GetRect(0, pixels, GUILayoutUtility.spaceStyle, new GUILayoutOption[] { GUILayout.Height(pixels) });
else
LayoutUtilityUnstrip.GetRect(pixels, 0, GUILayoutUtility.spaceStyle, new GUILayoutOption[] { GUILayout.Width(pixels) });
if (Event.current.type == EventType.Layout)
{
last = GUILayoutUtility.kDummyRect;
GUILayoutUtility.current.topLevel.entries[GUILayoutUtility.current.topLevel.entries.Count - 1].consideredForMargin = false;
}
return last;
}
// Fix for BeginScrollView.

View File

@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Explorer
{
public class LayoutUtilityUnstrip
{
public static Rect GetRect(float width, float height) { return DoGetRect(width, width, height, height, GUIStyle.none, null); }
public static Rect GetRect(float width, float height, GUIStyle style) { return DoGetRect(width, width, height, height, style, null); }
public static Rect GetRect(float width, float height, params GUILayoutOption[] options) { return DoGetRect(width, width, height, height, GUIStyle.none, options); }
// Reserve layout space for a rectangle with a fixed content area.
public static Rect GetRect(float width, float height, GUIStyle style, params GUILayoutOption[] options)
{ return DoGetRect(width, width, height, height, style, options); }
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight)
{ return DoGetRect(minWidth, maxWidth, minHeight, maxHeight, GUIStyle.none, null); }
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, GUIStyle style)
{ return DoGetRect(minWidth, maxWidth, minHeight, maxHeight, style, null); }
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, params GUILayoutOption[] options)
{ return DoGetRect(minWidth, maxWidth, minHeight, maxHeight, GUIStyle.none, options); }
// Reserve layout space for a flexible rect.
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, GUIStyle style, params GUILayoutOption[] options)
{ return DoGetRect(minWidth, maxWidth, minHeight, maxHeight, style, options); }
static Rect DoGetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, GUIStyle style, GUILayoutOption[] options)
{
switch (Event.current.type)
{
case EventType.Layout:
GUILayoutUtility.current.topLevel.Add(new GUILayoutEntry(minWidth, maxWidth, minHeight, maxHeight, style, options));
return GUILayoutUtility.kDummyRect;
case EventType.Used:
return GUILayoutUtility.kDummyRect;
default:
return GUILayoutUtility.current.topLevel.GetNext().rect;
}
}
public static Rect GetRect(GUIContent content, GUIStyle style) { return DoGetRect(content, style, null); }
// Reserve layout space for a rectangle for displaying some contents with a specific style.
public static Rect GetRect(GUIContent content, GUIStyle style, params GUILayoutOption[] options) { return DoGetRect(content, style, options); }
static Rect DoGetRect(GUIContent content, GUIStyle style, GUILayoutOption[] options)
{
GUIUtility.CheckOnGUI();
switch (Event.current.type)
{
case EventType.Layout:
if (style.isHeightDependantOnWidth)
{
GUILayoutUtility.current.topLevel.Add(new GUIWordWrapSizer(style, content, options));
}
else
{
Vector2 sizeConstraints = new Vector2(0, 0);
if (options != null)
{
foreach (var option in options)
{
if (float.TryParse(option.value.ToString(), out float f))
{
switch (option.type)
{
case GUILayoutOption.Type.maxHeight:
sizeConstraints.y = f;
break;
case GUILayoutOption.Type.maxWidth:
sizeConstraints.x = f;
break;
}
}
}
}
Vector2 size = style.CalcSizeWithConstraints(content, sizeConstraints);
// This is needed on non-integer scale ratios to avoid errors to accumulate in further layout calculations
size.x = Mathf.Ceil(size.x);
size.y = Mathf.Ceil(size.y);
GUILayoutUtility.current.topLevel.Add(new GUILayoutEntry(size.x, size.x, size.y, size.y, style, options));
}
return GUILayoutUtility.kDummyRect;
case EventType.Used:
return GUILayoutUtility.kDummyRect;
default:
var entry = GUILayoutUtility.current.topLevel.GetNext();
//GUIDebugger.LogLayoutEntry(entry.rect, entry.marginLeft, entry.marginRight, entry.marginTop, entry.marginBottom, entry.style);
return entry.rect;
}
}
public static Rect GetLastRect()
{
EventType type = Event.current.type;
Rect last;
if (type != EventType.Layout && type != EventType.Used)
{
last = GUILayoutUtility.current.topLevel.GetLastUnstripped();
}
else
{
last = GUILayoutUtility.kDummyRect;
}
return last;
}
}
}