2017-12-02 03:33:27 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Chat
|
|
|
|
|
{
|
|
|
|
|
public class ChatLinkSpriteText : OsuLinkSpriteText
|
|
|
|
|
{
|
2017-12-02 04:31:12 +08:00
|
|
|
|
public int LinkId;
|
|
|
|
|
|
2017-12-02 03:33:27 +08:00
|
|
|
|
private Color4 hoverColour;
|
|
|
|
|
private Color4 urlColour;
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
2017-12-02 04:03:41 +08:00
|
|
|
|
// Every word is one sprite in chat (for word wrap) so we need to find all other sprites that display the same link
|
2017-12-02 04:31:12 +08:00
|
|
|
|
var otherSpritesWithSameLink = ((Container<Drawable>)Parent).Children.Where(child => (child as ChatLinkSpriteText)?.LinkId == LinkId && !Equals(child));
|
2017-12-02 03:33:27 +08:00
|
|
|
|
|
|
|
|
|
var hoverResult = base.OnHover(state);
|
|
|
|
|
|
|
|
|
|
if (!otherSpritesWithSameLink.Any(sprite => sprite.IsHovered))
|
|
|
|
|
foreach (ChatLinkSpriteText sprite in otherSpritesWithSameLink)
|
|
|
|
|
sprite.TriggerOnHover(state);
|
|
|
|
|
|
|
|
|
|
Content.FadeColour(hoverColour, 500, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
return hoverResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
2017-12-02 04:31:12 +08:00
|
|
|
|
var spritesWithSameLink = ((Container<Drawable>)Parent).Children.Where(child => (child as ChatLinkSpriteText)?.LinkId == LinkId);
|
2017-12-02 03:33:27 +08:00
|
|
|
|
|
|
|
|
|
if (spritesWithSameLink.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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (ChatLinkSpriteText sprite in spritesWithSameLink)
|
|
|
|
|
sprite.Content.FadeColour(urlColour, 500, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
hoverColour = colours.Yellow;
|
|
|
|
|
urlColour = colours.Blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|