From 4277193aed2bfb7dd22cf5f9578ac1f4e09d8ab9 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:18:15 -0400 Subject: [PATCH] we forgot scrolling colors --- .../Patches/Colors/ScrollingColorsPatch.cs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 MiraAPI/Patches/Colors/ScrollingColorsPatch.cs diff --git a/MiraAPI/Patches/Colors/ScrollingColorsPatch.cs b/MiraAPI/Patches/Colors/ScrollingColorsPatch.cs new file mode 100644 index 0000000..9fdc6d4 --- /dev/null +++ b/MiraAPI/Patches/Colors/ScrollingColorsPatch.cs @@ -0,0 +1,58 @@ +using HarmonyLib; +using MiraAPI.Utilities.Assets; +using UnityEngine; + +namespace MiraAPI.Patches.Colors; + +[HarmonyPatch(typeof(PlayerTab))] +public static class ScrollingColorsPatch +{ + /// Collider + private static BoxCollider2D _collider; + + /// + /// Add scrolling to the colors tab + /// + [HarmonyPostfix, HarmonyPatch("OnEnable")] + public static void AddScrollingToColorsTabPatch(PlayerTab __instance) + { + if (!PlayerCustomizationMenu.Instance) + { + return; + } + + var tab = PlayerCustomizationMenu.Instance.Tabs[1].Tab; + + if (__instance.scroller == null) + { + var newScroller = Object.Instantiate(tab.scroller, __instance.transform, true); + newScroller.Inner.transform.DestroyChildren(); + + var maskObj = new GameObject + { + layer = 5, + name = "SpriteMask" + }; + maskObj.transform.SetParent(__instance.transform); + maskObj.transform.localPosition = new Vector3(0, 0, 0); + maskObj.transform.localScale = new Vector3(500, 4.76f); + + var mask = maskObj.AddComponent(); + mask.sprite = MiraAssets.Empty.LoadAsset(); + + _collider = maskObj.AddComponent(); + _collider.size = new Vector2(1f, 0.75f); + _collider.enabled = true; + __instance.scroller = newScroller; + } + + foreach (var chip in __instance.ColorChips) + { + chip.transform.SetParent(__instance.scroller.Inner); + chip.Button.ClickMask = _collider; + chip.GetComponent().maskInteraction = SpriteMaskInteraction.VisibleInsideMask; + } + + __instance.SetScrollerBounds(); + } +} \ No newline at end of file