Skip to content

Commit

Permalink
Fix grid not being always resized
Browse files Browse the repository at this point in the history
  • Loading branch information
Meivyn committed Jun 19, 2024
1 parent a5f620e commit d241bef
Showing 1 changed file with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,27 @@ namespace PlaylistManager.AffinityPatches
{
public class AnnotatedBeatmapLevelCollectionsGridViewAnimatorPatches : IAffinity
{
private readonly AnnotatedBeatmapLevelCollectionsViewController _annotatedBeatmapLevelCollectionsTableViewController;
private readonly SelectLevelCategoryViewController _selectLevelCategoryViewController;

private int _originalColumnCount;
private Vector2 _originalScreenSize;
private bool _isGridViewResized;

public AnnotatedBeatmapLevelCollectionsGridViewAnimatorPatches(AnnotatedBeatmapLevelCollectionsViewController annotatedBeatmapLevelCollectionsTableViewController, SelectLevelCategoryViewController selectLevelCategoryViewController)
public AnnotatedBeatmapLevelCollectionsGridViewAnimatorPatches(SelectLevelCategoryViewController selectLevelCategoryViewController)
{
_annotatedBeatmapLevelCollectionsTableViewController = annotatedBeatmapLevelCollectionsTableViewController;
_selectLevelCategoryViewController = selectLevelCategoryViewController;
}

// TODO: Doesn't resize on internal restart.
[AffinityPatch(typeof(AnnotatedBeatmapLevelCollectionsGridView), nameof(AnnotatedBeatmapLevelCollectionsGridView.SetData))]
[AffinityPrefix]
private void AddColumnsAndResize(AnnotatedBeatmapLevelCollectionsGridView __instance, IReadOnlyList<BeatmapLevelPack> annotatedBeatmapLevelCollections)
private void ResizeGridView(AnnotatedBeatmapLevelCollectionsGridView __instance, IReadOnlyList<BeatmapLevelPack> annotatedBeatmapLevelCollections)
{
if (__instance._gridView._dataSource == null)
{
return;
}

if (_originalColumnCount == default)
{
_originalColumnCount = __instance._gridView._columnCount;
}

var selectedLevelCategory = _selectLevelCategoryViewController.selectedLevelCategory;
var animator = _annotatedBeatmapLevelCollectionsTableViewController._annotatedBeatmapLevelCollectionsGridView._animator;

if (selectedLevelCategory == SelectLevelCategoryViewController.LevelCategory.CustomSongs)
{
// Number of columns for max visible row count before it starts clipping with the ground.
Expand All @@ -52,8 +42,8 @@ private void AddColumnsAndResize(AnnotatedBeatmapLevelCollectionsGridView __inst
__instance._gridView._visibleColumnCount -= 1;

var rectTransform = (RectTransform)__instance._gridView.transform;
rectTransform.sizeDelta -= new Vector2(animator._columnWidth, 0);
rectTransform.anchoredPosition -= new Vector2(animator._columnWidth / 2, 0);
rectTransform.sizeDelta -= new Vector2(__instance._cellWidth, 0);
rectTransform.anchoredPosition -= new Vector2(__instance._cellWidth / 2, 0);

_isGridViewResized = true;
}
Expand All @@ -67,8 +57,8 @@ private void AddColumnsAndResize(AnnotatedBeatmapLevelCollectionsGridView __inst
__instance._gridView._visibleColumnCount += 1;

var rectTransform = (RectTransform)__instance._gridView.transform;
rectTransform.sizeDelta += new Vector2(animator._columnWidth, 0);
rectTransform.anchoredPosition += new Vector2(animator._columnWidth / 2, 0);
rectTransform.sizeDelta += new Vector2(__instance._cellWidth, 0);
rectTransform.anchoredPosition += new Vector2(__instance._cellWidth / 2, 0);

_isGridViewResized = false;
}
Expand Down

0 comments on commit d241bef

Please sign in to comment.