Substitute two jank interdependent bool flags for single tri-state enums

This commit is contained in:
Bartłomiej Dach 2024-02-22 11:57:40 +01:00
parent 47db317df8
commit d06c67ad8f
No known key found for this signature in database
6 changed files with 34 additions and 24 deletions

View File

@ -50,18 +50,12 @@ public void CreateDifficultyIcon()
fill.Add(difficultyIcon = new DifficultyIcon(beatmapInfo, rulesetInfo)
{
Scale = new Vector2(2),
ShowTooltip = true,
ShowExtendedTooltip = true
});
}, 10);
AddStep("hide extended tooltip", () => difficultyIcon.ShowExtendedTooltip = false);
AddStep("hide tooltip", () => difficultyIcon.ShowTooltip = false);
AddStep("show tooltip", () => difficultyIcon.ShowTooltip = true);
AddStep("show extended tooltip", () => difficultyIcon.ShowExtendedTooltip = true);
AddStep("no tooltip", () => difficultyIcon.TooltipType = DifficultyIconTooltipType.None);
AddStep("basic tooltip", () => difficultyIcon.TooltipType = DifficultyIconTooltipType.StarRating);
AddStep("extended tooltip", () => difficultyIcon.TooltipType = DifficultyIconTooltipType.Extended);
}
}
}

View File

@ -32,14 +32,9 @@ public partial class DifficultyIcon : CompositeDrawable, IHasCustomTooltip<Diffi
}
/// <summary>
/// Whether to display a tooltip on hover. Only works if a beatmap was provided at construction time.
/// Which type of tooltip to show. Only works if a beatmap was provided at construction time.
/// </summary>
public bool ShowTooltip { get; set; } = true;
/// <summary>
/// Whether to include the difficulty stats in the tooltip or not. Defaults to false. Has no effect if <see cref="ShowTooltip"/> is false.
/// </summary>
public bool ShowExtendedTooltip { get; set; }
public DifficultyIconTooltipType TooltipType { get; set; } = DifficultyIconTooltipType.StarRating;
private readonly IBeatmapInfo? beatmap;
@ -138,6 +133,24 @@ ITooltip<DifficultyIconTooltipContent> IHasCustomTooltip<DifficultyIconTooltipCo
GetCustomTooltip() => new DifficultyIconTooltip();
DifficultyIconTooltipContent IHasCustomTooltip<DifficultyIconTooltipContent>.
TooltipContent => (ShowTooltip && beatmap != null ? new DifficultyIconTooltipContent(beatmap, Current, ruleset, mods, ShowExtendedTooltip) : null)!;
TooltipContent => (TooltipType != DifficultyIconTooltipType.None && beatmap != null ? new DifficultyIconTooltipContent(beatmap, Current, ruleset, mods, TooltipType) : null)!;
}
public enum DifficultyIconTooltipType
{
/// <summary>
/// No tooltip.
/// </summary>
None,
/// <summary>
/// Star rating only.
/// </summary>
StarRating,
/// <summary>
/// Star rating, OD, HP, CS, AR, length, BPM, and max combo.
/// </summary>
Extended,
}
}

View File

@ -113,7 +113,7 @@ public void SetContent(DifficultyIconTooltipContent content)
starRating.Current.BindTarget = displayedContent.Difficulty;
difficultyName.Text = displayedContent.BeatmapInfo.DifficultyName;
if (!displayedContent.ShowExtendedTooltip)
if (displayedContent.TooltipType == DifficultyIconTooltipType.StarRating)
{
difficultyFillFlowContainer.Hide();
miscFillFlowContainer.Hide();
@ -166,15 +166,18 @@ internal class DifficultyIconTooltipContent
public readonly IBindable<StarDifficulty> Difficulty;
public readonly IRulesetInfo Ruleset;
public readonly Mod[]? Mods;
public readonly bool ShowExtendedTooltip;
public readonly DifficultyIconTooltipType TooltipType;
public DifficultyIconTooltipContent(IBeatmapInfo beatmapInfo, IBindable<StarDifficulty> difficulty, IRulesetInfo rulesetInfo, Mod[]? mods, bool showExtendedTooltip = false)
public DifficultyIconTooltipContent(IBeatmapInfo beatmapInfo, IBindable<StarDifficulty> difficulty, IRulesetInfo rulesetInfo, Mod[]? mods, DifficultyIconTooltipType tooltipType)
{
if (tooltipType == DifficultyIconTooltipType.None)
throw new ArgumentOutOfRangeException(nameof(tooltipType), tooltipType, "Cannot instantiate a tooltip without a type");
BeatmapInfo = beatmapInfo;
Difficulty = difficulty;
Ruleset = rulesetInfo;
Mods = mods;
ShowExtendedTooltip = showExtendedTooltip;
TooltipType = tooltipType;
}
}
}

View File

@ -297,7 +297,7 @@ public DifficultySelectorButton(APIBeatmap beatmapInfo, IRulesetInfo? ruleset)
},
icon = new DifficultyIcon(beatmapInfo, ruleset)
{
ShowTooltip = false,
TooltipType = DifficultyIconTooltipType.None,
Current = { Value = new StarDifficulty(beatmapInfo.StarRating, 0) },
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -285,7 +285,7 @@ private void refresh()
difficultyIconContainer.Child = new DifficultyIcon(beatmap, ruleset, requiredMods)
{
Size = new Vector2(icon_height),
ShowExtendedTooltip = true
TooltipType = DifficultyIconTooltipType.Extended,
};
}
else

View File

@ -122,7 +122,7 @@ private void load(BeatmapManager? manager, SongSelect? songSelect)
{
difficultyIcon = new DifficultyIcon(beatmapInfo)
{
ShowTooltip = false,
TooltipType = DifficultyIconTooltipType.None,
Scale = new Vector2(1.8f),
},
new FillFlowContainer