2019-01-24 16:43:03 +08:00
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables
|
|
|
|
{
|
2018-07-13 16:15:06 +08:00
|
|
|
public abstract class DifficultyColouredContainer : Container, IHasAccentColour
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
public Color4 AccentColour { get; set; }
|
|
|
|
|
|
|
|
private readonly BeatmapInfo beatmap;
|
|
|
|
private OsuColour palette;
|
|
|
|
|
2018-07-13 16:15:06 +08:00
|
|
|
protected DifficultyColouredContainer(BeatmapInfo beatmap)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2019-02-14 18:19:41 +08:00
|
|
|
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;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|