1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02:55 +08:00

Changed it so ChatLinks handle hover and click sounds themselves

This commit is contained in:
FreezyLemon 2017-12-11 11:05:32 +01:00
parent 13bc50ad56
commit 4d475f1c1b
2 changed files with 27 additions and 13 deletions

View File

@ -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<Drawable> 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,
});

View File

@ -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;
/// <summary>
/// Every other sprite in the containing ChatLine that represents the same link.
@ -41,6 +42,12 @@ namespace osu.Game.Online.Chat
protected override Container<Drawable> 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
{
}
}
}