osu/osu.Game/Overlays/BeatmapSetOverlay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

206 lines
6.3 KiB
C#
Raw Normal View History

// 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.
2018-04-13 09:19:50 +00:00
2022-06-17 07:37:17 +00:00
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2017-09-08 21:32:07 +00:00
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;
2017-09-25 09:26:27 +00:00
using osu.Game.Overlays.BeatmapSet;
2017-11-11 00:46:06 +00:00
using osu.Game.Overlays.BeatmapSet.Scores;
using osu.Game.Overlays.Comments;
using osu.Game.Rulesets.Mods;
2022-07-23 07:15:52 +00:00
using osu.Game.Screens.Select.Details;
2018-11-20 07:51:59 +00:00
using osuTK;
2021-01-18 07:48:12 +00:00
using osuTK.Graphics;
2019-07-09 14:56:08 +00:00
2017-09-08 21:32:07 +00:00
namespace osu.Game.Overlays
{
2021-01-21 04:30:47 +00:00
public partial class BeatmapSetOverlay : OnlineOverlay<BeatmapSetHeader>
2017-09-08 21:32:07 +00:00
{
public const float X_PADDING = 40;
2020-02-04 19:17:27 +00:00
public const float Y_PADDING = 25;
2017-09-08 21:32:07 +00:00
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 int? lastRequestedBeatmapId;
private BeatmapSetLookupType? lastBeatmapSetLookupType;
2022-07-23 07:15:52 +00:00
/// <remarks>
/// Isolates the beatmap set overlay from the game-wide selected mods bindable
/// to avoid affecting the beatmap details section (i.e. <see cref="AdvancedStats.StatisticRow"/>).
/// </remarks>
[Cached]
[Cached(typeof(IBindable<IReadOnlyList<Mod>>))]
protected readonly Bindable<IReadOnlyList<Mod>> SelectedMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
2017-09-25 09:26:27 +00:00
public BeatmapSetOverlay()
2021-01-18 07:48:12 +00:00
: base(OverlayColourScheme.Blue)
2017-09-08 21:32:07 +00:00
{
2019-02-28 10:58:21 +00:00
Info info;
CommentsSection comments;
2021-01-18 07:48:12 +00:00
Child = new FillFlowContainer
2017-09-08 21:32:07 +00:00
{
2021-01-18 07:48:12 +00:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 20),
Children = new Drawable[]
2017-09-13 00:00:20 +00:00
{
2021-01-21 04:30:47 +00:00
info = new Info(),
2021-01-18 07:48:12 +00:00
new ScoresContainer
{
2021-01-21 04:30:47 +00:00
Beatmap = { BindTarget = Header.HeaderContent.Picker.Beatmap }
2021-01-18 07:48:12 +00:00
},
comments = new CommentsSection()
}
2017-09-08 21:32:07 +00:00
};
2018-04-13 09:19:50 +00:00
Header.BeatmapSet.BindTo(beatmapSet);
info.BeatmapSet.BindTo(beatmapSet);
comments.BeatmapSet.BindTo(beatmapSet);
Header.HeaderContent.Picker.Beatmap.ValueChanged += b =>
{
2021-10-02 15:55:29 +00:00
info.BeatmapInfo = b.NewValue;
2021-01-18 07:48:12 +00:00
ScrollFlow.ScrollToStart();
2017-11-13 15:49:10 +00:00
};
2017-09-08 21:32:07 +00:00
}
2018-04-13 09:19:50 +00:00
[BackgroundDependencyLoader]
private void load()
{
apiUser = api.LocalUser.GetBoundCopy();
apiUser.BindValueChanged(_ => Schedule(() =>
{
if (api.IsLoggedIn)
fetchAndSetLastRequestedBeatmap();
}));
}
2021-01-21 04:30:47 +00:00
protected override BeatmapSetHeader CreateHeader() => new BeatmapSetHeader();
2021-01-18 07:48:12 +00:00
protected override Color4 BackgroundColour => ColourProvider.Background6;
2018-04-13 09:19:50 +00:00
2019-05-14 06:19:23 +00:00
protected override void PopOutComplete()
2017-09-08 21:32:07 +00:00
{
2019-05-14 06:19:23 +00:00
base.PopOutComplete();
beatmapSet.Value = null;
2017-09-08 21:32:07 +00:00
}
2018-04-13 09:19:50 +00:00
public void FetchAndShowBeatmap(int beatmapId)
{
lastRequestedBeatmapId = beatmapId;
lastBeatmapSetLookupType = BeatmapSetLookupType.BeatmapId;
beatmapSet.Value = null;
fetchAndSetBeatmap(beatmapId);
Show();
}
public void FetchAndShowBeatmapSet(int beatmapSetId)
{
lastRequestedBeatmapId = beatmapSetId;
lastBeatmapSetLookupType = BeatmapSetLookupType.SetId;
beatmapSet.Value = null;
fetchAndSetBeatmapSet(beatmapSetId);
Show();
}
2018-04-13 09:19:50 +00:00
/// <summary>
/// Show an already fully-populated beatmap set.
/// </summary>
/// <param name="set">The set to show.</param>
public void ShowBeatmapSet(APIBeatmapSet set)
2017-09-08 21:32:07 +00:00
{
beatmapSet.Value = set;
Show();
2017-09-08 21:32:07 +00:00
}
private void fetchAndSetBeatmap(int beatmapId)
{
if (!api.IsLoggedIn)
return;
var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId);
req.Success += res =>
{
beatmapSet.Value = res;
Header.HeaderContent.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineID == beatmapId);
};
API.Queue(req);
}
private void fetchAndSetBeatmapSet(int beatmapSetId)
{
if (!api.IsLoggedIn)
return;
var req = new GetBeatmapSetRequest(beatmapSetId);
req.Success += res => beatmapSet.Value = res;
API.Queue(req);
}
private void fetchAndSetLastRequestedBeatmap()
{
if (lastRequestedBeatmapId == null)
return;
switch (lastBeatmapSetLookupType)
{
case BeatmapSetLookupType.SetId:
fetchAndSetBeatmapSet(lastRequestedBeatmapId.Value);
break;
case BeatmapSetLookupType.BeatmapId:
fetchAndSetBeatmap(lastRequestedBeatmapId.Value);
break;
}
}
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);
}
}
2017-09-08 21:32:07 +00:00
}
}