1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-16 13:03:34 +08:00
Files
osu-lazer/osu.Game/Overlays/BeatmapSetOverlay.cs
T
Bartłomiej Dach 7bb97d5796 Show user tags on beatmap set overlay
Resolves one part of
https://github.com/ppy/osu/discussions/32568#discussioncomment-12612928

A few caveats:

- Layout is slightly different than web intentionally. Web does things
  that I think will be difficult to reproduce or just plain look bad in
  client, such as:

  - On web, the metadata info box has 200px min height and 300px max
    height. I just hardcoded 300 units.

  - On web, user tags and mapper tags are individually scrollable, and
    the amount of space taken up by each is calculated in a way that
    is - as far as I can tell - indeterminate, and probably influenced
    by some flexbox magic. I just made the entire thing scrollable
    instead.

- Because song select shares controls with the beatmap set overlay, now
  song select says "Mapper Tags" in the header instead of just "Tags"
  too. I think this is fine, because people asked for user tags to be
  shown in song select too.

- Search query syntax lifted from
  https://github.com/ppy/osu-web/pull/12047.

- Using hardcoded English strings for now, will update to the
  translations after the next osu-resources localisations update.
2025-03-27 14:58:03 +01:00

163 lines
4.9 KiB
C#

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.BeatmapSet;
using osu.Game.Overlays.BeatmapSet.Scores;
using osu.Game.Overlays.Comments;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays
{
public partial class BeatmapSetOverlay : OnlineOverlay<BeatmapSetHeader>
{
public const float Y_PADDING = 25;
public const float RIGHT_WIDTH = 275;
private readonly Bindable<APIBeatmapSet> beatmapSet = new Bindable<APIBeatmapSet>();
[Resolved]
private IAPIProvider api { get; set; }
private IBindable<APIUser> apiUser;
private (BeatmapSetLookupType type, int id)? lastLookup;
public BeatmapSetOverlay()
: base(OverlayColourScheme.Blue)
{
Info info;
CommentsSection comments;
Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 20),
Children = new Drawable[]
{
info = new Info
{
Beatmap = { BindTarget = Header.HeaderContent.Picker.Beatmap }
},
new ScoresContainer
{
Beatmap = { BindTarget = Header.HeaderContent.Picker.Beatmap }
},
comments = new CommentsSection()
}
};
Header.BeatmapSet.BindTo(beatmapSet);
info.BeatmapSet.BindTo(beatmapSet);
comments.BeatmapSet.BindTo(beatmapSet);
Header.HeaderContent.Picker.Beatmap.ValueChanged += b => ScrollFlow.ScrollToStart();
}
[BackgroundDependencyLoader]
private void load()
{
apiUser = api.LocalUser.GetBoundCopy();
apiUser.BindValueChanged(_ => Schedule(() =>
{
if (api.IsLoggedIn)
performFetch();
}));
}
protected override BeatmapSetHeader CreateHeader() => new BeatmapSetHeader();
protected override Color4 BackgroundColour => ColourProvider.Background6;
protected override void PopOutComplete()
{
base.PopOutComplete();
beatmapSet.Value = null;
}
public void FetchAndShowBeatmap(int beatmapId)
{
lastLookup = (BeatmapSetLookupType.BeatmapId, beatmapId);
beatmapSet.Value = null;
performFetch();
Show();
}
public void FetchAndShowBeatmapSet(int beatmapSetId)
{
lastLookup = (BeatmapSetLookupType.SetId, beatmapSetId);
beatmapSet.Value = null;
performFetch();
Show();
}
/// <summary>
/// Show an already fully-populated beatmap set.
/// </summary>
/// <param name="set">The set to show.</param>
public void ShowBeatmapSet(APIBeatmapSet set)
{
beatmapSet.Value = set;
Show();
}
private void performFetch()
{
if (!api.IsLoggedIn)
return;
if (lastLookup == null)
return;
var req = new GetBeatmapSetRequest(lastLookup.Value.id, lastLookup.Value.type);
req.Success += res =>
{
beatmapSet.Value = res;
if (lastLookup.Value.type == BeatmapSetLookupType.BeatmapId)
Header.HeaderContent.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineID == lastLookup.Value.id);
};
API.Queue(req);
}
private partial class CommentsSection : BeatmapSetLayoutSection
{
public readonly Bindable<APIBeatmapSet> BeatmapSet = new Bindable<APIBeatmapSet>();
public CommentsSection()
{
CommentsContainer comments;
Add(comments = new CommentsContainer());
BeatmapSet.BindValueChanged(beatmapSet =>
{
if (beatmapSet.NewValue?.OnlineID > 0)
{
Show();
comments.ShowComments(CommentableType.Beatmapset, beatmapSet.NewValue.OnlineID);
}
else
{
Hide();
}
}, true);
}
}
}
}