Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Beat Saber 1.37.0 #68

Merged
merged 26 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ee04928
Update for Beat Saber 1.37.0
nicoco007 Feb 29, 2024
6e45382
Fix covers not being displayed properly
Meivyn Jun 12, 2024
2cc1fdf
Use the publicizer properly in patches
Meivyn Jun 12, 2024
37dbd1e
Use the existing `ProgressBar` instance
Meivyn Jun 12, 2024
1ceb86b
Fix refresh patch on internal restart
Meivyn Jun 12, 2024
4ba4767
Remove custom grid UI and use base game one
Meivyn Jun 12, 2024
46c8b72
Adjust grid X offset based on number of columns
KnuckleDF Jun 12, 2024
b6fc7da
Leftovers from custom grid
Meivyn Jun 12, 2024
958b0d7
Fix soft restart warning placement
nicoco007 Jun 13, 2024
f645344
Fix collection not working with one row
Meivyn Jun 16, 2024
4f9fac9
Fix viewport width when hovering collection
Meivyn Jun 17, 2024
392bc05
Dynamically resize grid so it isn't clipping
Meivyn Jun 18, 2024
e1325ad
Fix playlist hover hint not being shown outside screen bounds
Meivyn Jun 19, 2024
a5f620e
Show level collection header when playlist is empty
Meivyn Jun 19, 2024
d241bef
Fix grid not being always resized
Meivyn Jun 19, 2024
54f345d
Better patch to resize grid on hover
Metalit Jun 19, 2024
72a32e4
Use Zenject whenever possible
Meivyn Jun 20, 2024
f5ad0e7
Remove CI for now
Meivyn Jun 20, 2024
d0cad9a
Remove more custom grid leftovers
Meivyn Jul 4, 2024
4e91bd8
Final touch to UI patches
Meivyn Jul 4, 2024
f0e113b
Rename some stuff, cleanup
Meivyn Jul 4, 2024
a77b1dc
Fix SongCore integration
Meivyn Jul 4, 2024
c9b01be
Some optimization
Meivyn Jul 4, 2024
ec50a29
Fix UI refresh, less stutter
Meivyn Jul 5, 2024
a0af827
Fix UI patches
Meivyn Jul 5, 2024
1b99bc1
Bump version
Meivyn Jul 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions .github/workflows/master.yml

This file was deleted.

50 changes: 0 additions & 50 deletions .github/workflows/pr.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Reflection.Emit;
using HarmonyLib;
using SiraUtil.Affinity;
using SongCore.Utilities;
using UnityEngine;

namespace PlaylistManager.AffinityPatches
{
internal class AnnotatedBeatmapLevelCollectionsUIPatches : IAffinity
{
private readonly AnnotatedBeatmapLevelCollectionsViewController _annotatedBeatmapLevelCollectionsViewController;
private readonly SelectLevelCategoryViewController _selectLevelCategoryViewController;

private int _originalColumnCount;
private Vector2 _originalScreenSize;
private bool _isGridResized;

private AnnotatedBeatmapLevelCollectionsUIPatches(AnnotatedBeatmapLevelCollectionsViewController annotatedBeatmapLevelCollectionsViewController, SelectLevelCategoryViewController selectLevelCategoryViewController)
{
_annotatedBeatmapLevelCollectionsViewController = annotatedBeatmapLevelCollectionsViewController;
_selectLevelCategoryViewController = selectLevelCategoryViewController;
}

[AffinityPatch(typeof(AnnotatedBeatmapLevelCollectionsGridView), nameof(AnnotatedBeatmapLevelCollectionsGridView.SetData))]
[AffinityPrefix]
private void ResizeGrid(AnnotatedBeatmapLevelCollectionsGridView __instance, IReadOnlyList<BeatmapLevelPack> annotatedBeatmapLevelCollections)
{
if (_originalColumnCount == default)
{
_originalColumnCount = __instance._gridView._columnCount;
}

var selectedLevelCategory = _selectLevelCategoryViewController.selectedLevelCategory;
if (selectedLevelCategory == SelectLevelCategoryViewController.LevelCategory.CustomSongs)
{
// Number of columns for max visible row count before it starts clipping with the ground.
__instance._gridView._columnCount = Math.Max(Mathf.CeilToInt((annotatedBeatmapLevelCollections?.Count ?? 0) / 5f), _originalColumnCount);

// Remove one column to make room for our buttons.
if (!_isGridResized)
{
__instance._gridView._visibleColumnCount -= 1;

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

_isGridResized = true;
}
}
else if (selectedLevelCategory == SelectLevelCategoryViewController.LevelCategory.MusicPacks)
{
__instance._gridView._columnCount = _originalColumnCount;

// Restore the removed column since we don't want to show an empty cell.
if (_isGridResized)
{
__instance._gridView._visibleColumnCount += 1;

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

_isGridResized = false;
}
}
}

[AffinityPatch(typeof(AnnotatedBeatmapLevelCollectionsGridView), nameof(AnnotatedBeatmapLevelCollectionsGridView.OnPointerEnter))]
[AffinityTranspiler]
private IEnumerable<CodeInstruction> ChangeInteractableConditionOnEnter(IEnumerable<CodeInstruction> instructions, ILGenerator il)
{
return ChangeInteractableCondition(instructions, il);
}

[AffinityPatch(typeof(AnnotatedBeatmapLevelCollectionsGridView), nameof(AnnotatedBeatmapLevelCollectionsGridView.OnPointerExit))]
[AffinityTranspiler]
private IEnumerable<CodeInstruction> ChangeInteractableConditionOnExit(IEnumerable<CodeInstruction> instructions, ILGenerator il)
{
return ChangeInteractableCondition(instructions, il);
}

[AffinityPatch(typeof(AnnotatedBeatmapLevelCollectionsGridView), nameof(AnnotatedBeatmapLevelCollectionsGridView.HandleCellSelectionDidChange))]
[AffinityTranspiler]
private IEnumerable<CodeInstruction> ChangeInteractableConditionOnSelect(IEnumerable<CodeInstruction> instructions, ILGenerator il)
{
return ChangeInteractableCondition(instructions, il);
}

private static IEnumerable<CodeInstruction> ChangeInteractableCondition(IEnumerable<CodeInstruction> instructions, ILGenerator il)
{
// Makes the grid interactable when there's 1 row or more, and when there's more collections to display than the number of visible columns.
var codeMatcher = new CodeMatcher(instructions, il)
.MatchStartForward(new CodeMatch(OpCodes.Ldc_I4_1))
.ThrowIfInvalid()
.SetOpcodeAndAdvance(OpCodes.Ldc_I4_0);
return codeMatcher
.InsertBranchAndAdvance(OpCodes.Ble_S, codeMatcher.Pos + 1)
.Insert(
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(AnnotatedBeatmapLevelCollectionsGridView), nameof(AnnotatedBeatmapLevelCollectionsGridView._annotatedBeatmapLevelCollections))),
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(IReadOnlyCollection<>).MakeGenericType(typeof(BeatmapLevelPack)), nameof(IReadOnlyList<BeatmapLevelPack>.Count))),
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(AnnotatedBeatmapLevelCollectionsGridView), nameof(AnnotatedBeatmapLevelCollectionsGridView._gridView))),
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(GridView), nameof(GridView.visibleColumnCount))))
.InstructionEnumeration();
}

