1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 04:02:59 +08:00

show guest diff author in BeatmapPicker

This commit is contained in:
cdwcgt 2023-04-02 22:25:58 +09:00
parent 327e284db2
commit 2cf8636366
No known key found for this signature in database
GPG Key ID: 144396D01095C3A2
2 changed files with 101 additions and 2 deletions

View File

@ -14,6 +14,7 @@ using System.Collections.Generic;
using System.Linq;
using osu.Framework.Testing;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
@ -26,7 +27,7 @@ using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
namespace osu.Game.Tests.Visual.Online
{
public partial class TestSceneBeatmapSetOverlay : OsuTestScene
public partial class TestSceneBeatmapSetOverlay : OsuManualInputManagerTestScene
{
private readonly TestBeatmapSetOverlay overlay;
@ -281,6 +282,22 @@ namespace osu.Game.Tests.Visual.Online
AddAssert(@"type is correct", () => type == lookupType.ToString());
}
[Test]
public void TestBeatmapSetWithGuestDIff()
{
AddStep("show map", () => overlay.ShowBeatmapSet(createBeatmapSetWithGuestDiff()));
AddStep("Move mouse to host diff", () =>
{
InputManager.MoveMouseTo(overlay.ChildrenOfType<DifficultyIcon>().ElementAt(0));
});
AddAssert("Guset mapper information not show", () => !overlay.ChildrenOfType<BeatmapPicker>().Single().ChildrenOfType<LinkFlowContainer>().Any());
AddStep("move mouse to guest diff", () =>
{
InputManager.MoveMouseTo(overlay.ChildrenOfType<DifficultyIcon>().ElementAt(1));
});
AddAssert("Guset mapper information show", () => overlay.ChildrenOfType<BeatmapPicker>().Single().ChildrenOfType<LinkFlowContainer>().Any());
}
private APIBeatmapSet createManyDifficultiesBeatmapSet()
{
var set = getBeatmapSet();
@ -320,6 +337,60 @@ namespace osu.Game.Tests.Visual.Online
return beatmapSet;
}
private APIBeatmapSet createBeatmapSetWithGuestDiff()
{
var set = getBeatmapSet();
var beatmaps = new List<APIBeatmap>();
var guestUser = new APIUser
{
Username = @"BanchoBot",
Id = 3,
};
set.RelatedUsers = new[]
{
set.Author, guestUser
};
beatmaps.Add(new APIBeatmap
{
OnlineID = 1145,
DifficultyName = "Host Diff",
RulesetID = Ruleset.Value.OnlineID,
StarRating = 1.4,
OverallDifficulty = 3.5f,
AuthorID = set.AuthorID,
FailTimes = new APIFailTimes
{
Fails = Enumerable.Range(1, 100).Select(j => j % 12 - 6).ToArray(),
Retries = Enumerable.Range(-2, 100).Select(j => j % 12 - 6).ToArray(),
},
Status = BeatmapOnlineStatus.Graveyard
});
beatmaps.Add(new APIBeatmap
{
OnlineID = 1919,
DifficultyName = "Guest Diff",
RulesetID = Ruleset.Value.OnlineID,
StarRating = 8.1,
OverallDifficulty = 3.5f,
AuthorID = 3,
FailTimes = new APIFailTimes
{
Fails = Enumerable.Range(1, 100).Select(j => j % 12 - 6).ToArray(),
Retries = Enumerable.Range(-2, 100).Select(j => j % 12 - 6).ToArray(),
},
Status = BeatmapOnlineStatus.Graveyard
});
set.Beatmaps = beatmaps.ToArray();
return set;
}
private void downloadAssert(bool shown)
{
AddAssert($"is download button {(shown ? "shown" : "hidden")}", () => overlay.Header.HeaderContent.DownloadButtonsVisible == shown);

View File

@ -31,6 +31,7 @@ namespace osu.Game.Overlays.BeatmapSet
private const float tile_spacing = 2;
private readonly OsuSpriteText version, starRating, starRatingText;
public readonly FillFlowContainer GuestMapperContainer;
private readonly FillFlowContainer starRatingContainer;
private readonly Statistic plays, favourites;
@ -88,6 +89,12 @@ namespace osu.Game.Overlays.BeatmapSet
Origin = Anchor.BottomLeft,
Font = OsuFont.GetFont(size: 17, weight: FontWeight.Bold)
},
GuestMapperContainer = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
},
starRatingContainer = new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
@ -198,11 +205,32 @@ namespace osu.Game.Overlays.BeatmapSet
updateDifficultyButtons();
}
private void showBeatmap(IBeatmapInfo? beatmapInfo)
private void showBeatmap(APIBeatmap? beatmapInfo)
{
GuestMapperContainer.Clear();
if (beatmapInfo != null && beatmapSet?.Author.OnlineID != beatmapInfo.AuthorID)
{
if (BeatmapSet?.RelatedUsers?.Single(u => u.OnlineID == beatmapInfo.AuthorID) is APIUser user)
GuestMapperContainer.Child = getGueatMapper(user);
}
version.Text = beatmapInfo?.DifficultyName ?? string.Empty;
}
private Drawable getGueatMapper(APIUser user)
{
return new LinkFlowContainer(s =>
{
s.Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 15);
}).With(d =>
{
d.AutoSizeAxes = Axes.Both;
d.AddText("mapped by ");
d.AddUserLink(user);
});
}
private void updateDifficultyButtons()
{
Difficulties.Children.ToList().ForEach(diff => diff.State = diff.Beatmap == Beatmap.Value ? DifficultySelectorState.Selected : DifficultySelectorState.NotSelected);