Skip to content

Commit

Permalink
Added user filter in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
rithik-b committed Mar 21, 2022
1 parent edf8333 commit f3fddbb
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 15 deletions.
11 changes: 7 additions & 4 deletions MorePlaylists/BeatSaver/BeatSaverFiltersView.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
<horizontal anchor-min-y='0.9' bg='panel-top' pad-left='10' pad-right='10' horizontal-fit='PreferredSize'>
<text text='Filters' align='Center' font-size='8' />
</horizontal>
<vertical id="vertical" vertical-fit='PreferredSize' pref-height="50">
<checkbox-setting text="Include Empty" value="include-empty" hover-hint="Include empty playlists in the search." apply-on-change='true' bind-value='true' />
<checkbox-setting text="Curated Only" value="curated-only" hover-hint="Only show curated playlists." apply-on-change='true' bind-value='true' />
</vertical>
<text-segments id='filters-tab-selector' anchor-pos-y="-12" size-delta-x="-105" size-delta-y='-74' select-cell="tab-switched" contents="filters" />
<bg id="filter-ui" anchor-pos-y="-3">
<vertical id="search-vertical" vertical-fit='PreferredSize' pref-height="40" anchor-pos-y="-5">
<checkbox-setting text="Include Empty" value="include-empty" hover-hint="Include empty playlists in the search." apply-on-change='true' bind-value='true' />
<checkbox-setting text="Curated Only" value="curated-only" hover-hint="Only show curated playlists." apply-on-change='true' bind-value='true' />
</vertical>
</bg>
<horizontal horizontal-fit='PreferredSize' child-control-height='false' child-expand-height='false' child-align='MiddleCenter' anchor-min-x='0.5' anchor-max-x='0.5' anchor-min-y='0' anchor-max-y='0' size-delta-x='120' size-delta-y='10' pivot-y='0' spacing='2'>
<button text='Cancel' pref-width='34' pref-height='10' on-click='cancel-click' />
<action-button text='Ok' pref-width='34' pref-height='10' on-click='ok-click' />
Expand Down
66 changes: 55 additions & 11 deletions MorePlaylists/BeatSaver/BeatSaverFiltersViewController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using BeatSaberMarkupLanguage.Attributes;
using BeatSaberMarkupLanguage.ViewControllers;
using HMUI;
Expand All @@ -15,39 +17,78 @@ internal class BeatSaverFiltersViewController : BSMLAutomaticViewController
[Inject]
private readonly InputFieldGrabber inputFieldGrabber = null!;

[Inject]
private readonly AnimationGrabber animationGrabber = null!;

private InputFieldView? inputFieldView;
private CurvedTextMeshPro? placeholderText;
public readonly BeatSaverFilterModel filterOptions = new();

public event Action<BeatSaverFilterModel>? FiltersSet;
public event Action? RequestDismiss;

[UIComponent("vertical")]
private readonly RectTransform? verticalTransform = null!;

[UIComponent("filters-tab-selector")]
private readonly TextSegmentedControl? filtersTabSelector = null!;

[UIComponent("filter-ui")]
private readonly RectTransform? filterUITransform = null!;

[UIComponent("search-vertical")]
private readonly RectTransform? searchVerticalTransform = null!;

[UIAction("#post-parse")]
private void PostParse()
{
inputFieldView = inputFieldGrabber.GetNewInputField(verticalTransform!, new Vector3(0, -15, 0));
inputFieldView = inputFieldGrabber.GetNewInputField(filterUITransform!, new Vector3(0, -15, 0));
if (inputFieldView.transform is RectTransform inputFieldTransform)
{
inputFieldTransform.localPosition = new Vector3(-45, 19, 0);
inputFieldTransform.sizeDelta = new Vector2(90, 12);
inputFieldTransform.SetSiblingIndex(0);
inputFieldTransform.sizeDelta = new Vector2(50, 8);

placeholderText = inputFieldTransform.Find("PlaceholderText").GetComponent<CurvedTextMeshPro>();
}

// For fixing no backgrounds in segmented control
foreach (var cell in filtersTabSelector!.transform.GetComponentsInChildren<TextSegmentedControlCell>())
{
cell.transform.Find("BG").gameObject.SetActive(true);
}
}


