Move colours to HitErrorMeter class

This commit is contained in:
Andrei Zavatski
2019-12-21 14:52:53 +03:00
parent 5af1260094
commit b61aa660c6
3 changed files with 37 additions and 64 deletions

View File

@ -163,30 +163,9 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
centre.Width = 2.5f; centre.Width = 2.5f;
colourBars.Add(centre); colourBars.Add(centre);
Color4 getColour(HitResult result)
{
switch (result)
{
case HitResult.Meh:
return colours.Yellow;
case HitResult.Ok:
return colours.Green;
case HitResult.Good:
return colours.GreenLight;
case HitResult.Great:
return colours.Blue;
default:
return colours.BlueLight;
}
}
Drawable createColourBar(HitResult result, float height, bool first = false) Drawable createColourBar(HitResult result, float height, bool first = false)
{ {
var colour = getColour(result); var colour = GetColourForHitResult(result);
if (first) if (first)
{ {
@ -201,7 +180,7 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = getColour(result), Colour = colour,
Height = height * gradient_start Height = height * gradient_start
}, },
new Box new Box

View File

@ -1,14 +1,13 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osuTK; using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD.HitErrorMeters namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{ {
@ -34,56 +33,21 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
public override void OnNewJudgement(JudgementResult judgement) public override void OnNewJudgement(JudgementResult judgement)
{ {
judgementsFlow.Add(new DrawableJudgement(HitWindows.ResultFor(judgement.TimeOffset))); judgementsFlow.Add(new DrawableJudgement(GetColourForHitResult(HitWindows.ResultFor(judgement.TimeOffset))));
} }
private class DrawableJudgement : CircularContainer private class DrawableJudgement : CircularContainer
{ {
private readonly Box background; public DrawableJudgement(Color4 colour)
private readonly HitResult result;
public DrawableJudgement(HitResult result)
{ {
this.result = result;
Masking = true; Masking = true;
Size = new Vector2(8); Size = new Vector2(8);
Child = background = new Box Child = new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = colour
}; };
} }
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
switch (result)
{
case HitResult.Miss:
background.Colour = colours.Red;
break;
case HitResult.Meh:
background.Colour = colours.Yellow;
break;
case HitResult.Ok:
background.Colour = colours.Green;
break;
case HitResult.Good:
background.Colour = colours.GreenLight;
break;
case HitResult.Great:
background.Colour = colours.Blue;
break;
default:
background.Colour = colours.BlueLight;
break;
}
}
} }
} }
} }

View File

@ -1,9 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD.HitErrorMeters namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{ {
@ -11,11 +14,38 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{ {
protected readonly HitWindows HitWindows; protected readonly HitWindows HitWindows;
[Resolved]
private OsuColour colours { get; set; }
protected HitErrorMeter(HitWindows hitWindows) protected HitErrorMeter(HitWindows hitWindows)
{ {
HitWindows = hitWindows; HitWindows = hitWindows;
} }
public abstract void OnNewJudgement(JudgementResult judgement); public abstract void OnNewJudgement(JudgementResult judgement);
protected Color4 GetColourForHitResult(HitResult result)
{
switch (result)
{
case HitResult.Miss:
return colours.Red;
case HitResult.Meh:
return colours.Yellow;
case HitResult.Ok:
return colours.Green;
case HitResult.Good:
return colours.GreenLight;
case HitResult.Great:
return colours.Blue;
default:
return colours.BlueLight;
}
}
} }
} }