Merge branch 'master' into no-more-difficulty-control-points-info

This commit is contained in:
Dean Herbert
2021-09-28 13:53:56 +09:00
307 changed files with 6952 additions and 2297 deletions

View File

@ -228,9 +228,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
return false;
}
public bool OnPressed(PlatformAction action)
public bool OnPressed(KeyBindingPressEvent<PlatformAction> e)
{
switch (action)
switch (e.Action)
{
case PlatformAction.SelectAll:
SelectAll();
@ -240,7 +240,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
return false;
}
public void OnReleased(PlatformAction action)
public void OnReleased(KeyBindingReleaseEvent<PlatformAction> e)
{
}

View File

@ -1,12 +1,12 @@
// 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 System.Collections.Generic;
using osu.Framework.Bindables;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Screens.Edit.Compose.Components
{
@ -15,69 +15,62 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary>
public sealed class HitObjectOrderedSelectionContainer : Container<SelectionBlueprint<HitObject>>
{
[Resolved]
private EditorBeatmap editorBeatmap { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
editorBeatmap.HitObjectUpdated += hitObjectUpdated;
}
private void hitObjectUpdated(HitObject _) => SortInternal();
public override void Add(SelectionBlueprint<HitObject> drawable)
{
SortInternal();
base.Add(drawable);
bindStartTime(drawable);
}
public override bool Remove(SelectionBlueprint<HitObject> drawable)
{
if (!base.Remove(drawable))
return false;
unbindStartTime(drawable);
return true;
}
public override void Clear(bool disposeChildren)
{
base.Clear(disposeChildren);
unbindAllStartTimes();
}
private readonly Dictionary<SelectionBlueprint<HitObject>, IBindable> startTimeMap = new Dictionary<SelectionBlueprint<HitObject>, IBindable>();
private void bindStartTime(SelectionBlueprint<HitObject> blueprint)
{
var bindable = blueprint.Item.StartTimeBindable.GetBoundCopy();
bindable.BindValueChanged(_ =>
{
if (LoadState >= LoadState.Ready)
SortInternal();
});
startTimeMap[blueprint] = bindable;
}
private void unbindStartTime(SelectionBlueprint<HitObject> blueprint)
{
startTimeMap[blueprint].UnbindAll();
startTimeMap.Remove(blueprint);
}
private void unbindAllStartTimes()
{
foreach (var kvp in startTimeMap)
kvp.Value.UnbindAll();
startTimeMap.Clear();
SortInternal();
return base.Remove(drawable);
}
protected override int Compare(Drawable x, Drawable y)
{
var xObj = (SelectionBlueprint<HitObject>)x;
var yObj = (SelectionBlueprint<HitObject>)y;
var xObj = ((SelectionBlueprint<HitObject>)x).Item;
var yObj = ((SelectionBlueprint<HitObject>)y).Item;
// Put earlier blueprints towards the end of the list, so they handle input first
int i = yObj.Item.StartTime.CompareTo(xObj.Item.StartTime);
if (i != 0) return i;
int result = yObj.StartTime.CompareTo(xObj.StartTime);
if (result != 0) return result;
// Fall back to end time if the start time is equal.
i = yObj.Item.GetEndTime().CompareTo(xObj.Item.GetEndTime());
result = yObj.GetEndTime().CompareTo(xObj.GetEndTime());
if (result != 0) return result;
return i == 0 ? CompareReverseChildID(y, x) : i;
// As a final fallback, use combo information if available.
if (xObj is IHasComboInformation xHasCombo && yObj is IHasComboInformation yHasCombo)
{
result = yHasCombo.ComboIndex.CompareTo(xHasCombo.ComboIndex);
if (result != 0) return result;
result = yHasCombo.IndexInCurrentCombo.CompareTo(xHasCombo.IndexInCurrentCombo);
if (result != 0) return result;
}
return CompareReverseChildID(y, x);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (editorBeatmap != null)
editorBeatmap.HitObjectUpdated -= hitObjectUpdated;
}
}
}

View File

@ -0,0 +1,113 @@
// 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 System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Layout;
using osuTK;
namespace osu.Game.Screens.Edit.Compose.Components
{
public class RectangularPositionSnapGrid : CompositeDrawable
{
/// <summary>
/// The position of the origin of this <see cref="RectangularPositionSnapGrid"/> in local coordinates.
/// </summary>
public Vector2 StartPosition { get; }
private Vector2 spacing = Vector2.One;
/// <summary>
/// The spacing between grid lines of this <see cref="RectangularPositionSnapGrid"/>.
/// </summary>
public Vector2 Spacing
{
get => spacing;
set
{
if (spacing.X <= 0 || spacing.Y <= 0)
throw new ArgumentException("Grid spacing must be positive.");
spacing = value;
gridCache.Invalidate();
}
}
private readonly LayoutValue gridCache = new LayoutValue(Invalidation.RequiredParentSizeToFit);
public RectangularPositionSnapGrid(Vector2 startPosition)
{
StartPosition = startPosition;
AddLayout(gridCache);
}
protected override void Update()
{
base.Update();
if (!gridCache.IsValid)
{
ClearInternal();
createContent();
gridCache.Validate();
}
}
private void createContent()
{
var drawSize = DrawSize;
generateGridLines(Direction.Horizontal, StartPosition.Y, 0, -Spacing.Y);
generateGridLines(Direction.Horizontal, StartPosition.Y, drawSize.Y, Spacing.Y);
generateGridLines(Direction.Vertical, StartPosition.X, 0, -Spacing.X);
generateGridLines(Direction.Vertical, StartPosition.X, drawSize.X, Spacing.X);
}
private void generateGridLines(Direction direction, float startPosition, float endPosition, float step)
{
int index = 0;
float currentPosition = startPosition;
while ((endPosition - currentPosition) * Math.Sign(step) > 0)
{
var gridLine = new Box
{
Colour = Colour4.White,
Alpha = index == 0 ? 0.3f : 0.1f,
EdgeSmoothness = new Vector2(0.2f)
};
if (direction == Direction.Horizontal)
{
gridLine.RelativeSizeAxes = Axes.X;
gridLine.Height = 1;
gridLine.Y = currentPosition;
}
else
{
gridLine.RelativeSizeAxes = Axes.Y;
gridLine.Width = 1;
gridLine.X = currentPosition;
}
AddInternal(gridLine);
index += 1;
currentPosition = startPosition + index * step;
}
}
public Vector2 GetSnappedPosition(Vector2 original)
{
Vector2 relativeToStart = original - StartPosition;
Vector2 offset = Vector2.Divide(relativeToStart, Spacing);
Vector2 roundedOffset = new Vector2(MathF.Round(offset.X), MathF.Round(offset.Y));
return StartPosition + Vector2.Multiply(roundedOffset, Spacing);
}
}
}

View File

@ -137,9 +137,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <returns>Whether any items could be reversed.</returns>
public virtual bool HandleReverse() => false;
public bool OnPressed(PlatformAction action)
public bool OnPressed(KeyBindingPressEvent<PlatformAction> e)
{
switch (action)
switch (e.Action)
{
case PlatformAction.Delete:
DeleteSelected();
@ -149,7 +149,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
return false;
}
public void OnReleased(PlatformAction action)
public void OnReleased(KeyBindingReleaseEvent<PlatformAction> e)
{
}
@ -191,7 +191,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <param name="blueprint">The blueprint.</param>
/// <param name="e">The mouse event responsible for selection.</param>
/// <returns>Whether a selection was performed.</returns>
internal bool MouseDownSelectionRequested(SelectionBlueprint<T> blueprint, MouseButtonEvent e)
internal virtual bool MouseDownSelectionRequested(SelectionBlueprint<T> blueprint, MouseButtonEvent e)
{
if (e.ShiftPressed && e.Button == MouseButton.Right)
{

View File

@ -1,12 +1,19 @@
// 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 System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osuTK;
using osuTK.Input;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
@ -20,9 +27,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
// for now we always allow movement. snapping is provided by the Timeline's "distance" snap implementation
public override bool HandleMovement(MoveSelectionEvent<HitObject> moveEvent) => true;
public bool OnPressed(GlobalAction action)
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
switch (action)
switch (e.Action)
{
case GlobalAction.EditorNudgeLeft:
nudgeSelection(-1);
@ -36,7 +43,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
return false;
}
public void OnReleased(GlobalAction action)
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
@ -61,5 +68,62 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
EditorBeatmap.Update(h);
});
}
/// <summary>
/// The "pivot" object, used in range selection mode.
/// When in range selection, the range to select is determined by the pivot object
/// (last existing object interacted with prior to holding down Shift)
/// and by the object clicked last when Shift was pressed.
/// </summary>
[CanBeNull]
private HitObject pivot;
internal override bool MouseDownSelectionRequested(SelectionBlueprint<HitObject> blueprint, MouseButtonEvent e)
{
if (e.ShiftPressed && e.Button == MouseButton.Left && pivot != null)
{
handleRangeSelection(blueprint, e.ControlPressed);
return true;
}
bool result = base.MouseDownSelectionRequested(blueprint, e);
// ensure that the object wasn't removed by the base implementation before making it the new pivot.
if (EditorBeatmap.HitObjects.Contains(blueprint.Item))
pivot = blueprint.Item;
return result;
}
/// <summary>
/// Handles a request for range selection (triggered when Shift is held down).
/// </summary>
/// <param name="blueprint">The blueprint which was clicked in range selection mode.</param>
/// <param name="cumulative">
/// Whether the selection should be cumulative.
/// In cumulative mode, consecutive range selections will shift the pivot (which usually stays fixed for the duration of a range selection)
/// and will never deselect an object that was previously selected.
/// </param>
private void handleRangeSelection(SelectionBlueprint<HitObject> blueprint, bool cumulative)
{
var clickedObject = blueprint.Item;
Debug.Assert(pivot != null);
double rangeStart = Math.Min(clickedObject.StartTime, pivot.StartTime);
double rangeEnd = Math.Max(clickedObject.GetEndTime(), pivot.GetEndTime());
var newSelection = new HashSet<HitObject>(EditorBeatmap.HitObjects.Where(obj => isInRange(obj, rangeStart, rangeEnd)));
if (cumulative)
{
pivot = clickedObject;
newSelection.UnionWith(EditorBeatmap.SelectedHitObjects);
}
EditorBeatmap.SelectedHitObjects.Clear();
EditorBeatmap.SelectedHitObjects.AddRange(newSelection);
bool isInRange(HitObject hitObject, double start, double end)
=> hitObject.StartTime >= start && hitObject.GetEndTime() <= end;
}
}
}