diff --git a/MiraAPI/Modifiers/BaseModifier.cs b/MiraAPI/Modifiers/BaseModifier.cs index 0ca73e04..11fac1d7 100644 --- a/MiraAPI/Modifiers/BaseModifier.cs +++ b/MiraAPI/Modifiers/BaseModifier.cs @@ -9,8 +9,6 @@ using MiraAPI.Utilities; using MiraAPI.Utilities.Assets; using TMPro; using UnityEngine; -using UnityEngine.UI; -using Object = UnityEngine.Object; namespace MiraAPI.Modifiers; @@ -113,54 +111,15 @@ public abstract class BaseModifier : IOptionable /// The of the wiki. public virtual GameObject GetAdvancedWiki(MatchInfoGuide guide, TextMeshPro titleText, Scroller parent) { - parent.ScrollToTop(); - var obj = Helpers.CreateAdvancedWikiTab( + var abilities = WikiAbilities; + return Helpers.CreateAdvancedWikiPage( guide, + titleText, + parent, ModifierNameLocale, ModifierName + $" ({ModifierCategoryTitle})", ModifierWikiDescription, - titleText, - out var desc); - var num = 0; - if (WikiAbilities.Count != 0) - { - var grid = Object.Instantiate(parent.Inner, obj.transform); - var layoutGroup = grid.GetComponent(); - layoutGroup.startAxis = GridLayoutGroup.Axis.Vertical; - layoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount; - layoutGroup.spacing = new Vector2(0.75f, 0.4f); - grid.DestroyChildren(); - foreach (var ability in WikiAbilities) - { - num++; - var panel = Object.Instantiate( - guide.MatchInfoRolePanelPrefab, - grid); - panel.roleCount.text = ability.AbilityType; - panel.roleCount.transform.localPosition += new Vector3(-0.04f, 0); - panel.roleName.text = ability.Name; - panel.roleName.transform.localPosition += new Vector3(-0.04f, 0); - panel.roleDescription.text = ability.Description; - panel.roleDescription.rectTransform.sizeDelta = new Vector2(2.601f, 0.8f); - panel.roleDescription.transform.localPosition += new Vector3(0, -0.1f); - panel.roleIcon.sprite = ability.Icon.LoadAsset(); - panel.roleIcon.SetSizeLimit(0.13f); - - panel.roleIcon.material.SetInt(PlayerMaterial.MaskLayer, 50); - panel.roleName.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f); - panel.roleDescription.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f); - panel.roleCount.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f); - panel.roleIcon.transform.localScale = new Vector3(3.5f, 3.5f, 1f); - } - - grid.localPosition = new Vector3(-3.9f, 1.1f - desc.textBounds.size.y, 0f); - grid.localScale = new Vector3(1.3f, 1.3f, 1); - } - - obj.transform.SetParent(parent.Inner.transform); - obj.transform.localPosition = new Vector3(0f, 0f, 0f); - parent.SetYBoundsMax(Mathf.Clamp(desc.textBounds.size.y - 2 + Mathf.Ceil(num / 2f) * 1.45f, 0f, 999f)); - return obj; + abilities); } /// diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index dc384230..79f6570c 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -12,8 +12,6 @@ using MiraAPI.Utilities; using MiraAPI.Utilities.Assets; using TMPro; using UnityEngine; -using UnityEngine.UI; -using Object = UnityEngine.Object; namespace MiraAPI.Roles; @@ -324,54 +322,15 @@ public interface ICustomRole : IOptionable /// The of the wiki. GameObject GetAdvancedWiki(MatchInfoGuide guide, TextMeshPro titleText, Scroller parent) { - parent.ScrollToTop(); - var obj = Helpers.CreateAdvancedWikiTab( + var abilities = WikiAbilities; + return Helpers.CreateAdvancedWikiPage( guide, + titleText, + parent, RoleNameLocale, RoleName + $" ({RoleFactionTitle})", RoleWikiDescription, - titleText, - out var desc); - var num = 0; - if (WikiAbilities.Count != 0) - { - var grid = Object.Instantiate(parent.Inner, obj.transform); - var layoutGroup = grid.GetComponent(); - layoutGroup.startAxis = GridLayoutGroup.Axis.Vertical; - layoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount; - layoutGroup.spacing = new Vector2(0.75f, 0.4f); - grid.DestroyChildren(); - foreach (var ability in WikiAbilities) - { - num++; - var panel = Object.Instantiate( - guide.MatchInfoRolePanelPrefab, - grid); - panel.roleCount.text = ability.AbilityType; - panel.roleCount.transform.localPosition += new Vector3(-0.04f, 0); - panel.roleName.text = ability.Name; - panel.roleName.transform.localPosition += new Vector3(-0.04f, 0); - panel.roleDescription.text = ability.Description; - panel.roleDescription.rectTransform.sizeDelta = new Vector2(2.601f, 0.8f); - panel.roleDescription.transform.localPosition += new Vector3(0, -0.1f); - panel.roleIcon.sprite = ability.Icon.LoadAsset(); - panel.roleIcon.SetSizeLimit(0.13f); - - panel.roleIcon.material.SetInt(PlayerMaterial.MaskLayer, 50); - panel.roleName.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f); - panel.roleDescription.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f); - panel.roleCount.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f); - panel.roleIcon.transform.localScale = new Vector3(3.5f, 3.5f, 1f); - } - - grid.localPosition = new Vector3(-3.9f, 1.1f - desc.textBounds.size.y, 0f); - grid.localScale = new Vector3(1.3f, 1.3f, 1); - } - - obj.transform.SetParent(parent.Inner.transform); - obj.transform.localPosition = new Vector3(0f, 0f, 0f); - parent.SetYBoundsMax(Mathf.Clamp((desc.textBounds.size.y - 2) + (Mathf.Ceil(num / 2f) * 1.45f), 0f, 999f)); - return obj; + abilities); } /// diff --git a/MiraAPI/Utilities/Helpers.cs b/MiraAPI/Utilities/Helpers.cs index 35845887..c8b85b15 100644 --- a/MiraAPI/Utilities/Helpers.cs +++ b/MiraAPI/Utilities/Helpers.cs @@ -13,9 +13,11 @@ using MiraAPI.GameOptions.OptionTypes; using MiraAPI.Roles; using MiraAPI.Translation; using MiraAPI.Utilities.Assets; +using Reactor.Utilities.Extensions; using Rewired; using TMPro; using UnityEngine; +using UnityEngine.UI; using MethodBase = System.Reflection.MethodBase; using Object = UnityEngine.Object; using Random = UnityEngine.Random; @@ -757,4 +759,76 @@ public static class Helpers descriptionTmp.ForceMeshUpdate(); return obj; } + + /// + /// Creates a full advanced wiki page with a title, a description, and an optional grid of ability panels. + /// + /// The guide object. + /// The instance of the title. + /// The the page should be parented to. + /// The name of the page object. + /// The title of the page. + /// The description of the page. + /// The abilities to display in a grid below the description. + /// The of the wiki page. + public static GameObject CreateAdvancedWikiPage( + MatchInfoGuide guide, + TextMeshPro titleTmp, + Scroller parent, + string objName, + string title, + string description, + IReadOnlyCollection abilities) + { + parent.ScrollToTop(); + var obj = CreateAdvancedWikiTab( + guide, + objName, + title, + description, + titleTmp, + out var desc); + var num = 0; + if (abilities.Count != 0) + { + var grid = Object.Instantiate(parent.Inner, obj.transform); + var layoutGroup = grid.GetComponent(); + layoutGroup.startAxis = GridLayoutGroup.Axis.Vertical; + layoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount; + layoutGroup.spacing = new Vector2(0.75f, 0.4f); + grid.DestroyChildren(); + foreach (var ability in abilities) + { + num++; + SetupAbilityPanel(Object.Instantiate(guide.MatchInfoRolePanelPrefab, grid), ability); + } + + grid.localPosition = new Vector3(-3.9f, 1.1f - desc.textBounds.size.y, 0f); + grid.localScale = new Vector3(1.3f, 1.3f, 1); + } + + obj.transform.SetParent(parent.Inner.transform); + obj.transform.localPosition = new Vector3(0f, 0f, 0f); + parent.SetYBoundsMax(Mathf.Clamp(desc.textBounds.size.y - 2 + Mathf.Ceil(num / 2f) * 1.45f, 0f, 999f)); + return obj; + } + + private static void SetupAbilityPanel(MatchInfoRolePanel panel, AdvancedWikiAbilityDescription ability) + { + panel.roleCount.text = ability.AbilityType; + panel.roleCount.transform.localPosition += new Vector3(-0.04f, 0); + panel.roleName.text = ability.Name; + panel.roleName.transform.localPosition += new Vector3(-0.04f, 0); + panel.roleDescription.text = ability.Description; + panel.roleDescription.rectTransform.sizeDelta = new Vector2(2.601f, 0.8f); + panel.roleDescription.transform.localPosition += new Vector3(0, -0.1f); + panel.roleIcon.sprite = ability.Icon.LoadAsset(); + panel.roleIcon.SetSizeLimit(0.13f); + + panel.roleIcon.material.SetInt(PlayerMaterial.MaskLayer, 50); + panel.roleName.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f); + panel.roleDescription.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f); + panel.roleCount.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f); + panel.roleIcon.transform.localScale = new Vector3(3.5f, 3.5f, 1f); + } }