2019-02-26 15:10:06 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-07-01 18:41:30 +08:00
|
|
|
|
using System.Linq;
|
2017-03-26 06:33:03 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-07-01 18:41:30 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-03-25 06:02:24 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-03-26 06:33:03 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-07-26 12:22:46 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2019-02-12 12:04:46 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2017-12-25 23:44:35 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2021-07-01 18:41:30 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-02-21 14:31:40 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-07-01 18:41:30 +08:00
|
|
|
|
using osu.Game.Online;
|
|
|
|
|
using osu.Game.Online.API;
|
2019-06-13 15:57:19 +08:00
|
|
|
|
using osu.Game.Online.API.Requests;
|
2021-07-02 17:09:16 +08:00
|
|
|
|
using osu.Game.Overlays.BeatmapSet;
|
2022-01-28 12:53:48 +08:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2021-07-01 18:41:30 +08:00
|
|
|
|
using osu.Game.Screens.Select.Details;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-04-04 01:28:05 +08:00
|
|
|
|
namespace osu.Game.Screens.Select
|
2017-03-25 06:02:24 +08:00
|
|
|
|
{
|
2017-03-30 23:32:18 +08:00
|
|
|
|
public class BeatmapDetails : Container
|
2017-03-25 06:02:24 +08:00
|
|
|
|
{
|
2017-09-08 01:53:53 +08:00
|
|
|
|
private const float spacing = 10;
|
|
|
|
|
private const float transition_duration = 250;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
private readonly AdvancedStats advanced;
|
2021-10-25 13:44:49 +08:00
|
|
|
|
private readonly UserRatings ratingsDisplay;
|
2017-09-08 01:53:53 +08:00
|
|
|
|
private readonly MetadataSection description, source, tags;
|
|
|
|
|
private readonly Container failRetryContainer;
|
|
|
|
|
private readonly FailRetryGraph failRetryGraph;
|
2020-02-21 14:31:40 +08:00
|
|
|
|
private readonly LoadingLayer loading;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-14 21:14:00 +08:00
|
|
|
|
[Resolved]
|
2022-07-15 11:52:06 +08:00
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-07-15 11:52:06 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private SongSelect? songSelect { get; set; }
|
2022-07-15 11:41:49 +08:00
|
|
|
|
|
2022-07-15 11:52:06 +08:00
|
|
|
|
private IBeatmapInfo? beatmapInfo;
|
2019-02-27 20:07:17 +08:00
|
|
|
|
|
2022-07-15 11:52:06 +08:00
|
|
|
|
private APIFailTimes? failTimes;
|
2021-10-25 14:34:41 +08:00
|
|
|
|
|
2022-07-15 11:52:06 +08:00
|
|
|
|
private int[]? ratings;
|
2021-10-25 13:44:49 +08:00
|
|
|
|
|
2022-07-15 11:52:06 +08:00
|
|
|
|
public IBeatmapInfo? BeatmapInfo
|
2017-03-25 06:02:24 +08:00
|
|
|
|
{
|
2021-10-02 23:55:29 +08:00
|
|
|
|
get => beatmapInfo;
|
2017-03-25 06:02:24 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2021-10-02 23:55:29 +08:00
|
|
|
|
if (value == beatmapInfo) return;
|
2019-02-27 20:07:17 +08:00
|
|
|
|
|
2021-10-02 23:55:29 +08:00
|
|
|
|
beatmapInfo = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-11-01 14:42:12 +08:00
|
|
|
|
var onlineInfo = beatmapInfo as IBeatmapOnlineInfo;
|
2022-07-15 11:52:06 +08:00
|
|
|
|
var onlineSetInfo = beatmapInfo?.BeatmapSet as IBeatmapSetOnlineInfo;
|
2021-11-01 14:42:12 +08:00
|
|
|
|
|
|
|
|
|
failTimes = onlineInfo?.FailTimes;
|
|
|
|
|
ratings = onlineSetInfo?.Ratings;
|
2021-10-25 13:44:49 +08:00
|
|
|
|
|
2021-04-06 15:17:38 +08:00
|
|
|
|
Scheduler.AddOnce(updateStatistics);
|
2017-04-24 18:17:11 +08:00
|
|
|
|
}
|
2017-03-29 02:18:56 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-30 23:32:18 +08:00
|
|
|
|
public BeatmapDetails()
|
2017-03-25 06:02:24 +08:00
|
|
|
|
{
|
2017-03-26 06:33:03 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-03-25 06:02:24 +08:00
|
|
|
|
{
|
2017-03-26 06:33:03 +08:00
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-09-08 01:53:53 +08:00
|
|
|
|
Colour = Color4.Black.Opacity(0.5f),
|
2017-03-26 06:33:03 +08:00
|
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
|
new Container
|
2017-03-25 06:02:24 +08:00
|
|
|
|
{
|
2017-09-08 01:53:53 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Horizontal = spacing },
|
2017-03-30 23:32:18 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
new GridContainer
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
RowDimensions = new[]
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
new Dimension()
|
|
|
|
|
},
|
|
|
|
|
Content = new[]
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
new Drawable[]
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
new FillFlowContainer
|
2017-03-28 23:12:54 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Children = new Drawable[]
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
new FillFlowContainer
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-04-06 15:29:07 +08:00
|
|
|
|
Width = 0.5f,
|
|
|
|
|
Spacing = new Vector2(spacing),
|
|
|
|
|
Padding = new MarginPadding { Right = spacing / 2 },
|
|
|
|
|
Children = new[]
|
2021-04-06 15:17:38 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
new DetailBox().WithChild(advanced = new AdvancedStats
|
2021-04-06 15:17:38 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding { Horizontal = spacing, Top = spacing * 2, Bottom = spacing },
|
|
|
|
|
}),
|
|
|
|
|
new DetailBox().WithChild(new OnlineViewContainer(string.Empty)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 134,
|
|
|
|
|
Padding = new MarginPadding { Horizontal = spacing, Top = spacing },
|
2021-10-25 13:44:49 +08:00
|
|
|
|
Child = ratingsDisplay = new UserRatings
|
2021-04-06 15:29:07 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
},
|
2017-09-08 01:53:53 +08:00
|
|
|
|
},
|
2021-04-06 15:29:07 +08:00
|
|
|
|
new OsuScrollContainer
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0.5f,
|
|
|
|
|
ScrollbarVisible = false,
|
|
|
|
|
Padding = new MarginPadding { Left = spacing / 2 },
|
|
|
|
|
Child = new FillFlowContainer
|
2021-04-06 15:17:38 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
LayoutDuration = transition_duration,
|
|
|
|
|
LayoutEasing = Easing.OutQuad,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2022-07-15 11:41:49 +08:00
|
|
|
|
description = new MetadataSection(MetadataType.Description, searchOnSongSelect),
|
|
|
|
|
source = new MetadataSection(MetadataType.Source, searchOnSongSelect),
|
|
|
|
|
tags = new MetadataSection(MetadataType.Tags, searchOnSongSelect),
|
2021-04-06 15:29:07 +08:00
|
|
|
|
},
|
2021-04-06 15:17:38 +08:00
|
|
|
|
},
|
2017-09-08 01:53:53 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
2017-03-28 23:12:54 +08:00
|
|
|
|
},
|
2017-03-26 06:33:03 +08:00
|
|
|
|
},
|
2021-04-06 15:29:07 +08:00
|
|
|
|
new Drawable[]
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
failRetryContainer = new OnlineViewContainer("Sign in to view more details")
|
2017-04-12 16:52:24 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
2017-03-28 23:12:54 +08:00
|
|
|
|
{
|
2021-04-06 15:29:07 +08:00
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2022-01-28 12:53:48 +08:00
|
|
|
|
Text = BeatmapsetsStrings.ShowInfoPointsOfFailure,
|
2021-04-06 15:29:07 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
|
|
|
|
|
},
|
|
|
|
|
failRetryGraph = new FailRetryGraph
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Top = 14 + spacing / 2 },
|
|
|
|
|
},
|
2017-03-29 02:18:56 +08:00
|
|
|
|
},
|
2017-03-28 23:12:54 +08:00
|
|
|
|
},
|
2021-04-06 15:29:07 +08:00
|
|
|
|
}
|
2021-04-06 15:17:38 +08:00
|
|
|
|
}
|
2017-03-29 02:18:56 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
2017-06-12 15:40:53 +08:00
|
|
|
|
},
|
2021-04-06 16:09:51 +08:00
|
|
|
|
loading = new LoadingLayer(true)
|
2017-03-25 06:02:24 +08:00
|
|
|
|
};
|
2022-07-15 11:41:49 +08:00
|
|
|
|
|
|
|
|
|
void searchOnSongSelect(string text)
|
|
|
|
|
{
|
|
|
|
|
if (songSelect != null)
|
2022-07-15 17:01:35 +08:00
|
|
|
|
songSelect.FilterControl.CurrentTextSearch.Value = text;
|
2022-07-15 11:41:49 +08:00
|
|
|
|
}
|
2017-03-25 06:02:24 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
private void updateStatistics()
|
|
|
|
|
{
|
2021-10-02 23:55:29 +08:00
|
|
|
|
advanced.BeatmapInfo = BeatmapInfo;
|
2021-11-01 14:42:12 +08:00
|
|
|
|
description.Text = BeatmapInfo?.DifficultyName;
|
|
|
|
|
source.Text = BeatmapInfo?.Metadata.Source;
|
|
|
|
|
tags.Text = BeatmapInfo?.Metadata.Tags;
|
2019-03-08 17:44:35 +08:00
|
|
|
|
|
2021-10-29 16:58:46 +08:00
|
|
|
|
// failTimes may have been previously fetched
|
2021-10-25 14:34:41 +08:00
|
|
|
|
if (ratings != null && failTimes != null)
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2019-06-15 13:45:51 +08:00
|
|
|
|
updateMetrics();
|
2017-09-08 01:53:53 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-11-12 16:45:05 +08:00
|
|
|
|
// for now, let's early abort if an OnlineID is not present (should have been populated at import time).
|
2021-11-01 14:42:12 +08:00
|
|
|
|
if (BeatmapInfo == null || BeatmapInfo.OnlineID <= 0 || api.State.Value == APIState.Offline)
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2019-06-15 13:45:51 +08:00
|
|
|
|
updateMetrics();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-02 23:55:29 +08:00
|
|
|
|
var requestedBeatmap = BeatmapInfo;
|
2019-06-15 13:45:51 +08:00
|
|
|
|
|
|
|
|
|
var lookup = new GetBeatmapRequest(requestedBeatmap);
|
2019-06-13 16:10:09 +08:00
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
lookup.Success += res =>
|
|
|
|
|
{
|
|
|
|
|
Schedule(() =>
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2021-10-02 23:55:29 +08:00
|
|
|
|
if (beatmapInfo != requestedBeatmap)
|
2020-05-05 09:31:11 +08:00
|
|
|
|
// the beatmap has been changed since we started the lookup.
|
2017-09-08 01:53:53 +08:00
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-25 13:44:49 +08:00
|
|
|
|
ratings = res.BeatmapSet?.Ratings;
|
2021-10-25 14:34:41 +08:00
|
|
|
|
failTimes = res.FailTimes;
|
2019-06-13 15:57:19 +08:00
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
updateMetrics();
|
|
|
|
|
});
|
|
|
|
|
};
|
2019-06-13 16:10:09 +08:00
|
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
|
lookup.Failure += _ =>
|
2019-06-15 13:45:51 +08:00
|
|
|
|
{
|
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
2021-10-02 23:55:29 +08:00
|
|
|
|
if (beatmapInfo != requestedBeatmap)
|
2020-05-05 09:31:11 +08:00
|
|
|
|
// the beatmap has been changed since we started the lookup.
|
2019-06-15 13:45:51 +08:00
|
|
|
|
return;
|
2019-06-13 16:10:09 +08:00
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
updateMetrics();
|
|
|
|
|
});
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
api.Queue(lookup);
|
|
|
|
|
loading.Show();
|
2017-03-26 06:33:03 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
private void updateMetrics()
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
|
bool hasMetrics = (failTimes?.Retries?.Any() ?? false) || (failTimes?.Fails?.Any() ?? false);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-25 13:44:49 +08:00
|
|
|
|
if (ratings?.Any() ?? false)
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2021-10-25 13:44:49 +08:00
|
|
|
|
ratingsDisplay.Ratings = ratings;
|
|
|
|
|
ratingsDisplay.FadeIn(transition_duration);
|
2017-09-08 01:53:53 +08:00
|
|
|
|
}
|
2019-03-08 17:44:35 +08:00
|
|
|
|
else
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
// loading or just has no data server-side.
|
2021-10-25 13:44:49 +08:00
|
|
|
|
ratingsDisplay.Ratings = new int[10];
|
|
|
|
|
ratingsDisplay.FadeTo(0.25f, transition_duration);
|
2017-09-08 02:09:50 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-25 13:44:49 +08:00
|
|
|
|
if (hasMetrics)
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2021-10-25 14:34:41 +08:00
|
|
|
|
failRetryGraph.FailTimes = failTimes;
|
2017-09-08 01:53:53 +08:00
|
|
|
|
failRetryContainer.FadeIn(transition_duration);
|
|
|
|
|
}
|
2019-03-08 17:44:35 +08:00
|
|
|
|
else
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2021-10-25 14:34:41 +08:00
|
|
|
|
failRetryGraph.FailTimes = new APIFailTimes
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2017-09-08 01:53:53 +08:00
|
|
|
|
Fails = new int[100],
|
|
|
|
|
Retries = new int[100],
|
|
|
|
|
};
|
2017-03-26 06:33:03 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
loading.Hide();
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
private class DetailBox : Container
|
|
|
|
|
{
|
|
|
|
|
private readonly Container content;
|
|
|
|
|
protected override Container<Drawable> Content => content;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
public DetailBox()
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2017-04-10 22:42:23 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2017-09-08 01:53:53 +08:00
|
|
|
|
new Box
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-09-08 01:53:53 +08:00
|
|
|
|
Colour = Color4.Black.Opacity(0.5f),
|
2017-03-26 06:33:03 +08:00
|
|
|
|
},
|
2017-09-08 01:53:53 +08:00
|
|
|
|
content = new Container
|
2017-03-26 06:33:03 +08:00
|
|
|
|
{
|
2017-09-08 01:53:53 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-03-26 06:33:03 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-03-25 06:02:24 +08:00
|
|
|
|
}
|
2020-01-30 12:30:25 +08:00
|
|
|
|
}
|
2017-04-24 17:34:27 +08:00
|
|
|
|
}
|