예제 #1
0
        internal static void InitRequirementsMenu()
        {
            reqDialog         = BeatSaberUI.CreateCustomMenu <CustomMenu>("Additional Song Information");
            reqViewController = BeatSaberUI.CreateViewController <CustomListViewController>();
            RectTransform confirmContainer = new GameObject("CustomListContainer", typeof(RectTransform)).transform as RectTransform;

            confirmContainer.SetParent(reqViewController.rectTransform, false);
            confirmContainer.sizeDelta = new Vector2(60f, 0f);
            GetIcons();
            reqDialog.SetMainViewController(reqViewController, true);
        }
예제 #2
0
        /// <summary>
        /// Display a keyboard interface to accept user input.
        /// </summary>
        /// <param name="title">The title to be displayed above the keyboard.</param>
        /// <param name="initialValue">The starting value of the keyboard.</param>
        /// <param name="TextChangedEvent">Callback when the text is modified by the user (when any key is pressed basically).</param>
        /// <param name="TextEntrySuccessEvent">Callback when the user successfully submits the changed text.</param>
        /// <param name="TextEntryCancelledEvent">Callback when the user presses the cancel button.</param>
        /// <returns></returns>
        public static bool DisplayKeyboard(string title, string initialValue, Action <string> TextChangedEvent = null, Action <string> TextEntrySuccessEvent = null, Action TextEntryCancelledEvent = null)
        {
            if (_isKeyboardOpen)
            {
                return(false);
            }

            if (_keyboardMenu == null)
            {
                _keyboardMenu = CreateCustomMenu <CustomMenu>(title);
                var mainViewController = CreateViewController <CustomViewController>();
                _keyboardMenu.SetMainViewController(mainViewController, false, (firstActivation, type) =>
                {
                    if (firstActivation)
                    {
                        var _customKeyboardGO = Instantiate(Resources.FindObjectsOfTypeAll <UIKeyboard>().First(x => x.name != "CustomUIKeyboard"), mainViewController.rectTransform, false).gameObject;
                        Destroy(_customKeyboardGO.GetComponent <UIKeyboard>());
                        _keyboard = _customKeyboardGO.AddComponent <CustomUIKeyboard>();

                        _inputText           = CreateText(mainViewController.rectTransform, String.Empty, new Vector2(0f, 22f));
                        _inputText.alignment = TextAlignmentOptions.Center;
                        _inputText.fontSize  = 6f;

                        _keyboard.okButtonWasPressedEvent += () =>
                        {
                            _textEntrySuccessEvent?.Invoke(_inputText.text);
                            _inputText.text = String.Empty;
                            _keyboard.OkButtonInteractivity = false;
                            _keyboardMenu.Dismiss();
                            _isKeyboardOpen = false;
                        };
                        _keyboard.cancelButtonWasPressedEvent += () =>
                        {
                            _textEntryCancelledEvent?.Invoke();
                            _inputText.text = String.Empty;
                            _keyboard.OkButtonInteractivity = false;
                            _keyboardMenu.Dismiss();
                            _isKeyboardOpen = false;
                        };
                        _keyboard.textKeyWasPressedEvent += (key) =>
                        {
                            _inputText.text += key;
                            _textChangedEvent?.Invoke(_inputText.text);

                            if (_inputText.text.Length > 0)
                            {
                                _keyboard.OkButtonInteractivity = true;
                            }
                        };
                        _keyboard.deleteButtonWasPressedEvent += () =>
                        {
                            if (_inputText.text.Length > 0)
                            {
                                _inputText.text = _inputText.text.Substring(0, _inputText.text.Length - 1);
                                _textChangedEvent?.Invoke(_inputText.text);
                            }
                            if (_inputText.text.Length == 0)
                            {
                                _keyboard.OkButtonInteractivity = false;
                            }
                        };
                    }
                    _inputText.text = _initialValue;
                    _keyboard.OkButtonInteractivity = _inputText.text.Length > 0;
                });
            }
            _keyboardMenu.title      = title == null ? String.Empty : title;
            _initialValue            = initialValue == null ? String.Empty : initialValue;
            _textChangedEvent        = TextChangedEvent;
            _textEntrySuccessEvent   = TextEntrySuccessEvent;
            _textEntryCancelledEvent = TextEntryCancelledEvent;

            if (!_keyboardMenu.Present(false))
            {
                return(false);
            }

            _isKeyboardOpen = true;
            return(true);
        }