Prechádzať zdrojové kódy

Restore delete button.

Halsafar 4 rokov pred
rodič
commit
e92db4cfc5

+ 37 - 12
SongBrowserPlugin/Internals/BeatSaberUI.cs

@@ -61,22 +61,34 @@ namespace SongBrowser.Internals
         }
 
         /// <summary>
-        /// Create an icon button, simple.
+        /// Create Base button
         /// </summary>
+        /// <param name="name"></param>
         /// <param name="parent"></param>
         /// <param name="buttonTemplate"></param>
-        /// <param name="iconSprite"></param>
         /// <returns></returns>
-        public static Button CreateIconButton(String name, RectTransform parent, String buttonTemplate, Vector2 anchoredPosition, Vector2 sizeDelta, UnityAction onClick, Sprite icon)
+        public static Button CreateBaseButton(String name, RectTransform parent, String buttonTemplate)
         {
-            Logger.Debug("CreateIconButton({0}, {1}, {2}, {3}, {4}", name, parent, buttonTemplate, anchoredPosition, sizeDelta);
             Button btn = UnityEngine.Object.Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last(x => (x.name == buttonTemplate)), parent, false);
             btn.name = name;
             btn.interactable = true;
+            return btn;
+        }
+
+        /// <summary>
+        /// Create basic icon button.
+        /// </summary>
+        /// <param name="name"></param>
+        /// <param name="parent"></param>
+        /// <param name="buttonTemplate"></param>
+        /// <returns></returns>
+        public static Button CreateIconButton(String name, RectTransform parent, String buttonTemplate, Sprite icon)
+        {
+            Button btn = CreateBaseButton(name, parent, buttonTemplate);
 
             UnityEngine.Object.Destroy(btn.GetComponent<HoverHint>());
             GameObject.Destroy(btn.GetComponent<LocalizedHoverHint>());
-            btn.gameObject.AddComponent<BeatSaberMarkupLanguage.Components.ExternalComponents>().components.Add(btn.GetComponentsInChildren<LayoutGroup>().First(x => x.name == "Content"));
+            btn.gameObject.AddComponent<ExternalComponents>().components.Add(btn.GetComponentsInChildren<LayoutGroup>().First(x => x.name == "Content"));
 
             Transform contentTransform = btn.transform.Find("Content");
             GameObject.Destroy(contentTransform.Find("Text").gameObject);
@@ -88,7 +100,7 @@ namespace SongBrowser.Internals
             iconImage.preserveAspect = true;
             if (iconImage != null)
             {
-                BeatSaberMarkupLanguage.Components.ButtonIconImage btnIcon = btn.gameObject.AddComponent<BeatSaberMarkupLanguage.Components.ButtonIconImage>();
+                ButtonIconImage btnIcon = btn.gameObject.AddComponent<ButtonIconImage>();
                 btnIcon.image = iconImage;
             }
 
@@ -99,6 +111,23 @@ namespace SongBrowser.Internals
             buttonSizeFitter.verticalFit = ContentSizeFitter.FitMode.Unconstrained;
             buttonSizeFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
 
+            btn.onClick.RemoveAllListeners();
+
+            return btn;
+        }
+
+        /// <summary>
+        /// Create an icon button, simple.
+        /// </summary>
+        /// <param name="parent"></param>
+        /// <param name="buttonTemplate"></param>
+        /// <param name="iconSprite"></param>
+        /// <returns></returns>
+        public static Button CreateIconButton(String name, RectTransform parent, String buttonTemplate, Vector2 anchoredPosition, Vector2 sizeDelta, UnityAction onClick, Sprite icon)
+        {
+            Logger.Debug("CreateIconButton({0}, {1}, {2}, {3}, {4}", name, parent, buttonTemplate, anchoredPosition, sizeDelta);
+            Button btn = CreateIconButton(name, parent, buttonTemplate, icon);
+
             (btn.transform as RectTransform).anchorMin = new Vector2(0.5f, 0.5f);
             (btn.transform as RectTransform).anchorMax = new Vector2(0.5f, 0.5f);
             (btn.transform as RectTransform).anchoredPosition = anchoredPosition;
@@ -114,9 +143,7 @@ namespace SongBrowser.Internals
         public static Button CreatePageButton(String name, RectTransform parent, String buttonTemplate, Vector2 anchoredPosition, Vector2 sizeDelta, UnityAction onClick, Sprite icon)
         {
             Logger.Debug("CreatePageButton({0}, {1}, {2}, {3}, {4}", name, parent, buttonTemplate, anchoredPosition, sizeDelta);
-            Button btn = UnityEngine.Object.Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last(x => (x.name == buttonTemplate)), parent, false);
-            btn.name = name;
-            btn.interactable = true;
+            Button btn = CreateBaseButton(name, parent, buttonTemplate);
 
             (btn.transform as RectTransform).anchorMin = new Vector2(0.5f, 0.5f);
             (btn.transform as RectTransform).anchorMax = new Vector2(0.5f, 0.5f);
@@ -149,10 +176,8 @@ namespace SongBrowser.Internals
         public static Button CreateUIButton(String name, RectTransform parent, string buttonTemplate, Vector2 anchoredPosition, Vector2 sizeDelta, UnityAction onClick = null, string buttonText = "BUTTON")
         {
             Logger.Debug("CreateUIButton({0}, {1}, {2}, {3}, {4}", name, parent, buttonTemplate, anchoredPosition, sizeDelta);
-            Button btn = UnityEngine.Object.Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last(x => (x.name == buttonTemplate)), parent, false);
+            Button btn = CreateBaseButton(name, parent, buttonTemplate);
             btn.gameObject.SetActive(true);
-            btn.name = name;
-            btn.interactable = true;
 
             Polyglot.LocalizedTextMeshProUGUI localizer = btn.GetComponentInChildren<Polyglot.LocalizedTextMeshProUGUI>();
             if (localizer != null)

+ 1 - 1
SongBrowserPlugin/UI/Browser/BeatSaberUIController.cs

@@ -98,7 +98,7 @@ namespace SongBrowser.DataAccess
             ActionButtons = LevelDetailViewController.GetComponentsInChildren<RectTransform>().First(x => x.name == "ActionButtons");
             Logger.Debug("Acquired ActionButtons [{0}]", ActionButtons.GetInstanceID());
 
-            SimpleDialogPromptViewControllerPrefab = Resources.FindObjectsOfTypeAll<SimpleDialogPromptViewController>().First();
+            SimpleDialogPromptViewControllerPrefab = Resources.FindObjectsOfTypeAll<SimpleDialogPromptViewController>().Last();
             Logger.Debug("Acquired SimpleDialogPromptViewControllerPrefab [{0}]", SimpleDialogPromptViewControllerPrefab.GetInstanceID());
 
             BeatmapLevelsModel = Resources.FindObjectsOfTypeAll<BeatmapLevelsModel>().Last();

+ 34 - 36
SongBrowserPlugin/UI/Browser/SongBrowserUI.cs

@@ -10,6 +10,7 @@ using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 using UnityEngine.UI;
+using VRUIControls;
 using Logger = SongBrowser.Logging.Logger;
 
 namespace SongBrowser.UI
@@ -142,16 +143,11 @@ namespace SongBrowser.UI
                 _viewController.rectTransform.sizeDelta = new Vector2(125, 25);
                 _viewController.gameObject.SetActive(true);
 
-                // delete dialog
-                this._deleteDialog = UnityEngine.Object.Instantiate<SimpleDialogPromptViewController>(_beatUi.SimpleDialogPromptViewControllerPrefab);
-                this._deleteDialog.name = "DeleteDialogPromptViewController";
-                this._deleteDialog.gameObject.SetActive(false);
-
                 // create song browser main ui
                 CreateOuterUi();
                 CreateSortButtons();
                 CreateFilterButtons();
-                CreateDeleteButton();
+                CreateDeleteUI();
                 CreateFastPageButtons();
 
                 this.InstallHandlers();
@@ -380,15 +376,20 @@ namespace SongBrowser.UI
         /// <summary>
         /// Create the delete button in the play button container
         /// </summary>
-        private void CreateDeleteButton()
+        private void CreateDeleteUI()
         {
-            // Create delete button
-            /*Logger.Debug("Creating delete button...");
-            _deleteButton = BeatSaberUI.CreateIconButton(_beatUi.PlayButtons, _beatUi.PracticeButton, Base64Sprites.DeleteIcon);
+            Logger.Debug("Creating delete dialog...");
+            _deleteDialog = UnityEngine.Object.Instantiate<SimpleDialogPromptViewController>(_beatUi.SimpleDialogPromptViewControllerPrefab);
+            _deleteDialog.GetComponent<VRGraphicRaycaster>().SetField("_physicsRaycaster", BeatSaberUI.PhysicsRaycasterWithCache);
+            _deleteDialog.name = "DeleteDialogPromptViewController";
+            _deleteDialog.gameObject.SetActive(false);
+
+            Logger.Debug("Creating delete button...");
+            _deleteButton = BeatSaberUI.CreateIconButton("DeleteLevelButton", _beatUi.ActionButtons, "PracticeButton", Base64Sprites.DeleteIcon);
+            _deleteButton.transform.SetAsFirstSibling();
             _deleteButton.onClick.AddListener(delegate () {
                 HandleDeleteSelectedLevel();
             });
-            BeatSaberUI.DestroyHoverHint(_deleteButton.transform as RectTransform);*/
         }
 
         /// <summary>
@@ -433,8 +434,7 @@ namespace SongBrowser.UI
         public void ResizeSongUI()
         {
             // shrink play button container
-            //RectTransform playButtonsRect = Resources.FindObjectsOfTypeAll<RectTransform>().First(x => x.name == "ActionButtons");
-            //playButtonsRect.localScale = new Vector3(0.825f, 0.825f, 0.825f);
+            _beatUi.ActionButtons.localScale = new Vector3(0.875f, 0.875f, 0.875f);
         }
 
         /// <summary>
@@ -879,11 +879,7 @@ namespace SongBrowser.UI
                 return;
             }
 
