diff --git a/MiraAPI.Example/Roles/NeutralKillerRole.cs b/MiraAPI.Example/Roles/NeutralKillerRole.cs index d9e4798..eb937e1 100644 --- a/MiraAPI.Example/Roles/NeutralKillerRole.cs +++ b/MiraAPI.Example/Roles/NeutralKillerRole.cs @@ -16,9 +16,10 @@ public class NeutralKillerRole : ImpostorRole, ICustomRole UseVanillaKillButton = true, CanGetKilled = true, CanUseVent = true, - RoleGroup = new RoleGroup("Outcast", Color.gray), }; + public RoleOptionsGroup RoleOptionsGroup { get; } = new("Outcast", Color.gray); + public override void SpawnTaskHeader(PlayerControl playerControl) { // remove existing task header. diff --git a/MiraAPI/Patches/IntroCutscenePatches.cs b/MiraAPI/Patches/IntroCutscenePatches.cs index 571fd9b..b98c58e 100644 --- a/MiraAPI/Patches/IntroCutscenePatches.cs +++ b/MiraAPI/Patches/IntroCutscenePatches.cs @@ -39,20 +39,12 @@ public static class IntroCutscenePatches return; } - if (customRole.Configuration.IntroTeamColor is { } color) + if (customRole.IntroConfiguration is { } introConfig) { - __instance.BackgroundBar.material.SetColor(ShaderID.Color, color); - __instance.TeamTitle.color = color; - } - - if (customRole.Configuration.IntroTeamTitle is { } title) - { - __instance.TeamTitle.text = title; - } - - if (customRole.Configuration.IntroTeamDescription is { } description) - { - __instance.ImpostorText.text = description; + __instance.BackgroundBar.material.SetColor(ShaderID.Color, introConfig.IntroTeamColor); + __instance.TeamTitle.color = introConfig.IntroTeamColor; + __instance.TeamTitle.text = introConfig.IntroTeamTitle; + __instance.ImpostorText.text = introConfig.IntroTeamDescription; } } @@ -65,20 +57,12 @@ public static class IntroCutscenePatches return true; } - if (customRole.Configuration.IntroTeamColor is { } color) + if (customRole.IntroConfiguration is { } introConfig) { - __instance.BackgroundBar.material.SetColor(ShaderID.Color, color); - __instance.TeamTitle.color = color; - } - - if (customRole.Configuration.IntroTeamTitle is { } title) - { - __instance.TeamTitle.text = title; - } - - if (customRole.Configuration.IntroTeamDescription is { } description) - { - __instance.ImpostorText.text = description; + __instance.BackgroundBar.material.SetColor(ShaderID.Color, introConfig.IntroTeamColor); + __instance.TeamTitle.color = introConfig.IntroTeamColor; + __instance.TeamTitle.text = introConfig.IntroTeamTitle; + __instance.ImpostorText.text = introConfig.IntroTeamDescription; } if (customRole.Team is not ModdedRoleTeams.Custom) diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 790024a..9212e86 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -22,7 +22,7 @@ namespace MiraAPI.Patches.Options; [HarmonyPatch(typeof(RolesSettingsMenu))] public static class RoleSettingMenuPatches { - private static Dictionary RoleGroupHidden { get; } = []; + private static Dictionary RoleGroupHidden { get; } = []; private static List CategoryHeaderEditRoles { get; } = []; private static List RoleOptionSettings { get; } = []; @@ -61,7 +61,7 @@ public static class RoleSettingMenuPatches var num3 = 0; var roleGroups = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values.OfType() - .ToLookup(x => x.Configuration.RoleGroup); + .ToLookup(x => x.RoleOptionsGroup); if (roleGroups is null) { diff --git a/MiraAPI/Patches/Roles/TaskAdderPatch.cs b/MiraAPI/Patches/Roles/TaskAdderPatch.cs index 6b549a2..98e93bc 100644 --- a/MiraAPI/Patches/Roles/TaskAdderPatch.cs +++ b/MiraAPI/Patches/Roles/TaskAdderPatch.cs @@ -21,6 +21,10 @@ public static class TaskAdderPatch private static readonly Dictionary ModsFolders = []; private static Scroller? _scroller; + /// + /// Adds custom roles to the TaskAdder. + /// + /// TaskAdder instance. [HarmonyPostfix] [HarmonyPatch(typeof(TaskAdderGame), nameof(TaskAdderGame.Begin))] public static void AddRolesFolder(TaskAdderGame __instance) @@ -86,13 +90,17 @@ public static class TaskAdderPatch __instance.GoToRoot(); } + /// + /// Sets the color of the role button based on the role. + /// + /// TaskAddButton instance. [HarmonyPostfix] - [HarmonyPatch(typeof(TaskAddButton), "Role", MethodType.Setter)] + [HarmonyPatch(typeof(TaskAddButton), nameof(TaskAddButton.Role), MethodType.Setter)] public static void RoleGetterPatch(TaskAddButton __instance) { if (__instance.role is ICustomRole { Team: ModdedRoleTeams.Custom } customRole) { - __instance.FileImage.color = customRole.Configuration.IntroTeamColor ?? Color.gray; + __instance.FileImage.color = customRole.IntroConfiguration?.IntroTeamColor ?? Color.gray; } __instance.RolloverHandler.OutColor = __instance.FileImage.color; diff --git a/MiraAPI/Roles/CustomRoleConfiguration.cs b/MiraAPI/Roles/CustomRoleConfiguration.cs index a6b1b21..2f69d09 100644 --- a/MiraAPI/Roles/CustomRoleConfiguration.cs +++ b/MiraAPI/Roles/CustomRoleConfiguration.cs @@ -39,31 +39,8 @@ public struct CustomRoleConfiguration HideSettings = roleBehaviour?.IsDead == true; ShowInFreeplay = roleBehaviour?.IsDead == false; CanModifyChance = true; - IntroTeamColor = role.Team switch - { - ModdedRoleTeams.Custom => Color.gray, - _ => null, - }; - IntroTeamTitle = role.Team switch - { - ModdedRoleTeams.Custom => "NEUTRAL", - _ => null, - }; - IntroTeamDescription = role.Team switch - { - ModdedRoleTeams.Custom => "You are Neutral. You do not have a team.", - _ => null, - }; - RoleGroup = role.Team switch - { - ModdedRoleTeams.Crewmate => RoleGroup.Crewmate, - ModdedRoleTeams.Impostor => RoleGroup.Impostor, - ModdedRoleTeams.Custom => RoleGroup.Neutral, - }; } - public RoleGroup RoleGroup; - /// /// Gets the hard limit of players that can have this role. This property is used to set a limit in the Role Options menu. If set to 0, the role will not be assigned at start. /// @@ -134,21 +111,6 @@ public struct CustomRoleConfiguration /// public bool ShowInFreeplay; - /// - /// Gets the color to show during the "Team" part of the intro cutscene. - /// - public Color? IntroTeamColor; - - /// - /// Gets the title text to show during the "Team" part of the intro cutscene. - /// - public string? IntroTeamTitle; - - /// - /// Gets the description text to show during the "Team" part of the intro cutscene. - /// - public string? IntroTeamDescription; - /// /// Gets the outline color for the KillButton if is true. /// diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index b42c9e3..0c77019 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -1,4 +1,5 @@ -using BepInEx.Configuration; +using System; +using BepInEx.Configuration; using MiraAPI.Modifiers; using MiraAPI.PluginLoading; using MiraAPI.Utilities; @@ -43,6 +44,26 @@ public interface ICustomRole /// CustomRoleConfiguration Configuration { get; } + /// + /// Gets the role options group. + /// + public RoleOptionsGroup RoleOptionsGroup => Team switch + { + ModdedRoleTeams.Crewmate => RoleOptionsGroup.Crewmate, + ModdedRoleTeams.Impostor => RoleOptionsGroup.Impostor, + ModdedRoleTeams.Custom => RoleOptionsGroup.Neutral, + _ => new RoleOptionsGroup(RoleName, RoleColor), + }; + + /// + /// Gets the role's IntroCutscene configuration. + /// + public RoleIntroConfiguration? IntroConfiguration => Team switch + { + ModdedRoleTeams.Custom => RoleIntroConfiguration.Neutral, + _ => null, + }; + /// /// Gets the parent mod of this role. /// diff --git a/MiraAPI/Roles/RoleGroup.cs b/MiraAPI/Roles/RoleGroup.cs deleted file mode 100644 index 4d9a0c5..0000000 --- a/MiraAPI/Roles/RoleGroup.cs +++ /dev/null @@ -1,16 +0,0 @@ -using UnityEngine; - -namespace MiraAPI.Roles; - -/// -/// Represents a group of roles. -/// -/// The group's name. -/// The group's color. -/// The priority to sort by on role setting screen. Negative means first. -public record struct RoleGroup(string Name, Color Color, int Priority = 0) -{ - public static RoleGroup Crewmate { get; } = new("Crewmate", Palette.CrewmateBlue, -2); - public static RoleGroup Impostor { get; } = new("Impostor", Palette.ImpostorRed, -1); - public static RoleGroup Neutral { get; } = new("Neutral Roles", Color.gray); -} diff --git a/MiraAPI/Roles/RoleIntroConfiguration.cs b/MiraAPI/Roles/RoleIntroConfiguration.cs new file mode 100644 index 0000000..53ca749 --- /dev/null +++ b/MiraAPI/Roles/RoleIntroConfiguration.cs @@ -0,0 +1,20 @@ +using UnityEngine; + +namespace MiraAPI.Roles; + +/// +/// Used to configure the intro cutscene. +/// +/// The color to show during the "Team" part of the intro cutscene. +/// The title text to show during the "Team" part of the intro cutscene. +/// The description text to show during the "Team" part of the intro cutscene. +public record struct RoleIntroConfiguration(Color IntroTeamColor, string IntroTeamTitle, string IntroTeamDescription) +{ + /// + /// Gets the default configuration for the "Neutral" team. + /// + public static RoleIntroConfiguration Neutral { get; } = new( + Color.gray, + "NEUTRAL", + "You are Neutral. You do not have a team."); +} diff --git a/MiraAPI/Roles/RoleOptionsGroup.cs b/MiraAPI/Roles/RoleOptionsGroup.cs new file mode 100644 index 0000000..a1785b0 --- /dev/null +++ b/MiraAPI/Roles/RoleOptionsGroup.cs @@ -0,0 +1,27 @@ +using UnityEngine; + +namespace MiraAPI.Roles; + +/// +/// Represents a group of roles. +/// +/// The group's name. +/// The group's color. +/// The priority to sort by on role setting screen. Negative means first. +public record struct RoleOptionsGroup(string Name, Color Color, int Priority = 0) +{ + /// + /// Gets the default group for crewmates. + /// + public static RoleOptionsGroup Crewmate { get; } = new("Crewmate", Palette.CrewmateBlue, -2); + + /// + /// Gets the default group for impostors. + /// + public static RoleOptionsGroup Impostor { get; } = new("Impostor", Palette.ImpostorRed, -1); + + /// + /// Gets the default group for neutral roles. + /// + public static RoleOptionsGroup Neutral { get; } = new("Neutral Roles", Color.gray); +}