2019-01-24 16:43:03 +08:00
|
|
|
|
// 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 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
2024-02-17 05:45:30 +08:00
|
|
|
|
using osu.Framework.Extensions.ListExtensions;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-08-01 23:12:04 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2024-02-17 05:45:30 +08:00
|
|
|
|
using osu.Framework.Lists;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-05-17 15:58:54 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Chat
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2018-12-07 18:39:54 +08:00
|
|
|
|
/// An invisible drawable that brings multiple <see cref="Drawable"/> pieces together to form a consumable clickable link.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// </summary>
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class DrawableLinkCompiler : OsuHoverContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Each word part of a chat link (split for word-wrap support).
|
|
|
|
|
/// </summary>
|
2024-02-17 05:45:30 +08:00
|
|
|
|
public readonly SlimReadOnlyListWrapper<Drawable> Parts;
|
2021-05-17 15:58:54 +08:00
|
|
|
|
|
2023-06-23 00:37:25 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OverlayColourProvider? overlayColourProvider { get; set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-02-17 05:45:30 +08:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
|
|
|
|
{
|
|
|
|
|
foreach (var part in Parts)
|
|
|
|
|
{
|
|
|
|
|
if (part.ReceivePositionalInputAt(screenSpacePos))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-07-09 10:16:47 +08:00
|
|
|
|
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new LinkHoverSounds(sampleSet, Parts);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-08-01 23:12:04 +08:00
|
|
|
|
public DrawableLinkCompiler(ITextPart part)
|
|
|
|
|
: this(part.Drawables.OfType<SpriteText>())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-07 18:39:54 +08:00
|
|
|
|
public DrawableLinkCompiler(IEnumerable<Drawable> parts)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2024-02-17 05:45:30 +08:00
|
|
|
|
Parts = parts.ToList().AsSlimReadOnly();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
2021-05-17 15:58:54 +08:00
|
|
|
|
IdleColour = overlayColourProvider?.Light2 ?? colours.Blue;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IEnumerable<Drawable> EffectTargets => Parts;
|
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class LinkHoverSounds : HoverClickSounds
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2024-02-17 05:45:30 +08:00
|
|
|
|
private readonly SlimReadOnlyListWrapper<Drawable> parts;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-02-17 05:45:30 +08:00
|
|
|
|
public LinkHoverSounds(HoverSampleSet sampleSet, SlimReadOnlyListWrapper<Drawable> parts)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
: base(sampleSet)
|
|
|
|
|
{
|
|
|
|
|
this.parts = parts;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-17 05:45:30 +08:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
|
|
|
|
{
|
|
|
|
|
foreach (var part in parts)
|
|
|
|
|
{
|
|
|
|
|
if (part.ReceivePositionalInputAt(screenSpacePos))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|