mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 10:02:59 +08:00
Added bindable stardifficulty to StarRatingDisplay
This commit is contained in:
parent
505a117862
commit
6e72ee5f76
@ -1,8 +1,10 @@
|
||||
// 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;
|
||||
using System.Globalization;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
@ -22,7 +24,11 @@ namespace osu.Game.Screens.Ranking.Expanded
|
||||
/// </summary>
|
||||
public class StarRatingDisplay : CompositeDrawable
|
||||
{
|
||||
private readonly StarDifficulty difficulty;
|
||||
private CircularContainer colorContainer;
|
||||
private OsuTextFlowContainer textContainer;
|
||||
|
||||
private readonly StarDifficulty starDifficulty;
|
||||
private readonly IBindable<StarDifficulty?> bindableStarDifficulty;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="StarRatingDisplay"/> using an already computed <see cref="StarDifficulty"/>.
|
||||
@ -30,14 +36,21 @@ namespace osu.Game.Screens.Ranking.Expanded
|
||||
/// <param name="starDifficulty">The already computed <see cref="StarDifficulty"/> to display the star difficulty of.</param>
|
||||
public StarRatingDisplay(StarDifficulty starDifficulty)
|
||||
{
|
||||
difficulty = starDifficulty;
|
||||
this.starDifficulty = starDifficulty;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache)
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="StarRatingDisplay"/> using a binded nullable <see cref="StarDifficulty"/>.
|
||||
/// </summary>
|
||||
/// <param name="starDifficulty">The binded nullable <see cref="StarDifficulty"/> to display the star difficulty of. If <c>null</c>, a new instance of <see cref="StarDifficulty"/> will be created </param>
|
||||
public StarRatingDisplay(IBindable<StarDifficulty?> starDifficulty)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
bindableStarDifficulty = starDifficulty;
|
||||
}
|
||||
|
||||
private void setDifficulty(OsuColour colours)
|
||||
{
|
||||
var difficulty = bindableStarDifficulty == null ? starDifficulty : bindableStarDifficulty.Value ?? new StarDifficulty();
|
||||
var starRatingParts = difficulty.Stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.');
|
||||
string wholePart = starRatingParts[0];
|
||||
string fractionPart = starRatingParts[1];
|
||||
@ -47,9 +60,36 @@ namespace osu.Game.Screens.Ranking.Expanded
|
||||
? ColourInfo.GradientVertical(Color4Extensions.FromHex("#C1C1C1"), Color4Extensions.FromHex("#595959"))
|
||||
: (ColourInfo)colours.ForDifficultyRating(difficulty.DifficultyRating);
|
||||
|
||||
colorContainer.Colour = backgroundColour;
|
||||
|
||||
textContainer.Text = string.Empty;
|
||||
|
||||
textContainer.With(t =>
|
||||
{
|
||||
t.AddText($"{wholePart}", s =>
|
||||
{
|
||||
s.Colour = Color4.Black;
|
||||
s.Font = s.Font.With(size: 14);
|
||||
s.UseFullGlyphHeight = false;
|
||||
});
|
||||
|
||||
t.AddText($"{separator}{fractionPart}", s =>
|
||||
{
|
||||
s.Colour = Color4.Black;
|
||||
s.Font = s.Font.With(size: 7);
|
||||
s.UseFullGlyphHeight = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new CircularContainer
|
||||
colorContainer = new CircularContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
@ -58,7 +98,6 @@ namespace osu.Game.Screens.Ranking.Expanded
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = backgroundColour
|
||||
},
|
||||
}
|
||||
},
|
||||
@ -78,32 +117,24 @@ namespace osu.Game.Screens.Ranking.Expanded
|
||||
Icon = FontAwesome.Solid.Star,
|
||||
Colour = Color4.Black
|
||||
},
|
||||
new OsuTextFlowContainer(s => s.Font = OsuFont.Numeric.With(weight: FontWeight.Black))
|
||||
textContainer = 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,
|
||||
}.With(t =>
|
||||
{
|
||||
t.AddText($"{wholePart}", s =>
|
||||
{
|
||||
s.Colour = Color4.Black;
|
||||
s.Font = s.Font.With(size: 14);
|
||||
s.UseFullGlyphHeight = false;
|
||||
});
|
||||
|
||||
t.AddText($"{separator}{fractionPart}", s =>
|
||||
{
|
||||
s.Colour = Color4.Black;
|
||||
s.Font = s.Font.With(size: 7);
|
||||
s.UseFullGlyphHeight = false;
|
||||
});
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (bindableStarDifficulty != null)
|
||||
{
|
||||
bindableStarDifficulty.BindValueChanged(_ => setDifficulty(colours));
|
||||
}
|
||||
|
||||
setDifficulty(colours);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,6 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
beatmapDifficulty?.UnbindAll();
|
||||
beatmapDifficulty = difficultyCache.GetBindableDifficulty(beatmap.BeatmapInfo, cancellationSource.Token);
|
||||
beatmapDifficulty.BindValueChanged(_ => updateDisplay());
|
||||
|
||||
updateDisplay();
|
||||
}
|
||||
@ -151,7 +150,7 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
removeOldInfo();
|
||||
Add(Background = loaded);
|
||||
Add(Info = new WedgeInfoText(beatmap, ruleset.Value, mods.Value, beatmapDifficulty.Value ?? new StarDifficulty())
|
||||
Add(Info = new WedgeInfoText(beatmap, ruleset.Value, mods.Value, beatmapDifficulty)
|
||||
{
|
||||
Shear = -Shear
|
||||
});
|
||||
@ -176,15 +175,16 @@ namespace osu.Game.Screens.Select
|
||||
private ILocalisedBindableString titleBinding;
|
||||
private ILocalisedBindableString artistBinding;
|
||||
private FillFlowContainer infoLabelContainer;
|
||||
private Drawable starRatingDisplay;
|
||||
private Container bpmLabelContainer;
|
||||
private ModSettingChangeTracker settingChangeTracker;
|
||||
|
||||
private readonly WorkingBeatmap beatmap;
|
||||
private readonly RulesetInfo ruleset;
|
||||
private readonly IReadOnlyList<Mod> mods;
|
||||
private readonly StarDifficulty starDifficulty;
|
||||
private readonly IBindable<StarDifficulty?> starDifficulty;
|
||||
|
||||
public WedgeInfoText(WorkingBeatmap beatmap, RulesetInfo userRuleset, IReadOnlyList<Mod> mods, StarDifficulty difficulty)
|
||||
public WedgeInfoText(WorkingBeatmap beatmap, RulesetInfo userRuleset, IReadOnlyList<Mod> mods, IBindable<StarDifficulty?> difficulty)
|
||||
{
|
||||
this.beatmap = beatmap;
|
||||
ruleset = userRuleset ?? beatmap.BeatmapInfo.Ruleset;
|
||||
@ -241,12 +241,13 @@ namespace osu.Game.Screens.Select
|
||||
Shear = wedged_container_shear,
|
||||
Children = new[]
|
||||
{
|
||||
createStarRatingDisplay(starDifficulty).With(display =>
|
||||
starRatingDisplay = new StarRatingDisplay(starDifficulty)
|
||||
{
|
||||
display.Anchor = Anchor.TopRight;
|
||||
display.Origin = Anchor.TopRight;
|
||||
display.Shear = -wedged_container_shear;
|
||||
}),
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
Shear = -wedged_container_shear,
|
||||
Margin = new MarginPadding { Bottom = 5 }
|
||||
},
|
||||
StatusPill = new BeatmapSetOnlineStatusPill
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
@ -309,6 +310,18 @@ namespace osu.Game.Screens.Select
|
||||
addInfoLabels();
|
||||
}
|
||||
|
||||
private void setStarRatingDisplayVisibility()
|
||||
{
|
||||
if (starDifficulty.Value.HasValue && starDifficulty.Value.Value.Stars > 0)
|
||||
{
|
||||
starRatingDisplay.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
starRatingDisplay.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private InfoLabel[] getRulesetInfoLabels()
|
||||
{
|
||||
try
|
||||
@ -420,18 +433,14 @@ namespace osu.Game.Screens.Select
|
||||
};
|
||||
}
|
||||
|
||||
private static Drawable createStarRatingDisplay(StarDifficulty difficulty) => difficulty.Stars > 0
|
||||
? new StarRatingDisplay(difficulty)
|
||||
{
|
||||
Margin = new MarginPadding { Bottom = 5 }
|
||||
}
|
||||
: Empty();
|
||||
|
||||
private class DifficultyColourBar : Container
|
||||
{
|
||||
private readonly StarDifficulty difficulty;
|
||||
private Box solidDifficultyBox;
|
||||
private Box transparentDifficultyBox;
|
||||
|
||||
public DifficultyColourBar(StarDifficulty difficulty)
|
||||
private readonly IBindable<StarDifficulty?> difficulty;
|
||||
|
||||
public DifficultyColourBar(IBindable<StarDifficulty?> difficulty)
|
||||
{
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
@ -441,26 +450,33 @@ namespace osu.Game.Screens.Select
|
||||
{
|
||||
const float full_opacity_ratio = 0.7f;
|
||||
|
||||
var difficultyColour = colours.ForDifficultyRating(difficulty.DifficultyRating);
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
solidDifficultyBox = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = difficultyColour,
|
||||
Width = full_opacity_ratio,
|
||||
},
|
||||
new Box
|
||||
transparentDifficultyBox = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Colour = difficultyColour,
|
||||
Alpha = 0.5f,
|
||||
X = full_opacity_ratio,
|
||||
Width = 1 - full_opacity_ratio,
|
||||
}
|
||||
};
|
||||
|
||||
difficulty.BindValueChanged(_ => setColour(colours));
|
||||
setColour(colours);
|
||||
}
|
||||
|
||||
private void setColour(OsuColour colours)
|
||||
{
|
||||
var difficultyColour = colours.ForDifficultyRating(difficulty.Value?.DifficultyRating ?? (new StarDifficulty()).DifficultyRating);
|
||||
|
||||
solidDifficultyBox.Colour = difficultyColour;
|
||||
transparentDifficultyBox.Colour = difficultyColour;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user