-            if (_deleteButton != null)
-            {
-                _deleteButton.interactable = (view.selectedDifficultyBeatmap.level.levelID.Length >= 32);
-            }
-
+            UpdateDeleteButtonState(view.selectedDifficultyBeatmap.level.levelID);
             RefreshScoreSaberData(view.selectedDifficultyBeatmap.level);
             RefreshNoteJumpSpeed(beatmap.noteJumpMovementSpeed, beatmap.noteJumpStartBeatOffset);
         }
@@ -897,7 +893,6 @@ namespace SongBrowser.UI
         {
             Logger.Trace("OnDidPresentContentEvent()");
 
-            // v1.12.2 - TODO - is this safe to prevent us from trying to lookup empty/dead content?
             if (type != StandardLevelDetailViewController.ContentType.OwnedAndReady)
             {
                 return;
@@ -908,11 +903,7 @@ namespace SongBrowser.UI
                 return;
             }
 
-            if (_deleteButton != null)
-            {
-                _deleteButton.interactable = (_beatUi.LevelDetailViewController.selectedDifficultyBeatmap.level.levelID.Length >= 32);
-            }
-
+            UpdateDeleteButtonState(_beatUi.LevelDetailViewController.selectedDifficultyBeatmap.level.levelID);
             RefreshScoreSaberData(view.selectedDifficultyBeatmap.level);
             RefreshNoteJumpSpeed(view.selectedDifficultyBeatmap.noteJumpMovementSpeed, view.selectedDifficultyBeatmap.noteJumpStartBeatOffset);
         }
