Exemplo n.º 1
0
        private void UpdateDragGridTargetAction()
        {
            var     mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            var     newPosVec3 = NoteGridSnap.SnapToGrid(mousePos, EditorInput.selectedSnappingMode);
            Vector2 newPos     = new Vector2(newPosVec3.x, newPosVec3.y);

            foreach (TargetGridMoveIntent intent in gridTargetMoveIntents)
            {
                var offsetFromDragPoint = intent.startingPosition - startGridMovePos;
                var tempNewPos          = newPos + offsetFromDragPoint;
                intent.target.position = tempNewPos;

                intent.intendedPosition = tempNewPos;
            }
        }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (isMouseDown)
        {
            Vector3 mousePos = cam.ScreenToWorldPoint(Input.mousePosition);

            Vector3 currentPosition = mousePos;

            Vector3 diff = currentPosition - startMousePosition;

            Vector3 pos = startPosition + diff;
            pos.z = transform.position.z;

            if (!shouldSnap)
            {
                transform.position = pos;
            }
            else
            {
                transform.position = NoteGridSnap.SnapToGrid(new Vector3(pos.x, pos.y, -1f), EditorInput.selectedSnappingMode);
            }
        }
    }
Exemplo n.º 3
0
        void Update()
        {
            //If the user decides they hate productivity and want to unselect all their notes, so be it.
            if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.D))
            {
                timeline.DeselectAllTargets();
            }

            //Applying hitsounds to selected:

            if (!activated)
            {
                return;
            }


            //TODO: Add shift + ctrl detection up here instead of multipule times


            if (Input.GetKeyDown(KeyCode.Q))
            {
                SetHitsoundAction(TargetVelocity.Standard);
            }
            else if (Input.GetKeyDown(KeyCode.W))
            {
                SetHitsoundAction(TargetVelocity.Snare);
            }
            else if (Input.GetKeyDown(KeyCode.E))
            {
                SetHitsoundAction(TargetVelocity.Percussion);
            }
            else if (Input.GetKeyDown(KeyCode.R))
            {
                SetHitsoundAction(TargetVelocity.ChainStart);
            }
            else if (Input.GetKeyDown(KeyCode.T))
            {
                SetHitsoundAction(TargetVelocity.Chain);
            }
            else if (Input.GetKeyDown(KeyCode.Y))
            {
                SetHitsoundAction(TargetVelocity.Melee);
            }


            var        iconsUnderMouse = MouseUtil.IconsUnderMouse(notesLayer);
            TargetIcon iconUnderMouse  = iconsUnderMouse.Length > 0 ? iconsUnderMouse[0] : null;

            /** Click Detection **/
            if (isSelectionDown && !hasMovedOutOfClickBounds)
            {
                // Check for a tiny amount of mouse movement to ensure this was meant to be a click

                float movement = Math.Abs(startClickDetectPos.magnitude - Input.mousePosition.magnitude);
                if (movement > 2)
                {
                    hasMovedOutOfClickBounds = true;
                }
            }

            /** Cut Copy Paste Delete **/
            // TODO: Move these actions into timeline to record sane undo actions!
            Action delete = () => {
                if (timeline.selectedNotes.Count > 0)
                {
                    timeline.DeleteTargets(timeline.selectedNotes);
                }
                timeline.selectedNotes = new List <Target>();
            };

            Action copy = () => {
                clipboardNotes = new List <Cue>();
                timeline.selectedNotes.ForEach(note => clipboardNotes.Add(NotePosCalc.ToCue(note, 0, false)));
            };

            Action paste = () => {
                timeline.DeselectAllTargets();
                timeline.PasteCues(clipboardNotes, Timeline.BeatTime());
            };

            if (Input.GetKeyDown(KeyCode.Delete))
            {
                delete();
            }

            bool dev          = false;
            bool modifierHeld = dev ?
                                Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) :
                                Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);

            if (modifierHeld)
            {
                if (Input.GetKeyDown(KeyCode.X))
                {
                    copy();
                    delete();
                }

                if (Input.GetKeyDown(KeyCode.C))
                {
                    copy();
                }

                if (Input.GetKeyDown(KeyCode.V))
                {
                    paste();
                }
            }

            /** Note flipping **/
            if (Input.GetKeyDown(KeyCode.F))
            {
                var ctrlHeld  = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
                var shiftHeld = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

                // flip horizontal
                if (ctrlHeld && !shiftHeld)
                {
                    timeline.FlipTargetsHorizontal(timeline.selectedNotes);
                }

                // flip vertical
                else if (shiftHeld)
                {
                    timeline.FlipTargetsVertical(timeline.selectedNotes);
                }

                // invert
                else
                {
                    timeline.SwapTargets(timeline.selectedNotes);
                }
            }

            /** Click + Drag Handling **/
            //TODOUNDO I think I fixed this? //TODO: it should deselect when resiszing the grid dragger, but not deselect when scrubbing through the timeline while grid dragging

            if (EditorInput.selectedTool == EditorTool.DragSelect)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    if (iconUnderMouse)
                    {
                        var anySelectedIconUnderMouse = iconsUnderMouse.Where(icon => icon.isSelected).ToArray();
                        if (anySelectedIconUnderMouse.Length == 0)
                        {
                            return;
                        }
                        switch (iconUnderMouse.location)
                        {
                        case TargetIconLocation.Grid:
                            StartDragGridTargetAction(iconUnderMouse);
                            break;

                        case TargetIconLocation.Timeline:
                            StartDragTimelineTargetAction(iconUnderMouse);
                            break;
                        }
                    }
                }

                if (Input.GetMouseButtonUp(0))
                {
                    if (isDraggingNotesOnGrid)
                    {
                        EndDragGridTargetAction();
                    }
                    if (isDraggingNotesOnTimeline)
                    {
                        EndDragTimelineTargetAction();
                    }

                    foreach (Target target in timeline.selectedNotes)
                    {
                        if (target.gridTargetIcon)
                        {
                            target.gridTargetPos = target.gridTargetIcon.transform.localPosition;
                        }
                    }
                }

                if (Input.GetMouseButton(0))
                {
                    //If we're not already dragging

                    if (!isDraggingTimeline &&
                        !isDraggingGrid &&
                        !isDraggingNotesOnGrid &&
                        !isDraggingNotesOnTimeline &&
                        !iconUnderMouse
                        )
                    {
                        if (timeline.hover)
                        {
                            StartTimelineDrag();
                        }
                        else
                        {
                            StartGridDrag();
                        }
                    }
                    else if (isDraggingTimeline)
                    {
                        float diff = Camera.main.ScreenToWorldPoint(Input.mousePosition).x - dragSelectTimeline.position.x;
                        float timelineScaleMulti = Timeline.scale / 20f;
                        dragSelectTimeline.localScale = new Vector3(diff * timelineScaleMulti, 1.1f * (Timeline.scale / 20f), 1);
                    }
                    else if (isDraggingGrid)
                    {
                        Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - dragSelectGrid.transform.position;
                        dragSelectGrid.transform.localScale = new Vector3(diff.x, diff.y * -1, 1f);
                    }
                    else if (iconUnderMouse && !isSelectionDown)
                    {
                        StartSelectionAction();
                    }
                    else if (iconUnderMouse && timeline.selectedNotes.Count == 0 && hasMovedOutOfClickBounds)
                    {
                        iconUnderMouse.TrySelect();
                        if (iconUnderMouse.location == TargetIconLocation.Grid)
                        {
                            StartDragGridTargetAction(iconUnderMouse);
                        }
                        if (iconUnderMouse.location == TargetIconLocation.Timeline)
                        {
                            StartDragTimelineTargetAction(iconUnderMouse);
                        }
                    }
                }
                else
                {
                    if (isDraggingTimeline)
                    {
                        EndTimelineDrag();
                    }
                    else if (isDraggingGrid)
                    {
                        EndGridDrag();
                    }
                }
                if (Input.GetMouseButtonUp(0))
                {
                    EndSelectionAction();
                    if (!hasMovedOutOfClickBounds)
                    {
                        TryToggleSelection();
                    }
                }

                if (isDraggingNotesOnGrid)
                {
                    // TODO: this should really be handled by intermediary semi-transparent objects rather than updating "real" state as we go ...

                    var     mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    Vector3 newPos   = NoteGridSnap.SnapToGrid(mousePos, EditorInput.selectedSnappingMode);

                    foreach (TargetMoveIntent intent in gridTargetMoveIntents)
                    {
                        //var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                        var offsetFromDragPoint = intent.target.gridTargetPos - startDragMovePos;
                        //Vector3 newPos = NoteGridSnap.SnapToGrid(mousePos, EditorInput.selectedSnappingMode);
                        var tempNewPos = newPos + offsetFromDragPoint;
                        intent.target.gridTargetIcon.transform.localPosition = new Vector3(tempNewPos.x, tempNewPos.y, intent.target.gridTargetPos.z);
                        if (intent.target.behavior == TargetBehavior.Hold)
                        {
                            var holdEnd = intent.target.gridTargetIcon.GetComponentInChildren <HoldTargetManager>().endMarker;
                            if (holdEnd)
                            {
                                holdEnd.transform.localPosition = new Vector3(tempNewPos.x, tempNewPos.y, holdEnd.transform.localPosition.z);
                            }
                        }

                        //target.gridTargetPos = target.gridTargetIcon.transform.localPosition;

                        intent.intendedPosition = new Vector3(tempNewPos.x, tempNewPos.y, intent.target.gridTargetPos.z);
                    }
                }

                if (isDraggingNotesOnTimeline)
                {
                    foreach (TargetMoveIntent intent in timelineTargetMoveIntents)
                    {
                        var pos     = intent.startingPosition;
                        var gridPos = intent.target.gridTargetIcon.transform.localPosition;

                        var mousePos            = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                        var offsetFromDragPoint = pos - startDragMovePos;

                        Vector3 newPos = SnapToBeat(mousePos);
                        // TODO: Snap!

                        newPos += offsetFromDragPoint;
                        intent.target.timelineTargetIcon.transform.localPosition = new Vector3(newPos.x, pos.y, pos.z);
                        intent.target.gridTargetIcon.transform.localPosition     = new Vector3(gridPos.x, gridPos.y, newPos.x);

                        intent.intendedPosition = new Vector3(newPos.x, pos.y, pos.z);
                    }
                }
            }
        }