[UIAction("tab-switched")]
private void TabSwitched(SegmentedControl _, int index)
{
if (index == 0)
{
searchVerticalTransform!.gameObject.SetActive(true);
animationGrabber.PresentPanelAnimation.ExecuteAnimation(searchVerticalTransform!.gameObject);
placeholderText!.text = "Search";
}
else
{
animationGrabber.DismissPanelAnimation.ExecuteAnimation(searchVerticalTransform!.gameObject, () => searchVerticalTransform!.gameObject.SetActive(false));
placeholderText!.text = "Enter BeatSaver username of user (must be exact)";
}
}

[UIAction("cancel-click")]
private void CancelClicked() => RequestDismiss?.Invoke();

[UIAction("ok-click")]
private void OkClicked()
{
filterOptions.SearchFilter.IncludeEmpty = IncludeEmpty;
filterOptions.SearchFilter.IsCurated = CuratedOnly;

if (inputFieldView != null)
if (filtersTabSelector!.selectedCellNumber == 0)
{
filterOptions.SearchFilter.Query = inputFieldView.text;
filterOptions.FilterMode = FilterMode.Search;
filterOptions.SearchFilter.IncludeEmpty = IncludeEmpty;
filterOptions.SearchFilter.IsCurated = CuratedOnly;
filterOptions.SearchFilter.Query = inputFieldView!.text;
}
else
{
filterOptions.FilterMode = FilterMode.User;
filterOptions.UserName = inputFieldView!.text;
}

FiltersSet?.Invoke(filterOptions);
Expand All @@ -66,6 +107,9 @@ public void ClearFilters()

FiltersSet?.Invoke(filterOptions);
}

[UIValue("filters")]
private readonly List<object> filters = new() {nameof(FilterMode.Search), nameof(FilterMode.User)};

private bool includeEmpty;
[UIValue("include-empty")]
Expand Down
1 change: 1 addition & 0 deletions MorePlaylists/Installers/MorePlaylistsMenuInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public override void InstallBindings()
Container.Bind<SpriteLoader>().AsSingle();
Container.Bind<InputFieldGrabber>().AsSingle();
Container.Bind<MaterialGrabber>().AsSingle();
Container.Bind<AnimationGrabber>().AsSingle();
}
}
}
9 changes: 9 additions & 0 deletions MorePlaylists/Utilities/Accessors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,14 @@ internal class Accessors

public static readonly FieldAccessor<InputFieldView, Vector3>.Accessor KeyboardOffsetAccessor =
FieldAccessor<InputFieldView, Vector3>.GetAccessor("_keyboardPositionOffset");

public static readonly FieldAccessor<GameplaySetupViewController, ColorsOverrideSettingsPanelController>.Accessor ColorsPanelAccessor =
FieldAccessor<GameplaySetupViewController, ColorsOverrideSettingsPanelController>.GetAccessor("_colorsOverrideSettingsPanelController");

public static readonly FieldAccessor<ColorsOverrideSettingsPanelController, PanelAnimationSO>.Accessor PresentAnimationAccessor =
FieldAccessor<ColorsOverrideSettingsPanelController, PanelAnimationSO>.GetAccessor("_presentPanelAnimation");

public static readonly FieldAccessor<ColorsOverrideSettingsPanelController, PanelAnimationSO>.Accessor DismissAnimationAccessor =
FieldAccessor<ColorsOverrideSettingsPanelController, PanelAnimationSO>.GetAccessor("_dismissPanelAnimation");
}
}
19 changes: 19 additions & 0 deletions MorePlaylists/Utilities/AnimationGrabber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using HMUI;

namespace MorePlaylists.Utilities;

internal class AnimationGrabber
{
private ColorsOverrideSettingsPanelController colorsPanel;

private PanelAnimationSO? presentPanelAnimation;
public PanelAnimationSO PresentPanelAnimation => presentPanelAnimation ??= Accessors.PresentAnimationAccessor(ref colorsPanel);

private PanelAnimationSO? dismissPanelAnimation;
public PanelAnimationSO DismissPanelAnimation => dismissPanelAnimation ??= Accessors.DismissAnimationAccessor(ref colorsPanel);

public AnimationGrabber(GameplaySetupViewController gameplaySetupViewController)
{
colorsPanel = Accessors.ColorsPanelAccessor(ref gameplaySetupViewController);
}
}

0 comments on commit f3fddbb

Please sign in to comment.