Exemple #1
0
        private void clearButton_Click(object sender, EventArgs e)
        {
            if (ClearButtonPressed != null)
            {
                var args = new HandledEventArgs();
                ClearButtonPressed?.Invoke(this, args);

                if (args.Handled)
                {
                    return;
                }
            }

            Clear();
        }
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (firstActivation)
            {
                this.name = "SearchCompactKeyboardViewController";

                this.rectTransform.anchorMin        = new Vector2(0.5f, 0.5f);
                this.rectTransform.anchorMax        = this.rectTransform.anchorMin;
                this.rectTransform.pivot            = this.rectTransform.anchorMin;
                this.rectTransform.anchoredPosition = Vector2.zero;
                this.rectTransform.sizeDelta        = new Vector2(80f, 70f);

                _predictionBar = new GameObject("EnhancedSearchPredictionBar").AddComponent <PredictionBar>();
                _predictionBar.Initialize(this.transform, 3.5f, 19f, -35f, 45f);
                _predictionBar.PredictionPressed += delegate(string query, SuggestionType type)
                {
                    _searchText = query;
                    _textDisplayComponent.text = _searchText.ToUpper() + CursorText;

                    _predictionBar.ClearAndSetPredictionButtons(_searchText);

                    PredictionPressed?.Invoke(query, type);
                };

                var keyboardGO = Instantiate(Resources.FindObjectsOfTypeAll <UIKeyboard>().First(x => x.name != "CustomUIKeyboard" && x.name != "EnhancedSearchKeyboard"), this.transform, false).gameObject;
                Destroy(keyboardGO.GetComponent <UIKeyboard>());
                _keyboard       = keyboardGO.AddComponent <CompactSearchKeyboard>();
                keyboardGO.name = "EnhancedSearchKeyboard";

                var rt = _keyboard.transform as RectTransform;
                rt.anchorMin        = Vector2.zero;
                rt.anchorMax        = Vector2.one;
                rt.pivot            = new Vector2(0.5f, 0.5f);
                rt.anchoredPosition = new Vector2(OffsetX, 5f);
                rt.sizeDelta        = Vector2.zero;

                _keyboard.TextKeyPressed += delegate(char key)
                {
                    _searchText += key.ToString();
                    _textDisplayComponent.text = _searchText.ToUpper() + CursorText;

                    _predictionBar.ClearAndSetPredictionButtons(_searchText);

                    TextKeyPressed?.Invoke(key);
                };
                _keyboard.DeleteButtonPressed += delegate
                {
                    if (_searchText.Length > 0)
                    {
                        _searchText = _searchText.Substring(0, _searchText.Length - 1);
                    }

                    if (_searchText.Length > 0)
                    {
                        _textDisplayComponent.text = _searchText.ToUpper() + CursorText;
                    }
                    else
                    {
                        _textDisplayComponent.text = PlaceholderText;
                    }

                    _predictionBar.ClearAndSetPredictionButtons(_searchText);

                    DeleteButtonPressed?.Invoke();
                };
                _keyboard.ClearButtonPressed += delegate
                {
                    _searchText = "";
                    _textDisplayComponent.text = PlaceholderText;

                    _predictionBar.ClearAndSetPredictionButtons(_searchText);

                    ClearButtonPressed?.Invoke();
                };

                _textDisplayComponent                    = BeatSaberUI.CreateText(this.rectTransform, "", new Vector2(OffsetX, 28f), new Vector2(4f, 4f));
                _textDisplayComponent.fontSize           = 6f;
                _textDisplayComponent.alignment          = TextAlignmentOptions.Center;
                _textDisplayComponent.enableWordWrapping = false;
            }

            _searchText = "";
            _textDisplayComponent.text          = PlaceholderText;
            _keyboard.SymbolButtonInteractivity = !PluginConfig.StripSymbols;
            _keyboard.ResetSymbolMode();
            _predictionBar.ClearPredictionButtons();
        }
        public void Awake()
        {
            // create buttons for letters and their respective symbols
            string[] keyArray = 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",*/ "Symbols", "Clear"
            };
            string[] symbolArray = new string[]
            {
                "[", "]", "{", "}", "\\", "|", "-", "_", "=", "+",
                "", "", "", "", "", ";", ":", "'", "\"",
                "", ",", ".", "<", ">", "/", "?"
            };
            for (int i = 0; i < keyArray.Length; i++)
            {
                TextMeshProButton textMeshProButton;
                if (i < keyArray.Length - 2)
                {
                    textMeshProButton = CreateKeyboardButton(i);
                }
                else if (i == keyArray.Length - 2)
                {
                    // Symbol button adapted from Cancel button
                    textMeshProButton = CreateKeyboardButton(29);
                }
                else
                {
                    // Clear button adapted from Delete button
                    textMeshProButton = CreateKeyboardButton(26, true);
                }

                textMeshProButton.text.text = keyArray[i];

                if (i < keyArray.Length - 4)
                {
                    string key       = keyArray[i];
                    string symbolKey = symbolArray[i];

                    _keyPairs[i].button = textMeshProButton;
                    _keyPairs[i].key    = key;
                    _keyPairs[i].symKey = symbolArray[i];

                    textMeshProButton.button.onClick.AddListener(delegate()
                    {
                        if (_symbolModeActive)
                        {
                            if (!string.IsNullOrEmpty(symbolKey))
                            {
                                TextKeyPressed?.Invoke(symbolKey[0]);
                            }
                        }
                        else
                        {
                            TextKeyPressed?.Invoke(key[0]);
                        }
                    });
                }
                else if (i == keyArray.Length - 4)
                {
                    // Delete/Backspace button
                    textMeshProButton.button.onClick.AddListener(delegate()
                    {
                        DeleteButtonPressed?.Invoke();
                    });
                }
                else if (i == keyArray.Length - 3)
                {
                    // Space key
                    (textMeshProButton.button.transform as RectTransform).sizeDelta         = new Vector2(10f, 0f);
                    (textMeshProButton.button.transform as RectTransform).anchoredPosition += new Vector2(5f, 0f);
                    textMeshProButton.button.onClick.AddListener(delegate()
                    {
                        TextKeyPressed?.Invoke(' ');
                    });
                }
                //else if (i == keyArray.Length - 3)
                //{
                //    // Search button
                //    (textMeshProButton.transform as RectTransform).sizeDelta = new Vector2(4f, 2f);
                //    (textMeshProButton.transform as RectTransform).anchoredPosition += new Vector2(26f, -1f);
                //    textMeshProButton.text.fontSize = 6f;

                //    _searchButton = textMeshProButton.button;
                //    _searchButton.onClick.AddListener(delegate ()
                //    {
                //        SearchButtonPressed?.Invoke();
                //    });
                //    SearchButtonInteractivity = false;
                //}
                else if (i == keyArray.Length - 2)
                {
                    // Symbols button
                    (textMeshProButton.transform as RectTransform).sizeDelta         = new Vector2(10f, 0f);
                    (textMeshProButton.transform as RectTransform).anchoredPosition += new Vector2(-2f, 0f);

                    _symbolButton = textMeshProButton;
                    _symbolButton.button.onClick.AddListener(delegate()
                    {
                        SetSymbolMode(!_symbolModeActive);
                    });
                }
                else
                {
                    // Clear button
                    (textMeshProButton.transform as RectTransform).sizeDelta         = new Vector2(6f, 0);
                    (textMeshProButton.transform as RectTransform).anchoredPosition += new Vector2(2f, -10f);
                    textMeshProButton.button.onClick.AddListener(delegate()
                    {
                        ClearButtonPressed?.Invoke();
                    });
                }
            }

            // destroy the existing "OK" button
            Destroy(this.transform.GetChild(28).gameObject);

            // create buttons for numbers and their respective symbols
            TextMeshProButton keyButtonPrefab = Resources.FindObjectsOfTypeAll <TextMeshProButton>().First(x => x.name == "KeyboardButton");

            string[] numSymbolArray = new string[]
            {
                "!", "@", "#", "$", "%", "^", "&", "*", "(", ")"
            };

            for (int i = 1; i <= 10; i++)
            {
                TextMeshProButton textButton = Instantiate(keyButtonPrefab);
                string            key        = i.ToString().Last().ToString();
                string            symbolKey  = numSymbolArray[i - 1];
                int index = (i % 10) + 26;

                _keyPairs[index].key    = key;
                _keyPairs[index].symKey = symbolKey;
                _keyPairs[index].button = textButton;

                textButton.text.text = key;
                textButton.button.onClick.AddListener(delegate()
                {
                    if (_symbolModeActive)
                    {
                        TextKeyPressed?.Invoke(symbolKey[0]);
                    }
                    else
                    {
                        TextKeyPressed?.Invoke(key[0]);
                    }
                });

                RectTransform buttonRect = textButton.GetComponent <RectTransform>();
                RectTransform component2 = this.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;
            }

            name = "EnhancedSearchKeyboard";
        }
