osu/osu.Game/Online/Chat/DrawableLinkCompiler.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.2 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 09:19:50 +00:00
2022-06-17 07:37:17 +00:00
#nullable disable
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
2021-05-17 07:58:54 +00:00
using osu.Game.Overlays;
2018-11-20 07:51:59 +00:00
using osuTK;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Online.Chat
{
/// <summary>
/// An invisible drawable that brings multiple <see cref="Drawable"/> pieces together to form a consumable clickable link.
/// </summary>
public class DrawableLinkCompiler : OsuHoverContainer
{
/// <summary>
/// Each word part of a chat link (split for word-wrap support).
/// </summary>
2021-05-17 07:58:54 +00:00
public readonly List<Drawable> Parts;
[Resolved(CanBeNull = true)]
private OverlayColourProvider overlayColourProvider { get; set; }
2018-04-13 09:19:50 +00:00
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parts.Any(d => d.ReceivePositionalInputAt(screenSpacePos));
2018-04-13 09:19:50 +00:00
2021-07-09 02:16:47 +00:00
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new LinkHoverSounds(sampleSet, Parts);
2018-04-13 09:19:50 +00:00
public DrawableLinkCompiler(ITextPart part)
: this(part.Drawables.OfType<SpriteText>())
{
}
public DrawableLinkCompiler(IEnumerable<Drawable> parts)
{
Parts = parts.ToList();
}
2018-04-13 09:19:50 +00:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2021-05-17 07:58:54 +00:00
IdleColour = overlayColourProvider?.Light2 ?? colours.Blue;
}
2018-04-13 09:19:50 +00:00
protected override IEnumerable<Drawable> EffectTargets => Parts;
2018-04-13 09:19:50 +00:00
private class LinkHoverSounds : HoverClickSounds
{
private readonly List<Drawable> parts;
2018-04-13 09:19:50 +00:00
public LinkHoverSounds(HoverSampleSet sampleSet, List<Drawable> parts)
: base(sampleSet)
{
this.parts = parts;
}
2018-04-13 09:19:50 +00:00
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => parts.Any(d => d.ReceivePositionalInputAt(screenSpacePos));
}
}
}