Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions fluXis/Screens/Edit/Actions/Events/EventsMoveToTimeAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using fluXis.Map.Structures.Bases;

namespace fluXis.Screens.Edit.Actions.Events;

public class EventsMoveToTimeAction : EditorAction
{
public override string Description => $"Move {objects.Count} events to {destinationTime}ms.";

private readonly List<ITimedObject> objects;
private readonly double destinationTime;
private readonly double sourceTime;

public EventsMoveToTimeAction(List<ITimedObject> objects, double destinationTime)
{
this.objects = objects;
this.destinationTime = destinationTime;
this.sourceTime = objects[0].Time;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put some kind of Min() method here just incase. If the list is ever not sorted for whatever reason, this could break.

}

public override void Run(EditorMap map)
{
foreach (var o in objects)
{
double offset = o.Time - sourceTime;
o.Time = destinationTime + offset;
map.Update(o);
}
}

public override void Undo(EditorMap map)
{
foreach (var o in objects)
{
double offset = o.Time - destinationTime;
o.Time = sourceTime + offset;
map.Update(o);
}
}
}
13 changes: 13 additions & 0 deletions fluXis/Screens/Edit/Tabs/Shared/Points/List/PointListEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public abstract partial class PointListEntry : Container, IHasContextMenu
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new MenuActionItem("Clone to current time", FontAwesome6.Solid.Clone, clone),
new MenuActionItem("Move to current time", FontAwesome6.Solid.Clock, moveToCurrentTime),
new MenuActionItem("Go to time", FontAwesome6.Solid.ArrowRight, goTo),
new MenuActionItem("Bulk-Apply Group", FontAwesome6.Solid.ObjectGroup, applyGroup) { IsEnabled = () => State == SelectedState.Selected },
new MenuActionItem("Edit", FontAwesome6.Solid.PenRuler, OpenSettings),
Expand Down Expand Up @@ -72,6 +73,7 @@ public SelectedState State
public Action RequestApplyGroup { get; set; }
public Action DeleteSelected { get; set; }
public Action CloneSelected { get; set; }
public Action MoveSelectedToCurrentTime { get; set; }
public Action<ITimedObject> OnClone { get; set; }
public ITimedObject Object { get; }

Expand Down Expand Up @@ -287,6 +289,17 @@ private void clone()
OnClone?.Invoke(clone);
}

private void moveToCurrentTime()
{
if (State == SelectedState.Selected)
{
MoveSelectedToCurrentTime?.Invoke();
return;
}

ActionStack.Add(new EventsMoveToTimeAction(new List<ITimedObject> { Object }, clock.CurrentTime));
}

private void applyGroup()
{
if (State != SelectedState.Selected)
Expand Down
6 changes: 6 additions & 0 deletions fluXis/Screens/Edit/Tabs/Shared/Points/List/PointsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ protected void Create(ITimedObject obj, bool overrideTime = true, bool openSetti
flow.FirstOrDefault(e => e.Object == obj)?.OpenSettings();
}

private void moveSelectionToCurrentTime()
{
ActionStack.Add(new EventsMoveToTimeAction(selectedEntries.Select(x => x.Object).ToList(), clock.CurrentTime));
}

private void sortPoints()
{
flow.OrderBy(e => e.Object.Time).ForEach(e => flow.SetLayoutPosition(e, (float)e.Object.Time));
Expand Down Expand Up @@ -383,6 +388,7 @@ protected void AddPoint(ITimedObject obj)
entry.CloneSelected = duplicateSelected;
entry.DeleteSelected = deleteSelected;
entry.OnClone = o => Create(o);
entry.MoveSelectedToCurrentTime = moveSelectionToCurrentTime;

entry.Selected += select;
entry.Deselected += deselect;
Expand Down
Loading