瀏覽代碼

When song list refreshes the current node now updates properly. This
fixes the song list not updating when a song is deleted or a song is
added.

Stephen Damm 6 年之前
父節點
當前提交
58bce9f3e1
共有 2 個文件被更改,包括 98 次插入95 次删除
  1. 12 15
      SongBrowserPlugin/SongBrowserModel.cs
  2. 86 80
      SongBrowserPlugin/UI/SongBrowserUI.cs

+ 12 - 15
SongBrowserPlugin/SongBrowserModel.cs

@@ -305,6 +305,7 @@ namespace SongBrowserPlugin
         {
             // Determine folder mapping
             Uri customSongDirUri = new Uri(customSongsPath);
+
             _directoryTree = new Dictionary<string, DirectoryNode>();
             _directoryTree[CUSTOM_SONGS_DIR] = new DirectoryNode(CUSTOM_SONGS_DIR);
 
@@ -319,25 +320,21 @@ namespace SongBrowserPlugin
             {
                 _directoryTree[CUSTOM_SONGS_DIR].Levels = _originalSongs;
             }
-            
-        
+                    
             // Determine starting location
-            if (_directoryStack.Count < 1)
-            {
-                DirectoryNode currentNode = _directoryTree[CUSTOM_SONGS_DIR];
-                _directoryStack.Push(currentNode);
+            DirectoryNode currentNode = _directoryTree[CUSTOM_SONGS_DIR];
+            _directoryStack.Push(currentNode);
 
-                // Try to navigate directory path
-                if (!String.IsNullOrEmpty(this.CurrentDirectory))
+            // Try to navigate directory path
+            if (!String.IsNullOrEmpty(this.CurrentDirectory))
+            {
+                String[] paths = this.CurrentDirectory.Split('/');
+                for (int i = 1; i < paths.Length; i++)
                 {
-                    String[] paths = this.CurrentDirectory.Split('/');
-                    for (int i = 1; i < paths.Length; i++)
+                    if (currentNode.Nodes.ContainsKey(paths[i]))
                     {
-                        if (currentNode.Nodes.ContainsKey(paths[i]))
-                        {
-                            currentNode = currentNode.Nodes[paths[i]];
-                            _directoryStack.Push(currentNode);
-                        }
+                        currentNode = currentNode.Nodes[paths[i]];
+                        _directoryStack.Push(currentNode);
                     }
                 }
             }

+ 86 - 80
SongBrowserPlugin/UI/SongBrowserUI.cs

@@ -497,6 +497,7 @@ namespace SongBrowserPlugin.UI
                     }
                 }
 
+                _model.LastSelectedLevelId = null;
                 SongLoaderPlugin.SongLoader.Instance.RemoveSongWithPath(songPath);
                 this.UpdateSongList();
                 this.RefreshSongList();
@@ -783,7 +784,6 @@ namespace SongBrowserPlugin.UI
         /// </summary>
         public void LateUpdate()
         {
-            if (!this._levelListViewController.isActiveAndEnabled) return;
             CheckDebugUserInput();
         }
 
