protected virtual void Update() { if (currentSongObject == null || prevSongObject != currentSongObject) { // F*****g awful but it works. Basically a work-around due to how you can no longer use != to compare between events because they compare the strings of their titles. if (!(currentSongObject != null && prevSongObject != null && currentSongObject.GetType() == prevSongObjectRef.GetType() && ReferenceEquals(prevSongObjectRef, currentSongObject))) { ResetActionRecording(); } } }
protected virtual UndoRedoJumpInfo GetUndoRedoJumpInfo() { SongObject lowestTickSo = null; UndoRedoJumpInfo info = new UndoRedoJumpInfo(); foreach (SongObject songObject in songObjects) { if (lowestTickSo == null || songObject.tick < lowestTickSo.tick) { lowestTickSo = songObject; } } if (lowestTickSo != null) { info.jumpToPos = lowestTickSo.tick; info.viewMode = lowestTickSo.GetType().IsSubclassOf(typeof(ChartObject)) ? Globals.ViewMode.Chart : Globals.ViewMode.Song; } else { info.jumpToPos = null; } return(info); }
protected override UndoRedoJumpInfo GetUndoRedoJumpInfo() { SongObject lowestTickSo = null; SongObject highestTickSo = null; UndoRedoJumpInfo info = new UndoRedoJumpInfo(); foreach (SongEditCommand command in commands) { if (command.subActions.Count > 0) { foreach (BaseAction action in command.subActions) { SongObject so = action.songObject; if (lowestTickSo == null || so.tick < lowestTickSo.tick) { lowestTickSo = so; } if (highestTickSo == null || so.tick > highestTickSo.tick) { highestTickSo = so; } } } else { foreach (SongObject so in command.GetSongObjects()) { if (lowestTickSo == null || so.tick < lowestTickSo.tick) { lowestTickSo = so; } if (highestTickSo == null || so.tick > highestTickSo.tick) { highestTickSo = so; } } } } if (lowestTickSo != null) { info.jumpToPos = lowestTickSo.tick; info.viewMode = lowestTickSo.GetType().IsSubclassOf(typeof(ChartObject)) ? Globals.ViewMode.Chart : Globals.ViewMode.Song; info.min = lowestTickSo.tick; } else { info.jumpToPos = null; } if (highestTickSo != null) { info.max = highestTickSo.tick; } return(info); }
void PostExecuteUpdate(bool isInvoke) { if (!postExecuteEnabled) { return; } ChartEditor editor = ChartEditor.Instance; if (!bpmAnchorFixupCommandsGenerated) { GenerateFixUpBPMAnchorCommands(); } if (isInvoke) { foreach (ICommand command in bpmAnchorFixup) { command.Invoke(); } } else { foreach (ICommand command in bpmAnchorFixup) { command.Revoke(); } } editor.currentChart.UpdateCache(); editor.currentSong.UpdateCache(); if (Toolpane.currentTool != Toolpane.Tools.Note) { editor.currentSelectedObject = null; } ChartEditor.isDirty = true; var soList = validatedSongObjects.Count > 0 ? validatedSongObjects : songObjects; SongObject lowestTickSo = null; foreach (SongObject songObject in soList) { if (lowestTickSo == null || songObject.tick < lowestTickSo.tick) { lowestTickSo = songObject; } } if (lowestTickSo != null) { uint jumpToPos = lowestTickSo.tick; Globals.ViewMode viewMode = lowestTickSo.GetType().IsSubclassOf(typeof(ChartObject)) ? Globals.ViewMode.Chart : Globals.ViewMode.Song; editor.FillUndoRedoSnapInfo(jumpToPos, viewMode); } }
public static void ApplyAction(SongObject songObject) { ChartEditor editor = ChartEditor.Instance; if (songObject.GetType().IsSubclassOf(typeof(ChartObject)) || songObject.GetType() == typeof(ChartObject)) { TryDeleteSongObject((ChartObject)songObject, editor.currentChart.chartObjects); } else { if (songObject.GetType().IsSubclassOf(typeof(Event)) || songObject.GetType() == typeof(Event)) { TryDeleteSongObject((Event)songObject, editor.currentSong.eventsAndSections); } else { TryDeleteSongObject((SyncTrack)songObject, editor.currentSong.syncTrack); } } }
public static void ApplyAction(SongObject songObject, IList <SongObject> overwrittenList) { ChartEditor editor = ChartEditor.Instance; // Find each item if (songObject.GetType().IsSubclassOf(typeof(ChartObject)) || songObject.GetType() == typeof(ChartObject)) { TryDeleteSongObject((ChartObject)songObject, editor.currentChart.chartObjects, overwrittenList); } else { if (songObject.GetType().IsSubclassOf(typeof(Event)) || songObject.GetType() == typeof(Event)) { TryDeleteSongObject((Event)songObject, editor.currentSong.events, overwrittenList); } else { TryDeleteSongObject((SyncTrack)songObject, editor.currentSong.syncTrack, overwrittenList); } } }
public bool Undo(ChartEditor editor) { if (canUndo) { ChartEditor.isDirty = true; float frame = timestamps[historyPoint]; int actionsUndone = 0; SongObject setPos = null; while (historyPoint >= 0 && Mathf.Abs(timestamps[historyPoint] - frame) < ACTION_WINDOW_TIME) { for (int i = actionList[historyPoint].Length - 1; i >= 0; --i) { setPos = actionList[historyPoint][i].Revoke(editor); ++actionsUndone; } --historyPoint; } editor.currentChart.UpdateCache(); editor.currentSong.UpdateCache(); editor.FixUpBPMAnchors(); if (Toolpane.currentTool != Toolpane.Tools.Note) { editor.currentSelectedObject = null; } if (setPos.tick < editor.currentSong.WorldYPositionToTick(editor.visibleStrikeline.position.y) || setPos.tick > editor.maxPos) { editor.movement.SetPosition(setPos.tick); } if (setPos.GetType().IsSubclassOf(typeof(ChartObject))) { if (Globals.viewMode == Globals.ViewMode.Song) // Placing local object while in chart view { editor.toolPanel.ToggleSongViewMode(false); } } else if (Globals.viewMode == Globals.ViewMode.Chart) // Placing global object while in local view { editor.toolPanel.ToggleSongViewMode(true); } Debug.Log("Undo: " + actionsUndone + " actions"); return(true); } Debug.Log("Undo: 0 actions"); return(false); }
public static void ApplyAction(SongObject songObject) { ChartEditor editor = ChartEditor.Instance; if (songObject.GetType().IsSubclassOf(typeof(ChartObject)) || songObject.GetType() == typeof(ChartObject)) { TryDeleteSongObject((ChartObject)songObject, editor.currentChart.chartObjects); } else { if (songObject.GetType().IsSubclassOf(typeof(Event)) || songObject.GetType() == typeof(Event)) { TryDeleteSongObject((Event)songObject, editor.currentSong.events); } else { TryDeleteSongObject((SyncTrack)songObject, editor.currentSong.syncTrack); if (songObject.classID == (int)SongObject.ID.BPM) { ChartEditor.Instance.songObjectPoolManager.SetAllPoolsDirty(); } } } }
protected override bool Equals(SongObject b) { if (b.GetType() == typeof(Note)) { Note realB = b as Note; if (tick == realB.tick && rawNote == realB.rawNote) { return(true); } else { return(false); } } else { return(base.Equals(b)); } }
protected override bool Equals(SongObject b) { if (b.GetType() == typeof(Event)) { Event realB = b as Event; if (tick == realB.tick && title == realB.title) { return(true); } else { return(false); } } else { return(base.Equals(b)); } }
protected override bool Equals(SongObject b) { if (b.GetType() == typeof(ChartEvent)) { ChartEvent realB = b as ChartEvent; if (tick == realB.tick && eventName == realB.eventName) { return(true); } else { return(false); } } else { return(base.Equals(b)); } }
protected override bool LessThan(SongObject b) { if (b.GetType() == typeof(Note)) { Note realB = b as Note; if (tick < b.tick) { return(true); } else if (tick == b.tick) { if (rawNote < realB.rawNote) { return(true); } } return(false); } else { return(base.LessThan(b)); } }
protected override bool LessThan(SongObject b) { if (b.GetType() == typeof(Event)) { Event realB = b as Event; if (tick < b.tick) { return(true); } else if (tick == b.tick) { if (string.Compare(title, realB.title) < 0) { return(true); } } return(false); } else { return(base.LessThan(b)); } }
protected void UpdateInputFieldRecord() { if (currentSongObject == null || prevSongObject == null || prevSongObject != currentSongObject) { if (! ( (currentSongObject.GetType() == typeof(ChartEvent) || currentSongObject.GetType() == typeof(Event)) && currentSongObject.GetType() == prevSongObject.GetType() ) ) { return; } } string value = GetValue(currentSongObject); if (value == prevValue || value == GetValue(prevSongObject)) { return; } // Check if there's a record already in if (inputFieldModify == null || lastKnownDirection == ValueDirection.NONE) { // Add a new record inputFieldModify = new ActionHistory.Modify(prevSongObject, currentSongObject); // Add to action history editor.actionHistory.Insert(inputFieldModify); if (GetValue(currentSongObject).Length < GetValue(prevSongObject).Length) { lastKnownDirection = ValueDirection.DOWN; } else if (GetValue(currentSongObject).Length > GetValue(prevSongObject).Length) { lastKnownDirection = ValueDirection.UP; } else { lastKnownDirection = ValueDirection.NONE; } } // Else check if a new record needs to overwrite this current one or if this one needs to be edited else if (inputFieldModify != null) { if (value.Length < prevValue.Length) { if (lastKnownDirection == ValueDirection.DOWN) { // Edit action inputFieldModify.after = currentSongObject.Clone(); } else { // New action inputFieldModify = new ActionHistory.Modify(prevSongObject, currentSongObject); // Add to action history editor.actionHistory.Insert(inputFieldModify); } lastKnownDirection = ValueDirection.DOWN; } else if (value.Length > prevValue.Length) { if (lastKnownDirection == ValueDirection.UP) { // Edit action inputFieldModify.after = currentSongObject.Clone(); } else { // New action inputFieldModify = new ActionHistory.Modify(prevSongObject, currentSongObject); // Add to action history editor.actionHistory.Insert(inputFieldModify); } lastKnownDirection = ValueDirection.UP; } else { // Add a new record inputFieldModify = new ActionHistory.Modify(prevSongObject, currentSongObject); // Add to action history editor.actionHistory.Insert(inputFieldModify); } } prevValue = value; }
protected void ShouldRecordInputField(string newLabel, string oldLabel, out bool tentativeRecord, out bool lockedRecord, bool ignoreEmptyLabels = false) { tentativeRecord = false; lockedRecord = false; if (ignoreEmptyLabels && string.IsNullOrEmpty(newLabel)) { return; } if (currentSongObject == null || prevSongObject == null || prevSongObject != currentSongObject) { bool sameType = prevSongObject != null && currentSongObject.GetType() == prevSongObject.GetType(); if (!sameType) { return; } } string value = newLabel; if (value.Equals(oldLabel)) { return; } // Check if there's a record already in if (!commandRecordingInProcess || lastKnownDirection == ValueDirection.NONE) { if (value.Length < oldLabel.Length) { lastKnownDirection = ValueDirection.DOWN; } else if (value.Length > oldLabel.Length) { lastKnownDirection = ValueDirection.UP; } else { lastKnownDirection = ValueDirection.NONE; } lockedRecord = !commandRecordingInProcess; tentativeRecord = true; commandRecordingInProcess = true; } // Else check if a new record needs to overwrite this current one or if this one needs to be edited else if (commandRecordingInProcess) { if (value.Length < oldLabel.Length) { if (lastKnownDirection == ValueDirection.DOWN) { tentativeRecord = true; } else { lockedRecord = true; } lastKnownDirection = ValueDirection.DOWN; } else if (value.Length > oldLabel.Length) { if (lastKnownDirection == ValueDirection.UP) { tentativeRecord = true; } else { lockedRecord = true; } lastKnownDirection = ValueDirection.UP; } else { lockedRecord = true; } } }
// Paste the clipboard data into the chart, overwriting anything else in the process public void Paste(uint chartLocationToPaste) { //if (System.Windows.Forms.Clipboard.GetDataObject().GetFormats().Length > 0 && // !( // System.Windows.Forms.Clipboard.ContainsText(TextDataFormat.UnicodeText) && // System.Windows.Forms.Clipboard.ContainsText(TextDataFormat.Text) && // System.Windows.Forms.Clipboard.GetText() == "") // ) // Something else is pasted on the clipboard instead of Moonscraper stuff. // return; FileStream fs = null; clipboard = null; try { // Read clipboard data from a file instead of the actual clipboard because the actual clipboard doesn't work for whatever reason fs = new FileStream(CLIPBOARD_FILE_LOCATION, FileMode.Open); BinaryFormatter formatter = new BinaryFormatter(); clipboard = (Clipboard)formatter.Deserialize(fs); } catch (System.Exception e) { Logger.LogException(e, "Failed to read from clipboard file"); clipboard = null; } finally { if (fs != null) { fs.Close(); } else { Debug.LogError("Filestream when reading clipboard data failed to initialise"); } } if (Globals.applicationMode == Globals.ApplicationMode.Editor && clipboard != null && clipboard.data.Length > 0) { List <SongEditCommand> commands = new List <SongEditCommand>(); Rect collisionRect = clipboard.GetCollisionRect(chartLocationToPaste, editor.currentSong); if (clipboard.areaChartPosMin > clipboard.areaChartPosMax) { Debug.LogError("Clipboard minimum (" + clipboard.areaChartPosMin + ") is greater than clipboard the max (" + clipboard.areaChartPosMax + ")"); } uint colliderChartDistance = TickFunctions.TickScaling(clipboard.areaChartPosMax - clipboard.areaChartPosMin, clipboard.resolution, editor.currentSong.resolution); viewModeController.ToggleSongViewMode(!clipboard.data[0].GetType().IsSubclassOf(typeof(ChartObject))); { List <SongObject> newObjectsToDelete = new List <SongObject>(); // Overwrite any objects in the clipboard space if (clipboard.data[0].GetType().IsSubclassOf(typeof(ChartObject))) { foreach (ChartObject chartObject in editor.currentChart.chartObjects) { if (chartObject.tick >= chartLocationToPaste && chartObject.tick <= (chartLocationToPaste + colliderChartDistance) && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(chartObject), collisionRect)) { newObjectsToDelete.Add(chartObject); } } } else { // Overwrite synctrack, leave sections alone foreach (SyncTrack syncObject in editor.currentSong.syncTrack) { if (syncObject.tick >= chartLocationToPaste && syncObject.tick <= (chartLocationToPaste + colliderChartDistance) && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(syncObject), collisionRect)) { newObjectsToDelete.Add(syncObject); } } } if (newObjectsToDelete.Count > 0) { commands.Add(new SongEditDelete(newObjectsToDelete)); } } { uint maxLength = editor.currentSong.TimeToTick(editor.currentSong.length, editor.currentSong.resolution); List <SongObject> newObjectsToAddIn = new List <SongObject>(); // Paste the new objects in foreach (SongObject clipboardSongObject in clipboard.data) { SongObject objectToAdd = clipboardSongObject.Clone(); objectToAdd.tick = chartLocationToPaste + TickFunctions.TickScaling(clipboardSongObject.tick, clipboard.resolution, editor.currentSong.resolution) - TickFunctions.TickScaling(clipboard.areaChartPosMin, clipboard.resolution, editor.currentSong.resolution); if (objectToAdd.tick >= maxLength) { break; } if (objectToAdd.GetType() == typeof(Note)) { Note note = (Note)objectToAdd; if (clipboard.instrument == Song.Instrument.GHLiveGuitar || clipboard.instrument == Song.Instrument.GHLiveBass) { // Pasting from a ghl track if (!Globals.ghLiveMode) { if (note.ghliveGuitarFret == Note.GHLiveGuitarFret.Open) { note.guitarFret = Note.GuitarFret.Open; } else if (note.ghliveGuitarFret == Note.GHLiveGuitarFret.White3) { continue; } } } else if (Globals.ghLiveMode) { // Pasting onto a ghl track if (note.guitarFret == Note.GuitarFret.Open) { note.ghliveGuitarFret = Note.GHLiveGuitarFret.Open; } } note.length = TickFunctions.TickScaling(note.length, clipboard.resolution, editor.currentSong.resolution); } else if (objectToAdd.GetType() == typeof(Starpower)) { Starpower sp = (Starpower)objectToAdd; sp.length = TickFunctions.TickScaling(sp.length, clipboard.resolution, editor.currentSong.resolution); } newObjectsToAddIn.Add(objectToAdd); } if (newObjectsToAddIn.Count > 0) { commands.Add(new SongEditAdd(newObjectsToAddIn)); } } if (commands.Count > 0) { BatchedSongEditCommand batchedCommands = new BatchedSongEditCommand(commands); editor.commandStack.Push(batchedCommands); } } // 0 objects in clipboard, don't bother pasting }