1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 23:59:16 +08:00

Removed LinkId and word wrapping (for now).

Also reimplemented the OsuHoverContainer properly
This commit is contained in:
FreezyLemon 2017-12-25 20:46:04 +01:00
parent 025d3941a2
commit 962e4d7c8a
5 changed files with 26 additions and 97 deletions

View File

@ -11,6 +11,7 @@ namespace osu.Game.Graphics.Containers
public class OsuHoverContainer : OsuClickableContainer public class OsuHoverContainer : OsuClickableContainer
{ {
private Color4 hoverColour; private Color4 hoverColour;
private Color4 unhoverColour;
protected override bool OnHover(InputState state) protected override bool OnHover(InputState state)
{ {
@ -20,7 +21,7 @@ namespace osu.Game.Graphics.Containers
protected override void OnHoverLost(InputState state) protected override void OnHoverLost(InputState state)
{ {
this.FadeColour(Color4.White, 500, Easing.OutQuint); this.FadeColour(unhoverColour, 500, Easing.OutQuint);
base.OnHoverLost(state); base.OnHoverLost(state);
} }
@ -28,6 +29,7 @@ namespace osu.Game.Graphics.Containers
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
hoverColour = colours.Yellow; hoverColour = colours.Yellow;
unhoverColour = Colour;
} }
} }
} }

View File

