From a99fbd283f986e264efc913a42c300d7ab5b2dfa Mon Sep 17 00:00:00 2001 From: fu-majime Date: Tue, 16 Apr 2024 17:13:08 +0900 Subject: [PATCH] wip --- Assets/Scripts/LevelEditor/Commands/Space.cs | 191 ++++++++++++++++++ .../LevelEditor/Commands/Space.cs.meta | 11 + Assets/Scripts/LevelEditor/Editor.cs | 12 ++ .../Scripts/LevelEditor/Timeline/Timeline.cs | 24 +++ .../LevelEditor/Timeline/TimelineEventObj.cs | 5 +- 5 files changed, 240 insertions(+), 3 deletions(-) create mode 100644 Assets/Scripts/LevelEditor/Commands/Space.cs create mode 100644 Assets/Scripts/LevelEditor/Commands/Space.cs.meta diff --git a/Assets/Scripts/LevelEditor/Commands/Space.cs b/Assets/Scripts/LevelEditor/Commands/Space.cs new file mode 100644 index 000000000..f3466c5c7 --- /dev/null +++ b/Assets/Scripts/LevelEditor/Commands/Space.cs @@ -0,0 +1,191 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using Jukebox; + +using HeavenStudio.Editor.Track; +using Newtonsoft.Json; +using UnityEditor; +using UnityEngine.Timeline; + +namespace HeavenStudio.Editor.Commands +{ + // Insert / Delete Space + public class MoveEntity : ICommand + { + private readonly List entityIDs = new(); + private EntityMove newMove; + private EntityMove lastMove; + + private struct EntityMove + { + public List beat; + public List layer; + + public EntityMove(List beat, List layer) + { + this.beat = beat; + this.layer = layer; + } + } + + public MoveEntity(List originalEntities, List newBeat, List newLayer) + { + entityIDs = originalEntities.Select(c => c.guid).ToList(); + newMove = new EntityMove(newBeat, newLayer); + } + + public void Execute() + { + lastMove = new EntityMove(); + lastMove.beat = new(); + lastMove.layer = new(); + + for (var i = 0; i < entityIDs.Count; i++) + { + var entity = GameManager.instance.Beatmap.Entities.Find(c => c.guid == entityIDs[i]); + + lastMove.beat.Add(entity.beat); + lastMove.layer.Add((int)entity["track"]); + + entity.beat = newMove.beat[i]; + entity["track"] = newMove.layer[i]; + + if (TimelineBlockManager.Instance.EntityMarkers.ContainsKey(entity.guid)) + TimelineBlockManager.Instance.EntityMarkers[entity.guid].SetColor((int)entity["track"]); + } + } + + public void Undo() + { + for (var i = 0; i < entityIDs.Count; i++) + { + var entity = GameManager.instance.Beatmap.Entities.Find(c => c.guid == entityIDs[i]); + + entity.beat = lastMove.beat[i]; + entity["track"] = lastMove.layer[i]; + + if (TimelineBlockManager.Instance.EntityMarkers.ContainsKey(entity.guid)) + TimelineBlockManager.Instance.EntityMarkers[entity.guid].SetColor((int)entity["track"]); + } + } + } + + public class InsertSpace : ICommand + { + private Guid entityId; + private double newBeat, lastBeat; + private SpecialTimeline.HoveringTypes type; + + public InsertSpace(Guid entityId, double newBeat, SpecialTimeline.HoveringTypes type) + { + this.entityId = entityId; + this.newBeat = newBeat; + this.type = type; + } + + public void Execute() + { + RiqEntity movedEntity = null; + switch (type) + { + case SpecialTimeline.HoveringTypes.TempoChange: + movedEntity = GameManager.instance.Beatmap.TempoChanges.Find(x => x.guid == entityId); + break; + case SpecialTimeline.HoveringTypes.VolumeChange: + movedEntity = GameManager.instance.Beatmap.VolumeChanges.Find(x => x.guid == entityId); + break; + case SpecialTimeline.HoveringTypes.SectionChange: + movedEntity = GameManager.instance.Beatmap.SectionMarkers.Find(x => x.guid == entityId); + break; + } + if (movedEntity != null) + { + lastBeat = movedEntity.beat; + movedEntity.beat = newBeat; + } + } + + public void Undo() + { + RiqEntity movedEntity = null; + switch (type) + { + case SpecialTimeline.HoveringTypes.TempoChange: + movedEntity = GameManager.instance.Beatmap.TempoChanges.Find(x => x.guid == entityId); + break; + case SpecialTimeline.HoveringTypes.VolumeChange: + movedEntity = GameManager.instance.Beatmap.VolumeChanges.Find(x => x.guid == entityId); + break; + case SpecialTimeline.HoveringTypes.SectionChange: + movedEntity = GameManager.instance.Beatmap.SectionMarkers.Find(x => x.guid == entityId); + break; + } + if (movedEntity != null) + { + movedEntity.beat = lastBeat; + } + } + } + + public class DeleteSpace : ICommand + { + private readonly List entityIDs = new(); + private EntityMove newMove; + private EntityMove lastMove; + + private struct EntityMove + { + public List beat; + public List layer; + + public EntityMove(List beat, List layer) + { + this.beat = beat; + this.layer = layer; + } + } + + public DeleteSpace(List originalEntities, List newBeat, List newLayer) + { + entityIDs = originalEntities.Select(c => c.guid).ToList(); + newMove = new EntityMove(newBeat, newLayer); + } + + public void Execute() + { + lastMove = new EntityMove(); + lastMove.beat = new(); + lastMove.layer = new(); + + for (var i = 0; i < entityIDs.Count; i++) + { + var entity = GameManager.instance.Beatmap.Entities.Find(c => c.guid == entityIDs[i]); + + lastMove.beat.Add(entity.beat); + lastMove.layer.Add((int)entity["track"]); + + entity.beat = newMove.beat[i]; + entity["track"] = newMove.layer[i]; + + if (TimelineBlockManager.Instance.EntityMarkers.ContainsKey(entity.guid)) + TimelineBlockManager.Instance.EntityMarkers[entity.guid].SetColor((int)entity["track"]); + } + } + + public void Undo() + { + for (var i = 0; i < entityIDs.Count; i++) + { + var entity = GameManager.instance.Beatmap.Entities.Find(c => c.guid == entityIDs[i]); + + entity.beat = lastMove.beat[i]; + entity["track"] = lastMove.layer[i]; + + if (TimelineBlockManager.Instance.EntityMarkers.ContainsKey(entity.guid)) + TimelineBlockManager.Instance.EntityMarkers[entity.guid].SetColor((int)entity["track"]); + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/LevelEditor/Commands/Space.cs.meta b/Assets/Scripts/LevelEditor/Commands/Space.cs.meta new file mode 100644 index 000000000..8d3c184d4 --- /dev/null +++ b/Assets/Scripts/LevelEditor/Commands/Space.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6bb50347e9fcfa143aa79f3ef0f0b436 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/LevelEditor/Editor.cs b/Assets/Scripts/LevelEditor/Editor.cs index d85ad599d..800c894bf 100644 --- a/Assets/Scripts/LevelEditor/Editor.cs +++ b/Assets/Scripts/LevelEditor/Editor.cs @@ -199,6 +199,18 @@ namespace HeavenStudio.Editor { Timeline.instance.Paste(); } + + if (Input.GetKey(KeyCode.LeftShift)) + { + if (Input.GetKeyDown(KeyCode.I)) + { + Timeline.instance.InsertSpace(); + } + else if (Input.GetKeyDown(KeyCode.U)) + { + Timeline.instance.DeleteSpace(); + } + } } if (Input.GetKey(KeyCode.LeftControl)) diff --git a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs index d393ca8bd..3af97d883 100644 --- a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs +++ b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs @@ -935,6 +935,30 @@ namespace HeavenStudio.Editor.Track return dup; } + public void InsertSpace() + { + Debug.Log($"{snapInterval} {PlaybackBeat}"); + + // List newBeats = new(); + // List lastLayers = new(); + // foreach (var marker in Selections.instance.eventsSelected) + // { + // var entity = marker.entity; + + // lastBeats.Add(marker.entity.beat); + // lastLayers.Add((int)marker.entity["track"]); + + // entity.beat = marker.lastBeat; + // entity["track"] = marker.lastLayer; + // } + // CommandManager.Instance.AddCommand(new Commands.MoveEntity(Selections.instance.eventsSelected.Select(c => c.entity).ToList(), lastBeats, lastLayers)); + } + + public void DeleteSpace() + { + Debug.Log($"{snapInterval} {PlaybackBeat}"); + } + public float SnapToLayer(float y) { float size = LayerHeight(); diff --git a/Assets/Scripts/LevelEditor/Timeline/TimelineEventObj.cs b/Assets/Scripts/LevelEditor/Timeline/TimelineEventObj.cs index 4aea9618a..2fa616596 100644 --- a/Assets/Scripts/LevelEditor/Timeline/TimelineEventObj.cs +++ b/Assets/Scripts/LevelEditor/Timeline/TimelineEventObj.cs @@ -238,11 +238,10 @@ namespace HeavenStudio.Editor.Track if (moving) { - // Debug.Log($"{minBeat} {maxBeat} {minTrack} {maxTrack} {Timeline.instance.MousePos2BeatSnap}"); foreach (var marker in Selections.instance.eventsSelected) { - var nextBeat = System.Math.Max(Timeline.instance.MousePos2BeatSnap, 0 + selectedMaxInitMoveX) - marker.initMoveX; - var nextTrack = Mathf.Clamp(Timeline.instance.MousePos2Layer, 0 + selectedMaxInitMoveY, Timeline.instance.LayerCount - 1 + selectedMinInitMoveY) - marker.initMoveY; + var nextBeat = System.Math.Max(Timeline.instance.MousePos2BeatSnap, selectedMaxInitMoveX) - marker.initMoveX; + var nextTrack = Mathf.Clamp(Timeline.instance.MousePos2Layer, selectedMaxInitMoveY, Timeline.instance.LayerCount - 1 + selectedMinInitMoveY) - marker.initMoveY; marker.entity.beat = System.Math.Max(nextBeat, 0); marker.entity["track"] = Mathf.Clamp(nextTrack, 0, Timeline.instance.LayerCount - 1); marker.SetColor((int)entity["track"]);