duplicating entities can now be undone / redone

This commit is contained in:
minenice55
2022-07-08 12:50:23 -04:00
parent 4d3e330f90
commit 216c50a99f
5 changed files with 91 additions and 33 deletions

View File

@ -171,4 +171,38 @@ namespace HeavenStudio.Editor.Commands
}
}
}
public class Duplicate : IAction
{
List<TimelineEventObj> eventObjs;
List<TimelineEventObj> copiedObjs;
public Duplicate(List<TimelineEventObj> eventObjs)
{
this.eventObjs = eventObjs;
}
public void Execute()
{
}
public void Redo()
{
for (int i = 0; i < copiedObjs.Count; i++)
{
Beatmap.Entity e = copiedObjs[i].entity;
eventObjs[i] = Timeline.instance.AddEventObject(e.datamodel, false, new Vector3(e.beat, -e.track * Timeline.instance.LayerHeight()), e, true, e.eventObj.eventObjID);
}
}
public void Undo()
{
copiedObjs = eventObjs;
for (int i = 0; i < eventObjs.Count; i++)
{
Selections.instance.Deselect(eventObjs[i]);
Timeline.instance.DestroyEventObject(eventObjs[i].entity);
}
}
}
}

View File

@ -199,7 +199,7 @@ namespace HeavenStudio.Editor
for (int i = 0; i < selectedEvents.Count; i++)
{
if (selectedEvents[i].isCreating == false)
if (!(selectedEvents[i].isCreating || selectedEvents[i].wasDuplicated))
{
result.Add(selectedEvents[i]);
}

View File

@ -611,14 +611,22 @@ namespace HeavenStudio.Editor.Track
return eventObj;
}
public TimelineEventObj CopyEventObject(Beatmap.Entity e)
private List<TimelineEventObj> duplicatedEventObjs = new List<TimelineEventObj>();
public TimelineEventObj CopyEventObject(TimelineEventObj e)
{
Beatmap.Entity clone = e.DeepCopy();
Beatmap.Entity clone = e.entity.DeepCopy();
TimelineEventObj dup = AddEventObject(clone.datamodel, false, new Vector3(clone.beat, -clone.track * Timeline.instance.LayerHeight()), clone, true, RandomID());
duplicatedEventObjs.Add(dup);
return dup;
}
public void FinalizeDuplicateEventStack()
{
CommandManager.instance.Execute(new Commands.Duplicate(duplicatedEventObjs));
duplicatedEventObjs = new List<TimelineEventObj>();
}
public void DestroyEventObject(Beatmap.Entity entity)
{
if (EventParameterManager.instance.entity == entity)

View File

@ -38,10 +38,10 @@ namespace HeavenStudio.Editor.Track
public bool resizable;
public bool resizing;
public bool moving;
public bool wasDuplicated;
private bool resizingLeft;
private bool resizingRight;
private bool inResizeRegion;
private bool wasDuplicated;
public Vector2 lastMovePos;
public bool isCreating;
public string eventObjID;
@ -120,7 +120,10 @@ namespace HeavenStudio.Editor.Track
selectedImage.gameObject.SetActive(true);
for (int i = 0; i < outline.childCount; i++)
{
outline.GetChild(i).GetComponent<Image>().color = Color.cyan;
if (moving)
outline.GetChild(i).GetComponent<Image>().color = Color.magenta;
else
outline.GetChild(i).GetComponent<Image>().color = Color.cyan;
}
}
else
@ -153,29 +156,33 @@ namespace HeavenStudio.Editor.Track
if (!resizing)
{
if (Input.GetMouseButtonUp(0) && Timeline.instance.timelineState.selected)
{
if (Timeline.instance.eventObjs.FindAll(c => c.mouseHovering).Count == 0 && Timeline.instance.eventObjs.FindAll(c => c.moving).Count == 0 && !BoxSelection.instance.selecting && Timeline.instance.eventObjs.FindAll(c => c.resizing).Count == 0)
{
if (!Input.GetKey(KeyCode.LeftShift))
{
// Selections.instance.Deselect(this);
}
}
// OnUp();
}
if (Timeline.instance.eventObjs.FindAll(c => c.moving).Count > 0 && selected)
{
//duplicate the entity if holding alt or r-click
if ((!wasDuplicated) && (Input.GetKey(KeyCode.LeftAlt) || Input.GetMouseButton(1)))
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
//duplicate the entity if holding alt or m-click
if ((!wasDuplicated) && (Input.GetKey(KeyCode.LeftAlt) || Input.GetMouseButton(2)))
{
wasDuplicated = true;
var te = Timeline.instance.CopyEventObject(entity);
Selections.instance.Deselect(this);
this.wasDuplicated = false;
this.moving = false;
var te = Timeline.instance.CopyEventObject(this);
Selections.instance.DragSelect(te);
te.wasDuplicated = true;
te.transform.localPosition = transform.localPosition;
te.lastPos_ = transform.localPosition;
for (int i = 0; i < Timeline.instance.eventObjs.Count; i++)
{
Timeline.instance.eventObjs[i].startPosX = mousePos.x - Timeline.instance.eventObjs[i].transform.position.x;
Timeline.instance.eventObjs[i].startPosY = mousePos.y - Timeline.instance.eventObjs[i].transform.position.y;
}
te.moving = true;
}
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
lastPos_ = transform.localPosition;
@ -231,7 +238,12 @@ namespace HeavenStudio.Editor.Track
if (resizable)
Cursor.SetCursor(Resources.Load<Texture2D>("Cursors/horizontal_resize"), new Vector2(8, 8), CursorMode.Auto);
}
else if (Timeline.instance.eventObjs.FindAll(c => c.inResizeRegion).Count == 0 && Timeline.instance.eventObjs.FindAll(c => c.resizing).Count == 0)
// should consider adding this someday
// else if (moving && selected || mouseHovering && selected)
// {
// Cursor.SetCursor(Resources.Load<Texture2D>("Cursors/move"), new Vector2(8, 8), CursorMode.Auto);
// }
else
{
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
}
@ -293,13 +305,17 @@ namespace HeavenStudio.Editor.Track
if (selected && Timeline.instance.timelineState.selected)
{
if (wasDuplicated)
{
Timeline.instance.FinalizeDuplicateEventStack();
wasDuplicated = false;
}
if (eligibleToMove)
{
OnComplete(true);
}
moving = false;
wasDuplicated = false;
Cancel();
if (isCreating == true)