From 962e4d7c8afeb9c0d66086466049848324db313e Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Mon, 25 Dec 2017 20:46:04 +0100 Subject: [PATCH] Removed LinkId and word wrapping (for now). Also reimplemented the OsuHoverContainer properly --- .../Graphics/Containers/OsuHoverContainer.cs | 4 +- .../Containers/OsuLinkTextFlowContainer.cs | 3 + .../Graphics/Sprites/OsuLinkSpriteText.cs | 21 ++--- osu.Game/Online/Chat/ChatLink.cs | 88 ++----------------- osu.Game/Overlays/Chat/ChatLine.cs | 7 +- 5 files changed, 26 insertions(+), 97 deletions(-) diff --git a/osu.Game/Graphics/Containers/OsuHoverContainer.cs b/osu.Game/Graphics/Containers/OsuHoverContainer.cs index 3f82ad2179..77b6b3773e 100644 --- a/osu.Game/Graphics/Containers/OsuHoverContainer.cs +++ b/osu.Game/Graphics/Containers/OsuHoverContainer.cs @@ -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; } } } diff --git a/osu.Game/Graphics/Containers/OsuLinkTextFlowContainer.cs b/osu.Game/Graphics/Containers/OsuLinkTextFlowContainer.cs index 382d2d73f4..bc23d128f2 100644 --- a/osu.Game/Graphics/Containers/OsuLinkTextFlowContainer.cs +++ b/osu.Game/Graphics/Containers/OsuLinkTextFlowContainer.cs @@ -36,6 +36,9 @@ namespace osu.Game.Graphics.Containers public void AddLink(string text, string url, Action creationParameters = null) { + // TODO: Remove this and get word wrapping working + text = text.Replace(' ', '_'); + AddText(text, link => { creationParameters?.Invoke(link); diff --git a/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs b/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs index 897df39d0c..dc49ff4daf 100644 --- a/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs +++ b/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs @@ -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); diff --git a/osu.Game/Online/Chat/ChatLink.cs b/osu.Game/Online/Chat/ChatLink.cs index 917de7bd70..43a9792e52 100644 --- a/osu.Game/Online/Chat/ChatLink.cs +++ b/osu.Game/Online/Chat/ChatLink.cs @@ -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 { - /// - /// Identifier unique to every link in a message. - /// A value of -1 means that this instance does not contain a link. - /// - public int LinkId = -1; - private APIAccess api; private BeatmapSetOverlay beatmapSetOverlay; private ChatOverlay chat; - private Color4 hoverColour; - private Color4 urlColour; - - private readonly HoverClickSounds hoverClickSounds; - - /// - /// Every other sprite in the containing ChatLine that represents the same link. - /// - protected IEnumerable 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)d.Parent).Children.Where(child => (child as ChatLink)?.LinkId == LinkId && !d.Equals(child)).Cast(); - }; - } - - 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; } } } diff --git a/osu.Game/Overlays/Chat/ChatLine.cs b/osu.Game/Overlays/Chat/ChatLine.cs index 5fbfed5a67..b86b138012 100644 --- a/osu.Game/Overlays/Chat/ChatLine.cs +++ b/osu.Game/Overlays/Chat/ChatLine.cs @@ -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; }); }