2019-01-24 17:43:03 +09:00
|
|
|
|
// 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 18:19:50 +09:00
|
|
|
|
|
2022-06-17 16:37:17 +09:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2022-07-22 23:15:24 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-05-25 23:51:05 +03:00
|
|
|
|
using System.Linq;
|
2022-07-22 23:15:24 -05:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-28 18:44:40 +09:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-09-08 18:32:07 -03:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-01-10 23:30:09 +00:00
|
|
|
|
using osu.Game.Online.API;
|
2017-10-13 19:58:25 +09:00
|
|
|
|
using osu.Game.Online.API.Requests;
|
2021-10-29 17:58:46 +09:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2017-09-25 17:26:27 +08:00
|
|
|
|
using osu.Game.Overlays.BeatmapSet;
|
2017-11-11 03:46:06 +03:00
|
|
|
|
using osu.Game.Overlays.BeatmapSet.Scores;
|
2020-02-22 03:24:50 +03:00
|
|
|
|
using osu.Game.Overlays.Comments;
|
2022-07-22 23:15:24 -05:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2022-07-23 10:15:52 +03:00
|
|
|
|
using osu.Game.Screens.Select.Details;
|
2018-11-20 16:51:59 +09:00
|
|
|
|
using osuTK;
|
2021-01-18 10:48:12 +03:00
|
|
|
|
using osuTK.Graphics;
|
2019-07-09 17:56:08 +03:00
|
|
|
|
|
2017-09-08 18:32:07 -03:00
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2021-01-21 07:30:47 +03:00
|
|
|
|
public partial class BeatmapSetOverlay : OnlineOverlay<BeatmapSetHeader>
|
2017-09-08 18:32:07 -03:00
|
|
|
|
{
|
2020-02-04 20:17:27 +01:00
|
|
|
|
public const float Y_PADDING = 25;
|
2017-09-08 18:32:07 -03:00
|
|
|
|
public const float RIGHT_WIDTH = 275;
|
2020-09-03 15:46:56 +09:00
|
|
|
|
|
2021-10-29 17:58:46 +09:00
|
|
|
|
private readonly Bindable<APIBeatmapSet> beatmapSet = new Bindable<APIBeatmapSet>();
|
2018-04-18 13:08:53 +09:00
|
|
|
|
|
2023-01-10 23:30:09 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
|
|
|
|
|
private IBindable<APIUser> apiUser;
|
|
|
|
|
|
2023-01-11 16:15:28 +09:00
|
|
|
|
private (BeatmapSetLookupType type, int id)? lastLookup;
|
2023-01-10 23:30:09 +00:00
|
|
|
|
|
2022-07-23 10:15:52 +03: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>
|
2022-07-22 23:15:24 -05:00
|
|
|
|
[Cached]
|
|
|
|
|
[Cached(typeof(IBindable<IReadOnlyList<Mod>>))]
|
|
|
|
|
protected readonly Bindable<IReadOnlyList<Mod>> SelectedMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
|
|
|
|
|
2017-09-25 17:26:27 +08:00
|
|
|
|
public BeatmapSetOverlay()
|
2021-01-18 10:48:12 +03:00
|
|
|
|
: base(OverlayColourScheme.Blue)
|
2017-09-08 18:32:07 -03:00
|
|
|
|
{
|
2019-02-28 19:58:21 +09:00
|
|
|
|
Info info;
|
2020-02-22 03:40:59 +03:00
|
|
|
|
CommentsSection comments;
|
2019-07-10 19:40:29 +03:00
|
|
|
|
|
2021-01-18 10:48:12 +03:00
|
|
|
|
Child = new FillFlowContainer
|
2017-09-08 18:32:07 -03:00
|
|
|
|
{
|
2021-01-18 10:48:12 +03:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 20),
|
|
|
|
|
Children = new Drawable[]
|
2017-09-12 21:00:20 -03:00
|
|
|
|
{
|
2021-01-21 07:30:47 +03:00
|
|
|
|
info = new Info(),
|
2021-01-18 10:48:12 +03:00
|
|
|
|
new ScoresContainer
|
|
|
|
|
{
|
2021-01-21 07:30:47 +03:00
|
|
|
|
Beatmap = { BindTarget = Header.HeaderContent.Picker.Beatmap }
|
2021-01-18 10:48:12 +03:00
|
|
|
|
},
|
|
|
|
|
comments = new CommentsSection()
|
|
|
|
|
}
|
2017-09-08 18:32:07 -03:00
|
|
|
|
};
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-06-12 17:37:34 +03:00
|
|
|
|
Header.BeatmapSet.BindTo(beatmapSet);
|
2019-02-28 18:44:40 +09:00
|
|
|
|
info.BeatmapSet.BindTo(beatmapSet);
|
2020-02-22 03:24:50 +03:00
|
|
|
|
comments.BeatmapSet.BindTo(beatmapSet);
|
2019-02-28 18:44:40 +09:00
|
|
|
|
|
2021-01-20 04:56:46 +03:00
|
|
|
|
Header.HeaderContent.Picker.Beatmap.ValueChanged += b =>
|
2017-11-12 07:05:50 +03:00
|
|
|
|
{
|
2021-10-03 00:55:29 +09:00
|
|
|
|
info.BeatmapInfo = b.NewValue;
|
2021-01-18 10:48:12 +03:00
|
|
|
|
ScrollFlow.ScrollToStart();
|
2017-11-13 18:49:10 +03:00
|
|
|
|
};
|
2017-09-08 18:32:07 -03:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2023-01-10 23:30:09 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
apiUser = api.LocalUser.GetBoundCopy();
|
|
|
|
|
apiUser.BindValueChanged(_ => Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
if (api.IsLoggedIn)
|
2023-01-11 16:15:28 +09:00
|
|
|
|
performFetch();
|
2023-01-10 23:30:09 +00:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 07:30:47 +03:00
|
|
|
|
protected override BeatmapSetHeader CreateHeader() => new BeatmapSetHeader();
|
2021-01-18 10:48:12 +03:00
|
|
|
|
|
2021-02-09 18:32:44 +09:00
|
|
|
|
protected override Color4 BackgroundColour => ColourProvider.Background6;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-05-14 15:19:23 +09:00
|
|
|
|
protected override void PopOutComplete()
|
2017-09-08 18:32:07 -03:00
|
|
|
|
{
|
2019-05-14 15:19:23 +09:00
|
|
|
|
base.PopOutComplete();
|
|
|
|
|
beatmapSet.Value = null;
|
2017-09-08 18:32:07 -03:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-04-18 15:58:45 +09:00
|
|
|
|
public void FetchAndShowBeatmap(int beatmapId)
|
2018-04-18 13:08:53 +09:00
|
|
|
|
{
|
2023-01-11 16:15:28 +09:00
|
|
|
|
lastLookup = (BeatmapSetLookupType.BeatmapId, beatmapId);
|
2019-02-28 18:44:40 +09:00
|
|
|
|
beatmapSet.Value = null;
|
2019-07-09 17:38:17 +03:00
|
|
|
|
|
2023-01-11 16:15:28 +09:00
|
|
|
|
performFetch();
|
2018-04-18 13:08:53 +09:00
|
|
|
|
Show();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-18 15:58:45 +09:00
|
|
|
|
public void FetchAndShowBeatmapSet(int beatmapSetId)
|
2017-10-13 19:58:25 +09:00
|
|
|
|
{
|
2023-01-11 16:15:28 +09:00
|
|
|
|
lastLookup = (BeatmapSetLookupType.SetId, beatmapSetId);
|
2023-01-10 23:30:09 +00:00
|
|
|
|
|
2019-02-28 18:44:40 +09:00
|
|
|
|
beatmapSet.Value = null;
|
2019-07-09 17:38:17 +03:00
|
|
|
|
|
2023-01-11 16:15:28 +09:00
|
|
|
|
performFetch();
|
2018-04-18 13:08:53 +09:00
|
|
|
|
Show();
|
2017-10-13 19:58:25 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-06-27 12:00:31 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Show an already fully-populated beatmap set.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="set">The set to show.</param>
|
2021-10-29 17:58:46 +09:00
|
|
|
|
public void ShowBeatmapSet(APIBeatmapSet set)
|
2017-09-08 18:32:07 -03:00
|
|
|
|
{
|
2019-06-27 12:00:31 +09:00
|
|
|
|
beatmapSet.Value = set;
|
|
|
|
|
Show();
|
2017-09-08 18:32:07 -03:00
|
|
|
|
}
|
2020-02-22 03:24:50 +03:00
|
|
|
|
|
2023-01-11 16:15:28 +09:00
|
|
|
|
private void performFetch()
|
2023-01-10 23:30:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (!api.IsLoggedIn)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-01-11 16:15:28 +09:00
|
|
|
|
if (lastLookup == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-01-11 19:06:51 -08:00
|
|
|
|
var req = new GetBeatmapSetRequest(lastLookup.Value.id, lastLookup.Value.type);
|
2023-01-10 23:30:09 +00:00
|
|
|
|
req.Success += res =>
|
|
|
|
|
{
|
|
|
|
|
beatmapSet.Value = res;
|
2023-01-11 16:15:28 +09:00
|
|
|
|
if (lastLookup.Value.type == BeatmapSetLookupType.BeatmapId)
|
|
|
|
|
Header.HeaderContent.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineID == lastLookup.Value.id);
|
2023-01-10 23:30:09 +00:00
|
|
|
|
};
|
|
|
|
|
API.Queue(req);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 03:40:59 +03:00
|
|
|
|
private partial class CommentsSection : BeatmapSetLayoutSection
|
2020-02-22 03:24:50 +03:00
|
|
|
|
{
|
2021-10-29 17:58:46 +09:00
|
|
|
|
public readonly Bindable<APIBeatmapSet> BeatmapSet = new Bindable<APIBeatmapSet>();
|
2020-02-22 03:24:50 +03:00
|
|
|
|
|
2020-02-22 03:40:59 +03:00
|
|
|
|
public CommentsSection()
|
2020-02-22 03:24:50 +03:00
|
|
|
|
{
|
2020-02-22 03:40:59 +03:00
|
|
|
|
CommentsContainer comments;
|
|
|
|
|
|
|
|
|
|
Add(comments = new CommentsContainer());
|
|
|
|
|
|
2020-02-22 03:24:50 +03:00
|
|
|
|
BeatmapSet.BindValueChanged(beatmapSet =>
|
|
|
|
|
{
|
2021-10-29 17:58:46 +09:00
|
|
|
|
if (beatmapSet.NewValue?.OnlineID > 0)
|
2020-02-22 03:24:50 +03:00
|
|
|
|
{
|
2020-02-23 14:46:42 +01:00
|
|
|
|
Show();
|
2021-10-29 17:58:46 +09:00
|
|
|
|
comments.ShowComments(CommentableType.Beatmapset, beatmapSet.NewValue.OnlineID);
|
2020-02-22 03:24:50 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-02-23 14:46:42 +01:00
|
|
|
|
Hide();
|
2020-02-22 03:24:50 +03:00
|
|
|
|
}
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-08 18:32:07 -03:00
|
|
|
|
}
|
|
|
|
|
}
|