1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 00:02:54 +08:00

Merge branch 'master' into add-hw-accel-setting

This commit is contained in:
Bartłomiej Dach 2021-10-30 15:19:01 +02:00 committed by GitHub
commit 9e05e7af74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 22 deletions

View File

@ -15,6 +15,7 @@ using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Select; using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Carousel; using osu.Game.Screens.Select.Carousel;
using osu.Game.Screens.Select.Filter; using osu.Game.Screens.Select.Filter;
@ -684,6 +685,7 @@ namespace osu.Game.Tests.Visual.SongSelect
set.Beatmaps.Add(new BeatmapInfo set.Beatmaps.Add(new BeatmapInfo
{ {
Version = $"Stars: {i}", Version = $"Stars: {i}",
Ruleset = new OsuRuleset().RulesetInfo,
StarDifficulty = i, StarDifficulty = i,
}); });
} }
@ -868,6 +870,7 @@ namespace osu.Game.Tests.Visual.SongSelect
OnlineBeatmapID = id++ * 10, OnlineBeatmapID = id++ * 10,
Version = version, Version = version,
StarDifficulty = diff, StarDifficulty = diff,
Ruleset = new OsuRuleset().RulesetInfo,
BaseDifficulty = new BeatmapDifficulty BaseDifficulty = new BeatmapDifficulty
{ {
OverallDifficulty = diff, OverallDifficulty = diff,

View File

@ -37,10 +37,10 @@ namespace osu.Game.Beatmaps.Drawables
} }
[NotNull] [NotNull]
private readonly BeatmapInfo beatmapInfo; private readonly IBeatmapInfo beatmapInfo;
[CanBeNull] [CanBeNull]
private readonly RulesetInfo ruleset; private readonly IRulesetInfo ruleset;
[CanBeNull] [CanBeNull]
private readonly IReadOnlyList<Mod> mods; private readonly IReadOnlyList<Mod> mods;
@ -60,7 +60,7 @@ namespace osu.Game.Beatmaps.Drawables
/// <param name="ruleset">The ruleset to show the difficulty with.</param> /// <param name="ruleset">The ruleset to show the difficulty with.</param>
/// <param name="mods">The mods to show the difficulty with.</param> /// <param name="mods">The mods to show the difficulty with.</param>
/// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param> /// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param>
public DifficultyIcon([NotNull] BeatmapInfo beatmapInfo, [CanBeNull] RulesetInfo ruleset, [CanBeNull] IReadOnlyList<Mod> mods, bool shouldShowTooltip = true) public DifficultyIcon([NotNull] IBeatmapInfo beatmapInfo, [CanBeNull] IRulesetInfo ruleset, [CanBeNull] IReadOnlyList<Mod> mods, bool shouldShowTooltip = true)
: this(beatmapInfo, shouldShowTooltip) : this(beatmapInfo, shouldShowTooltip)
{ {
this.ruleset = ruleset ?? beatmapInfo.Ruleset; this.ruleset = ruleset ?? beatmapInfo.Ruleset;
@ -73,7 +73,7 @@ namespace osu.Game.Beatmaps.Drawables
/// <param name="beatmapInfo">The beatmap to show the difficulty of.</param> /// <param name="beatmapInfo">The beatmap to show the difficulty of.</param>
/// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param> /// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param>
/// <param name="performBackgroundDifficultyLookup">Whether to perform difficulty lookup (including calculation if necessary).</param> /// <param name="performBackgroundDifficultyLookup">Whether to perform difficulty lookup (including calculation if necessary).</param>
public DifficultyIcon([NotNull] BeatmapInfo beatmapInfo, bool shouldShowTooltip = true, bool performBackgroundDifficultyLookup = true) public DifficultyIcon([NotNull] IBeatmapInfo beatmapInfo, bool shouldShowTooltip = true, bool performBackgroundDifficultyLookup = true)
{ {
this.beatmapInfo = beatmapInfo ?? throw new ArgumentNullException(nameof(beatmapInfo)); this.beatmapInfo = beatmapInfo ?? throw new ArgumentNullException(nameof(beatmapInfo));
this.shouldShowTooltip = shouldShowTooltip; this.shouldShowTooltip = shouldShowTooltip;
@ -84,6 +84,9 @@ namespace osu.Game.Beatmaps.Drawables
InternalChild = iconContainer = new Container { Size = new Vector2(20f) }; InternalChild = iconContainer = new Container { Size = new Vector2(20f) };
} }
[Resolved]
private RulesetStore rulesets { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
@ -105,7 +108,7 @@ namespace osu.Game.Beatmaps.Drawables
Child = background = new Box Child = background = new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = colours.ForStarDifficulty(beatmapInfo.StarDifficulty) // Default value that will be re-populated once difficulty calculation completes Colour = colours.ForStarDifficulty(beatmapInfo.StarRating) // Default value that will be re-populated once difficulty calculation completes
}, },
}, },
new ConstrainedIconContainer new ConstrainedIconContainer
@ -114,18 +117,28 @@ namespace osu.Game.Beatmaps.Drawables
Origin = Anchor.Centre, Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both, 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) // the null coalesce here is only present to make unit tests work (ruleset dlls aren't copied correctly for testing at the moment)
Icon = (ruleset ?? beatmapInfo.Ruleset)?.CreateInstance()?.CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle } Icon = getRulesetIcon()
}, },
}; };
if (performBackgroundDifficultyLookup) if (performBackgroundDifficultyLookup)
iconContainer.Add(new DelayedLoadUnloadWrapper(() => new DifficultyRetriever(beatmapInfo, ruleset, mods) { StarDifficulty = { BindTarget = difficultyBindable } }, 0)); iconContainer.Add(new DelayedLoadUnloadWrapper(() => new DifficultyRetriever(beatmapInfo, ruleset, mods) { StarDifficulty = { BindTarget = difficultyBindable } }, 0));
else else
difficultyBindable.Value = new StarDifficulty(beatmapInfo.StarDifficulty, 0); difficultyBindable.Value = new StarDifficulty(beatmapInfo.StarRating, 0);
difficultyBindable.BindValueChanged(difficulty => background.Colour = colours.ForStarDifficulty(difficulty.NewValue.Stars)); difficultyBindable.BindValueChanged(difficulty => background.Colour = colours.ForStarDifficulty(difficulty.NewValue.Stars));
} }
private Drawable getRulesetIcon()
{
int? onlineID = (ruleset ?? beatmapInfo.Ruleset).OnlineID;
if (onlineID >= 0 && rulesets.GetRuleset(onlineID.Value)?.CreateInstance() is Ruleset rulesetInstance)
return rulesetInstance.CreateIcon();
return new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle };
}
ITooltip<DifficultyIconTooltipContent> IHasCustomTooltip<DifficultyIconTooltipContent>.GetCustomTooltip() => new DifficultyIconTooltip(); ITooltip<DifficultyIconTooltipContent> IHasCustomTooltip<DifficultyIconTooltipContent>.GetCustomTooltip() => new DifficultyIconTooltip();
DifficultyIconTooltipContent IHasCustomTooltip<DifficultyIconTooltipContent>.TooltipContent => shouldShowTooltip ? new DifficultyIconTooltipContent(beatmapInfo, difficultyBindable) : null; DifficultyIconTooltipContent IHasCustomTooltip<DifficultyIconTooltipContent>.TooltipContent => shouldShowTooltip ? new DifficultyIconTooltipContent(beatmapInfo, difficultyBindable) : null;
@ -134,8 +147,8 @@ namespace osu.Game.Beatmaps.Drawables
{ {
public readonly Bindable<StarDifficulty> StarDifficulty = new Bindable<StarDifficulty>(); public readonly Bindable<StarDifficulty> StarDifficulty = new Bindable<StarDifficulty>();
private readonly BeatmapInfo beatmapInfo; private readonly IBeatmapInfo beatmapInfo;
private readonly RulesetInfo ruleset; private readonly IRulesetInfo ruleset;
private readonly IReadOnlyList<Mod> mods; private readonly IReadOnlyList<Mod> mods;
private CancellationTokenSource difficultyCancellation; private CancellationTokenSource difficultyCancellation;
@ -143,7 +156,7 @@ namespace osu.Game.Beatmaps.Drawables
[Resolved] [Resolved]
private BeatmapDifficultyCache difficultyCache { get; set; } private BeatmapDifficultyCache difficultyCache { get; set; }
public DifficultyRetriever(BeatmapInfo beatmapInfo, RulesetInfo ruleset, IReadOnlyList<Mod> mods) public DifficultyRetriever(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset, IReadOnlyList<Mod> mods)
{ {
this.beatmapInfo = beatmapInfo; this.beatmapInfo = beatmapInfo;
this.ruleset = ruleset; this.ruleset = ruleset;

View File

@ -89,7 +89,7 @@ namespace osu.Game.Beatmaps.Drawables
public void SetContent(DifficultyIconTooltipContent content) public void SetContent(DifficultyIconTooltipContent content)
{ {
difficultyName.Text = content.BeatmapInfo.Version; difficultyName.Text = content.BeatmapInfo.DifficultyName;
starDifficulty.UnbindAll(); starDifficulty.UnbindAll();
starDifficulty.BindTo(content.Difficulty); starDifficulty.BindTo(content.Difficulty);
@ -109,10 +109,10 @@ namespace osu.Game.Beatmaps.Drawables
internal class DifficultyIconTooltipContent internal class DifficultyIconTooltipContent
{ {
public readonly BeatmapInfo BeatmapInfo; public readonly IBeatmapInfo BeatmapInfo;
public readonly IBindable<StarDifficulty> Difficulty; public readonly IBindable<StarDifficulty> Difficulty;
public DifficultyIconTooltipContent(BeatmapInfo beatmapInfo, IBindable<StarDifficulty> difficulty) public DifficultyIconTooltipContent(IBeatmapInfo beatmapInfo, IBindable<StarDifficulty> difficulty)
{ {
BeatmapInfo = beatmapInfo; BeatmapInfo = beatmapInfo;
Difficulty = difficulty; Difficulty = difficulty;

View File

@ -19,8 +19,8 @@ namespace osu.Game.Beatmaps.Drawables
/// </remarks> /// </remarks>
public class GroupedDifficultyIcon : DifficultyIcon public class GroupedDifficultyIcon : DifficultyIcon
{ {
public GroupedDifficultyIcon(List<BeatmapInfo> beatmaps, RulesetInfo ruleset, Color4 counterColour) public GroupedDifficultyIcon(IEnumerable<IBeatmapInfo> beatmaps, IRulesetInfo ruleset, Color4 counterColour)
: base(beatmaps.OrderBy(b => b.StarDifficulty).Last(), ruleset, null, false) : base(beatmaps.OrderBy(b => b.StarRating).Last(), ruleset, null, false)
{ {
AddInternal(new OsuSpriteText AddInternal(new OsuSpriteText
{ {
@ -29,7 +29,7 @@ namespace osu.Game.Beatmaps.Drawables
Padding = new MarginPadding { Left = Size.X }, Padding = new MarginPadding { Left = Size.X },
Margin = new MarginPadding { Left = 2, Right = 5 }, Margin = new MarginPadding { Left = 2, Right = 5 },
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold), Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold),
Text = beatmaps.Count.ToString(), Text = beatmaps.Count().ToString(),
Colour = counterColour, Colour = counterColour,
}); });
} }

View File

@ -11,7 +11,7 @@ namespace osu.Game.Beatmaps
/// <summary> /// <summary>
/// A single beatmap difficulty. /// A single beatmap difficulty.
/// </summary> /// </summary>
public interface IBeatmapInfo : IHasOnlineID public interface IBeatmapInfo : IHasOnlineID<int>
{ {
/// <summary> /// <summary>
/// The user-specified name given to this beatmap. /// The user-specified name given to this beatmap.

View File

@ -12,7 +12,7 @@ namespace osu.Game.Beatmaps
/// <summary> /// <summary>
/// A representation of a collection of beatmap difficulties, generally packaged as an ".osz" archive. /// A representation of a collection of beatmap difficulties, generally packaged as an ".osz" archive.
/// </summary> /// </summary>
public interface IBeatmapSetInfo : IHasOnlineID public interface IBeatmapSetInfo : IHasOnlineID<int>
{ {
/// <summary> /// <summary>
/// The date when this beatmap was imported. /// The date when this beatmap was imported.

View File

@ -5,7 +5,7 @@
namespace osu.Game.Database namespace osu.Game.Database
{ {
public interface IHasOnlineID public interface IHasOnlineID<out T>
{ {
/// <summary> /// <summary>
/// The server-side ID representing this instance, if one exists. Any value 0 or less denotes a missing ID. /// The server-side ID representing this instance, if one exists. Any value 0 or less denotes a missing ID.
@ -14,6 +14,6 @@ namespace osu.Game.Database
/// Generally we use -1 when specifying "missing" in code, but values of 0 are also considered missing as the online source /// Generally we use -1 when specifying "missing" in code, but values of 0 are also considered missing as the online source
/// is generally a MySQL autoincrement value, which can never be 0. /// is generally a MySQL autoincrement value, which can never be 0.
/// </remarks> /// </remarks>
int OnlineID { get; } T OnlineID { get; }
} }
} }

View File

@ -11,7 +11,7 @@ namespace osu.Game.Rulesets
/// <summary> /// <summary>
/// A representation of a ruleset's metadata. /// A representation of a ruleset's metadata.
/// </summary> /// </summary>
public interface IRulesetInfo : IHasOnlineID public interface IRulesetInfo : IHasOnlineID<int>
{ {
/// <summary> /// <summary>
/// The user-exposed name of this ruleset. /// The user-exposed name of this ruleset.

View File

@ -19,7 +19,7 @@ using osu.Game.Utils;
namespace osu.Game.Scoring namespace osu.Game.Scoring
{ {
public class ScoreInfo : IHasFiles<ScoreFileInfo>, IHasPrimaryKey, ISoftDelete, IEquatable<ScoreInfo>, IDeepCloneable<ScoreInfo> public class ScoreInfo : IHasFiles<ScoreFileInfo>, IHasPrimaryKey, ISoftDelete, IEquatable<ScoreInfo>, IDeepCloneable<ScoreInfo>, IHasOnlineID<long>
{ {
public int ID { get; set; } public int ID { get; set; }
@ -271,5 +271,11 @@ namespace osu.Game.Scoring
return ReferenceEquals(this, other); return ReferenceEquals(this, other);
} }
#region Implementation of IHasOnlineID
public long OnlineID => OnlineScoreID ?? -1;
#endregion
} }
} }