1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 20:33:21 +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
{
private Color4 hoverColour;
private Color4 unhoverColour;
protected override bool OnHover(InputState state)
{
@ -20,7 +21,7 @@ namespace osu.Game.Graphics.Containers
protected override void OnHoverLost(InputState state)
{
this.FadeColour(Color4.White, 500, Easing.OutQuint);
this.FadeColour(unhoverColour, 500, Easing.OutQuint);
base.OnHoverLost(state);
}
@ -28,6 +29,7 @@ namespace osu.Game.Graphics.Containers
private void load(OsuColour colours)
{
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)
{
// TODO: Remove this and get word wrapping working
text = text.Replace(' ', '_');
AddText(text, link =>
{
creationParameters?.Invoke(link);

View File

@ -21,23 +21,18 @@ namespace osu.Game.Graphics.Sprites
public OsuLinkSpriteText()
{
AddInternal(content = new OsuHoverContainer { AutoSizeAxes = Axes.Both });
}
protected override bool OnClick(InputState state)
{
OnLinkClicked();
return true;
AddInternal(content = new OsuHoverContainer
{
AutoSizeAxes = Axes.Both,
Action = OnLinkClicked,
});
}
private string url;
public string Url
{
get
{
return url;
}
get => url;
set
{
if (!string.IsNullOrEmpty(value))
@ -47,8 +42,8 @@ namespace osu.Game.Graphics.Sprites
public ColourInfo TextColour
{
get { return Content.Colour; }
set { Content.Colour = value; }
get => Content.Colour;
set => Content.Colour = value;
}
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.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
@ -22,33 +23,11 @@ namespace osu.Game.Online.Chat
{
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 BeatmapSetOverlay beatmapSetOverlay;
private ChatOverlay chat;
private Color4 hoverColour;
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);
}
public override bool HandleInput => !string.IsNullOrEmpty(Url);
protected override void OnLinkClicked()
{
@ -145,19 +124,19 @@ namespace osu.Game.Online.Chat
}
else
base.OnLinkClicked();
}
private int getId(string input)
{
var index = input.IndexOf('#');
return int.Parse(index > 0 ? input.Remove(index) : input);
int getId(string input)
{
var index = input.IndexOf('#');
return int.Parse(index > 0 ? input.Remove(index) : input);
}
}
public string TooltipText
{
get
{
if (LinkId == -1 || Url == Text)
if (Url == Text)
return null;
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]
private void load(APIAccess api, BeatmapSetOverlay beatmapSetOverlay, ChatOverlay chat, OsuColour colours)
{
// Should be ok, inexpensive operation
LoadComponentAsync(hoverClickSounds);
this.api = api;
this.beatmapSetOverlay = beatmapSetOverlay;
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)
{
this.chat = chat;
urlColour = colours.Blue;
customUsernameColour = colours.ChatBlue;
}
@ -204,6 +205,7 @@ namespace osu.Game.Overlays.Chat
}
private ChatOverlay chat;
private Color4 urlColour;
private void updateMessageContent()
{
@ -244,11 +246,10 @@ namespace osu.Game.Overlays.Chat
contentFlow.AddLink(message.Content.Substring(link.Index, link.Length), link.Url, sprite =>
{
((OsuLinkSpriteText)sprite).TextColour = urlColour;
if (message.IsAction)
sprite.Font = @"Exo2.0-MediumItalic";
// We want to use something that is unique to every formatted link PER MESSAGE
((ChatLink)sprite).LinkId = link.Index;
});
}