Merge pull request #18603 from peppy/fix-import-dialog

Add placeholder when no results are visible at song select
This commit is contained in:
Dan Balasescu 2022-06-08 15:22:31 +09:00 committed by GitHub
commit c43670fcd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 197 additions and 62 deletions

View File

@ -609,8 +609,6 @@ namespace osu.Game.Tests.Visual.Navigation
public ModSelectOverlay ModSelectOverlay => ModSelect; public ModSelectOverlay ModSelectOverlay => ModSelect;
public BeatmapOptionsOverlay BeatmapOptionsOverlay => BeatmapOptions; public BeatmapOptionsOverlay BeatmapOptionsOverlay => BeatmapOptions;
protected override bool DisplayStableImportPrompt => false;
} }
} }
} }

View File

@ -18,6 +18,7 @@ using osu.Game.Database;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Mods; using osu.Game.Overlays.Mods;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -80,6 +81,37 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("delete all beatmaps", () => manager?.Delete()); AddStep("delete all beatmaps", () => manager?.Delete());
} }
[Test]
public void TestPlaceholderBeatmapPresence()
{
createSongSelect();
AddUntilStep("wait for placeholder visible", () => getPlaceholder()?.State.Value == Visibility.Visible);
addRulesetImportStep(0);
AddUntilStep("wait for placeholder hidden", () => getPlaceholder()?.State.Value == Visibility.Hidden);
AddStep("delete all beatmaps", () => manager?.Delete());
AddUntilStep("wait for placeholder visible", () => getPlaceholder()?.State.Value == Visibility.Visible);
}
[Test]
public void TestPlaceholderConvertSetting()
{
changeRuleset(2);
addRulesetImportStep(0);
AddStep("change convert setting", () => config.SetValue(OsuSetting.ShowConvertedBeatmaps, false));
createSongSelect();
AddUntilStep("wait for placeholder visible", () => getPlaceholder()?.State.Value == Visibility.Visible);
AddStep("click link in placeholder", () => getPlaceholder().ChildrenOfType<DrawableLinkCompiler>().First().TriggerClick());
AddUntilStep("convert setting changed", () => config.Get<bool>(OsuSetting.ShowConvertedBeatmaps));
AddUntilStep("wait for placeholder visible", () => getPlaceholder()?.State.Value == Visibility.Hidden);
}
[Test] [Test]
public void TestSingleFilterOnEnter() public void TestSingleFilterOnEnter()
{ {
@ -941,6 +973,8 @@ namespace osu.Game.Tests.Visual.SongSelect
private int getBeatmapIndex(BeatmapSetInfo set, BeatmapInfo info) => set.Beatmaps.IndexOf(info); private int getBeatmapIndex(BeatmapSetInfo set, BeatmapInfo info) => set.Beatmaps.IndexOf(info);
private NoResultsPlaceholder getPlaceholder() => songSelect.ChildrenOfType<NoResultsPlaceholder>().FirstOrDefault();
private int getCurrentBeatmapIndex() => getBeatmapIndex(songSelect.Carousel.SelectedBeatmapSet, songSelect.Carousel.SelectedBeatmapInfo); private int getCurrentBeatmapIndex() => getBeatmapIndex(songSelect.Carousel.SelectedBeatmapSet, songSelect.Carousel.SelectedBeatmapInfo);
private int getDifficultyIconIndex(DrawableCarouselBeatmapSet set, FilterableDifficultyIcon icon) private int getDifficultyIconIndex(DrawableCarouselBeatmapSet set, FilterableDifficultyIcon icon)

View File

@ -98,6 +98,8 @@ namespace osu.Game.Screens.Select
protected readonly CarouselScrollContainer Scroll; protected readonly CarouselScrollContainer Scroll;
private readonly NoResultsPlaceholder noResultsPlaceholder;
private IEnumerable<CarouselBeatmapSet> beatmapSets => root.Children.OfType<CarouselBeatmapSet>(); private IEnumerable<CarouselBeatmapSet> beatmapSets => root.Children.OfType<CarouselBeatmapSet>();
// todo: only used for testing, maybe remove. // todo: only used for testing, maybe remove.
@ -171,7 +173,8 @@ namespace osu.Game.Screens.Select
Scroll = new CarouselScrollContainer Scroll = new CarouselScrollContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
} },
noResultsPlaceholder = new NoResultsPlaceholder()
} }
}; };
} }
@ -649,8 +652,18 @@ namespace osu.Game.Screens.Select
// First we iterate over all non-filtered carousel items and populate their // First we iterate over all non-filtered carousel items and populate their
// vertical position data. // vertical position data.
if (revalidateItems) if (revalidateItems)
{
updateYPositions(); updateYPositions();
if (visibleItems.Count == 0)
{
noResultsPlaceholder.Filter = activeCriteria;
noResultsPlaceholder.Show();
}
else
noResultsPlaceholder.Hide();
}
// if there is a pending scroll action we apply it without animation and transfer the difference in position to the panels. // if there is a pending scroll action we apply it without animation and transfer the difference in position to the panels.
// this is intentionally applied before updating the visible range below, to avoid animating new items (sourced from pool) from locations off-screen, as it looks bad. // this is intentionally applied before updating the visible range below, to avoid animating new items (sourced from pool) from locations off-screen, as it looks bad.
if (pendingScrollOperation != PendingScrollOperation.None) if (pendingScrollOperation != PendingScrollOperation.None)

