diff --git a/Hitbloq/Other/SpriteLoader.cs b/Hitbloq/Other/SpriteLoader.cs index 0fed3b1..17fd1fa 100644 --- a/Hitbloq/Other/SpriteLoader.cs +++ b/Hitbloq/Other/SpriteLoader.cs @@ -108,11 +108,11 @@ public async Task DownloadSpriteAsync(string spriteURL, Action onComplet private void QueueLoadSprite(string key, byte[] imageBytes, Action onCompletion, CancellationToken cancellationToken) { - _spriteQueue.Enqueue(() => + _spriteQueue.Enqueue(async () => { try { - var sprite = BeatSaberMarkupLanguage.Utilities.LoadSpriteRaw(imageBytes); + var sprite = await BeatSaberMarkupLanguage.Utilities.LoadSpriteAsync(imageBytes); sprite.texture.wrapMode = TextureWrapMode.Clamp; _cachedSprites.TryAdd(key, sprite); if (!cancellationToken.IsCancellationRequested) diff --git a/Hitbloq/Sources/AroundMeLeaderboardSource.cs b/Hitbloq/Sources/AroundMeLeaderboardSource.cs index 418dfc8..eb57386 100644 --- a/Hitbloq/Sources/AroundMeLeaderboardSource.cs +++ b/Hitbloq/Sources/AroundMeLeaderboardSource.cs @@ -15,7 +15,6 @@ internal class AroundMeLeaderboardSource : IMapLeaderboardSource private readonly UserIDSource _userIDSource; private List? _cachedEntries; - private Sprite? _icon; public AroundMeLeaderboardSource(IHttpService siraHttpService, UserIDSource userIDSource) { @@ -24,19 +23,9 @@ public AroundMeLeaderboardSource(IHttpService siraHttpService, UserIDSource user } public string HoverHint => "Around Me"; - - public Sprite Icon - { - get - { - if (_icon == null) - { - _icon = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("Hitbloq.Images.PlayerIcon.png"); - } - - return _icon; - } - } + + public Task Icon { get; } = + BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.PlayerIcon.png"); public bool Scrollable => false; diff --git a/Hitbloq/Sources/AroundMePoolLeaderboardSource.cs b/Hitbloq/Sources/AroundMePoolLeaderboardSource.cs index 62a5175..f3657d9 100644 --- a/Hitbloq/Sources/AroundMePoolLeaderboardSource.cs +++ b/Hitbloq/Sources/AroundMePoolLeaderboardSource.cs @@ -12,7 +12,6 @@ internal class AroundMePoolLeaderboardSource : IPoolLeaderboardSource { private readonly IHttpService _siraHttpService; private readonly UserIDSource _userIDSource; - private Sprite? _icon; public AroundMePoolLeaderboardSource(IHttpService siraHttpService, UserIDSource userIDSource) { @@ -21,19 +20,10 @@ public AroundMePoolLeaderboardSource(IHttpService siraHttpService, UserIDSource } public string HoverHint => "Around Me"; - - public Sprite Icon - { - get - { - if (_icon == null) - { - _icon = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("Hitbloq.Images.PlayerIcon.png"); - } - - return _icon; - } - } + + + public Task Icon { get; } = + BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.PlayerIcon.png"); public async Task GetScoresAsync(string poolID, CancellationToken cancellationToken = default, int page = 0) { diff --git a/Hitbloq/Sources/FriendsLeaderboardSource.cs b/Hitbloq/Sources/FriendsLeaderboardSource.cs index 85edd36..a29b947 100644 --- a/Hitbloq/Sources/FriendsLeaderboardSource.cs +++ b/Hitbloq/Sources/FriendsLeaderboardSource.cs @@ -17,7 +17,6 @@ internal class FriendsLeaderboardSource : IMapLeaderboardSource private readonly UserIDSource _userIDSource; private List>? _cachedEntries; - private Sprite? _icon; public FriendsLeaderboardSource(IHttpService siraHttpService, UserIDSource userIDSource, FriendIDSource friendIDSource) { @@ -27,19 +26,9 @@ public FriendsLeaderboardSource(IHttpService siraHttpService, UserIDSource userI } public string HoverHint => "Friends"; - - public Sprite Icon - { - get - { - if (_icon == null) - { - _icon = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("Hitbloq.Images.FriendsIcon.png"); - } - - return _icon; - } - } + + public Task Icon { get; } = + BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.FriendsIcon.png"); public bool Scrollable => true; diff --git a/Hitbloq/Sources/FriendsPoolLeaderboardSource.cs b/Hitbloq/Sources/FriendsPoolLeaderboardSource.cs index 068a52a..ab13e44 100644 --- a/Hitbloq/Sources/FriendsPoolLeaderboardSource.cs +++ b/Hitbloq/Sources/FriendsPoolLeaderboardSource.cs @@ -15,7 +15,6 @@ internal class FriendsPoolLeaderboardSource : IPoolLeaderboardSource private readonly IHttpService _siraHttpService; private readonly UserIDSource _userIDSource; - private Sprite? _icon; public FriendsPoolLeaderboardSource(IHttpService siraHttpService, UserIDSource userIDSource, FriendIDSource friendIDSource) { @@ -25,19 +24,9 @@ public FriendsPoolLeaderboardSource(IHttpService siraHttpService, UserIDSource u } public string HoverHint => "Friends"; - - public Sprite Icon - { - get - { - if (_icon == null) - { - _icon = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("Hitbloq.Images.FriendsIcon.png"); - } - - return _icon; - } - } + + public Task Icon { get; } = + BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.FriendsIcon.png"); public async Task GetScoresAsync(string poolID, CancellationToken cancellationToken = default, int page = 0) { diff --git a/Hitbloq/Sources/GlobalLeaderboardSource.cs b/Hitbloq/Sources/GlobalLeaderboardSource.cs index fae651f..0601f2b 100644 --- a/Hitbloq/Sources/GlobalLeaderboardSource.cs +++ b/Hitbloq/Sources/GlobalLeaderboardSource.cs @@ -13,7 +13,6 @@ internal class GlobalLeaderboardSource : IMapLeaderboardSource { private readonly List> _cachedEntries = new(); private readonly IHttpService _siraHttpService; - private Sprite? _icon; public GlobalLeaderboardSource(IHttpService siraHttpService) { @@ -21,19 +20,9 @@ public GlobalLeaderboardSource(IHttpService siraHttpService) } public string HoverHint => "Global"; - - public Sprite Icon - { - get - { - if (_icon == null) - { - _icon = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("Hitbloq.Images.GlobalIcon.png"); - } - - return _icon; - } - } + + public Task Icon { get; } = + BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.GlobalIcon.png"); public bool Scrollable => true; diff --git a/Hitbloq/Sources/GlobalPoolLeaderboardSource.cs b/Hitbloq/Sources/GlobalPoolLeaderboardSource.cs index 2dfde6a..ab43235 100644 --- a/Hitbloq/Sources/GlobalPoolLeaderboardSource.cs +++ b/Hitbloq/Sources/GlobalPoolLeaderboardSource.cs @@ -11,7 +11,6 @@ namespace Hitbloq.Sources internal class GlobalPoolLeaderboardSource : IPoolLeaderboardSource { private readonly IHttpService _siraHttpService; - private Sprite? _icon; public GlobalPoolLeaderboardSource(IHttpService siraHttpService) { @@ -20,18 +19,8 @@ public GlobalPoolLeaderboardSource(IHttpService siraHttpService) public string HoverHint => "Global"; - public Sprite Icon - { - get - { - if (_icon == null) - { - _icon = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("Hitbloq.Images.GlobalIcon.png"); - } - - return _icon; - } - } + public Task Icon { get; } = + BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.GlobalIcon.png"); public async Task GetScoresAsync(string poolID, CancellationToken cancellationToken = default, int page = 0) { diff --git a/Hitbloq/Sources/ILeaderboardSource.cs b/Hitbloq/Sources/ILeaderboardSource.cs index 397aaa3..4f42a34 100644 --- a/Hitbloq/Sources/ILeaderboardSource.cs +++ b/Hitbloq/Sources/ILeaderboardSource.cs @@ -1,10 +1,11 @@ -using UnityEngine; +using System.Threading.Tasks; +using UnityEngine; namespace Hitbloq.Sources { public interface ILeaderboardSource { public string HoverHint { get; } - public Sprite Icon { get; } + public Task Icon { get; } } } \ No newline at end of file diff --git a/Hitbloq/UI/ViewControllers/HitbloqLeaderboardViewController.cs b/Hitbloq/UI/ViewControllers/HitbloqLeaderboardViewController.cs index 259a015..275ab30 100644 --- a/Hitbloq/UI/ViewControllers/HitbloqLeaderboardViewController.cs +++ b/Hitbloq/UI/ViewControllers/HitbloqLeaderboardViewController.cs @@ -20,6 +20,9 @@ namespace Hitbloq.UI.ViewControllers [ViewDefinition("Hitbloq.UI.Views.HitbloqLeaderboardView.bsml")] internal class HitbloqLeaderboardViewController : BSMLAutomaticViewController, IDifficultyBeatmapUpdater, ILeaderboardEntriesUpdater, IPoolUpdater { + [UIComponent("vertical-icon-segments")] + private readonly IconSegmentedControl? _iconSegmentedControl = null!; + [UIComponent("leaderboard")] private readonly LeaderboardTableView? _leaderboard = null!; @@ -207,8 +210,16 @@ private void SetNoDependenciesInstalledText() } [UIAction("#post-parse")] - private void PostParse() + private async Task PostParse() { + var list = new List(); + foreach (var leaderboardSource in _leaderboardSources) + { + list.Add(new IconSegmentedControl.DataItem(await leaderboardSource.Icon, leaderboardSource.HoverHint)); + } + + _iconSegmentedControl!.SetData(list.ToArray()); + // To set rich text, I have to iterate through all cells, set each cell to allow rich text and next time they will have it var leaderboardTableCells = _leaderboardTransform!.GetComponentsInChildren(true); @@ -384,21 +395,6 @@ private void OnCellSelected(SegmentedControl _, int index) SelectedCellIndex = index; } - [UIValue("cell-data")] - private List CellData - { - get - { - var list = new List(); - foreach (var leaderboardSource in _leaderboardSources) - { - list.Add(new IconSegmentedControl.DataItem(leaderboardSource.Icon, leaderboardSource.HoverHint)); - } - - return list; - } - } - #endregion } } \ No newline at end of file diff --git a/Hitbloq/UI/ViewControllers/HitbloqPanelController.cs b/Hitbloq/UI/ViewControllers/HitbloqPanelController.cs index 66ee12a..358567e 100644 --- a/Hitbloq/UI/ViewControllers/HitbloqPanelController.cs +++ b/Hitbloq/UI/ViewControllers/HitbloqPanelController.cs @@ -187,7 +187,7 @@ public void Initialize() } public void LeaderboardEntriesUpdated(List? leaderboardEntries) - { + { CuteMode = leaderboardEntries != null && leaderboardEntries.Exists(u => u.UserID == 726); } @@ -208,9 +208,9 @@ public void PoolUpdated(string pool) public event Action? EventClickedEvent; [UIAction("#post-parse")] - private void PostParse() + private async Task PostParse() { - // Backround related stuff + // Background related stuff if (_container!.background is ImageView background) { background.material = BeatSaberMarkupLanguage.Utilities.ImageResources.NoGlowMat; @@ -222,9 +222,9 @@ private void PostParse() } // Loading up logos - _logoSprite = _logo!.sprite; - _flushedSprite = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("Hitbloq.Images.LogoFlushed.png"); - _logo.sprite = CuteMode ? _flushedSprite : _logoSprite; + _logoSprite = await BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.Logo.png"); + _flushedSprite = await BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.LogoFlushed.png"); + _logo!.sprite = CuteMode ? _flushedSprite : _logoSprite; Accessors.SkewAccessor(ref _logo) = 0.18f; _logo.SetVerticesDirty(); diff --git a/Hitbloq/UI/ViewControllers/HitbloqPoolLeaderboardViewController.cs b/Hitbloq/UI/ViewControllers/HitbloqPoolLeaderboardViewController.cs index ffef8d5..cb00a91 100644 --- a/Hitbloq/UI/ViewControllers/HitbloqPoolLeaderboardViewController.cs +++ b/Hitbloq/UI/ViewControllers/HitbloqPoolLeaderboardViewController.cs @@ -25,6 +25,10 @@ internal class HitbloqPoolLeaderboardViewController : BSMLAutomaticViewControlle { [UIComponent("list")] private readonly CustomListTableData? _customListTableData = null!; + + [UIComponent("vertical-icon-segments")] + + private readonly IconSegmentedControl? _iconSegmentedControl = null!; private readonly List _leaderboardEntries = new(); @@ -106,8 +110,16 @@ private void OnScrollPositionChanged(float newPos) } [UIAction("#post-parse")] - private void PostParse() + private async Task PostParse() { + var list = new List(); + foreach (var leaderboardSource in _leaderboardSources) + { + list.Add(new IconSegmentedControl.DataItem(await leaderboardSource.Icon, leaderboardSource.HoverHint)); + } + + _iconSegmentedControl!.SetData(list.ToArray()); + if (_customListTableData != null) { _customListTableData.tableView.SetDataSource(this, true); @@ -218,21 +230,6 @@ private void OnCellSelected(SegmentedControl _, int index) SelectedCellIndex = index; } - [UIValue("cell-data")] - private List CellData - { - get - { - var list = new List(); - foreach (var leaderboardSource in _leaderboardSources) - { - list.Add(new IconSegmentedControl.DataItem(leaderboardSource.Icon, leaderboardSource.HoverHint)); - } - - return list; - } - } - #endregion #region Loading diff --git a/Hitbloq/UI/ViewControllers/HitbloqProfileModalController.cs b/Hitbloq/UI/ViewControllers/HitbloqProfileModalController.cs index 77da8a3..f806221 100644 --- a/Hitbloq/UI/ViewControllers/HitbloqProfileModalController.cs +++ b/Hitbloq/UI/ViewControllers/HitbloqProfileModalController.cs @@ -158,7 +158,7 @@ private HitbloqProfile? HitbloqProfile { if (_hitbloqProfile.ProfilePictureURL != null) { - _modalProfilePic.SetImage(_hitbloqProfile.ProfilePictureURL); + _ = _modalProfilePic.SetImageAsync(_hitbloqProfile.ProfilePictureURL); } else { @@ -263,7 +263,7 @@ private string PoolName public event PropertyChangedEventHandler? PropertyChanged; [UIAction("#post-parse")] - private void PostParse() + private async Task PostParse() { _parsed = true; _modalView!.gameObject.name = "HitbloqProfileModal"; @@ -276,8 +276,8 @@ private void PostParse() _modalProfilePic!.material = _materialGrabber.NoGlowRoundEdge; _addFriendButton!.transform.localScale = new Vector3(0.3f, 0.3f, 1f); - _addFriend = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("Hitbloq.Images.AddFriend.png"); - _friendAdded = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("Hitbloq.Images.FriendAdded.png"); + _addFriend = await BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.AddFriend.png"); + _friendAdded = await BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.FriendAdded.png"); if (_modalInfoVertical!.background is ImageView verticalBackground) { diff --git a/Hitbloq/UI/Views/HitbloqLeaderboardView.bsml b/Hitbloq/UI/Views/HitbloqLeaderboardView.bsml index 800ae48..6359b0e 100644 --- a/Hitbloq/UI/Views/HitbloqLeaderboardView.bsml +++ b/Hitbloq/UI/Views/HitbloqLeaderboardView.bsml @@ -1,7 +1,7 @@  - + diff --git a/Hitbloq/UI/Views/HitbloqPanel.bsml b/Hitbloq/UI/Views/HitbloqPanel.bsml index 17d10c7..3da3edd 100644 --- a/Hitbloq/UI/Views/HitbloqPanel.bsml +++ b/Hitbloq/UI/Views/HitbloqPanel.bsml @@ -8,7 +8,7 @@ - diff --git a/Hitbloq/UI/Views/HitbloqPoolLeaderboardView.bsml b/Hitbloq/UI/Views/HitbloqPoolLeaderboardView.bsml index 8b1637a..5571cc8 100644 --- a/Hitbloq/UI/Views/HitbloqPoolLeaderboardView.bsml +++ b/Hitbloq/UI/Views/HitbloqPoolLeaderboardView.bsml @@ -5,7 +5,7 @@ - +