瀏覽代碼

Remove custom keyboard. Use BSML keyboard.

Halsafar 4 年之前
父節點
當前提交
e7c5410964

+ 1 - 0
SongBrowserPlugin/Internals/BeatSaberUI.cs

@@ -13,6 +13,7 @@ using Image = UnityEngine.UI.Image;
 using Logger = SongBrowser.Logging.Logger;
 using UnityEngine.Events;
 using BS_Utils.Utilities;
+using BeatSaberMarkupLanguage;
 
 namespace SongBrowser.Internals
 {

+ 0 - 2
SongBrowserPlugin/SongBrowser.csproj

@@ -153,8 +153,6 @@
     <Compile Include="DataAccess\SongBrowserModel.cs" />
     <Compile Include="DataAccess\SongBrowserSettings.cs" />
     <Compile Include="UI\Base64Sprites.cs" />
-    <Compile Include="UI\Keyboard\CustomUIKeyboard.cs" />
-    <Compile Include="UI\Keyboard\SearchKeyboardViewController.cs" />
     <Compile Include="UI\Browser\SongBrowserUI.cs" />
     <Compile Include="UI\Browser\SongFilterButton.cs" />
     <Compile Include="UI\Browser\SongSortButton.cs" />

+ 8 - 27
SongBrowserPlugin/UI/Browser/SongBrowserUI.cs

@@ -10,7 +10,7 @@ using System.Collections;
 using SongCore.Utilities;
 using SongBrowser.Internals;
 using SongDataCore.BeatStar;
-
+using BeatSaberMarkupLanguage.Components;
 
 namespace SongBrowser.UI
 {
@@ -63,8 +63,6 @@ namespace SongBrowser.UI
         private Button _pageUpFastButton;
         private Button _pageDownFastButton;
 
-        private SearchKeyboardViewController _searchViewController;
-
         private RectTransform _ppStatButton;
         private RectTransform _starStatButton;
         private RectTransform _njsStatButton;
@@ -983,28 +981,13 @@ namespace SongBrowser.UI
         /// </summary>
         void ShowSearchKeyboard()
         {
-            if (_searchViewController == null)
-            {
-                _searchViewController = BeatSaberUI.CreateViewController<SearchKeyboardViewController>("SearchKeyboardViewController");
-                _searchViewController.searchButtonPressed += SearchViewControllerSearchButtonPressed;
-                _searchViewController.backButtonPressed += SearchViewControllerbackButtonPressed;
-            }
-
-            Logger.Debug("Presenting search keyboard");
-            _beatUi.LevelSelectionFlowCoordinator.InvokePrivateMethod("PresentViewController", new object[] { _searchViewController, null, ViewController.AnimationDirection.Horizontal, false });
-        }
-
-        /// <summary>
-        /// Handle back button event from search keyboard.
-        /// </summary>
-        private void SearchViewControllerbackButtonPressed()
-        {
-            _beatUi.LevelSelectionFlowCoordinator.InvokePrivateMethod("DismissViewController", new object[] { _searchViewController, null, false });
-
-            this._model.Settings.filterMode = SongFilterMode.None;
-            this._model.Settings.Save();
-
-            RefreshSongUI();
+            var modalKbTag = new BeatSaberMarkupLanguage.Tags.ModalKeyboardTag();
+            var modalKbView = modalKbTag.CreateObject(_beatUi.LevelSelectionNavigationController.rectTransform);
+            modalKbView.gameObject.SetActive(true);
+            var modalKb = modalKbView.GetComponent<ModalKeyboard>();
+            modalKb.gameObject.SetActive(true);
+            modalKb.keyboard.EnterPressed += SearchViewControllerSearchButtonPressed;
+            modalKb.modalView.Show(true, true);
         }
 
         /// <summary>
@@ -1013,8 +996,6 @@ namespace SongBrowser.UI
         /// <param name="searchFor"></param>
         private void SearchViewControllerSearchButtonPressed(string searchFor)
         {
-            _beatUi.LevelSelectionFlowCoordinator.InvokePrivateMethod("DismissViewController", new object[] { _searchViewController, null, false });
-
             Logger.Debug("Searching for \"{0}\"...", searchFor);
 
             _model.Settings.filterMode = SongFilterMode.Search;

+ 0 - 182
SongBrowserPlugin/UI/Keyboard/CustomUIKeyboard.cs

@@ -1,182 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using UnityEngine;
-using UnityEngine.UI;
-using Logger = SongBrowser.Logging.Logger;
-
-namespace SongBrowser.UI
-{
-    // https://github.com/andruzzzhka/BeatSaverDownloader/blob/master/BeatSaverDownloader/PluginUI/UIElements/CustomUIKeyboard.cs
-    class CustomUIKeyboard : MonoBehaviour
-    {
-        public event Action<char> textKeyWasPressedEvent;
-        public event Action deleteButtonWasPressedEvent;
-        public event Action cancelButtonWasPressedEvent;
-        public event Action okButtonWasPressedEvent;
-
-        public bool HideCancelButton { get { return hideCancelButton; } set { hideCancelButton = value; _cancelButton.gameObject.SetActive(!value); } }
-        public bool OkButtonInteractivity { get { return okButtonInteractivity; } set { okButtonInteractivity = value; _okButton.interactable = value; } }
-
-        private bool okButtonInteractivity;
-        private bool hideCancelButton;
-
-        TextMeshProButton _keyButtonPrefab;
-        Button _cancelButton;
-        Button _okButton;
-
-
-        public void Awake()
-        {
-            _keyButtonPrefab = Resources.FindObjectsOfTypeAll<TextMeshProButton>().First(x => x.name == "KeyboardButton");
-
-            Logger.Log("Found keyboard button!");
-
-            string[] array = new string[]
-            {
-                "q",
-                "w",
-                "e",
-                "r",
-                "t",
-                "y",
-                "u",
-                "i",
-                "o",
-                "p",
-                "a",
-                "s",
-                "d",
-                "f",
-                "g",
-                "h",
-                "j",
-                "k",
-                "l",
-                "z",
-                "x",
-                "c",
-                "v",
-                "b",
-                "n",
-                "m",
-                "<-",
-                "space",
-                "OK",
-                "Cancel"
-            };
-
-            for (int i = 0; i < array.Length; i++)
-            {
-                RectTransform parent = transform.GetChild(i) as RectTransform;
-                //TextMeshProButton textMeshProButton = Instantiate(_keyButtonPrefab, parent);
-                TextMeshProButton textMeshProButton = parent.GetComponentInChildren<TextMeshProButton>();
-                textMeshProButton.text.text = array[i];
-                RectTransform rectTransform = textMeshProButton.transform as RectTransform;
-                rectTransform.localPosition = Vector2.zero;
-                rectTransform.localScale = Vector3.one;
-                rectTransform.anchoredPosition = Vector2.zero;
-                rectTransform.anchorMin = Vector2.zero;
-                rectTransform.anchorMax = Vector3.one;
-                rectTransform.offsetMin = Vector2.zero;
-                rectTransform.offsetMax = Vector2.zero;
-                Navigation navigation = textMeshProButton.button.navigation;
-                navigation.mode = Navigation.Mode.None;
-                textMeshProButton.button.navigation = navigation;
-                textMeshProButton.button.onClick.RemoveAllListeners();
-                if (i < array.Length - 4)
-                {
-                    string key = array[i];
-                    textMeshProButton.button.onClick.AddListener(delegate ()
-                    {
-                        textKeyWasPressedEvent?.Invoke(key[0]);
-                    });
-                }
-                else if (i == array.Length - 4)
-                {
-                    textMeshProButton.button.onClick.AddListener(delegate ()
-                    {
-                        deleteButtonWasPressedEvent?.Invoke();
-                    });
-                }
-                else if (i == array.Length - 1)
-                {
-                    (textMeshProButton.transform as RectTransform).sizeDelta = new Vector2(7f, 1.5f);
-                    _cancelButton = textMeshProButton.button;
-                    _cancelButton.gameObject.SetActive(!HideCancelButton);
-                    textMeshProButton.button.onClick.AddListener(delegate ()
-                    {
-                        cancelButtonWasPressedEvent?.Invoke();
-                    });
-                }
-                else if (i == array.Length - 2)
-                {
-                    _okButton = textMeshProButton.button;
-                    _okButton.interactable = OkButtonInteractivity;
-                    textMeshProButton.button.onClick.AddListener(delegate ()
-                    {
-                        okButtonWasPressedEvent?.Invoke();
-                    });
-                }
-                else
-                {
-                    textMeshProButton.button.onClick.AddListener(delegate ()
-                    {
-                        textKeyWasPressedEvent?.Invoke(' ');
-                    });
-                }
-            }
-
-            name = "CustomUIKeyboard";
-
-            (transform as RectTransform).anchoredPosition -= new Vector2(0f, 0f);
-
-            for (int i = 1; i <= 10; i++)
-            {
-                TextMeshProButton textButton = Instantiate(_keyButtonPrefab);
-                textButton.text.text = (i % 10).ToString();
-
-                string key = (i % 10).ToString();
-                textButton.button.onClick.AddListener(delegate ()
-                {
-                    textKeyWasPressedEvent?.Invoke(key[0]);
-                });
-
-                RectTransform buttonRect = textButton.GetComponent<RectTransform>();
-                RectTransform component2 = transform.GetChild(i - 1).gameObject.GetComponent<RectTransform>();
-
-                RectTransform buttonHolder = Instantiate(component2, component2.parent, false);
-                Destroy(buttonHolder.GetComponentInChildren<Button>().gameObject);
-
-                buttonHolder.anchoredPosition -= new Vector2(0f, -10.5f);
-
-                buttonRect.SetParent(buttonHolder, false);
-
-                buttonRect.localPosition = Vector2.zero;
-                buttonRect.localScale = Vector3.one;
-                buttonRect.anchoredPosition = Vector2.zero;
-                buttonRect.anchorMin = Vector2.zero;
-                buttonRect.anchorMax = Vector3.one;
-                buttonRect.offsetMin = Vector2.zero;
-                buttonRect.offsetMax = Vector2.zero;
-            }
-
-        }
-
-        public void KeyPressed(char key)
-        {
-            textKeyWasPressedEvent.Invoke(key);
-        }
-
-        public void DeleteButtonWasPressed()
-        {
-            deleteButtonWasPressedEvent.Invoke();
-        }
-
-        public void OkButtonWasPressed()
-        {
-            okButtonWasPressedEvent.Invoke();
-        }
-    }
-}

+ 0 - 77
SongBrowserPlugin/UI/Keyboard/SearchKeyboardViewController.cs

@@ -1,77 +0,0 @@
-using SongBrowser.Internals;
-using System;
-using System.Linq;
-using TMPro;
-using UnityEngine;
-
-
-namespace SongBrowser.UI
-{
-    // https://github.com/andruzzzhka/BeatSaverDownloader/blob/master/BeatSaverDownloader/PluginUI/ViewControllers/SearchKeyboardViewController.cs
-    class SearchKeyboardViewController : HMUI.ViewController
-    {
-        GameObject _searchKeyboardGO;
-
-        CustomUIKeyboard _searchKeyboard;
-
-        TextMeshProUGUI _inputText;
-        public string _inputString = "";
-
-        public event Action<string> searchButtonPressed;
-        public event Action backButtonPressed;
-
-        protected override void DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling)
-        {
-            if (addedToHierarchy && firstActivation)
-            {
-                _searchKeyboardGO = Instantiate(Resources.FindObjectsOfTypeAll<HMUI.UIKeyboard>().First(x => x.name != "CustomUIKeyboard"), rectTransform, false).gameObject;
-
-                Destroy(_searchKeyboardGO.GetComponent<UIKeyboard>());
-                _searchKeyboard = _searchKeyboardGO.AddComponent<CustomUIKeyboard>();
-
-                _searchKeyboard.textKeyWasPressedEvent += delegate (char input) { _inputString += input; UpdateInputText(); };
-                _searchKeyboard.deleteButtonWasPressedEvent += delegate () { _inputString = _inputString.Substring(0, _inputString.Length - 1); UpdateInputText(); };
-                _searchKeyboard.cancelButtonWasPressedEvent += () => { backButtonPressed?.Invoke(); };
-                _searchKeyboard.okButtonWasPressedEvent += () => { searchButtonPressed?.Invoke(_inputString); };
-
-                _inputText = BeatSaberUI.CreateText(rectTransform, "Search...", new Vector2(0f, 22f));
-                _inputText.alignment = TextAlignmentOptions.Center;
-                _inputText.fontSize = 6f;
-
-            }
-            else
-            {
-                _inputString = "";
-                UpdateInputText();
-            }
-
-        }
-
-        void UpdateInputText()
-        {
-            if (_inputText != null)
-            {
-                _inputText.text = _inputString?.ToUpper() ?? "";
-                if (string.IsNullOrEmpty(_inputString))
-                {
-                    _searchKeyboard.OkButtonInteractivity = false;
-                }
-                else
-                {
-                    _searchKeyboard.OkButtonInteractivity = true;
-                }
-            }
-        }
-
-        void ClearInput()
-        {
-            _inputString = "";
-        }
-
-        void Back()
-        {
-            _inputString = "";
-            backButtonPressed?.Invoke();
-        }
-    }
-}