1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 16:03:01 +08:00

Add StarDifficulty property and correct colouring of difficulty icons.

This commit is contained in:
Dean Herbert 2017-01-30 15:26:28 +09:00
parent 1f2f2fa144
commit 0272c4b559
5 changed files with 102 additions and 11 deletions

View File

@ -131,7 +131,7 @@ namespace osu.Game.Beatmaps.Drawables
},
}
},
new StarCounter { Count = beatmap.BaseDifficulty?.OverallDifficulty ?? 5, StarSize = 8 }
new StarCounter { Count = beatmap.StarDifficulty, StarSize = 8 }
}
}
}

View File

@ -1,7 +1,10 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Game.Database;
using osu.Game.Graphics;
@ -13,20 +16,76 @@ namespace osu.Game.Beatmaps.Drawables
{
class DifficultyIcon : Container
{
private readonly BeatmapInfo beatmap;
private OsuColour palette;
public DifficultyIcon(BeatmapInfo beatmap)
{
this.beatmap = beatmap;
const float size = 20;
Size = new Vector2(size);
Children = new[]
}
[BackgroundDependencyLoader]
private void load(OsuColour palette)
{
this.palette = palette;
Children = new[]
{
new TextAwesome
{
Anchor = Anchor.Centre,
TextSize = size,
Colour = new Color4(159, 198, 0, 255),
TextSize = Size.X,
Colour = getColour(beatmap),
Icon = FontAwesome.fa_circle
},
new TextAwesome
{
Anchor = Anchor.Centre,
TextSize = Size.X,
Colour = Color4.White,
Icon = Ruleset.GetRuleset(beatmap.Mode).Icon
}
};
};
}
enum DifficultyRating
{
Easy,
Normal,
Hard,
Insane,
Expert
}
private DifficultyRating getDifficultyRating(BeatmapInfo beatmap)
{
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;
return DifficultyRating.Expert;
}
private Color4 getColour(BeatmapInfo beatmap)
{
switch (getDifficultyRating(beatmap))
{
case DifficultyRating.Easy:
return palette.Green;
default:
case DifficultyRating.Normal:
return palette.Yellow;
case DifficultyRating.Hard:
return palette.Pink;
case DifficultyRating.Insane:
return palette.Purple;
case DifficultyRating.Expert:
return palette.Gray0;
}
}
}
}

View File

@ -73,6 +73,8 @@ namespace osu.Game.Database
// Metadata
public string Version { get; set; }
public float StarDifficulty => BaseDifficulty?.OverallDifficulty ?? 5; //todo: implement properly
public bool Equals(BeatmapInfo other)
{
return ID == other?.ID;

View File

@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using OpenTK.Graphics;
using osu.Framework.Graphics.Colour;
@ -17,11 +18,23 @@ namespace osu.Game.Graphics
private static Color4 FromHex(string hex)
{
return new Color4(
Convert.ToByte(hex.Substring(0, 2), 16),
Convert.ToByte(hex.Substring(2, 2), 16),
Convert.ToByte(hex.Substring(4, 2), 16),
255);
switch (hex.Length)
{
default:
throw new Exception(@"Invalid hex string length!");
case 3:
return new Color4(
(byte)(Convert.ToByte(hex.Substring(0, 1), 16) * 17),
(byte)(Convert.ToByte(hex.Substring(1, 1), 16) * 17),
(byte)(Convert.ToByte(hex.Substring(2, 1), 16) * 17),
255);
case 6:
return new Color4(
Convert.ToByte(hex.Substring(0, 2), 16),
Convert.ToByte(hex.Substring(2, 2), 16),
Convert.ToByte(hex.Substring(4, 2), 16),
255);
}
}
// See https://github.com/ppy/osu-web/blob/master/resources/assets/less/colors.less
@ -56,6 +69,23 @@ namespace osu.Game.Graphics
public Color4 GreenDark = FromHex(@"668800");
public Color4 GreenDarker = FromHex(@"445500");
public Color4 Gray0 = FromHex(@"000");
public Color4 Gray1 = FromHex(@"111");
public Color4 Gray2 = FromHex(@"222");
public Color4 Gray3 = FromHex(@"333");
public Color4 Gray4 = FromHex(@"444");
public Color4 Gray5 = FromHex(@"555");
public Color4 Gray6 = FromHex(@"666");
public Color4 Gray7 = FromHex(@"777");
public Color4 Gray8 = FromHex(@"888");
public Color4 Gray9 = FromHex(@"999");
public Color4 GrayA = FromHex(@"aaa");
public Color4 GrayB = FromHex(@"bbb");
public Color4 GrayC = FromHex(@"ccc");
public Color4 GrayD = FromHex(@"ddd");
public Color4 GrayE = FromHex(@"eee");
public Color4 GrayF = FromHex(@"fff");
public Color4 Red = FromHex(@"fc4549");
}
}

View File

@ -310,7 +310,7 @@ namespace osu.Game.Screens.Select
if (b.Metadata == null) b.Metadata = beatmapSet.Metadata;
});
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty).ToList();
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.StarDifficulty).ToList();
var beatmap = new WorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault(), beatmapSet, database);