osu/osu.Game/Overlays/BeatmapSetOverlay.cs

156 lines
4.7 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
using System.Linq;
2018-04-13 09:19:50 +00:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2018-04-13 09:19:50 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2018-10-02 03:02:47 +00:00
using osu.Framework.Input.Events;
2018-04-13 09:19:50 +00:00
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
2018-04-13 09:19:50 +00:00
using osu.Game.Online.API.Requests;
using osu.Game.Overlays.BeatmapSet;
using osu.Game.Overlays.BeatmapSet.Scores;
using osu.Game.Rulesets;
2018-11-20 07:51:59 +00:00
using osuTK;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Overlays
{
2019-05-14 05:18:06 +00:00
public class BeatmapSetOverlay : FullscreenOverlay
2018-04-13 09:19:50 +00:00
{
private const int fade_duration = 300;
2018-04-13 09:19:50 +00:00
public const float X_PADDING = 40;
2019-06-19 14:38:43 +00:00
public const float TOP_PADDING = 25;
2018-04-13 09:19:50 +00:00
public const float RIGHT_WIDTH = 275;
protected readonly Header Header;
2018-04-13 09:19:50 +00:00
private RulesetStore rulesets;
2019-07-09 05:25:10 +00:00
private readonly ScoresContainer scores;
private GetScoresRequest getScoresRequest;
2018-04-13 09:19:50 +00:00
private readonly Bindable<BeatmapSetInfo> beatmapSet = new Bindable<BeatmapSetInfo>();
[Resolved]
private IAPIProvider api { get; set; }
2018-04-13 09:19:50 +00:00
// receive input outside our bounds so we can trigger a close event on ourselves.
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
2018-04-13 09:19:50 +00:00
public BeatmapSetOverlay()
{
OsuScrollContainer scroll;
2019-02-28 10:58:21 +00:00
Info info;
2018-04-13 09:19:50 +00:00
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.2f)
},
scroll = new OsuScrollContainer
2018-04-13 09:19:50 +00:00
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,
Child = new ReverseChildIDFillFlowContainer<Drawable>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
Header = new Header(),
2018-04-13 09:19:50 +00:00
info = new Info(),
scores = new ScoresContainer(),
},
},
},
};
Header.BeatmapSet.BindTo(beatmapSet);
info.BeatmapSet.BindTo(beatmapSet);
Header.Picker.Beatmap.ValueChanged += b =>
2018-04-13 09:19:50 +00:00
{
info.Beatmap = b.NewValue;
getScores(b.NewValue);
scroll.ScrollToStart();
2018-04-13 09:19:50 +00:00
};
}
private void getScores(BeatmapInfo b)
{
getScoresRequest?.Cancel();
if (b?.OnlineBeatmapID.HasValue != true)
{
scores.Scores = null;
return;
}
scores.Loading = true;
getScoresRequest = new GetScoresRequest(b, b.Ruleset);
2019-07-09 08:40:51 +00:00
getScoresRequest.Success += r => Schedule(() => scores.Scores = r);
api.Queue(getScoresRequest);
}
2018-04-13 09:19:50 +00:00
[BackgroundDependencyLoader]
2019-05-14 06:07:18 +00:00
private void load(RulesetStore rulesets)
2018-04-13 09:19:50 +00:00
{
this.rulesets = rulesets;
}
2019-05-14 06:19:23 +00:00
protected override void PopOutComplete()
2018-04-13 09:19:50 +00:00
{
2019-05-14 06:19:23 +00:00
base.PopOutComplete();
beatmapSet.Value = null;
2018-04-13 09:19:50 +00:00
}
2018-10-02 03:02:47 +00:00
protected override bool OnClick(ClickEvent e)
2018-04-13 09:19:50 +00:00
{
Hide();
2018-04-13 09:19:50 +00:00
return true;
}
public void FetchAndShowBeatmap(int beatmapId)
{
beatmapSet.Value = null;
var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId);
req.Success += res =>
{
beatmapSet.Value = res.ToBeatmapSet(rulesets);
Header.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineBeatmapID == beatmapId);
};
2019-05-14 06:07:18 +00:00
API.Queue(req);
Show();
}
public void FetchAndShowBeatmapSet(int beatmapSetId)
2018-04-13 09:19:50 +00:00
{
beatmapSet.Value = null;
2018-04-13 09:19:50 +00:00
var req = new GetBeatmapSetRequest(beatmapSetId);
req.Success += res => beatmapSet.Value = res.ToBeatmapSet(rulesets);
2019-05-14 06:07:18 +00:00
API.Queue(req);
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(BeatmapSetInfo set)
2018-04-13 09:19:50 +00:00
{
beatmapSet.Value = set;
Show();
2018-04-13 09:19:50 +00:00
}
}
}