mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Full gamemode option in vanilla Game Options menu.
This commit is contained in:
1 parent
8b19271e34
commit
44415019cc
7 files changed
+93
-46
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using MiraAPI.GameModes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.GameModes;
|
||||
|
||||
@@ -6,4 +7,5 @@ public class ExampleMode : AbstractGameMode
|
||||
{
|
||||
public override string Name => "Example Mode";
|
||||
public override string Description => "An example gamemode.";
|
||||
public override Color Color => Color.red;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.PluginLoading;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
@@ -45,7 +44,7 @@ public static class CustomGameModeManager
|
||||
|
||||
IdToModeMap.Add(GetNextId(), mode);
|
||||
pluginInfo.GameModes.Add(LastId, mode);
|
||||
|
||||
GameModeOption.AddOption($"<color=#{mode.Color.ToHtmlStringRGBA()}>{mode.Name}</color>");
|
||||
mode.ID = LastId;
|
||||
}
|
||||
|
||||
@@ -53,7 +52,7 @@ public static class CustomGameModeManager
|
||||
/// Checks to see if the default game mode is on.
|
||||
/// </summary>
|
||||
/// <returns>True if the default mode is one.</returns>
|
||||
public static bool IsDefault() => (uint)OptionGroupSingleton<GameModeOption>.Instance.CurrentMode.Value == 0;
|
||||
public static bool IsDefault() => (uint) GameModeOption.Value == 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current gamemode.
|
||||
@@ -64,6 +63,8 @@ public static class CustomGameModeManager
|
||||
{
|
||||
var defaultMode = new DefaultMode();
|
||||
IdToModeMap.Add(0, defaultMode);
|
||||
// no need to add to game mode option as it already contains it
|
||||
// because we cannot have the option be created with no values
|
||||
defaultMode.ID = 0;
|
||||
}
|
||||
|
||||
@@ -76,19 +77,14 @@ public static class CustomGameModeManager
|
||||
else if (id != 0)
|
||||
{
|
||||
ActiveMode = IdToModeMap[0];
|
||||
OptionGroupSingleton<GameModeOption>.Instance.CurrentMode.SetValue(0);
|
||||
GameModeOption.Value = 0;
|
||||
Logger<MiraApiPlugin>.Warning($"Unable to find game mode of id {id}!");
|
||||
}
|
||||
|
||||
if (OptionGroupSingleton<GameModeOption>.Instance.CurrentMode.OptionBehaviour != null && ActiveMode != null)
|
||||
{
|
||||
((NumberOption)OptionGroupSingleton<GameModeOption>.Instance.CurrentMode.OptionBehaviour).TitleText.SetText($"Game Mode: <color=#{ActiveMode.Color.ToHtmlStringRGBA()}>{ActiveMode}</color>");
|
||||
}
|
||||
}
|
||||
|
||||
internal static void GetAndSetGameMode()
|
||||
{
|
||||
var id = (uint)OptionGroupSingleton<GameModeOption>.Instance.CurrentMode.Value;
|
||||
var id = (uint)GameModeOption.Value;
|
||||
|
||||
if (IdToModeMap.TryGetValue(id, out var mode))
|
||||
{
|
||||
|
||||
@@ -1,22 +1,85 @@
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using System.Collections.Generic;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using Il2CppSystem;
|
||||
using Reactor.Localization.Utilities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.ProBuilder;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
/// <summary>
|
||||
/// The game mode option.
|
||||
/// </summary>
|
||||
// TODO: Replace this with a proper gamemode selection.
|
||||
public class GameModeOption : AbstractOptionGroup
|
||||
[HarmonyPatch]
|
||||
public static class GameModeOption
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override string GroupName => "Game Mode";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the game mode option.
|
||||
/// </summary>
|
||||
public ModdedNumberOption CurrentMode { get; set; } = new("Game Mode: {0}", 0, 0, CustomGameModeManager.LastId, 1, Utilities.MiraNumberSuffixes.None)
|
||||
public static int Value
|
||||
{
|
||||
ChangedEvent = x => CustomGameModeManager.SetGameMode((uint)x),
|
||||
};
|
||||
get =>
|
||||
OptionBehaviour != null
|
||||
? OptionBehaviour.GetInt()
|
||||
: 0;
|
||||
set
|
||||
{
|
||||
if (OptionBehaviour == null)
|
||||
return;
|
||||
OptionBehaviour.Value = value;
|
||||
OptionBehaviour.UpdateValue();
|
||||
}
|
||||
}
|
||||
|
||||
internal static StringOption OptionBehaviour { get; private set; } = null!;
|
||||
|
||||
private static readonly List<String> Queue = [];
|
||||
// loading takes place before option creation
|
||||
internal static void AddOption(string opt)
|
||||
{
|
||||
if (OptionBehaviour == null)
|
||||
{
|
||||
Queue.Add(opt);
|
||||
return;
|
||||
}
|
||||
OptionBehaviour.Values = (Il2CppStructArray<StringNames>)OptionBehaviour.Values.Add(CustomStringName.CreateAndRegister(opt));
|
||||
}
|
||||
[HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.CreateSettings))]
|
||||
[HarmonyPostfix]
|
||||
public static void CreateSettingsPatch(GameOptionsMenu __instance)
|
||||
{
|
||||
float num = -9.5f;
|
||||
CategoryHeaderMasked categoryHeaderMasked = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer);
|
||||
categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister("Custom"), 20);
|
||||
categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f;
|
||||
categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f);
|
||||
OptionBehaviour = Object.Instantiate(
|
||||
__instance.stringOptionOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
__instance.settingsContainer);
|
||||
OptionBehaviour.transform.localPosition = new Vector3(0.952f, num - 0.63f, -2f);
|
||||
OptionBehaviour.SetClickMask(__instance.ButtonClickMask);
|
||||
StringGameSetting setting = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
setting.Type = OptionTypes.MultipleChoice;
|
||||
setting.Title = CustomStringName.CreateAndRegister("Gamemode");
|
||||
setting.Index = 0;
|
||||
setting.Values = new Il2CppStructArray<StringNames>([CustomStringName.CreateAndRegister("Default")]);
|
||||
OptionBehaviour.SetUpFromData(setting, 20);
|
||||
OptionBehaviour.OnValueChanged = (Action<OptionBehaviour>) ((OptionBehaviour opt) =>
|
||||
{
|
||||
CustomGameModeManager.SetGameMode((uint)opt.GetInt());
|
||||
});
|
||||
__instance.Children.Add(OptionBehaviour);
|
||||
__instance.scrollBar.SetYBoundsMax(9f);
|
||||
foreach (var str in Queue)
|
||||
AddOption(str);
|
||||
Queue.Clear();
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.ValueChanged))]
|
||||
[HarmonyPrefix]
|
||||
public static bool ValueChanged(GameOptionsMenu __instance, OptionBehaviour option)
|
||||
{
|
||||
return !OptionBehaviour.Equals(option);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Presets;
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using HarmonyLib;
|
||||
using Il2CppSystem;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
using Object = Il2CppSystem.Object;
|
||||
|
||||
@@ -206,17 +201,7 @@ public static class OptionsPatches
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (__instance == OptionGroupSingleton<GameModeOption>.Instance.CurrentMode.OptionBehaviour)
|
||||
{
|
||||
__instance.TitleText.text =
|
||||
TranslationController.Instance.GetString(__instance.Title, $"<color=#{CustomGameModeManager.ActiveMode?.Color.ToHtmlStringRGBA()}>{CustomGameModeManager.ActiveMode}</color>");
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.TitleText.text =
|
||||
TranslationController.Instance.GetString(__instance.Title);
|
||||
}
|
||||
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ public sealed class MiraPluginManager
|
||||
internal void Initialize()
|
||||
{
|
||||
Instance = this;
|
||||
ModdedOptionsManager.RegisterGroup(typeof(GameModeOption)); // TODO: dont do this
|
||||
CustomGameModeManager.RegisterDefaultMode();
|
||||
CustomGameModeManager.GetAndSetGameMode();
|
||||
IL2CPPChainloader.Instance.PluginLoad += RegisterPlugin;
|
||||
@@ -67,6 +66,9 @@ public sealed class MiraPluginManager
|
||||
continue;
|
||||
}
|
||||
dict.Add(value.Name, key);
|
||||
if (((AmongUs.GameOptions.GameModes) key) == AmongUs.GameOptions.GameModes.Normal)
|
||||
return;
|
||||
// 'Default' was still being registered twice and idk why
|
||||
GameModesHelpers.ModeToName.Add((AmongUs.GameOptions.GameModes)key, CustomStringName.CreateAndRegister(value.Name));
|
||||
}
|
||||
EnumInjector.InjectEnumValues<AmongUs.GameOptions.GameModes>(dict);
|
||||
|
||||
@@ -5,11 +5,11 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Voting;
|
||||
using Reactor.Utilities;
|
||||
using Rewired;
|
||||
using Rewired.Data;
|
||||
using TMPro;
|
||||
@@ -429,7 +429,8 @@ public static class Extensions
|
||||
public static bool IsCustom(this OptionBehaviour optionBehaviour)
|
||||
{
|
||||
return ModdedOptionsManager.ModdedOptions.Values.Any(
|
||||
opt => opt.OptionBehaviour && opt.OptionBehaviour == optionBehaviour);
|
||||
opt => opt.OptionBehaviour && opt.OptionBehaviour == optionBehaviour)
|
||||
|| optionBehaviour.Equals(GameModeOption.OptionBehaviour);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user