-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
227 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<vertical horizontal-fit='PreferredSize' vertical-fit='PreferredSize' pref-width='70'> | ||
<horizontal horizontal-fit='PreferredSize' pref-width='60' pref-height="15" spacing="1" bg="panel-top" pad-left="2" child-control-width="false"> | ||
<vertical vertical-fit='PreferredSize' pref-width='10' pref-height='10'> | ||
<image id='playlist-cover' preserve-aspect='false' /> | ||
</vertical> | ||
<vertical vertical-fit='PreferredSize' pref-width="45" spacing="-1" pref-height="10"> | ||
<text text='~playlist-name' text-align="left" word-wrapping='true' /> | ||
<horizontal child-control-height="false" child-control-width="false" spacing="0.5"> | ||
<image id='user-image' preserve-aspect='true' size-delta-x="3" size-delta-y="3" /> | ||
<clickable-text text='~playlist-author' font-size="3.5" font-align="MidlineLeft" word-wrapping='true' color="#FFFFFFBF" size-delta-x="45" size-delta-y="3" /> | ||
</horizontal> | ||
</vertical> | ||
</horizontal> | ||
<horizontal horizontal-fit='PreferredSize' vertical-fit='PreferredSize' pref-width='65' pref-height='35' spacing='2'> | ||
<text-page id='text-page' text='~playlist-description' /> | ||
</horizontal> | ||
<primary-button text='Go To Playlist!' on-click='go-to-playlist' active='~go-to-active' pref-height='10' pref-width='50' anchor-pos-y='25' /> | ||
<horizontal pref-width='60' horizontal-fit='PreferredSize' vertical-fit='PreferredSize' spacing='2' active='~download-active'> | ||
<button text='⏬ Playlist' on-click='download-click' interactable='~download-interactable' pad='0' pref-height='8' pref-width='25' anchor-pos-y='25' /> | ||
<button text='⏬ Playlist + Songs' on-click='download-all-click' interactable='~download-interactable' pad='0' pref-height='8' pref-width='35' anchor-pos-y='25' /> | ||
</horizontal> | ||
</vertical> |
160 changes: 160 additions & 0 deletions
160
MorePlaylists/BeatSaver/BeatSaverDetailViewController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
using System; | ||
using System.Threading; | ||
using BeatSaberMarkupLanguage.Attributes; | ||
using BeatSaberMarkupLanguage.ViewControllers; | ||
using BeatSaberPlaylistsLib.Types; | ||
using HMUI; | ||
using MorePlaylists.Entries; | ||
using MorePlaylists.UI; | ||
using MorePlaylists.Utilities; | ||
using UnityEngine; | ||
using Zenject; | ||
|
||
namespace MorePlaylists.BeatSaver; | ||
|
||
[HotReload(RelativePathToLayout = @".\BeatSaverDetailView.bsml")] | ||
[ViewDefinition("MorePlaylists.BeatSaver.BeatSaverDetailView.bsml")] | ||
internal class BeatSaverDetailViewController : BSMLAutomaticViewController, IDetailViewController | ||
{ | ||
[Inject] | ||
private readonly SpriteLoader spriteLoader = null!; | ||
|
||
[Inject] | ||
private readonly MaterialGrabber materialGrabber = null!; | ||
|
||
private BeatSaverEntry? selectedPlaylistEntry; | ||
private CancellationTokenSource? spriteLoadTokenSource; | ||
|
||
public ViewController ViewController => this; | ||
public event Action<IEntry, bool>? DidPressDownload; | ||
public event Action<IPlaylist>? DidGoToPlaylist; | ||
|
||
[UIComponent("playlist-cover")] | ||
private readonly ImageView playlistCoverView = null!; | ||
|
||
[UIComponent("user-image")] | ||
private readonly ImageView userImageView = null!; | ||
|
||
[UIComponent("text-page")] | ||
private readonly TextPageScrollView descriptionTextPage = null!; | ||
|
||
#region Actions | ||
|
||
[UIAction("#post-parse")] | ||
private void PostParse() | ||
{ | ||
rectTransform.anchorMax = new Vector2(0.5f, 1); | ||
playlistCoverView.material = materialGrabber.NoGlowRoundEdge; | ||
userImageView.material = materialGrabber.NoGlowRoundEdge; | ||
} | ||
|
||
[UIAction("download-click")] | ||
private void DownloadPressed() | ||
{ | ||
if (selectedPlaylistEntry != null) | ||
{ | ||
DidPressDownload?.Invoke(selectedPlaylistEntry, false); | ||
NotifyPropertyChanged(nameof(DownloadInteractable)); | ||
} | ||
} | ||
|
||
[UIAction("download-all-click")] | ||
private void DownloadAllPressed() | ||
{ | ||
if (selectedPlaylistEntry != null) | ||
{ | ||
DidPressDownload?.Invoke(selectedPlaylistEntry, true); | ||
NotifyPropertyChanged(nameof(DownloadInteractable)); | ||
} | ||
} | ||
|
||
[UIAction("go-to-playlist")] | ||
private void GoToPlaylist() | ||
{ | ||
if (selectedPlaylistEntry?.LocalPlaylist != null) | ||
{ | ||
DidGoToPlaylist?.Invoke(selectedPlaylistEntry.LocalPlaylist); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
public void ShowDetail(IEntry selectedPlaylistEntry) | ||
{ | ||
if (selectedPlaylistEntry is BeatSaverEntry beatSaverEntry) | ||
{ | ||
this.selectedPlaylistEntry = beatSaverEntry; | ||
NotifyPropertyChanged(nameof(DownloadInteractable)); | ||
NotifyPropertyChanged(nameof(DownloadActive)); | ||
NotifyPropertyChanged(nameof(GoToActive)); | ||
NotifyPropertyChanged(nameof(PlaylistName)); | ||
NotifyPropertyChanged(nameof(PlaylistAuthor)); | ||
NotifyPropertyChanged(nameof(PlaylistDescription)); | ||
descriptionTextPage.ScrollTo(0, true); | ||
|
||
spriteLoadTokenSource?.Cancel(); | ||
spriteLoadTokenSource?.Dispose(); | ||
spriteLoadTokenSource = new CancellationTokenSource(); | ||
_ = spriteLoader.DownloadSpriteAsync(beatSaverEntry.SpriteURL, sprite => playlistCoverView.sprite = sprite, spriteLoadTokenSource.Token); | ||
userImageView.sprite = BeatSaberMarkupLanguage.Utilities.ImageResources.BlankSprite; | ||
_ = spriteLoader.DownloadSpriteAsync(beatSaverEntry.Owner.Avatar, sprite => userImageView.sprite = sprite, spriteLoadTokenSource.Token); | ||
} | ||
} | ||
|
||
public void OnPlaylistDownloaded() | ||
{ | ||
NotifyPropertyChanged(nameof(DownloadInteractable)); | ||
NotifyPropertyChanged(nameof(DownloadActive)); | ||
NotifyPropertyChanged(nameof(GoToActive)); | ||
} | ||
|
||
#region Values | ||
|
||
[UIValue("playlist-name")] | ||
public string PlaylistName | ||
{ | ||
get | ||
{ | ||
if (selectedPlaylistEntry != null) | ||
{ | ||
if (selectedPlaylistEntry.Title.Length > 32) | ||
{ | ||
return selectedPlaylistEntry.Title.Substring(0, 28) + "..."; | ||
} | ||
return selectedPlaylistEntry.Title; | ||
} | ||
return string.Empty; | ||
} | ||
} | ||
|
||
[UIValue("playlist-author")] | ||
public string PlaylistAuthor | ||
{ | ||
get | ||
{ | ||
if (selectedPlaylistEntry != null) | ||
{ | ||
if (selectedPlaylistEntry.Author.Length > 32) | ||
{ | ||
return selectedPlaylistEntry.Author.Substring(0, 28) + "..."; | ||
} | ||
return selectedPlaylistEntry.Author; | ||
} | ||
return string.Empty; | ||
} | ||
} | ||
|
||
[UIValue("playlist-description")] | ||
private string PlaylistDescription => string.IsNullOrWhiteSpace(selectedPlaylistEntry?.Description) ? "No Description available for this playlist." : selectedPlaylistEntry?.Description ?? ""; | ||
|
||
[UIValue("download-interactable")] | ||
public bool DownloadInteractable => selectedPlaylistEntry is {DownloadBlocked: false}; | ||
|
||
[UIValue("download-active")] | ||
public bool DownloadActive => selectedPlaylistEntry is {LocalPlaylist: null}; | ||
|
||
[UIValue("go-to-active")] | ||
public bool GoToActive => selectedPlaylistEntry is {LocalPlaylist: { }}; | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
<div> | ||
<vertical horizontal-fit='PreferredSize' vertical-fit='PreferredSize' pref-width='70'> | ||
<horizontal horizontal-fit='PreferredSize' pref-width='60' pref-height="15" bg="panel-top"> | ||
<vertical vertical-fit='PreferredSize' pref-width='10' pref-height='10'> | ||
<image id='playlist-cover' preserve-aspect='false' /> | ||
</vertical> | ||
<vertical vertical-fit='PreferredSize' pref-width="45" spacing="-1" pref-height="10"> | ||
<text text='~playlist-name' text-align="left" word-wrapping='true' /> | ||
<text text='~playlist-author' text-align="left" word-wrapping='true' color="#FFFFFFBF" /> | ||
</vertical> | ||
</horizontal> | ||
<horizontal horizontal-fit='PreferredSize' vertical-fit='PreferredSize' pref-width='65' pref-height='35' spacing='2'> | ||
<text-page id='text-page' text='~playlist-description' /> | ||
</horizontal> | ||
<primary-button text='Go To Playlist!' on-click='go-to-playlist' active='~go-to-active' pref-height='10' pref-width='50' anchor-pos-y='25' /> | ||
<horizontal pref-width='60' horizontal-fit='PreferredSize' vertical-fit='PreferredSize' spacing='2' active='~download-active'> | ||
<button text='⏬ Playlist' on-click='download-click' interactable='~download-interactable' pad='0' pref-height='8' pref-width='25' anchor-pos-y='25' /> | ||
<button text='⏬ Playlist + Songs' on-click='download-all-click' interactable='~download-interactable' pad='0' pref-height='8' pref-width='35' anchor-pos-y='25' /> | ||
</horizontal> | ||
</vertical> | ||
</div> | ||
<vertical horizontal-fit='PreferredSize' vertical-fit='PreferredSize' pref-width='70'> | ||
<horizontal horizontal-fit='PreferredSize' pref-width='60' pref-height="15" bg="panel-top" pad-left="2" child-control-width="false"> | ||
<vertical vertical-fit='PreferredSize' pref-width='10' pref-height='10'> | ||
<image id='playlist-cover' preserve-aspect='false' /> | ||
</vertical> | ||
<vertical vertical-fit='PreferredSize' pref-width="45" spacing="-1" pref-height="10"> | ||
<text text='~playlist-name' text-align="left" word-wrapping='true' /> | ||
<text text='~playlist-author' text-align="left" word-wrapping='true' color="#FFFFFFBF" /> | ||
</vertical> | ||
</horizontal> | ||
<horizontal horizontal-fit='PreferredSize' vertical-fit='PreferredSize' pref-width='65' pref-height='35' spacing='2'> | ||
<text-page id='text-page' text='~playlist-description' /> | ||
</horizontal> | ||
<primary-button text='Go To Playlist!' on-click='go-to-playlist' active='~go-to-active' pref-height='10' pref-width='50' anchor-pos-y='25' /> | ||
<horizontal pref-width='60' horizontal-fit='PreferredSize' vertical-fit='PreferredSize' spacing='2' active='~download-active'> | ||
<button text='⏬ Playlist' on-click='download-click' interactable='~download-interactable' pad='0' pref-height='8' pref-width='25' anchor-pos-y='25' /> | ||
<button text='⏬ Playlist + Songs' on-click='download-all-click' interactable='~download-interactable' pad='0' pref-height='8' pref-width='35' anchor-pos-y='25' /> | ||
</horizontal> | ||
</vertical> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
namespace MorePlaylists.Utilities; | ||
|
||
public class MaterialGrabber | ||
{ | ||
private Material? noGlowRoundEdge; | ||
public Material NoGlowRoundEdge => noGlowRoundEdge ??= Resources.FindObjectsOfTypeAll<Material>().First(m => m.name == "UINoGlowRoundEdge"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters