mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Some stuff
This commit is contained in:
1 parent
658e3659c5
commit
2348863386
4 files changed
+37
-39
No files matched your search
@@ -4,7 +4,6 @@ using MiraAPI.GameOptions;
|
||||
using MiraAPI.Networking.Options;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -19,15 +18,10 @@ public static class CustomOptionsManager
|
||||
public static readonly List<CustomToggleOption> CustomToggleOptions = [];
|
||||
public static readonly List<CustomStringOption> CustomStringOptions = [];
|
||||
public static readonly List<CustomOptionGroup> CustomGroups = [];
|
||||
public static readonly List<PluginInfo> RegisteredMods = [];
|
||||
public static readonly Dictionary<PluginInfo, IModOptions> RegisteredMods = [];
|
||||
|
||||
public static void RegisterOptionsForMod(Type type, List<FieldInfo> fields, string modId)
|
||||
public static void RegisterOptionsForMod(IModOptions type, List<FieldInfo> fields, string modId)
|
||||
{
|
||||
if (!typeof(IModOptions).IsAssignableFrom(type))
|
||||
{
|
||||
Debug.LogError($"Cannot register options for {modId}! Missing IModOptions interface.");
|
||||
return;
|
||||
}
|
||||
PluginInfo info = IL2CPPChainloader.Instance.Plugins[modId];
|
||||
|
||||
if (info == null)
|
||||
@@ -37,7 +31,8 @@ public static class CustomOptionsManager
|
||||
|
||||
Debug.Log($"Registering Options for {modId}");
|
||||
|
||||
RegisteredMods.Add(info);
|
||||
RegisteredMods.Add(info, type);
|
||||
|
||||
foreach (FieldInfo field in fields)
|
||||
{
|
||||
AbstractGameOption option = (AbstractGameOption)field.GetValue(null);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Reactor.Utilities.Extensions;
|
||||
using MiraAPI.GameOptions;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
@@ -10,22 +11,21 @@ public static class CustomOptionsTab
|
||||
{
|
||||
public static List<GameObject> CustomTabs;
|
||||
public static List<GameObject> CustomScreens;
|
||||
public static SpriteRenderer Rend;
|
||||
|
||||
public static GameObject Initialize(GameSettingMenu __instance)
|
||||
public static GameObject InitializeForMod(IModOptions modOptions, GameSettingMenu __instance)
|
||||
{
|
||||
var gameBtn = __instance.transform.FindChild("Header/Tabs/GameTab").gameObject;
|
||||
var roleBtn = __instance.transform.FindChild("Header/Tabs/RoleTab").gameObject;
|
||||
var screen = CreateNewMenu(__instance);
|
||||
var tab = CreateCustomTab(__instance, screen, gameBtn, roleBtn);
|
||||
var tab = CreateCustomTab(modOptions, __instance, screen, gameBtn, roleBtn);
|
||||
|
||||
CustomScreens.Add(screen);
|
||||
CustomTabs.Add(tab);
|
||||
|
||||
Rend = tab.transform.FindChild("Btn/Tab Background").GetComponent<SpriteRenderer>();
|
||||
Rend.enabled = false;
|
||||
SpriteRenderer rend = tab.transform.FindChild("Btn/Tab Background").GetComponent<SpriteRenderer>();
|
||||
rend.enabled = false;
|
||||
|
||||
UpdateListeners(__instance, gameBtn.GetComponentInChildren<PassiveButton>(), roleBtn.GetComponentInChildren<PassiveButton>(), Rend);
|
||||
UpdateListeners(__instance, gameBtn.GetComponentInChildren<PassiveButton>(), roleBtn.GetComponentInChildren<PassiveButton>(), rend);
|
||||
|
||||
var container = screen.transform.FindChild("GameGroup/SliderInner");
|
||||
container.DestroyChildren();
|
||||
@@ -34,6 +34,7 @@ public static class CustomOptionsTab
|
||||
return container.gameObject;
|
||||
}
|
||||
|
||||
|
||||
/*private static void CreateNewResetButton(GameSettingMenu __instance, Transform container)
|
||||
{
|
||||
var resetBtn = __instance.RegularGameSettings.transform.FindChild("GameGroup/SliderInner/ResetToDefault");
|
||||
@@ -111,7 +112,7 @@ public static class CustomOptionsTab
|
||||
return header.gameObject;
|
||||
}
|
||||
|
||||
public static GameObject CreateCustomTab(GameSettingMenu __instance, GameObject newSettings,
|
||||
public static GameObject CreateCustomTab(IModOptions options, GameSettingMenu __instance, GameObject newSettings,
|
||||
GameObject gameTab, GameObject roleTab)
|
||||
{
|
||||
var newTab = Object.Instantiate(gameTab, gameTab.transform.parent);
|
||||
@@ -128,7 +129,7 @@ public static class CustomOptionsTab
|
||||
btn.OnClick.AddListener((Action)TabAction);
|
||||
|
||||
var spriteRend = inside.GetComponentInChildren<SpriteRenderer>();
|
||||
//spriteRend.sprite = LaunchpadAssets.HackButton.LoadAsset();
|
||||
spriteRend.sprite = options.OptionsTabIcon.LoadAsset();
|
||||
spriteRend.gameObject.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
|
||||
|
||||
return newTab;
|
||||
|
||||
@@ -25,42 +25,45 @@ public static class GameSettingsMenuPatches
|
||||
|
||||
CustomOptionsTab.CustomTabs = new();
|
||||
|
||||
__instance.Tabs.transform.position += new Vector3(0.5f, 0, 0);
|
||||
_gameBtn = __instance.transform.FindChild("Header/Tabs/GameTab").gameObject;
|
||||
_roleBtn = __instance.transform.FindChild("Header/Tabs/RoleTab").gameObject;
|
||||
|
||||
var numberOpt = __instance.RegularGameSettings.GetComponentInChildren<NumberOption>();
|
||||
var toggleOpt = Object.FindObjectOfType<ToggleOption>();
|
||||
var stringOpt = __instance.RegularGameSettings.GetComponentInChildren<StringOption>();
|
||||
var container = GameManager.Instance.IsNormal() ? CustomOptionsTab.Initialize(__instance).transform : __instance.HideAndSeekScroller.Inner;
|
||||
|
||||
foreach (var group in CustomOptionsManager.CustomGroups.Where(group => group.AdvancedRole == null))
|
||||
foreach (var pair in CustomOptionsManager.RegisteredMods)
|
||||
{
|
||||
if (GameManager.Instance.IsNormal())
|
||||
var container = CustomOptionsTab.InitializeForMod(pair.Value, __instance).transform;
|
||||
|
||||
foreach (var group in CustomOptionsManager.CustomGroups.Where(group => group.AdvancedRole == null && group.ParentMod == pair.Key))
|
||||
{
|
||||
if (GameManager.Instance.IsNormal())
|
||||
{
|
||||
group.Header = CustomOptionsTab.CreateHeader(toggleOpt, container, group.Title);
|
||||
CreateOptionsFor(__instance, toggleOpt, numberOpt, stringOpt, container,
|
||||
group.CustomToggleOptions, group.CustomNumberOptions, group.CustomStringOptions);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!group.Options.Any(x => x.ShowInHideNSeek))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
group.Header = CustomOptionsTab.CreateHeader(toggleOpt, container, group.Title);
|
||||
__instance.AllHideAndSeekItems = __instance.AllHideAndSeekItems.Append(group.Header.transform).ToArray();
|
||||
|
||||
CreateOptionsFor(__instance, toggleOpt, numberOpt, stringOpt, container,
|
||||
group.CustomToggleOptions, group.CustomNumberOptions, group.CustomStringOptions);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!group.Options.Any(x => x.ShowInHideNSeek))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
group.Header = CustomOptionsTab.CreateHeader(toggleOpt, container, group.Title);
|
||||
__instance.AllHideAndSeekItems = __instance.AllHideAndSeekItems.Append(group.Header.transform).ToArray();
|
||||
|
||||
CreateOptionsFor(__instance, toggleOpt, numberOpt, stringOpt, container,
|
||||
group.CustomToggleOptions, group.CustomNumberOptions, group.CustomStringOptions);
|
||||
CustomOptionsManager.CustomToggleOptions.Where(option => option.Group == null && option.ParentMod == pair.Key),
|
||||
CustomOptionsManager.CustomNumberOptions.Where(option => option.Group == null && option.ParentMod == pair.Key),
|
||||
CustomOptionsManager.CustomStringOptions.Where(option => option.Group == null && option.ParentMod == pair.Key));
|
||||
}
|
||||
|
||||
CreateOptionsFor(__instance, toggleOpt, numberOpt, stringOpt, container,
|
||||
CustomOptionsManager.CustomToggleOptions.Where(option => option.Group == null),
|
||||
CustomOptionsManager.CustomNumberOptions.Where(option => option.Group == null),
|
||||
CustomOptionsManager.CustomStringOptions.Where(option => option.Group == null));
|
||||
|
||||
if (!numberOpt || !toggleOpt || !stringOpt)
|
||||
{
|
||||
Logger<MiraAPIPlugin>.Error("OPTION PREFABS MISSING");
|
||||
@@ -84,7 +87,6 @@ public static class GameSettingsMenuPatches
|
||||
__instance.RolesSettings.gameObject.SetActive(false);
|
||||
|
||||
//CustomOptionsTab.CustomScreen.gameObject.SetActive(true);
|
||||
CustomOptionsTab.Rend.enabled = true;
|
||||
|
||||
__instance.GameSettingsHightlight.enabled = false;
|
||||
__instance.RolesSettingsHightlight.enabled = false;
|
||||
|
||||
@@ -89,7 +89,7 @@ public static class ToHudStringPatch
|
||||
|
||||
if (CurrentPage != 0)
|
||||
{
|
||||
PluginInfo currentPlugin = CustomOptionsManager.RegisteredMods[CurrentPage - 1];
|
||||
PluginInfo currentPlugin = CustomOptionsManager.RegisteredMods.Keys.ToArray()[CurrentPage - 1];
|
||||
if (currentPlugin == null)
|
||||
{
|
||||
CurrentPage = 0;
|
||||
|
||||
Reference in new issue
Block a user