mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 13:22:55 +08:00
Merge both variants of the star rating display
This commit is contained in:
parent
0a8d37defa
commit
d4399f10f9
@ -1,65 +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.Linq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Utils;
|
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Screens.Ranking.Expanded;
|
|
||||||
using osuTK;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Ranking
|
|
||||||
{
|
|
||||||
public class TestSceneStarRatingDisplay : OsuTestScene
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void TestDisplay()
|
|
||||||
{
|
|
||||||
AddStep("load displays", () => Child = new FillFlowContainer
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
ChildrenEnumerable = new[]
|
|
||||||
{
|
|
||||||
1.23,
|
|
||||||
2.34,
|
|
||||||
3.45,
|
|
||||||
4.56,
|
|
||||||
5.67,
|
|
||||||
6.78,
|
|
||||||
10.11,
|
|
||||||
}.Select(starRating => new StarRatingDisplay(new StarDifficulty(starRating, 0))
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestChangingStarRatingDisplay()
|
|
||||||
{
|
|
||||||
StarRatingDisplay starRating = null;
|
|
||||||
|
|
||||||
AddStep("load display", () => Child = starRating = new StarRatingDisplay(new StarDifficulty(5.55, 1))
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Scale = new Vector2(3f),
|
|
||||||
});
|
|
||||||
|
|
||||||
AddRepeatStep("set random value", () =>
|
|
||||||
{
|
|
||||||
starRating.Current.Value = new StarDifficulty(RNG.NextDouble(0.0, 11.0), 1);
|
|
||||||
}, 10);
|
|
||||||
|
|
||||||
AddSliderStep("set exact stars", 0.0, 11.0, 5.55, d =>
|
|
||||||
{
|
|
||||||
if (starRating != null)
|
|
||||||
starRating.Current.Value = new StarDifficulty(d, 1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,12 +12,36 @@ using osuTK;
|
|||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
public class TestSceneStarRatingDisplayV2 : OsuTestScene
|
public class TestSceneStarRatingDisplay : OsuTestScene
|
||||||
{
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestOldColoursDisplay()
|
||||||
|
{
|
||||||
|
AddStep("load displays", () => Child = new FillFlowContainer
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
ChildrenEnumerable = new[]
|
||||||
|
{
|
||||||
|
1.23,
|
||||||
|
2.34,
|
||||||
|
3.45,
|
||||||
|
4.56,
|
||||||
|
5.67,
|
||||||
|
6.78,
|
||||||
|
10.11,
|
||||||
|
}.Select(starRating => new StarRatingDisplay(new StarDifficulty(starRating, 0))
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[TestCase(52f, 20f)]
|
[TestCase(52f, 20f)]
|
||||||
[TestCase(52f, 16f)]
|
[TestCase(52f, 16f)]
|
||||||
[TestCase(50f, 14f)]
|
[TestCase(50f, 14f)]
|
||||||
public void TestDisplay(float width, float height)
|
public void TestNewColoursDisplay(float width, float height)
|
||||||
{
|
{
|
||||||
AddStep("load displays", () =>
|
AddStep("load displays", () =>
|
||||||
{
|
{
|
||||||
@ -35,7 +59,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
Spacing = new Vector2(2f),
|
Spacing = new Vector2(2f),
|
||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
ChildrenEnumerable = Enumerable.Range(0, 10).Select(j => new StarRatingDisplayV2(new StarDifficulty(i + j * 0.1f, 0))
|
ChildrenEnumerable = Enumerable.Range(0, 10).Select(j => new StarRatingDisplay(new StarDifficulty(i + j * 0.1f, 0), true)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
@ -47,11 +71,11 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestChangingStarRatingDisplay()
|
public void TestChangingStarRatingDisplay([Values(false, true)] bool useNewColours)
|
||||||
{
|
{
|
||||||
StarRatingDisplayV2 starRating = null;
|
StarRatingDisplay starRating = null;
|
||||||
|
|
||||||
AddStep("load display", () => Child = starRating = new StarRatingDisplayV2(new StarDifficulty(5.55, 1))
|
AddStep("load display", () => Child = starRating = new StarRatingDisplay(new StarDifficulty(5.55, 1), useNewColours)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
@ -17,8 +17,12 @@ using osuTK.Graphics;
|
|||||||
|
|
||||||
namespace osu.Game.Beatmaps.Drawables
|
namespace osu.Game.Beatmaps.Drawables
|
||||||
{
|
{
|
||||||
public class StarRatingDisplayV2 : CompositeDrawable, IHasCurrentValue<StarDifficulty>
|
/// <summary>
|
||||||
|
/// A pill that displays the star rating of a beatmap.
|
||||||
|
/// </summary>
|
||||||
|
public class StarRatingDisplay : CompositeDrawable, IHasCurrentValue<StarDifficulty>
|
||||||
{
|
{
|
||||||
|
private readonly bool useNewDifficultyColours;
|
||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
private readonly SpriteIcon starIcon;
|
private readonly SpriteIcon starIcon;
|
||||||
private readonly OsuSpriteText starsText;
|
private readonly OsuSpriteText starsText;
|
||||||
@ -38,13 +42,18 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
private OverlayColourProvider colourProvider { get; set; }
|
private OverlayColourProvider colourProvider { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="StarRatingDisplayV2"/> using an already computed <see cref="StarDifficulty"/>.
|
/// Creates a new <see cref="StarRatingDisplay"/> using an already computed <see cref="StarDifficulty"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="starDifficulty">The already computed <see cref="StarDifficulty"/> to display the star difficulty of.</param>
|
/// <param name="starDifficulty">The already computed <see cref="StarDifficulty"/> to display.</param>
|
||||||
public StarRatingDisplayV2(StarDifficulty starDifficulty)
|
/// <param name="useNewDifficultyColours">Use the new spectrum-based difficulty colours for the display, rather than the old.</param>
|
||||||
|
public StarRatingDisplay(StarDifficulty starDifficulty, bool useNewDifficultyColours = false)
|
||||||
{
|
{
|
||||||
|
this.useNewDifficultyColours = useNewDifficultyColours;
|
||||||
|
|
||||||
Current.Value = starDifficulty;
|
Current.Value = starDifficulty;
|
||||||
|
|
||||||
|
Size = new Vector2(52f, 20f);
|
||||||
|
|
||||||
InternalChild = new CircularContainer
|
InternalChild = new CircularContainer
|
||||||
{
|
{
|
||||||
Masking = true,
|
Masking = true,
|
||||||
@ -82,7 +91,9 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
{
|
{
|
||||||
starsText.Text = c.NewValue.Stars.ToString("0.00");
|
starsText.Text = c.NewValue.Stars.ToString("0.00");
|
||||||
|
|
||||||
background.Colour = colours.ForStarDifficulty(c.NewValue.Stars);
|
background.Colour = useNewDifficultyColours
|
||||||
|
? colours.ForStarDifficulty(c.NewValue.Stars)
|
||||||
|
: colours.ForDifficultyRating(c.NewValue.DifficultyRating);
|
||||||
|
|
||||||
starIcon.Colour = c.NewValue.Stars >= 6.5 ? colours.Orange1 : colourProvider?.Background5 ?? Color4Extensions.FromHex("303d47");
|
starIcon.Colour = c.NewValue.Stars >= 6.5 ? colours.Orange1 : colourProvider?.Background5 ?? Color4Extensions.FromHex("303d47");
|
||||||
starsText.Colour = c.NewValue.Stars >= 6.5 ? colours.Orange1 : colourProvider?.Background5 ?? Color4.Black.Opacity(0.75f);
|
starsText.Colour = c.NewValue.Stars >= 6.5 ? colours.Orange1 : colourProvider?.Background5 ?? Color4.Black.Opacity(0.75f);
|
@ -8,14 +8,16 @@ 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.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Beatmaps.Drawables;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Screens.Ranking.Expanded;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.OnlinePlay.Components
|
namespace osu.Game.Screens.OnlinePlay.Components
|
||||||
{
|
{
|
||||||
public class StarRatingRangeDisplay : OnlinePlayComposite
|
public class StarRatingRangeDisplay : OnlinePlayComposite
|
||||||
{
|
{
|
||||||
|
private readonly bool useNewDifficultyColours;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuColour colours { get; set; }
|
private OsuColour colours { get; set; }
|
||||||
|
|
||||||
@ -24,8 +26,10 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
private StarRatingDisplay maxDisplay;
|
private StarRatingDisplay maxDisplay;
|
||||||
private Drawable maxBackground;
|
private Drawable maxBackground;
|
||||||
|
|
||||||
public StarRatingRangeDisplay()
|
public StarRatingRangeDisplay(bool useNewDifficultyColours = false)
|
||||||
{
|
{
|
||||||
|
this.useNewDifficultyColours = useNewDifficultyColours;
|
||||||
|
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +66,8 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
minDisplay = new StarRatingDisplay(default),
|
minDisplay = new StarRatingDisplay(default) { Size = new Vector2(52f, 16f) },
|
||||||
maxDisplay = new StarRatingDisplay(default)
|
maxDisplay = new StarRatingDisplay(default) { Size = new Vector2(52f, 16f) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -10,12 +10,12 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Beatmaps.Drawables;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Screens.Play.HUD;
|
using osu.Game.Screens.Play.HUD;
|
||||||
using osu.Game.Screens.Ranking.Expanded;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play
|
namespace osu.Game.Screens.Play
|
||||||
|
@ -9,6 +9,7 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Beatmaps.Drawables;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
@ -1,129 +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.Globalization;
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Shapes;
|
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Graphics.UserInterface;
|
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osu.Game.Graphics.Containers;
|
|
||||||
using osuTK;
|
|
||||||
using osuTK.Graphics;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.Ranking.Expanded
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A pill that displays the star rating of a <see cref="BeatmapInfo"/>.
|
|
||||||
/// </summary>
|
|
||||||
public class StarRatingDisplay : CompositeDrawable, IHasCurrentValue<StarDifficulty>
|
|
||||||
{
|
|
||||||
private Box background;
|
|
||||||
private FillFlowContainer content;
|
|
||||||
private OsuTextFlowContainer textFlow;
|
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private OsuColour colours { get; set; }
|
|
||||||
|
|
||||||
private readonly BindableWithCurrent<StarDifficulty> current = new BindableWithCurrent<StarDifficulty>();
|
|
||||||
|
|
||||||
public Bindable<StarDifficulty> Current
|
|
||||||
{
|
|
||||||
get => current.Current;
|
|
||||||
set => current.Current = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new <see cref="StarRatingDisplay"/> using an already computed <see cref="StarDifficulty"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="starDifficulty">The already computed <see cref="StarDifficulty"/> to display the star difficulty of.</param>
|
|
||||||
public StarRatingDisplay(StarDifficulty starDifficulty)
|
|
||||||
{
|
|
||||||
Current.Value = starDifficulty;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache)
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both;
|
|
||||||
|
|
||||||
InternalChildren = new Drawable[]
|
|
||||||
{
|
|
||||||
new CircularContainer
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Masking = true,
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
background = new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
content = new FillFlowContainer
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Padding = new MarginPadding { Horizontal = 8, Vertical = 4 },
|
|
||||||
Direction = FillDirection.Horizontal,
|
|
||||||
Spacing = new Vector2(2, 0),
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
new SpriteIcon
|
|
||||||
{
|
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
Size = new Vector2(7),
|
|
||||||
Icon = FontAwesome.Solid.Star,
|
|
||||||
},
|
|
||||||
textFlow = new OsuTextFlowContainer(s => s.Font = OsuFont.Numeric.With(weight: FontWeight.Black))
|
|
||||||
{
|
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Direction = FillDirection.Horizontal,
|
|
||||||
TextAnchor = Anchor.BottomLeft,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
|
|
||||||
Current.BindValueChanged(_ => updateDisplay(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDisplay()
|
|
||||||
{
|
|
||||||
var starRatingParts = Current.Value.Stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.');
|
|
||||||
string wholePart = starRatingParts[0];
|
|
||||||
string fractionPart = starRatingParts[1];
|
|
||||||
string separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
|
|
||||||
|
|
||||||
var stars = Current.Value.Stars;
|
|
||||||
|
|
||||||
background.Colour = colours.ForStarDifficulty(stars);
|
|
||||||
content.Colour = stars >= 6.5 ? colours.Orange1 : Color4.Black;
|
|
||||||
|
|
||||||
textFlow.Clear();
|
|
||||||
textFlow.AddText($"{wholePart}", s =>
|
|
||||||
{
|
|
||||||
s.Font = s.Font.With(size: 14);
|
|
||||||
s.UseFullGlyphHeight = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
textFlow.AddText($"{separator}{fractionPart}", s =>
|
|
||||||
{
|
|
||||||
s.Font = s.Font.With(size: 7);
|
|
||||||
s.UseFullGlyphHeight = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -28,7 +28,6 @@ using osu.Game.Extensions;
|
|||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
using osu.Game.Screens.Ranking.Expanded;
|
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Select
|
namespace osu.Game.Screens.Select
|
||||||
|
Loading…
Reference in New Issue
Block a user