mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 15:03:16 +08:00
Changed it so ChatLinks handle hover and click sounds themselves
This commit is contained in:
parent
13bc50ad56
commit
4d475f1c1b
@ -4,6 +4,7 @@
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Colour;
|
using osu.Framework.Graphics.Colour;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Input;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@ -12,7 +13,7 @@ namespace osu.Game.Graphics.Sprites
|
|||||||
{
|
{
|
||||||
public class OsuLinkSpriteText : OsuSpriteText
|
public class OsuLinkSpriteText : OsuSpriteText
|
||||||
{
|
{
|
||||||
private readonly OsuHoverContainer content;
|
private readonly OsuClickableContainer content;
|
||||||
|
|
||||||
public override bool HandleInput => content.Action != null;
|
public override bool HandleInput => content.Action != null;
|
||||||
|
|
||||||
@ -20,6 +21,12 @@ namespace osu.Game.Graphics.Sprites
|
|||||||
|
|
||||||
protected override IEnumerable<Drawable> FlowingChildren => Children;
|
protected override IEnumerable<Drawable> FlowingChildren => Children;
|
||||||
|
|
||||||
|
protected override bool OnClick(InputState state)
|
||||||
|
{
|
||||||
|
OnLinkClicked();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private string url;
|
private string url;
|
||||||
|
|
||||||
public string Url
|
public string Url
|
||||||
@ -31,17 +38,13 @@ namespace osu.Game.Graphics.Sprites
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(value))
|
if (!string.IsNullOrEmpty(value))
|
||||||
{
|
|
||||||
url = value;
|
url = value;
|
||||||
|
|
||||||
content.Action = OnLinkClicked;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public OsuLinkSpriteText()
|
public OsuLinkSpriteText()
|
||||||
{
|
{
|
||||||
AddInternal(content = new OsuHoverContainer
|
AddInternal(content = new OsuClickableContainer
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
});
|
});
|
||||||
|
@ -32,7 +32,8 @@ namespace osu.Game.Online.Chat
|
|||||||
private Color4 hoverColour;
|
private Color4 hoverColour;
|
||||||
private Color4 urlColour;
|
private Color4 urlColour;
|
||||||
|
|
||||||
private readonly ChatHoverContainer content;
|
private readonly Container content;
|
||||||
|
private readonly HoverClickSounds hoverClickSounds;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Every other sprite in the containing ChatLine that represents the same link.
|
/// 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 Container<Drawable> Content => content ?? base.Content;
|
||||||
|
|
||||||
|
protected override bool OnClick(InputState state)
|
||||||
|
{
|
||||||
|
hoverClickSounds.TriggerOnClick(state);
|
||||||
|
return base.OnClick(state);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnLinkClicked()
|
protected override void OnLinkClicked()
|
||||||
{
|
{
|
||||||
var url = Url;
|
var url = Url;
|
||||||
@ -167,7 +174,9 @@ namespace osu.Game.Online.Chat
|
|||||||
|
|
||||||
public ChatLink()
|
public ChatLink()
|
||||||
{
|
{
|
||||||
AddInternal(content = new ChatHoverContainer
|
hoverClickSounds = new HoverClickSounds();
|
||||||
|
|
||||||
|
AddInternal(content = new Container
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
});
|
});
|
||||||
@ -182,8 +191,12 @@ namespace osu.Game.Online.Chat
|
|||||||
protected override bool OnHover(InputState state)
|
protected override bool OnHover(InputState state)
|
||||||
{
|
{
|
||||||
if (!SameLinkSprites.Any(sprite => sprite.IsHovered))
|
if (!SameLinkSprites.Any(sprite => sprite.IsHovered))
|
||||||
|
{
|
||||||
|
hoverClickSounds.TriggerOnHover(state);
|
||||||
|
|
||||||
foreach (ChatLink sprite in SameLinkSprites)
|
foreach (ChatLink sprite in SameLinkSprites)
|
||||||
sprite.TriggerOnHover(state);
|
sprite.TriggerOnHover(state);
|
||||||
|
}
|
||||||
|
|
||||||
Content.FadeColour(hoverColour, 500, Easing.OutQuint);
|
Content.FadeColour(hoverColour, 500, Easing.OutQuint);
|
||||||
|
|
||||||
@ -210,6 +223,9 @@ namespace osu.Game.Online.Chat
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(APIAccess api, BeatmapSetOverlay beatmapSetOverlay, ChatOverlay chat, OsuColour colours)
|
private void load(APIAccess api, BeatmapSetOverlay beatmapSetOverlay, ChatOverlay chat, OsuColour colours)
|
||||||
{
|
{
|
||||||
|
// Should be ok, inexpensive operation
|
||||||
|
LoadComponentAsync(hoverClickSounds);
|
||||||
|
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.beatmapSetOverlay = beatmapSetOverlay;
|
this.beatmapSetOverlay = beatmapSetOverlay;
|
||||||
this.chat = chat;
|
this.chat = chat;
|
||||||
@ -219,10 +235,5 @@ namespace osu.Game.Online.Chat
|
|||||||
if (LinkId != -1)
|
if (LinkId != -1)
|
||||||
Content.Colour = urlColour;
|
Content.Colour = urlColour;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ChatHoverContainer : OsuHoverContainer
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user