From 5de771389ee12a7df946b73ce121433ad7599678 Mon Sep 17 00:00:00 2001
From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com>
Date: Fri, 4 Sep 2020 01:27:44 +1000
Subject: [PATCH] 1.5.3
* Added exception handling for scrollview when unstripping fails
* Added some better logging in some places
---
src/CppExplorer.cs | 4 +++-
src/Helpers/UIHelpers.cs | 29 +++++++++++++++++++++++++++++
src/MainMenu/MainMenu.cs | 18 +++++++++---------
src/MainMenu/Pages/SearchPage.cs | 4 ++--
src/Windows/GameObjectWindow.cs | 22 +++++++++++-----------
src/Windows/ReflectionWindow.cs | 4 ++--
6 files changed, 56 insertions(+), 25 deletions(-)
diff --git a/src/CppExplorer.cs b/src/CppExplorer.cs
index 933bd4a..d9dd74d 100644
--- a/src/CppExplorer.cs
+++ b/src/CppExplorer.cs
@@ -12,7 +12,7 @@ namespace Explorer
public class CppExplorer : MelonMod
{
public const string GUID = "com.sinai.cppexplorer";
- public const string VERSION = "1.5.2";
+ public const string VERSION = "1.5.3";
public const string AUTHOR = "Sinai";
public const string NAME = "CppExplorer"
@@ -99,6 +99,8 @@ namespace Explorer
public override void OnGUI()
{
+ if (!ShowMenu) return;
+
MainMenu.Instance.OnGUI();
WindowManager.Instance.OnGUI();
InspectUnderMouse.OnGUI();
diff --git a/src/Helpers/UIHelpers.cs b/src/Helpers/UIHelpers.cs
index 922eff6..c7a7db1 100644
--- a/src/Helpers/UIHelpers.cs
+++ b/src/Helpers/UIHelpers.cs
@@ -10,6 +10,35 @@ namespace Explorer
{
public class UIHelpers
{
+ private static bool ScrollUnstrippingFailed = false;
+
+ public static Vector2 BeginScrollView(Vector2 scroll) => BeginScrollView(scroll, null);
+
+ public static Vector2 BeginScrollView(Vector2 scroll, GUIStyle style, params GUILayoutOption[] layoutOptions)
+ {
+ if (ScrollUnstrippingFailed) return scroll;
+
+ try
+ {
+ if (style != null)
+ return GUILayout.BeginScrollView(scroll, style, layoutOptions);
+ else
+ return GUILayout.BeginScrollView(scroll, layoutOptions);
+ }
+ catch
+ {
+ ScrollUnstrippingFailed = true;
+ return scroll;
+ }
+ }
+
+ public static void EndScrollView()
+ {
+ if (ScrollUnstrippingFailed) return;
+
+ GUILayout.EndScrollView();
+ }
+
// helper for "Instantiate" button on UnityEngine.Objects
public static void InstantiateButton(Object obj, float width = 100)
{
diff --git a/src/MainMenu/MainMenu.cs b/src/MainMenu/MainMenu.cs
index 5081f67..84c7790 100644
--- a/src/MainMenu/MainMenu.cs
+++ b/src/MainMenu/MainMenu.cs
@@ -51,15 +51,12 @@ namespace Explorer
public void OnGUI()
{
- if (CppExplorer.ShowMenu)
- {
- var origSkin = GUI.skin;
- GUI.skin = UIStyles.WindowSkin;
+ var origSkin = GUI.skin;
+ GUI.skin = UIStyles.WindowSkin;
- MainRect = GUI.Window(MainWindowID, MainRect, (GUI.WindowFunction)MainWindow, CppExplorer.NAME);
+ MainRect = GUI.Window(MainWindowID, MainRect, (GUI.WindowFunction)MainWindow, CppExplorer.NAME);
- GUI.skin = origSkin;
- }
+ GUI.skin = origSkin;
}
private void MainWindow(int id)
@@ -77,9 +74,12 @@ namespace Explorer
MainHeader();
var page = Pages[m_currentPage];
- page.scroll = GUILayout.BeginScrollView(page.scroll, GUI.skin.scrollView);
+
+ page.scroll = UIHelpers.BeginScrollView(page.scroll);
+
page.DrawWindow();
- GUILayout.EndScrollView();
+
+ UIHelpers.EndScrollView();
MainRect = ResizeDrag.ResizeWindow(MainRect, MainWindowID);
diff --git a/src/MainMenu/Pages/SearchPage.cs b/src/MainMenu/Pages/SearchPage.cs
index abab30c..e078e62 100644
--- a/src/MainMenu/Pages/SearchPage.cs
+++ b/src/MainMenu/Pages/SearchPage.cs
@@ -132,7 +132,7 @@ namespace Explorer
GUILayout.EndHorizontal();
- resultsScroll = GUILayout.BeginScrollView(resultsScroll, GUI.skin.scrollView);
+ resultsScroll = UIHelpers.BeginScrollView(resultsScroll);
var _temprect = new Rect(MainMenu.MainRect.x, MainMenu.MainRect.y, MainMenu.MainRect.width + 160, MainMenu.MainRect.height);
@@ -153,7 +153,7 @@ namespace Explorer
GUILayout.Label("No results found!", null);
}
- GUILayout.EndScrollView();
+ UIHelpers.EndScrollView();
GUILayout.EndVertical();
}
catch
diff --git a/src/Windows/GameObjectWindow.cs b/src/Windows/GameObjectWindow.cs
index 908ee96..7fc86f9 100644
--- a/src/Windows/GameObjectWindow.cs
+++ b/src/Windows/GameObjectWindow.cs
@@ -73,8 +73,8 @@ namespace Explorer
m_name = m_object.name;
m_scene = string.IsNullOrEmpty(m_object.scene.name)
- ? "None"
- : m_object.scene.name;
+ ? "None"
+ : m_object.scene.name;
Update();
}
@@ -121,7 +121,7 @@ namespace Explorer
private void DestroyOnException(Exception e)
{
- MelonLogger.Log($"{e.GetType()}, {e.Message}");
+ MelonLogger.Log($"Exception drawing GameObject Window: {e.GetType()}, {e.Message}");
DestroyWindow();
}
@@ -169,7 +169,7 @@ namespace Explorer
GUILayout.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box);
}
- scroll = GUILayout.BeginScrollView(scroll, GUI.skin.scrollView);
+ scroll = UIHelpers.BeginScrollView(scroll);
GUILayout.BeginHorizontal(null);
GUILayout.Label("Scene: " + (m_scene == "" ? "n/a" : m_scene) + "", null);
@@ -220,7 +220,7 @@ namespace Explorer
GameObjectControls();
- GUILayout.EndScrollView();
+ UIHelpers.EndScrollView();
if (!WindowManager.TabView)
{
@@ -237,8 +237,8 @@ namespace Explorer
private void TransformList(Rect m_rect)
{
- GUILayout.BeginVertical(GUI.skin.box, null); // new GUILayoutOption[] { GUILayout.Height(250) });
- m_transformScroll = GUILayout.BeginScrollView(m_transformScroll, GUI.skin.scrollView);
+ GUILayout.BeginVertical(GUI.skin.box, null);
+ m_transformScroll = UIHelpers.BeginScrollView(m_transformScroll);
GUILayout.Label("Children", null);
@@ -287,14 +287,14 @@ namespace Explorer
GUILayout.Label("None", null);
}
- GUILayout.EndScrollView();
+ UIHelpers.EndScrollView();
GUILayout.EndVertical();
}
private void ComponentList(Rect m_rect)
{
- GUILayout.BeginVertical(GUI.skin.box, null); // new GUILayoutOption[] { GUILayout.Height(250) });
- m_compScroll = GUILayout.BeginScrollView(m_compScroll, GUI.skin.scrollView);
+ GUILayout.BeginVertical(GUI.skin.box, null);
+ m_compScroll = UIHelpers.BeginScrollView(m_compScroll);
GUILayout.Label("Components", null);
GUILayout.BeginHorizontal(null);
@@ -369,7 +369,7 @@ namespace Explorer
}
}
- GUILayout.EndScrollView();
+ UIHelpers.EndScrollView();
GUILayout.EndVertical();
}
diff --git a/src/Windows/ReflectionWindow.cs b/src/Windows/ReflectionWindow.cs
index 6132843..7d787a0 100644
--- a/src/Windows/ReflectionWindow.cs
+++ b/src/Windows/ReflectionWindow.cs
@@ -283,7 +283,7 @@ namespace Explorer
// ====== BODY ======
- scroll = GUILayout.BeginScrollView(scroll, GUI.skin.scrollView);
+ scroll = UIHelpers.BeginScrollView(scroll);
GUILayout.Space(10);
@@ -316,7 +316,7 @@ namespace Explorer
}
GUILayout.EndVertical();
- GUILayout.EndScrollView();
+ UIHelpers.EndScrollView();
if (!WindowManager.TabView)
{