Exemple #4
0
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (firstActivation)
            {
                _predictionBar = new GameObject("EnhancedSearchPredictionBar").AddComponent <PredictionBar>();
                _predictionBar.Initialize(this.transform, 4f, 19f, -50f, 50f);
                _predictionBar.PredictionPressed += delegate(string query)
                {
                    _searchText = query;
                    _textDisplayComponent.SetText(_searchText.ToUpper());

                    _predictionBar.ClearAndSetPredictionButtons(_searchText);

                    PredictionPressed?.Invoke(query);
                };

                var keyboardGO = Instantiate(Resources.FindObjectsOfTypeAll <UIKeyboard>().First(x => x.name != "CustomUIKeyboard"), this.rectTransform, false).gameObject;
                Destroy(keyboardGO.GetComponent <UIKeyboard>());
                _keyboard       = keyboardGO.AddComponent <SearchKeyboard>();
                keyboardGO.name = "EnhancedSearchKeyboard";

                _keyboard.TextKeyPressed += delegate(char key)
                {
                    _searchText += key.ToString();
                    _textDisplayComponent.text = _searchText.ToUpper();

                    _predictionBar.ClearAndSetPredictionButtons(_searchText);

                    TextKeyPressed?.Invoke(key);
                };
                _keyboard.DeleteButtonPressed += delegate
                {
                    if (_searchText.Length > 0)
                    {
                        _searchText = _searchText.Substring(0, _searchText.Length - 1);
                    }

                    if (_searchText.Length > 0)
                    {
                        _textDisplayComponent.text = _searchText.ToUpper();
                    }
                    else
                    {
                        _textDisplayComponent.text = PlaceholderText;
                    }

                    _predictionBar.ClearAndSetPredictionButtons(_searchText);

                    DeleteButtonPressed?.Invoke();
                };
                _keyboard.ClearButtonPressed += delegate
                {
                    _searchText = "";
                    _textDisplayComponent.text = PlaceholderText;

                    _predictionBar.ClearAndSetPredictionButtons(_searchText);

                    ClearButtonPressed?.Invoke();
                };

                _textDisplayComponent                    = BeatSaberUI.CreateText(this.rectTransform, "", new Vector2(0f, 28f), new Vector2(4f, 4f));
                _textDisplayComponent.fontSize           = 7.5f;
                _textDisplayComponent.alignment          = TextAlignmentOptions.Center;
                _textDisplayComponent.enableWordWrapping = false;
            }

            _searchText = "";
            _textDisplayComponent.text          = PlaceholderText;
            _keyboard.SymbolButtonInteractivity = !PluginConfig.StripSymbols;
            _keyboard.ResetSymbolMode();

            _predictionBar.ClearPredictionButtons();
        }
