1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-18 05:52:56 +08:00
osu-lazer/osu.Game/Graphics/Containers/OsuClickableContainer.cs

58 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 17:19:50 +08:00
using System;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics.UserInterface;
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Graphics.Containers
{
2022-11-24 13:32:20 +08:00
public partial class OsuClickableContainer : ClickableContainer, IHasTooltip
2018-04-13 17:19:50 +08:00
{
private readonly HoverSampleSet sampleSet;
private readonly Container content = new Container { RelativeSizeAxes = Axes.Both };
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
// base call is checked for cases when `OsuClickableContainer` has masking applied to it directly (ie. externally in object initialisation).
base.ReceivePositionalInputAt(screenSpacePos)
// Implementations often apply masking / edge rounding at a content level, so it's imperative to check that as well.
&& Content.ReceivePositionalInputAt(screenSpacePos);
2018-04-13 17:19:50 +08:00
protected override Container<Drawable> Content => content;
protected virtual HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverClickSounds(sampleSet) { Enabled = { BindTarget = Enabled } };
2018-04-13 17:19:50 +08:00
public OsuClickableContainer(HoverSampleSet sampleSet = HoverSampleSet.Default)
2018-04-13 17:19:50 +08:00
{
this.sampleSet = sampleSet;
}
public virtual LocalisableString TooltipText { get; set; }
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load()
{
if (AutoSizeAxes != Axes.None)
{
content.RelativeSizeAxes = (Axes.Both & ~AutoSizeAxes);
2018-04-13 17:19:50 +08:00
content.AutoSizeAxes = AutoSizeAxes;
}
AddRangeInternal(new Drawable[]
{
CreateHoverSounds(sampleSet),
content,
});
2018-04-13 17:19:50 +08:00
}
protected override void ClearInternal(bool disposeChildren = true) =>
throw new InvalidOperationException($"Clearing {nameof(InternalChildren)} will cause critical failure. Use {nameof(Clear)} instead.");
2018-04-13 17:19:50 +08:00
}
}