Esempio n. 1
0
 public void OnBeginDrag(PointerEventData eventData)
 {
     ignoreDrag     = false;
     isDragging     = true;
     dragStartEvent = CreateNoteAreaBeginDragEvent(eventData);
     NotifyListeners(listener => listener.OnBeginDrag(dragStartEvent), true);
 }
    public void OnDrag(NoteAreaDragEvent dragEvent)
    {
        switch (dragAction)
        {
        case DragAction.Move:
            DragDirection dragDirection = GetDragDirection(dragEvent);
            if (dragDirection == DragDirection.Horizontal)
            {
                MoveNotesHorizontal(dragEvent, selectedNotes, true);
            }
            else
            {
                MoveNotesVertical(dragEvent, selectedNotes, true);
            }
            break;

        case DragAction.StretchLeft:
            StretchNotesLeft(dragEvent, selectedNotes);
            break;

        case DragAction.StretchRight:
            StretchNotesRight(dragEvent, selectedNotes, true);
            break;

        default:
            throw new UnityException("Unkown drag action: " + dragAction);
        }

        editorNoteDisplayer.UpdateNotesAndSentences();
    }
Esempio n. 3
0
    private NoteAreaDragEvent CreateNoteAreaDragEvent(PointerEventData eventData, NoteAreaDragEvent dragStartEvent)
    {
        float xDragStartInPixels = dragStartEvent.XDragStartInPixels;
        float yDragStartInPixels = dragStartEvent.YDragStartInPixels;
        float xDistanceInPixels  = eventData.position.x - xDragStartInPixels;
        float yDistanceInPixels  = eventData.position.y - yDragStartInPixels;

        List <RaycastResult> raycastResults = dragStartEvent.RaycastResultsDragStart;

        float  noteAreaWidthInPixels  = noteAreaRectTransform.rect.width;
        float  noteAreaHeightInPixels = noteAreaRectTransform.rect.height;
        double xDistancePercent       = xDistanceInPixels / noteAreaWidthInPixels;
        double yDistancePercent       = yDistanceInPixels / noteAreaHeightInPixels;

        int midiNoteDragStart = dragStartEvent.MidiNoteDragStart;
        int midiNoteDistance  = (int)(yDistancePercent * noteArea.ViewportHeight);

        int positionInSongInMillisDragStart = dragStartEvent.PositionInSongInMillisDragStart;
        int millisDistance = (int)(xDistancePercent * noteArea.ViewportWidth);

        int positionInSongInBeatsDragStart = dragStartEvent.PositionInSongInBeatsDragStart;
        int beatDistance = (int)(xDistancePercent * noteArea.ViewportWidthInBeats);

        NoteAreaDragEvent result = new NoteAreaDragEvent(xDragStartInPixels, yDragStartInPixels,
                                                         xDistanceInPixels, yDistanceInPixels,
                                                         midiNoteDragStart, midiNoteDistance,
                                                         positionInSongInMillisDragStart, millisDistance,
                                                         positionInSongInBeatsDragStart, beatDistance,
                                                         raycastResults,
                                                         eventData.button);

        return(result);
    }
    private bool IsInSelectionFrame(EditorUiNote uiNote, NoteAreaDragEvent dragEvent)
    {
        Note note = uiNote.Note;

        if (note == null)
        {
            return(false);
        }

        int startMidiNote = dragEvent.MidiNoteDragStart;
        int endMidiNote   = dragEvent.MidiNoteDragStart + dragEvent.MidiNoteDistance;

        if (startMidiNote > endMidiNote)
        {
            ObjectUtils.Swap(ref startMidiNote, ref endMidiNote);
        }

        int startBeat = dragEvent.PositionInSongInBeatsDragStart;
        int endBeat   = dragEvent.PositionInSongInBeatsDragStart + dragEvent.BeatDistance;

        if (startBeat > endBeat)
        {
            ObjectUtils.Swap(ref startBeat, ref endBeat);
        }

        return((startBeat <= note.StartBeat && note.EndBeat <= endBeat) &&
               (startMidiNote <= note.MidiNote && note.MidiNote <= endMidiNote));
    }
    private void UpdateSelection(NoteAreaDragEvent dragEvent)
    {
        List <EditorUiNote> selectedUiNotes = new List <EditorUiNote>();

        foreach (Transform child in noteContainer.transform)
        {
            EditorUiNote uiNote = child.GetComponent <EditorUiNote>();
            if (uiNote != null && IsInSelectionFrame(uiNote, dragEvent))
            {
                selectedUiNotes.Add(uiNote);
            }
        }

        // Add to selection via Shift. Remove from selection via Ctrl+Shift. Without modifier, set selection.
        if (Input.GetKey(KeyCode.LeftShift))
        {
            if (Input.GetKey(KeyCode.LeftControl))
            {
                selectionController.RemoveFromSelection(selectedUiNotes);
            }
            else
            {
                selectionController.AddToSelection(selectedUiNotes);
            }
        }
        else
        {
            selectionController.SetSelection(selectedUiNotes);
        }
    }
 private DragDirection GetDragDirection(NoteAreaDragEvent dragEvent)
 {
     if (Math.Abs(dragEvent.YDistanceInPixels) > Math.Abs(dragEvent.XDistanceInPixels))
     {
         return(DragDirection.Vertical);
     }
     return(DragDirection.Horizontal);
 }
 public void OnEndDrag(NoteAreaDragEvent dragEvent)
 {
     if (noteToSnapshotOfNoteMap.Count > 0)
     {
         // Values have been directly applied to the notes. The snapshot can be cleared.
         noteToSnapshotOfNoteMap.Clear();
         songMetaChangeEventStream.OnNext(new NotesChangedEvent());
     }
 }
