mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 12:42:54 +08:00
Merge branch 'refactor-difficulty-colours' into difficulty-icon-tooltip
This commit is contained in:
commit
3dc81bdad5
@ -129,6 +129,22 @@ namespace osu.Game.Beatmaps
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<ScoreInfo> Scores { get; set; }
|
public List<ScoreInfo> Scores { get; set; }
|
||||||
|
|
||||||
|
public DifficultyRating DifficultyRating
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var rating = StarDifficulty;
|
||||||
|
|
||||||
|
if (rating < 2.0) return DifficultyRating.Easy;
|
||||||
|
if (rating < 2.7) return DifficultyRating.Normal;
|
||||||
|
if (rating < 4.0) return DifficultyRating.Hard;
|
||||||
|
if (rating < 5.3) return DifficultyRating.Insane;
|
||||||
|
if (rating < 6.5) return DifficultyRating.Expert;
|
||||||
|
|
||||||
|
return DifficultyRating.ExpertPlus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString() => $"{Metadata} [{Version}]".Trim();
|
public override string ToString() => $"{Metadata} [{Version}]".Trim();
|
||||||
|
|
||||||
public bool Equals(BeatmapInfo other)
|
public bool Equals(BeatmapInfo other)
|
||||||
|
15
osu.Game/Beatmaps/DifficultyRating.cs
Normal file
15
osu.Game/Beatmaps/DifficultyRating.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps
|
||||||
|
{
|
||||||
|
public enum DifficultyRating
|
||||||
|
{
|
||||||
|
Easy,
|
||||||
|
Normal,
|
||||||
|
Hard,
|
||||||
|
Insane,
|
||||||
|
Expert,
|
||||||
|
ExpertPlus
|
||||||
|
}
|
||||||
|
}
|
@ -1,85 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osuTK.Graphics;
|
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps.Drawables
|
|
||||||
{
|
|
||||||
public abstract class DifficultyColouredContainer : Container, IHasAccentColour
|
|
||||||
{
|
|
||||||
public Color4 AccentColour { get; set; }
|
|
||||||
|
|
||||||
private readonly BeatmapInfo beatmap;
|
|
||||||
private OsuColour palette;
|
|
||||||
|
|
||||||
protected DifficultyColouredContainer(BeatmapInfo beatmap)
|
|
||||||
{
|
|
||||||
this.beatmap = beatmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OsuColour palette)
|
|
||||||
{
|
|
||||||
if (palette == null)
|
|
||||||
throw new ArgumentNullException(nameof(palette));
|
|
||||||
|
|
||||||
this.palette = palette;
|
|
||||||
AccentColour = getColour(beatmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum DifficultyRating
|
|
||||||
{
|
|
||||||
Easy,
|
|
||||||
Normal,
|
|
||||||
Hard,
|
|
||||||
Insane,
|
|
||||||
Expert,
|
|
||||||
ExpertPlus
|
|
||||||
}
|
|
||||||
|
|
||||||
private DifficultyRating getDifficultyRating(BeatmapInfo beatmap)
|
|
||||||
{
|
|
||||||
if (beatmap == null)
|
|
||||||
throw new ArgumentNullException(nameof(beatmap));
|
|
||||||
|
|
||||||
var rating = beatmap.StarDifficulty;
|
|
||||||
|
|
||||||
if (rating < 2.0) return DifficultyRating.Easy;
|
|
||||||
if (rating < 2.7) return DifficultyRating.Normal;
|
|
||||||
if (rating < 4.0) return DifficultyRating.Hard;
|
|
||||||
if (rating < 5.3) return DifficultyRating.Insane;
|
|
||||||
if (rating < 6.5) return DifficultyRating.Expert;
|
|
||||||
|
|
||||||
return DifficultyRating.ExpertPlus;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Color4 getColour(BeatmapInfo beatmap)
|
|
||||||
{
|
|
||||||
switch (getDifficultyRating(beatmap))
|
|
||||||
{
|
|
||||||
case DifficultyRating.Easy:
|
|
||||||
return palette.Green;
|
|
||||||
|
|
||||||
default:
|
|
||||||
case DifficultyRating.Normal:
|
|
||||||
return palette.Blue;
|
|
||||||
|
|
||||||
case DifficultyRating.Hard:
|
|
||||||
return palette.Yellow;
|
|
||||||
|
|
||||||
case DifficultyRating.Insane:
|
|
||||||
return palette.Pink;
|
|
||||||
|
|
||||||
case DifficultyRating.Expert:
|
|
||||||
return palette.Purple;
|
|
||||||
|
|
||||||
case DifficultyRating.ExpertPlus:
|
|
||||||
return palette.Gray0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,16 +19,18 @@ using osuTK.Graphics;
|
|||||||
|
|
||||||
namespace osu.Game.Beatmaps.Drawables
|
namespace osu.Game.Beatmaps.Drawables
|
||||||
{
|
{
|
||||||
public class DifficultyIcon : DifficultyColouredContainer, IHasCustomTooltip
|
public class DifficultyIcon : Container, IHasCustomTooltip
|
||||||
{
|
{
|
||||||
|
private readonly BeatmapInfo beatmap;
|
||||||
private readonly RulesetInfo ruleset;
|
private readonly RulesetInfo ruleset;
|
||||||
|
|
||||||
public DifficultyIcon(BeatmapInfo beatmap, RulesetInfo ruleset = null, bool shouldShowTooltip = true)
|
public DifficultyIcon(BeatmapInfo beatmap, RulesetInfo ruleset = null, bool shouldShowTooltip = true)
|
||||||
: base(beatmap)
|
|
||||||
{
|
{
|
||||||
if (beatmap == null)
|
if (beatmap == null)
|
||||||
throw new ArgumentNullException(nameof(beatmap));
|
throw new ArgumentNullException(nameof(beatmap));
|
||||||
|
|
||||||
|
this.beatmap = beatmap;
|
||||||
|
|
||||||
this.ruleset = ruleset ?? beatmap.Ruleset;
|
this.ruleset = ruleset ?? beatmap.Ruleset;
|
||||||
TooltipText = shouldShowTooltip ? $"{beatmap.Version}${beatmap.StarDifficulty:0.##}" : String.Empty;
|
TooltipText = shouldShowTooltip ? $"{beatmap.Version}${beatmap.StarDifficulty:0.##}" : String.Empty;
|
||||||
|
|
||||||
@ -40,7 +42,7 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
public ITooltip GetCustomTooltip() => new DifficultyIconTooltip(AccentColour);
|
public ITooltip GetCustomTooltip() => new DifficultyIconTooltip(AccentColour);
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -60,7 +62,7 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
Child = new Box
|
Child = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = AccentColour,
|
Colour = colours.ForDifficultyRating(beatmap.DifficultyRating),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
new ConstrainedIconContainer
|
new ConstrainedIconContainer
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Graphics
|
namespace osu.Game.Graphics
|
||||||
@ -37,6 +38,31 @@ namespace osu.Game.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Color4 ForDifficultyRating(DifficultyRating difficulty)
|
||||||
|
{
|
||||||
|
switch (difficulty)
|
||||||
|
{
|
||||||
|
case DifficultyRating.Easy:
|
||||||
|
return Green;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case DifficultyRating.Normal:
|
||||||
|
return Blue;
|
||||||
|
|
||||||
|
case DifficultyRating.Hard:
|
||||||
|
return Yellow;
|
||||||
|
|
||||||
|
case DifficultyRating.Insane:
|
||||||
|
return Pink;
|
||||||
|
|
||||||
|
case DifficultyRating.Expert:
|
||||||
|
return Purple;
|
||||||
|
|
||||||
|
case DifficultyRating.ExpertPlus:
|
||||||
|
return Gray0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// See https://github.com/ppy/osu-web/blob/master/resources/assets/less/colors.less
|
// See https://github.com/ppy/osu-web/blob/master/resources/assets/less/colors.less
|
||||||
public readonly Color4 PurpleLighter = FromHex(@"eeeeff");
|
public readonly Color4 PurpleLighter = FromHex(@"eeeeff");
|
||||||
public readonly Color4 PurpleLight = FromHex(@"aa88ff");
|
public readonly Color4 PurpleLight = FromHex(@"aa88ff");
|
||||||
|
@ -402,31 +402,35 @@ namespace osu.Game.Screens.Select
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DifficultyColourBar : DifficultyColouredContainer
|
private class DifficultyColourBar : Container
|
||||||
{
|
{
|
||||||
|
private readonly BeatmapInfo beatmap;
|
||||||
|
|
||||||
public DifficultyColourBar(BeatmapInfo beatmap)
|
public DifficultyColourBar(BeatmapInfo beatmap)
|
||||||
: base(beatmap)
|
|
||||||
{
|
{
|
||||||
|
this.beatmap = beatmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
const float full_opacity_ratio = 0.7f;
|
const float full_opacity_ratio = 0.7f;
|
||||||
|
|
||||||
|
var difficultyColour = colours.ForDifficultyRating(beatmap.DifficultyRating);
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = AccentColour,
|
Colour = difficultyColour,
|
||||||
Width = full_opacity_ratio,
|
Width = full_opacity_ratio,
|
||||||
},
|
},
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
RelativePositionAxes = Axes.Both,
|
RelativePositionAxes = Axes.Both,
|
||||||
Colour = AccentColour,
|
Colour = difficultyColour,
|
||||||
Alpha = 0.5f,
|
Alpha = 0.5f,
|
||||||
X = full_opacity_ratio,
|
X = full_opacity_ratio,
|
||||||
Width = 1 - full_opacity_ratio,
|
Width = 1 - full_opacity_ratio,
|
||||||
|
Loading…
Reference in New Issue
Block a user