Merge pull request #15648 from peppy/playlist-show-invalid-beatmaps

Highlight invalid playlist items during room creation
This commit is contained in:
Dan Balasescu
2021-11-17 22:24:22 +09:00
committed by GitHub
5 changed files with 123 additions and 30 deletions

View File

@ -13,7 +13,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
@ -45,6 +44,8 @@ namespace osu.Game.Screens.OnlinePlay
private ExplicitContentBeatmapPill explicitContentPill;
private ModDisplay modDisplay;
private readonly IBindable<bool> valid = new Bindable<bool>();
private readonly Bindable<IBeatmapInfo> beatmap = new Bindable<IBeatmapInfo>();
private readonly Bindable<IRulesetInfo> ruleset = new Bindable<IRulesetInfo>();
private readonly BindableList<Mod> requiredMods = new BindableList<Mod>();
@ -66,14 +67,18 @@ namespace osu.Game.Screens.OnlinePlay
this.allowSelection = allowSelection;
beatmap.BindTo(item.Beatmap);
valid.BindTo(item.Valid);
ruleset.BindTo(item.Ruleset);
requiredMods.BindTo(item.RequiredMods);
ShowDragHandle.Value = allowEdit;
}
[Resolved]
private OsuColour colours { get; set; }
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load()
{
if (!allowEdit)
HandleColour = HandleColour.Opacity(0);
@ -85,27 +90,43 @@ namespace osu.Game.Screens.OnlinePlay
{
base.LoadComplete();
SelectedItem.BindValueChanged(selected => maskingContainer.BorderThickness = selected.NewValue == Model ? 5 : 0, true);
SelectedItem.BindValueChanged(selected =>
{
bool isCurrent = selected.NewValue == Model;
beatmap.BindValueChanged(_ => scheduleRefresh());
ruleset.BindValueChanged(_ => scheduleRefresh());
if (!valid.Value)
{
// Don't allow selection when not valid.
if (isCurrent)
{
SelectedItem.Value = selected.OldValue;
}
requiredMods.CollectionChanged += (_, __) => scheduleRefresh();
// Don't update border when not valid (the border is displaying this fact).
return;
}
maskingContainer.BorderThickness = isCurrent ? 5 : 0;
}, true);
beatmap.BindValueChanged(_ => Scheduler.AddOnce(refresh));
ruleset.BindValueChanged(_ => Scheduler.AddOnce(refresh));
valid.BindValueChanged(_ => Scheduler.AddOnce(refresh));
requiredMods.CollectionChanged += (_, __) => Scheduler.AddOnce(refresh);
refresh();
}
private ScheduledDelegate scheduledRefresh;
private PanelBackground panelBackground;
private void scheduleRefresh()
{
scheduledRefresh?.Cancel();
scheduledRefresh = Schedule(refresh);
}
private void refresh()
{
if (!valid.Value)
{
maskingContainer.BorderThickness = 5;
maskingContainer.BorderColour = colours.Red;
}
difficultyIconContainer.Child = new DifficultyIcon(Item.Beatmap.Value, ruleset.Value, requiredMods, performBackgroundDifficultyLookup: false) { Size = new Vector2(32) };
panelBackground.Beatmap.Value = Item.Beatmap.Value;
@ -278,7 +299,7 @@ namespace osu.Game.Screens.OnlinePlay
protected override bool OnClick(ClickEvent e)
{
if (allowSelection)
if (allowSelection && valid.Value)
SelectedItem.Value = Model;
return true;
}

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Specialized;
using System.Linq;
using Humanizer;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
@ -204,7 +205,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
{
new Drawable[]
{
playlist = new DrawableRoomPlaylist(true, true) { RelativeSizeAxes = Axes.Both }
playlist = new DrawableRoomPlaylist(true, false) { RelativeSizeAxes = Axes.Both }
},
new Drawable[]
{
@ -339,9 +340,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
Duration.Value = DurationField.Current.Value;
manager?.CreateRoom(room, onSuccess, onError);
loadingLayer.Show();
manager?.CreateRoom(room, onSuccess, onError);
}
private void hideError() => ErrorText.FadeOut(50);
@ -350,9 +350,31 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
private void onError(string text)
{
ErrorText.Text = text;
ErrorText.FadeIn(50);
// see https://github.com/ppy/osu-web/blob/2c97aaeb64fb4ed97c747d8383a35b30f57428c7/app/Models/Multiplayer/PlaylistItem.php#L48.
const string not_found_prefix = "beatmaps not found:";
if (text.StartsWith(not_found_prefix, StringComparison.Ordinal))
{
ErrorText.Text = "One or more beatmaps were not available online. Please remove or replace the highlighted items.";
int[] invalidBeatmapIDs = text
.Substring(not_found_prefix.Length + 1)
.Split(", ")
.Select(int.Parse)
.ToArray();
foreach (var item in Playlist)
{
if (invalidBeatmapIDs.Contains(item.BeatmapID))
item.MarkInvalid();
}
}
else
{
ErrorText.Text = text;
}
ErrorText.FadeIn(50);
loadingLayer.Hide();
}
}