Esempio n. 8
0
    public void OnDrag(PointerEventData eventData)
    {
        if (ignoreDrag)
        {
            return;
        }

        NoteAreaDragEvent dragEvent = CreateNoteAreaDragEvent(eventData, dragStartEvent);

        NotifyListeners(listener => listener.OnDrag(dragEvent), false);
    }
    public void OnBeginDrag(NoteAreaDragEvent dragEvent)
    {
        isCanceled = false;
        if (dragEvent.InputButton != PointerEventData.InputButton.Middle)
        {
            CancelDrag();
            return;
        }

        viewportXBeginDrag = noteArea.ViewportX;
    }
 private void StretchNotesLeft(NoteAreaDragEvent dragEvent, List <Note> notes)
 {
     foreach (Note note in notes)
     {
         Note noteSnapshot = noteToSnapshotOfNoteMap[note];
         int  newStartBeat = noteSnapshot.StartBeat + dragEvent.BeatDistance;
         if (newStartBeat < noteSnapshot.EndBeat)
         {
             note.SetStartBeat(newStartBeat);
         }
     }
 }
 private DragAction GetDragAction(EditorUiNote dragStartUiNote, NoteAreaDragEvent dragEvent)
 {
     if (dragStartUiNote.IsPositionOverLeftHandle(dragEvent.DragStartPositionInPixels))
     {
         return(DragAction.StretchLeft);
     }
     else if (dragStartUiNote.IsPositionOverRightHandle(dragEvent.DragStartPositionInPixels))
     {
         return(DragAction.StretchRight);
     }
     return(DragAction.Move);
 }
    private void MoveNotesVertical(NoteAreaDragEvent dragEvent, List <Note> notes, bool adjustFollowingNotesIfNeeded)
    {
        foreach (Note note in notes)
        {
            Note noteSnapshot = noteToSnapshotOfNoteMap[note];
            int  newMidiNote  = noteSnapshot.MidiNote + dragEvent.MidiNoteDistance;
            note.SetMidiNote(newMidiNote);
            note.SetStartAndEndBeat(noteSnapshot.StartBeat, noteSnapshot.EndBeat);
        }

        if (adjustFollowingNotesIfNeeded && settings.SongEditorSettings.AdjustFollowingNotes)
        {
            MoveNotesVertical(dragEvent, followingNotes, false);
        }
    }
    private void StretchNotesRight(NoteAreaDragEvent dragEvent, List <Note> notes, bool adjustFollowingNotesIfNeeded)
    {
        foreach (Note note in notes)
        {
            Note noteSnapshot = noteToSnapshotOfNoteMap[note];
            int  newEndBeat   = noteSnapshot.EndBeat + dragEvent.BeatDistance;
            if (newEndBeat > noteSnapshot.StartBeat)
            {
                note.SetEndBeat(newEndBeat);
            }
        }

        if (adjustFollowingNotesIfNeeded && settings.SongEditorSettings.AdjustFollowingNotes)
        {
            MoveNotesHorizontal(dragEvent, followingNotes, false);
        }
    }
    public void OnBeginDrag(NoteAreaDragEvent dragEvent)
    {
        isCanceled = false;
        if (dragEvent.InputButton != PointerEventData.InputButton.Left)
        {
            CancelDrag();
            return;
        }

        GameObject raycastTarget = dragEvent.RaycastResultsDragStart.Select(it => it.gameObject).FirstOrDefault();

        if (raycastTarget != noteArea.gameObject)
        {
            CancelDrag();
            return;
        }

        selectionFrame.gameObject.SetActive(true);
    }
