2018-01-05 19:21:19 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-04-24 19:11:36 +08:00
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2017-11-08 06:16:19 +08:00
|
|
|
using System;
|
2017-04-24 19:11:36 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables
|
|
|
|
{
|
2017-05-19 23:52:23 +08:00
|
|
|
public class DifficultyColouredContainer : Container, IHasAccentColour
|
2017-04-24 19:11:36 +08:00
|
|
|
{
|
|
|
|
public Color4 AccentColour { get; set; }
|
|
|
|
|
|
|
|
private readonly BeatmapInfo beatmap;
|
|
|
|
private OsuColour palette;
|
|
|
|
|
|
|
|
public DifficultyColouredContainer(BeatmapInfo beatmap)
|
|
|
|
{
|
|
|
|
this.beatmap = beatmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour palette)
|
|
|
|
{
|
2017-11-08 06:16:19 +08:00
|
|
|
if (palette == null)
|
|
|
|
throw new ArgumentNullException(nameof(palette));
|
|
|
|
|
2017-04-24 19:11:36 +08:00
|
|
|
this.palette = palette;
|
|
|
|
AccentColour = getColour(beatmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
private enum DifficultyRating
|
|
|
|
{
|
|
|
|
Easy,
|
|
|
|
Normal,
|
|
|
|
Hard,
|
|
|
|
Insane,
|
2017-09-05 19:57:30 +08:00
|
|
|
Expert,
|
|
|
|
ExpertPlus
|
2017-04-24 19:11:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private DifficultyRating getDifficultyRating(BeatmapInfo beatmap)
|
|
|
|
{
|
2017-11-08 06:17:45 +08:00
|
|
|
if (beatmap == null)
|
|
|
|
throw new ArgumentNullException(nameof(beatmap));
|
|
|
|
|
2017-04-24 19:11:36 +08:00
|
|
|
var rating = beatmap.StarDifficulty;
|
|
|
|
|
|
|
|
if (rating < 1.5) return DifficultyRating.Easy;
|
|
|
|
if (rating < 2.25) return DifficultyRating.Normal;
|
|
|
|
if (rating < 3.75) return DifficultyRating.Hard;
|
|
|
|
if (rating < 5.25) return DifficultyRating.Insane;
|
2017-09-05 19:57:30 +08:00
|
|
|
if (rating < 6.75) return DifficultyRating.Expert;
|
|
|
|
return DifficultyRating.ExpertPlus;
|
2017-04-24 19:11:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private Color4 getColour(BeatmapInfo beatmap)
|
|
|
|
{
|
|
|
|
switch (getDifficultyRating(beatmap))
|
|
|
|
{
|
|
|
|
case DifficultyRating.Easy:
|
|
|
|
return palette.Green;
|
|
|
|
default:
|
|
|
|
case DifficultyRating.Normal:
|
2017-09-05 19:57:30 +08:00
|
|
|
return palette.Blue;
|
2017-04-24 19:11:36 +08:00
|
|
|
case DifficultyRating.Hard:
|
2017-09-05 19:57:30 +08:00
|
|
|
return palette.Yellow;
|
2017-04-24 19:11:36 +08:00
|
|
|
case DifficultyRating.Insane:
|
2017-09-05 19:57:30 +08:00
|
|
|
return palette.Pink;
|
2017-04-24 19:11:36 +08:00
|
|
|
case DifficultyRating.Expert:
|
2017-09-05 19:57:30 +08:00
|
|
|
return palette.Purple;
|
|
|
|
case DifficultyRating.ExpertPlus:
|
2017-04-24 19:11:36 +08:00
|
|
|
return palette.Gray0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|