Exemple #5
0
 protected void InvokeClearButtonPressed() => ClearButtonPressed?.Invoke();
        public void Awake()
        {
            // clear all existing buttons
            int childCount = this.transform.childCount;

            for (int i = 0; i < childCount; ++i)
            {
                Destroy(this.transform.GetChild(i).gameObject);
            }

            _buttonPrefab = Resources.FindObjectsOfTypeAll <TextMeshProButton>().First(x => x.name == "KeyboardButton");

            // work under the assumption that the box we can draw on is of size 80u x 60u
            TextMeshProButton button;

            string[] keyArray = 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"
            };
            string[] symbolArray = new string[]
            {
                "[", "]", "{", "}", "\\", "|", "-", "_", "=", "+",
                "", "", "", "", "", ";", ":", "'", "\"",
                "", ",", ".", "<", ">", "/", "?"
            };
            for (int i = 0; i < keyArray.Length; ++i)
            {
                Vector2 anchoredPos;

                if (i < 10)
                {
                    anchoredPos = new Vector2(i * 8f, 29f);
                }
                else if (i < 19)
                {
                    anchoredPos = new Vector2((i - 10) * 8f + 4f, 21f);
                }
                else
                {
                    anchoredPos = new Vector2((i - 19) * 8f + 8f, 13f);
                }

                button = CreateKeyboardButton(anchoredPos);

                button.text.text = keyArray[i];

                string key    = keyArray[i];
                string symbol = symbolArray[i];

                _keyPairs[i].button = button;
                _keyPairs[i].key    = key;
                _keyPairs[i].symKey = symbol;

                button.button.onClick.AddListener(delegate()
                {
                    if (_symbolModeActive)
                    {
                        if (!string.IsNullOrEmpty(symbol))
                        {
                            TextKeyPressed?.Invoke(symbol[0]);
                        }
                    }
                    else
                    {
                        TextKeyPressed?.Invoke(key[0]);
                    }
                });
            }

            // Backspace
            button           = CreateKeyboardButton(new Vector2(64f, 13f), new Vector2(15f, 7f));
            button.text.text = "<-";
            button.button.onClick.AddListener(delegate()
            {
                DeleteButtonPressed?.Invoke();
            });

            // Space bar
            button           = CreateKeyboardButton(new Vector2(16f, 5f), new Vector2(47f, 7f));
            button.text.text = "Space";
            button.button.onClick.AddListener(delegate()
            {
                TextKeyPressed?.Invoke(' ');
            });

            // Symbols
            _symbolButton               = CreateKeyboardButton(new Vector2(0f, 5f), new Vector2(15f, 7f));
            _symbolButton.text.text     = "Symbols";
            _symbolButton.text.fontSize = 3f;
            _symbolButton.button.onClick.AddListener(delegate()
            {
                SetSymbolMode(!_symbolModeActive);
            });

            // Clear
            button           = CreateKeyboardButton(new Vector2(64f, 5f), new Vector2(15f, 7f));
            button.text.text = "Clear";
            button.button.onClick.AddListener(delegate()
            {
                ClearButtonPressed?.Invoke();
            });

            // Numbers
            string[] numSymbolArray = new string[]
            {
                "!", "@", "#", "$", "%", "^", "&", "*", "(", ")"
            };
            for (int i = 1; i <= 10; ++i)
            {
                button = CreateKeyboardButton(new Vector2((i - 1) * 8f, 37f));

                string key    = i.ToString().Last().ToString();
                string symbol = numSymbolArray[i - 1];
                int    index  = (i % 10) + 26;

                _keyPairs[index].key    = key;
                _keyPairs[index].symKey = symbol;
                _keyPairs[index].button = button;

                button.text.text = key;
                button.button.onClick.AddListener(delegate()
                {
                    if (_symbolModeActive)
                    {
                        TextKeyPressed?.Invoke(symbol[0]);
                    }
                    else
                    {
                        TextKeyPressed?.Invoke(key[0]);
                    }
                });
            }
        }
Exemple #7
0
 private void OnClearButtonClicked()
 {
     _clearButton.GetComponentInChildren <TextMeshProUGUI>().color = Color.white;
     ClearButtonPressed?.Invoke();
 }