Esempio n. 15
0
    private NoteAreaDragEvent CreateNoteAreaBeginDragEvent(PointerEventData eventData)
    {
        float xDragStartInPixels = eventData.pressPosition.x;
        float yDragStartInPixels = eventData.pressPosition.y;
        float xDistanceInPixels  = 0;
        float yDistanceInPixels  = 0;

        List <RaycastResult> raycastResults      = new List <RaycastResult>();
        PointerEventData     eventDataForRaycast = new PointerEventData(EventSystem.current);

        eventDataForRaycast.position = eventData.pressPosition;
        graphicRaycaster.Raycast(eventDataForRaycast, raycastResults);

        RectTransformUtility.ScreenPointToLocalPointInRectangle(noteAreaRectTransform,
                                                                eventData.pressPosition,
                                                                eventData.pressEventCamera,
                                                                out Vector2 localPoint);

        float  noteAreaWidthInPixels  = noteAreaRectTransform.rect.width;
        float  noteAreaHeightInPixels = noteAreaRectTransform.rect.height;
        double xPercent = (localPoint.x + (noteAreaWidthInPixels / 2)) / noteAreaWidthInPixels;
        double yPercent = (localPoint.y + (noteAreaHeightInPixels / 2)) / noteAreaHeightInPixels;

        int midiNoteDragStart = (int)(noteArea.ViewportY + yPercent * noteArea.ViewportHeight);
        int midiNoteDistance  = 0;

        int positionInSongInMillisDragStart = (int)(noteArea.ViewportX + xPercent * noteArea.ViewportWidth);
        int millisDistance = 0;

        int positionInSongInBeatsDragStart = (int)(noteArea.MinBeatInViewport + xPercent * noteArea.ViewportWidthInBeats);
        int beatDistance = 0;

        NoteAreaDragEvent result = new NoteAreaDragEvent(xDragStartInPixels, yDragStartInPixels,
                                                         xDistanceInPixels, yDistanceInPixels,
                                                         midiNoteDragStart, midiNoteDistance,
                                                         positionInSongInMillisDragStart, millisDistance,
                                                         positionInSongInBeatsDragStart, beatDistance,
                                                         raycastResults,
                                                         eventData.button);

        return(result);
    }
    private void UpdateSelectionFrame(NoteAreaDragEvent dragEvent)
    {
        float x      = dragEvent.XDragStartInPixels;
        float y      = dragEvent.YDragStartInPixels;
        float width  = dragEvent.XDistanceInPixels;
        float height = -dragEvent.YDistanceInPixels;

        if (width < 0)
        {
            width = -width;
            x    -= width;
        }
        if (height < 0)
        {
            height = -height;
            y     += height;
        }
        selectionFrame.position  = new Vector2(x, y);
        selectionFrame.sizeDelta = new Vector2(width, height);
    }
    public void OnBeginDrag(NoteAreaDragEvent dragEvent)
    {
        if (dragEvent.InputButton != PointerEventData.InputButton.Left)
        {
            CancelDrag();
            return;
        }

        isCanceled = false;
        GameObject   raycastTarget   = dragEvent.RaycastResultsDragStart.Select(it => it.gameObject).FirstOrDefault();
        EditorUiNote dragStartUiNote = raycastTarget.GetComponent <EditorUiNote>();

        if (dragStartUiNote == null)
        {
            CancelDrag();
            return;
        }

        if (!selectionController.IsSelected(dragStartUiNote.Note))
        {
            selectionController.SetSelection(new List <EditorUiNote> {
                dragStartUiNote
            });
        }

        dragAction = GetDragAction(dragStartUiNote, dragEvent);

        selectedNotes = selectionController.GetSelectedNotes();
        if (settings.SongEditorSettings.AdjustFollowingNotes)
        {
            followingNotes = SongMetaUtils.GetFollowingNotes(songMeta, selectedNotes);
        }
        else
        {
            followingNotes.Clear();
        }

        CreateSnapshot(selectedNotes.Union(followingNotes));
    }
 public void OnEndDrag(NoteAreaDragEvent dragEvent)
 {
     selectionFrame.gameObject.SetActive(false);
 }
 public void OnDrag(NoteAreaDragEvent dragEvent)
 {
     UpdateSelectionFrame(dragEvent);
     UpdateSelection(dragEvent);
 }
 public void OnEndDrag(NoteAreaDragEvent dragEvent)
 {
     // Do nothing, scrolling was done already in OnDrag.
 }
    public void OnDrag(NoteAreaDragEvent dragEvent)
    {
        int newViewportX = viewportXBeginDrag - dragEvent.MillisDistance;

        noteArea.SetViewportX(newViewportX);
    }