New role options

This commit is contained in:
ang-xd committed 2024-09-14 14:42:20 -04:00
1 parent 6e3de08043
commit fd75c99850
7 files changed
+54 -14

No files matched your search

+1 -1
View File
@@ -15,7 +15,7 @@ public class ChameloenRole : CrewmateRole, ICustomRole
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
{
MaxPlayers = 2,
MaxRoleCount = 0,
OptionsScreenshot = ExampleAssets.Banner,
};
+1 -1
View File
@@ -15,6 +15,6 @@ public class FreezerRole : ImpostorRole, ICustomRole
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
{
OptionsScreenshot = ExampleAssets.Banner,
MaxPlayers = 2,
MaxRoleCount = 2,
};
}
+1 -1
View File
@@ -16,7 +16,7 @@ public class NeutralKillerRole : ImpostorRole, ICustomRole
{
UseVanillaKillButton = true,
CanGetKilled = true,
CanUseVent = true
CanUseVent = true,
};
public override void SpawnTaskHeader(PlayerControl playerControl)
+4 -1
View File
@@ -12,8 +12,11 @@ public class TeleporterRole : CrewmateRole, ICustomRole
public Color RoleColor => new Color32(221, 176, 152, 255);
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration()
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
{
OptionsScreenshot = ExampleAssets.Banner,
CanModifyChance = false,
DefaultChance = 73,
DefaultRoleCount = 4,
};
}
@@ -166,11 +166,17 @@ public static class RoleSettingMenuPatches
try
{
role.ParentMod.PluginConfig.TryGetEntry<int>(role.NumConfigDefinition, out var numEntry);
numEntry.Value = roleSetting.RoleMaxCount;
if (role.Configuration.MaxRoleCount != 0)
{
role.ParentMod.PluginConfig.TryGetEntry<int>(role.NumConfigDefinition, out var numEntry);
numEntry.Value = Mathf.Clamp(roleSetting.RoleMaxCount, 0, role.Configuration.MaxRoleCount);
}
role.ParentMod.PluginConfig.TryGetEntry<int>(role.ChanceConfigDefinition, out var chanceEntry);
chanceEntry.Value = roleSetting.RoleChance;
if (role.Configuration.CanModifyChance)
{
role.ParentMod.PluginConfig.TryGetEntry<int>(role.ChanceConfigDefinition, out var chanceEntry);
chanceEntry.Value = roleSetting.RoleChance;
}
}
catch (Exception e)
{
@@ -305,12 +311,24 @@ public static class RoleSettingMenuPatches
Quaternion.identity,
__instance.RoleChancesSettings.transform);
roleOptionSetting.transform.localPosition = new Vector3(-0.15f, yPos, -2f);
roleOptionSetting.SetRole(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions, role, 20);
roleOptionSetting.labelSprite.color = customRole.RoleColor;
roleOptionSetting.OnValueChanged = new Action<OptionBehaviour>(ValueChanged);
roleOptionSetting.SetClickMask(__instance.ButtonClickMask);
__instance.roleChances.Add(roleOptionSetting);
if (customRole.Configuration.MaxRoleCount == 0 && customRole.Configuration.CanModifyChance)
{
roleOptionSetting.CountMinusBtn.gameObject.SetActive(false);
roleOptionSetting.CountPlusBtn.gameObject.SetActive(false);
}
else if (!customRole.Configuration.CanModifyChance)
{
roleOptionSetting.ChanceMinusBtn.gameObject.SetActive(false);
roleOptionSetting.ChancePlusBtn.gameObject.SetActive(false);
}
roleOptionSetting.titleText.transform.localPosition = new Vector3(-0.5376f, -0.2923f, 0f);
roleOptionSetting.titleText.color = customRole.RoleColor.GetAlternateColor();
roleOptionSetting.titleText.horizontalAlignment = HorizontalAlignmentOptions.Left;
+22 -3
View File
@@ -15,7 +15,10 @@ public struct CustomRoleConfiguration
/// <param name="role">The role in which you are configuring.</param>
public CustomRoleConfiguration(ICustomRole role)
{
MaxPlayers = 15;
MaxRoleCount = 15;
DefaultRoleCount = 0;
DefaultChance = 0;
OptionsScreenshot = Icon = MiraAssets.Empty;
AffectedByLightOnAirship = role.Team == ModdedRoleTeams.Crewmate;
KillButtonOutlineColor = role.Team switch
@@ -33,12 +36,28 @@ public struct CustomRoleConfiguration
TasksCountForProgress = role.Team == ModdedRoleTeams.Crewmate;
IsGhostRole = false;
HideSettings = IsGhostRole;
CanModifyChance = true;
}
/// <summary>
/// Gets the hard limit of players that can have this role. This property is used to set a limit in the Role Options menu.
/// 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.
/// </summary>
public int MaxPlayers;
public int MaxRoleCount;
/// <summary>
/// Gets the default role count.
/// </summary>
public int DefaultRoleCount;
/// <summary>
/// Gets the default role chance.
/// </summary>
public int DefaultChance;
/// <summary>
/// Whether the chance option can be changed or not.
/// </summary>
public bool CanModifyChance;
/// <summary>
/// Gets the Sprite used for the Role Options menu screenshot.
+3 -3
View File
@@ -90,7 +90,7 @@ public static class CustomRoleManager
roleBehaviour.TasksCountTowardProgress = customRole.Configuration.TasksCountForProgress;
roleBehaviour.CanVent = customRole.Configuration.CanUseVent;
roleBehaviour.DefaultGhostRole = customRole.Configuration.GhostRole;
roleBehaviour.MaxCount = customRole.Configuration.MaxPlayers;
roleBehaviour.MaxCount = customRole.Configuration.MaxRoleCount;
roleBehaviour.RoleScreenshot = customRole.Configuration.OptionsScreenshot.LoadAsset();
if (customRole.Configuration.IsGhostRole)
@@ -114,8 +114,8 @@ public static class CustomRoleManager
}
var config = parentMod.PluginConfig;
config.Bind(customRole.NumConfigDefinition, 1);
config.Bind(customRole.ChanceConfigDefinition, 100);
config.Bind(customRole.NumConfigDefinition, Mathf.Clamp(customRole.Configuration.DefaultRoleCount, 0, customRole.Configuration.MaxRoleCount));
config.Bind(customRole.ChanceConfigDefinition, Mathf.Clamp(customRole.Configuration.DefaultChance, 0, 100));
return roleBehaviour;
}