From 6efa61b992a44cf4c3004ca9dc284da8952c90ba Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Wed, 29 May 2019 20:24:01 +0300 Subject: [PATCH] Split UnderscoredLinkContainer in different classes --- .../Historical/DrawableMostPlayedBeatmap.cs | 20 ++++--------- .../Sections/UnderscoredBeatmapLink.cs | 30 +++++++++++++++++++ .../Sections/UnderscoredLinkContainer.cs | 7 +++-- .../Profile/Sections/UnderscoredUserLink.cs | 23 ++++++++++++++ 4 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 osu.Game/Overlays/Profile/Sections/UnderscoredBeatmapLink.cs create mode 100644 osu.Game/Overlays/Profile/Sections/UnderscoredUserLink.cs diff --git a/osu.Game/Overlays/Profile/Sections/Historical/DrawableMostPlayedBeatmap.cs b/osu.Game/Overlays/Profile/Sections/Historical/DrawableMostPlayedBeatmap.cs index e8ce11555f..50f419e07c 100644 --- a/osu.Game/Overlays/Profile/Sections/Historical/DrawableMostPlayedBeatmap.cs +++ b/osu.Game/Overlays/Profile/Sections/Historical/DrawableMostPlayedBeatmap.cs @@ -30,8 +30,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical private const int corner_radius = 10; private readonly SpriteIcon icon; private readonly OsuSpriteText playCountText; - private readonly UnderscoredLinkContainer mapper; - private readonly UnderscoredLinkContainer beatmapName; + private readonly UnderscoredUserLink mapper; public DrawableMostPlayedBeatmap(BeatmapInfo beatmap, int playCount) { @@ -76,7 +75,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical Padding = new MarginPadding { Left = 15, Right = 20 }, Children = new Drawable[] { - beatmapName = new UnderscoredLinkContainer + new UnderscoredBeatmapLink(beatmap) { Anchor = Anchor.CentreLeft, Origin = Anchor.BottomLeft, @@ -111,7 +110,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical Text = "mapped by ", Font = OsuFont.GetFont(size: 15, weight: FontWeight.Regular), }, - mapper = new UnderscoredLinkContainer + mapper = new UnderscoredUserLink(beatmap.Metadata.Author.Id) { Text = new OsuSpriteText[] { @@ -157,22 +156,13 @@ namespace osu.Game.Overlays.Profile.Sections.Historical }; } - [BackgroundDependencyLoader(permitNulls: true)] - private void load(OsuColour colors, UserProfileOverlay userProfileOverlay, BeatmapSetOverlay beatmapSetOverlay) + [BackgroundDependencyLoader] + private void load(OsuColour colors) { idleBackgroundColour = background.Colour = colors.GreySeafoam; hoveredBackgroundColour = colors.GreySeafoamLight; mapperText.Colour = mapper.Colour = colors.GreySeafoamLighter; 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) diff --git a/osu.Game/Overlays/Profile/Sections/UnderscoredBeatmapLink.cs b/osu.Game/Overlays/Profile/Sections/UnderscoredBeatmapLink.cs new file mode 100644 index 0000000000..370d6d84ef --- /dev/null +++ b/osu.Game/Overlays/Profile/Sections/UnderscoredBeatmapLink.cs @@ -0,0 +1,30 @@ +// Copyright (c) ppy Pty Ltd . 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); + }; + } + } +} diff --git a/osu.Game/Overlays/Profile/Sections/UnderscoredLinkContainer.cs b/osu.Game/Overlays/Profile/Sections/UnderscoredLinkContainer.cs index 087bd03837..8daf0bd24d 100644 --- a/osu.Game/Overlays/Profile/Sections/UnderscoredLinkContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/UnderscoredLinkContainer.cs @@ -11,13 +11,14 @@ using System.Collections.Generic; namespace osu.Game.Overlays.Profile.Sections { - public class UnderscoredLinkContainer : Container + public abstract class UnderscoredLinkContainer : Container { private const int duration = 200; - public Action ClickAction; private readonly Container underscore; private readonly FillFlowContainer textContent; + protected Action ClickAction; + public IReadOnlyList Text { get => textContent.Children; @@ -28,7 +29,7 @@ namespace osu.Game.Overlays.Profile.Sections } } - public UnderscoredLinkContainer() + protected UnderscoredLinkContainer() { AutoSizeAxes = Axes.Both; Child = new Container diff --git a/osu.Game/Overlays/Profile/Sections/UnderscoredUserLink.cs b/osu.Game/Overlays/Profile/Sections/UnderscoredUserLink.cs new file mode 100644 index 0000000000..f50bc7f7ba --- /dev/null +++ b/osu.Game/Overlays/Profile/Sections/UnderscoredUserLink.cs @@ -0,0 +1,23 @@ +// Copyright (c) ppy Pty Ltd . 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); + } + } +}