mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 19:13:20 +08:00
Merge branch 'master' into move-online-beatmap-metrics
This commit is contained in:
commit
efe6763226
@ -0,0 +1,53 @@
|
|||||||
|
// 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 System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Beatmaps.Drawables;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Tests.Visual.UserInterface;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Beatmaps
|
||||||
|
{
|
||||||
|
public class TestSceneBeatmapSetOnlineStatusPill : ThemeComparisonTestScene
|
||||||
|
{
|
||||||
|
protected override Drawable CreateContent() => new FillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
|
Spacing = new Vector2(0, 10),
|
||||||
|
ChildrenEnumerable = Enum.GetValues(typeof(BeatmapSetOnlineStatus)).Cast<BeatmapSetOnlineStatus>().Select(status => new BeatmapSetOnlineStatusPill
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Status = status
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
private IEnumerable<BeatmapSetOnlineStatusPill> statusPills => this.ChildrenOfType<BeatmapSetOnlineStatusPill>();
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestFixedWidth()
|
||||||
|
{
|
||||||
|
AddStep("create themed content", () => CreateThemedContent(OverlayColourScheme.Red));
|
||||||
|
|
||||||
|
AddStep("set fixed width", () => statusPills.ForEach(pill =>
|
||||||
|
{
|
||||||
|
pill.AutoSizeAxes = Axes.Y;
|
||||||
|
pill.Width = 90;
|
||||||
|
}));
|
||||||
|
AddStep("unset fixed width", () => statusPills.ForEach(pill => pill.AutoSizeAxes = Axes.Both));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -224,7 +224,7 @@ namespace osu.Game.Tests.Visual.Components
|
|||||||
|
|
||||||
public new PreviewTrack CurrentTrack => base.CurrentTrack;
|
public new PreviewTrack CurrentTrack => base.CurrentTrack;
|
||||||
|
|
||||||
protected override TrackManagerPreviewTrack CreatePreviewTrack(BeatmapSetInfo beatmapSetInfo, ITrackStore trackStore) => new TestPreviewTrack(beatmapSetInfo, trackStore);
|
protected override TrackManagerPreviewTrack CreatePreviewTrack(IBeatmapSetInfo beatmapSetInfo, ITrackStore trackStore) => new TestPreviewTrack(beatmapSetInfo, trackStore);
|
||||||
|
|
||||||
public override bool UpdateSubTree()
|
public override bool UpdateSubTree()
|
||||||
{
|
{
|
||||||
@ -240,7 +240,7 @@ namespace osu.Game.Tests.Visual.Components
|
|||||||
|
|
||||||
public new Track Track => base.Track;
|
public new Track Track => base.Track;
|
||||||
|
|
||||||
public TestPreviewTrack(BeatmapSetInfo beatmapSetInfo, ITrackStore trackManager)
|
public TestPreviewTrack(IBeatmapSetInfo beatmapSetInfo, ITrackStore trackManager)
|
||||||
: base(beatmapSetInfo, trackManager)
|
: base(beatmapSetInfo, trackManager)
|
||||||
{
|
{
|
||||||
this.trackManager = trackManager;
|
this.trackManager = trackManager;
|
||||||
|
@ -43,11 +43,11 @@ namespace osu.Game.Audio
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves a <see cref="PreviewTrack"/> for a <see cref="BeatmapSetInfo"/>.
|
/// Retrieves a <see cref="PreviewTrack"/> for a <see cref="IBeatmapSetInfo"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmapSetInfo">The <see cref="BeatmapSetInfo"/> to retrieve the preview track for.</param>
|
/// <param name="beatmapSetInfo">The <see cref="IBeatmapSetInfo"/> to retrieve the preview track for.</param>
|
||||||
/// <returns>The playable <see cref="PreviewTrack"/>.</returns>
|
/// <returns>The playable <see cref="PreviewTrack"/>.</returns>
|
||||||
public PreviewTrack Get(BeatmapSetInfo beatmapSetInfo)
|
public PreviewTrack Get(IBeatmapSetInfo beatmapSetInfo)
|
||||||
{
|
{
|
||||||
var track = CreatePreviewTrack(beatmapSetInfo, trackStore);
|
var track = CreatePreviewTrack(beatmapSetInfo, trackStore);
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ namespace osu.Game.Audio
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the <see cref="TrackManagerPreviewTrack"/>.
|
/// Creates the <see cref="TrackManagerPreviewTrack"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual TrackManagerPreviewTrack CreatePreviewTrack(BeatmapSetInfo beatmapSetInfo, ITrackStore trackStore) =>
|
protected virtual TrackManagerPreviewTrack CreatePreviewTrack(IBeatmapSetInfo beatmapSetInfo, ITrackStore trackStore) =>
|
||||||
new TrackManagerPreviewTrack(beatmapSetInfo, trackStore);
|
new TrackManagerPreviewTrack(beatmapSetInfo, trackStore);
|
||||||
|
|
||||||
public class TrackManagerPreviewTrack : PreviewTrack
|
public class TrackManagerPreviewTrack : PreviewTrack
|
||||||
@ -99,10 +99,10 @@ namespace osu.Game.Audio
|
|||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
public IPreviewTrackOwner Owner { get; private set; }
|
public IPreviewTrackOwner Owner { get; private set; }
|
||||||
|
|
||||||
private readonly BeatmapSetInfo beatmapSetInfo;
|
private readonly IBeatmapSetInfo beatmapSetInfo;
|
||||||
private readonly ITrackStore trackManager;
|
private readonly ITrackStore trackManager;
|
||||||
|
|
||||||
public TrackManagerPreviewTrack(BeatmapSetInfo beatmapSetInfo, ITrackStore trackManager)
|
public TrackManagerPreviewTrack(IBeatmapSetInfo beatmapSetInfo, ITrackStore trackManager)
|
||||||
{
|
{
|
||||||
this.beatmapSetInfo = beatmapSetInfo;
|
this.beatmapSetInfo = beatmapSetInfo;
|
||||||
this.trackManager = trackManager;
|
this.trackManager = trackManager;
|
||||||
@ -114,7 +114,7 @@ namespace osu.Game.Audio
|
|||||||
Logger.Log($"A {nameof(PreviewTrack)} was created without a containing {nameof(IPreviewTrackOwner)}. An owner should be added for correct behaviour.");
|
Logger.Log($"A {nameof(PreviewTrack)} was created without a containing {nameof(IPreviewTrackOwner)}. An owner should be added for correct behaviour.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Track GetTrack() => trackManager.Get($"https://b.ppy.sh/preview/{beatmapSetInfo?.OnlineBeatmapSetID}.mp3");
|
protected override Track GetTrack() => trackManager.Get($"https://b.ppy.sh/preview/{beatmapSetInfo.OnlineID}.mp3");
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PreviewTrackStore : AudioCollectionManager<AdjustableAudioComponent>, ITrackStore
|
private class PreviewTrackStore : AudioCollectionManager<AdjustableAudioComponent>, ITrackStore
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Extensions.LocalisationExtensions;
|
using osu.Framework.Extensions.LocalisationExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -8,15 +11,13 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Overlays;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps.Drawables
|
namespace osu.Game.Beatmaps.Drawables
|
||||||
{
|
{
|
||||||
public class BeatmapSetOnlineStatusPill : CircularContainer
|
public class BeatmapSetOnlineStatusPill : CircularContainer
|
||||||
{
|
{
|
||||||
private readonly OsuSpriteText statusText;
|
|
||||||
private readonly Box background;
|
|
||||||
|
|
||||||
private BeatmapSetOnlineStatus status;
|
private BeatmapSetOnlineStatus status;
|
||||||
|
|
||||||
public BeatmapSetOnlineStatus Status
|
public BeatmapSetOnlineStatus Status
|
||||||
@ -29,8 +30,8 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
|
|
||||||
status = value;
|
status = value;
|
||||||
|
|
||||||
Alpha = value == BeatmapSetOnlineStatus.None ? 0 : 1;
|
if (IsLoaded)
|
||||||
statusText.Text = value.GetLocalisableDescription().ToUpper();
|
updateState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,15 +47,17 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
set => statusText.Padding = value;
|
set => statusText.Padding = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color4 BackgroundColour
|
private readonly OsuSpriteText statusText;
|
||||||
{
|
private readonly Box background;
|
||||||
get => background.Colour;
|
|
||||||
set => background.Colour = value;
|
[Resolved]
|
||||||
}
|
private OsuColour colours { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved(CanBeNull = true)]
|
||||||
|
private OverlayColourProvider? colourProvider { get; set; }
|
||||||
|
|
||||||
public BeatmapSetOnlineStatusPill()
|
public BeatmapSetOnlineStatusPill()
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both;
|
|
||||||
Masking = true;
|
Masking = true;
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
@ -63,7 +66,6 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = Color4.Black,
|
Colour = Color4.Black,
|
||||||
Alpha = 0.5f,
|
|
||||||
},
|
},
|
||||||
statusText = new OsuSpriteText
|
statusText = new OsuSpriteText
|
||||||
{
|
{
|
||||||
@ -74,6 +76,27 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
};
|
};
|
||||||
|
|
||||||
Status = BeatmapSetOnlineStatus.None;
|
Status = BeatmapSetOnlineStatus.None;
|
||||||
|
TextPadding = new MarginPadding { Horizontal = 5, Bottom = 1 };
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
updateState();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateState()
|
||||||
|
{
|
||||||
|
Alpha = Status == BeatmapSetOnlineStatus.None ? 0 : 1;
|
||||||
|
|
||||||
|
statusText.Text = Status.GetLocalisableDescription().ToUpper();
|
||||||
|
|
||||||
|
if (colourProvider != null)
|
||||||
|
statusText.Colour = status == BeatmapSetOnlineStatus.Graveyard ? colourProvider.Background1 : colourProvider.Background3;
|
||||||
|
else
|
||||||
|
statusText.Colour = status == BeatmapSetOnlineStatus.Graveyard ? colours.GreySeafoamLight : Color4.Black;
|
||||||
|
|
||||||
|
background.Colour = OsuColour.ForBeatmapSetOnlineStatus(Status) ?? colourProvider?.Light1 ?? colours.GreySeafoamLighter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,42 @@ namespace osu.Game.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves a colour for the given <see cref="BeatmapSetOnlineStatus"/>.
|
||||||
|
/// A <see langword="null"/> value indicates that a "background" shade from the local <see cref="OverlayColourProvider"/>
|
||||||
|
/// (or another fallback colour) should be used.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Sourced from web: https://github.com/ppy/osu-web/blob/007eebb1916ed5cb6a7866d82d8011b1060a945e/resources/assets/less/layout.less#L36-L50
|
||||||
|
/// </remarks>
|
||||||
|
public static Color4? ForBeatmapSetOnlineStatus(BeatmapSetOnlineStatus status)
|
||||||
|
{
|
||||||
|
switch (status)
|
||||||
|
{
|
||||||
|
case BeatmapSetOnlineStatus.Ranked:
|
||||||
|
case BeatmapSetOnlineStatus.Approved:
|
||||||
|
return Color4Extensions.FromHex(@"b3ff66");
|
||||||
|
|
||||||
|
case BeatmapSetOnlineStatus.Loved:
|
||||||
|
return Color4Extensions.FromHex(@"ff66ab");
|
||||||
|
|
||||||
|
case BeatmapSetOnlineStatus.Qualified:
|
||||||
|
return Color4Extensions.FromHex(@"66ccff");
|
||||||
|
|
||||||
|
case BeatmapSetOnlineStatus.Pending:
|
||||||
|
return Color4Extensions.FromHex(@"ffd966");
|
||||||
|
|
||||||
|
case BeatmapSetOnlineStatus.WIP:
|
||||||
|
return Color4Extensions.FromHex(@"ff9966");
|
||||||
|
|
||||||
|
case BeatmapSetOnlineStatus.Graveyard:
|
||||||
|
return Color4.Black;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a foreground text colour that is supposed to contrast well with
|
/// Returns a foreground text colour that is supposed to contrast well with
|
||||||
/// the supplied <paramref name="backgroundColour"/>.
|
/// the supplied <paramref name="backgroundColour"/>.
|
||||||
|
@ -1,20 +1,38 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.IO.Network;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace osu.Game.Online.API.Requests
|
namespace osu.Game.Online.API.Requests
|
||||||
{
|
{
|
||||||
public class GetBeatmapRequest : APIRequest<APIBeatmap>
|
public class GetBeatmapRequest : APIRequest<APIBeatmap>
|
||||||
{
|
{
|
||||||
private readonly BeatmapInfo beatmapInfo;
|
private readonly IBeatmapInfo beatmapInfo;
|
||||||
|
|
||||||
public GetBeatmapRequest(BeatmapInfo beatmapInfo)
|
private readonly string filename;
|
||||||
|
|
||||||
|
public GetBeatmapRequest(IBeatmapInfo beatmapInfo)
|
||||||
{
|
{
|
||||||
this.beatmapInfo = beatmapInfo;
|
this.beatmapInfo = beatmapInfo;
|
||||||
|
|
||||||
|
filename = (beatmapInfo as BeatmapInfo)?.Path ?? string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Target => $@"beatmaps/lookup?id={beatmapInfo.OnlineBeatmapID}&checksum={beatmapInfo.MD5Hash}&filename={System.Uri.EscapeUriString(beatmapInfo.Path ?? string.Empty)}";
|
protected override WebRequest CreateWebRequest()
|
||||||
|
{
|
||||||
|
var request = base.CreateWebRequest();
|
||||||
|
|
||||||
|
request.AddParameter(@"id", beatmapInfo.OnlineID.ToString());
|
||||||
|
request.AddParameter(@"checksum", beatmapInfo.MD5Hash);
|
||||||
|
request.AddParameter(@"filename", filename);
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Target => @"beatmaps/lookup";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,6 +243,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
|
|||||||
|
|
||||||
statusContainer.Add(new BeatmapSetOnlineStatusPill
|
statusContainer.Add(new BeatmapSetOnlineStatusPill
|
||||||
{
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
TextSize = 12,
|
TextSize = 12,
|
||||||
TextPadding = new MarginPadding { Horizontal = 10, Vertical = 5 },
|
TextPadding = new MarginPadding { Horizontal = 10, Vertical = 5 },
|
||||||
Status = SetInfo.OnlineInfo?.Status ?? BeatmapSetOnlineStatus.None,
|
Status = SetInfo.OnlineInfo?.Status ?? BeatmapSetOnlineStatus.None,
|
||||||
|
@ -257,6 +257,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
|
|||||||
|
|
||||||
statusContainer.Add(new BeatmapSetOnlineStatusPill
|
statusContainer.Add(new BeatmapSetOnlineStatusPill
|
||||||
{
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
TextSize = 12,
|
TextSize = 12,
|
||||||
TextPadding = new MarginPadding { Horizontal = 10, Vertical = 4 },
|
TextPadding = new MarginPadding { Horizontal = 10, Vertical = 4 },
|
||||||
Status = SetInfo.OnlineInfo?.Status ?? BeatmapSetOnlineStatus.None,
|
Status = SetInfo.OnlineInfo?.Status ?? BeatmapSetOnlineStatus.None,
|
||||||
|
@ -198,6 +198,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
{
|
{
|
||||||
onlineStatusPill = new BeatmapSetOnlineStatusPill
|
onlineStatusPill = new BeatmapSetOnlineStatusPill
|
||||||
{
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
Origin = Anchor.TopRight,
|
Origin = Anchor.TopRight,
|
||||||
TextSize = 14,
|
TextSize = 14,
|
||||||
@ -220,7 +221,6 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
private void load(OverlayColourProvider colourProvider)
|
private void load(OverlayColourProvider colourProvider)
|
||||||
{
|
{
|
||||||
coverGradient.Colour = ColourInfo.GradientVertical(colourProvider.Background6.Opacity(0.3f), colourProvider.Background6.Opacity(0.8f));
|
coverGradient.Colour = ColourInfo.GradientVertical(colourProvider.Background6.Opacity(0.3f), colourProvider.Background6.Opacity(0.8f));
|
||||||
onlineStatusPill.BackgroundColour = colourProvider.Background6;
|
|
||||||
|
|
||||||
State.BindValueChanged(_ => updateDownloadButtons());
|
State.BindValueChanged(_ => updateDownloadButtons());
|
||||||
|
|
||||||
|
@ -257,6 +257,7 @@ namespace osu.Game.Screens.Select
|
|||||||
},
|
},
|
||||||
StatusPill = new BeatmapSetOnlineStatusPill
|
StatusPill = new BeatmapSetOnlineStatusPill
|
||||||
{
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
Origin = Anchor.TopRight,
|
Origin = Anchor.TopRight,
|
||||||
Shear = -wedged_container_shear,
|
Shear = -wedged_container_shear,
|
||||||
|
@ -60,6 +60,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
{
|
{
|
||||||
new BeatmapSetOnlineStatusPill
|
new BeatmapSetOnlineStatusPill
|
||||||
{
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Margin = new MarginPadding { Right = 5 },
|
Margin = new MarginPadding { Right = 5 },
|
||||||
|
Loading…
Reference in New Issue
Block a user