From 1f1c7dd70fb12bf2b2d80bb8956d4a9935f08537 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Fri, 1 Dec 2017 20:26:51 +0100 Subject: [PATCH] Moved LinkFlowContainer out of ProfileHeader to make it available for other uses too (e.g. chat) and renamed it to LinkTextFlowContainer bc it can contain both links and text, not only one --- .../Containers/OsuLinkTextFlowContainer.cs | 44 +++++++++++++ osu.Game/Overlays/Profile/ProfileHeader.cs | 61 +++---------------- 2 files changed, 54 insertions(+), 51 deletions(-) create mode 100644 osu.Game/Graphics/Containers/OsuLinkTextFlowContainer.cs diff --git a/osu.Game/Graphics/Containers/OsuLinkTextFlowContainer.cs b/osu.Game/Graphics/Containers/OsuLinkTextFlowContainer.cs new file mode 100644 index 0000000000..b5490d42f9 --- /dev/null +++ b/osu.Game/Graphics/Containers/OsuLinkTextFlowContainer.cs @@ -0,0 +1,44 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input; +using osu.Game.Graphics.Sprites; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Graphics.Containers +{ + public class OsuLinkTextFlowContainer : OsuLinkTextFlowContainer + { + public OsuLinkTextFlowContainer(Action defaultCreationParameters = null) + : base(defaultCreationParameters) + { + } + } + + public class OsuLinkTextFlowContainer : OsuTextFlowContainer + where T : OsuLinkSpriteText, new() + { + public override bool HandleInput => true; + + public OsuLinkTextFlowContainer(Action defaultCreationParameters = null) : base(defaultCreationParameters) + { + } + + protected override SpriteText CreateSpriteText() => new T(); + + public void AddLink(string text, string url, Action creationParameters = null) + { + AddText(text, link => + { + ((T)link).Url = url; + creationParameters?.Invoke(link); + }); + } + } +} diff --git a/osu.Game/Overlays/Profile/ProfileHeader.cs b/osu.Game/Overlays/Profile/ProfileHeader.cs index c7bc5c1d93..af3e97db27 100644 --- a/osu.Game/Overlays/Profile/ProfileHeader.cs +++ b/osu.Game/Overlays/Profile/ProfileHeader.cs @@ -25,7 +25,7 @@ namespace osu.Game.Overlays.Profile public class ProfileHeader : Container { private readonly OsuTextFlowContainer infoTextLeft; - private readonly LinkFlowContainer infoTextRight; + private readonly OsuLinkTextFlowContainer infoTextRight; private readonly FillFlowContainer scoreText, scoreNumberText; private readonly Container coverContainer, chartContainer, supporterTag; @@ -119,7 +119,7 @@ public ProfileHeader(User user) } } }, - new LinkFlowContainer.ProfileLink(user) + new ProfileLink(user) { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, @@ -160,7 +160,7 @@ public ProfileHeader(User user) ParagraphSpacing = 0.8f, LineSpacing = 0.2f }, - infoTextRight = new LinkFlowContainer(t => + infoTextRight = new OsuLinkTextFlowContainer(t => { t.TextSize = 14; t.Font = @"Exo2.0-RegularItalic"; @@ -488,57 +488,16 @@ private void load(TextureStore textures) } } - private class LinkFlowContainer : OsuTextFlowContainer + private class ProfileLink : OsuLinkSpriteText, IHasTooltip { - public override bool HandleInput => true; + public string TooltipText => "View Profile in Browser"; - public LinkFlowContainer(Action defaultCreationParameters = null) : base(defaultCreationParameters) + public ProfileLink(User user) { - } - - protected override SpriteText CreateSpriteText() => new LinkText(); - - public void AddLink(string text, string url) => AddText(text, link => ((LinkText)link).Url = url); - - public class LinkText : OsuSpriteText - { - private readonly OsuHoverContainer content; - - public override bool HandleInput => content.Action != null; - - protected override Container Content => content ?? (Container)this; - - protected override IEnumerable FlowingChildren => Children; - - public string Url - { - set - { - if(value != null) - content.Action = () => Process.Start(value); - } - } - - public LinkText() - { - AddInternal(content = new OsuHoverContainer - { - AutoSizeAxes = Axes.Both, - }); - } - } - - public class ProfileLink : LinkText, IHasTooltip - { - public string TooltipText => "View Profile in Browser"; - - public ProfileLink(User user) - { - Text = user.Username; - Url = $@"https://osu.ppy.sh/users/{user.Id}"; - Font = @"Exo2.0-RegularItalic"; - TextSize = 30; - } + Text = user.Username; + Url = $@"https://osu.ppy.sh/users/{user.Id}"; + Font = @"Exo2.0-RegularItalic"; + TextSize = 30; } } }