@@ -925,11 +916,7 @@ namespace SongBrowser.UI
         {
             Logger.Trace("HandleDidSelectLevelRow({0})", level);
 
-            if (_deleteButton != null)
-            {
-                _deleteButton.interactable = (level.levelID.Length >= 32);
-            }
-
+            UpdateDeleteButtonState(level.levelID);
             RefreshQuickScrollButtons();
         }
 
@@ -942,14 +929,11 @@ namespace SongBrowser.UI
             _deleteDialog.Init("Delete song", $"Do you really want to delete \"{ level.songName} {level.songSubName}\"?", "Delete", "Cancel",
                 (selectedButton) =>
                 {
-                    _beatUi.LevelSelectionFlowCoordinator.InvokePrivateMethod("DismissViewController", new object[] { _deleteDialog, null, false });
+                    _deleteDialog.__DismissViewController(null);
                     if (selectedButton == 0)
                     {
                         try
                         {
-                            // determine the index we are deleting so we can keep the cursor near the same spot after
-                            // the header counts as an index, so if the index came from the level array we have to add 1.
-                            var levelsTableView = _beatUi.LevelCollectionTableView;
                             List<IPreviewBeatmapLevel> levels = _beatUi.GetCurrentLevelCollectionLevels().ToList();
                             int selectedIndex = levels.FindIndex(x => x.levelID == _beatUi.StandardLevelDetailView.selectedDifficultyBeatmap.level.levelID);
 
@@ -958,11 +942,11 @@ namespace SongBrowser.UI
                                 var song = SongCore.Loader.CustomLevels.First(x => x.Value.levelID == _beatUi.LevelDetailViewController.selectedDifficultyBeatmap.level.levelID).Value;
 
                                 Logger.Info($"Deleting song: {song.customLevelPath}");
+
                                 SongCore.Loader.Instance.DeleteSong(song.customLevelPath);
-                                this._model.RemoveSongFromLevelCollection(_beatUi.GetCurrentSelectedAnnotatedBeatmapLevelCollection(), _beatUi.LevelDetailViewController.selectedDifficultyBeatmap.level.levelID);
 
                                 int removedLevels = levels.RemoveAll(x => x.levelID == _beatUi.StandardLevelDetailView.selectedDifficultyBeatmap.level.levelID);
-                                Logger.Info("Removed " + removedLevels + " level(s) from song list!");
+                                Logger.Info($"Removed [{removedLevels}] level(s) from song list!");
 
                                 this.UpdateLevelDataModel();
 
@@ -984,7 +968,7 @@ namespace SongBrowser.UI
                         }
                     }
                 });
-            _beatUi.LevelSelectionFlowCoordinator.InvokePrivateMethod("PresentViewController", new object[] { _deleteDialog, null, false });
+            _beatUi.LevelSelectionNavigationController.__PresentViewController(_deleteDialog, null);
         }
 
         /// <summary>
@@ -1147,6 +1131,20 @@ namespace SongBrowser.UI
         }
 
         /// <summary>
+        /// Update delete button state.  Enable for custom levels, disable for all else.
+        /// </summary>
+        /// <param name="levelId"></param>
+        public void UpdateDeleteButtonState(String levelId)
+        {
+            if (_deleteButton == null)
+            {
+                return;
+            }
+
+            _deleteButton.gameObject.SetActive(levelId.Length >= 32);
+        }
+
+        /// <summary>
         /// Show the UI.
         /// </summary>
         public void Show()