From 152eb83c42c4abc3f6608830e8f0514fbaaa0e0d Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Fri, 1 Dec 2017 20:33:27 +0100 Subject: [PATCH] Added new class for chat lines, that colour the messages after formatting. URLs will become blue, and on hover (also defined here) be turned yellow-ish --- osu.Game/Online/Chat/ChatLinkSpriteText.cs | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 osu.Game/Online/Chat/ChatLinkSpriteText.cs diff --git a/osu.Game/Online/Chat/ChatLinkSpriteText.cs b/osu.Game/Online/Chat/ChatLinkSpriteText.cs new file mode 100644 index 0000000000..a47ee7cbb3 --- /dev/null +++ b/osu.Game/Online/Chat/ChatLinkSpriteText.cs @@ -0,0 +1,63 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// 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 + { + private Color4 hoverColour; + private Color4 urlColour; + + protected override bool OnHover(InputState state) + { + var otherSpritesWithSameLink = ((Container)Parent).Children.Where(child => (child as OsuLinkSpriteText)?.Url == Url && !Equals(child)); + + 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) + { + var spritesWithSameLink = ((Container)Parent).Children.Where(child => (child as OsuLinkSpriteText)?.Url == Url); + + 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; + } + } +}