duplicating entities can now be undone / redone

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

View file

@ -2342,7 +2342,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -289.15002, y: 2}
m_AnchoredPosition: {x: -289.15, y: 2}
m_SizeDelta: {x: -578.29, y: 49.92}
m_Pivot: {x: 0.5, y: 0}
--- !u!114 &156962255
@ -8869,7 +8869,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 704039020}
m_Direction: 0
m_Value: 0
m_Size: 0.032871284
m_Size: 0.03287128
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
@ -12488,8 +12488,8 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 1589389272}
m_HandleRect: {fileID: 1589389271}
m_Direction: 2
m_Value: 1
m_Size: 0.5293149
m_Value: 1.0000002
m_Size: 0.52891773
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
@ -15074,7 +15074,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -408.97992, y: -17}
m_AnchoredPosition: {x: -408.97998, y: -17}
m_SizeDelta: {x: -817.96, y: -46.29}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &1121370303
@ -15607,7 +15607,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 1, y: 0.5}
m_AnchoredPosition: {x: 0, y: 129.94681}
m_AnchoredPosition: {x: 0, y: 129.85045}
m_SizeDelta: {x: 0, y: 491}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &1154875944
@ -26349,8 +26349,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: -26.463135}
m_SizeDelta: {x: 1054, y: -115.3}
m_AnchoredPosition: {x: -0, y: -28.03}
m_SizeDelta: {x: 1054, y: -113.92}
m_Pivot: {x: 0, y: 0.5}
--- !u!114 &2066632681
MonoBehaviour:

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,6 +120,9 @@ namespace HeavenStudio.Editor.Track
selectedImage.gameObject.SetActive(true);
for (int i = 0; i < outline.childCount; i++)
{
if (moving)
outline.GetChild(i).GetComponent<Image>().color = Color.magenta;
else
outline.GetChild(i).GetComponent<Image>().color = Color.cyan;
}
}
@ -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)