Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://github.com/andruzzzhka/BeatSaverDownloader/blob/master/BeatSaverDownloader/PluginUI/ViewControllers/SearchKeyboardViewController.cs
- class KeyboardViewController : HMUI.ViewController
- {
- GameObject keyboardGO;
- CustomUIKeyboard keyboard;
- TextMeshProUGUI _inputText;
- public string _inputString = "";
- public event Action<string> confirmPressed;
- public event Action cancelPressed;
- protected override void DidActivate(bool firstActivation, ActivationType type)
- {
- if (type == ActivationType.AddedToHierarchy && firstActivation)
- {
- var kb = Resources.FindObjectsOfTypeAll<UIKeyboard>().First(x => x.name != "CustomUIKeyboard");
- Logger.log.Debug("Found UIKeyboard object: " + kb);
- keyboardGO = Instantiate(kb, rectTransform, false).gameObject;
- Destroy(keyboardGO.GetComponent<UIKeyboard>());
- keyboard = keyboardGO.AddComponent<CustomUIKeyboard>();
- keyboard.textKeyWasPressedEvent += delegate (char input) { _inputString += input; UpdateInputText(); };
- keyboard.deleteButtonWasPressedEvent += delegate () { _inputString = _inputString.Substring(0, _inputString.Length - 1); UpdateInputText(); };
- keyboard.cancelButtonWasPressedEvent += () => { cancelPressed?.Invoke(); };
- keyboard.okButtonWasPressedEvent += () => { confirmPressed?.Invoke(_inputString); };
- _inputText = BeatSaberMarkupLanguage.BeatSaberUI.CreateText(rectTransform, "Enter PIN...", 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) || _inputString.Length <= 5)
- {
- keyboard.OkButtonInteractivity = false;
- }
- else
- {
- keyboard.OkButtonInteractivity = true;
- }
- }
- }
- void ClearInput()
- {
- _inputString = "";
- }
- void Back()
- {
- _inputString = "";
- cancelPressed?.Invoke();
- }
- }
Add Comment
Please, Sign In to add comment