diff --git a/MiraAPI/Modifiers/BaseModifier.cs b/MiraAPI/Modifiers/BaseModifier.cs
index 3daeb567..10931ec9 100644
--- a/MiraAPI/Modifiers/BaseModifier.cs
+++ b/MiraAPI/Modifiers/BaseModifier.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using Il2CppInterop.Runtime.Attributes;
using MiraAPI.GameOptions;
using MiraAPI.PluginLoading;
@@ -96,6 +97,48 @@ public abstract class BaseModifier : IOptionable
///
public virtual string ModifierCategoryTitle => MiraLocaleManager.Get("Modifier");
+ ///
+ /// Gets a value indicating whether to exclude the "amount" from the displayed amount text within the role guide.
+ ///
+ public virtual bool ShowModifierAsUnique => false;
+
+ ///
+ /// Gets the displayed amount and chance of the modifier. Used in the role guide.
+ /// By default, 0 amount or chance results in a complete 0 amount and chance, so override if necessary.
+ ///
+ /// The amount of the modifier.
+ /// The chance of the modifier.
+ /// The mod source of the modifier.
+ /// The result.
+ public virtual string GetAmountText(int amount, int chance, string source)
+ {
+ if (amount == 0)
+ {
+ chance = 0;
+ }
+
+ if (ShowModifierAsUnique)
+ {
+ return string.Format(
+ CultureInfo.InvariantCulture,
+ "{0}% ({1})",
+ chance.ToString(CultureInfo.InvariantCulture),
+ source);
+ }
+
+ if (chance == 0)
+ {
+ amount = 0;
+ }
+
+ return string.Format(
+ CultureInfo.InvariantCulture,
+ "{0} at {1}% ({2})",
+ amount.ToString(CultureInfo.InvariantCulture),
+ chance.ToString(CultureInfo.InvariantCulture),
+ source);
+ }
+
///
/// Gets whether the modifier is forcibly shown or disabled in the wiki screen.
///
diff --git a/MiraAPI/Modifiers/Types/GameModifier.cs b/MiraAPI/Modifiers/Types/GameModifier.cs
index b4329203..4f0b0883 100644
--- a/MiraAPI/Modifiers/Types/GameModifier.cs
+++ b/MiraAPI/Modifiers/Types/GameModifier.cs
@@ -1,4 +1,5 @@
-using MiraAPI.GameModes;
+using System.Globalization;
+using MiraAPI.GameModes;
using MiraAPI.PluginLoading;
namespace MiraAPI.Modifiers.Types;
diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs
index 5354c042..e9aaf24a 100644
--- a/MiraAPI/Patches/RoleGuidePatches.cs
+++ b/MiraAPI/Patches/RoleGuidePatches.cs
@@ -1157,7 +1157,9 @@ public static class RoleGuidePatches
entry.Visible = entry.CanShow && MatchesSearch(entry, searchText);
if (entry.Panel)
{
- SetPanelCount(entry.Panel!, entry.Amount, entry.Chance, entry.ModId);
+ dynamic entryType = entry.Modifier != null ? entry.Modifier : entry.Role!;
+ var text = GetPanelCountText(entryType, entry.Amount, entry.Chance, entry.ModId);
+ SetPanelCount(entry.Panel!, text);
if (!entry.Visible && entry.Panel!.gameObject.activeSelf)
{
entry.Panel.gameObject.SetActive(false);
@@ -1793,21 +1795,22 @@ public static class RoleGuidePatches
return false;
}
- __instance.roleCount.text = string.Format(
- CultureInfo.InvariantCulture,
- "{0} at {1}%",
- numPerGame.ToString(CultureInfo.InvariantCulture),
- chancePerGame);
if (role is ICustomRole customRole)
{
__instance.roleName.text = customRole.RoleName;
__instance.roleDescription.text =
$"{role.GetCategoryTitle()}\n" + customRole.RoleMedDescription;
__instance.roleIcon.sprite = customRole.Configuration.Icon?.LoadAsset();
- __instance.roleCount.text += $" ({customRole.ParentMod.MiraPlugin.GetAbbreviatedModName()})";
+ var text = GetCustomRolePanelCountText(customRole, numPerGame, chancePerGame, customRole.ParentMod.MiraPlugin.GetAbbreviatedModName());
+ SetPanelCount(__instance, text);
}
else
{
+ __instance.roleCount.text = string.Format(
+ CultureInfo.InvariantCulture,
+ "{0} at {1}%",
+ numPerGame.ToString(CultureInfo.InvariantCulture),
+ chancePerGame);
__instance.roleName.text = role.NiceName;
__instance.roleDescription.text = $"{role.GetCategoryTitle()}\n" + role.BlurbMed;
__instance.roleIcon.sprite = role.RoleIconColor;
@@ -1823,9 +1826,20 @@ public static class RoleGuidePatches
return false;
}
- private static void SetPanelCount(MatchInfoRolePanel panel, int amount, int chance, string modId)
+ // NOTE: This is specifically meant to be a different method name as to not have the game check this method and the GetPanelCountText method made for roles overall.
+ private static string GetCustomRolePanelCountText(ICustomRole custom, int amount, int chance, string modId)
{
- panel.roleCount.text = string.Format(
+ return custom.GetAmountText(amount, chance, modId);
+ }
+
+ private static string GetPanelCountText(RoleBehaviour role, int amount, int chance, string modId)
+ {
+ if (role is ICustomRole custom)
+ {
+ return custom.GetAmountText(amount, chance, modId);
+ }
+
+ return string.Format(
CultureInfo.InvariantCulture,
"{0} at {1}% ({2})",
amount.ToString(CultureInfo.InvariantCulture),
@@ -1833,6 +1847,18 @@ public static class RoleGuidePatches
modId);
}
+ private static string GetPanelCountText(BaseModifier modifier, int amount, int chance, string modId)
+ {
+ return modifier.GetAmountText(amount, chance, modId);
+ }
+
+ private static void SetPanelCount(MatchInfoRolePanel panel, string amountChanceText)
+ {
+ panel.roleCount.text = string.Format(
+ CultureInfo.InvariantCulture,
+ amountChanceText);
+ }
+
public static void SetRolePanel(
this MatchInfoRolePanel instance,
RoleBehaviour role,
@@ -1845,14 +1871,16 @@ public static class RoleGuidePatches
instance.roleDescription.text =
$"{role.GetCategoryTitle()}\n" + customRole.RoleMedDescription;
instance.roleIcon.sprite = customRole.Configuration.Icon?.LoadAsset();
- SetPanelCount(instance, numPerGame, chancePerGame, customRole.ParentMod.MiraPlugin.GetAbbreviatedModName());
+ var text = GetCustomRolePanelCountText(customRole, numPerGame, chancePerGame, customRole.ParentMod.MiraPlugin.GetAbbreviatedModName());
+ SetPanelCount(instance, text);
}
else
{
instance.roleName.text = role.NiceName;
instance.roleDescription.text = $"{role.GetCategoryTitle()}\n" + role.BlurbMed;
instance.roleIcon.sprite = role.RoleIconColor;
- SetPanelCount(instance, numPerGame, chancePerGame, "AU");
+ var text = GetPanelCountText(role, numPerGame, chancePerGame, "AU");
+ SetPanelCount(instance, text);
}
instance.roleIcon.SetSizeLimit(0.13f);
@@ -1873,7 +1901,8 @@ public static class RoleGuidePatches
instance.roleDescription.text =
$"{modifier.ModifierCategoryTitle}\n" + modifier.ModifierMedDescription;
instance.roleIcon.sprite = modifier.ModifierIcon?.LoadAsset();
- SetPanelCount(instance, numPerGame, chancePerGame, modifier.ParentMod.MiraPlugin.GetAbbreviatedModName());
+ var text = GetPanelCountText(modifier, numPerGame, chancePerGame, modifier.ParentMod.MiraPlugin.GetAbbreviatedModName());
+ SetPanelCount(instance, text);
instance.roleIcon.SetSizeLimit(0.13f);
instance.roleIcon.material.SetInt(PlayerMaterial.MaskLayer, 50);
diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs
index 26dd0cfa..ba5c896a 100644
--- a/MiraAPI/Roles/ICustomRole.cs
+++ b/MiraAPI/Roles/ICustomRole.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Text;
using BepInEx.Configuration;
using Il2CppInterop.Runtime.Attributes;
@@ -92,6 +93,48 @@ public interface ICustomRole : IOptionable
_ => MiraLocaleManager.Get("MiraApi.RoleTeam.Other"),
};
+ ///
+ /// Gets a value indicating whether to exclude the "amount" from the displayed amount text within the role guide.
+ ///
+ public virtual bool ShowRoleAsUnique => Configuration.MaxRoleCount == 1;
+
+ ///
+ /// Gets the displayed amount and chance of the role. Used in the role guide.
+ /// By default, 0 amount or chance results in a complete 0 amount and chance, so override if necessary.
+ ///
+ /// The amount of the role.
+ /// The chance of the role.
+ /// The mod source of the role.
+ /// The result.
+ public virtual string GetAmountText(int amount, int chance, string source)
+ {
+ if (amount == 0)
+ {
+ chance = 0;
+ }
+
+ if (ShowRoleAsUnique)
+ {
+ return string.Format(
+ CultureInfo.InvariantCulture,
+ "{0}% ({1})",
+ chance.ToString(CultureInfo.InvariantCulture),
+ source);
+ }
+
+ if (chance == 0)
+ {
+ amount = 0;
+ }
+
+ return string.Format(
+ CultureInfo.InvariantCulture,
+ "{0} at {1}% ({2})",
+ amount.ToString(CultureInfo.InvariantCulture),
+ chance.ToString(CultureInfo.InvariantCulture),
+ source);
+ }
+
///
/// Gets the of the role.
///