View File

@ -1,33 +0,0 @@
// 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;
using osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
namespace osu.Game.Screens.Select
{
public class ImportFromStablePopup : PopupDialog
{
public ImportFromStablePopup(Action importFromStable)
{
HeaderText = @"You have no beatmaps!";
BodyText = "Would you like to import your beatmaps, skins, collections and scores from an existing osu!stable installation?\nThis will create a second copy of all files on disk.";
Icon = FontAwesome.Solid.Plane;
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = @"Yes please!",
Action = importFromStable
},
new PopupDialogCancelButton
{
Text = @"No, I'd like to start from scratch",
},
};
}
}
}

View File

@ -0,0 +1,145 @@
// 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.
#nullable enable
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Localisation;
using osu.Game.Online.Chat;
using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Screens.Select
{
public class NoResultsPlaceholder : VisibilityContainer
{
private FilterCriteria? filter;
private LinkFlowContainer textFlow = null!;
[Resolved]
private BeatmapManager beatmaps { get; set; } = null!;
[Resolved]
private FirstRunSetupOverlay? firstRunSetupOverlay { get; set; }
[Resolved]
private OsuConfigManager config { get; set; } = null!;
public FilterCriteria Filter
{
set
{
if (filter == value)
return;
filter = value;
Scheduler.AddOnce(updateText);
}
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Masking = true;
CornerRadius = 10;
Width = 300;
AutoSizeAxes = Axes.Y;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
InternalChildren = new Drawable[]
{
new Box
{
Colour = colours.Gray2,
RelativeSizeAxes = Axes.Both,
},
new SpriteIcon
{
Icon = FontAwesome.Regular.SadTear,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Margin = new MarginPadding(10),
Size = new Vector2(50),
},
textFlow = new LinkFlowContainer
{
Y = 60,
Padding = new MarginPadding(10),
TextAnchor = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
}
};
}
protected override void PopIn()
{
this.FadeIn(600, Easing.OutQuint);
Scheduler.AddOnce(updateText);
}
protected override void PopOut()
{
this.FadeOut(200, Easing.OutQuint);
}
private void updateText()
{
// TODO: Refresh this text when new beatmaps are imported. Right now it won't get up-to-date suggestions.
// Bounce should play every time the filter criteria is updated.
this.ScaleTo(0.9f)
.ScaleTo(1f, 1000, Easing.OutElastic);
textFlow.Clear();
if (beatmaps.QueryBeatmapSet(s => !s.Protected && !s.DeletePending) == null)
{
textFlow.AddParagraph("No beatmaps found!");
textFlow.AddParagraph(string.Empty);
textFlow.AddParagraph("Consider using the \"");
textFlow.AddLink(FirstRunSetupOverlayStrings.FirstRunSetupTitle, () => firstRunSetupOverlay?.Show());
textFlow.AddText("\" to download or import some beatmaps!");
}
else
{
textFlow.AddParagraph("No beatmaps match your filter criteria!");
textFlow.AddParagraph(string.Empty);
if (string.IsNullOrEmpty(filter?.SearchText))
{
// TODO: Add realm queries to hint at which ruleset results are available in (and allow clicking to switch).
// TODO: Make this message more certain by ensuring the osu! beatmaps exist before suggesting.
if (filter?.Ruleset.OnlineID > 0 && !filter.AllowConvertedBeatmaps)
{
textFlow.AddParagraph("Beatmaps may be available by ");
textFlow.AddLink("enabling automatic conversion", () => config.SetValue(OsuSetting.ShowConvertedBeatmaps, true));
textFlow.AddText("!");
}
}
else
{
textFlow.AddParagraph("You can try ");
textFlow.AddLink("searching online", LinkAction.SearchBeatmapSet, filter.SearchText);
textFlow.AddText(" for this query.");
}
}
// TODO: add clickable link to reset criteria.
}
}
}

