2021-07-01 19:35:31 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-08-11 17:20:39 +08:00
|
|
|
using System;
|
2021-07-01 19:35:31 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-08-05 19:58:51 +08:00
|
|
|
using osu.Framework.Utils;
|
2021-07-01 19:35:31 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2021-07-17 11:54:11 +08:00
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2021-07-01 19:35:31 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Components
|
|
|
|
{
|
|
|
|
public partial class StarRatingRangeDisplay : OnlinePlayComposite
|
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
|
|
private StarRatingDisplay minDisplay;
|
|
|
|
private Drawable minBackground;
|
|
|
|
private StarRatingDisplay maxDisplay;
|
|
|
|
private Drawable maxBackground;
|
|
|
|
|
2021-08-04 22:06:07 +08:00
|
|
|
public StarRatingRangeDisplay()
|
2021-07-01 19:35:31 +08:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 1,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
minBackground = new Box
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Size = new Vector2(0.5f),
|
|
|
|
},
|
|
|
|
maxBackground = new Box
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Size = new Vector2(0.5f),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-08-18 16:36:27 +08:00
|
|
|
minDisplay = new StarRatingDisplay(default, StarRatingDisplaySize.Range),
|
|
|
|
maxDisplay = new StarRatingDisplay(default, StarRatingDisplaySize.Range)
|
2021-07-01 19:35:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-02-24 15:12:15 +08:00
|
|
|
DifficultyRange.BindValueChanged(_ => updateRange());
|
2022-06-24 20:25:23 +08:00
|
|
|
Playlist.BindCollectionChanged((_, _) => updateRange(), true);
|
2021-07-01 19:35:31 +08:00
|
|
|
}
|
|
|
|
|
2022-02-24 15:12:15 +08:00
|
|
|
private void updateRange()
|
2021-07-01 19:35:31 +08:00
|
|
|
{
|
2022-02-17 18:15:09 +08:00
|
|
|
StarDifficulty minDifficulty;
|
|
|
|
StarDifficulty maxDifficulty;
|
|
|
|
|
2023-05-14 18:09:15 +08:00
|
|
|
if (DifficultyRange.Value != null && Playlist.Count == 0)
|
2022-02-17 18:15:09 +08:00
|
|
|
{
|
2023-05-14 18:09:15 +08:00
|
|
|
// When Playlist is empty (in lounge) we take retrieved range
|
2022-02-24 15:12:15 +08:00
|
|
|
minDifficulty = new StarDifficulty(DifficultyRange.Value.Min, 0);
|
|
|
|
maxDifficulty = new StarDifficulty(DifficultyRange.Value.Max, 0);
|
2022-02-17 18:15:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-14 18:09:15 +08:00
|
|
|
// When Playlist is not empty (in room) we compute actual range
|
2022-02-17 18:15:09 +08:00
|
|
|
var orderedDifficulties = Playlist.Select(p => p.Beatmap).OrderBy(b => b.StarRating).ToArray();
|
2021-07-01 19:35:31 +08:00
|
|
|
|
2022-02-17 18:15:09 +08:00
|
|
|
minDifficulty = new StarDifficulty(orderedDifficulties.Length > 0 ? orderedDifficulties[0].StarRating : 0, 0);
|
|
|
|
maxDifficulty = new StarDifficulty(orderedDifficulties.Length > 0 ? orderedDifficulties[^1].StarRating : 0, 0);
|
|
|
|
}
|
2021-07-01 19:35:31 +08:00
|
|
|
|
|
|
|
minDisplay.Current.Value = minDifficulty;
|
|
|
|
maxDisplay.Current.Value = maxDifficulty;
|
2021-08-11 17:20:39 +08:00
|
|
|
maxDisplay.Alpha = Precision.AlmostEquals(Math.Round(minDifficulty.Stars, 2), Math.Round(maxDifficulty.Stars, 2)) ? 0 : 1;
|
2021-07-01 19:35:31 +08:00
|
|
|
|
2021-08-03 19:17:02 +08:00
|
|
|
minBackground.Colour = colours.ForStarDifficulty(minDifficulty.Stars);
|
|
|
|
maxBackground.Colour = colours.ForStarDifficulty(maxDifficulty.Stars);
|
2021-07-01 19:35:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|