1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 23:22:55 +08:00

Add a loading state to BeatmapSetOverlay.

- Handle null value in header and info sections
- Add item to context menu for carousel beatmaps to show details
This commit is contained in:
naoey 2018-03-10 11:25:26 +05:30
parent c304c1eecf
commit 7482d5986a
No known key found for this signature in database
GPG Key ID: 3908EC682A3E19C7
6 changed files with 64 additions and 11 deletions

View File

@ -374,6 +374,7 @@ namespace osu.Game.Tests.Visual
AddStep(@"hide", overlay.Hide);
AddStep(@"show without reload", overlay.Show);
AddStep(@"show loading", () => overlay.BeatmapSet = null);
}
}
}

View File

@ -150,7 +150,7 @@ namespace osu.Game.Overlays.BeatmapSet
Beatmap.TriggerChange();
}
private void showBeatmap(BeatmapInfo beatmap) => version.Text = beatmap.Version;
private void showBeatmap(BeatmapInfo beatmap) => version.Text = beatmap?.Version;
private void updateDifficultyButtons()
{

View File

@ -48,6 +48,9 @@ namespace osu.Game.Overlays.BeatmapSet
if (value == beatmapSet) return;
beatmapSet = value;
if (beatmapSet == null)
return;
Picker.BeatmapSet = author.BeatmapSet = Details.BeatmapSet = BeatmapSet;
title.Text = BeatmapSet.Metadata.Title;
artist.Text = BeatmapSet.Metadata.Artist;

View File

@ -34,6 +34,9 @@ namespace osu.Game.Overlays.BeatmapSet
if (value == beatmapSet) return;
beatmapSet = value;
if (beatmapSet == null)
return;
source.Text = BeatmapSet.Metadata.Source;
tags.Text = BeatmapSet.Metadata.Tags;
}

View File

@ -18,17 +18,22 @@ using osu.Game.Overlays.BeatmapSet;
using osu.Game.Rulesets;
using osu.Game.Overlays.BeatmapSet.Scores;
using System.Linq;
using osu.Framework.Configuration;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays
{
public class BeatmapSetOverlay : WaveOverlayContainer
{
private const int fade_duration = 300;
public const float X_PADDING = 40;
public const float RIGHT_WIDTH = 275;
private readonly Header header;
private readonly Info info;
private readonly ScoresContainer scores;
private readonly LoadingAnimation loading;
private APIAccess api;
private RulesetStore rulesets;
@ -36,6 +41,31 @@ namespace osu.Game.Overlays
private readonly ScrollContainer scroll;
private BeatmapSetInfo beatmapSet;
public BeatmapSetInfo BeatmapSet
{
get => beatmapSet;
set
{
if (value == beatmapSet)
return;
beatmapSet = value;
if (beatmapSet == null)
{
scroll.FadeOut(fade_duration);
loading.FadeIn(fade_duration);
return;
}
header.BeatmapSet = info.BeatmapSet = beatmapSet;
loading.FadeOut(fade_duration);
scroll.FadeIn(fade_duration);
}
}
// receive input outside our bounds so we can trigger a close event on ourselves.
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
@ -67,10 +97,17 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.2f)
},
loading = new LoadingAnimation
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 1,
},
scroll = new ScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,
Alpha = 0,
Child = new ReverseChildIDFillFlowContainer<Drawable>
{
RelativeSizeAxes = Axes.X,
@ -89,7 +126,9 @@ namespace osu.Game.Overlays
header.Picker.Beatmap.ValueChanged += b =>
{
info.Beatmap = b;
updateScores(b);
if (b != null)
updateScores(b);
};
}
@ -132,6 +171,7 @@ namespace osu.Game.Overlays
base.PopOut();
header.Details.StopPreview();
FadeEdgeEffectTo(0, DISAPPEAR_DURATION, Easing.Out);
BeatmapSet = null;
}
protected override bool OnClick(InputState state)
@ -142,6 +182,7 @@ namespace osu.Game.Overlays
public void ShowBeatmap(int beatmapId)
{
BeatmapSet = null;
var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId);
req.Success += res =>
{
@ -149,25 +190,21 @@ namespace osu.Game.Overlays
header.Picker.Beatmap.Value = header.BeatmapSet.Beatmaps.First(b => b.OnlineBeatmapID == beatmapId);
};
api.Queue(req);
}
public void ShowBeatmap(BeatmapInfo beatmap)
{
ShowBeatmapSet(beatmap.BeatmapSet);
header.Picker.Beatmap.Value = beatmap;
Show();
}
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.
BeatmapSet = null;
var req = new GetBeatmapSetRequest(beatmapSetId);
req.Success += res => ShowBeatmapSet(res.ToBeatmapSet(rulesets));
api.Queue(req);
Show();
}
public void ShowBeatmapSet(BeatmapSetInfo set)
{
header.BeatmapSet = info.BeatmapSet = set;
BeatmapSet = set;
Show();
scroll.ScrollTo(0);
}

View File

@ -17,6 +17,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using OpenTK;
using OpenTK.Graphics;
@ -35,6 +36,8 @@ namespace osu.Game.Screens.Select.Carousel
private Triangles triangles;
private StarCounter starCounter;
private BeatmapSetOverlay beatmapOverlay;
public DrawableCarouselBeatmap(CarouselBeatmap panel) : base(panel)
{
beatmap = panel.Beatmap;
@ -42,8 +45,10 @@ namespace osu.Game.Screens.Select.Carousel
}
[BackgroundDependencyLoader(true)]
private void load(SongSelect songSelect, BeatmapManager manager)
private void load(SongSelect songSelect, BeatmapManager manager, BeatmapSetOverlay beatmapOverlay)
{
this.beatmapOverlay = beatmapOverlay;
if (songSelect != null)
{
startRequested = songSelect.FinaliseSelection;
@ -171,6 +176,10 @@ namespace osu.Game.Screens.Select.Carousel
new OsuMenuItem("Play", MenuItemType.Highlighted, () => startRequested?.Invoke(beatmap)),
new OsuMenuItem("Edit", MenuItemType.Standard, () => editRequested?.Invoke(beatmap)),
new OsuMenuItem("Hide", MenuItemType.Destructive, () => hideRequested?.Invoke(beatmap)),
new OsuMenuItem("Details", MenuItemType.Standard, () =>
{
if (beatmap.OnlineBeatmapID.HasValue) beatmapOverlay?.ShowBeatmap(beatmap.OnlineBeatmapID.Value);
}),
};
}
}