// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osuTK; namespace osu.Game.Beatmaps.Drawables { /// /// A difficulty icon which automatically calculates difficulty in the background. /// public class CalculatingDifficultyIcon : CompositeDrawable { /// /// Size of this difficulty icon. /// public new Vector2 Size { get => difficultyIcon.Size; set => difficultyIcon.Size = value; } public bool ShowTooltip { get => difficultyIcon.ShowTooltip; set => difficultyIcon.ShowTooltip = value; } private readonly IBeatmapInfo beatmapInfo; private readonly DifficultyIcon difficultyIcon; /// /// Creates a new that follows the currently-selected ruleset and mods. /// /// The beatmap to show the difficulty of. /// Whether to display a tooltip when hovered. /// Whether to perform difficulty lookup (including calculation if necessary). public CalculatingDifficultyIcon(IBeatmapInfo beatmapInfo, bool shouldShowTooltip = true, bool performBackgroundDifficultyLookup = true) { this.beatmapInfo = beatmapInfo ?? throw new ArgumentNullException(nameof(beatmapInfo)); AutoSizeAxes = Axes.Both; InternalChildren = new Drawable[] { difficultyIcon = new DifficultyIcon(beatmapInfo), new DelayedLoadUnloadWrapper(createDifficultyRetriever, 0) }; } private Drawable createDifficultyRetriever() => new DifficultyRetriever(beatmapInfo) { StarDifficulty = { BindTarget = difficultyIcon.Current } }; } }