mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:17:23 +08:00
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
This commit is contained in:
parent
f5f287bed5
commit
1f1c7dd70f
44
osu.Game/Graphics/Containers/OsuLinkTextFlowContainer.cs
Normal file
44
osu.Game/Graphics/Containers/OsuLinkTextFlowContainer.cs
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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<OsuLinkSpriteText>
|
||||
{
|
||||
public OsuLinkTextFlowContainer(Action<SpriteText> defaultCreationParameters = null)
|
||||
: base(defaultCreationParameters)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class OsuLinkTextFlowContainer<T> : OsuTextFlowContainer
|
||||
where T : OsuLinkSpriteText, new()
|
||||
{
|
||||
public override bool HandleInput => true;
|
||||
|
||||
public OsuLinkTextFlowContainer(Action<SpriteText> defaultCreationParameters = null) : base(defaultCreationParameters)
|
||||
{
|
||||
}
|
||||
|
||||
protected override SpriteText CreateSpriteText() => new T();
|
||||
|
||||
public void AddLink(string text, string url, Action<SpriteText> creationParameters = null)
|
||||
{
|
||||
AddText(text, link =>
|
||||
{
|
||||
((T)link).Url = url;
|
||||
creationParameters?.Invoke(link);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -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<SpriteText> scoreText, scoreNumberText;
|
||||
|
||||
private readonly Container coverContainer, chartContainer, supporterTag;
|
||||
@ -119,7 +119,7 @@ namespace osu.Game.Overlays.Profile
|
||||
}
|
||||
}
|
||||
},
|
||||
new LinkFlowContainer.ProfileLink(user)
|
||||
new ProfileLink(user)
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
@ -160,7 +160,7 @@ namespace osu.Game.Overlays.Profile
|
||||
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 @@ namespace osu.Game.Overlays.Profile
|
||||
}
|
||||
}
|
||||
|
||||
private class LinkFlowContainer : OsuTextFlowContainer
|
||||
private class ProfileLink : OsuLinkSpriteText, IHasTooltip
|
||||
{
|
||||
public override bool HandleInput => true;
|
||||
public string TooltipText => "View Profile in Browser";
|
||||
|
||||
public LinkFlowContainer(Action<SpriteText> 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<Drawable> Content => content ?? (Container<Drawable>)this;
|
||||
|
||||
protected override IEnumerable<Drawable> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user