Merge pull request #8697 from smoogipoo/more-change-state-support

Add change state support to more Editor components
This commit is contained in:
Dean Herbert 2020-04-13 20:19:04 +09:00 committed by GitHub
commit 64422fbf6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 6 deletions

View File

@ -12,6 +12,7 @@ using osu.Game.Graphics;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit;
using osuTK;
using osuTK.Graphics;
using osuTK.Input;
@ -33,6 +34,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
private readonly Container marker;
private readonly Drawable markerRing;
[Resolved(CanBeNull = true)]
private IEditorChangeHandler changeHandler { get; set; }
[Resolved(CanBeNull = true)]
private IDistanceSnapProvider snapProvider { get; set; }
@ -137,7 +141,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
protected override bool OnClick(ClickEvent e) => RequestSelection != null;
protected override bool OnDragStart(DragStartEvent e) => e.Button == MouseButton.Left;
protected override bool OnDragStart(DragStartEvent e)
{
if (e.Button == MouseButton.Left)
{
changeHandler?.BeginChange();
return true;
}
return false;
}
protected override void OnDrag(DragEvent e)
{
@ -158,6 +171,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
ControlPoint.Position.Value += e.Delta;
}
protected override void OnDragEnd(DragEndEvent e) => changeHandler?.EndChange();
/// <summary>
/// Updates the state of the circular control point marker.
/// </summary>

View File

@ -38,6 +38,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
[Resolved(CanBeNull = true)]
private EditorBeatmap editorBeatmap { get; set; }
[Resolved(CanBeNull = true)]
private IEditorChangeHandler changeHandler { get; set; }
public SliderSelectionBlueprint(DrawableSlider slider)
: base(slider)
{
@ -92,7 +95,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private int? placementControlPointIndex;
protected override bool OnDragStart(DragStartEvent e) => placementControlPointIndex != null;
protected override bool OnDragStart(DragStartEvent e)
{
if (placementControlPointIndex != null)
{
changeHandler?.BeginChange();
return true;
}
return false;
}
protected override void OnDrag(DragEvent e)
{
@ -103,7 +115,11 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
protected override void OnDragEnd(DragEndEvent e)
{
placementControlPointIndex = null;
if (placementControlPointIndex != null)
{
placementControlPointIndex = null;
changeHandler?.EndChange();
}
}
private BindableList<PathControlPoint> controlPoints => HitObject.Path.ControlPoints;

View File

@ -37,6 +37,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
private SelectionHandler selectionHandler;
[Resolved(CanBeNull = true)]
private IEditorChangeHandler changeHandler { get; set; }
[Resolved]
private IAdjustableClock adjustableClock { get; set; }
@ -164,7 +167,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
return false;
if (movementBlueprint != null)
{
isDraggingBlueprint = true;
changeHandler?.BeginChange();
return true;
}
if (DragBox.HandleDrag(e))
{
@ -191,6 +198,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (e.Button == MouseButton.Right)
return;
if (isDraggingBlueprint)
{
changeHandler?.EndChange();
isDraggingBlueprint = false;
}
if (DragBox.State == Visibility.Visible)
{
DragBox.Hide();
@ -354,6 +367,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private Vector2? movementBlueprintOriginalPosition;
private SelectionBlueprint movementBlueprint;
private bool isDraggingBlueprint;
/// <summary>
/// Attempts to begin the movement of any selected blueprints.

View File

@ -40,6 +40,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
[Resolved(CanBeNull = true)]
private EditorBeatmap editorBeatmap { get; set; }
[Resolved(CanBeNull = true)]
private IEditorChangeHandler changeHandler { get; set; }
public SelectionHandler()
{
selectedBlueprints = new List<SelectionBlueprint>();
@ -152,8 +155,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void deleteSelected()
{
changeHandler?.BeginChange();
foreach (var h in selectedBlueprints.ToList())
editorBeatmap.Remove(h.HitObject);
editorBeatmap?.Remove(h.HitObject);
changeHandler?.EndChange();
}
#endregion
@ -205,6 +212,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <param name="sampleName">The name of the hit sample.</param>
public void AddHitSample(string sampleName)
{
changeHandler?.BeginChange();
foreach (var h in SelectedHitObjects)
{
// Make sure there isn't already an existing sample
@ -213,6 +222,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
h.Samples.Add(new HitSampleInfo { Name = sampleName });
}
changeHandler?.EndChange();
}
/// <summary>
@ -221,8 +232,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <param name="sampleName">The name of the hit sample.</param>
public void RemoveHitSample(string sampleName)
{
changeHandler?.BeginChange();
foreach (var h in SelectedHitObjects)
h.SamplesBindable.RemoveAll(s => s.Name == sampleName);
changeHandler?.EndChange();
}
#endregion

View File

@ -254,14 +254,21 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
Colour = IsHovered || hasMouseDown ? Color4.OrangeRed : Color4.White;
}
protected override bool OnDragStart(DragStartEvent e) => true;
[Resolved]
private EditorBeatmap beatmap { get; set; }
[Resolved]
private IBeatSnapProvider beatSnapProvider { get; set; }
[Resolved(CanBeNull = true)]
private IEditorChangeHandler changeHandler { get; set; }
protected override bool OnDragStart(DragStartEvent e)
{
changeHandler?.BeginChange();
return true;
}
protected override void OnDrag(DragEvent e)
{
base.OnDrag(e);
@ -301,6 +308,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
base.OnDragEnd(e);
OnDragHandled?.Invoke(null);
changeHandler?.EndChange();
}
}
}