Browse Source

Missing files.

Stephen Damm 6 years ago
parent
commit
d22809c6b2

+ 137 - 0
SongBrowserPlugin/UI/CustomUIKeyboard.cs

@@ -0,0 +1,137 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using UnityEngine;
+using UnityEngine.UI;
+
+namespace SongBrowserPlugin.UI
+{
+    // https://github.com/andruzzzhka/BeatSaverDownloader/blob/master/BeatSaverDownloader/PluginUI/UIElements/CustomUIKeyboard.cs
+    class CustomUIKeyboard : UIKeyboard
+    {
+        public void Awake()
+        {
+            UIKeyboard original = GetComponent<UIKeyboard>();
+
+            System.Reflection.FieldInfo[] fields = original.GetType().GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
+            foreach (System.Reflection.FieldInfo field in fields)
+            {
+                field.SetValue(this, field.GetValue(original));
+            }
+
+            Destroy(original);
+
+        }
+
+        public override void Start()
+        {
+            name = "CustomUIKeyboard";
+
+            (transform as RectTransform).anchoredPosition -= new Vector2(0f, 5f);
+
+            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"
+            };
+
+
+            for (int i = 0; i < array.Length; i++)
+            {
+                TextMeshProButton textButton = Instantiate(_keyButtonPrefab);
+                textButton.text.text = array[i];
+                if (i < array.Length - 2)
+                {
+                    string key = array[i];
+                    textButton.button.onClick.AddListener(delegate ()
+                    {
+                        KeyButtonWasPressed(key);
+                    });
+                }
+                else if (i == array.Length - 2)
+                {
+                    textButton.button.onClick.AddListener(delegate ()
+                    {
+                        DeleteButtonWasPressed();
+                    });
+                }
+                else
+                {
+                    textButton.button.onClick.AddListener(delegate ()
+                    {
+                        SpaceButtonWasPressed();
+                    });
+                }
+                RectTransform buttonRect = textButton.GetComponent<RectTransform>();
+                RectTransform component2 = transform.GetChild(i).gameObject.GetComponent<RectTransform>();
+                buttonRect.SetParent(component2, 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;
+            }
+
+
+            for (int i = 1; i <= 10; i++)
+            {
+                TextMeshProButton textButton = Instantiate(_keyButtonPrefab);
+                textButton.text.text = i.ToString().Last().ToString();
+
+                string key = i.ToString().Last().ToString();
+                textButton.button.onClick.AddListener(delegate ()
+                {
+                    KeyButtonWasPressed(key);
+                });
+
+                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;
+            }
+
+        }
+    }
+}

+ 117 - 0
SongBrowserPlugin/UI/SearchKeyboardViewController.cs

