1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00

Merge pull request #18071 from frenzibyte/distance-spacing-osd

Display toast notification on editor distance spacing changes
This commit is contained in:
Dean Herbert 2022-05-04 18:42:00 +09:00 committed by GitHub
commit 0018408bdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,12 +3,18 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osu.Game.Overlays.OSD;
using osu.Game.Overlays.Settings.Sections;
using osu.Game.Rulesets.Objects;
using osuTK;
@ -36,6 +42,9 @@ namespace osu.Game.Rulesets.Edit
private ExpandableSlider<double, SizeSlider<double>> distanceSpacingSlider;
[Resolved(canBeNull: true)]
private OnScreenDisplay onScreenDisplay { get; set; }
protected DistancedHitObjectComposer(Ruleset ruleset)
: base(ruleset)
{
@ -67,11 +76,15 @@ namespace osu.Game.Rulesets.Edit
if (!DistanceSpacingMultiplier.Disabled)
{
DistanceSpacingMultiplier.Value = EditorBeatmap.BeatmapInfo.DistanceSpacing;
DistanceSpacingMultiplier.BindValueChanged(v =>
DistanceSpacingMultiplier.BindValueChanged(multiplier =>
{
distanceSpacingSlider.ContractedLabelText = $"D. S. ({v.NewValue:0.##x})";
distanceSpacingSlider.ExpandedLabelText = $"Distance Spacing ({v.NewValue:0.##x})";
EditorBeatmap.BeatmapInfo.DistanceSpacing = v.NewValue;
distanceSpacingSlider.ContractedLabelText = $"D. S. ({multiplier.NewValue:0.##x})";
distanceSpacingSlider.ExpandedLabelText = $"Distance Spacing ({multiplier.NewValue:0.##x})";
if (multiplier.NewValue != multiplier.OldValue)
onScreenDisplay?.Display(new DistanceSpacingToast(multiplier.NewValue.ToLocalisableString(@"0.##x"), multiplier));
EditorBeatmap.BeatmapInfo.DistanceSpacing = multiplier.NewValue;
}, true);
}
}
@ -168,5 +181,26 @@ namespace osu.Game.Rulesets.Edit
FillFlow.Spacing = new Vector2(10);
}
}
private class DistanceSpacingToast : Toast
{
private readonly ValueChangedEvent<double> change;
public DistanceSpacingToast(LocalisableString value, ValueChangedEvent<double> change)
: base(getAction(change).GetLocalisableDescription(), value, string.Empty)
{
this.change = change;
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
ShortcutText.Text = config.LookupKeyBindings(getAction(change)).ToUpper();
}
private static GlobalAction getAction(ValueChangedEvent<double> change) => change.NewValue - change.OldValue > 0
? GlobalAction.EditorIncreaseDistanceSpacing
: GlobalAction.EditorDecreaseDistanceSpacing;
}
}
}