From 4d475f1c1bcfa420ead2ea077c4e191f09d3806b Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Mon, 11 Dec 2017 11:05:32 +0100 Subject: [PATCH] Changed it so ChatLinks handle hover and click sounds themselves --- .../Graphics/Sprites/OsuLinkSpriteText.cs | 15 ++++++----- osu.Game/Online/Chat/ChatLink.cs | 25 +++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs b/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs index 771903c8f3..21b62ee37e 100644 --- a/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs +++ b/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs @@ -4,6 +4,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; +using osu.Framework.Input; using osu.Game.Graphics.Containers; using System.Collections.Generic; using System.Diagnostics; @@ -12,7 +13,7 @@ namespace osu.Game.Graphics.Sprites { public class OsuLinkSpriteText : OsuSpriteText { - private readonly OsuHoverContainer content; + private readonly OsuClickableContainer content; public override bool HandleInput => content.Action != null; @@ -20,6 +21,12 @@ namespace osu.Game.Graphics.Sprites protected override IEnumerable FlowingChildren => Children; + protected override bool OnClick(InputState state) + { + OnLinkClicked(); + return true; + } + private string url; public string Url @@ -31,17 +38,13 @@ namespace osu.Game.Graphics.Sprites set { if (!string.IsNullOrEmpty(value)) - { url = value; - - content.Action = OnLinkClicked; - } } } public OsuLinkSpriteText() { - AddInternal(content = new OsuHoverContainer + AddInternal(content = new OsuClickableContainer { AutoSizeAxes = Axes.Both, }); diff --git a/osu.Game/Online/Chat/ChatLink.cs b/osu.Game/Online/Chat/ChatLink.cs index 83b1429993..08a3184034 100644 --- a/osu.Game/Online/Chat/ChatLink.cs +++ b/osu.Game/Online/Chat/ChatLink.cs @@ -32,7 +32,8 @@ namespace osu.Game.Online.Chat private Color4 hoverColour; private Color4 urlColour; - private readonly ChatHoverContainer content; + private readonly Container content; + private readonly HoverClickSounds hoverClickSounds; /// /// Every other sprite in the containing ChatLine that represents the same link. @@ -41,6 +42,12 @@ namespace osu.Game.Online.Chat protected override Container Content => content ?? base.Content; + protected override bool OnClick(InputState state) + { + hoverClickSounds.TriggerOnClick(state); + return base.OnClick(state); + } + protected override void OnLinkClicked() { var url = Url; @@ -167,7 +174,9 @@ namespace osu.Game.Online.Chat public ChatLink() { - AddInternal(content = new ChatHoverContainer + hoverClickSounds = new HoverClickSounds(); + + AddInternal(content = new Container { AutoSizeAxes = Axes.Both, }); @@ -182,8 +191,12 @@ namespace osu.Game.Online.Chat 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); @@ -210,6 +223,9 @@ namespace osu.Game.Online.Chat [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; @@ -219,10 +235,5 @@ namespace osu.Game.Online.Chat if (LinkId != -1) Content.Colour = urlColour; } - - private class ChatHoverContainer : OsuHoverContainer - { - - } } }