mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 19:22:56 +08:00
Merge pull request #11904 from peppy/editor-centralise-selection-change-handling
Centralise cases of performing actions on the current selection
This commit is contained in:
commit
b1702273c8
@ -45,6 +45,7 @@ namespace osu.Game.Rulesets.Mania.Edit
|
|||||||
int minColumn = int.MaxValue;
|
int minColumn = int.MaxValue;
|
||||||
int maxColumn = int.MinValue;
|
int maxColumn = int.MinValue;
|
||||||
|
|
||||||
|
// find min/max in an initial pass before actually performing the movement.
|
||||||
foreach (var obj in EditorBeatmap.SelectedHitObjects.OfType<ManiaHitObject>())
|
foreach (var obj in EditorBeatmap.SelectedHitObjects.OfType<ManiaHitObject>())
|
||||||
{
|
{
|
||||||
if (obj.Column < minColumn)
|
if (obj.Column < minColumn)
|
||||||
@ -55,8 +56,11 @@ namespace osu.Game.Rulesets.Mania.Edit
|
|||||||
|
|
||||||
columnDelta = Math.Clamp(columnDelta, -minColumn, maniaPlayfield.TotalColumns - 1 - maxColumn);
|
columnDelta = Math.Clamp(columnDelta, -minColumn, maniaPlayfield.TotalColumns - 1 - maxColumn);
|
||||||
|
|
||||||
foreach (var obj in EditorBeatmap.SelectedHitObjects.OfType<ManiaHitObject>())
|
EditorBeatmap.PerformOnSelection(h =>
|
||||||
obj.Column += columnDelta;
|
{
|
||||||
|
if (h is ManiaHitObject maniaObj)
|
||||||
|
maniaObj.Column += columnDelta;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,32 +52,24 @@ namespace osu.Game.Rulesets.Taiko.Edit
|
|||||||
|
|
||||||
public void SetStrongState(bool state)
|
public void SetStrongState(bool state)
|
||||||
{
|
{
|
||||||
var hits = EditorBeatmap.SelectedHitObjects.OfType<Hit>();
|
EditorBeatmap.PerformOnSelection(h =>
|
||||||
|
|
||||||
EditorBeatmap.BeginChange();
|
|
||||||
|
|
||||||
foreach (var h in hits)
|
|
||||||
{
|
{
|
||||||
if (h.IsStrong != state)
|
if (!(h is Hit taikoHit)) return;
|
||||||
{
|
|
||||||
h.IsStrong = state;
|
|
||||||
EditorBeatmap.Update(h);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorBeatmap.EndChange();
|
if (taikoHit.IsStrong != state)
|
||||||
|
{
|
||||||
|
taikoHit.IsStrong = state;
|
||||||
|
EditorBeatmap.Update(taikoHit);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRimState(bool state)
|
public void SetRimState(bool state)
|
||||||
{
|
{
|
||||||
var hits = EditorBeatmap.SelectedHitObjects.OfType<Hit>();
|
EditorBeatmap.PerformOnSelection(h =>
|
||||||
|
{
|
||||||
EditorBeatmap.BeginChange();
|
if (h is Hit taikoHit) taikoHit.Type = state ? HitType.Rim : HitType.Centre;
|
||||||
|
});
|
||||||
foreach (var h in hits)
|
|
||||||
h.Type = state ? HitType.Rim : HitType.Centre;
|
|
||||||
|
|
||||||
EditorBeatmap.EndChange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint> selection)
|
protected override IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint> selection)
|
||||||
|
@ -495,8 +495,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
// 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 - movementBlueprints.First().HitObject.StartTime;
|
double offset = result.Time.Value - movementBlueprints.First().HitObject.StartTime;
|
||||||
|
|
||||||
foreach (HitObject obj in Beatmap.SelectedHitObjects)
|
Beatmap.PerformOnSelection(obj => obj.StartTime += offset);
|
||||||
obj.StartTime += offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -320,18 +320,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// <param name="sampleName">The name of the hit sample.</param>
|
/// <param name="sampleName">The name of the hit sample.</param>
|
||||||
public void AddHitSample(string sampleName)
|
public void AddHitSample(string sampleName)
|
||||||
{
|
{
|
||||||
EditorBeatmap.BeginChange();
|
EditorBeatmap.PerformOnSelection(h =>
|
||||||
|
|
||||||
foreach (var h in EditorBeatmap.SelectedHitObjects)
|
|
||||||
{
|
{
|
||||||
// Make sure there isn't already an existing sample
|
// Make sure there isn't already an existing sample
|
||||||
if (h.Samples.Any(s => s.Name == sampleName))
|
if (h.Samples.Any(s => s.Name == sampleName))
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
h.Samples.Add(new HitSampleInfo(sampleName));
|
h.Samples.Add(new HitSampleInfo(sampleName));
|
||||||
}
|
});
|
||||||
|
|
||||||
EditorBeatmap.EndChange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -341,19 +337,15 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// <exception cref="InvalidOperationException">Throws if any selected object doesn't implement <see cref="IHasComboInformation"/></exception>
|
/// <exception cref="InvalidOperationException">Throws if any selected object doesn't implement <see cref="IHasComboInformation"/></exception>
|
||||||
public void SetNewCombo(bool state)
|
public void SetNewCombo(bool state)
|
||||||
{
|
{
|
||||||
EditorBeatmap.BeginChange();
|
EditorBeatmap.PerformOnSelection(h =>
|
||||||
|
|
||||||
foreach (var h in EditorBeatmap.SelectedHitObjects)
|
|
||||||
{
|
{
|
||||||
var comboInfo = h as IHasComboInformation;
|
var comboInfo = h as IHasComboInformation;
|
||||||
|
|
||||||
if (comboInfo == null || comboInfo.NewCombo == state) continue;
|
if (comboInfo == null || comboInfo.NewCombo == state) return;
|
||||||
|
|
||||||
comboInfo.NewCombo = state;
|
comboInfo.NewCombo = state;
|
||||||
EditorBeatmap.Update(h);
|
EditorBeatmap.Update(h);
|
||||||
}
|
});
|
||||||
|
|
||||||
EditorBeatmap.EndChange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -362,12 +354,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// <param name="sampleName">The name of the hit sample.</param>
|
/// <param name="sampleName">The name of the hit sample.</param>
|
||||||
public void RemoveHitSample(string sampleName)
|
public void RemoveHitSample(string sampleName)
|
||||||
{
|
{
|
||||||
EditorBeatmap.BeginChange();
|
EditorBeatmap.PerformOnSelection(h => h.SamplesBindable.RemoveAll(s => s.Name == sampleName));
|
||||||
|
|
||||||
foreach (var h in EditorBeatmap.SelectedHitObjects)
|
|
||||||
h.SamplesBindable.RemoveAll(s => s.Name == sampleName);
|
|
||||||
|
|
||||||
EditorBeatmap.EndChange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -100,6 +100,22 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
private readonly HashSet<HitObject> batchPendingUpdates = new HashSet<HitObject>();
|
private readonly HashSet<HitObject> batchPendingUpdates = new HashSet<HitObject>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform the provided action on every selected hitobject.
|
||||||
|
/// Changes will be grouped as one history action.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="action">The action to perform.</param>
|
||||||
|
public void PerformOnSelection(Action<HitObject> action)
|
||||||
|
{
|
||||||
|
if (SelectedHitObjects.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BeginChange();
|
||||||
|
foreach (var h in SelectedHitObjects)
|
||||||
|
action(h);
|
||||||
|
EndChange();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a collection of <see cref="HitObject"/>s to this <see cref="EditorBeatmap"/>.
|
/// Adds a collection of <see cref="HitObject"/>s to this <see cref="EditorBeatmap"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user