From 54f345d6fcd2554fc52018292fb752422caadcd3 Mon Sep 17 00:00:00 2001 From: Metalit <48568911+metalit@users.noreply.github.com> Date: Wed, 19 Jun 2024 00:44:49 -0400 Subject: [PATCH] Better patch to resize grid on hover --- ...LevelCollectionsGridViewAnimatorPatches.cs | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/PlaylistManager/AffinityPatches/AnnotatedBeatmapLevelCollectionsGridViewAnimatorPatches.cs b/PlaylistManager/AffinityPatches/AnnotatedBeatmapLevelCollectionsGridViewAnimatorPatches.cs index b6ea4bd..a4c9cd3 100644 --- a/PlaylistManager/AffinityPatches/AnnotatedBeatmapLevelCollectionsGridViewAnimatorPatches.cs +++ b/PlaylistManager/AffinityPatches/AnnotatedBeatmapLevelCollectionsGridViewAnimatorPatches.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Reflection; using System.Reflection.Emit; using HarmonyLib; using SiraUtil.Affinity; @@ -93,24 +92,18 @@ private IEnumerable OpenCollectionWithOneRow(IEnumerable FixViewportWidth(IEnumerable instructions) + private void ChangeGridAndScreenSize(AnnotatedBeatmapLevelCollectionsGridViewAnimator __instance, bool animated) { - return new CodeMatcher(instructions) - .MatchStartForward(new CodeMatch(i => i.opcode == OpCodes.Call && i.operand as ConstructorInfo == AccessTools.Constructor(typeof(Vector2), new[] { typeof(float), typeof(float) }))) - .ThrowIfInvalid() - .Advance(-2) - .RemoveInstruction() - .Insert( - new CodeInstruction(OpCodes.Ldarg_0), - Transpilers.EmitDelegate>(animator => - ((animator._columnCount - animator._visibleColumnCount) * 2 + animator._visibleColumnCount) * animator._columnWidth)) - .InstructionEnumeration(); - } + var x = ((__instance._columnCount - __instance._visibleColumnCount) * 2 + __instance._visibleColumnCount) * __instance._columnWidth; + if (animated) + { + __instance._viewportSizeTween.toValue = new Vector2(x, __instance._viewportSizeTween.toValue.y); + } + else + { + __instance._viewportTransform.sizeDelta = new Vector2(x, __instance._viewportTransform.sizeDelta.y); + } - [AffinityPatch(typeof(AnnotatedBeatmapLevelCollectionsGridViewAnimator), nameof(AnnotatedBeatmapLevelCollectionsGridViewAnimator.AnimateOpen))] - private void ChangeScreenSize(AnnotatedBeatmapLevelCollectionsGridViewAnimator __instance) - { if (_isGridViewResized) { var rectTransform = (RectTransform)_selectLevelCategoryViewController.transform;