1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Merge pull request #11035 from smoogipoo/add-playlist-length

This commit is contained in:
Dean Herbert 2020-12-03 18:39:54 +09:00 committed by GitHub
commit 37d550f42a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 2 deletions

View File

@ -75,6 +75,7 @@ namespace osu.Game.Online.API.Requests.Responses
StarDifficulty = starDifficulty,
OnlineBeatmapID = OnlineBeatmapID,
Version = version,
// this is actually an incorrect mapping (Length is calculated as drain length in lazer's import process, see BeatmapManager.calculateLength).
Length = TimeSpan.FromSeconds(length).TotalMilliseconds,
Status = Status,
BeatmapSet = set,

View File

@ -0,0 +1,16 @@
// 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.Linq;
using Humanizer;
using Humanizer.Localisation;
using osu.Framework.Bindables;
namespace osu.Game.Online.Multiplayer
{
public static class PlaylistExtensions
{
public static string GetTotalDuration(this BindableList<PlaylistItem> playlist) =>
playlist.Select(p => p.Beatmap.Value.Length).Sum().Milliseconds().Humanize(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Hour, precision: 2);
}
}

View File

@ -0,0 +1,22 @@
// 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 osu.Game.Online.Multiplayer;
namespace osu.Game.Screens.Multi.Components
{
public class OverlinedPlaylistHeader : OverlinedHeader
{
public OverlinedPlaylistHeader()
: base("Playlist")
{
}
protected override void LoadComplete()
{
base.LoadComplete();
Playlist.BindCollectionChanged((_, __) => Details.Value = Playlist.GetTotalDuration(), true);
}
}
}

View File

@ -67,7 +67,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
}
}
},
new Drawable[] { new OverlinedHeader("Playlist"), },
new Drawable[] { new OverlinedPlaylistHeader(), },
new Drawable[]
{
new DrawableRoomPlaylist(false, false)

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Specialized;
using Humanizer;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -69,6 +70,7 @@ namespace osu.Game.Screens.Multi.Match.Components
private OsuSpriteText typeLabel;
private LoadingLayer loadingLayer;
private DrawableRoomPlaylist playlist;
private OsuSpriteText playlistLength;
[Resolved(CanBeNull = true)]
private IRoomManager manager { get; set; }
@ -229,6 +231,15 @@ namespace osu.Game.Screens.Multi.Match.Components
playlist = new DrawableRoomPlaylist(true, true) { RelativeSizeAxes = Axes.Both }
},
new Drawable[]
{
playlistLength = new OsuSpriteText
{
Margin = new MarginPadding { Vertical = 5 },
Colour = colours.Yellow,
Font = OsuFont.GetFont(size: 12),
}
},
new Drawable[]
{
new PurpleTriangleButton
{
@ -243,6 +254,7 @@ namespace osu.Game.Screens.Multi.Match.Components
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
}
}
},
@ -315,6 +327,7 @@ namespace osu.Game.Screens.Multi.Match.Components
Duration.BindValueChanged(duration => DurationField.Current.Value = duration.NewValue, true);
playlist.Items.BindTo(Playlist);
Playlist.BindCollectionChanged(onPlaylistChanged, true);
}
protected override void Update()
@ -324,6 +337,9 @@ namespace osu.Game.Screens.Multi.Match.Components
ApplyButton.Enabled.Value = hasValidSettings;
}
private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e) =>
playlistLength.Text = $"Length: {Playlist.GetTotalDuration()}";
private bool hasValidSettings => RoomID.Value == null && NameField.Text.Length > 0 && Playlist.Count > 0;
private void apply()

View File

@ -135,7 +135,7 @@ namespace osu.Game.Screens.Multi.Match
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[] { new OverlinedHeader("Playlist"), },
new Drawable[] { new OverlinedPlaylistHeader(), },
new Drawable[]
{
new DrawableRoomPlaylistWithResults

View File

@ -31,6 +31,7 @@ namespace osu.Game.Tests.Beatmaps
BeatmapInfo.BeatmapSet.Metadata = BeatmapInfo.Metadata;
BeatmapInfo.BeatmapSet.Files = new List<BeatmapSetFileInfo>();
BeatmapInfo.BeatmapSet.Beatmaps = new List<BeatmapInfo> { BeatmapInfo };
BeatmapInfo.Length = 75000;
BeatmapInfo.BeatmapSet.OnlineInfo = new BeatmapSetOnlineInfo
{
Status = BeatmapSetOnlineStatus.Ranked,