public void PickRandomSong()
 {
     if (availableSongs.Count() == 0)
     {
         return;
     }
     SongSelected?.Invoke(availableSongs.Random());
 }
Beispiel #2
0
 void songSelectComponent_SongSelected(object sender, EventArgs e)
 {
     if (SongSelected != null)
     {
         SongInformation = songSelectComponent.SongInformation;
         Difficulty      = songSelectComponent.Difficulty;
         SongSelected.Invoke(this, EventArgs.Empty);
     }
 }
Beispiel #3
0
 private void SongsTableView_DidSelectRow(TableView sender, int row)
 {
     if (requestMode && !isHost)
     {
         selectedSong = availableSongs[row];
         _requestSongButton.interactable = selectedSong != null;
     }
     else
     {
         SongSelected?.Invoke(availableSongs[row]);
     }
 }
Beispiel #4
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            bool left   = e.Button.HasFlag(MouseButtons.Left);
            bool middle = e.Button.HasFlag(MouseButtons.Middle) || (e.Button.HasFlag(MouseButtons.Left) && ModifierKeys.HasFlag(Keys.Alt));
            bool right  = e.Button.HasFlag(MouseButtons.Right);

            var buttonIdx = GetButtonAtCoord(e.X, e.Y, out var subButtonType);

            if (buttonIdx >= 0)
            {
                var button = buttons[buttonIdx];

                if (left)
                {
                    if (button.type == ButtonType.SongHeader)
                    {
                        if (subButtonType == SubButtonType.Add)
                        {
                            App.UndoRedoManager.BeginTransaction(TransactionScope.Project);
                            App.Project.CreateSong();
                            App.UndoRedoManager.EndTransaction();
                            RefreshButtons();
                            ConditionalInvalidate();
                        }
                    }
                    else if (button.type == ButtonType.Song)
                    {
                        if (button.song != selectedSong)
                        {
                            selectedSong = button.song;
                            SongSelected?.Invoke(selectedSong);
                            ConditionalInvalidate();
                        }
                    }
                    else if (button.type == ButtonType.InstrumentHeader)
                    {
                        if (subButtonType == SubButtonType.Add)
                        {
                            App.UndoRedoManager.BeginTransaction(TransactionScope.Project);
                            App.Project.CreateInstrument();
                            App.UndoRedoManager.EndTransaction();
                            RefreshButtons();
                            ConditionalInvalidate();
                        }
                        if (subButtonType == SubButtonType.LoadInstrument)
                        {
                            var filename = PlatformDialogs.ShowOpenFileDialog("Open File", "Fami Tracker Instrument (*.fti)|*.fti");
                            if (filename != null)
                            {
                                App.UndoRedoManager.BeginTransaction(TransactionScope.Project);
                                var instrument = FamitrackerInstrumentFile.CreateFromFile(App.Project, filename);
                                if (instrument == null)
                                {
                                    App.UndoRedoManager.AbortTransaction();
                                }
                                else
                                {
                                    App.UndoRedoManager.EndTransaction();
                                }
                            }

                            RefreshButtons();
                            ConditionalInvalidate();
                        }
                    }
                    else if (button.type == ButtonType.Instrument)
                    {
                        selectedInstrument = button.instrument;

                        if (selectedInstrument != null)
                        {
                            instrumentDrag = selectedInstrument;
                            mouseDragY     = e.Y;
                        }

                        if (subButtonType == SubButtonType.Volume)
                        {
                            InstrumentEdited?.Invoke(selectedInstrument, Envelope.Volume);
                            envelopeDragIdx = Envelope.Volume;
                        }
                        else if (subButtonType == SubButtonType.Pitch)
                        {
                            InstrumentEdited?.Invoke(selectedInstrument, Envelope.Pitch);
                            envelopeDragIdx = Envelope.Pitch;
                        }
                        else if (subButtonType == SubButtonType.Arpeggio)
                        {
                            InstrumentEdited?.Invoke(selectedInstrument, Envelope.Arpeggio);
                            envelopeDragIdx = Envelope.Arpeggio;
                        }
                        else if (subButtonType == SubButtonType.DPCM)
                        {
                            InstrumentEdited?.Invoke(selectedInstrument, Envelope.Max);
                        }
                        else if (subButtonType >= SubButtonType.DutyCycle0 && subButtonType <= SubButtonType.DutyCycle3)
                        {
                            selectedInstrument.DutyCycle = (selectedInstrument.DutyCycle + 1) % 4;
                        }

                        InstrumentSelected?.Invoke(selectedInstrument);
                        ConditionalInvalidate();
                    }
                }
                else if (right)
                {
                    if (button.type == ButtonType.Song && App.Project.Songs.Count > 1)
                    {
                        var song = button.song;
                        if (PlatformDialogs.MessageBox($"Are you sure you want to delete '{song.Name}' ?", "Delete song", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            bool selectNewSong = song == selectedSong;
                            App.Stop();
                            App.UndoRedoManager.BeginTransaction(TransactionScope.Project);
                            App.Project.DeleteSong(song);
                            if (selectNewSong)
                            {
                                selectedSong = App.Project.Songs[0];
                            }
                            SongSelected?.Invoke(selectedSong);
                            App.UndoRedoManager.EndTransaction();
                            RefreshButtons();
                            ConditionalInvalidate();
                        }
                    }
                    else if (button.type == ButtonType.Instrument && button.instrument != null)
                    {
                        var instrument = button.instrument;

                        if (subButtonType == SubButtonType.Arpeggio ||
                            subButtonType == SubButtonType.Pitch ||
                            subButtonType == SubButtonType.Volume)
                        {
                            int envType = Envelope.Volume;

                            switch (subButtonType)
                            {
                            case SubButtonType.Arpeggio: envType = Envelope.Arpeggio; break;

                            case SubButtonType.Pitch: envType = Envelope.Pitch;    break;
                            }

                            App.UndoRedoManager.BeginTransaction(TransactionScope.Instrument, instrument.Id);
                            instrument.Envelopes[envType].Length = 0;
                            App.UndoRedoManager.EndTransaction();
                            ConditionalInvalidate();
                        }
                        else if (subButtonType == SubButtonType.Max)
                        {
                            if (PlatformDialogs.MessageBox($"Are you sure you want to delete '{instrument.Name}' ? All notes using this instrument will be deleted.", "Delete intrument", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                bool selectNewInstrument = instrument == selectedInstrument;
                                App.StopInstrumentNoteAndWait();
                                App.UndoRedoManager.BeginTransaction(TransactionScope.Project);
                                App.Project.DeleteInstrument(instrument);
                                if (selectNewInstrument)
                                {
                                    selectedInstrument = App.Project.Instruments.Count > 0 ? App.Project.Instruments[0] : null;
                                }
                                SongSelected?.Invoke(selectedSong);
                                InstrumentDeleted?.Invoke(instrument);
                                App.UndoRedoManager.EndTransaction();
                                RefreshButtons();
                                ConditionalInvalidate();
                            }
                        }
                    }
                }
            }

            if (middle)
            {
                mouseLastY = e.Y;
            }
        }
 private void SongsTableView_DidSelectRow(TableView sender, int row)
 {
     SongSelected?.Invoke(availableSongs[row]);
 }
 private void MenuOnInstanceItemSelected(object sender, string e)
 {
     SongSelected?.Invoke(this, e);
     Close();
 }
Beispiel #7
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            bool left   = e.Button.HasFlag(MouseButtons.Left);
            bool middle = e.Button.HasFlag(MouseButtons.Middle) || (e.Button.HasFlag(MouseButtons.Left) && ModifierKeys.HasFlag(Keys.Alt));
            bool right  = e.Button.HasFlag(MouseButtons.Right);

            var buttonIndex     = (e.Y + scrollY) / ButtonSizeY;
            var songIndex       = buttonIndex - 1;
            var instrumentIndex = buttonIndex - (App.Project.Songs.Count + 2);
            var shiftY          = (buttonIndex * ButtonSizeY - scrollY);

            if (left)
            {
                if (songIndex == -1)
                {
                    if (GetButtonRect(1, shiftY).Contains(e.X, e.Y))
                    {
                        App.UndoRedoManager.BeginTransaction(TransactionScope.Project);
                        App.Project.CreateSong();
                        App.UndoRedoManager.EndTransaction();
                        ConditionalInvalidate();
                    }
                }
                else if (instrumentIndex == -1)
                {
                    if (GetButtonRect(1, shiftY).Contains(e.X, e.Y))
                    {
                        App.UndoRedoManager.BeginTransaction(TransactionScope.Project);
                        App.Project.CreateInstrument();
                        App.UndoRedoManager.EndTransaction();
                        ConditionalInvalidate();
                    }
                }
                else if (songIndex >= 0 && songIndex < App.Project.Songs.Count)
                {
                    selectedSong = App.Project.Songs[songIndex];
                    SongSelected?.Invoke(selectedSong);
                    ConditionalInvalidate();
                    return;
                }
                else if (instrumentIndex >= 0 && instrumentIndex <= App.Project.Instruments.Count)
                {
                    selectedInstrument = instrumentIndex == 0 ? null : App.Project.Instruments[instrumentIndex - 1];

                    if (selectedInstrument != null)
                    {
                        instrumentDragIdx = instrumentIndex - 1;
                        mouseDragY        = e.Y;
                    }

                    if (selectedInstrument != null && GetButtonRect(4, shiftY).Contains(e.X, e.Y))
                    {
                        InstrumentEdited?.Invoke(selectedInstrument, Envelope.Volume);
                        envelopeDragIdx = Envelope.Volume;
                    }
                    else if (selectedInstrument != null && GetButtonRect(3, shiftY).Contains(e.X, e.Y))
                    {
                        InstrumentEdited?.Invoke(selectedInstrument, Envelope.Pitch);
                        envelopeDragIdx = Envelope.Pitch;
                    }
                    else if (selectedInstrument != null && GetButtonRect(2, shiftY).Contains(e.X, e.Y))
                    {
                        InstrumentEdited?.Invoke(selectedInstrument, Envelope.Arpeggio);
                        envelopeDragIdx = Envelope.Arpeggio;
                    }
                    else if (GetButtonRect(1, shiftY).Contains(e.X, e.Y))
                    {
                        if (selectedInstrument == null)
                        {
                            InstrumentEdited?.Invoke(selectedInstrument, Envelope.Max);
                        }
                        else
                        {
                            selectedInstrument.DutyCycle = (selectedInstrument.DutyCycle + 1) % 4;
                            ConditionalInvalidate();
                        }
                    }

                    InstrumentSelected?.Invoke(selectedInstrument);
                    ConditionalInvalidate();
                }
            }
            else if (right)
            {
                instrumentIndex--;

                if (songIndex >= 0 && songIndex < App.Project.Songs.Count && App.Project.Songs.Count > 1)
                {
                    var song = App.Project.Songs[songIndex];
                    if (MessageBox.Show($"Are you sure you want to delete '{song.Name}' ?", "Delete song", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        bool selectNewSong = song == selectedSong;
                        App.Stop();
                        App.UndoRedoManager.BeginTransaction(TransactionScope.Project);
                        App.Project.DeleteSong(song);
                        App.UndoRedoManager.EndTransaction();
                        if (selectNewSong)
                        {
                            selectedSong = App.Project.Songs[0];
                        }
                        SongSelected?.Invoke(selectedSong);
                        ConditionalInvalidate();
                        return;
                    }
                }
                else if (instrumentIndex >= 0 && instrumentIndex < App.Project.Instruments.Count)
                {
                    var instrument = App.Project.Instruments[instrumentIndex];
                    if (MessageBox.Show($"Are you sure you want to delete '{instrument.Name}' ? All notes using this instrument will be deleted.", "Delete intrument", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        bool selectNewInstrument = instrument == selectedInstrument;
                        App.StopInstrumentNoteAndWait();
                        App.UndoRedoManager.BeginTransaction(TransactionScope.Project);
                        App.Project.DeleteInstrument(instrument);
                        App.UndoRedoManager.EndTransaction();
                        if (selectNewInstrument)
                        {
                            selectedInstrument = App.Project.Instruments.Count > 0 ? App.Project.Instruments[0] : null;
                        }
                        SongSelected?.Invoke(selectedSong);
                        ConditionalInvalidate();
                        return;
                    }
                }
            }

            if (middle)
            {
                mouseLastY = e.Y;
            }
        }
 public void PlayButtonPressed()
 {
     SongSelected?.Invoke(_selectedSong);
 }
Beispiel #9
0
 private void ServerClicked(TableView sender, SongListItem songListItem)
 {
     SongSelected?.Invoke(songListItem.parameters);
 }
Beispiel #10
0
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (firstActivation && activationType == ActivationType.AddedToHierarchy)
            {
                title          = "Search For Songs";
                showBackButton = true;

                _searchResultsNavigationController   = BeatSaberUI.CreateViewController <SearchResultsNavigationController>();
                _searchResultsListViewController     = BeatSaberUI.CreateViewController <SearchResultsListViewController>();
                _songDetailsViewController           = BeatSaberUI.CreateViewController <SongDetailsViewController>();
                _searchOptionsViewController         = BeatSaberUI.CreateViewController <SearchOptionsViewController>();
                _searchKeyboardViewController        = BeatSaberUI.CreateViewController <SearchKeyboardViewController>();
                _searchCompactKeyboardViewController = BeatSaberUI.CreateViewController <SearchCompactKeyboardViewController>();
                _searchResultsNavigationController.ForceShowButtonPressed += delegate()
                {
                    ShowSearchResult(SearchBehaviour.Instance.CachedResult, true);
                };
                _searchResultsNavigationController.LastSearchButtonPressed += delegate()
                {
                    _searchResultsNavigationController.ShowLastSearchButton(false);

                    if (string.IsNullOrEmpty(_lastSearchQuery))
                    {
                        return;
                    }

                    PopAllViewControllersFromNavigationController();
                    _searchResultsNavigationController.ShowLoadingSpinner();
                    _searchResultsListViewController.UpdateSongs(new IPreviewBeatmapLevel[0]);

                    _searchQuery = _lastSearchQuery;

                    if (PluginConfig.CompactSearchMode)
                    {
                        _searchCompactKeyboardViewController.SetText(_searchQuery);
                    }
                    else
                    {
                        _searchKeyboardViewController.SetText(_searchQuery);
                    }
                    SearchBehaviour.Instance.StartNewSearch(_levelsSearchSpace, _searchQuery, levels => ShowSearchResult(levels, true));
                };
                _searchResultsListViewController.SongSelected += delegate(IPreviewBeatmapLevel level)
                {
                    if (_searchCompactKeyboardViewController.isInViewControllerHierarchy)
                    {
                        PopViewControllerFromNavigationController(_searchResultsNavigationController, null, true);
                    }
                    if (!_songDetailsViewController.isInViewControllerHierarchy)
                    {
                        PushViewControllerToNavigationController(_searchResultsNavigationController, _songDetailsViewController, null, PluginConfig.CompactSearchMode);
                    }
                    _songDetailsViewController.SetContent(level);
                    _searchResultsNavigationController.CrossfadeAudioToLevelAsync(level);
                };
                _songDetailsViewController.SelectButtonPressed += delegate(IPreviewBeatmapLevel level)
                {
                    _lastSearchQuery = _searchQuery;

                    SearchBehaviour.Instance.StopSearch();
                    _searchResultsListViewController.UpdateSongs(new IPreviewBeatmapLevel[0]);
                    PopAllViewControllersFromNavigationController(true);
                    SongSelected?.Invoke(level);
                };
                _songDetailsViewController.CompactKeyboardButtonPressed += delegate()
                {
                    if (!PluginConfig.CompactSearchMode)
                    {
                        return;
                    }

                    PopViewControllerFromNavigationController(_searchResultsNavigationController, null, true);
                    PushViewControllerToNavigationController(_searchResultsNavigationController, _searchCompactKeyboardViewController, null, true);

                    _searchCompactKeyboardViewController.SetText(_searchQuery);
                    _searchResultsListViewController.DeselectSong();
                };

                _searchOptionsViewController.SearchOptionsApplied += OptionsChanged;

                _searchKeyboardViewController.TextKeyPressed      += KeyboardTextKeyPressed;
                _searchKeyboardViewController.DeleteButtonPressed += KeyboardDeleteButtonPressed;
                _searchKeyboardViewController.ClearButtonPressed  += KeyboardClearButtonPressed;
                _searchKeyboardViewController.PredictionPressed   += KeyboardPredictionPressed;

                _searchCompactKeyboardViewController.TextKeyPressed      += KeyboardTextKeyPressed;
                _searchCompactKeyboardViewController.DeleteButtonPressed += KeyboardDeleteButtonPressed;
                _searchCompactKeyboardViewController.ClearButtonPressed  += KeyboardClearButtonPressed;
                _searchCompactKeyboardViewController.PredictionPressed   += KeyboardPredictionPressed;

                ProvideInitialViewControllers(_searchResultsNavigationController, _searchOptionsViewController, PluginConfig.CompactSearchMode ? null : _searchKeyboardViewController);
            }
            else
            {
                _searchQuery          = "";
                _readyForDeactivation = false;
            }
        }
Beispiel #11
0
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (firstActivation && activationType == ActivationType.AddedToHierarchy)
            {
                title          = "Search For Songs";
                showBackButton = true;

                if (PluginConfig.TwoHandedTyping)
                {
                    CreateLaserPointerManager();
                }

                _searchResultsNavigationController = BeatSaberUI.CreateViewController <SearchResultsNavigationController>();
                _searchResultsListViewController   = BeatSaberUI.CreateViewController <SearchResultsListViewController>();
                _songDetailsViewController         = BeatSaberUI.CreateViewController <SongDetailsViewController>();
                _searchOptionsViewController       = BeatSaberUI.CreateViewController <SearchOptionsViewController>();

                CreateKeyboardManager();

                _searchResultsNavigationController.ForceShowButtonPressed += delegate()
                {
                    ShowSearchResult(SearchBehaviour.Instance.CachedResult, true);
                };
                _searchResultsNavigationController.LastSearchButtonPressed += delegate()
                {
                    _searchResultsNavigationController.ShowLastSearchButton(false);

                    if (string.IsNullOrEmpty(_lastSearchQuery))
                    {
                        return;
                    }

                    PopAllViewControllersFromNavigationController();
                    _searchResultsNavigationController.ShowLoadingSpinner();
                    _searchResultsListViewController.UpdateSongs(new IPreviewBeatmapLevel[0]);

                    _searchQuery = _lastSearchQuery;
                    _keyboardManager.SetText(_searchQuery);

                    SearchBehaviour.Instance.StartNewSearch(_levelsSearchSpace, _searchQuery, levels => ShowSearchResult(levels, true));
                };
                _searchResultsNavigationController.ResetKeyboardPositionButtonPressed += delegate()
                {
                    if (PluginConfig.SearchKeyboard == SearchKeyboardType.Floating && _keyboardManager is FloatingSearchKeyboardManager keyboardManager)
                    {
                        keyboardManager.ResetPosition();
                    }
                };

                _searchResultsListViewController.SongSelected += delegate(IPreviewBeatmapLevel level)
                {
                    if (PluginConfig.SearchKeyboard == SearchKeyboardType.Compact && _keyboardViewController.isInViewControllerHierarchy)
                    {
                        PopViewControllerFromNavigationController(_searchResultsNavigationController, null, true);
                    }
                    if (!_songDetailsViewController.isInViewControllerHierarchy)
                    {
                        PushViewControllerToNavigationController(_searchResultsNavigationController, _songDetailsViewController, null, PluginConfig.SearchKeyboard == SearchKeyboardType.Compact);
                    }
                    _songDetailsViewController.SetContent(level);
                    _searchResultsNavigationController.CrossfadeAudioToLevelAsync(level);
                };
                _songDetailsViewController.SelectButtonPressed += delegate(IPreviewBeatmapLevel level)
                {
                    _lastSearchQuery = _searchQuery;

                    SearchBehaviour.Instance.StopSearch();
                    _searchResultsListViewController.UpdateSongs(new IPreviewBeatmapLevel[0]);
                    PopAllViewControllersFromNavigationController(true);
                    SongSelected?.Invoke(level);
                };
                _songDetailsViewController.CompactKeyboardButtonPressed += delegate()
                {
                    if (PluginConfig.SearchKeyboard != SearchKeyboardType.Compact)
                    {
                        return;
                    }

                    PopViewControllerFromNavigationController(_searchResultsNavigationController, null, true);
                    PushViewControllerToNavigationController(_searchResultsNavigationController, _keyboardViewController, null, true);

                    _keyboardManager.SetText(_searchQuery);
                    _searchResultsListViewController.DeselectSong();
                };

                _searchOptionsViewController.SearchOptionsApplied += OptionsChanged;

                ProvideInitialViewControllers(_searchResultsNavigationController, _searchOptionsViewController, PluginConfig.SearchKeyboard == SearchKeyboardType.RightScreen ? _keyboardViewController : null);
            }
            else
            {
                _searchQuery          = "";
                _readyForDeactivation = false;

                if (_laserPointerInputManager != null)
                {
                    _laserPointerInputManager.gameObject.SetActive(true);
                }

                _keyboardManager.Activate();
            }
        }