mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 21:07:18 +09:00
Implement DrawableErrorHandler component
This commit is contained in:
parent
0c78c8cb4f
commit
237be50e37
@ -2,12 +2,15 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Effects;
|
using osu.Framework.Graphics.Effects;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -31,6 +34,8 @@ namespace osu.Game.Overlays
|
|||||||
private RulesetStore rulesets { get; set; }
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
private SearchBeatmapSetsRequest getSetsRequest;
|
private SearchBeatmapSetsRequest getSetsRequest;
|
||||||
|
private CancellationTokenSource cancellationToken;
|
||||||
|
|
||||||
private Container panelsPlaceholder;
|
private Container panelsPlaceholder;
|
||||||
private BeatmapListingSearchSection searchSection;
|
private BeatmapListingSearchSection searchSection;
|
||||||
private BeatmapListingSortTabControl sortControl;
|
private BeatmapListingSortTabControl sortControl;
|
||||||
@ -121,7 +126,7 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Padding = new MarginPadding { Vertical = 15, Horizontal = 20 },
|
Padding = new MarginPadding { Horizontal = 20 },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,6 +172,7 @@ namespace osu.Game.Overlays
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
getSetsRequest?.Cancel();
|
getSetsRequest?.Cancel();
|
||||||
|
cancellationToken?.Cancel();
|
||||||
previewTrackManager.StopAnyPlaying(this);
|
previewTrackManager.StopAnyPlaying(this);
|
||||||
|
|
||||||
panelsPlaceholder.FadeColour(Color4.DimGray, 400, Easing.OutQuint);
|
panelsPlaceholder.FadeColour(Color4.DimGray, 400, Easing.OutQuint);
|
||||||
@ -185,30 +191,28 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private void recreatePanels(SearchBeatmapSetsResponse response)
|
private void recreatePanels(SearchBeatmapSetsResponse response)
|
||||||
{
|
{
|
||||||
var beatmaps = response.BeatmapSets.Select(r => r.ToBeatmapSet(rulesets)).ToList();
|
|
||||||
|
|
||||||
var hasError = !string.IsNullOrEmpty(response.Error);
|
var hasError = !string.IsNullOrEmpty(response.Error);
|
||||||
|
|
||||||
if (response.Total == 0 || hasError)
|
if (response.Total == 0 || hasError)
|
||||||
{
|
{
|
||||||
searchSection.BeatmapSet = null;
|
searchSection.BeatmapSet = null;
|
||||||
panelsPlaceholder.Clear();
|
|
||||||
panelsPlaceholder.FadeColour(Color4.White);
|
LoadComponentAsync(new DrawableErrorHandler(hasError ? response.Error : @"... nope, nothing found."), loaded =>
|
||||||
panelsPlaceholder.Add(new OsuSpriteText
|
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
addContentToPlaceholder(loaded);
|
||||||
Origin = Anchor.Centre,
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
||||||
Text = hasError ? response.Error : @"... nope, nothing found."
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var beatmaps = response.BeatmapSets.Select(r => r.ToBeatmapSet(rulesets)).ToList();
|
||||||
|
|
||||||
var newPanels = new FillFlowContainer<DirectPanel>
|
var newPanels = new FillFlowContainer<DirectPanel>
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Spacing = new Vector2(10),
|
Spacing = new Vector2(10),
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
|
Margin = new MarginPadding { Vertical = 15 },
|
||||||
ChildrenEnumerable = beatmaps.Select<BeatmapSetInfo, DirectPanel>(b => new DirectGridPanel(b)
|
ChildrenEnumerable = beatmaps.Select<BeatmapSetInfo, DirectPanel>(b => new DirectGridPanel(b)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.TopCentre,
|
Anchor = Anchor.TopCentre,
|
||||||
@ -218,12 +222,70 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
LoadComponentAsync(newPanels, loaded =>
|
LoadComponentAsync(newPanels, loaded =>
|
||||||
{
|
{
|
||||||
panelsPlaceholder.Clear();
|
addContentToPlaceholder(loaded);
|
||||||
panelsPlaceholder.FadeColour(Color4.White);
|
|
||||||
panelsPlaceholder.Add(loaded);
|
|
||||||
loaded.FadeIn(600, Easing.OutQuint);
|
loaded.FadeIn(600, Easing.OutQuint);
|
||||||
searchSection.BeatmapSet = beatmaps.First();
|
searchSection.BeatmapSet = beatmaps.First();
|
||||||
});
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addContentToPlaceholder(Drawable content)
|
||||||
|
{
|
||||||
|
panelsPlaceholder.Clear();
|
||||||
|
panelsPlaceholder.FadeColour(Color4.White);
|
||||||
|
panelsPlaceholder.Add(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
getSetsRequest?.Cancel();
|
||||||
|
cancellationToken?.Cancel();
|
||||||
|
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DrawableErrorHandler : CompositeDrawable
|
||||||
|
{
|
||||||
|
private readonly string error;
|
||||||
|
|
||||||
|
public DrawableErrorHandler(string error)
|
||||||
|
{
|
||||||
|
this.error = error;
|
||||||
|
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
Height = 250;
|
||||||
|
Margin = new MarginPadding { Top = 15 };
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(TextureStore textures)
|
||||||
|
{
|
||||||
|
AddInternal(new FillFlowContainer
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
RelativeSizeAxes = Axes.Y,
|
||||||
|
AutoSizeAxes = Axes.X,
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
Spacing = new Vector2(10, 0),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Sprite
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
FillMode = FillMode.Fit,
|
||||||
|
Texture = textures.Get(@"Online/not-found")
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Text = error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user