Split UnderscoredLinkContainer in different classes

This commit is contained in:
EVAST9919
2019-05-29 20:24:01 +03:00
parent 52fad723a2
commit 6efa61b992
4 changed files with 62 additions and 18 deletions

View File

@ -30,8 +30,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
private const int corner_radius = 10; private const int corner_radius = 10;
private readonly SpriteIcon icon; private readonly SpriteIcon icon;
private readonly OsuSpriteText playCountText; private readonly OsuSpriteText playCountText;
private readonly UnderscoredLinkContainer mapper; private readonly UnderscoredUserLink mapper;
private readonly UnderscoredLinkContainer beatmapName;
public DrawableMostPlayedBeatmap(BeatmapInfo beatmap, int playCount) public DrawableMostPlayedBeatmap(BeatmapInfo beatmap, int playCount)
{ {
@ -76,7 +75,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
Padding = new MarginPadding { Left = 15, Right = 20 }, Padding = new MarginPadding { Left = 15, Right = 20 },
Children = new Drawable[] Children = new Drawable[]
{ {
beatmapName = new UnderscoredLinkContainer new UnderscoredBeatmapLink(beatmap)
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
@ -111,7 +110,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
Text = "mapped by ", Text = "mapped by ",
Font = OsuFont.GetFont(size: 15, weight: FontWeight.Regular), Font = OsuFont.GetFont(size: 15, weight: FontWeight.Regular),
}, },
mapper = new UnderscoredLinkContainer mapper = new UnderscoredUserLink(beatmap.Metadata.Author.Id)
{ {
Text = new OsuSpriteText[] Text = new OsuSpriteText[]
{ {
@ -157,22 +156,13 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
}; };
} }
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader]
private void load(OsuColour colors, UserProfileOverlay userProfileOverlay, BeatmapSetOverlay beatmapSetOverlay) private void load(OsuColour colors)
{ {
idleBackgroundColour = background.Colour = colors.GreySeafoam; idleBackgroundColour = background.Colour = colors.GreySeafoam;
hoveredBackgroundColour = colors.GreySeafoamLight; hoveredBackgroundColour = colors.GreySeafoamLight;
mapperText.Colour = mapper.Colour = colors.GreySeafoamLighter; mapperText.Colour = mapper.Colour = colors.GreySeafoamLighter;
icon.Colour = playCountText.Colour = colors.Yellow; icon.Colour = playCountText.Colour = colors.Yellow;
mapper.ClickAction = () => userProfileOverlay.ShowUser(beatmap.Metadata.Author.Id);
beatmapName.ClickAction = () =>
{
if (beatmap.OnlineBeatmapID != null)
beatmapSetOverlay?.FetchAndShowBeatmap(beatmap.OnlineBeatmapID.Value);
else if (beatmap.BeatmapSet?.OnlineBeatmapSetID != null)
beatmapSetOverlay?.FetchAndShowBeatmapSet(beatmap.BeatmapSet.OnlineBeatmapSetID.Value);
};
} }
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)

View File

@ -0,0 +1,30 @@
// 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.Framework.Allocation;
using osu.Game.Beatmaps;
namespace osu.Game.Overlays.Profile.Sections
{
public class UnderscoredBeatmapLink : UnderscoredLinkContainer
{
private readonly BeatmapInfo beatmap;
public UnderscoredBeatmapLink(BeatmapInfo beatmap)
{
this.beatmap = beatmap;
}
[BackgroundDependencyLoader(true)]
private void load(BeatmapSetOverlay beatmapSetOverlay)
{
ClickAction = () =>
{
if (beatmap.OnlineBeatmapID != null)
beatmapSetOverlay?.FetchAndShowBeatmap(beatmap.OnlineBeatmapID.Value);
else if (beatmap.BeatmapSet?.OnlineBeatmapSetID != null)
beatmapSetOverlay?.FetchAndShowBeatmapSet(beatmap.BeatmapSet.OnlineBeatmapSetID.Value);
};
}
}
}

View File

@ -11,13 +11,14 @@ using System.Collections.Generic;
namespace osu.Game.Overlays.Profile.Sections namespace osu.Game.Overlays.Profile.Sections
{ {
public class UnderscoredLinkContainer : Container public abstract class UnderscoredLinkContainer : Container
{ {
private const int duration = 200; private const int duration = 200;
public Action ClickAction;
private readonly Container underscore; private readonly Container underscore;
private readonly FillFlowContainer<OsuSpriteText> textContent; private readonly FillFlowContainer<OsuSpriteText> textContent;
protected Action ClickAction;
public IReadOnlyList<OsuSpriteText> Text public IReadOnlyList<OsuSpriteText> Text
{ {
get => textContent.Children; get => textContent.Children;
@ -28,7 +29,7 @@ namespace osu.Game.Overlays.Profile.Sections
} }
} }
public UnderscoredLinkContainer() protected UnderscoredLinkContainer()
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Child = new Container Child = new Container

View File

@ -0,0 +1,23 @@
// 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.Framework.Allocation;
namespace osu.Game.Overlays.Profile.Sections
{
public class UnderscoredUserLink : UnderscoredLinkContainer
{
private readonly long userId;
public UnderscoredUserLink(long userId)
{
this.userId = userId;
}
[BackgroundDependencyLoader(true)]
private void load(UserProfileOverlay userProfileOverlay)
{
ClickAction = () => userProfileOverlay?.ShowUser(userId);
}
}
}