2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2022-12-19 17:25:45 +00:00
|
|
|
|
using System;
|
2017-06-27 12:05:49 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-11-25 19:59:55 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-06-27 12:05:49 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-05-19 02:28:24 +00:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2021-06-25 17:10:04 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2017-11-25 17:41:18 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-12-12 11:42:50 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-06-27 12:05:49 +00:00
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
|
{
|
2019-05-19 02:28:24 +00:00
|
|
|
|
public partial class OsuClickableContainer : ClickableContainer, IHasTooltip
|
2017-06-27 12:05:49 +00:00
|
|
|
|
{
|
2017-11-25 17:41:18 +00:00
|
|
|
|
private readonly HoverSampleSet sampleSet;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-25 19:59:55 +00:00
|
|
|
|
private readonly Container content = new Container { RelativeSizeAxes = Axes.Both };
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-12-13 13:06:03 +00:00
|
|
|
|
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);
|
2022-12-12 11:42:50 +00:00
|
|
|
|
|
2017-11-25 19:59:55 +00:00
|
|
|
|
protected override Container<Drawable> Content => content;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-11-03 08:44:54 +00:00
|
|
|
|
protected virtual HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverClickSounds(sampleSet) { Enabled = { BindTarget = Enabled } };
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-06-11 11:42:10 +00:00
|
|
|
|
public OsuClickableContainer(HoverSampleSet sampleSet = HoverSampleSet.Default)
|
2017-06-27 12:05:49 +00:00
|
|
|
|
{
|
2017-11-25 17:41:18 +00:00
|
|
|
|
this.sampleSet = sampleSet;
|
2017-06-27 12:05:49 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-06-25 17:10:04 +00:00
|
|
|
|
public virtual LocalisableString TooltipText { get; set; }
|
2019-05-19 02:28:24 +00:00
|
|
|
|
|
2017-11-25 17:41:18 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2017-06-27 12:05:49 +00:00
|
|
|
|
{
|
2017-11-25 19:59:55 +00:00
|
|
|
|
if (AutoSizeAxes != Axes.None)
|
|
|
|
|
{
|
2019-06-03 04:53:24 +00:00
|
|
|
|
content.RelativeSizeAxes = (Axes.Both & ~AutoSizeAxes);
|
2017-11-25 19:59:55 +00:00
|
|
|
|
content.AutoSizeAxes = AutoSizeAxes;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-02-03 07:43:08 +00:00
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
|
{
|
2023-02-13 18:18:45 +00:00
|
|
|
|
CreateHoverSounds(sampleSet),
|
2023-02-03 07:43:08 +00:00
|
|
|
|
content,
|
|
|
|
|
});
|
2017-06-27 12:05:49 +00:00
|
|
|
|
}
|
2022-12-19 17:25:45 +00:00
|
|
|
|
|
|
|
|
|
protected override void ClearInternal(bool disposeChildren = true) =>
|
|
|
|
|
throw new InvalidOperationException($"Clearing {nameof(InternalChildren)} will cause critical failure. Use {nameof(Clear)} instead.");
|
2017-06-27 12:05:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|