Пример #1
0
    ChartObject[] ScanArea(Vector2 cornerA, Vector2 cornerB, uint minLimitInclusive, uint maxLimitNonInclusive)
    {
        Clipboard.SelectionArea area = new Clipboard.SelectionArea(cornerA, cornerB, minLimitInclusive, maxLimitNonInclusive);
        Rect areaRect = area.GetRect(editor.currentSong);

        List <ChartObject> chartObjectsList = new List <ChartObject>();
        int index, length;
        var chartObjects = editor.currentChart.chartObjects;

        SongObjectHelper.GetRange(chartObjects, minLimitInclusive, maxLimitNonInclusive, out index, out length);

        for (int i = index; i < index + length; ++i)
        {
            if (chartObjects[i].tick < maxLimitNonInclusive && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(chartObjects[i]), areaRect))
            {
                chartObjectsList.Add(chartObjects[i]);
            }
        }

        return(chartObjectsList.ToArray());
    }
Пример #2
0
    // 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
    }
    SongObject[] ScanArea(Vector2 cornerA, Vector2 cornerB, uint minLimitInclusive, uint maxLimitNonInclusive)
    {
        Clipboard.SelectionArea area = new Clipboard.SelectionArea(cornerA, cornerB, minLimitInclusive, maxLimitNonInclusive);
        Rect areaRect = area.GetRect(editor.currentSong);

        List <SongObject> chartObjectsList = new List <SongObject>();

        if (Globals.viewMode == Globals.ViewMode.Chart)
        {
            int index, length;
            SongObjectHelper.GetRange(editor.currentChart.chartObjects, minLimitInclusive, maxLimitNonInclusive, out index, out length);

            for (int i = index; i < index + length; ++i)
            {
                ChartObject chartObject = editor.currentChart.chartObjects[i];
                float       offset      = 0;
                if ((SongObject.ID)chartObject.classID == SongObject.ID.ChartEvent)
                {
                    offset = ChartEventController.GetOffset(editor, (ChartEvent)chartObject);
                }

                if (chartObject.tick < maxLimitNonInclusive && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(chartObject, 0, offset), areaRect))
                {
                    chartObjectsList.Add(chartObject);
                }
            }
        }
        else
        {
            // Gather synctrack, sections and events
            int index, length;
            SongObjectHelper.GetRange(editor.currentSong.syncTrack, minLimitInclusive, maxLimitNonInclusive, out index, out length);

            // Synctrack
            for (int i = index; i < index + length; ++i)
            {
                SongObject chartObject = editor.currentSong.syncTrack[i];

                if (chartObject.tick < maxLimitNonInclusive && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(chartObject), areaRect))
                {
                    chartObjectsList.Add(chartObject);
                }
            }

            SongObjectHelper.GetRange(editor.currentSong.eventsAndSections, minLimitInclusive, maxLimitNonInclusive, out index, out length);

            // Events and sections
            for (int i = index; i < index + length; ++i)
            {
                SongObject chartObject = editor.currentSong.eventsAndSections[i];
                float      offset      = 0;
                if ((SongObject.ID)chartObject.classID == SongObject.ID.Event)
                {
                    offset = EventController.GetOffset(editor, (Event)chartObject);
                }

                if (chartObject.tick < maxLimitNonInclusive && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(chartObject, 0, offset), areaRect))
                {
                    chartObjectsList.Add(chartObject);
                }
            }
        }

        return(chartObjectsList.ToArray());
    }
    SongObject[] ScanArea(Vector2 cornerA, Vector2 cornerB, uint minLimitInclusive, uint maxLimitNonInclusive)
    {
        Clipboard.SelectionArea area = new Clipboard.SelectionArea(cornerA, cornerB, minLimitInclusive, maxLimitNonInclusive);
        Rect areaRect = area.GetRect(editor.currentSong);

        List <SongObject> chartObjectsList = new List <SongObject>();

        if (Globals.viewMode == Globals.ViewMode.Chart)
        {
            int index, length;
            SongObjectHelper.GetRange(editor.currentChart.chartObjects, minLimitInclusive, maxLimitNonInclusive, out index, out length);

            for (int i = index; i < index + length; ++i)
            {
                ChartObject chartObject = editor.currentChart.chartObjects[i];
                float       offset      = 0;

                if ((SongObject.ID)chartObject.classID == SongObject.ID.Note)
                {
                    // If the object is within a lane that is not currently included we need to skip over this note
                    if (((Note)chartObject).ShouldBeCulledFromLanes(editor.laneInfo))
                    {
                        continue;
                    }
                }

                if (chartObject.tick < maxLimitNonInclusive && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(chartObject, 0, offset), areaRect))
                {
                    chartObjectsList.Add(chartObject);
                }
            }
        }
        else
        {
            // Gather synctrack, sections and events
            int index, length;
            SongObjectHelper.GetRange(editor.currentSong.syncTrack, minLimitInclusive, maxLimitNonInclusive, out index, out length);

            // Synctrack
            for (int i = index; i < index + length; ++i)
            {
                SongObject chartObject = editor.currentSong.syncTrack[i];

                if (chartObject.tick < maxLimitNonInclusive && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(chartObject), areaRect))
                {
                    chartObjectsList.Add(chartObject);
                }
            }

            SongObjectHelper.GetRange(editor.currentSong.eventsAndSections, minLimitInclusive, maxLimitNonInclusive, out index, out length);

            // Events and sections
            for (int i = index; i < index + length; ++i)
            {
                SongObject chartObject = editor.currentSong.eventsAndSections[i];
                float      offset      = 0;

                if (chartObject.tick < maxLimitNonInclusive && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(chartObject, 0, offset), areaRect))
                {
                    chartObjectsList.Add(chartObject);
                }
            }
        }

        return(chartObjectsList.ToArray());
    }