@@ -0,0 +1,117 @@
+using System;
+using System.Linq;
+using TMPro;
+using UnityEngine;
+using UnityEngine.UI;
+using VRUI;
+
+namespace SongBrowserPlugin.UI
+{
+    // https://github.com/andruzzzhka/BeatSaverDownloader/blob/master/BeatSaverDownloader/PluginUI/ViewControllers/SearchKeyboardViewController.cs
+    class SearchKeyboardViewController : VRUIViewController
+    {
+        GameObject _searchKeyboardGO;
+
+        CustomUIKeyboard _searchKeyboard;
+
+        Button _searchButton;
+        Button _backButton;
+
+        TextMeshProUGUI _inputText;
+        public string _inputString = "";
+
+        public event Action<string> searchButtonPressed;
+        public event Action backButtonPressed;
+
+        protected override void DidActivate(bool firstActivation, ActivationType type)
+        {
+            if (_searchKeyboard == null)
+            {
+                _searchKeyboardGO = Instantiate(Resources.FindObjectsOfTypeAll<UIKeyboard>().First(x => x.name != "CustomUIKeyboard"), rectTransform, false).gameObject;
+
+                _searchKeyboard = _searchKeyboardGO.AddComponent<CustomUIKeyboard>();
+
+                _searchKeyboard.uiKeyboardKeyEvent = delegate (char input) { _inputString += input; UpdateInputText(); };
+                _searchKeyboard.uiKeyboardDeleteEvent = delegate () { _inputString = _inputString.Substring(0, _inputString.Length - 1); UpdateInputText(); };
+            }
+
+            if (_inputText == null)
+            {
+                _inputText = UIBuilder.CreateText(rectTransform, "Search...", new Vector2(0f, -11.5f));
+                _inputText.alignment = TextAlignmentOptions.Center;
+                _inputText.fontSize = 6f;
+            }
+            else
+            {
+                _inputString = "";
+                UpdateInputText();
+            }
+
+            if (_searchButton == null)
+            {
+                _searchButton = UIBuilder.CreateUIButton(rectTransform, "ApplyButton");
+                UIBuilder.SetButtonText(ref _searchButton, "Search");
+                (_searchButton.transform as RectTransform).sizeDelta = new Vector2(30f, 10f);
+                (_searchButton.transform as RectTransform).anchoredPosition = new Vector2(-15f, 1.5f);
+                _searchButton.onClick.RemoveAllListeners();
+                _searchButton.onClick.AddListener(delegate ()
+                {
+                    searchButtonPressed?.Invoke(_inputString);
+                    DismissModalViewController(null, false);
+                });
+            }
+
+            if (_backButton == null)
+            {
+                _backButton = UIBuilder.CreateBackButton(rectTransform);
+
+                _backButton.onClick.AddListener(delegate ()
+                {
+                    _inputString = "";
+                    backButtonPressed?.Invoke();
+                    DismissModalViewController(null, false);
+                });
+            }
+
+        }
+
+        void UpdateInputText()
+        {
+            if (_inputText != null)
+            {
+                _inputText.text = _inputString.ToUpper();
+            }
+        }
+
+        void ClearInput()
+        {
+            _inputString = "";
+        }
+
+        private void LateUpdate()
+        {
+            if (!this.isInViewControllerHierarchy) return;
+
+            foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
+            {
+                if (kcode.CompareTo(KeyCode.Backspace) == 0)
+                {
+                    this._searchKeyboard.DeleteButtonWasPressed();                   
+                }
+                else if (kcode.CompareTo(KeyCode.Space) == 0)
+                {
+                    this._searchKeyboard.SpaceButtonWasPressed();
+                }
+                else if (Input.GetKeyDown(kcode))
+                {
+                    this._searchKeyboard.KeyButtonWasPressed(kcode.ToString());
+                }
+            }
+
+            if (Input.GetKeyDown(KeyCode.KeypadEnter))
+            {
+                _searchButton.onClick.Invoke();                
+            }
+        }
+    }
+}

+ 5 - 7
SongBrowserPlugin/UI/SongBrowserUI.cs

@@ -152,15 +152,15 @@ namespace SongBrowserPlugin.UI
                 
                 Sprite arrowIcon = SongBrowserApplication.Instance.CachedIcons["ArrowIcon"];
 
-                float fontSize = 2.75f;
-                float buttonWidth = 17.0f;
+                float fontSize = 2.5f;
+                float buttonWidth = 14.0f;
                 float buttonHeight = 5.0f;
                 float buttonX = 68.0f;
                 float buttonY = 74.5f;
 
                 string[] buttonNames = new string[]
                 {
-                    "Favorite", "Song", "Author", "Original", "Newest", "PlayCount", "Random", "Search"
+                    "Favorite", "Song", "Author", "Original", "Newest", "Plays", "Random", "Search"
                 };
 
                 SongSortMode[] sortModes = new SongSortMode[]
@@ -625,10 +625,8 @@ namespace SongBrowserPlugin.UI
         /// </summary>
         public void LateUpdate()
         {
-            if (this._levelListViewController.isInViewControllerHierarchy)
-            {
-                CheckDebugUserInput();
-            }
+            if (!this._levelListViewController.isActiveAndEnabled) return;
+            CheckDebugUserInput();
         }
 
         /// <summary>