Skip to content

Commit

Permalink
Updated for BSML 1.7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirspam committed Mar 3, 2024
1 parent f049204 commit ee72ae3
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 133 deletions.
4 changes: 2 additions & 2 deletions Hitbloq/Other/SpriteLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ public async Task DownloadSpriteAsync(string spriteURL, Action<Sprite> onComplet

private void QueueLoadSprite(string key, byte[] imageBytes, Action<Sprite> 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)
Expand Down
17 changes: 3 additions & 14 deletions Hitbloq/Sources/AroundMeLeaderboardSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ internal class AroundMeLeaderboardSource : IMapLeaderboardSource
private readonly UserIDSource _userIDSource;

private List<HitbloqMapLeaderboardEntry>? _cachedEntries;
private Sprite? _icon;

public AroundMeLeaderboardSource(IHttpService siraHttpService, UserIDSource userIDSource)
{
Expand All @@ -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<Sprite> Icon { get; } =
BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.PlayerIcon.png");

public bool Scrollable => false;

Expand Down
18 changes: 4 additions & 14 deletions Hitbloq/Sources/AroundMePoolLeaderboardSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<Sprite> Icon { get; } =
BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.PlayerIcon.png");

public async Task<PoolLeaderboardPage?> GetScoresAsync(string poolID, CancellationToken cancellationToken = default, int page = 0)
{
Expand Down
17 changes: 3 additions & 14 deletions Hitbloq/Sources/FriendsLeaderboardSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ internal class FriendsLeaderboardSource : IMapLeaderboardSource
private readonly UserIDSource _userIDSource;

private List<List<HitbloqMapLeaderboardEntry>>? _cachedEntries;
private Sprite? _icon;

public FriendsLeaderboardSource(IHttpService siraHttpService, UserIDSource userIDSource, FriendIDSource friendIDSource)
{
Expand All @@ -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<Sprite> Icon { get; } =
BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.FriendsIcon.png");

public bool Scrollable => true;

Expand Down
17 changes: 3 additions & 14 deletions Hitbloq/Sources/FriendsPoolLeaderboardSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<Sprite> Icon { get; } =
BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.FriendsIcon.png");

public async Task<PoolLeaderboardPage?> GetScoresAsync(string poolID, CancellationToken cancellationToken = default, int page = 0)
{
Expand Down
17 changes: 3 additions & 14 deletions Hitbloq/Sources/GlobalLeaderboardSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,16 @@ internal class GlobalLeaderboardSource : IMapLeaderboardSource
{
private readonly List<List<HitbloqMapLeaderboardEntry>> _cachedEntries = new();
private readonly IHttpService _siraHttpService;
private Sprite? _icon;

public GlobalLeaderboardSource(IHttpService siraHttpService)
{
_siraHttpService = siraHttpService;
}

public string HoverHint => "Global";

public Sprite Icon
{
get
{
if (_icon == null)
{
_icon = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("Hitbloq.Images.GlobalIcon.png");
}

return _icon;
}
}

public Task<Sprite> Icon { get; } =
BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.GlobalIcon.png");

public bool Scrollable => true;

Expand Down
15 changes: 2 additions & 13 deletions Hitbloq/Sources/GlobalPoolLeaderboardSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Hitbloq.Sources
internal class GlobalPoolLeaderboardSource : IPoolLeaderboardSource
{
private readonly IHttpService _siraHttpService;
private Sprite? _icon;

public GlobalPoolLeaderboardSource(IHttpService siraHttpService)
{
Expand All @@ -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<Sprite> Icon { get; } =
BeatSaberMarkupLanguage.Utilities.LoadSpriteFromAssemblyAsync("Hitbloq.Images.GlobalIcon.png");

public async Task<PoolLeaderboardPage?> GetScoresAsync(string poolID, CancellationToken cancellationToken = default, int page = 0)
{
Expand Down
5 changes: 3 additions & 2 deletions Hitbloq/Sources/ILeaderboardSource.cs
Original file line number Diff line number Diff line change
@@ -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<Sprite> Icon { get; }
}
}
28 changes: 12 additions & 16 deletions Hitbloq/UI/ViewControllers/HitbloqLeaderboardViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!;

Expand Down Expand Up @@ -207,8 +210,16 @@ private void SetNoDependenciesInstalledText()
}

[UIAction("#post-parse")]
private void PostParse()
private async Task PostParse()
{
var list = new List<IconSegmentedControl.DataItem>();
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<LeaderboardTableCell>(true);

Expand Down Expand Up @@ -384,21 +395,6 @@ private void OnCellSelected(SegmentedControl _, int index)
SelectedCellIndex = index;
}

[UIValue("cell-data")]
private List<IconSegmentedControl.DataItem> CellData
{
get
{
var list = new List<IconSegmentedControl.DataItem>();
foreach (var leaderboardSource in _leaderboardSources)
{
list.Add(new IconSegmentedControl.DataItem(leaderboardSource.Icon, leaderboardSource.HoverHint));
}

return list;
}
}

#endregion
}
}
12 changes: 6 additions & 6 deletions Hitbloq/UI/ViewControllers/HitbloqPanelController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void Initialize()
}

public void LeaderboardEntriesUpdated(List<HitbloqMapLeaderboardEntry>? leaderboardEntries)
{
{
CuteMode = leaderboardEntries != null && leaderboardEntries.Exists(u => u.UserID == 726);
}

Expand All @@ -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;
Expand All @@ -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();
Expand Down
29 changes: 13 additions & 16 deletions Hitbloq/UI/ViewControllers/HitbloqPoolLeaderboardViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HitbloqPoolLeaderboardEntry> _leaderboardEntries = new();

Expand Down Expand Up @@ -106,8 +110,16 @@ private void OnScrollPositionChanged(float newPos)
}

[UIAction("#post-parse")]
private void PostParse()
private async Task PostParse()
{
var list = new List<IconSegmentedControl.DataItem>();
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);
Expand Down Expand Up @@ -218,21 +230,6 @@ private void OnCellSelected(SegmentedControl _, int index)
SelectedCellIndex = index;
}

[UIValue("cell-data")]
private List<IconSegmentedControl.DataItem> CellData
{
get
{
var list = new List<IconSegmentedControl.DataItem>();
foreach (var leaderboardSource in _leaderboardSources)
{
list.Add(new IconSegmentedControl.DataItem(leaderboardSource.Icon, leaderboardSource.HoverHint));
}

return list;
}
}

#endregion

#region Loading
Expand Down
8 changes: 4 additions & 4 deletions Hitbloq/UI/ViewControllers/HitbloqProfileModalController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private HitbloqProfile? HitbloqProfile
{
if (_hitbloqProfile.ProfilePictureURL != null)
{
_modalProfilePic.SetImage(_hitbloqProfile.ProfilePictureURL);
_ = _modalProfilePic.SetImageAsync(_hitbloqProfile.ProfilePictureURL);
}
else
{
Expand Down Expand Up @@ -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";
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Hitbloq/UI/Views/HitbloqLeaderboardView.bsml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<bg>
<horizontal horizontal-fit='PreferredSize' vertical-fit='PreferredSize' pref-width='100' pref-height='70'>
<vertical horizontal-fit='PreferredSize' vertical-fit='PreferredSize' pref-width='9' pref-height='25'>
<vertical-icon-segments data='cell-data' select-cell='cell-selected'/>
<vertical-icon-segments id='vertical-icon-segments' select-cell='cell-selected'/>
</vertical>
<vertical horizontal-fit='PreferredSize' vertical-fit='PreferredSize' pref-width='80' pref-height='70'>
<leaderboard id='leaderboard' cell-size='5.99'/>
Expand Down
2 changes: 1 addition & 1 deletion Hitbloq/UI/Views/HitbloqPanel.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<horizontal id='container' pref-width='91' horizontal-fit='PreferredSize' vertical-fit='PreferredSize' spacing='3'
bg='round-rect-panel' bg-color='#0078B9' pad='2'>
<vertical pref-width='10' pref-height='10'>
<clickable-image id='hitbloq-logo' src='Hitbloq.Images.Logo.png' on-click="logo-click"
<clickable-image id='hitbloq-logo' on-click="logo-click"
hover-hint='Open Hitbloq Menu' preserve-aspect='true' pref-width='10' pref-height='10'/>
</vertical>
<vertical pref-width='0.5' pref-height='10'>
Expand Down
Loading

0 comments on commit ee72ae3

Please sign in to comment.