diff --git a/MiraAPI/Patches/Menu/HatsTabPatches.cs b/MiraAPI/Patches/Menu/HatsTabPatches.cs index 8d36e9c..8cd2bfd 100644 --- a/MiraAPI/Patches/Menu/HatsTabPatches.cs +++ b/MiraAPI/Patches/Menu/HatsTabPatches.cs @@ -6,10 +6,13 @@ using System.Linq; using AmongUs.Data; using HarmonyLib; using MiraAPI.Utilities; +using MiraAPI.Utilities.Assets; using Reactor.Utilities; using Reactor.Utilities.Extensions; using TMPro; using UnityEngine; +using UnityEngine.Events; +using UnityEngine.UI; using Object = UnityEngine.Object; namespace MiraAPI.Patches.Menu; @@ -20,6 +23,20 @@ public static class HatsTabPatches private static SortedList> sortedHats = []; private static int currentPage; + private static void PreviousPage(HatsTab hatsTab) + { + currentPage--; + currentPage = currentPage < 0 ? sortedHats.Count - 1 : currentPage; + GenerateHats(hatsTab, currentPage); + } + + private static void NextPage(HatsTab hatsTab) + { + currentPage++; + currentPage = currentPage > sortedHats.Count - 1 ? 0 : currentPage; + GenerateHats(hatsTab, currentPage); + } + [HarmonyPatch(nameof(HatsTab.OnEnable))] [HarmonyPrefix] public static bool OnEnablePrefix(HatsTab __instance) @@ -38,6 +55,8 @@ public static class HatsTabPatches } } + InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage); + GenerateHats(__instance, currentPage); return false; @@ -45,22 +64,17 @@ public static class HatsTabPatches [HarmonyPatch(typeof(HatsTab), nameof(HatsTab.Update))] [HarmonyPrefix] - public static void UpdatePrefix(HatsTab __instance) { if (sortedHats.Count == 0) return; if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow)) { - currentPage--; - currentPage = currentPage < 0 ? sortedHats.Count - 1 : currentPage; - GenerateHats(__instance, currentPage); + PreviousPage(__instance); } else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow)) { - currentPage++; - currentPage = currentPage > sortedHats.Count - 1 ? 0 : currentPage; - GenerateHats(__instance, currentPage); + NextPage(__instance); } } @@ -84,10 +98,10 @@ public static class HatsTabPatches text.gameObject.transform.localScale = Vector3.one; text.GetComponent().Destroy(); text.EnableStencilMasking(); - text.text = $"{groupName} ({currentPage + 1}/{sortedHats.Count})\nPress Ctrl or Tab to cycle pages"; + text.text = $"{groupName} ({currentPage + 1}/{sortedHats.Count})"; text.alignment = TextAlignmentOptions.Center; - text.fontSize = 3f; - text.fontSizeMax = 3f; + text.fontSize = 5f; + text.fontSizeMax = 5f; text.fontSizeMin = 0f; var xLerp = __instance.XRange.Lerp(0.5f); var yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; @@ -125,9 +139,17 @@ public static class HatsTabPatches { var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner); colorChip.gameObject.name = hat.ProductId; - colorChip.Button.OnClick.AddListener((Action)(() => __instance.ClickEquip())); - colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectHat(hat))); - colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectHat(HatManager.Instance.GetHatById(DataManager.Player.Customization.Hat)))); + if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard) + { + colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip); + colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectHat(hat))); + colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectHat(HatManager.Instance.GetHatById(DataManager.Player.Customization.Hat)))); + } + else + { + colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectHat(hat))); + } + colorChip.Inner.SetHat(hat, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color); colorChip.Button.ClickMask = __instance.scroller.Hitbox; colorChip.SelectionHighlight.gameObject.SetActive(false); diff --git a/MiraAPI/Patches/Menu/InventoryUtility.cs b/MiraAPI/Patches/Menu/InventoryUtility.cs new file mode 100644 index 0000000..95004d0 --- /dev/null +++ b/MiraAPI/Patches/Menu/InventoryUtility.cs @@ -0,0 +1,54 @@ +using System; +using MiraAPI.Utilities.Assets; +using TMPro; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.UI; +using Object = UnityEngine.Object; + +namespace MiraAPI.Patches.Menu; + +public static class InventoryUtility +{ + public static void CreateNextBackButtons(T tab, Action previousPage, Action nextPage) where T : InventoryTab + { + var title = tab.transform.FindChild("Text"); + title.localPosition = new Vector3(.9123f, -.23f, -55); + title.GetComponent().alignment = TextAlignmentOptions.Center; + + tab.scroller.Hitbox.transform.localScale -= new Vector3(0, 0.1f, 0); + tab.scroller.Hitbox.transform.localPosition -= new Vector3(0, 0.1f, 0); + + var leftButtonElement = Object.Instantiate(PlayerCustomizationMenu.Instance.BackButton.gameObject, tab.transform); + var leftSpriteRenderer = leftButtonElement.GetComponent(); + var leftButton = leftButtonElement.GetComponent(); + + leftButtonElement.transform.localPosition = new Vector3(-1.1f, -0.2f, -55); + leftSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset(); + leftSpriteRenderer.flipX = true; + + leftButton.OnMouseOver = new UnityEvent(); + leftButton.OnMouseOver.AddListener((Action)(() => leftSpriteRenderer.sprite = MiraAssets.NextButtonActive.LoadAsset())); + leftButton.OnMouseOut = new UnityEvent(); + leftButton.OnMouseOut.AddListener((Action)(() => leftSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset())); + + leftButton.OnClick = new Button.ButtonClickedEvent(); + leftButton.OnClick.AddListener((Action)(() => previousPage(tab))); + + var rightButtonElement = Object.Instantiate(leftButtonElement, tab.transform); + var rightSpriteRenderer = rightButtonElement.GetComponent(); + var rightButton = rightButtonElement.GetComponent(); + + rightButtonElement.transform.localPosition = new Vector3(2.8f, -0.2f, -55); + rightSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset(); + rightSpriteRenderer.flipX = false; + + rightButton.OnMouseOver = new UnityEvent(); + rightButton.OnMouseOver.AddListener((Action)(() => rightSpriteRenderer.sprite = MiraAssets.NextButtonActive.LoadAsset())); + rightButton.OnMouseOut = new UnityEvent(); + rightButton.OnMouseOut.AddListener((Action)(() => rightSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset())); + + rightButton.OnClick = new Button.ButtonClickedEvent(); + rightButton.OnClick.AddListener((Action)(() => nextPage(tab))); + } +} diff --git a/MiraAPI/Patches/Menu/NameplatesTabPatches.cs b/MiraAPI/Patches/Menu/NameplatesTabPatches.cs index 11657a0..0b7acfe 100644 --- a/MiraAPI/Patches/Menu/NameplatesTabPatches.cs +++ b/MiraAPI/Patches/Menu/NameplatesTabPatches.cs @@ -26,6 +26,20 @@ public static class NameplatesTabPatches } } + private static void PreviousPage(NameplatesTab tab) + { + currentPage--; + currentPage = currentPage < 0 ? SortedNameplates.Count - 1 : currentPage; + GenerateHats(tab, currentPage); + } + + private static void NextPage(NameplatesTab tab) + { + currentPage++; + currentPage = currentPage > SortedNameplates.Count - 1 ? 0 : currentPage; + GenerateHats(tab, currentPage); + } + [HarmonyPatch(nameof(NameplatesTab.OnEnable))] [HarmonyPrefix] public static bool OnEnablePrefix(NameplatesTab __instance) @@ -33,6 +47,9 @@ public static class NameplatesTabPatches __instance.plateId = HatManager.Instance.GetNamePlateById(DataManager.Player.Customization.namePlate).ProdId; if (!SortedNameplates.ContainsKey("Vanilla")) AddRange(DestroyableSingleton.Instance.GetUnlockedNamePlates().Select(x => ("Vanilla", x))); + + InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage); + GenerateHats(__instance, currentPage); return false; @@ -45,15 +62,11 @@ public static class NameplatesTabPatches { if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow)) { - currentPage--; - currentPage = currentPage < 0 ? SortedNameplates.Count - 1 : currentPage; - GenerateHats(__instance, currentPage); + PreviousPage(__instance); } else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow)) { - currentPage++; - currentPage = currentPage > SortedNameplates.Count - 1 ? 0 : currentPage; - GenerateHats(__instance, currentPage); + NextPage(__instance); } } @@ -73,10 +86,10 @@ public static class NameplatesTabPatches text.gameObject.transform.localScale = Vector3.one; text.GetComponent().Destroy(); text.EnableStencilMasking(); - text.text = $"{groupName} ({currentPage + 1}/{SortedNameplates.Count})\nPress Ctrl or Tab to cycle pages"; + text.text = $"{groupName} ({currentPage + 1}/{SortedNameplates.Count})"; text.alignment = TextAlignmentOptions.Center; - text.fontSize = 3f; - text.fontSizeMax = 3f; + text.fontSize = 5f; + text.fontSizeMax = 5f; text.fontSizeMin = 0f; float xLerp = __instance.XRange.Lerp(0.5f); float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; @@ -99,9 +112,20 @@ public static class NameplatesTabPatches { var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner); colorChip.gameObject.name = namePlate.ProductId; - colorChip.Button.OnClick.AddListener((Action)(() => __instance.ClickEquip())); - colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectNameplate(namePlate))); - colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectNameplate(HatManager.Instance.GetNamePlateById(DataManager.Player.Customization.NamePlate)))); + + if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard) + { + colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip); + colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectNameplate(namePlate))); + colorChip.Button.OnMouseOut.AddListener( + (Action)(() => __instance.SelectNameplate( + HatManager.Instance.GetNamePlateById(DataManager.Player.Customization.NamePlate)))); + } + else + { + colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectNameplate(namePlate))); + } + colorChip.Button.ClickMask = __instance.scroller.Hitbox; colorChip.ProductId = namePlate.ProdId; diff --git a/MiraAPI/Patches/Menu/SkinsTabPatches.cs b/MiraAPI/Patches/Menu/SkinsTabPatches.cs index 9378d8b..b5ea7d7 100644 --- a/MiraAPI/Patches/Menu/SkinsTabPatches.cs +++ b/MiraAPI/Patches/Menu/SkinsTabPatches.cs @@ -18,6 +18,20 @@ public static class SkinsTabPatches private static SortedList> sortedSkins = []; private static int currentPage; + private static void PreviousPage(SkinsTab tab) + { + currentPage--; + currentPage = currentPage < 0 ? sortedSkins.Count - 1 : currentPage; + GenerateHats(tab, currentPage); + } + + private static void NextPage(SkinsTab tab) + { + currentPage++; + currentPage = currentPage > sortedSkins.Count - 1 ? 0 : currentPage; + GenerateHats(tab, currentPage); + } + [HarmonyPatch(nameof(SkinsTab.OnEnable))] [HarmonyPrefix] public static bool OnEnablePrefix(SkinsTab __instance) @@ -36,6 +50,8 @@ public static class SkinsTabPatches } } + InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage); + GenerateHats(__instance, currentPage); return false; @@ -48,15 +64,11 @@ public static class SkinsTabPatches { if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow)) { - currentPage--; - currentPage = currentPage < 0 ? sortedSkins.Count - 1 : currentPage; - GenerateHats(__instance, currentPage); + PreviousPage(__instance); } else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow)) { - currentPage++; - currentPage = currentPage > sortedSkins.Count - 1 ? 0 : currentPage; - GenerateHats(__instance, currentPage); + NextPage(__instance); } } @@ -76,10 +88,10 @@ public static class SkinsTabPatches text.gameObject.transform.localScale = Vector3.one; text.GetComponent().Destroy(); text.EnableStencilMasking(); - text.text = $"{groupName} ({currentPage + 1}/{sortedSkins.Count})\nPress Ctrl or Tab to cycle pages"; + text.text = $"{groupName} ({currentPage + 1}/{sortedSkins.Count})"; text.alignment = TextAlignmentOptions.Center; - text.fontSize = 3f; - text.fontSizeMax = 3f; + text.fontSize = 5f; + text.fontSizeMax = 5f; text.fontSizeMin = 0f; float xLerp = __instance.XRange.Lerp(0.5f); float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; @@ -102,9 +114,18 @@ public static class SkinsTabPatches { var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner); colorChip.gameObject.name = skin.ProductId; - colorChip.Button.OnClick.AddListener((Action)(() => __instance.ClickEquip())); - colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectSkin(skin))); - colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectSkin(HatManager.Instance.GetSkinById(DataManager.Player.Customization.Skin)))); + if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard) + { + colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip); + colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectSkin(skin))); + colorChip.Button.OnMouseOut.AddListener( + (Action)(() => + __instance.SelectSkin(HatManager.Instance.GetSkinById(DataManager.Player.Customization.Skin)))); + } + else + { + colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectSkin(skin))); + } colorChip.Button.ClickMask = __instance.scroller.Hitbox; colorChip.ProductId = skin.ProductId; colorChip.SelectionHighlight.gameObject.SetActive(false); diff --git a/MiraAPI/Patches/Menu/VisorsTabPatches.cs b/MiraAPI/Patches/Menu/VisorsTabPatches.cs index 92d5b8e..e801c1a 100644 --- a/MiraAPI/Patches/Menu/VisorsTabPatches.cs +++ b/MiraAPI/Patches/Menu/VisorsTabPatches.cs @@ -25,6 +25,21 @@ public static class VisorsTabPatches } } + private static void PreviousPage(VisorsTab tab) + { + currentPage--; + currentPage = currentPage < 0 ? SortedVisors.Count - 1 : currentPage; + GenerateHats(tab, currentPage); + } + + private static void NextPage(VisorsTab tab) + { + currentPage++; + currentPage = currentPage > SortedVisors.Count - 1 ? 0 : currentPage; + GenerateHats(tab, currentPage); + } + + [HarmonyPatch(nameof(VisorsTab.OnEnable))] [HarmonyPrefix] public static bool OnEnablePrefix(VisorsTab __instance) @@ -32,6 +47,9 @@ public static class VisorsTabPatches __instance.visorId = HatManager.Instance.GetVisorById(DataManager.Player.Customization.Visor).ProdId; if (!SortedVisors.ContainsKey("Vanilla")) AddRange(DestroyableSingleton.Instance.GetUnlockedVisors().Select(x => ("Vanilla", x))); + + InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage); + GenerateHats(__instance, currentPage); return false; @@ -44,15 +62,11 @@ public static class VisorsTabPatches { if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow)) { - currentPage--; - currentPage = currentPage < 0 ? SortedVisors.Count - 1 : currentPage; - GenerateHats(__instance, currentPage); + PreviousPage(__instance); } else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow)) { - currentPage++; - currentPage = currentPage > SortedVisors.Count - 1 ? 0 : currentPage; - GenerateHats(__instance, currentPage); + NextPage(__instance); } } @@ -72,10 +86,10 @@ public static class VisorsTabPatches text.gameObject.transform.localScale = Vector3.one; text.GetComponent().Destroy(); text.EnableStencilMasking(); - text.text = $"{groupName} ({currentPage + 1}/{SortedVisors.Count})\nPress Ctrl or Tab to cycle pages"; + text.text = $"{groupName} ({currentPage + 1}/{SortedVisors.Count})"; text.alignment = TextAlignmentOptions.Center; - text.fontSize = 3f; - text.fontSizeMax = 3f; + text.fontSize = 5f; + text.fontSizeMax = 5f; text.fontSizeMin = 0f; float xLerp = __instance.XRange.Lerp(0.5f); float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; @@ -98,9 +112,20 @@ public static class VisorsTabPatches { var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner); colorChip.gameObject.name = visor.ProductId; - colorChip.Button.OnClick.AddListener((Action)(() => __instance.ClickEquip())); - colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectVisor(visor))); - colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectVisor(HatManager.Instance.GetVisorById(DataManager.Player.Customization.Visor)))); + + if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard) + { + colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip); + colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectVisor(visor))); + colorChip.Button.OnMouseOut.AddListener( + (Action)(() => + __instance.SelectVisor(HatManager.Instance.GetVisorById(DataManager.Player.Customization.Visor)))); + } + else + { + colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectVisor(visor))); + } + colorChip.Button.ClickMask = __instance.scroller.Hitbox; colorChip.ProductId = visor.ProductId; colorChip.SelectionHighlight.gameObject.SetActive(false);