View File

@ -28,7 +28,6 @@ using osuTK.Input;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
@ -37,7 +36,6 @@ using osu.Game.Graphics.UserInterface;
using System.Diagnostics; using System.Diagnostics;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Database;
using osu.Game.Skinning; using osu.Game.Skinning;
namespace osu.Game.Screens.Select namespace osu.Game.Screens.Select
@ -59,8 +57,6 @@ namespace osu.Game.Screens.Select
protected virtual bool ShowFooter => true; protected virtual bool ShowFooter => true;
protected virtual bool DisplayStableImportPrompt => legacyImportManager?.SupportsImportFromStable == true;
public override bool? AllowTrackAdjustments => true; public override bool? AllowTrackAdjustments => true;
/// <summary> /// <summary>
@ -94,14 +90,13 @@ namespace osu.Game.Screens.Select
protected Container LeftArea { get; private set; } protected Container LeftArea { get; private set; }
private BeatmapInfoWedge beatmapInfoWedge; private BeatmapInfoWedge beatmapInfoWedge;
private IDialogOverlay dialogOverlay;
[Resolved(canBeNull: true)]
private IDialogOverlay dialogOverlay { get; set; }
[Resolved] [Resolved]
private BeatmapManager beatmaps { get; set; } private BeatmapManager beatmaps { get; set; }
[Resolved(CanBeNull = true)]
private LegacyImportManager legacyImportManager { get; set; }
protected ModSelectOverlay ModSelect { get; private set; } protected ModSelectOverlay ModSelect { get; private set; }
protected Sample SampleConfirm { get; private set; } protected Sample SampleConfirm { get; private set; }
@ -127,7 +122,7 @@ namespace osu.Game.Screens.Select
internal IOverlayManager OverlayManager { get; private set; } internal IOverlayManager OverlayManager { get; private set; }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(AudioManager audio, IDialogOverlay dialog, OsuColour colours, ManageCollectionsDialog manageCollectionsDialog, DifficultyRecommender recommender) private void load(AudioManager audio, OsuColour colours, ManageCollectionsDialog manageCollectionsDialog, DifficultyRecommender recommender)
{ {
// initial value transfer is required for FilterControl (it uses our re-cached bindables in its async load for the initial filter). // initial value transfer is required for FilterControl (it uses our re-cached bindables in its async load for the initial filter).
transferRulesetValue(); transferRulesetValue();
@ -289,26 +284,9 @@ namespace osu.Game.Screens.Select
BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.Solid.Eraser, colours.Purple, () => clearScores(Beatmap.Value.BeatmapInfo)); BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.Solid.Eraser, colours.Purple, () => clearScores(Beatmap.Value.BeatmapInfo));
} }
dialogOverlay = dialog;
sampleChangeDifficulty = audio.Samples.Get(@"SongSelect/select-difficulty"); sampleChangeDifficulty = audio.Samples.Get(@"SongSelect/select-difficulty");
sampleChangeBeatmap = audio.Samples.Get(@"SongSelect/select-expand"); sampleChangeBeatmap = audio.Samples.Get(@"SongSelect/select-expand");
SampleConfirm = audio.Samples.Get(@"SongSelect/confirm-selection"); SampleConfirm = audio.Samples.Get(@"SongSelect/confirm-selection");
if (dialogOverlay != null)
{
Schedule(() =>
{
// if we have no beatmaps, let's prompt the user to import from over a stable install if he has one.
if (beatmaps.QueryBeatmapSet(s => !s.Protected && !s.DeletePending) == null && DisplayStableImportPrompt)
{
dialogOverlay.Push(new ImportFromStablePopup(() =>
{
Task.Run(() => legacyImportManager.ImportFromStableAsync(StableContent.All));
}));
}
});
}
} }
protected override void LoadComplete() protected override void LoadComplete()