2023-08-29 04:16:33 +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.
|
|
|
|
|
|
2023-09-09 01:32:55 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2023-11-12 14:47:20 +08:00
|
|
|
|
using System.Threading;
|
2023-08-29 04:16:33 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
2023-09-03 07:09:01 +08:00
|
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2023-08-29 04:16:33 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2023-11-04 23:47:02 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2023-11-05 03:55:46 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2023-09-03 07:09:01 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2023-08-29 04:16:33 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2023-09-03 07:09:01 +08:00
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2024-02-27 02:26:35 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2023-08-29 04:16:33 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2023-09-12 21:44:44 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
2023-09-09 01:32:55 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2024-02-22 17:27:37 +08:00
|
|
|
|
using osu.Game.Utils;
|
2023-08-29 04:16:33 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
|
{
|
2023-09-12 16:15:16 +08: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-12-14 23:11:08 +08:00
|
|
|
|
public partial class BeatmapAttributesDisplay : ModFooterInformationDisplay, IHasCustomTooltip<AdjustedAttributesTooltip.Data?>
|
2023-08-29 04:16:33 +08:00
|
|
|
|
{
|
2023-09-11 14:26:05 +08:00
|
|
|
|
private StarRatingDisplay starRatingDisplay = null!;
|
|
|
|
|
private BPMDisplay bpmDisplay = null!;
|
2023-09-03 07:09:01 +08:00
|
|
|
|
|
2023-09-11 14:26:05 +08:00
|
|
|
|
private VerticalAttributeDisplay circleSizeDisplay = null!;
|
|
|
|
|
private VerticalAttributeDisplay drainRateDisplay = null!;
|
|
|
|
|
private VerticalAttributeDisplay approachRateDisplay = null!;
|
|
|
|
|
private VerticalAttributeDisplay overallDifficultyDisplay = null!;
|
2023-08-29 04:16:33 +08:00
|
|
|
|
|
2023-09-11 14:44:25 +08:00
|
|
|
|
public Bindable<IBeatmapInfo?> BeatmapInfo { get; } = new Bindable<IBeatmapInfo?>();
|
2023-09-09 01:32:55 +08:00
|
|
|
|
|
2024-02-23 22:28:54 +08:00
|
|
|
|
public Bindable<IReadOnlyList<Mod>> Mods { get; } = new Bindable<IReadOnlyList<Mod>>();
|
2024-02-18 04:12:15 +08:00
|
|
|
|
|
2023-09-14 20:56:58 +08:00
|
|
|
|
public BindableBool Collapsed { get; } = new BindableBool(true);
|
2023-09-11 14:44:25 +08:00
|
|
|
|
|
2024-02-27 02:26:35 +08:00
|
|
|
|
private ModSettingChangeTracker? modSettingChangeTracker;
|
|
|
|
|
|
2023-08-29 04:16:33 +08:00
|
|
|
|
[Resolved]
|
2023-09-09 01:32:55 +08:00
|
|
|
|
private BeatmapDifficultyCache difficultyCache { get; set; } = null!;
|
2023-08-29 04:16:33 +08:00
|
|
|
|
|
2023-09-12 21:44:44 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuGameBase game { get; set; } = null!;
|
2023-11-12 14:47:20 +08:00
|
|
|
|
|
2024-02-18 09:13:57 +08:00
|
|
|
|
protected IBindable<RulesetInfo> GameRuleset = null!;
|
2023-09-12 21:44:44 +08:00
|
|
|
|
|
2023-09-11 14:26:05 +08:00
|
|
|
|
private CancellationTokenSource? cancellationSource;
|
2023-09-09 01:32:55 +08:00
|
|
|
|
private IBindable<StarDifficulty?> starDifficulty = null!;
|
|
|
|
|
|
2023-12-14 23:11:08 +08:00
|
|
|
|
public ITooltip<AdjustedAttributesTooltip.Data?> GetCustomTooltip() => new AdjustedAttributesTooltip();
|
2023-11-24 05:30:18 +08:00
|
|
|
|
|
2023-12-14 23:11:08 +08:00
|
|
|
|
public AdjustedAttributesTooltip.Data? TooltipContent { get; private set; }
|
2023-11-12 15:15:33 +08:00
|
|
|
|
|
2023-09-14 20:56:58 +08:00
|
|
|
|
private const float transition_duration = 250;
|
2023-11-04 23:47:02 +08:00
|
|
|
|
|
2023-09-11 14:26:05 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2023-09-03 07:09:01 +08:00
|
|
|
|
{
|
2024-05-16 12:27:54 +08:00
|
|
|
|
const float shear = OsuGame.SHEAR;
|
2023-08-29 04:16:33 +08:00
|
|
|
|
|
2023-09-13 18:33:30 +08:00
|
|
|
|
LeftContent.AddRange(new Drawable[]
|
2023-09-03 07:09:01 +08:00
|
|
|
|
{
|
2023-09-13 18:33:30 +08:00
|
|
|
|
starRatingDisplay = new StarRatingDisplay(default, animated: true)
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Shear = new Vector2(-shear, 0),
|
|
|
|
|
},
|
|
|
|
|
bpmDisplay = new BPMDisplay
|
2023-09-03 07:09:01 +08:00
|
|
|
|
{
|
2023-09-13 18:33:30 +08:00
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Shear = new Vector2(-shear, 0),
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Width = 75,
|
2023-09-03 07:09:01 +08:00
|
|
|
|
}
|
2023-09-13 18:33:30 +08:00
|
|
|
|
});
|
|
|
|
|
|
2023-09-14 20:56:58 +08:00
|
|
|
|
RightContent.Alpha = 0;
|
2023-09-13 18:33:30 +08:00
|
|
|
|
RightContent.AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
circleSizeDisplay = new VerticalAttributeDisplay("CS") { Shear = new Vector2(-shear, 0), },
|
|
|
|
|
drainRateDisplay = new VerticalAttributeDisplay("HP") { Shear = new Vector2(-shear, 0), },
|
|
|
|
|
overallDifficultyDisplay = new VerticalAttributeDisplay("OD") { Shear = new Vector2(-shear, 0), },
|
2023-12-14 20:31:19 +08:00
|
|
|
|
approachRateDisplay = new VerticalAttributeDisplay("AR") { Shear = new Vector2(-shear, 0), },
|
2023-09-13 18:33:30 +08:00
|
|
|
|
});
|
2023-09-03 07:09:01 +08:00
|
|
|
|
}
|
2023-09-11 14:26:05 +08:00
|
|
|
|
|
2023-08-29 04:16:33 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
2023-09-13 18:33:30 +08:00
|
|
|
|
base.LoadComplete();
|
2023-09-09 01:32:55 +08:00
|
|
|
|
|
2024-02-27 02:26:35 +08:00
|
|
|
|
Mods.BindValueChanged(_ =>
|
|
|
|
|
{
|
|
|
|
|
modSettingChangeTracker?.Dispose();
|
|
|
|
|
modSettingChangeTracker = new ModSettingChangeTracker(Mods.Value);
|
|
|
|
|
modSettingChangeTracker.SettingChanged += _ => updateValues();
|
|
|
|
|
updateValues();
|
|
|
|
|
}, true);
|
|
|
|
|
|
2024-02-23 22:28:54 +08:00
|
|
|
|
BeatmapInfo.BindValueChanged(_ => updateValues());
|
2023-09-14 20:56:58 +08:00
|
|
|
|
|
2023-09-12 16:00:06 +08:00
|
|
|
|
Collapsed.BindValueChanged(_ =>
|
|
|
|
|
{
|
|
|
|
|
// Only start autosize animations on first collapse toggle. This avoids an ugly initial presentation.
|
|
|
|
|
startAnimating();
|
|
|
|
|
updateCollapsedState();
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-18 09:13:57 +08:00
|
|
|
|
GameRuleset = game.Ruleset.GetBoundCopy();
|
|
|
|
|
GameRuleset.BindValueChanged(_ => updateValues());
|
2023-09-12 21:44:44 +08:00
|
|
|
|
|
2024-02-23 22:28:54 +08:00
|
|
|
|
BeatmapInfo.BindValueChanged(_ => updateValues());
|
2023-11-12 14:47:20 +08:00
|
|
|
|
|
2024-02-23 22:28:54 +08:00
|
|
|
|
updateValues();
|
2023-09-14 20:56:58 +08:00
|
|
|
|
updateCollapsedState();
|
2023-08-29 04:16:33 +08:00
|
|
|
|
}
|
2023-09-11 14:26:05 +08:00
|
|
|
|
|
2023-09-11 16:59:19 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
2023-09-12 16:00:06 +08:00
|
|
|
|
startAnimating();
|
2023-09-11 16:59:19 +08: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 16:00:06 +08:00
|
|
|
|
private void startAnimating()
|
|
|
|
|
{
|
2023-12-15 15:01:07 +08:00
|
|
|
|
LeftContent.AutoSizeEasing = Content.AutoSizeEasing = Easing.OutQuint;
|
|
|
|
|
LeftContent.AutoSizeDuration = Content.AutoSizeDuration = transition_duration;
|
2023-09-12 16:00:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 14:44:25 +08:00
|
|
|
|
private void updateValues() => Scheduler.AddOnce(() =>
|
2023-09-09 01:32:55 +08:00
|
|
|
|
{
|
2023-09-11 14:44:25 +08:00
|
|
|
|
if (BeatmapInfo.Value == null)
|
2023-09-11 14:26:05 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cancellationSource?.Cancel();
|
2023-09-12 16:00:06 +08:00
|
|
|
|
|
2023-09-11 14:44:25 +08:00
|
|
|
|
starDifficulty = difficultyCache.GetBindableDifficulty(BeatmapInfo.Value, (cancellationSource = new CancellationTokenSource()).Token);
|
2023-09-09 01:32:55 +08:00
|
|
|
|
starDifficulty.BindValueChanged(s =>
|
|
|
|
|
{
|
|
|
|
|
starRatingDisplay.Current.Value = s.NewValue ?? default;
|
2023-08-29 04:16:33 +08:00
|
|
|
|
|
2023-09-09 01:32:55 +08:00
|
|
|
|
if (!starRatingDisplay.IsPresent)
|
|
|
|
|
starRatingDisplay.FinishTransforms(true);
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-06 23:59:15 +08:00
|
|
|
|
double rate = ModUtils.CalculateRateWithMods(Mods.Value);
|
2024-02-20 18:57:28 +08:00
|
|
|
|
|
2024-02-22 17:27:37 +08:00
|
|
|
|
bpmDisplay.Current.Value = FormatUtils.RoundBPM(BeatmapInfo.Value.BPM, rate);
|
2024-02-20 18:57:28 +08:00
|
|
|
|
|
|
|
|
|
BeatmapDifficulty originalDifficulty = new BeatmapDifficulty(BeatmapInfo.Value.Difficulty);
|
|
|
|
|
|
2024-02-23 22:28:54 +08:00
|
|
|
|
foreach (var mod in Mods.Value.OfType<IApplicableToDifficulty>())
|
2024-02-20 18:57:28 +08:00
|
|
|
|
mod.ApplyToDifficulty(originalDifficulty);
|
2024-02-18 05:01:31 +08:00
|
|
|
|
|
2024-02-18 09:13:57 +08:00
|
|
|
|
Ruleset ruleset = GameRuleset.Value.CreateInstance();
|
2023-11-24 05:30:18 +08:00
|
|
|
|
BeatmapDifficulty adjustedDifficulty = ruleset.GetRateAdjustedDisplayDifficulty(originalDifficulty, rate);
|
2023-11-04 23:25:09 +08:00
|
|
|
|
|
2023-12-14 23:11:08 +08:00
|
|
|
|
TooltipContent = new AdjustedAttributesTooltip.Data(originalDifficulty, adjustedDifficulty);
|
2023-11-04 23:47:02 +08:00
|
|
|
|
|
2023-11-05 03:55:46 +08:00
|
|
|
|
approachRateDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(originalDifficulty.ApproachRate, adjustedDifficulty.ApproachRate);
|
|
|
|
|
overallDifficultyDisplay.AdjustType.Value = VerticalAttributeDisplay.CalculateEffect(originalDifficulty.OverallDifficulty, adjustedDifficulty.OverallDifficulty);
|
2023-11-04 23:25:09 +08:00
|
|
|
|
|
2023-11-05 03:55:46 +08:00
|
|
|
|
circleSizeDisplay.Current.Value = adjustedDifficulty.CircleSize;
|
|
|
|
|
drainRateDisplay.Current.Value = adjustedDifficulty.DrainRate;
|
|
|
|
|
approachRateDisplay.Current.Value = adjustedDifficulty.ApproachRate;
|
|
|
|
|
overallDifficultyDisplay.Current.Value = adjustedDifficulty.OverallDifficulty;
|
2023-09-11 14:44:25 +08:00
|
|
|
|
});
|
2023-09-03 07:09:01 +08:00
|
|
|
|
|
2023-11-12 15:15:33 +08:00
|
|
|
|
private void updateCollapsedState()
|
2023-11-04 23:47:02 +08:00
|
|
|
|
{
|
2023-11-12 15:15:33 +08:00
|
|
|
|
RightContent.FadeTo(Collapsed.Value && !IsHovered ? 0 : 1, transition_duration, Easing.OutQuint);
|
|
|
|
|
}
|
2023-11-04 23:47:02 +08:00
|
|
|
|
|
2024-02-23 23:42:07 +08:00
|
|
|
|
public partial class BPMDisplay : RollingCounter<int>
|
2023-09-03 07:09:01 +08:00
|
|
|
|
{
|
2024-01-17 17:18:53 +08:00
|
|
|
|
protected override double RollingDuration => 250;
|
2023-09-03 07:09:01 +08:00
|
|
|
|
|
2024-02-19 06:59:56 +08:00
|
|
|
|
protected override LocalisableString FormatCount(int count) => count.ToLocalisableString("0 BPM");
|
2023-09-03 07:09:01 +08:00
|
|
|
|
|
|
|
|
|
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText
|
|
|
|
|
{
|
2023-09-13 18:33:30 +08:00
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
2023-09-11 15:37:25 +08:00
|
|
|
|
Font = OsuFont.Default.With(size: 20, weight: FontWeight.SemiBold),
|
|
|
|
|
UseFullGlyphHeight = false,
|
2023-09-03 07:09:01 +08:00
|
|
|
|
};
|
2023-08-29 04:16:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|