Exemplo n.º 1
0
    public void Update()
    {
        if ((InputManager.leftMousePushed && !HoveringOverSubmenuItem()) || InputManager.anyPushed)
        {
            UntoggleAllSubmenus();
        }

        // Exit
        if (backButton.clicked)
        {
            Vector2 windowCenter = new Vector2(VoezEditor.windowRes.x * 0.5f, VoezEditor.windowRes.y * 0.5f);
            exitConfirm = new ConfirmBox(new Rect(new Vector2(windowCenter.x - 300f, windowCenter.y - 150f), new Vector2(600f, 300f)), "Save your changes before exiting?");
            exitConfirm.enableCancel = true;
            VoezEditor.Editor.AddObject(exitConfirm);
            backButton.clicked = false;
        }
        if (exitConfirm != null)
        {
            if (exitConfirm.yesButton != null && exitConfirm.yesButton.clicked)
            {
                VoezEditor.Editor.project.ExportActiveProject();
                VoezEditor.Editor.readyToShutDown  = true;
                InputManager.ignoreNextLeftRelease = true;
                exitConfirm.Destroy();
                exitConfirm = null;
            }
            else if (exitConfirm.noButton != null && exitConfirm.noButton.clicked)
            {
                VoezEditor.Editor.readyToShutDown  = true;
                InputManager.ignoreNextLeftRelease = true;
                exitConfirm.Destroy();
                exitConfirm = null;
            }
            else if (exitConfirm.cancelButton != null && exitConfirm.cancelButton.clicked)
            {
                exitConfirm.Destroy();
                exitConfirm = null;
            }
        }

        // Handle Playback Slider Dragged
        if (playbackSlider.progressUpdate)
        {
            VoezEditor.Editor.musicPlayer.source.time = VoezEditor.Editor.musicPlayer.source.clip.length * Mathf.Clamp(playbackSlider.progress, 0f, 0.99f);
            VoezEditor.Editor.currentFrame            = (int)(VoezEditor.Editor.musicPlayer.source.time * VoezEditor.Editor.framesPerSecond);
            grid.SnapPlaytimeToGrid();
            playbackSlider.progressUpdate = false;
        }

        // Update timestamp for current song time
        if (VoezEditor.Editor.musicPlayer.source.clip != null)
        {
            playbackSlider.allowScrubbing = true;
            playbackSlider.progress       = VoezEditor.Editor.songTime / VoezEditor.Editor.musicPlayer.source.clip.length;
            if (!playbackSlider.clicked)
            {
                // If playback slider is not being dragged, show current song time.
                playbackTimeLabel.SetText(BeatTimeStamp(VoezEditor.Editor.songTime));
            }
            else
            {
                // If playback slider is being dragged, show song time at slider's current position
                playbackTimeLabel.SetText(BeatTimeStamp(VoezEditor.Editor.musicPlayer.source.clip.length * playbackSlider.pendingProgress));
            }
        }
        else
        {
            playbackSlider.allowScrubbing = false;
        }

        // Play/Pause
        if (playButton.clicked || InputManager.spacePushed)
        {
            if (VoezEditor.Editor.musicPlayer.paused)
            {
                VoezEditor.Editor.musicPlayer.ResumeSong();
                playButton.mySymbol.element = Futile.atlasManager.GetElementWithName("pause");
            }
            else
            {
                VoezEditor.Editor.musicPlayer.PauseSong();
                playButton.mySymbol.element = Futile.atlasManager.GetElementWithName("play");
                grid.SnapPlaytimeToGrid();
            }
            playButton.clicked = false;
        }

        // Toggle Loop Point
        if (playbackSlider.rightClicked)
        {
            if (playbackSlider.loopPoint >= 0f)
            {
                playbackSlider.loopPoint = -1;
            }
            else
            {
                playbackSlider.loopPoint = Mathf.Clamp(playbackSlider.progress, 0f, 0.99f);
            }
            playbackSlider.rightClicked = false;
        }

        // Jump Playback To Loop Point
        if (playbackSlider.loopPoint >= 0f && (playButton.rightClicked || InputManager.returnPushed || InputManager.middleMousePushed))
        {
            VoezEditor.Editor.musicPlayer.source.time = VoezEditor.Editor.musicPlayer.source.clip.length * Mathf.Clamp(playbackSlider.loopPoint, 0f, 0.99f);
            VoezEditor.Editor.currentFrame            = (int)(VoezEditor.Editor.musicPlayer.source.time * VoezEditor.Editor.framesPerSecond);
            grid.SnapPlaytimeToGrid();
            playButton.rightClicked = false;
        }

        // BPM Editing
        if (bpmButton.clicked)
        {
            bpmButton.toggled = !bpmButton.toggled;
            bpmButton.clicked = false;
        }
        if (bpmButton.toggled)
        {
            float lastBPM = VoezEditor.Editor.project.songBPM;
            if (InputManager.UpTick())
            {
                VoezEditor.Editor.project.songBPM += 1;
            }
            if (InputManager.DownTick())
            {
                VoezEditor.Editor.project.songBPM -= 1;
            }
            if (InputManager.RightTick())
            {
                VoezEditor.Editor.project.songBPM += 5;
            }
            if (InputManager.LeftTick())
            {
                VoezEditor.Editor.project.songBPM -= 5;
            }
            VoezEditor.Editor.project.songBPM = Mathf.Clamp(VoezEditor.Editor.project.songBPM, 10, 250);
            if (VoezEditor.Editor.project.songBPM != lastBPM && VoezEditor.Editor.EditMode)
            {
                grid.SnapPlaytimeToGrid();
            }
            bpmButton.myText.text = "BPM" + Environment.NewLine + VoezEditor.Editor.project.songBPM.ToString();
        }
        if (bpmButton.toggled && VoezEditor.Editor.bpmPulse)
        {
            playbackSlider.pulseFlashEffectTime       = 3;
            VoezEditor.Editor.bg.pulseFlashEffectTime = 3;
        }

        // Open Playback Speed Menu
        if (playbackTimeButton.clicked)
        {
            UntoggleAllSubmenus();
            if (playbackTimes == null)
            {
                SpawnPlaybackTimeButtons();
            }
            else
            {
                DespawnPlaybackTimeButtons();
            }
            InputManager.ClearMouseInputs();
            playbackTimeButton.toggled = playbackTimes != null;
            playbackTimeButton.clicked = false;
        }

        // Open Notes Selection Menu
        if (notesButton.clicked)
        {
            UntoggleAllSubmenus();
            if (noteTypes == null)
            {
                SpawnNoteButtons();
            }
            else
            {
                DespawnNoteButtons();
            }
            InputManager.ClearMouseInputs();
            notesButton.toggled = noteTypes != null;
            notesButton.clicked = false;
        }

        // Open Grid Snap Menu
        if (gridButton.clicked)
        {
            UntoggleAllSubmenus();
            if (snapTimes == null)
            {
                SpawnGridButtons();
            }
            else
            {
                DespawnGridButtons();
            }
            InputManager.ClearMouseInputs();
            gridButton.toggled = snapTimes != null;
            gridButton.clicked = false;
        }

        // Open Scroll Rate Menu
        if (scrollButton.clicked)
        {
            UntoggleAllSubmenus();
            if (scrollRates == null)
            {
                SpawnScrollButtons();
            }
            else
            {
                DespawnScrollButtons();
            }
            InputManager.ClearMouseInputs();
            scrollButton.toggled = scrollRates != null;
            scrollButton.clicked = false;
        }

        // Open Sound Assist Options Menu
        if (soundAssistButton.clicked)
        {
            UntoggleAllSubmenus();
            if (metronomeToggle == null)
            {
                SpawnSoundAssistButtons();
            }
            else
            {
                DespawnSoundAssistButtons();
            }
            InputManager.ClearMouseInputs();
            soundAssistButton.toggled = metronomeToggle != null;
            soundAssistButton.clicked = false;
        }

        // Save Project
        if (saveButton.clicked)
        {
            VoezEditor.Editor.project.ExportActiveProject();
            saveButton.clicked = false;
        }

        // Set Playback Speed
        if (InputManager.onePushed && !Util.ShiftDown())
        {
            if (playbackTimes != null)
            {
                playbackTimes[0].clicked = true;
            }
            else
            {
                VoezEditor.Editor.musicPlayer.playbackSpeed = 0.25f;
            }
        }
        if (InputManager.twoPushed && !Util.ShiftDown())
        {
            if (playbackTimes != null)
            {
                playbackTimes[1].clicked = true;
            }
            else
            {
                VoezEditor.Editor.musicPlayer.playbackSpeed = 0.5f;
            }
        }
        if (InputManager.threePushed && !Util.ShiftDown())
        {
            if (playbackTimes != null)
            {
                playbackTimes[2].clicked = true;
            }
            else
            {
                VoezEditor.Editor.musicPlayer.playbackSpeed = 1.0f;
            }
        }
        if (InputManager.fourPushed && !Util.ShiftDown())
        {
            if (playbackTimes != null)
            {
                playbackTimes[3].clicked = true;
            }
            else
            {
                VoezEditor.Editor.musicPlayer.playbackSpeed = 2.0f;
            }
        }
        if (playbackTimes != null)
        {
            for (int i = 0; i < playbackTimes.Length; i += 1)
            {
                if (playbackTimes[i].clicked)
                {
                    for (int j = 0; j < playbackTimes.Length; j += 1)
                    {
                        playbackTimes[j].toggled = false;
                    }
                    playbackTimes[i].toggled = true;
                    if (i == 0)
                    {
                        VoezEditor.Editor.musicPlayer.playbackSpeed = 0.25f;
                    }
                    else if (i == 1)
                    {
                        VoezEditor.Editor.musicPlayer.playbackSpeed = 0.5f;
                    }
                    else if (i == 2)
                    {
                        VoezEditor.Editor.musicPlayer.playbackSpeed = 1.0f;
                    }
                    else if (i == 3)
                    {
                        VoezEditor.Editor.musicPlayer.playbackSpeed = 2.0f;
                    }
                    playbackTimes[i].clicked = false;

                    // Automatically close the playback time selector after a choice has been made.
                    if (playbackTimeButton.toggled)
                    {
                        DespawnPlaybackTimeButtons();
                        InputManager.ClearMouseInputs();
                        playbackTimeButton.toggled = false;
                        break;
                    }
                }
            }
        }

        // Set Selected Note Type
        if (InputManager.zPushed)
        {
            if (noteTypes != null)
            {
                noteTypes[0].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedNoteType = ProjectData.NoteData.NoteType.CLICK;
                notesButton.mySymbol.element       = Futile.atlasManager.GetElementWithName("click");
                notesButton.mySymbol.color         = Note.QUANTIZATION_COLORS[0];
                VoezEditor.Editor.trackEditMode    = false;
                notesButton.mySymbol.rotation      = 45f + 180f;
            }
        }
        if (InputManager.xPushed)
        {
            if (noteTypes != null)
            {
                noteTypes[1].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedNoteType = ProjectData.NoteData.NoteType.SLIDE;
                notesButton.mySymbol.element       = Futile.atlasManager.GetElementWithName("slide");
                notesButton.mySymbol.color         = Color.white;
                VoezEditor.Editor.trackEditMode    = false;
                notesButton.mySymbol.rotation      = 45f + 180f;
            }
        }
        if (InputManager.cPushed)
        {
            if (noteTypes != null)
            {
                noteTypes[2].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedNoteType = ProjectData.NoteData.NoteType.SWIPE;
                notesButton.mySymbol.element       = Futile.atlasManager.GetElementWithName("swipe");
                notesButton.mySymbol.color         = Color.white;
                VoezEditor.Editor.trackEditMode    = false;
                notesButton.mySymbol.rotation      = 45f + 180f;
            }
        }
        if (InputManager.vPushed)
        {
            if (noteTypes != null)
            {
                noteTypes[3].clicked = true;
            }
            else
            {
                VoezEditor.Editor.trackEditMode = true;
                notesButton.mySymbol.element    = Futile.atlasManager.GetElementWithName("track");
                notesButton.mySymbol.color      = Color.white;
                notesButton.mySymbol.rotation   = 0f;
            }
        }
        if (noteTypes != null)
        {
            for (int i = 0; i < noteTypes.Length; i += 1)
            {
                if (noteTypes[i].clicked)
                {
                    for (int j = 0; j < noteTypes.Length; j += 1)
                    {
                        noteTypes[j].toggled = false;
                    }
                    noteTypes[i].toggled = true;
                    noteTypes[i].clicked = false;
                    if (i == 0)
                    {
                        VoezEditor.Editor.selectedNoteType = ProjectData.NoteData.NoteType.CLICK;
                        notesButton.mySymbol.element       = Futile.atlasManager.GetElementWithName("click");
                        notesButton.mySymbol.color         = Note.QUANTIZATION_COLORS[0];
                    }
                    else if (i == 1)
                    {
                        VoezEditor.Editor.selectedNoteType = ProjectData.NoteData.NoteType.SLIDE;
                        notesButton.mySymbol.element       = Futile.atlasManager.GetElementWithName("slide");
                        notesButton.mySymbol.color         = Color.white;
                    }
                    else if (i == 2)
                    {
                        VoezEditor.Editor.selectedNoteType = ProjectData.NoteData.NoteType.SWIPE;
                        notesButton.mySymbol.element       = Futile.atlasManager.GetElementWithName("swipe");
                        notesButton.mySymbol.color         = Color.white;
                    }

                    if (i == 3)
                    {
                        VoezEditor.Editor.trackEditMode = true;
                        notesButton.mySymbol.element    = Futile.atlasManager.GetElementWithName("track");
                        notesButton.mySymbol.color      = Color.white;
                        notesButton.mySymbol.rotation   = 0f;
                    }
                    else
                    {
                        VoezEditor.Editor.trackEditMode = false;
                        notesButton.mySymbol.rotation   = 45f;
                    }

                    // Automatically close the note type selector after a choice has been made.
                    if (notesButton.toggled)
                    {
                        DespawnNoteButtons();
                        InputManager.ClearMouseInputs();
                        notesButton.toggled = false;
                        break;
                    }
                }
            }
        }

        // Set Grid Snapping
        if (InputManager.onePushed && Util.ShiftDown())
        {
            if (snapTimes != null)
            {
                snapTimes[0].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedTimeSnap = 0;
            }
        }
        if (InputManager.twoPushed && Util.ShiftDown())
        {
            if (snapTimes != null)
            {
                snapTimes[1].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedTimeSnap = 16;
            }
        }
        if (InputManager.threePushed && Util.ShiftDown())
        {
            if (snapTimes != null)
            {
                snapTimes[2].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedTimeSnap = 12;
            }
        }
        if (InputManager.fourPushed && Util.ShiftDown())
        {
            if (snapTimes != null)
            {
                snapTimes[3].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedTimeSnap = 8;
            }
        }
        if (InputManager.fivePushed && Util.ShiftDown())
        {
            if (snapTimes != null)
            {
                snapTimes[4].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedTimeSnap = 6;
            }
        }
        if (InputManager.sixPushed && Util.ShiftDown())
        {
            if (snapTimes != null)
            {
                snapTimes[5].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedTimeSnap = 4;
            }
        }
        if (InputManager.sevenPushed && Util.ShiftDown())
        {
            if (snapTimes != null)
            {
                snapTimes[6].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedTimeSnap = 3;
            }
        }
        if (InputManager.eightPushed && Util.ShiftDown())
        {
            if (snapTimes != null)
            {
                snapTimes[7].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedTimeSnap = 2;
            }
        }
        if (InputManager.ninePushed && Util.ShiftDown())
        {
            if (snapTimes != null)
            {
                snapTimes[8].clicked = true;
            }
            else
            {
                VoezEditor.Editor.selectedTimeSnap = 1;
            }
        }
        if (snapTimes != null)
        {
            for (int i = 0; i < snapTimes.Length; i += 1)
            {
                if (snapTimes[i].clicked)
                {
                    for (int j = 0; j < snapTimes.Length; j += 1)
                    {
                        snapTimes[j].toggled = false;
                    }
                    snapTimes[i].toggled = true;
                    if (i == 0)
                    {
                        VoezEditor.Editor.selectedTimeSnap = 0;
                    }
                    else if (i == 1)
                    {
                        VoezEditor.Editor.selectedTimeSnap = 16;
                    }
                    else if (i == 2)
                    {
                        VoezEditor.Editor.selectedTimeSnap = 12;
                    }
                    else if (i == 3)
                    {
                        VoezEditor.Editor.selectedTimeSnap = 8;
                    }
                    else if (i == 4)
                    {
                        VoezEditor.Editor.selectedTimeSnap = 6;
                    }
                    else if (i == 5)
                    {
                        VoezEditor.Editor.selectedTimeSnap = 4;
                    }
                    else if (i == 6)
                    {
                        VoezEditor.Editor.selectedTimeSnap = 3;
                    }
                    else if (i == 7)
                    {
                        VoezEditor.Editor.selectedTimeSnap = 2;
                    }
                    else if (i == 8)
                    {
                        VoezEditor.Editor.selectedTimeSnap = 1;
                    }
                    snapTimes[i].clicked = false;
                    grid.SnapPlaytimeToGrid();

                    // Automatically close the grid snap selector after a choice has been made.
                    if (gridButton.toggled)
                    {
                        DespawnGridButtons();
                        InputManager.ClearMouseInputs();
                        gridButton.toggled = false;
                        break;
                    }
                }
            }
        }

        // Set Scroll Rate
        if (scrollRates != null)
        {
            for (int i = 0; i < scrollRates.Length; i += 1)
            {
                if (scrollRates[i].clicked)
                {
                    for (int j = 0; j < scrollRates.Length; j += 1)
                    {
                        scrollRates[j].toggled = false;
                    }
                    scrollRates[i].toggled = true;
                    VoezEditor.Editor.selectedScrollRate = i + 1;
                    Note.NOTE_DURATION = Note.SCROLL_DURATIONS[i];
                    VoezEditor.Editor.RefreshAllNotes();

                    // Automatically close the scroll rate selector after a choice has been made.
                    if (scrollButton.toggled)
                    {
                        DespawnScrollButtons();
                        InputManager.ClearMouseInputs();
                        scrollButton.toggled = false;
                        break;
                    }
                }
            }
        }

        // Set Sound Assist Options
        if (metronomeToggle != null && metronomeToggle.clicked)
        {
            metronomeToggle.toggled            = !metronomeToggle.toggled;
            VoezEditor.Editor.metronomeEnabled = metronomeToggle.toggled;
            metronomeToggle.clicked            = false;
        }
        if (hitSoundToggle != null && hitSoundToggle.clicked)
        {
            hitSoundToggle.toggled             = !hitSoundToggle.toggled;
            VoezEditor.Editor.hitSoundsEnabled = hitSoundToggle.toggled;
            hitSoundToggle.clicked             = false;
        }
        if (quantizationToggle != null && quantizationToggle.clicked)
        {
            quantizationToggle.toggled            = !quantizationToggle.toggled;
            VoezEditor.Editor.quantizationEnabled = quantizationToggle.toggled;
            quantizationToggle.clicked            = false;
        }
    }
