mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Various fixes (csproj and options)
This commit is contained in:
1 parent
c242559956
commit
ca828ea388
15 files changed
+92
-82
No files matched your search
@@ -0,0 +1,27 @@
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
|
||||
namespace MiraAPI.Example;
|
||||
|
||||
public class ExampleOptions2 : IModdedOptionGroup
|
||||
{
|
||||
public string GroupName => "Example 2";
|
||||
|
||||
public ModdedToggleOption UseThing { get; } = new("Use Thingy 5", false);
|
||||
|
||||
public ModdedToggleOption UseThing2 { get; } = new("Use Thingy 6", false);
|
||||
|
||||
public ModdedStringOption Sussy { get; } = new("Sussy", 0, ["Sussy 1", "Sussy 2", "Sussy 3"]);
|
||||
|
||||
public ModdedEnumOption SussyEnum { get; } = new("Sussy Enum", 0, typeof(SussyEnum));
|
||||
|
||||
public ModdedNumberOption YeezyLevel { get; } = new("Yeezy Level", 50, 0, 100, 25, NumberSuffixes.Multiplier);
|
||||
}
|
||||
|
||||
public enum SussyEnum
|
||||
{
|
||||
Sussy,
|
||||
Baka,
|
||||
Imposter,
|
||||
Kanye
|
||||
}
|
||||
@@ -12,14 +12,14 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<GamePlatform Condition="'$(GamePlatform)' == ''">Steam</GamePlatform>
|
||||
<GameVersion Condition="'$(GamePlatform)' == 'Steam'">2024.3.5</GameVersion>
|
||||
<GameVersion Condition="'$(GamePlatform)' == 'Steam'">2024.6.18</GameVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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="Reactor" Version="2.3.0" />
|
||||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.697" Private="false" ExcludeAssets="runtime;native" />
|
||||
<PackageReference Include="Iced" Version="1.21.0" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="$(GameVersion)" 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">
|
||||
|
||||
@@ -9,7 +9,7 @@ public interface IModdedOption
|
||||
{
|
||||
public uint Id { get; }
|
||||
public BaseGameSetting Data { get; }
|
||||
public ModdedOptionGroup Group { get; set; }
|
||||
public IModdedOptionGroup Group { get; set; }
|
||||
public IMiraPlugin ParentMod { get; set; }
|
||||
public Type AdvancedRole { get; }
|
||||
public OptionBehaviour OptionBehaviour { get; protected set; }
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Linq;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
public class ModdedGroupSingleton<T> where T : ModdedOptionGroup
|
||||
public class ModdedGroupSingleton<T> where T : IModdedOptionGroup
|
||||
{
|
||||
private static T _instance;
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using MiraAPI.PluginLoading;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
public class ModdedOptionGroup
|
||||
{
|
||||
public IMiraPlugin ParentMod;
|
||||
public GameObject Header;
|
||||
public string GroupName;
|
||||
public Func<bool> GroupVisible;
|
||||
public Color GroupColor;
|
||||
public Type AdvancedRole;
|
||||
}
|
||||
@@ -14,9 +14,9 @@ public class ModdedOptionsManager
|
||||
{
|
||||
public static readonly Dictionary<uint, IModdedOption> ModdedOptions = new();
|
||||
public static readonly List<IModdedOption> Options = [];
|
||||
public static readonly List<ModdedOptionGroup> Groups = [];
|
||||
public static readonly List<IModdedOptionGroup> Groups = [];
|
||||
private static readonly Dictionary<PropertyInfo, ModdedOptionAttribute> OptionAttributes = new();
|
||||
public static readonly Dictionary<Type, ModdedOptionGroup> OriginalTypes = new();
|
||||
public static readonly Dictionary<Type, IModdedOptionGroup> OriginalTypes = new();
|
||||
public static uint NextId = 1;
|
||||
|
||||
public static IModdedOption RegisterOption(Type type, ModdedOptionAttribute attribute, PropertyInfo property)
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
|
||||
public bool ZeroInfinity { get; }
|
||||
|
||||
public ModdedNumberOption(string title, float defaultValue, float min, float max, float increment, NumberSuffixes suffixType, bool zeroInfinity, Type roleType=null) : base(title, defaultValue, roleType)
|
||||
public ModdedNumberOption(string title, float defaultValue, float min, float max, float increment, NumberSuffixes suffixType, bool zeroInfinity=false, Type roleType=null) : base(title, defaultValue, roleType)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
|
||||
@@ -21,7 +21,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
public Func<bool> Visible { get; set; }
|
||||
public Type AdvancedRole { get; }
|
||||
public OptionBehaviour OptionBehaviour { get; set; }
|
||||
public ModdedOptionGroup Group { get; set; } = null;
|
||||
public IModdedOptionGroup Group { get; set; } = null;
|
||||
public IMiraPlugin ParentMod { get; set; } = null;
|
||||
|
||||
protected ModdedOption(string title, T defaultValue, Type roleType) : this()
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<GamePlatform Condition="'$(GamePlatform)' == ''">Steam</GamePlatform>
|
||||
<GameVersion Condition="'$(GamePlatform)' == 'Steam'">2024.3.5</GameVersion>
|
||||
<GameVersion Condition="'$(GamePlatform)' == 'Steam'">2024.6.18</GameVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -25,10 +25,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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.6.18" PrivateAssets="all" />
|
||||
<PackageReference Include="Reactor" Version="2.3.0" />
|
||||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.697" Private="false" ExcludeAssets="runtime;native" />
|
||||
<PackageReference Include="Iced" Version="1.21.0" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="$(GameVersion)" 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">
|
||||
|
||||
@@ -17,12 +17,12 @@ public static class GameOptionsMenuPatch
|
||||
[HarmonyPatch(nameof(GameOptionsMenu.CreateSettings))]
|
||||
public static bool SettingsPatch(GameOptionsMenu __instance)
|
||||
{
|
||||
if (GameSettingMenuPatches.currentSelectedMod == 0) return true;
|
||||
if (GameSettingMenuPatches.CurrentSelectedMod == 0) return true;
|
||||
|
||||
__instance.MapPicker.gameObject.SetActive(false);
|
||||
|
||||
float num = 2.1f;
|
||||
foreach (IModdedOptionGroup group in GameSettingMenuPatches.selectedMod.OptionGroups)
|
||||
foreach (IModdedOptionGroup group in GameSettingMenuPatches.SelectedMod.OptionGroups)
|
||||
{
|
||||
CategoryHeaderMasked categoryHeaderMasked = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer);
|
||||
categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister(group.GroupName), 20);
|
||||
|
||||
@@ -15,9 +15,11 @@ namespace MiraAPI.Patches.Options;
|
||||
[HarmonyPatch(typeof(GameSettingMenu))]
|
||||
public static class GameSettingMenuPatches
|
||||
{
|
||||
public static int currentSelectedMod = 0;
|
||||
public static MiraPluginInfo selectedMod = null;
|
||||
public static TextMeshPro text;
|
||||
public static int CurrentSelectedMod { get; private set; }
|
||||
|
||||
public static MiraPluginInfo SelectedMod { get; private set; }
|
||||
|
||||
private static TextMeshPro _text;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(GameSettingMenu.Start))]
|
||||
@@ -32,11 +34,11 @@ public static class GameSettingMenuPatches
|
||||
tmpText.name = "SelectedMod";
|
||||
tmpText.transform.localPosition = new Vector3(-3.3382f, 1.5399f, -2);
|
||||
|
||||
text = tmpText.GetComponent<TextMeshPro>();
|
||||
text.fontSizeMax = 3.2f;
|
||||
_text = tmpText.GetComponent<TextMeshPro>();
|
||||
_text.fontSizeMax = 3.2f;
|
||||
UpdateText(__instance.GameSettingsTab, __instance.RoleSettingsTab);
|
||||
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
_text.alignment = TextAlignmentOptions.Center;
|
||||
|
||||
GameObject nextButton = Object.Instantiate(__instance.BackButton, __instance.BackButton.transform.parent).gameObject;
|
||||
nextButton.transform.localPosition = new Vector3(-2.2663f, 1.5272f, -25f);
|
||||
@@ -49,9 +51,9 @@ public static class GameSettingMenuPatches
|
||||
passiveButton.OnClick = new ButtonClickedEvent();
|
||||
passiveButton.OnClick.AddListener((UnityAction)(() =>
|
||||
{
|
||||
if (currentSelectedMod != MiraPluginManager.Instance.RegisteredPlugins.Count)
|
||||
if (CurrentSelectedMod != MiraPluginManager.Instance.RegisteredPlugins.Count)
|
||||
{
|
||||
currentSelectedMod += 1;
|
||||
CurrentSelectedMod += 1;
|
||||
UpdateText(__instance.GameSettingsTab, __instance.RoleSettingsTab);
|
||||
}
|
||||
}));
|
||||
@@ -63,9 +65,9 @@ public static class GameSettingMenuPatches
|
||||
backButton.transform.FindChild("Active").gameObject.GetComponent<SpriteRenderer>().flipX = backButton.transform.FindChild("Inactive").gameObject.GetComponent<SpriteRenderer>().flipX = true;
|
||||
backButton.gameObject.GetComponent<PassiveButton>().OnClick.AddListener((UnityAction)(() =>
|
||||
{
|
||||
if (currentSelectedMod != 0)
|
||||
if (CurrentSelectedMod != 0)
|
||||
{
|
||||
currentSelectedMod -= 1;
|
||||
CurrentSelectedMod -= 1;
|
||||
UpdateText(__instance.GameSettingsTab, __instance.RoleSettingsTab);
|
||||
}
|
||||
}));
|
||||
@@ -73,23 +75,23 @@ public static class GameSettingMenuPatches
|
||||
|
||||
public static void UpdateText(GameOptionsMenu settings, RolesSettingsMenu roles)
|
||||
{
|
||||
if (currentSelectedMod == 0)
|
||||
if (CurrentSelectedMod == 0)
|
||||
{
|
||||
text.text = "Default";
|
||||
text.fontSizeMax = 3.2f;
|
||||
_text.text = "Default";
|
||||
_text.fontSizeMax = 3.2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
text.fontSizeMax = 2f;
|
||||
selectedMod = MiraPluginManager.Instance.RegisteredPlugins.ElementAt(currentSelectedMod - 1).Value;
|
||||
if (selectedMod == null)
|
||||
_text.fontSizeMax = 2f;
|
||||
SelectedMod = MiraPluginManager.Instance.RegisteredPlugins.ElementAt(CurrentSelectedMod - 1).Value;
|
||||
if (SelectedMod == null)
|
||||
{
|
||||
currentSelectedMod = 0;
|
||||
CurrentSelectedMod = 0;
|
||||
UpdateText(settings, roles);
|
||||
}
|
||||
|
||||
string name = selectedMod.PluginInfo.Metadata.Name;
|
||||
text.text = name.Substring(0, Math.Min(name.Length, 15));
|
||||
string name = SelectedMod.PluginInfo.Metadata.Name;
|
||||
_text.text = name.Substring(0, Math.Min(name.Length, 15));
|
||||
}
|
||||
|
||||
if (roles is not null && roles.roleChances is not null)
|
||||
|
||||
@@ -28,7 +28,7 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
var maskBg = __instance.scrollBar.transform.FindChild("MaskBg");
|
||||
|
||||
if (GameSettingMenuPatches.currentSelectedMod == 0)
|
||||
if (GameSettingMenuPatches.CurrentSelectedMod == 0)
|
||||
{
|
||||
__instance.AllButton.transform.parent.gameObject.SetActive(true);
|
||||
__instance.AllButton.gameObject.SetActive(true);
|
||||
@@ -52,7 +52,7 @@ public static class RoleSettingMenuPatches
|
||||
num -= 0.522f;
|
||||
int num3 = 0;
|
||||
|
||||
foreach (var role in GameSettingMenuPatches.selectedMod.CustomRoles.Values.OfType<ICustomRole>().Where(role => role.Team == ModdedRoleTeams.Crewmate))
|
||||
foreach (var role in GameSettingMenuPatches.SelectedMod.CustomRoles.Values.OfType<ICustomRole>().Where(role => role.Team == ModdedRoleTeams.Crewmate))
|
||||
{
|
||||
CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3);
|
||||
num3++;
|
||||
@@ -65,7 +65,7 @@ public static class RoleSettingMenuPatches
|
||||
num -= 0.522f;
|
||||
|
||||
|
||||
foreach (var role in GameSettingMenuPatches.selectedMod.CustomRoles.Values.OfType<ICustomRole>().Where(role => role.Team == ModdedRoleTeams.Impostor))
|
||||
foreach (var role in GameSettingMenuPatches.SelectedMod.CustomRoles.Values.OfType<ICustomRole>().Where(role => role.Team == ModdedRoleTeams.Impostor))
|
||||
{
|
||||
CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3);
|
||||
num3++;
|
||||
@@ -79,7 +79,7 @@ public static class RoleSettingMenuPatches
|
||||
num -= 0.522f;
|
||||
|
||||
|
||||
foreach (var role in GameSettingMenuPatches.selectedMod.CustomRoles.Values.OfType<ICustomRole>().Where(role => role.Team == ModdedRoleTeams.Neutral))
|
||||
foreach (var role in GameSettingMenuPatches.SelectedMod.CustomRoles.Values.OfType<ICustomRole>().Where(role => role.Team == ModdedRoleTeams.Neutral))
|
||||
{
|
||||
CreateQuotaOption(__instance, role as RoleBehaviour, ref num, num3);
|
||||
num3++;
|
||||
@@ -92,7 +92,7 @@ public static class RoleSettingMenuPatches
|
||||
[HarmonyPatch(nameof(RolesSettingsMenu.Update))]
|
||||
public static bool UpdatePatch()
|
||||
{
|
||||
if (GameSettingMenuPatches.currentSelectedMod == 0)
|
||||
if (GameSettingMenuPatches.CurrentSelectedMod == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public static class RoleSettingMenuPatches
|
||||
__instance.advancedSettingChildren.Clear();
|
||||
|
||||
float num = -0.872f;
|
||||
foreach (var option in GameSettingMenuPatches.selectedMod.Options.Where(option => option.AdvancedRole == role.GetType()))
|
||||
foreach (var option in GameSettingMenuPatches.SelectedMod.Options.Where(option => option.AdvancedRole == role.GetType()))
|
||||
{
|
||||
OptionBehaviour newOpt = option.CreateOption(__instance.checkboxOrigin, __instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.AdvancedRolesSettings.transform);
|
||||
newOpt.transform.localPosition = new Vector3(2.17f, num, -2f);
|
||||
@@ -210,7 +210,7 @@ public static class RoleSettingMenuPatches
|
||||
ChangeTab(role, __instance);
|
||||
}));
|
||||
|
||||
if (index < GameSettingMenuPatches.selectedMod.CustomRoles.Count - 1)
|
||||
if (index < GameSettingMenuPatches.SelectedMod.CustomRoles.Count - 1)
|
||||
{
|
||||
yPos += -0.43f;
|
||||
}
|
||||
|
||||
@@ -6,25 +6,16 @@ using System.Collections.Generic;
|
||||
|
||||
namespace MiraAPI.PluginLoading;
|
||||
|
||||
public class MiraPluginInfo
|
||||
public class MiraPluginInfo(string id, IMiraPlugin miraPlugin, PluginInfo info)
|
||||
{
|
||||
public string PluginId { get; set; }
|
||||
public IMiraPlugin MiraPlugin { get; set; }
|
||||
public PluginInfo PluginInfo { get; set; }
|
||||
public ConfigFile PluginConfig { get; set; }
|
||||
public string PluginId { get; set; } = id;
|
||||
public IMiraPlugin MiraPlugin { get; set; } = miraPlugin;
|
||||
public PluginInfo PluginInfo { get; set; } = info;
|
||||
public ConfigFile PluginConfig { get; set; } = miraPlugin.GetConfigFile();
|
||||
|
||||
public readonly List<IModdedOptionGroup> OptionGroups = [];
|
||||
public readonly List<IModdedOption> Options = [];
|
||||
|
||||
public readonly Dictionary<ushort, RoleBehaviour> CustomRoles = [];
|
||||
public readonly Dictionary<int, CustomGameMode> GameModes = [];
|
||||
|
||||
public MiraPluginInfo(string id, IMiraPlugin miraPlugin, PluginInfo info)
|
||||
{
|
||||
PluginId = id;
|
||||
MiraPlugin = miraPlugin;
|
||||
PluginInfo = info;
|
||||
PluginConfig = miraPlugin.GetConfigFile();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -74,17 +74,19 @@ public class MiraPluginManager
|
||||
if (typeof(IModdedOptionGroup).IsAssignableFrom(type))
|
||||
{
|
||||
IModdedOptionGroup group = (IModdedOptionGroup)Activator.CreateInstance(type);
|
||||
ModdedOptionGroup newGroup = new ModdedOptionGroup
|
||||
{
|
||||
AdvancedRole = group.AdvancedRole,
|
||||
GroupColor = group.GroupColor,
|
||||
GroupName = group.GroupName,
|
||||
GroupVisible = group.GroupVisible
|
||||
};
|
||||
|
||||
ModdedOptionsManager.Groups.Add(newGroup);
|
||||
ModdedOptionsManager.OriginalTypes.Add(type, newGroup);
|
||||
ModdedOptionsManager.Groups.Add(group);
|
||||
ModdedOptionsManager.OriginalTypes.Add(type, group);
|
||||
pluginInfo.OptionGroups.Add(group);
|
||||
|
||||
foreach (var property in type.GetProperties())
|
||||
{
|
||||
if (typeof(IModdedOption).IsAssignableFrom(property.PropertyType))
|
||||
{
|
||||
IModdedOption option = (IModdedOption)property.GetValue(group);
|
||||
option.Group = group;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,8 @@
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
<add key="Reactor" value="https://nuget.reactor.gg/v3/index.json" />
|
||||
<add key="Samboy063" value="https://nuget.samboy.dev/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
Reference in new issue
Block a user