Fix "centre on selected object" button not respecting precision of allowable grid positions

This commit is contained in:
Bartłomiej Dach 2024-10-07 10:29:45 +02:00
parent 04c65ad919
commit 2b5ddddf4f
No known key found for this signature in database
1 changed files with 5 additions and 2 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -10,6 +11,7 @@
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
@ -123,7 +125,8 @@ private void load()
if (editorBeatmap.SelectedHitObjects.Count != 1) if (editorBeatmap.SelectedHitObjects.Count != 1)
return; return;
StartPosition.Value = ((IHasPosition)editorBeatmap.SelectedHitObjects.Single()).Position; var position = ((IHasPosition)editorBeatmap.SelectedHitObjects.Single()).Position;
StartPosition.Value = new Vector2(MathF.Round(position.X), MathF.Round(position.Y));
updateEnabledStates(); updateEnabledStates();
}, },
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -243,7 +246,7 @@ private void updateEnabledStates()
{ {
useSelectedObjectPositionButton.Enabled.Value = expandingContainer?.Expanded.Value == true useSelectedObjectPositionButton.Enabled.Value = expandingContainer?.Expanded.Value == true
&& editorBeatmap.SelectedHitObjects.Count == 1 && editorBeatmap.SelectedHitObjects.Count == 1
&& StartPosition.Value != ((IHasPosition)editorBeatmap.SelectedHitObjects.Single()).Position; && !Precision.AlmostEquals(StartPosition.Value, ((IHasPosition)editorBeatmap.SelectedHitObjects.Single()).Position, 0.5f);
} }
private void nextGridSize() private void nextGridSize()