@@ -794,106 +794,112 @@ namespace SongBrowserPlugin.UI
         {
             try
             {
-                bool isShiftKeyDown = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
-
-                // back
-                if (Input.GetKeyDown(KeyCode.Escape))
+                if (this._levelListViewController.isActiveAndEnabled)
                 {
-                    this._levelSelectionNavigationController.DismissButtonWasPressed();
-                }
+                    bool isShiftKeyDown = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
 
-                // cycle sort modes
-                if (Input.GetKeyDown(KeyCode.T))
-                {
-                    _sortButtonLastPushedIndex = (_sortButtonLastPushedIndex + 1) % _sortButtonGroup.Count;
-                    _sortButtonGroup[_sortButtonLastPushedIndex].Button.onClick.Invoke();
-                }
+                    // back
+                    if (Input.GetKeyDown(KeyCode.Escape))
+                    {
+                        this._levelSelectionNavigationController.DismissButtonWasPressed();
+                    }
 
-                if (Input.GetKeyDown(KeyCode.S))
-                {
-                    onSortButtonClickEvent(SongSortMode.Search);
-                }
+                    // cycle sort modes
+                    if (Input.GetKeyDown(KeyCode.T))
+                    {
+                        _sortButtonLastPushedIndex = (_sortButtonLastPushedIndex + 1) % _sortButtonGroup.Count;
+                        _sortButtonGroup[_sortButtonLastPushedIndex].Button.onClick.Invoke();
+                    }
 
-                // select current sort mode again (toggle inverting)
-                if (Input.GetKeyDown(KeyCode.Y))
-                {
-                    _sortButtonGroup[_sortButtonLastPushedIndex].Button.onClick.Invoke();
-                }
+                    if (Input.GetKeyDown(KeyCode.S))
+                    {
+                        onSortButtonClickEvent(SongSortMode.Search);
+                    }
 
-                // playlists
-                if (Input.GetKeyDown(KeyCode.P))
-                {
-                    _sortButtonGroup[_sortButtonGroup.Count - 2].Button.onClick.Invoke();
-                }
+                    // select current sort mode again (toggle inverting)
+                    if (Input.GetKeyDown(KeyCode.Y))
+                    {
+                        _sortButtonGroup[_sortButtonLastPushedIndex].Button.onClick.Invoke();
+                    }
 
-                // delete
-                if (Input.GetKeyDown(KeyCode.D))
-                {
-                    if (_deleteDialog.isInViewControllerHierarchy)
+                    // playlists
+                    if (Input.GetKeyDown(KeyCode.P))
                     {
-                        return;
+                        _sortButtonGroup[_sortButtonGroup.Count - 2].Button.onClick.Invoke();
                     }
-                    _deleteButton.onClick.Invoke();
-                }
 
-                // accept delete
-                if (Input.GetKeyDown(KeyCode.B) && _deleteDialog.isInViewControllerHierarchy)
-                {
-                    _deleteDialog.GetPrivateField<TextMeshProButton>("_okButton").button.onClick.Invoke();
-                }
+                    // delete
+                    if (Input.GetKeyDown(KeyCode.D))
+                    {
+                        _deleteButton.onClick.Invoke();
+                    }
 
-                // c - select difficulty for top song
-                if (Input.GetKeyDown(KeyCode.C))
-                {
-                    this.SelectAndScrollToLevel(_levelListTableView, _model.SortedSongList[0].levelID);                 
-                    this._levelDifficultyViewController.HandleDifficultyTableViewDidSelectRow(null, 0);
-                    this._levelSelectionFlowCoordinator.HandleDifficultyViewControllerDidSelectDifficulty(_levelDifficultyViewController, _model.SortedSongList[0].GetDifficultyLevel(LevelDifficulty.Easy));
-                }
+                    // c - select difficulty for top song
+                    if (Input.GetKeyDown(KeyCode.C))
+                    {
+                        this.SelectAndScrollToLevel(_levelListTableView, _model.SortedSongList[0].levelID);
+                        this._levelDifficultyViewController.HandleDifficultyTableViewDidSelectRow(null, 0);
+                        this._levelSelectionFlowCoordinator.HandleDifficultyViewControllerDidSelectDifficulty(_levelDifficultyViewController, _model.SortedSongList[0].GetDifficultyLevel(LevelDifficulty.Easy));
+                    }
 
-                // v start a song or enter a folder
-                if (Input.GetKeyDown(KeyCode.Return))
-                {
-                    if (_playButton.isActiveAndEnabled)
+                    // v start a song or enter a folder
+                    if (Input.GetKeyDown(KeyCode.Return))
                     {
-                        _playButton.onClick.Invoke();
+                        if (_playButton.isActiveAndEnabled)
+                        {
+                            _playButton.onClick.Invoke();
+                        }
+                        else if (_enterFolderButton.isActiveAndEnabled)
+                        {
+                            _enterFolderButton.onClick.Invoke();
+                        }
                     }
-                    else if (_enterFolderButton.isActiveAndEnabled)
+
+                    // backspace - up a folder
+                    if (Input.GetKeyDown(KeyCode.Backspace))
                     {
-                        _enterFolderButton.onClick.Invoke();
+                        _upFolderButton.onClick.Invoke();
                     }
-                }
 
-                // backspace - up a folder
-                if (Input.GetKeyDown(KeyCode.Backspace))
-                {
-                    _upFolderButton.onClick.Invoke();
-                }
+                    // change song index
+                    if (isShiftKeyDown && Input.GetKeyDown(KeyCode.N))
+                    {
+                        _pageUpTenPercent.onClick.Invoke();
+                    }
+                    else if (Input.GetKeyDown(KeyCode.N))
+                    {
+                        _lastRow = (_lastRow - 1) != -1 ? (_lastRow - 1) % this._model.SortedSongList.Count : 0;
+                        this.SelectAndScrollToLevel(_levelListTableView, _model.SortedSongList[_lastRow].levelID);
+                    }
 
-                // change song index
-                if (isShiftKeyDown && Input.GetKeyDown(KeyCode.N))
-                {
-                    _pageUpTenPercent.onClick.Invoke();
-                }
-                else if (Input.GetKeyDown(KeyCode.N))
-                {
-                    _lastRow = (_lastRow - 1) != -1 ? (_lastRow - 1) % this._model.SortedSongList.Count : 0;
-                    this.SelectAndScrollToLevel(_levelListTableView, _model.SortedSongList[_lastRow].levelID);
-                }
+                    if (isShiftKeyDown && Input.GetKeyDown(KeyCode.M))
+                    {
+                        _pageDownTenPercent.onClick.Invoke();
+                    }
+                    else if (Input.GetKeyDown(KeyCode.M))
+                    {
+                        _lastRow = (_lastRow + 1) % this._model.SortedSongList.Count;
+                        this.SelectAndScrollToLevel(_levelListTableView, _model.SortedSongList[_lastRow].levelID);
+                    }
 
-                if (isShiftKeyDown && Input.GetKeyDown(KeyCode.M))
-                {
-                    _pageDownTenPercent.onClick.Invoke();
+                    // add to favorites
+                    if (Input.GetKeyDown(KeyCode.F))
+                    {
+                        ToggleSongInFavorites();
+                    }
                 }
-                else if (Input.GetKeyDown(KeyCode.M))
+                else if (_deleteDialog.isInViewControllerHierarchy)
                 {
-                    _lastRow = (_lastRow + 1) % this._model.SortedSongList.Count;
-                    this.SelectAndScrollToLevel(_levelListTableView, _model.SortedSongList[_lastRow].levelID);
-                }
+                    // accept delete
+                    if (Input.GetKeyDown(KeyCode.Return))
+                    {
+                        _deleteDialog.GetPrivateField<TextMeshProButton>("_okButton").button.onClick.Invoke();
+                    }
 
-                // add to favorites
-                if (Input.GetKeyDown(KeyCode.F))
-                {
-                    ToggleSongInFavorites();
+                    if (Input.GetKeyDown(KeyCode.Escape))
+                    {
+                        _deleteDialog.GetPrivateField<TextMeshProButton>("_cancelButton").button.onClick.Invoke();
+                    }
                 }
             }
             catch (Exception e)