diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index e7ac548..345c9a6 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -165,85 +165,6 @@ public static class HudManagerPatches { __instance.chatNotifyDot.transform.localPosition = new Vector3(-0.34f, 0.373f, -1f); } - [HarmonyPrefix] - [HarmonyPriority(Priority.First)] - [HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.Open))] - public static bool Open(MatchInfoGuide __instance) - { - if (HudManager.Instance.GameMenu.IsOpen || HudManager.Instance.Chat.IsOpenOrOpening) - { - return false; - } - if (Minigame.Instance != null) - { - Minigame.Instance.Close(); - } - if (MapBehaviour.Instance) - { - MapBehaviour.Instance.Close(); - } - if (HudManager.InstanceExists) - { - ConsoleJoystick.SetMode_MenuAdditive(); - } - ControllerManager.Instance.OpenOverlayMenu("MatchInfoGuide", __instance.closeButton); - bool enabled = ActiveInputManager.currentControlType == ActiveInputManager.InputType.Joystick; - __instance.glyphL.enabled = enabled; - __instance.glyphR.enabled = enabled; - if (GameManager.Instance.TryCast() != null) - { - if (__instance.NormalModeSettings.Count == 0) - { - __instance.numOfTabs = 3; - __instance.TabButtons[0].SelectButton(true); - __instance.CreateNormalModeSettings(); - } - } - else if (__instance.HnSModeSettings.Count == 0) - { - __instance.numOfTabs = 2; - __instance.TabButtons[0].SelectButton(true); - __instance.CreateHnSModeSettings(); - } - PlayerControl.LocalPlayer.NetTransform.Halt(); - __instance.MatchInfoParent.SetActive(true); - ControllerManager instance = ControllerManager.Instance; - ControllerUiElementsState currentUiState = ControllerManager.Instance.CurrentUiState; - Il2CppSystem.Collections.Generic.List controllerSelectable = __instance.ControllerSelectable; - instance.SetUpSelectables(currentUiState, controllerSelectable[controllerSelectable.Count - 1], __instance.ControllerSelectable); - ControllerManager instance2 = ControllerManager.Instance; - Il2CppSystem.Collections.Generic.List controllerSelectable2 = __instance.ControllerSelectable; - instance2.SetCurrentSelected(controllerSelectable2[controllerSelectable2.Count - 1]); - __instance.SetActiveTab(0); - return false; - } - [HarmonyPrefix] - [HarmonyPriority(Priority.First)] - [HarmonyPatch(typeof(MatchInfoRolePanel), nameof(MatchInfoRolePanel.SetPanel))] - public static bool SetPanel(MatchInfoRolePanel __instance, RoleBehaviour role, int numPerGame, int chancePerGame) - { - if (role is ICustomRole customRole) - { - __instance.roleName.text = customRole.RoleName; - __instance.roleDescription.text = customRole.RoleDescription; - __instance.roleIcon.sprite = customRole.Configuration.Icon?.LoadAsset(); - } - else - { - __instance.roleName.text = role.NiceName; - __instance.roleDescription.text = role.BlurbMed; - __instance.roleIcon.sprite = role.RoleIconColor; - } - - __instance.roleIcon.SetSizeLimit(0.13f); - __instance.roleCount.text = string.Format(CultureInfo.InvariantCulture, "{0} at {1}%", numPerGame.ToString(CultureInfo.InvariantCulture), chancePerGame); - __instance.roleIcon.material.SetInt(PlayerMaterial.MaskLayer, 50); - __instance.roleName.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f); - __instance.roleDescription.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f); - __instance.roleCount.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f); - __instance.roleIcon.transform.localScale = new Vector3(4f, 4f, 1f); - return false; - } /// /// Create custom buttons and arrange them on the hud. diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs new file mode 100644 index 0000000..8ddfd00 --- /dev/null +++ b/MiraAPI/Patches/RoleGuidePatches.cs @@ -0,0 +1,129 @@ +using System.Globalization; +using System.Linq; +using HarmonyLib; +using MiraAPI.Roles; +using MiraAPI.Utilities; +using UnityEngine; + +namespace MiraAPI.Patches; + +[HarmonyPatch] +public static class RoleGuidePatches +{ + [HarmonyPostfix] + [HarmonyPriority(Priority.First)] + [HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.CreateNormalModeSettings))] + [HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.CreateHnSModeSettings))] + public static void CreateNormalModeSettings(MatchInfoGuide __instance) + { + __instance.MatchInfoRoleMaskArea.transform.localPosition = new Vector3(-0.0184f, 0.15f, -0.1f); + + __instance.matchInfoPlayersMaskArea.transform.localPosition = + __instance.matchInfoSettingsMaskArea.transform.localPosition = new Vector3(1.22f, -0.335f, -0.1f); + + __instance.matchInfoPlayersMaskArea.size = + __instance.matchInfoSettingsMaskArea.size = + __instance.MatchInfoRoleMaskArea.size = new Vector2(-6, 1.8f); + + __instance.matchInfoPlayersMaskArea.transform.parent.GetAllChildren().First(x => x.name.Contains("BG_Gradient")) + .GetComponent() + .maskInteraction = + __instance.matchInfoSettingsMaskArea.transform.parent.GetAllChildren() + .First(x => x.name.Contains("BG_Gradient")).GetComponent() + .maskInteraction = + __instance.MatchInfoRoleMaskArea.transform.parent.GetAllChildren() + .First(x => x.name.Contains("BG_Gradient")).GetComponent() + .maskInteraction = SpriteMaskInteraction.VisibleInsideMask; + } + + [HarmonyPrefix] + [HarmonyPriority(Priority.First)] + [HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.Awake))] + public static void Awake(MatchInfoGuide __instance) + { + __instance.transitionOpen.targetSize = 1.3f; + } + + [HarmonyPrefix] + [HarmonyPriority(Priority.First)] + [HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.Open))] + public static bool Open(MatchInfoGuide __instance) + { + if (HudManager.Instance.GameMenu.IsOpen || HudManager.Instance.Chat.IsOpenOrOpening) + { + return false; + } + + if (Minigame.Instance != null) + { + Minigame.Instance.Close(); + } + if (MapBehaviour.Instance) + { + MapBehaviour.Instance.Close(); + } + if (HudManager.InstanceExists) + { + ConsoleJoystick.SetMode_MenuAdditive(); + } + ControllerManager.Instance.OpenOverlayMenu("MatchInfoGuide", __instance.closeButton); + bool enabled = ActiveInputManager.currentControlType == ActiveInputManager.InputType.Joystick; + __instance.glyphL.enabled = enabled; + __instance.glyphR.enabled = enabled; + if (GameManager.Instance.TryCast() != null) + { + if (__instance.NormalModeSettings.Count == 0) + { + __instance.numOfTabs = 3; + __instance.TabButtons[0].SelectButton(true); + __instance.CreateNormalModeSettings(); + } + } + else if (__instance.HnSModeSettings.Count == 0) + { + __instance.numOfTabs = 2; + __instance.TabButtons[0].SelectButton(true); + __instance.CreateHnSModeSettings(); + } + PlayerControl.LocalPlayer.NetTransform.Halt(); + __instance.MatchInfoParent.SetActive(true); + ControllerManager instance = ControllerManager.Instance; + ControllerUiElementsState currentUiState = ControllerManager.Instance.CurrentUiState; + Il2CppSystem.Collections.Generic.List controllerSelectable = __instance.ControllerSelectable; + instance.SetUpSelectables(currentUiState, controllerSelectable[controllerSelectable.Count - 1], __instance.ControllerSelectable); + ControllerManager instance2 = ControllerManager.Instance; + Il2CppSystem.Collections.Generic.List controllerSelectable2 = __instance.ControllerSelectable; + instance2.SetCurrentSelected(controllerSelectable2[controllerSelectable2.Count - 1]); + __instance.SetActiveTab(0); + return false; + } + [HarmonyPrefix] + [HarmonyPriority(Priority.First)] + [HarmonyPatch(typeof(MatchInfoRolePanel), nameof(MatchInfoRolePanel.SetPanel))] + public static bool SetPanel(MatchInfoRolePanel __instance, RoleBehaviour role, int numPerGame, int chancePerGame) + { + __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 = customRole.RoleDescription; + __instance.roleIcon.sprite = customRole.Configuration.Icon?.LoadAsset(); + __instance.roleCount.text += $" ({customRole.ParentMod.MiraPlugin.GetAbbreviatedModName()})"; + } + else + { + __instance.roleName.text = role.NiceName; + __instance.roleDescription.text = role.BlurbMed; + __instance.roleIcon.sprite = role.RoleIconColor; + __instance.roleCount.text += " (AU)"; + } + + __instance.roleIcon.SetSizeLimit(0.13f); + __instance.roleIcon.material.SetInt(PlayerMaterial.MaskLayer, 50); + __instance.roleName.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f); + __instance.roleDescription.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f); + __instance.roleCount.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f); + __instance.roleIcon.transform.localScale = new Vector3(4f, 4f, 1f); + return false; + } +} diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 7a219da..0bd42eb 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -378,6 +378,18 @@ public static class Extensions } } + /// + /// Gets all child objects in a parent Transform. + /// + /// An that contains s. + public static IEnumerable GetAllChildren(this Transform go) + { + for (var i = 0; i < go.transform.childCount; i++) + { + yield return go.transform.GetChild(i).gameObject; + } + } + /// /// Resizes a appropriate to the maximum pixel size without messing up ratios. ///