mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:27:29 +08:00
Merge pull request #22055 from Joehuu/beatmap-info-nominators
Display nominators on beatmap set overlay
This commit is contained in:
commit
74b11cc8f1
22
osu.Game/Beatmaps/BeatmapSetOnlineNomination.cs
Normal file
22
osu.Game/Beatmaps/BeatmapSetOnlineNomination.cs
Normal 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 Newtonsoft.Json;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
public struct BeatmapSetOnlineNomination
|
||||
{
|
||||
[JsonProperty(@"beatmapset_id")]
|
||||
public int BeatmapsetId { get; set; }
|
||||
|
||||
[JsonProperty(@"reset")]
|
||||
public bool Reset { get; set; }
|
||||
|
||||
[JsonProperty(@"rulesets")]
|
||||
public string[]? Rulesets { get; set; }
|
||||
|
||||
[JsonProperty(@"user_id")]
|
||||
public int UserId { get; set; }
|
||||
}
|
||||
}
|
@ -111,6 +111,12 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
[JsonProperty(@"language")]
|
||||
public BeatmapSetOnlineLanguage Language { get; set; }
|
||||
|
||||
[JsonProperty(@"current_nominations")]
|
||||
public BeatmapSetOnlineNomination[]? CurrentNominations { get; set; }
|
||||
|
||||
[JsonProperty(@"related_users")]
|
||||
public APIUser[]? RelatedUsers { get; set; }
|
||||
|
||||
public string Source { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty(@"tags")]
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
@ -36,6 +37,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
|
||||
public Info()
|
||||
{
|
||||
MetadataSectionNominators nominators;
|
||||
MetadataSection source, tags;
|
||||
MetadataSectionGenre genre;
|
||||
MetadataSectionLanguage language;
|
||||
@ -82,6 +84,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
Direction = FillDirection.Full,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
nominators = new MetadataSectionNominators(),
|
||||
source = new MetadataSectionSource(),
|
||||
genre = new MetadataSectionGenre { Width = 0.5f },
|
||||
language = new MetadataSectionLanguage { Width = 0.5f },
|
||||
@ -122,6 +125,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
|
||||
BeatmapSet.ValueChanged += b =>
|
||||
{
|
||||
nominators.Metadata = (b.NewValue?.CurrentNominations ?? Array.Empty<BeatmapSetOnlineNomination>(), b.NewValue?.RelatedUsers ?? Array.Empty<APIUser>());
|
||||
source.Metadata = b.NewValue?.Source ?? string.Empty;
|
||||
tags.Metadata = b.NewValue?.Tags ?? string.Empty;
|
||||
genre.Metadata = b.NewValue?.Genre ?? new BeatmapSetOnlineGenre { Id = (int)SearchGenre.Unspecified };
|
||||
|
63
osu.Game/Overlays/BeatmapSet/MetadataSectionNominators.cs
Normal file
63
osu.Game/Overlays/BeatmapSet/MetadataSectionNominators.cs
Normal file
@ -0,0 +1,63 @@
|
||||
// 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.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Resources.Localisation.Web;
|
||||
|
||||
namespace osu.Game.Overlays.BeatmapSet
|
||||
{
|
||||
public partial class MetadataSectionNominators : MetadataSection<(BeatmapSetOnlineNomination[] CurrentNominations, APIUser[] RelatedUsers)>
|
||||
{
|
||||
public override (BeatmapSetOnlineNomination[] CurrentNominations, APIUser[] RelatedUsers) Metadata
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value.CurrentNominations.Length == 0)
|
||||
{
|
||||
this.FadeOut(TRANSITION_DURATION);
|
||||
return;
|
||||
}
|
||||
|
||||
base.Metadata = value;
|
||||
}
|
||||
}
|
||||
|
||||
public MetadataSectionNominators(Action<(BeatmapSetOnlineNomination[] CurrentNominations, APIUser[] RelatedUsers)>? searchAction = null)
|
||||
: base(MetadataType.Nominators, searchAction)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void AddMetadata((BeatmapSetOnlineNomination[] CurrentNominations, APIUser[] RelatedUsers) metadata, LinkFlowContainer loaded)
|
||||
{
|
||||
int[] nominatorIds = metadata.CurrentNominations.Select(n => n.UserId).ToArray();
|
||||
|
||||
int nominatorsFound = 0;
|
||||
|
||||
foreach (int nominatorId in nominatorIds)
|
||||
{
|
||||
foreach (var user in metadata.RelatedUsers)
|
||||
{
|
||||
if (nominatorId != user.OnlineID) continue;
|
||||
|
||||
nominatorsFound++;
|
||||
|
||||
loaded.AddUserLink(new APIUser
|
||||
{
|
||||
Username = user.Username,
|
||||
Id = nominatorId,
|
||||
});
|
||||
|
||||
if (nominatorsFound < nominatorIds.Length)
|
||||
loaded.AddText(CommonStrings.ArrayAndWordsConnector);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -23,6 +23,9 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
Genre,
|
||||
|
||||
[LocalisableDescription(typeof(BeatmapsetsStrings), nameof(BeatmapsetsStrings.ShowInfoLanguage))]
|
||||
Language
|
||||
Language,
|
||||
|
||||
[LocalisableDescription(typeof(BeatmapsetsStrings), nameof(BeatmapsetsStrings.ShowInfoNominators))]
|
||||
Nominators,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user