0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 01:30:45 -05:00

Update BundleUtils (!148)

- Fixes problems with `GUI.skin`
- More efficient code

No longer breaks other IMGUI elements from my testing as the `GUIStyle` is isolated. Please test with SAIN and other possible mods.

Co-authored-by: Lacyway <20912169+Lacyway@users.noreply.github.com>
Reviewed-on: SPT/Modules#148
Co-authored-by: Lacyway <lacyway@noreply.dev.sp-tarkov.com>
Co-committed-by: Lacyway <lacyway@noreply.dev.sp-tarkov.com>
This commit is contained in:
Lacyway 2024-07-08 11:35:20 +00:00 committed by chomp
parent a3404853ff
commit 34e84ff737

View File

@ -9,6 +9,10 @@ namespace SPT.Custom.Utils
private int maximum;
private string bundleName;
private Texture2D bgTexture;
private bool started;
private GUIStyle labelStyle;
private GUIStyle windowStyle;
private Rect windowRect;
public static BundleUtils Create()
{
@ -19,6 +23,7 @@ namespace SPT.Custom.Utils
bundleUtils.maximum = 0;
bundleUtils.enabled = true;
bundleUtils.bgTexture = new Texture2D(2, 2);
bundleUtils.windowRect = bundleUtils.CreateRectangle(500, 80);
return bundleUtils;
}
@ -41,12 +46,29 @@ namespace SPT.Custom.Utils
public void OnGUI()
{
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUI.skin.window.alignment = TextAnchor.MiddleCenter;
GUI.skin.window.normal.background = bgTexture;
GUI.backgroundColor = Color.black;
if (!started)
{
CreateStyles();
}
GUI.Window(0, CreateRectangle(500, 80), DrawWindow, "Bundle Loading");
GUI.backgroundColor = Color.black;
GUI.Window(0, windowRect, DrawWindow, "Bundle Loading", windowStyle);
}
private void CreateStyles()
{
labelStyle = new GUIStyle(GUI.skin.label)
{
alignment = TextAnchor.MiddleCenter
};
windowStyle = new GUIStyle(GUI.skin.window)
{
alignment = TextAnchor.UpperCenter
};
windowStyle.normal.background = bgTexture;
started = true;
}
private Rect CreateRectangle(int width, int height)
@ -59,8 +81,8 @@ namespace SPT.Custom.Utils
private void DrawWindow(int windowId)
{
GUI.Label(new Rect(0, 35, 500, 20), $"Loading bundle: {current} / {maximum}");
GUI.Label(new Rect(0, 50, 500, 20), bundleName);
GUI.Label(new Rect(0, 35, 500, 20), $"Loading bundle: {current} / {maximum}", labelStyle);
GUI.Label(new Rect(0, 50, 500, 20), bundleName, labelStyle);
}
}
}