mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
WIP
This commit is contained in:
1 parent
0b84478184
commit
8ee71a7e10
20 files changed
+43
-97
No files matched your search
@@ -14,6 +14,6 @@ namespace MiraAPI.GameOptions
|
||||
public IMiraConfig ParentMod { get; set; }
|
||||
public void ValueChanged(OptionBehaviour optionBehaviour);
|
||||
public string GetHudStringText();
|
||||
public OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container);
|
||||
public OptionBehaviour CreateOption(OptionBehaviour optionBehaviour, Transform container);
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@ namespace MiraAPI.GameOptions
|
||||
{
|
||||
public class ModdedOptionsManager
|
||||
{
|
||||
public static List<IModdedOption> Options = new();
|
||||
public static List<ModdedOptionGroup> Groups = new();
|
||||
public static List<IModdedOption> Options = [];
|
||||
public static List<ModdedOptionGroup> Groups = [];
|
||||
private static Dictionary<PropertyInfo, ModdedOptionAttribute> OptionAttributes = new();
|
||||
private static Dictionary<Type, ModdedOptionGroup> OriginalTypes = new();
|
||||
public static Dictionary<Assembly, IMiraConfig> RegisteredMods = new();
|
||||
|
||||
@@ -9,21 +9,21 @@ namespace MiraAPI.GameOptions.OptionTypes
|
||||
{
|
||||
public string[] Values;
|
||||
|
||||
public ModdedEnumOption(string title, int defaultValue, Type enumType, System.Type roleType) : base(title, defaultValue, roleType)
|
||||
public ModdedEnumOption(string title, int defaultValue, Type enumType, Type roleType) : base(title, defaultValue, roleType)
|
||||
{
|
||||
Values = Enum.GetNames(enumType);
|
||||
}
|
||||
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container)
|
||||
public override OptionBehaviour CreateOption(OptionBehaviour optionBehaviour, Transform container)
|
||||
{
|
||||
var stringOption = UnityEngine.Object.Instantiate(stringOpt, container);
|
||||
var stringOption = (StringOption)UnityEngine.Object.Instantiate(optionBehaviour, container);
|
||||
|
||||
stringOption.name = Title;
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Value = Value;
|
||||
stringOption.Values = Values.Select(CustomStringName.CreateAndRegister).ToArray();
|
||||
stringOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
stringOption.OnEnable();
|
||||
stringOption.Initialize();
|
||||
|
||||
OptionBehaviour = stringOption;
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace MiraAPI.GameOptions.OptionTypes
|
||||
{
|
||||
if (OptionBehaviour is null) return;
|
||||
|
||||
StringOption opt = OptionBehaviour as StringOption;
|
||||
var opt = OptionBehaviour as StringOption;
|
||||
opt.Value = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ namespace MiraAPI.GameOptions.OptionTypes
|
||||
Value = Mathf.Clamp(defaultValue, min, max);
|
||||
}
|
||||
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container)
|
||||
public override OptionBehaviour CreateOption(OptionBehaviour optionBehaviour, Transform container)
|
||||
{
|
||||
var numberOption = Object.Instantiate(numberOpt, container);
|
||||
var numberOption = (NumberOption)Object.Instantiate(optionBehaviour, container);
|
||||
|
||||
numberOption.name = Title;
|
||||
numberOption.Title = StringName;
|
||||
@@ -34,7 +34,7 @@ namespace MiraAPI.GameOptions.OptionTypes
|
||||
numberOption.ValidRange = new FloatRange(Min, Max);
|
||||
numberOption.ZeroIsInfinity = ZeroInfinity;
|
||||
numberOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
numberOption.OnEnable();
|
||||
numberOption.Initialize();
|
||||
|
||||
OptionBehaviour = numberOption;
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace MiraAPI.GameOptions.OptionTypes
|
||||
|
||||
if (OptionBehaviour is null) return;
|
||||
|
||||
NumberOption opt = OptionBehaviour as NumberOption;
|
||||
var opt = OptionBehaviour as NumberOption;
|
||||
opt.Value = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace MiraAPI.GameOptions.OptionTypes
|
||||
|
||||
public void SetValue(T newValue)
|
||||
{
|
||||
T oldVal = Value;
|
||||
var oldVal = Value;
|
||||
Value = newValue;
|
||||
if (!Value.Equals(oldVal) && ChangedEvent != null)
|
||||
{
|
||||
@@ -53,7 +53,7 @@ namespace MiraAPI.GameOptions.OptionTypes
|
||||
|
||||
public abstract T GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour);
|
||||
|
||||
public abstract OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container);
|
||||
public abstract OptionBehaviour CreateOption(OptionBehaviour optionBehaviour, Transform container);
|
||||
|
||||
public abstract string GetHudStringText();
|
||||
}
|
||||
|
||||
@@ -12,16 +12,16 @@ namespace MiraAPI.GameOptions.OptionTypes
|
||||
Values = values;
|
||||
}
|
||||
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container)
|
||||
public override OptionBehaviour CreateOption(OptionBehaviour optionBehaviour, Transform container)
|
||||
{
|
||||
var stringOption = Object.Instantiate(stringOpt, container);
|
||||
var stringOption = (StringOption)Object.Instantiate(optionBehaviour, container);
|
||||
|
||||
stringOption.name = Title;
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Value = Value;
|
||||
stringOption.Values = Values.Select(CustomStringName.CreateAndRegister).ToArray();
|
||||
stringOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
stringOption.OnEnable();
|
||||
stringOption.Initialize();
|
||||
|
||||
OptionBehaviour = stringOption;
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace MiraAPI.GameOptions.OptionTypes
|
||||
{
|
||||
if (OptionBehaviour is null) return;
|
||||
|
||||
StringOption opt = OptionBehaviour as StringOption;
|
||||
var opt = OptionBehaviour as StringOption;
|
||||
opt.Value = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,15 @@ namespace MiraAPI.GameOptions.OptionTypes
|
||||
{
|
||||
}
|
||||
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container)
|
||||
public override OptionBehaviour CreateOption(OptionBehaviour optionBehaviour, Transform container)
|
||||
{
|
||||
var toggleOption = UnityEngine.Object.Instantiate(toggleOpt, container);
|
||||
var toggleOption = (ToggleOption)Object.Instantiate(optionBehaviour, container);
|
||||
|
||||
toggleOption.name = Title;
|
||||
toggleOption.Title = StringName;
|
||||
toggleOption.CheckMark.enabled = Value;
|
||||
toggleOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
toggleOption.OnEnable();
|
||||
toggleOption.Initialize();
|
||||
OptionBehaviour = toggleOption;
|
||||
return toggleOption;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace MiraAPI.GameOptions.OptionTypes
|
||||
{
|
||||
if (OptionBehaviour is null) return;
|
||||
|
||||
ToggleOption toggleOpt = OptionBehaviour as ToggleOption;
|
||||
var toggleOpt = OptionBehaviour as ToggleOption;
|
||||
toggleOpt.CheckMark.enabled = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.API.GameOptions;
|
||||
namespace MiraAPI.GameOptions.UI;
|
||||
public static class ModdedOptionsTab
|
||||
{
|
||||
public static List<GameObject> CustomTabs = new List<GameObject>();
|
||||
public static List<GameObject> CustomScreens = new List<GameObject>();
|
||||
public static readonly List<GameObject> CustomTabs = [];
|
||||
public static readonly List<GameObject> CustomScreens = [];
|
||||
|
||||
public static GameObject InitializeForMod(IMiraConfig config, GameSettingMenu __instance)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<PackageReference Include="Reactor" Version="2.2.0" />
|
||||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.688" Private="false" ExcludeAssets="runtime;native" />
|
||||
<PackageReference Include="Iced" Version="1.20.0" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2024.3.5" PrivateAssets="all" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2024.6.18" PrivateAssets="all" />
|
||||
|
||||
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
|
||||
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.1.0-rc.1" PrivateAssets="all" ExcludeAssets="runtime">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Networking.Rpc;
|
||||
|
||||
namespace MiraAPI.Networking.Options;
|
||||
namespace MiraAPI.Networking;
|
||||
|
||||
// METHOD RPC DOESNT WORK WITH THE ARRAYS AND STUFF SO THIS IS HOW WE WILL DO IT FOR NOW
|
||||
[RegisterCustomRpc((uint)MiraRpc.SyncGameOptions)]
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Hazel;
|
||||
using System;
|
||||
using Hazel;
|
||||
using MiraAPI.Roles;
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
|
||||
namespace MiraAPI.Networking.Options;
|
||||
namespace MiraAPI.Networking;
|
||||
|
||||
[RegisterCustomRpc((uint)MiraRpc.SyncRoleOptions)]
|
||||
public class SyncRoleOptionsRpc(MiraAPIPlugin plugin, uint id) : PlayerCustomRpc<MiraAPIPlugin, SyncRoleOptionsRpc.Data>(plugin, id)
|
||||
|
||||
@@ -18,66 +18,10 @@ namespace MiraAPI.Patches
|
||||
/// Custom role tab
|
||||
private static TaskPanelBehaviour _roleTab;
|
||||
|
||||
/// Scrolling increment
|
||||
private const float Increment = 0.3f;
|
||||
|
||||
/// Bounds for scrolling
|
||||
private static FloatRange _bounds = new FloatRange(2.9f, 4.6f);
|
||||
|
||||
/// <summary>
|
||||
/// Add options scrolling (on the hud text)
|
||||
/// </summary>
|
||||
public static void OptionsScrollingLogic(HudManager __instance)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Tab))
|
||||
{
|
||||
if (ToHudStringPatch.CurrentPage >= ModdedOptionsManager.RegisteredMods.Count)
|
||||
{
|
||||
ToHudStringPatch.CurrentPage = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ToHudStringPatch.CurrentPage += 1;
|
||||
}
|
||||
}
|
||||
|
||||
var numPlayers = GameData.Instance ? GameData.Instance.PlayerCount : 10;
|
||||
HudManager.Instance.GameSettings.text = GameOptionsManager.Instance.CurrentGameOptions.ToHudString(numPlayers);
|
||||
var pos = __instance.GameSettings.transform.localPosition;
|
||||
|
||||
if (!PlayerControl.LocalPlayer.CanMove)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ToHudStringPatch.CurrentPage == 0)
|
||||
{
|
||||
__instance.GameSettings.transform.localPosition = new Vector3(pos.x, _bounds.min, pos.z);
|
||||
return;
|
||||
}
|
||||
|
||||
_bounds.max = __instance.GameSettings.rectTransform.sizeDelta.y + _bounds.min;
|
||||
|
||||
var delta = Input.mouseScrollDelta.y switch
|
||||
{
|
||||
> 0f => -Increment,
|
||||
< 0f => Increment,
|
||||
_ => 0f
|
||||
};
|
||||
|
||||
pos = new Vector3(pos.x, Mathf.Clamp(pos.y + delta, _bounds.min, _bounds.max), pos.z);
|
||||
|
||||
__instance.GameSettings.transform.localPosition = pos;
|
||||
}
|
||||
|
||||
[HarmonyPostfix, HarmonyPatch("Update")]
|
||||
public static void UpdatePostfix(HudManager __instance)
|
||||
{
|
||||
var local = PlayerControl.LocalPlayer;
|
||||
if (LobbyBehaviour.Instance)
|
||||
{
|
||||
OptionsScrollingLogic(__instance);
|
||||
}
|
||||
|
||||
if (AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started && !ShipStatus.Instance)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.API.GameOptions;
|
||||
using MiraAPI.GameOptions;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MiraAPI.GameOptions.UI;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime;
|
||||
using MiraAPI.Networking.Options;
|
||||
using MiraAPI.Roles;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System.Linq;
|
||||
using MiraAPI.Networking;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using BepInEx;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using Il2CppInterop.Runtime;
|
||||
using MiraAPI.Networking.Options;
|
||||
using Reactor.Localization.Utilities;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
@@ -10,6 +9,7 @@ using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MiraAPI.Networking;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -82,7 +82,7 @@ public static class CustomRoleManager
|
||||
}
|
||||
else
|
||||
{
|
||||
ModRoles.TryAdd(info, new List<RoleBehaviour>() { roleBehaviour });
|
||||
ModRoles.TryAdd(info, [roleBehaviour]);
|
||||
}
|
||||
|
||||
CustomRoles.Add(roleId, roleBehaviour);
|
||||
|
||||
@@ -53,7 +53,7 @@ public interface ICustomRole
|
||||
|
||||
void HudUpdate(HudManager hudManager) { }
|
||||
|
||||
string GetCustomEjectionMessage(GameData.PlayerInfo player)
|
||||
string GetCustomEjectionMessage(NetworkedPlayerInfo player)
|
||||
{
|
||||
return Team == ModdedRoleTeams.Impostor ? $"{player.PlayerName} was The {RoleName}" : null;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MiraAPI.Utilities
|
||||
namespace MiraAPI.Utilities.Assets
|
||||
{
|
||||
public abstract class LoadableAsset<T> where T : UnityEngine.Object
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Utilities
|
||||
namespace MiraAPI.Utilities.Assets
|
||||
{
|
||||
public class LoadableBundleAsset<T>(string name, AssetBundle bundle) : LoadableAsset<T> where T : UnityEngine.Object
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user