mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Encapsulate distance spacing control handling to a "distance toolbox composite"
Encapsulated in a way which can allow further extensibility for the right-side area of toolboxes.
This commit is contained in:
@ -14,8 +14,6 @@ using osu.Framework.Input.Events;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays.Settings.Sections;
|
||||
using osu.Game.Rulesets.Configuration;
|
||||
using osu.Game.Rulesets.Edit.Tools;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
@ -58,26 +56,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
[Resolved]
|
||||
protected IBeatSnapProvider BeatSnapProvider { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this composer supports a "distance spacing" multiplier for distance snap grids.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Setting this to <see langword="true"/> displays a "distance spacing" slider and allows this composer to configure the value of <see cref="BeatmapInfo.DistanceSpacing"/>.
|
||||
/// </remarks>
|
||||
protected abstract bool SupportsDistanceSpacing { get; }
|
||||
|
||||
private readonly BindableDouble distanceSpacing = new BindableDouble
|
||||
{
|
||||
Default = 1.0,
|
||||
MinValue = 0.1,
|
||||
MaxValue = 6.0,
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
public override IBindable<double> DistanceSpacingMultiplier => distanceSpacing;
|
||||
|
||||
private SnappingToolboxContainer snappingToolboxContainer;
|
||||
|
||||
protected ComposeBlueprintContainer BlueprintContainer { get; private set; }
|
||||
|
||||
private DrawableEditorRulesetWrapper<TObject> drawableRulesetWrapper;
|
||||
@ -161,36 +139,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
},
|
||||
};
|
||||
|
||||
distanceSpacing.Value = EditorBeatmap.BeatmapInfo.DistanceSpacing;
|
||||
|
||||
if (SupportsDistanceSpacing)
|
||||
{
|
||||
ExpandableSlider<double, SizeSlider<double>> distanceSpacingSlider;
|
||||
|
||||
AddInternal(snappingToolboxContainer = new SnappingToolboxContainer
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
Child = new EditorToolboxGroup("snapping")
|
||||
{
|
||||
Child = distanceSpacingSlider = new ExpandableSlider<double, SizeSlider<double>>
|
||||
{
|
||||
Current = { BindTarget = distanceSpacing },
|
||||
KeyboardStep = 0.01f,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
distanceSpacing.BindValueChanged(v =>
|
||||
{
|
||||
distanceSpacingSlider.ContractedLabelText = $"D. S. ({v.NewValue:0.##x})";
|
||||
distanceSpacingSlider.ExpandedLabelText = $"Distance Spacing ({v.NewValue:0.##x})";
|
||||
EditorBeatmap.BeatmapInfo.DistanceSpacing = v.NewValue;
|
||||
}, true);
|
||||
}
|
||||
else
|
||||
distanceSpacing.Disabled = true;
|
||||
|
||||
toolboxCollection.Items = CompositionTools
|
||||
.Prepend(new SelectTool())
|
||||
.Select(t => new RadioButton(t.Name, () => toolSelected(t), t.CreateIcon))
|
||||
@ -265,17 +213,8 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
#region Tool selection logic
|
||||
|
||||
private bool distanceSpacingScrollActive;
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
{
|
||||
if (SupportsDistanceSpacing && e.AltPressed && e.Key == Key.D && !e.Repeat)
|
||||
{
|
||||
snappingToolboxContainer.Expanded.Value = true;
|
||||
distanceSpacingScrollActive = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (e.ControlPressed || e.AltPressed || e.SuperPressed)
|
||||
return false;
|
||||
|
||||
@ -305,28 +244,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
return base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
protected override void OnKeyUp(KeyUpEvent e)
|
||||
{
|
||||
if (distanceSpacingScrollActive && (e.Key == Key.AltLeft || e.Key == Key.AltRight || e.Key == Key.D))
|
||||
{
|
||||
snappingToolboxContainer.Expanded.Value = false;
|
||||
distanceSpacingScrollActive = false;
|
||||
}
|
||||
|
||||
base.OnKeyUp(e);
|
||||
}
|
||||
|
||||
protected override bool OnScroll(ScrollEvent e)
|
||||
{
|
||||
if (distanceSpacingScrollActive)
|
||||
{
|
||||
distanceSpacing.Value += e.ScrollDelta.Y * (e.IsPrecise ? 0.01f : 0.1f);
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnScroll(e);
|
||||
}
|
||||
|
||||
private bool checkLeftToggleFromKey(Key key, out int index)
|
||||
{
|
||||
if (key < Key.Number1 || key > Key.Number9)
|
||||
@ -468,7 +385,7 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
public override float GetBeatSnapDistanceAt(HitObject referenceObject)
|
||||
{
|
||||
return (float)(100 * referenceObject.DifficultyControlPoint.SliderVelocity * EditorBeatmap.Difficulty.SliderMultiplier * distanceSpacing.Value / BeatSnapProvider.BeatDivisor);
|
||||
return (float)(100 * referenceObject.DifficultyControlPoint.SliderVelocity * EditorBeatmap.Difficulty.SliderMultiplier / BeatSnapProvider.BeatDivisor);
|
||||
}
|
||||
|
||||
public override float DurationToDistance(HitObject referenceObject, double duration)
|
||||
@ -517,18 +434,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
FillFlow.Spacing = new Vector2(10);
|
||||
}
|
||||
}
|
||||
|
||||
private class SnappingToolboxContainer : ExpandingContainer
|
||||
{
|
||||
public SnappingToolboxContainer()
|
||||
: base(130, 250)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
Padding = new MarginPadding { Left = 10 };
|
||||
|
||||
FillFlow.Spacing = new Vector2(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -563,8 +468,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
#region IPositionSnapProvider
|
||||
|
||||
public abstract IBindable<double> DistanceSpacingMultiplier { get; }
|
||||
|
||||
public abstract SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition);
|
||||
|
||||
public virtual SnapResult SnapScreenSpacePositionToValidPosition(Vector2 screenSpacePosition) =>
|
||||
|
Reference in New Issue
Block a user