mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
WIP option toggling
This commit is contained in:
1 parent
d313089521
commit
59b8e92c48
5 files changed
+85
-5
No files matched your search
@@ -42,6 +42,11 @@ public abstract class AbstractGameMode : IOptionable
|
||||
/// </summary>
|
||||
public virtual bool IsHideAndSeek => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the gamemode removes the normal game settings.
|
||||
/// </summary>
|
||||
public virtual bool ShowNormalGameSettings => true;
|
||||
|
||||
/// <summary>
|
||||
/// Called on GameManager.GetBodyType().
|
||||
/// </summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using Il2CppSystem;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Patches.GameModes;
|
||||
using MiraAPI.Patches.Options;
|
||||
using Reactor.Localization.Utilities;
|
||||
@@ -54,16 +55,23 @@ public static class GameModeOption
|
||||
if (!Values.ContainsKey(opt))
|
||||
Values.Add(opt, CustomStringName.CreateAndRegister(opt));
|
||||
}
|
||||
|
||||
private static List<CategoryHeaderMasked> VanillaCategories = new();
|
||||
private static List<OptionBehaviour> VanillaOptions = new();
|
||||
private static List<CategoryHeaderMasked> BaseCategories = new();
|
||||
private static List<OptionBehaviour> BaseOptions = new();
|
||||
[HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.CreateSettings))]
|
||||
[HarmonyPostfix]
|
||||
private static void CreateSettingsPatch(GameOptionsMenu __instance)
|
||||
{
|
||||
if (GameSettingMenuPatches.SelectedModIdx != 0)
|
||||
if (GameSettingMenuPatches.SelectedModIdx != 0 || GameManager.Instance.IsHideAndSeek() || CustomGameModeManager.ActiveMode == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (GameManager.Instance.IsHideAndSeek())
|
||||
return;
|
||||
VanillaCategories.Clear();
|
||||
VanillaOptions.Clear();
|
||||
BaseCategories.Clear();
|
||||
BaseOptions.Clear();
|
||||
float num = 0.713f;
|
||||
foreach (var category in __instance.settingsContainer.GetComponentsInChildren<CategoryHeaderMasked>())
|
||||
{
|
||||
@@ -71,6 +79,21 @@ public static class GameModeOption
|
||||
category.gameObject.transform.localPosition -= new Vector3(0, 1.3f, 0);
|
||||
}
|
||||
|
||||
var showOpts = CustomGameModeManager.ActiveMode.ShowNormalGameSettings;
|
||||
|
||||
var newList = __instance.Children.ToArray();
|
||||
BaseOptions.Add(newList[0]);
|
||||
foreach (var obj in newList.Skip(1))
|
||||
{
|
||||
VanillaOptions.Add(obj);
|
||||
obj.gameObject.SetActive(showOpts);
|
||||
}
|
||||
foreach (var category in __instance.settingsContainer.GetComponentsInChildren<CategoryHeaderMasked>())
|
||||
{
|
||||
VanillaCategories.Add(category);
|
||||
category.gameObject.SetActive(showOpts);
|
||||
}
|
||||
|
||||
CategoryHeaderMasked categoryHeaderMasked = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer);
|
||||
categoryHeaderMasked.SetHeader(CustomName, 20);
|
||||
categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f;
|
||||
@@ -95,15 +118,60 @@ public static class GameModeOption
|
||||
_lastValue = opt.GetInt();
|
||||
CustomGameModeManager.SetGameMode((uint)_lastValue);
|
||||
HudPatches.SetGameModeText(Values.ElementAt(_lastValue).Key);
|
||||
__instance.RefreshOptions(CustomGameModeManager.ActiveMode);
|
||||
});
|
||||
foreach (var optionBehaviour in __instance.Children.ToArray().Skip(1))
|
||||
{
|
||||
optionBehaviour.gameObject.transform.localPosition -= new Vector3(0, 1.3f, 0);
|
||||
}
|
||||
__instance.Children.Add(OptionBehaviour);
|
||||
__instance.scrollBar.SetYBoundsMax(__instance.scrollBar.GetYBounds().max + 1);
|
||||
BaseCategories.Add(categoryHeaderMasked);
|
||||
BaseOptions.Add(OptionBehaviour);
|
||||
for (var i = 1; i < Values.Count; i++)
|
||||
OptionBehaviour.Values = (Il2CppStructArray<StringNames>)OptionBehaviour.Values.Add(Values.ElementAt(i).Value);
|
||||
__instance.RefreshOptions(CustomGameModeManager.ActiveMode);
|
||||
}
|
||||
|
||||
private static void RefreshOptions(this GameOptionsMenu instance, AbstractGameMode mode)
|
||||
{
|
||||
instance.Children.Clear();
|
||||
foreach (var group in BaseOptions)
|
||||
{
|
||||
instance.Children.Add(group);
|
||||
}
|
||||
|
||||
var showOpts = mode.ShowNormalGameSettings;
|
||||
var num = 0.083f;
|
||||
foreach (var category in VanillaCategories)
|
||||
{
|
||||
category.gameObject.SetActive(showOpts);
|
||||
}
|
||||
if (showOpts)
|
||||
{
|
||||
foreach (var obj in VanillaOptions)
|
||||
{
|
||||
obj.gameObject.SetActive(true);
|
||||
instance.Children.Add(obj);
|
||||
}
|
||||
instance.scrollBar.SetYBoundsMax(instance.scrollBar.GetYBounds().max + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var obj in VanillaOptions)
|
||||
{
|
||||
obj.gameObject.SetActive(false);
|
||||
}
|
||||
/*var filteredGroups =
|
||||
ModdedOptionsManager.GameModeOptionGroups
|
||||
.Where(x => x.Key == mode.GetType()) ?? [];
|
||||
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
GameOptionsMenuPatch.UpdateGroup(group.Value, ref num);
|
||||
}*/
|
||||
|
||||
instance.scrollBar.SetYBoundsMax(-num - 1.65f);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.ValueChanged))]
|
||||
|
||||
@@ -30,6 +30,7 @@ public class HideAndSeekMode : AbstractGameMode
|
||||
public override bool ShowGameModeIntroCutscene => true;
|
||||
public override bool GameModeBodyTypeOverride => true;
|
||||
public override bool IsHideAndSeek => true;
|
||||
public override bool ShowNormalGameSettings => false;
|
||||
|
||||
public override IEnumerator IntroCutscene(IntroCutscene __instance)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Reflection;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.Injection;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Networking;
|
||||
@@ -26,6 +27,7 @@ public static class ModdedOptionsManager
|
||||
|
||||
internal static readonly Dictionary<OptionBehaviour, ModdedPlayerOption> CreatedPlayerOptions = [];
|
||||
internal static readonly Dictionary<OptionBehaviour, ModdedStringOption> CreatedStringOptions = [];
|
||||
internal static readonly Dictionary<Type, AbstractOptionGroup> GameModeOptionGroups = [];
|
||||
internal static readonly Dictionary<uint, IModdedOption> ModdedOptions = [];
|
||||
internal static readonly List<AbstractOptionGroup> Groups = [];
|
||||
|
||||
@@ -70,6 +72,10 @@ public static class ModdedOptionsManager
|
||||
|
||||
Groups.Add(group);
|
||||
TypeToGroup.Add(type, group);
|
||||
if (group.OptionableType?.IsAssignableTo(typeof(AbstractGameMode)) == true)
|
||||
{
|
||||
GameModeOptionGroups.Add(group.OptionableType, group);
|
||||
}
|
||||
pluginInfo.InternalOptionGroups.Add(group);
|
||||
|
||||
typeof(OptionGroupSingleton<>).MakeGenericType(type)
|
||||
|
||||
@@ -72,7 +72,7 @@ internal static class GameOptionsMenuPatch
|
||||
__instance.scrollBar.SetYBoundsMax(-num - 1.65f);
|
||||
}
|
||||
|
||||
private static void UpdateGroup(AbstractOptionGroup group, ref float num)
|
||||
internal static void UpdateGroup(AbstractOptionGroup group, ref float num)
|
||||
{
|
||||
if (group.Options.Count == 0 || group.Header is null)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user