mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 20:07:29 +08:00
135 lines
4.1 KiB
C#
135 lines
4.1 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.
|
|
|
|
using System.Linq;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.Shapes;
|
|
using osu.Framework.Input.Events;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Graphics;
|
|
using osu.Game.Graphics.Containers;
|
|
using osu.Game.Online.API.Requests;
|
|
using osu.Game.Overlays.BeatmapSet;
|
|
using osu.Game.Overlays.BeatmapSet.Scores;
|
|
using osu.Game.Rulesets;
|
|
using osuTK;
|
|
|
|
namespace osu.Game.Overlays
|
|
{
|
|
public class BeatmapSetOverlay : FullscreenOverlay
|
|
{
|
|
public const float X_PADDING = 40;
|
|
public const float TOP_PADDING = 25;
|
|
public const float RIGHT_WIDTH = 275;
|
|
protected readonly Header Header;
|
|
|
|
private RulesetStore rulesets;
|
|
|
|
private readonly Bindable<BeatmapSetInfo> beatmapSet = new Bindable<BeatmapSetInfo>();
|
|
|
|
// receive input outside our bounds so we can trigger a close event on ourselves.
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
|
|
|
public BeatmapSetOverlay()
|
|
{
|
|
OsuScrollContainer scroll;
|
|
Info info;
|
|
ScoresContainer scoreContainer;
|
|
|
|
Children = new Drawable[]
|
|
{
|
|
new Box
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
Colour = OsuColour.Gray(0.2f)
|
|
},
|
|
scroll = new OsuScrollContainer
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
ScrollbarVisible = false,
|
|
Child = new ReverseChildIDFillFlowContainer<Drawable>
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Direction = FillDirection.Vertical,
|
|
Children = new Drawable[]
|
|
{
|
|
Header = new Header(),
|
|
info = new Info(),
|
|
scoreContainer = new ScoresContainer(),
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
Header.BeatmapSet.BindTo(beatmapSet);
|
|
info.BeatmapSet.BindTo(beatmapSet);
|
|
|
|
Header.Picker.Beatmap.ValueChanged += b =>
|
|
{
|
|
info.Beatmap = b.NewValue;
|
|
scoreContainer.Beatmap = b.NewValue;
|
|
|
|
scroll.ScrollToStart();
|
|
};
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(RulesetStore rulesets)
|
|
{
|
|
this.rulesets = rulesets;
|
|
}
|
|
|
|
protected override void PopOutComplete()
|
|
{
|
|
base.PopOutComplete();
|
|
beatmapSet.Value = null;
|
|
}
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
{
|
|
Hide();
|
|
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);
|
|
};
|
|
API.Queue(req);
|
|
|
|
Show();
|
|
}
|
|
|
|
public void FetchAndShowBeatmapSet(int beatmapSetId)
|
|
{
|
|
beatmapSet.Value = null;
|
|
|
|
var req = new GetBeatmapSetRequest(beatmapSetId);
|
|
req.Success += res => beatmapSet.Value = res.ToBeatmapSet(rulesets);
|
|
API.Queue(req);
|
|
|
|
Show();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Show an already fully-populated beatmap set.
|
|
/// </summary>
|
|
/// <param name="set">The set to show.</param>
|
|
public void ShowBeatmapSet(BeatmapSetInfo set)
|
|
{
|
|
beatmapSet.Value = set;
|
|
Show();
|
|
}
|
|
}
|
|
}
|