mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 09:02:55 +08:00
Use existing method to update combo state of selection
This commit is contained in:
parent
e009264f10
commit
a6adf8334e
@ -24,7 +24,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A container which provides a "blueprint" display of hitobjects.
|
/// A container which provides a "blueprint" display of hitobjects.
|
||||||
/// Includes selection and manipulation support via a <see cref="SelectionHandler"/>.
|
/// Includes selection and manipulation support via a <see cref="Components.SelectionHandler"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class BlueprintContainer : CompositeDrawable, IKeyBindingHandler<PlatformAction>
|
public abstract class BlueprintContainer : CompositeDrawable, IKeyBindingHandler<PlatformAction>
|
||||||
{
|
{
|
||||||
@ -32,7 +32,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
protected Container<SelectionBlueprint> SelectionBlueprints { get; private set; }
|
protected Container<SelectionBlueprint> SelectionBlueprints { get; private set; }
|
||||||
|
|
||||||
private SelectionHandler selectionHandler;
|
protected SelectionHandler SelectionHandler;
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private IEditorChangeHandler changeHandler { get; set; }
|
private IEditorChangeHandler changeHandler { get; set; }
|
||||||
@ -56,15 +56,15 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
selectionHandler = CreateSelectionHandler();
|
SelectionHandler = CreateSelectionHandler();
|
||||||
selectionHandler.DeselectAll = deselectAll;
|
SelectionHandler.DeselectAll = deselectAll;
|
||||||
|
|
||||||
AddRangeInternal(new[]
|
AddRangeInternal(new[]
|
||||||
{
|
{
|
||||||
DragBox = CreateDragBox(selectBlueprintsFromDragRectangle),
|
DragBox = CreateDragBox(selectBlueprintsFromDragRectangle),
|
||||||
selectionHandler,
|
SelectionHandler,
|
||||||
SelectionBlueprints = CreateSelectionBlueprintContainer(),
|
SelectionBlueprints = CreateSelectionBlueprintContainer(),
|
||||||
selectionHandler.CreateProxy(),
|
SelectionHandler.CreateProxy(),
|
||||||
DragBox.CreateProxy().With(p => p.Depth = float.MinValue)
|
DragBox.CreateProxy().With(p => p.Depth = float.MinValue)
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
new Container<SelectionBlueprint> { RelativeSizeAxes = Axes.Both };
|
new Container<SelectionBlueprint> { RelativeSizeAxes = Axes.Both };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="SelectionHandler"/> which outlines <see cref="DrawableHitObject"/>s and handles movement of selections.
|
/// Creates a <see cref="Components.SelectionHandler"/> which outlines <see cref="DrawableHitObject"/>s and handles movement of selections.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual SelectionHandler CreateSelectionHandler() => new SelectionHandler();
|
protected virtual SelectionHandler CreateSelectionHandler() => new SelectionHandler();
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// store for double-click handling
|
// store for double-click handling
|
||||||
clickedBlueprint = selectionHandler.SelectedBlueprints.FirstOrDefault(b => b.IsHovered);
|
clickedBlueprint = SelectionHandler.SelectedBlueprints.FirstOrDefault(b => b.IsHovered);
|
||||||
|
|
||||||
// Deselection should only occur if no selected blueprints are hovered
|
// Deselection should only occur if no selected blueprints are hovered
|
||||||
// A special case for when a blueprint was selected via this click is added since OnClick() may occur outside the hitobject and should not trigger deselection
|
// A special case for when a blueprint was selected via this click is added since OnClick() may occur outside the hitobject and should not trigger deselection
|
||||||
@ -147,7 +147,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// ensure the blueprint which was hovered for the first click is still the hovered blueprint.
|
// ensure the blueprint which was hovered for the first click is still the hovered blueprint.
|
||||||
if (clickedBlueprint == null || selectionHandler.SelectedBlueprints.FirstOrDefault(b => b.IsHovered) != clickedBlueprint)
|
if (clickedBlueprint == null || SelectionHandler.SelectedBlueprints.FirstOrDefault(b => b.IsHovered) != clickedBlueprint)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
editorClock?.SeekTo(clickedBlueprint.HitObject.StartTime);
|
editorClock?.SeekTo(clickedBlueprint.HitObject.StartTime);
|
||||||
@ -208,7 +208,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
if (DragBox.State == Visibility.Visible)
|
if (DragBox.State == Visibility.Visible)
|
||||||
{
|
{
|
||||||
DragBox.Hide();
|
DragBox.Hide();
|
||||||
selectionHandler.UpdateVisibility();
|
SelectionHandler.UpdateVisibility();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
switch (e.Key)
|
switch (e.Key)
|
||||||
{
|
{
|
||||||
case Key.Escape:
|
case Key.Escape:
|
||||||
if (!selectionHandler.SelectedBlueprints.Any())
|
if (!SelectionHandler.SelectedBlueprints.Any())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
deselectAll();
|
deselectAll();
|
||||||
@ -298,14 +298,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
bool allowDeselection = e.ControlPressed && e.Button == MouseButton.Left;
|
bool allowDeselection = e.ControlPressed && e.Button == MouseButton.Left;
|
||||||
|
|
||||||
// Todo: This is probably incorrectly disallowing multiple selections on stacked objects
|
// Todo: This is probably incorrectly disallowing multiple selections on stacked objects
|
||||||
if (!allowDeselection && selectionHandler.SelectedBlueprints.Any(s => s.IsHovered))
|
if (!allowDeselection && SelectionHandler.SelectedBlueprints.Any(s => s.IsHovered))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (SelectionBlueprint blueprint in SelectionBlueprints.AliveChildren)
|
foreach (SelectionBlueprint blueprint in SelectionBlueprints.AliveChildren)
|
||||||
{
|
{
|
||||||
if (blueprint.IsHovered)
|
if (blueprint.IsHovered)
|
||||||
{
|
{
|
||||||
selectionHandler.HandleSelectionRequested(blueprint, e.CurrentState);
|
SelectionHandler.HandleSelectionRequested(blueprint, e.CurrentState);
|
||||||
clickSelectionBegan = true;
|
clickSelectionBegan = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -358,23 +358,23 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
private void selectAll()
|
private void selectAll()
|
||||||
{
|
{
|
||||||
SelectionBlueprints.ToList().ForEach(m => m.Select());
|
SelectionBlueprints.ToList().ForEach(m => m.Select());
|
||||||
selectionHandler.UpdateVisibility();
|
SelectionHandler.UpdateVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deselects all selected <see cref="SelectionBlueprint"/>s.
|
/// Deselects all selected <see cref="SelectionBlueprint"/>s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void deselectAll() => selectionHandler.SelectedBlueprints.ToList().ForEach(m => m.Deselect());
|
private void deselectAll() => SelectionHandler.SelectedBlueprints.ToList().ForEach(m => m.Deselect());
|
||||||
|
|
||||||
private void onBlueprintSelected(SelectionBlueprint blueprint)
|
private void onBlueprintSelected(SelectionBlueprint blueprint)
|
||||||
{
|
{
|
||||||
selectionHandler.HandleSelected(blueprint);
|
SelectionHandler.HandleSelected(blueprint);
|
||||||
SelectionBlueprints.ChangeChildDepth(blueprint, 1);
|
SelectionBlueprints.ChangeChildDepth(blueprint, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onBlueprintDeselected(SelectionBlueprint blueprint)
|
private void onBlueprintDeselected(SelectionBlueprint blueprint)
|
||||||
{
|
{
|
||||||
selectionHandler.HandleDeselected(blueprint);
|
SelectionHandler.HandleDeselected(blueprint);
|
||||||
SelectionBlueprints.ChangeChildDepth(blueprint, 0);
|
SelectionBlueprints.ChangeChildDepth(blueprint, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,16 +391,16 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void prepareSelectionMovement()
|
private void prepareSelectionMovement()
|
||||||
{
|
{
|
||||||
if (!selectionHandler.SelectedBlueprints.Any())
|
if (!SelectionHandler.SelectedBlueprints.Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Any selected blueprint that is hovered can begin the movement of the group, however only the earliest hitobject is used for movement
|
// Any selected blueprint that is hovered can begin the movement of the group, however only the earliest hitobject is used for movement
|
||||||
// A special case is added for when a click selection occurred before the drag
|
// A special case is added for when a click selection occurred before the drag
|
||||||
if (!clickSelectionBegan && !selectionHandler.SelectedBlueprints.Any(b => b.IsHovered))
|
if (!clickSelectionBegan && !SelectionHandler.SelectedBlueprints.Any(b => b.IsHovered))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Movement is tracked from the blueprint of the earliest hitobject, since it only makes sense to distance snap from that hitobject
|
// Movement is tracked from the blueprint of the earliest hitobject, since it only makes sense to distance snap from that hitobject
|
||||||
movementBlueprint = selectionHandler.SelectedBlueprints.OrderBy(b => b.HitObject.StartTime).First();
|
movementBlueprint = SelectionHandler.SelectedBlueprints.OrderBy(b => b.HitObject.StartTime).First();
|
||||||
movementBlueprintOriginalPosition = movementBlueprint.ScreenSpaceSelectionPoint; // todo: unsure if correct
|
movementBlueprintOriginalPosition = movementBlueprint.ScreenSpaceSelectionPoint; // todo: unsure if correct
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,14 +425,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
var result = snapProvider.SnapScreenSpacePositionToValidTime(movePosition);
|
var result = snapProvider.SnapScreenSpacePositionToValidTime(movePosition);
|
||||||
|
|
||||||
// Move the hitobjects.
|
// Move the hitobjects.
|
||||||
if (!selectionHandler.HandleMovement(new MoveSelectionEvent(movementBlueprint, result.ScreenSpacePosition)))
|
if (!SelectionHandler.HandleMovement(new MoveSelectionEvent(movementBlueprint, result.ScreenSpacePosition)))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (result.Time.HasValue)
|
if (result.Time.HasValue)
|
||||||
{
|
{
|
||||||
// Apply the start time at the newly snapped-to position
|
// Apply the start time at the newly snapped-to position
|
||||||
double offset = result.Time.Value - draggedObject.StartTime;
|
double offset = result.Time.Value - draggedObject.StartTime;
|
||||||
foreach (HitObject obj in selectionHandler.SelectedHitObjects)
|
foreach (HitObject obj in SelectionHandler.SelectedHitObjects)
|
||||||
obj.StartTime += offset;
|
obj.StartTime += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,14 +66,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
{
|
{
|
||||||
if (Beatmap.SelectedHitObjects.Count > 0)
|
if (Beatmap.SelectedHitObjects.Count > 0)
|
||||||
{
|
{
|
||||||
foreach (var h in Beatmap.SelectedHitObjects)
|
SelectionHandler.SetNewCombo(combo.NewValue);
|
||||||
{
|
|
||||||
if (h is IHasComboInformation c)
|
|
||||||
{
|
|
||||||
c.NewCombo = combo.NewValue;
|
|
||||||
Beatmap.UpdateHitObject(h);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (currentPlacement != null)
|
else if (currentPlacement != null)
|
||||||
{
|
{
|
||||||
|
@ -285,7 +285,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
var comboInfo = h as IHasComboInformation;
|
var comboInfo = h as IHasComboInformation;
|
||||||
|
|
||||||
if (comboInfo == null)
|
if (comboInfo == null)
|
||||||
throw new InvalidOperationException($"Tried to change combo state of a {h.GetType()}, which doesn't implement {nameof(IHasComboInformation)}");
|
continue;
|
||||||
|
|
||||||
comboInfo.NewCombo = state;
|
comboInfo.NewCombo = state;
|
||||||
EditorBeatmap?.UpdateHitObject(h);
|
EditorBeatmap?.UpdateHitObject(h);
|
||||||
|
Loading…
Reference in New Issue
Block a user