2022-06-23 17:37:53 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2020-09-30 23:53:25 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-07-13 16:15:06 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Graphics;
|
2018-07-13 16:15:06 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-06-16 01:02:26 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-04-02 13:51:28 +08:00
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-07-13 16:15:06 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 18:29:27 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-06-23 17:37:53 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2019-06-16 01:02:26 +08:00
|
|
|
using osu.Game.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2018-12-27 17:16:17 +08:00
|
|
|
using osu.Game.Rulesets;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class DifficultyIcon : CompositeDrawable, IHasCustomTooltip<DifficultyIconTooltipContent>, IHasCurrentValue<StarDifficulty>
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-08-24 04:11:36 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Size of this difficulty icon.
|
|
|
|
/// </summary>
|
|
|
|
public new Vector2 Size
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-08-24 04:11:36 +08:00
|
|
|
get => iconContainer.Size;
|
|
|
|
set => iconContainer.Size = value;
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2022-06-23 17:53:21 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether to display a tooltip on hover. Only works if a beatmap was provided at construction time.
|
|
|
|
/// </summary>
|
|
|
|
public bool ShowTooltip { get; set; } = true;
|
|
|
|
|
2022-06-23 17:37:53 +08:00
|
|
|
private readonly IBeatmapInfo? beatmap;
|
2020-09-30 23:53:25 +08:00
|
|
|
|
2021-10-29 16:03:50 +08:00
|
|
|
private readonly IRulesetInfo ruleset;
|
2019-08-17 14:16:24 +08:00
|
|
|
|
2022-06-23 17:37:53 +08:00
|
|
|
private Drawable background = null!;
|
2020-10-14 13:15:53 +08:00
|
|
|
|
2022-06-23 17:37:53 +08:00
|
|
|
private readonly Container iconContainer;
|
2020-10-14 13:15:53 +08:00
|
|
|
|
2022-06-23 17:37:53 +08:00
|
|
|
private readonly BindableWithCurrent<StarDifficulty> difficulty = new BindableWithCurrent<StarDifficulty>();
|
2020-09-30 23:53:25 +08:00
|
|
|
|
2022-06-23 17:37:53 +08:00
|
|
|
public virtual Bindable<StarDifficulty> Current
|
|
|
|
{
|
|
|
|
get => difficulty.Current;
|
|
|
|
set => difficulty.Current = value;
|
|
|
|
}
|
2022-06-23 15:55:22 +08:00
|
|
|
|
2022-06-23 17:37:53 +08:00
|
|
|
[Resolved]
|
|
|
|
private IRulesetStore rulesets { get; set; } = null!;
|
2022-06-23 15:55:22 +08:00
|
|
|
|
2020-09-30 23:53:25 +08:00
|
|
|
/// <summary>
|
2022-06-24 12:59:17 +08:00
|
|
|
/// Creates a new <see cref="DifficultyIcon"/>. Will use provided beatmap's <see cref="BeatmapInfo.StarRating"/> for initial value.
|
2020-09-30 23:53:25 +08:00
|
|
|
/// </summary>
|
2022-06-23 17:37:53 +08:00
|
|
|
/// <param name="beatmap">The beatmap to be displayed in the tooltip, and to be used for the initial star rating value.</param>
|
|
|
|
/// <param name="ruleset">An optional ruleset to be used for the icon display, in place of the beatmap's ruleset.</param>
|
2022-06-23 17:53:21 +08:00
|
|
|
public DifficultyIcon(IBeatmapInfo beatmap, IRulesetInfo? ruleset = null)
|
2022-06-23 17:37:53 +08:00
|
|
|
: this(ruleset ?? beatmap.Ruleset)
|
2020-09-30 23:53:25 +08:00
|
|
|
{
|
2022-06-23 17:37:53 +08:00
|
|
|
this.beatmap = beatmap;
|
|
|
|
Current.Value = new StarDifficulty(beatmap.StarRating, 0);
|
2020-09-30 23:53:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2022-06-24 12:59:17 +08:00
|
|
|
/// Creates a new <see cref="DifficultyIcon"/> without an associated beatmap.
|
2020-09-30 23:53:25 +08:00
|
|
|
/// </summary>
|
2022-06-23 17:37:53 +08:00
|
|
|
/// <param name="ruleset">The ruleset to be used for the icon display.</param>
|
|
|
|
public DifficultyIcon(IRulesetInfo ruleset)
|
2020-09-30 23:53:25 +08:00
|
|
|
{
|
2022-06-23 17:37:53 +08:00
|
|
|
this.ruleset = ruleset;
|
2018-12-27 17:16:17 +08:00
|
|
|
|
2019-08-24 04:11:36 +08:00
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
InternalChild = iconContainer = new Container { Size = new Vector2(20f) };
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2019-08-15 11:11:54 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2019-08-17 14:16:24 +08:00
|
|
|
private void load(OsuColour colours)
|
2019-08-15 11:11:54 +08:00
|
|
|
{
|
2019-08-24 04:11:36 +08:00
|
|
|
iconContainer.Children = new Drawable[]
|
2019-08-15 11:11:54 +08:00
|
|
|
{
|
|
|
|
new CircularContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Masking = true,
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
2021-08-06 17:00:12 +08:00
|
|
|
Colour = Color4.Black.Opacity(0.06f),
|
|
|
|
|
2019-08-15 11:11:54 +08:00
|
|
|
Type = EdgeEffectType.Shadow,
|
2021-08-06 17:00:12 +08:00
|
|
|
Radius = 3,
|
2019-08-15 11:11:54 +08:00
|
|
|
},
|
2020-09-30 23:53:25 +08:00
|
|
|
Child = background = new Box
|
2019-08-15 11:11:54 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new ConstrainedIconContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
// the null coalesce here is only present to make unit tests work (ruleset dlls aren't copied correctly for testing at the moment)
|
2021-10-29 17:16:53 +08:00
|
|
|
Icon = getRulesetIcon()
|
2020-09-30 23:53:25 +08:00
|
|
|
},
|
2019-08-15 11:11:54 +08:00
|
|
|
};
|
2020-09-30 23:53:25 +08:00
|
|
|
|
2022-06-23 17:37:53 +08:00
|
|
|
Current.BindValueChanged(difficulty => background.Colour = colours.ForStarDifficulty(difficulty.NewValue.Stars), true);
|
2022-06-23 15:39:33 +08:00
|
|
|
}
|
|
|
|
|
2021-10-29 17:16:53 +08:00
|
|
|
private Drawable getRulesetIcon()
|
|
|
|
{
|
2022-06-23 17:37:53 +08:00
|
|
|
int? onlineID = ruleset.OnlineID;
|
2021-10-29 17:16:53 +08:00
|
|
|
|
|
|
|
if (onlineID >= 0 && rulesets.GetRuleset(onlineID.Value)?.CreateInstance() is Ruleset rulesetInstance)
|
|
|
|
return rulesetInstance.CreateIcon();
|
|
|
|
|
|
|
|
return new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle };
|
|
|
|
}
|
|
|
|
|
2022-06-23 15:39:33 +08:00
|
|
|
ITooltip<DifficultyIconTooltipContent> IHasCustomTooltip<DifficultyIconTooltipContent>.
|
|
|
|
GetCustomTooltip() => new DifficultyIconTooltip();
|
2020-09-30 23:53:25 +08:00
|
|
|
|
2022-06-23 15:39:33 +08:00
|
|
|
DifficultyIconTooltipContent IHasCustomTooltip<DifficultyIconTooltipContent>.
|
2022-06-23 17:53:21 +08:00
|
|
|
TooltipContent => (ShowTooltip && beatmap != null ? new DifficultyIconTooltipContent(beatmap, Current) : null)!;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|