Exemplo n.º 2
0
    public override void Update()
    {
        base.Update();
        trackProgress = (VoezEditor.Editor.songTime - data.start) / (data.end - data.start);
        pos.y         = VoezEditor.windowRes.y * (1.0f - TRACK_SCREEN_HEIGHT);
        float desiredX = GetXAtTime(VoezEditor.Editor.songTime);

        pos.x = Util.ScreenPosX(desiredX);

        if (trackProgress > 1f || trackProgress < 0f)
        {
            Destroy();
        }
        if (flashEffectTime > 0)
        {
            flashEffectTime -= 1;
        }
        if (pulseFlashEffectTime > 0)
        {
            pulseFlashEffectTime -= 1;
        }

        if (VoezEditor.Editor.ui.bpmButton.toggled && VoezEditor.Editor.bpmPulse)
        {
            pulseFlashEffectTime = 5;
        }

        if (VoezEditor.Editor.EditMode && !VoezEditor.Editor.MenuOpen && VoezEditor.Editor.trackEditMode)
        {
            // Delete Track
            if (activeHover && (InputManager.delPushed || (Util.ShiftDown() && InputManager.rightMousePushed)))
            {
                Vector2 windowCenter = new Vector2(VoezEditor.windowRes.x * 0.5f, VoezEditor.windowRes.y * 0.5f);
                int     damageCount  = 0;
                for (int i = 0; i < VoezEditor.Editor.project.notes.Count; i += 1)
                {
                    if (VoezEditor.Editor.project.notes[i].track == data.id)
                    {
                        damageCount += 1;
                    }
                }
                if (damageCount > 0)
                {
                    // There are notes attached to this track. Warn the user before deleting it!
                    deletionConfirm = new ConfirmBox(new Rect(new Vector2(windowCenter.x - 300f, windowCenter.y - 150f), new Vector2(600f, 300f)), "Warning:\nThere are notes attached to this track!\nDeleting it will also delete " + damageCount.ToString() + " note" + (damageCount != 1 ? "s" : "") + ".\nAre you sure you want to delete?");
                    VoezEditor.Editor.AddObject(deletionConfirm);
                }
                else
                {
                    // Empty track, delete it immediately.
                    VoezEditor.Editor.project.DeleteTrack(data.id);
                    VoezEditor.Editor.RefreshAllTracks();
                }
            }
            // Edit Track
            if (activeHover && InputManager.leftMousePushed && !VoezEditor.Editor.ui.HoveringOverSubmenuItem())
            {
                float trackEditWindowX = 0f;
                if (pos.x > VoezEditor.windowRes.x * 0.5f)
                {
                    trackEditWindowX = pos.x - TrackEditor.WIDTH * 0.5f - 64f;
                }
                else
                {
                    trackEditWindowX = pos.x + TrackEditor.WIDTH * 0.5f + 64f;
                }
                VoezEditor.Editor.trackEditor = new TrackEditor(new Vector2(trackEditWindowX, VoezEditor.windowRes.y * 0.55f), data);
                VoezEditor.Editor.AddObject(VoezEditor.Editor.trackEditor);
                VoezEditor.Editor.ui.bpmButton.toggled = false;
            }
        }

        if (deletionConfirm != null)
        {
            if (deletionConfirm.yesButton != null && deletionConfirm.yesButton.clicked)
            {
                deletionConfirm.Destroy();
                deletionConfirm = null;
                VoezEditor.Editor.project.DeleteTrack(data.id);
                VoezEditor.Editor.RefreshAllNotes();
                VoezEditor.Editor.RefreshAllTracks();
            }
            else if (deletionConfirm.noButton != null && deletionConfirm.noButton.clicked)
            {
                deletionConfirm.Destroy();
                deletionConfirm = null;
            }
        }
    }