mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 13:22:55 +08:00
Implement hitobject deletion
This commit is contained in:
parent
5a5e91eaed
commit
0e841628b6
@ -77,5 +77,7 @@ namespace osu.Game.Tests.Visual
|
||||
}
|
||||
|
||||
public void EndPlacement(HitObject hitObject) => composer.Add(hitObject);
|
||||
|
||||
public void Delete(HitObject hitObject) => composer.Remove(hitObject);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -28,6 +29,13 @@ namespace osu.Game.Rulesets.Edit
|
||||
/// <param name="hitObject">The <see cref="HitObject"/> to add.</param>
|
||||
/// <returns>The visual representation of <paramref name="hitObject"/>.</returns>
|
||||
internal abstract DrawableHitObject Add(HitObject hitObject);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a <see cref="HitObject"/> from the <see cref="Beatmap"/> and the display.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="HitObject"/> to remove.</param>
|
||||
/// <returns>The visual representation of the removed <paramref name="hitObject"/>.</returns>
|
||||
internal abstract DrawableHitObject Remove(HitObject hitObject);
|
||||
}
|
||||
|
||||
public class EditRulesetContainer<TObject> : EditRulesetContainer
|
||||
@ -72,5 +80,27 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
return drawableObject;
|
||||
}
|
||||
|
||||
internal override DrawableHitObject Remove(HitObject hitObject)
|
||||
{
|
||||
var tObject = (TObject)hitObject;
|
||||
|
||||
// Remove from beatmap
|
||||
beatmap.HitObjects.Remove(tObject);
|
||||
|
||||
// Process the beatmap
|
||||
var processor = ruleset.CreateBeatmapProcessor(beatmap);
|
||||
|
||||
processor.PreProcess();
|
||||
processor.PostProcess();
|
||||
|
||||
// Remove visual representation
|
||||
var drawableObject = Playfield.AllHitObjects.Single(d => d.HitObject == hitObject);
|
||||
|
||||
rulesetContainer.Playfield.Remove(drawableObject);
|
||||
rulesetContainer.Playfield.PostProcess();
|
||||
|
||||
return drawableObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -152,6 +152,8 @@ namespace osu.Game.Rulesets.Edit
|
||||
placementContainer.Refresh();
|
||||
}
|
||||
|
||||
public void Remove(HitObject hitObject) => maskLayer.RemoveMaskFor(rulesetContainer.Remove(hitObject));
|
||||
|
||||
internal abstract EditRulesetContainer CreateRulesetContainer();
|
||||
|
||||
protected abstract IReadOnlyList<HitObjectCompositionTool> CompositionTools { get; }
|
||||
|
@ -122,5 +122,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose
|
||||
}
|
||||
|
||||
public void EndPlacement(HitObject hitObject) => composer.Add(hitObject);
|
||||
|
||||
public void Delete(HitObject hitObject) => composer.Remove(hitObject);
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose
|
||||
{
|
||||
void BeginPlacement(HitObject hitObject);
|
||||
void EndPlacement(HitObject hitObject);
|
||||
|
||||
void Delete(HitObject hitObject);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -69,5 +70,19 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
|
||||
maskContainer.Add(mask);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a mask for a <see cref="DrawableHitObject"/>.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="DrawableHitObject"/> for which to remove the mask.</param>
|
||||
public void RemoveMaskFor(DrawableHitObject hitObject)
|
||||
{
|
||||
var maskToRemove = maskContainer.Single(m => m.HitObject == hitObject);
|
||||
if (maskToRemove == null)
|
||||
return;
|
||||
|
||||
maskToRemove.Deselect();
|
||||
maskContainer.Remove(maskToRemove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,15 +3,18 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Edit.Types;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
{
|
||||
@ -26,6 +29,9 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
|
||||
private Drawable outline;
|
||||
|
||||
[Resolved]
|
||||
private IPlacementHandler placementHandler { get; set; }
|
||||
|
||||
public MaskSelection()
|
||||
{
|
||||
selectedMasks = new List<SelectionMask>();
|
||||
@ -69,6 +75,21 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
{
|
||||
if (e.Repeat)
|
||||
return base.OnKeyDown(e);
|
||||
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Delete:
|
||||
foreach (var h in selectedMasks.ToList())
|
||||
placementHandler.Delete(h.HitObject.HitObject);
|
||||
return true;
|
||||
}
|
||||
return base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Selection Handling
|
||||
|
Loading…
Reference in New Issue
Block a user