Reduce duped code

This commit is contained in:
Atony committed 2026-09-23 21:53:46 -05:00
1 parent fc7eaef7c4
commit 2cfdbea51f
3 files changed
+37 -21

No files matched your search

+11 -12
View File
@@ -183,7 +183,7 @@ public static class RoleGuidePatches
StringNames.GameTaskBarMode, StringNames.GameTaskBarMode,
GameManager.Instance.LogicOptions.GetTaskBarMode().ToString()); GameManager.Instance.LogicOptions.GetTaskBarMode().ToString());
var hoverColor = new Color32(255, 255, 255, 150); var hoverColor = new Color32(255, 255, 255, 150);
foreach (RoleBehaviour roleBehaviour in RoleManager.Instance.AllRoles) foreach (RoleBehaviour roleBehaviour in RoleManager.Instance.AllRoles.ToArray().OrderBy(x => x.GetRoleName()))
{ {
if (roleBehaviour.Role != RoleTypes.Crewmate && roleBehaviour.Role != RoleTypes.Impostor && if (roleBehaviour.Role != RoleTypes.Crewmate && roleBehaviour.Role != RoleTypes.Impostor &&
roleBehaviour.Role is not RoleTypes.CrewmateGhost && roleBehaviour.Role is not RoleTypes.CrewmateGhost &&
@@ -196,6 +196,7 @@ public static class RoleGuidePatches
collider.size = new Vector2(0.13f, 0.13f); collider.size = new Vector2(0.13f, 0.13f);
collider.offset = new Vector2(0, 0); collider.offset = new Vector2(0, 0);
var passiveButton = panel.roleIcon.gameObject.AddComponent<PassiveButton>(); var passiveButton = panel.roleIcon.gameObject.AddComponent<PassiveButton>();
passiveButton.ClickSound = HudManager.Instance.MapButton.ClickSound;
passiveButton.OnMouseOver = new UnityEvent(); passiveButton.OnMouseOver = new UnityEvent();
passiveButton.OnMouseOver.AddListener( passiveButton.OnMouseOver.AddListener(
(UnityAction)(() => (UnityAction)(() =>
@@ -320,15 +321,11 @@ public static class RoleGuidePatches
if (role is ICustomRole custom) if (role is ICustomRole custom)
{ {
CurrentAdvancedTabObject = custom.GetAdvancedWiki(instance, TitleText, AdvancedWikiTab); CurrentAdvancedTabObject = custom.GetAdvancedWiki(instance, TitleText, AdvancedWikiTab);
CurrentAdvancedTabObject.transform.localPosition = new Vector3(0f, 0f, 0f);
} }
else else
{ {
AdvancedWikiTab.ScrollToTop(); AdvancedWikiTab.ScrollToTop();
CurrentAdvancedTabObject = new GameObject($"{role.Role}"); var titleTxt = role.GetRoleName() + $" ({TranslationController.Instance.GetString(role.TeamType is RoleTeamTypes.Crewmate ? StringNames.Crewmate : StringNames.Impostor)})";
TitleText.text = role.GetRoleName() + $" ({TranslationController.Instance.GetString(role.TeamType is RoleTeamTypes.Crewmate ? StringNames.Crewmate : StringNames.Impostor)})";
var desc = Object.Instantiate(instance.MatchInfoRolePanelPrefab.roleCount, CurrentAdvancedTabObject.transform);
desc.fontSizeMin = desc.fontSizeMax = desc.fontSize = 2f;
var description = TranslationController.Instance.GetString(role.BlurbNameLong); var description = TranslationController.Instance.GetString(role.BlurbNameLong);
if (description.Contains("STRMISS")) if (description.Contains("STRMISS"))
{ {
@@ -339,14 +336,16 @@ public static class RoleGuidePatches
} }
} }
desc.text = description; CurrentAdvancedTabObject = Helpers.CreateAdvancedWikiTab(
desc.rectTransform.sizeDelta = new Vector2(7.5f, 0.3f); instance,
desc.alignment = TextAlignmentOptions.TopLeft; role.Role.ToString(),
titleTxt,
description,
TitleText,
out var desc);
CurrentAdvancedTabObject.transform.SetParent(AdvancedWikiTab.Inner.transform); CurrentAdvancedTabObject.transform.SetParent(AdvancedWikiTab.Inner.transform);
desc.transform.localPosition = new Vector3(0, 1.125f, 0);
CurrentAdvancedTabObject.transform.localPosition = new Vector3(0f, 0f, 0f); CurrentAdvancedTabObject.transform.localPosition = new Vector3(0f, 0f, 0f);
desc.ForceMeshUpdate(); AdvancedWikiTab.SetYBoundsMax(Mathf.Clamp(desc.textBounds.size.y - 2, 0f, 999f));
AdvancedWikiTab.SetYBoundsMax(Mathf.Clamp(desc.textBounds.size.y- 2, 0f, 999f));
} }
} }
[HarmonyPrefix] [HarmonyPrefix]
+9 -9
View File
@@ -6,6 +6,7 @@ using MiraAPI.GameOptions;
using MiraAPI.Modifiers; using MiraAPI.Modifiers;
using MiraAPI.PluginLoading; using MiraAPI.PluginLoading;
using MiraAPI.Translation; using MiraAPI.Translation;
using MiraAPI.Utilities;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using Object = UnityEngine.Object; using Object = UnityEngine.Object;
@@ -318,16 +319,15 @@ public interface ICustomRole : IOptionable
public virtual GameObject GetAdvancedWiki(MatchInfoGuide guide, TextMeshPro titleText, Scroller parent) public virtual GameObject GetAdvancedWiki(MatchInfoGuide guide, TextMeshPro titleText, Scroller parent)
{ {
parent.ScrollToTop(); parent.ScrollToTop();
var obj = new GameObject(RoleNameLocale); var obj = Helpers.CreateAdvancedWikiTab(
titleText.text = RoleName + $" ({RoleFactionTitle})"; guide,
var desc = Object.Instantiate(guide.MatchInfoRolePanelPrefab.roleCount, obj.transform); RoleNameLocale,
desc.fontSizeMin = desc.fontSizeMax = desc.fontSize = 2f; RoleName + $" ({RoleFactionTitle})",
desc.text = RoleWikiDescription; RoleWikiDescription,
desc.rectTransform.sizeDelta = new Vector2(7.5f, 0.3f); titleText,
desc.alignment = TextAlignmentOptions.TopLeft; out var desc);
obj.transform.SetParent(parent.Inner.transform); obj.transform.SetParent(parent.Inner.transform);
desc.transform.localPosition = new Vector3(0, 1.125f, 0); obj.transform.localPosition = new Vector3(0f, 0f, 0f);
desc.ForceMeshUpdate();
parent.SetYBoundsMax(Mathf.Clamp(desc.textBounds.size.y - 2, 0f, 999f)); parent.SetYBoundsMax(Mathf.Clamp(desc.textBounds.size.y - 2, 0f, 999f));
return obj; return obj;
} }
+17
View File
@@ -594,4 +594,21 @@ public static class Helpers
// This should be patchable by mods when a vanilla role is meant to be replaced by a custom role. // This should be patchable by mods when a vanilla role is meant to be replaced by a custom role.
return false; return false;
} }
public static GameObject CreateAdvancedWikiTab(MatchInfoGuide guide, string objName, string title, string description, TextMeshPro titleTmp, out TextMeshPro descriptionTmp)
{
var obj = new GameObject(objName);
titleTmp.text = title;
descriptionTmp = Object.Instantiate(guide.MatchInfoRolePanelPrefab.roleCount, obj.transform);
descriptionTmp.fontSizeMin = descriptionTmp.fontSizeMax = descriptionTmp.fontSize = 2f;
var sourceTmp = HudManager.Instance.TaskPanel.taskText;
descriptionTmp.font = sourceTmp.font;
descriptionTmp.fontMaterial = sourceTmp.fontMaterial;
descriptionTmp.EnableStencilMasking();
descriptionTmp.text = description;
descriptionTmp.rectTransform.sizeDelta = new Vector2(7.5f, 0.3f);
descriptionTmp.alignment = TextAlignmentOptions.TopLeft;
descriptionTmp.transform.localPosition = new Vector3(0, 1.125f, 0);
descriptionTmp.ForceMeshUpdate();
return obj;
}
} }