mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 22:22:54 +08:00
improve grid from points tool code
This commit is contained in:
parent
4e3fe5112d
commit
98505d0bba
72
osu.Game.Rulesets.Osu/Edit/GridFromPointsTool.cs
Normal file
72
osu.Game.Rulesets.Osu/Edit/GridFromPointsTool.cs
Normal file
@ -0,0 +1,72 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit
|
||||
{
|
||||
public partial class GridFromPointsTool : Drawable
|
||||
{
|
||||
[Resolved]
|
||||
private OsuGridToolboxGroup gridToolboxGroup { get; set; } = null!;
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private IPositionSnapProvider? snapProvider { get; set; }
|
||||
|
||||
public bool IsPlacing { get; private set; }
|
||||
|
||||
private Vector2? startPosition;
|
||||
|
||||
public void BeginPlacement()
|
||||
{
|
||||
IsPlacing = true;
|
||||
startPosition = null;
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
if (!IsPlacing)
|
||||
return base.OnMouseDown(e);
|
||||
|
||||
var pos = snappedLocalPosition(e);
|
||||
|
||||
if (!startPosition.HasValue)
|
||||
startPosition = pos;
|
||||
else
|
||||
{
|
||||
gridToolboxGroup.SetGridFromPoints(startPosition.Value, pos);
|
||||
IsPlacing = false;
|
||||
}
|
||||
|
||||
if (e.Button == MouseButton.Right)
|
||||
IsPlacing = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
if (!IsPlacing)
|
||||
return base.OnMouseMove(e);
|
||||
|
||||
var pos = snappedLocalPosition(e);
|
||||
|
||||
if (!startPosition.HasValue)
|
||||
gridToolboxGroup.StartPosition.Value = pos;
|
||||
else
|
||||
gridToolboxGroup.SetGridFromPoints(startPosition.Value, pos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Vector2 snappedLocalPosition(UIEvent e)
|
||||
{
|
||||
return ToLocalSpace(snapProvider?.FindSnappedPositionAndTime(e.ScreenSpaceMousePosition, ~SnapType.GlobalGrids).ScreenSpacePosition ?? e.ScreenSpaceMousePosition);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles;
|
||||
@ -10,27 +8,16 @@ using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.Spinners;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit
|
||||
{
|
||||
public partial class OsuBlueprintContainer : ComposeBlueprintContainer
|
||||
{
|
||||
private OsuGridToolboxGroup gridToolbox = null!;
|
||||
|
||||
public OsuBlueprintContainer(HitObjectComposer composer)
|
||||
: base(composer)
|
||||
{
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGridToolboxGroup gridToolbox)
|
||||
{
|
||||
this.gridToolbox = gridToolbox;
|
||||
gridToolbox.GridFromPointsClicked += OnGridFromPointsClicked;
|
||||
}
|
||||
|
||||
protected override SelectionHandler<HitObject> CreateSelectionHandler() => new OsuSelectionHandler();
|
||||
|
||||
public override HitObjectSelectionBlueprint? CreateHitObjectBlueprintFor(HitObject hitObject)
|
||||
@ -49,55 +36,5 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
|
||||
return base.CreateHitObjectBlueprintFor(hitObject);
|
||||
}
|
||||
|
||||
private bool isPlacingGridFromPoints;
|
||||
private Vector2? gridFromPointsStart;
|
||||
|
||||
private void OnGridFromPointsClicked()
|
||||
{
|
||||
isPlacingGridFromPoints = true;
|
||||
gridFromPointsStart = null;
|
||||
|
||||
// Deselect all objects because we cant snap to objects which are selected.
|
||||
DeselectAll();
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
if (!isPlacingGridFromPoints)
|
||||
return base.OnMouseDown(e);
|
||||
|
||||
var pos = snappedLocalPosition(e);
|
||||
|
||||
if (!gridFromPointsStart.HasValue)
|
||||
gridFromPointsStart = pos;
|
||||
else
|
||||
{
|
||||
gridToolbox.SetGridFromPoints(gridFromPointsStart.Value, pos);
|
||||
isPlacingGridFromPoints = false;
|
||||
}
|
||||
|
||||
if (e.Button == MouseButton.Right)
|
||||
isPlacingGridFromPoints = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
if (!isPlacingGridFromPoints)
|
||||
return base.OnMouseMove(e);
|
||||
|
||||
var pos = snappedLocalPosition(e);
|
||||
|
||||
if (!gridFromPointsStart.HasValue)
|
||||
gridToolbox.StartPosition.Value = pos;
|
||||
else
|
||||
gridToolbox.SetGridFromPoints(gridFromPointsStart.Value, pos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Vector2 snappedLocalPosition(UIEvent e) => ToLocalSpace(Composer.FindSnappedPositionAndTime(e.ScreenSpaceMousePosition, ~SnapType.GlobalGrids).ScreenSpacePosition);
|
||||
}
|
||||
}
|
||||
|
@ -81,13 +81,12 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
// Give a bit of breathing room around the playfield content.
|
||||
PlayfieldContentContainer.Padding = new MarginPadding(10);
|
||||
|
||||
LayerBelowRuleset.AddRange(new Drawable[]
|
||||
{
|
||||
LayerBelowRuleset.Add(
|
||||
distanceSnapGridContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
selectedHitObjects = EditorBeatmap.SelectedHitObjects.GetBoundCopy();
|
||||
selectedHitObjects.CollectionChanged += (_, _) => updateDistanceSnapGrid();
|
||||
@ -100,6 +99,15 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
updateDistanceSnapGrid();
|
||||
|
||||
OsuGridToolboxGroup.GridType.BindValueChanged(updatePositionSnapGrid, true);
|
||||
OsuGridToolboxGroup.GridFromPointsClicked += () => gridFromPointsTool.BeginPlacement();
|
||||
|
||||
LayerAboveRuleset.Add(
|
||||
// Place it above the playfield and blueprints, so it takes priority when handling input.
|
||||
gridFromPointsTool = new GridFromPointsTool
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
);
|
||||
|
||||
RightToolbox.AddRange(new EditorToolboxGroup[]
|
||||
{
|
||||
@ -110,6 +118,8 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
);
|
||||
}
|
||||
|
||||
private GridFromPointsTool gridFromPointsTool;
|
||||
|
||||
private void updatePositionSnapGrid(ValueChangedEvent<PositionSnapGridType> obj)
|
||||
{
|
||||
if (positionSnapGrid != null)
|
||||
@ -278,7 +288,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
|
||||
foreach (var b in blueprints)
|
||||
{
|
||||
if (b.IsSelected)
|
||||
if (b.IsSelected && !gridFromPointsTool.IsPlacing)
|
||||
continue;
|
||||
|
||||
var snapPositions = b.ScreenSpaceSnapPoints;
|
||||
|
@ -76,6 +76,8 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
protected readonly Container LayerBelowRuleset = new Container { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
protected readonly Container LayerAboveRuleset = new Container { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
protected InputManager InputManager { get; private set; }
|
||||
|
||||
private EditorRadioButtonCollection toolboxCollection;
|
||||
@ -137,7 +139,8 @@ namespace osu.Game.Rulesets.Edit
|
||||
drawableRulesetWrapper,
|
||||
// layers above playfield
|
||||
drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer()
|
||||
.WithChild(BlueprintContainer = CreateBlueprintContainer())
|
||||
.WithChild(BlueprintContainer = CreateBlueprintContainer()),
|
||||
drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer().WithChild(LayerAboveRuleset),
|
||||
}
|
||||
},
|
||||
new Container
|
||||
|
Loading…
Reference in New Issue
Block a user