[AffinityPatch(typeof(AnnotatedBeatmapLevelCollectionsGridViewAnimator), nameof(AnnotatedBeatmapLevelCollectionsGridViewAnimator.GetContentXOffset))]
private void RecalculateContentXOffsetBasedOnColumnCount(AnnotatedBeatmapLevelCollectionsGridViewAnimator __instance, ref float __result)
{
if (_annotatedBeatmapLevelCollectionsViewController._annotatedBeatmapLevelCollectionsGridView._annotatedBeatmapLevelCollections == null)
{
return;
}

if (_annotatedBeatmapLevelCollectionsViewController._annotatedBeatmapLevelCollectionsGridView._annotatedBeatmapLevelCollections.Count <= __instance._visibleColumnCount)
{
__result = __instance._columnWidth;

return;
}

var zeroOffset = (__instance._columnCount - 1) / 2f;
var maxMove = (__instance._columnCount - __instance._visibleColumnCount) / 2f;
var toMove = zeroOffset - __instance._selectedColumn;
if (__instance._visibleColumnCount % 2 == 0)
{
toMove -= 0.5f;
}

__result = Math.Clamp(toMove, -maxMove, maxMove) * __instance._columnWidth;
}

[AffinityPatch(typeof(AnnotatedBeatmapLevelCollectionsGridViewAnimator), nameof(AnnotatedBeatmapLevelCollectionsGridViewAnimator.AnimateOpen))]
private void RecalculateSizeBasedOnColumnCount(AnnotatedBeatmapLevelCollectionsGridViewAnimator __instance, bool animated)
{
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);
}

if (_isGridResized)
{
// It would otherwise fly away when setting the Screen size.
var rectTransform = (RectTransform)_selectLevelCategoryViewController.transform;

if (rectTransform.anchorMin.x == 0 || rectTransform.anchorMax.x == 0)
{
var localPosition = rectTransform.localPosition;
rectTransform.anchorMin = new Vector2(0.5f, rectTransform.anchorMin.y);
rectTransform.anchorMax = new Vector2(0.5f, rectTransform.anchorMax.y);
rectTransform.localPosition = localPosition;
}

rectTransform = (RectTransform)__instance.gameObject.GetComponentInParent<HMUI.Screen>().transform;

if (_originalScreenSize == default)
{
_originalScreenSize = rectTransform.sizeDelta;
}

// Resizing Screen is needed to allow the hover hint to be shown when the GridView is larger.
rectTransform.sizeDelta = new Vector2(_originalScreenSize.x + (__instance._columnCount - __instance._visibleColumnCount - 1) * __instance._columnWidth * 2, _originalScreenSize.y);
}
}
}
}
Loading