mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-19 15:51:54 +00:00
Make imgui Window use GUILayout
This commit is contained in:
3 files changed
+70
-3
No files matched your search
@@ -43,7 +43,7 @@ namespace Reactor.Debugger
|
||||
|
||||
public DebuggerComponent(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
TestWindow = new DragWindow(new Rect(20, 20, 120, 120), "Debugger", () =>
|
||||
TestWindow = new DragWindow(new Rect(20, 20, 0, 0), "Debugger", () =>
|
||||
{
|
||||
GUILayout.Label("Name: " + SaveManager.PlayerName, new Il2CppReferenceArray<GUILayoutOption>(0));
|
||||
DisableGameEnd = GUILayout.Toggle(DisableGameEnd, "Disable game end", new Il2CppReferenceArray<GUILayoutOption>(0));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using UnhollowerBaseLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@@ -29,6 +30,16 @@ namespace Reactor.Extensions
|
||||
return rect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset Rect size
|
||||
/// </summary>
|
||||
public static Rect ResetSize(this Rect rect)
|
||||
{
|
||||
rect.width = rect.height = 0;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create <see cref="Sprite"/> from <paramref name="tex"/>
|
||||
/// </summary>
|
||||
@@ -103,7 +114,8 @@ namespace Reactor.Extensions
|
||||
{
|
||||
if (Enabled)
|
||||
{
|
||||
Rect = GUI.Window(Id, Rect, Func, Title);
|
||||
Rect = Rect.ResetSize();
|
||||
Rect = GUILayout.Window(Id, Rect, Func, Title, new Il2CppReferenceArray<GUILayoutOption>(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,68 @@ namespace Reactor.Unstrip
|
||||
[HarmonyPatch(typeof(GUIUtility), nameof(GUIUtility.HasKeyFocus))]
|
||||
public static class HasKeyFocusPatch
|
||||
{
|
||||
public static bool Prefix(int controlID, ref bool __result)
|
||||
public static bool Prefix(int controlID, out bool __result)
|
||||
{
|
||||
__result = controlID == GUIUtility.keyboardControl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(GUILayout), nameof(GUILayout.DoWindow), typeof(int), typeof(Rect), typeof(GUI.WindowFunction), typeof(GUIContent), typeof(GUIStyle), typeof(Il2CppReferenceArray<GUILayoutOption>))]
|
||||
public static class DoWindowPatch
|
||||
{
|
||||
private sealed class LayoutedWindow
|
||||
{
|
||||
internal LayoutedWindow(GUI.WindowFunction f, Rect screenRect, GUIContent content, GUILayoutOption[] options, GUIStyle style)
|
||||
{
|
||||
this.m_Func = f;
|
||||
this.m_ScreenRect = screenRect;
|
||||
this.m_Options = options;
|
||||
this.m_Style = style;
|
||||
}
|
||||
|
||||
public void DoWindow(int windowID)
|
||||
{
|
||||
var topLevel = GUILayoutUtility.current.topLevel;
|
||||
var type = Event.current.type;
|
||||
if (type != EventType.Layout)
|
||||
{
|
||||
topLevel.ResetCursor();
|
||||
}
|
||||
else
|
||||
{
|
||||
topLevel.resetCoords = true;
|
||||
topLevel.rect = this.m_ScreenRect;
|
||||
var flag = this.m_Options != null;
|
||||
if (flag)
|
||||
{
|
||||
topLevel.ApplyOptions(this.m_Options);
|
||||
}
|
||||
|
||||
topLevel.isWindow = true;
|
||||
topLevel.windowID = windowID;
|
||||
topLevel.style = this.m_Style;
|
||||
}
|
||||
|
||||
this.m_Func.Invoke(windowID);
|
||||
}
|
||||
|
||||
private readonly GUI.WindowFunction m_Func;
|
||||
private readonly Rect m_ScreenRect;
|
||||
private readonly GUILayoutOption[] m_Options;
|
||||
private readonly GUIStyle m_Style;
|
||||
}
|
||||
|
||||
public static bool Prefix(int id, Rect screenRect, GUI.WindowFunction func, GUIContent content, GUIStyle style, Il2CppReferenceArray<GUILayoutOption> options, out Rect __result)
|
||||
{
|
||||
GUIUtility.CheckOnGUI();
|
||||
var @object = new LayoutedWindow(func, screenRect, content, options, style);
|
||||
__result = GUI.Window(id, screenRect, (GUI.WindowFunction) @object.DoWindow, content, style);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(GUILayoutGroup), nameof(GUILayoutGroup.Add))]
|
||||
public static class AddPatch
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user