osu/osu.Game/Overlays/BeatmapSetOverlay.cs

158 lines
5.0 KiB
C#
Raw Normal View History

2018-01-05 11:21:19 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-09-08 21:32:07 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
2017-09-08 21:32:07 +00:00
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2017-09-13 00:00:20 +00:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
2017-09-08 21:32:07 +00:00
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
2017-09-25 09:26:27 +00:00
using osu.Game.Overlays.BeatmapSet;
using osu.Game.Rulesets;
2017-11-11 00:46:06 +00:00
using osu.Game.Overlays.BeatmapSet.Scores;
2017-09-08 21:32:07 +00:00
namespace osu.Game.Overlays
{
2017-09-25 09:26:27 +00:00
public class BeatmapSetOverlay : WaveOverlayContainer
2017-09-08 21:32:07 +00:00
{
public const float X_PADDING = 40;
public const float RIGHT_WIDTH = 275;
2017-09-13 15:37:18 +00:00
private readonly Header header;
private readonly Info info;
private readonly ScoresContainer scores;
2017-09-08 21:32:07 +00:00
private APIAccess api;
private RulesetStore rulesets;
private GetScoresRequest getScoresRequest;
private readonly ScrollContainer scroll;
// receive input outside our bounds so we can trigger a close event on ourselves.
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
2017-09-25 09:26:27 +00:00
public BeatmapSetOverlay()
2017-09-08 21:32:07 +00:00
{
FirstWaveColour = OsuColour.Gray(0.4f);
SecondWaveColour = OsuColour.Gray(0.3f);
ThirdWaveColour = OsuColour.Gray(0.2f);
FourthWaveColour = OsuColour.Gray(0.1f);
Anchor = Anchor.TopCentre;
Origin = Anchor.TopCentre;
RelativeSizeAxes = Axes.Both;
Width = 0.85f;
Masking = true;
EdgeEffect = new EdgeEffectParameters
{
Colour = Color4.Black.Opacity(0),
Type = EdgeEffectType.Shadow,
Radius = 3,
Offset = new Vector2(0f, 1f),
};
2017-09-13 00:00:20 +00:00
Children = new Drawable[]
2017-09-08 21:32:07 +00:00
{
2017-09-13 00:00:20 +00:00
new Box
2017-09-08 21:32:07 +00:00
{
2017-09-13 00:00:20 +00:00
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.2f)
},
scroll = new ScrollContainer
2017-09-13 00:00:20 +00:00
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,
2017-09-13 15:37:18 +00:00
Child = new ReverseChildIDFillFlowContainer<Drawable>
2017-09-13 00:00:20 +00:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
2017-09-13 15:37:18 +00:00
Children = new Drawable[]
{
header = new Header(),
2017-09-13 15:37:18 +00:00
info = new Info(),
2017-11-11 00:46:06 +00:00
scores = new ScoresContainer(),
2017-09-13 15:37:18 +00:00
},
2017-09-13 00:00:20 +00:00
},
2017-09-08 21:32:07 +00:00
},
};
2017-09-13 15:37:18 +00:00
header.Picker.Beatmap.ValueChanged += b =>
{
info.Beatmap = b;
updateScores(b);
};
}
private void updateScores(BeatmapInfo beatmap)
{
getScoresRequest?.Cancel();
if (!beatmap.OnlineBeatmapID.HasValue)
{
scores.CleanAllScores();
return;
}
2017-11-13 15:49:10 +00:00
scores.IsLoading = true;
getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset);
2017-11-13 15:49:10 +00:00
getScoresRequest.Success += r =>
{
scores.Scores = r.Scores;
scores.IsLoading = false;
};
api.Queue(getScoresRequest);
2017-09-08 21:32:07 +00:00
}
[BackgroundDependencyLoader]
private void load(APIAccess api, RulesetStore rulesets)
{
this.api = api;
this.rulesets = rulesets;
}
2017-09-08 21:32:07 +00:00
protected override void PopIn()
{
base.PopIn();
FadeEdgeEffectTo(0.25f, APPEAR_DURATION, Easing.In);
}
protected override void PopOut()
{
base.PopOut();
header.Details.StopPreview();
2017-09-08 21:32:07 +00:00
FadeEdgeEffectTo(0, DISAPPEAR_DURATION, Easing.Out);
}
protected override bool OnClick(InputState state)
{
State = Visibility.Hidden;
return true;
}
public void ShowBeatmapSet(int beatmapSetId)
{
// todo: display the overlay while we are loading here. we need to support setting BeatmapSet to null for this to work.
var req = new GetBeatmapSetRequest(beatmapSetId);
req.Success += res => ShowBeatmapSet(res.ToBeatmapSet(rulesets));
api.Queue(req);
}
2017-09-08 21:32:07 +00:00
public void ShowBeatmapSet(BeatmapSetInfo set)
{
header.BeatmapSet = info.BeatmapSet = set;
2017-09-08 21:32:07 +00:00
Show();
scroll.ScrollTo(0);
2017-09-08 21:32:07 +00:00
}
}
}