@ -36,6 +36,9 @@ namespace osu.Game.Graphics.Containers
public void AddLink(string text, string url, Action<SpriteText> creationParameters = null) public void AddLink(string text, string url, Action<SpriteText> creationParameters = null)
{ {
// TODO: Remove this and get word wrapping working
text = text.Replace(' ', '_');
AddText(text, link => AddText(text, link =>
{ {
creationParameters?.Invoke(link); creationParameters?.Invoke(link);

View File

@ -21,23 +21,18 @@ namespace osu.Game.Graphics.Sprites
public OsuLinkSpriteText() public OsuLinkSpriteText()
{ {
AddInternal(content = new OsuHoverContainer { AutoSizeAxes = Axes.Both }); AddInternal(content = new OsuHoverContainer
} {
AutoSizeAxes = Axes.Both,
protected override bool OnClick(InputState state) Action = OnLinkClicked,
{ });
OnLinkClicked();
return true;
} }
private string url; private string url;
public string Url public string Url
{ {
get get => url;
{
return url;
}
set set
{ {
if (!string.IsNullOrEmpty(value)) if (!string.IsNullOrEmpty(value))
@ -47,8 +42,8 @@ namespace osu.Game.Graphics.Sprites
public ColourInfo TextColour public ColourInfo TextColour
{ {
get { return Content.Colour; } get => Content.Colour;
set { Content.Colour = value; } set => Content.Colour = value;
} }
protected virtual void OnLinkClicked() => Process.Start(Url); protected virtual void OnLinkClicked() => Process.Start(Url);

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API; using osu.Game.Online.API;
@ -22,33 +23,11 @@ namespace osu.Game.Online.Chat
{ {
public class ChatLink : OsuLinkSpriteText, IHasTooltip public class ChatLink : OsuLinkSpriteText, IHasTooltip
{ {
/// <summary>
/// Identifier unique to every link in a message.
/// <para>A value of -1 means that this <see cref="ChatLink"/> instance does not contain a link.</para>
/// </summary>
public int LinkId = -1;
private APIAccess api; private APIAccess api;
private BeatmapSetOverlay beatmapSetOverlay; private BeatmapSetOverlay beatmapSetOverlay;
private ChatOverlay chat; private ChatOverlay chat;
private Color4 hoverColour; public override bool HandleInput => !string.IsNullOrEmpty(Url);
private Color4 urlColour;
private readonly HoverClickSounds hoverClickSounds;
/// <summary>
/// Every other sprite in the containing ChatLine that represents the same link.
/// </summary>
protected IEnumerable<ChatLink> SameLinkSprites { get; private set; }
public override bool HandleInput => LinkId != -1;
protected override bool OnClick(InputState state)
{
hoverClickSounds.TriggerOnClick(state);
return base.OnClick(state);
}
protected override void OnLinkClicked() protected override void OnLinkClicked()
{ {
@ -145,19 +124,19 @@ namespace osu.Game.Online.Chat
} }
else else
base.OnLinkClicked(); base.OnLinkClicked();
}
private int getId(string input) int getId(string input)
{ {
var index = input.IndexOf('#'); var index = input.IndexOf('#');
return int.Parse(index > 0 ? input.Remove(index) : input); return int.Parse(index > 0 ? input.Remove(index) : input);
}
} }
public string TooltipText public string TooltipText
{ {
get get
{ {
if (LinkId == -1 || Url == Text) if (Url == Text)
return null; return null;
if (Url.StartsWith("osu://")) if (Url.StartsWith("osu://"))
@ -177,63 +156,12 @@ namespace osu.Game.Online.Chat
} }
} }
public ChatLink()
{
hoverClickSounds = new HoverClickSounds();
OnLoadComplete = d =>
{
// All sprites in the same chatline that represent the same URL
SameLinkSprites = ((Container<Drawable>)d.Parent).Children.Where(child => (child as ChatLink)?.LinkId == LinkId && !d.Equals(child)).Cast<ChatLink>();
};
}
protected override bool OnHover(InputState state)
{
if (!SameLinkSprites.Any(sprite => sprite.IsHovered))
{
hoverClickSounds.TriggerOnHover(state);
foreach (ChatLink sprite in SameLinkSprites)
sprite.TriggerOnHover(state);
}
Content.FadeColour(hoverColour, 500, Easing.OutQuint);
return true;
}
protected override void OnHoverLost(InputState state)
{
if (SameLinkSprites.Any(sprite => sprite.IsHovered))
{
// We have to do this so this sprite does not fade its colour back
Content.FadeColour(hoverColour, 500, Easing.OutQuint);
return;
}
Content.FadeColour(urlColour, 500, Easing.OutQuint);
foreach (ChatLink sprite in SameLinkSprites)
sprite.Content.FadeColour(urlColour, 500, Easing.OutQuint);
base.OnHoverLost(state);
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(APIAccess api, BeatmapSetOverlay beatmapSetOverlay, ChatOverlay chat, OsuColour colours) private void load(APIAccess api, BeatmapSetOverlay beatmapSetOverlay, ChatOverlay chat, OsuColour colours)
{ {
// Should be ok, inexpensive operation
LoadComponentAsync(hoverClickSounds);
this.api = api; this.api = api;
this.beatmapSetOverlay = beatmapSetOverlay; this.beatmapSetOverlay = beatmapSetOverlay;
this.chat = chat; this.chat = chat;
hoverColour = colours.Yellow;
urlColour = colours.Blue;
if (LinkId != -1)
Content.Colour = urlColour;
} }
} }
} }

View File

@ -104,6 +104,7 @@ namespace osu.Game.Overlays.Chat
private void load(OsuColour colours, ChatOverlay chat) private void load(OsuColour colours, ChatOverlay chat)
{ {
this.chat = chat; this.chat = chat;
urlColour = colours.Blue;
customUsernameColour = colours.ChatBlue; customUsernameColour = colours.ChatBlue;
} }
@ -204,6 +205,7 @@ namespace osu.Game.Overlays.Chat
} }
private ChatOverlay chat; private ChatOverlay chat;
private Color4 urlColour;
private void updateMessageContent() private void updateMessageContent()
{ {
@ -244,11 +246,10 @@ namespace osu.Game.Overlays.Chat
contentFlow.AddLink(message.Content.Substring(link.Index, link.Length), link.Url, sprite => contentFlow.AddLink(message.Content.Substring(link.Index, link.Length), link.Url, sprite =>
{ {
((OsuLinkSpriteText)sprite).TextColour = urlColour;
if (message.IsAction) if (message.IsAction)
sprite.Font = @"Exo2.0-MediumItalic"; sprite.Font = @"Exo2.0-MediumItalic";
// We want to use something that is unique to every formatted link PER MESSAGE
((ChatLink)sprite).LinkId = link.Index;
}); });
} }