2023-08-28 20:16:33 +00: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.
|
|
|
|
|
|
2023-09-08 17:32:55 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
2023-09-02 23:09:01 +00:00
|
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-09-02 23:09:01 +00:00
|
|
|
|
using osu.Framework.Graphics.Colour;
|
2023-11-04 15:47:02 +00:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2023-09-02 23:09:01 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2023-09-02 23:09:01 +00:00
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2023-09-12 13:44:44 +00:00
|
|
|
|
using osu.Game.Rulesets;
|
2023-09-08 17:32:55 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2023-09-08 17:32:55 +00:00
|
|
|
|
using System.Threading;
|
2023-09-11 08:59:19 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2023-09-11 06:44:25 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2023-11-04 15:47:02 +00:00
|
|
|
|
using osu.Game.Rulesets.Difficulty;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
|
{
|
2023-09-12 08:15:16 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// On the mod select overlay, this provides a local updating view of BPM, star rating and other
|
|
|
|
|
/// difficulty attributes so the user can have a better insight into what mods are changing.
|
|
|
|
|
/// </summary>
|
2023-11-04 15:47:02 +00:00
|
|
|
|
public partial class BeatmapAttributesDisplay : CompositeDrawable, IHasTooltip
|
2023-08-28 20:16:33 +00:00
|
|
|
|
{
|
2023-09-11 06:26:05 +00:00
|
|
|
|
private Container content = null!;
|
|
|
|
|
private Container innerContent = null!;
|
2023-09-02 23:09:01 +00:00
|
|
|
|
|
2023-09-11 06:26:05 +00:00
|
|
|
|
private Box background = null!;
|
|
|
|
|
private Box innerBackground = null!;
|
2023-09-02 23:09:01 +00:00
|
|
|
|
|
2023-09-11 06:26:05 +00:00
|
|
|
|
private StarRatingDisplay starRatingDisplay = null!;
|
|
|
|
|
private BPMDisplay bpmDisplay = null!;
|
2023-09-02 23:09:01 +00:00
|
|
|
|
|
2023-09-11 08:16:24 +00:00
|
|
|
|
private FillFlowContainer<VerticalAttributeDisplay> outerContent = null!;
|
2023-09-11 06:26:05 +00:00
|
|
|
|
private VerticalAttributeDisplay circleSizeDisplay = null!;
|
|
|
|
|
private VerticalAttributeDisplay drainRateDisplay = null!;
|
|
|
|
|
private VerticalAttributeDisplay approachRateDisplay = null!;
|
|
|
|
|
private VerticalAttributeDisplay overallDifficultyDisplay = null!;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
|
2023-09-08 17:32:55 +00:00
|
|
|
|
private const float transition_duration = 250;
|
|
|
|
|
|
2023-09-11 06:44:25 +00:00
|
|
|
|
public Bindable<IBeatmapInfo?> BeatmapInfo { get; } = new Bindable<IBeatmapInfo?>();
|
2023-09-08 17:32:55 +00:00
|
|
|
|
|
2023-09-11 08:46:07 +00:00
|
|
|
|
public BindableBool Collapsed { get; } = new BindableBool(true);
|
2023-09-11 08:16:24 +00:00
|
|
|
|
|
2023-09-08 17:32:55 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private Bindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
|
|
|
|
|
|
2023-09-11 06:44:25 +00:00
|
|
|
|
private ModSettingChangeTracker? modSettingChangeTracker;
|
|
|
|
|
|
2023-08-28 20:16:33 +00:00
|
|
|
|
[Resolved]
|
2023-09-08 17:32:55 +00:00
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
2023-09-08 17:32:55 +00:00
|
|
|
|
private BeatmapDifficultyCache difficultyCache { get; set; } = null!;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
|
2023-09-12 13:44:44 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuGameBase game { get; set; } = null!;
|
|
|
|
|
private IBindable<RulesetInfo> gameRuleset = null!;
|
|
|
|
|
|
2023-09-11 06:26:05 +00:00
|
|
|
|
private CancellationTokenSource? cancellationSource;
|
2023-09-08 17:32:55 +00:00
|
|
|
|
private IBindable<StarDifficulty?> starDifficulty = null!;
|
|
|
|
|
|
2023-11-04 15:47:02 +00:00
|
|
|
|
private BeatmapDifficulty? baseDifficultyAttributes = null;
|
|
|
|
|
|
|
|
|
|
private bool haveRateChangedValues = false;
|
|
|
|
|
|
2023-09-11 06:26:05 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2023-09-02 23:09:01 +00:00
|
|
|
|
{
|
|
|
|
|
const float shear = ShearedOverlayContainer.SHEAR;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
|
2023-09-03 11:51:53 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2023-09-11 08:59:19 +00:00
|
|
|
|
InternalChild = content = new Container
|
2023-09-02 23:09:01 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
2023-09-11 06:29:37 +00:00
|
|
|
|
Height = ShearedButton.HEIGHT,
|
2023-09-02 23:09:01 +00:00
|
|
|
|
Shear = new Vector2(shear, 0),
|
2023-09-11 06:29:37 +00:00
|
|
|
|
CornerRadius = ShearedButton.CORNER_RADIUS,
|
|
|
|
|
BorderThickness = ShearedButton.BORDER_THICKNESS,
|
2023-09-02 23:09:01 +00:00
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer // divide inner and outer content
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
innerContent = new Container
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2023-09-11 06:29:37 +00:00
|
|
|
|
BorderThickness = ShearedButton.BORDER_THICKNESS,
|
|
|
|
|
CornerRadius = ShearedButton.CORNER_RADIUS,
|
2023-09-02 23:09:01 +00:00
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
innerBackground = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
2023-09-11 07:37:25 +00:00
|
|
|
|
new Container // actual inner content
|
2023-09-02 23:09:01 +00:00
|
|
|
|
{
|
2023-09-11 07:37:25 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Width = 140,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2023-09-02 23:09:01 +00:00
|
|
|
|
Margin = new MarginPadding { Horizontal = 15 },
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2023-09-11 07:37:25 +00:00
|
|
|
|
starRatingDisplay = new StarRatingDisplay(default, animated: true)
|
2023-09-02 23:09:01 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
2023-09-11 07:37:25 +00:00
|
|
|
|
Shear = new Vector2(-shear, 0),
|
|
|
|
|
},
|
|
|
|
|
bpmDisplay = new BPMDisplay
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Shear = new Vector2(-shear, 0),
|
2023-09-02 23:09:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-09-11 08:16:24 +00:00
|
|
|
|
outerContent = new FillFlowContainer<VerticalAttributeDisplay>
|
2023-09-02 23:09:01 +00:00
|
|
|
|
{
|
2023-09-12 08:00:06 +00:00
|
|
|
|
Alpha = 0,
|
2023-09-02 23:09:01 +00:00
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2023-09-12 08:06:42 +00:00
|
|
|
|
circleSizeDisplay = new VerticalAttributeDisplay("CS")
|
|
|
|
|
{
|
|
|
|
|
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
|
|
|
|
|
},
|
|
|
|
|
drainRateDisplay = new VerticalAttributeDisplay("HP")
|
|
|
|
|
{
|
|
|
|
|
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
|
|
|
|
|
},
|
|
|
|
|
approachRateDisplay = new VerticalAttributeDisplay("AR")
|
|
|
|
|
{
|
|
|
|
|
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
|
|
|
|
|
},
|
|
|
|
|
overallDifficultyDisplay = new VerticalAttributeDisplay("OD")
|
|
|
|
|
{
|
|
|
|
|
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
|
|
|
|
|
},
|
2023-09-02 23:09:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2023-09-11 06:26:05 +00:00
|
|
|
|
|
2023-08-28 20:16:33 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
2023-09-02 23:09:01 +00:00
|
|
|
|
background.Colour = colourProvider.Background4;
|
|
|
|
|
innerBackground.Colour = colourProvider.Background3;
|
2023-09-11 06:26:05 +00:00
|
|
|
|
Color4 glowColour = colourProvider.Background1;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
|
2023-09-11 06:26:05 +00:00
|
|
|
|
content.BorderColour = ColourInfo.GradientVertical(background.Colour, glowColour);
|
|
|
|
|
innerContent.BorderColour = ColourInfo.GradientVertical(innerBackground.Colour, glowColour);
|
2023-09-08 17:32:55 +00:00
|
|
|
|
|
2023-09-11 06:44:25 +00:00
|
|
|
|
mods.BindValueChanged(_ =>
|
|
|
|
|
{
|
|
|
|
|
modSettingChangeTracker?.Dispose();
|
|
|
|
|
|
|
|
|
|
modSettingChangeTracker = new ModSettingChangeTracker(mods.Value);
|
|
|
|
|
modSettingChangeTracker.SettingChanged += _ => updateValues();
|
|
|
|
|
updateValues();
|
2023-09-11 08:16:09 +00:00
|
|
|
|
}, true);
|
2023-09-11 08:16:24 +00:00
|
|
|
|
|
2023-09-12 08:00:06 +00:00
|
|
|
|
Collapsed.BindValueChanged(_ =>
|
|
|
|
|
{
|
|
|
|
|
// Only start autosize animations on first collapse toggle. This avoids an ugly initial presentation.
|
|
|
|
|
startAnimating();
|
|
|
|
|
|
|
|
|
|
updateCollapsedState();
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-12 13:44:44 +00:00
|
|
|
|
gameRuleset = game.Ruleset.GetBoundCopy();
|
|
|
|
|
gameRuleset.BindValueChanged(_ => updateValues());
|
|
|
|
|
|
2023-09-12 08:00:06 +00:00
|
|
|
|
BeatmapInfo.BindValueChanged(_ => updateValues(), true);
|
2023-08-28 20:16:33 +00:00
|
|
|
|
}
|
2023-09-11 06:26:05 +00:00
|
|
|
|
|
2023-09-11 08:59:19 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
2023-09-12 08:00:06 +00:00
|
|
|
|
startAnimating();
|
2023-09-11 08:59:19 +00:00
|
|
|
|
updateCollapsedState();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
|
|
|
|
updateCollapsedState();
|
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e) => true;
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e) => true;
|
|
|
|
|
|
2023-09-12 08:00:06 +00:00
|
|
|
|
private void startAnimating()
|
|
|
|
|
{
|
|
|
|
|
content.AutoSizeEasing = Easing.OutQuint;
|
|
|
|
|
content.AutoSizeDuration = transition_duration;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 06:44:25 +00:00
|
|
|
|
private void updateValues() => Scheduler.AddOnce(() =>
|
2023-09-08 17:32:55 +00:00
|
|
|
|
{
|
2023-09-11 06:44:25 +00:00
|
|
|
|
if (BeatmapInfo.Value == null)
|
2023-09-11 06:26:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cancellationSource?.Cancel();
|
2023-09-12 08:00:06 +00:00
|
|
|
|
|
2023-09-11 06:44:25 +00:00
|
|
|
|
starDifficulty = difficultyCache.GetBindableDifficulty(BeatmapInfo.Value, (cancellationSource = new CancellationTokenSource()).Token);
|
2023-09-08 17:32:55 +00:00
|
|
|
|
starDifficulty.BindValueChanged(s =>
|
|
|
|
|
{
|
|
|
|
|
starRatingDisplay.Current.Value = s.NewValue ?? default;
|
2023-08-28 20:16:33 +00:00
|
|
|
|
|
2023-09-08 17:32:55 +00:00
|
|
|
|
if (!starRatingDisplay.IsPresent)
|
|
|
|
|
starRatingDisplay.FinishTransforms(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
double rate = 1;
|
|
|
|
|
foreach (var mod in mods.Value.OfType<IApplicableToRate>())
|
|
|
|
|
rate = mod.ApplyToRate(0, rate);
|
|
|
|
|
|
2023-09-11 06:44:25 +00:00
|
|
|
|
bpmDisplay.Current.Value = BeatmapInfo.Value.BPM * rate;
|
2023-09-02 23:09:01 +00:00
|
|
|
|
|
2023-11-04 15:25:09 +00:00
|
|
|
|
var moddedDifficulty = new BeatmapDifficulty(BeatmapInfo.Value.Difficulty);
|
|
|
|
|
|
|
|
|
|
foreach (var mod in mods.Value.OfType<IApplicableToDifficulty>())
|
|
|
|
|
mod.ApplyToDifficulty(moddedDifficulty);
|
2023-09-12 13:44:44 +00:00
|
|
|
|
|
2023-11-04 15:47:02 +00:00
|
|
|
|
baseDifficultyAttributes = moddedDifficulty;
|
|
|
|
|
|
2023-09-12 13:44:44 +00:00
|
|
|
|
Ruleset ruleset = gameRuleset.Value.CreateInstance();
|
2023-11-04 15:25:09 +00:00
|
|
|
|
var rateAdjustedDifficulty = ruleset.GetRateAdjustedDifficulty(moddedDifficulty, rate);
|
|
|
|
|
|
2023-11-04 15:47:02 +00:00
|
|
|
|
haveRateChangedValues = !haveEqualDifficulties(rateAdjustedDifficulty, moddedDifficulty);
|
|
|
|
|
|
2023-11-04 15:25:09 +00:00
|
|
|
|
approachRateDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(moddedDifficulty.ApproachRate, rateAdjustedDifficulty.ApproachRate);
|
|
|
|
|
overallDifficultyDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(moddedDifficulty.OverallDifficulty, rateAdjustedDifficulty.OverallDifficulty);
|
|
|
|
|
|
|
|
|
|
circleSizeDisplay.Current.Value = rateAdjustedDifficulty.CircleSize;
|
|
|
|
|
drainRateDisplay.Current.Value = rateAdjustedDifficulty.DrainRate;
|
|
|
|
|
approachRateDisplay.Current.Value = rateAdjustedDifficulty.ApproachRate;
|
|
|
|
|
overallDifficultyDisplay.Current.Value = rateAdjustedDifficulty.OverallDifficulty;
|
2023-09-11 06:44:25 +00:00
|
|
|
|
});
|
2023-09-02 23:09:01 +00:00
|
|
|
|
|
2023-11-04 15:47:02 +00:00
|
|
|
|
private bool haveEqualDifficulties(BeatmapDifficulty? a, BeatmapDifficulty? b)
|
|
|
|
|
{
|
|
|
|
|
if (a == null && b == null) return true;
|
|
|
|
|
if (a == null || b == null) return false;
|
|
|
|
|
|
|
|
|
|
if (a.ApproachRate != b.ApproachRate) return false;
|
|
|
|
|
if (a.OverallDifficulty != b.OverallDifficulty) return false;
|
|
|
|
|
if (a.DrainRate != b.DrainRate) return false;
|
|
|
|
|
if (a.CircleSize != b.CircleSize) return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 08:59:19 +00:00
|
|
|
|
private void updateCollapsedState()
|
|
|
|
|
{
|
|
|
|
|
outerContent.FadeTo(Collapsed.Value && !IsHovered ? 0 : 1, transition_duration, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-02 23:09:01 +00:00
|
|
|
|
private partial class BPMDisplay : RollingCounter<double>
|
|
|
|
|
{
|
|
|
|
|
protected override double RollingDuration => 500;
|
|
|
|
|
|
|
|
|
|
protected override LocalisableString FormatCount(double count) => count.ToLocalisableString("0 BPM");
|
|
|
|
|
|
|
|
|
|
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText
|
|
|
|
|
{
|
2023-09-11 07:37:25 +00:00
|
|
|
|
Font = OsuFont.Default.With(size: 20, weight: FontWeight.SemiBold),
|
|
|
|
|
UseFullGlyphHeight = false,
|
2023-09-02 23:09:01 +00:00
|
|
|
|
};
|
2023-08-28 20:16:33 +00:00
|
|
|
|
}
|
2023-11-04 15:47:02 +00:00
|
|
|
|
|
|
|
|
|
public LocalisableString TooltipText
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (haveRateChangedValues)
|
|
|
|
|
{
|
|
|
|
|
return "Some of the values are Rate-Adjusted.";
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-28 20:16:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|