1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +08:00

Workaround single-frame layout issues with {Link|Text|Fill}FlowContainers

This commit is contained in:
Joseph Madamba 2024-08-12 23:31:00 -07:00
parent 625c6fc7eb
commit 2b41f71fd0
2 changed files with 33 additions and 6 deletions

View File

@ -69,7 +69,7 @@ namespace osu.Game.Tests.Visual.SongSelectV2
public void TestLocalBeatmap()
{
AddAssert("difficulty name is not set", () => LocalisableString.IsNullOrEmpty(difficultyNameContent.ChildrenOfType<TruncatingSpriteText>().Single().Text));
AddAssert("author is not set", () => !difficultyNameContent.ChildrenOfType<LinkFlowContainer>().Single().ChildrenOfType<OsuSpriteText>().Any());
AddAssert("author is not set", () => LocalisableString.IsNullOrEmpty(difficultyNameContent.ChildrenOfType<OsuHoverContainer>().Single().ChildrenOfType<OsuSpriteText>().Single().Text));
AddStep("set beatmap", () => Beatmap.Value = CreateWorkingBeatmap(new Beatmap
{
@ -85,7 +85,7 @@ namespace osu.Game.Tests.Visual.SongSelectV2
}));
AddAssert("difficulty name is set", () => !LocalisableString.IsNullOrEmpty(difficultyNameContent.ChildrenOfType<TruncatingSpriteText>().Single().Text));
AddAssert("author is set", () => difficultyNameContent.ChildrenOfType<LinkFlowContainer>().Single().ChildrenOfType<OsuSpriteText>().Any());
AddAssert("author is set", () => !LocalisableString.IsNullOrEmpty(difficultyNameContent.ChildrenOfType<OsuHoverContainer>().Single().ChildrenOfType<OsuSpriteText>().Single().Text));
}
[Test]

View File

@ -10,6 +10,10 @@ using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Localisation;
using osu.Game.Online;
using osu.Game.Online.Chat;
using osu.Game.Overlays;
namespace osu.Game.Screens.SelectV2.Wedge
{
@ -17,11 +21,15 @@ namespace osu.Game.Screens.SelectV2.Wedge
{
private OsuSpriteText difficultyName = null!;
private OsuSpriteText mappedByLabel = null!;
private LinkFlowContainer mapperName = null!;
private OsuHoverContainer mapperLink = null!;
private OsuSpriteText mapperName = null!;
[Resolved]
private IBindable<IBeatmapInfo?> beatmapInfo { get; set; } = null!;
[Resolved]
private ILinkHandler? linkHandler { get; set; }
public DifficultyNameContent()
{
RelativeSizeAxes = Axes.X;
@ -52,11 +60,15 @@ namespace osu.Game.Screens.SelectV2.Wedge
Text = " mapped by ",
Font = OsuFont.GetFont(size: 14),
},
mapperName = new LinkFlowContainer(t => t.Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 14))
mapperLink = new MapperLink
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
AutoSizeAxes = Axes.Both,
Child = mapperName = new OsuSpriteText
{
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 14),
}
},
}
};
@ -75,13 +87,14 @@ namespace osu.Game.Screens.SelectV2.Wedge
private void updateMapper()
{
mapperName.Clear();
mapperName.Text = string.Empty;
switch (beatmapInfo.Value)
{
case BeatmapInfo localBeatmap:
// TODO: should be the mapper of the guest difficulty, but that isn't stored correctly yet (see https://github.com/ppy/osu/issues/12965)
mapperName.AddUserLink(localBeatmap.Metadata.Author);
mapperName.Text = localBeatmap.Metadata.Author.Username;
mapperLink.Action = () => linkHandler?.HandleLink(new LinkDetails(LinkAction.OpenUserProfile, localBeatmap.Metadata.Author));
break;
}
}
@ -94,5 +107,19 @@ namespace osu.Game.Screens.SelectV2.Wedge
difficultyName.MaxWidth = Math.Max(DrawWidth - mappedByLabel.DrawWidth
- mapperName.DrawWidth, 0);
}
/// <summary>
/// This class is a workaround for the single-frame layout issues with `{Link|Text|Fill}FlowContainer`s.
/// See https://github.com/ppy/osu-framework/issues/3369.
/// </summary>
private partial class MapperLink : OsuHoverContainer
{
[BackgroundDependencyLoader]
private void load(OverlayColourProvider? overlayColourProvider, OsuColour colours)
{
TooltipText = ContextMenuStrings.ViewProfile;
IdleColour = overlayColourProvider?.Light2 ?? colours.Blue;
}
}
}
}