public override void HandleInput(IReadOnlyList <int> lastKeysPressed)
        {
            if (Input.IsKeyDown(InputKey.LeftControl) && Input.IsKeyPressed(InputKey.V))
            {
                base.HandleInput(lastKeysPressed);
                return;
            }

            if (lastKeysPressed.Count > 0)
            {
                foreach (var key in lastKeysPressed)
                {
                    if (SettingType == SettingType.String)
                    {
                        base.HandleInput(lastKeysPressed);
                    }
                    else if (Enum.IsDefined(typeof(KeyCodes), key))
                    {
                        if (key == (int)KeyCodes.Minus)
                        {
                            if (_editableWidget?.SelectedTextBegin != 0)
                            {
                                continue;
                            }
                        }
                        else if (SettingType == SettingType.Float)
                        {
                            // Handle input for float types
                            if (key == (int)KeyCodes.Decimal)
                            {
                                if (RealText.Any(ch => ch == '.'))
                                {
                                    continue;
                                }
                            }
                        }
                        else if (SettingType == SettingType.Int)
                        {
                            // Handle input for int types.
                            if (key == (int)KeyCodes.Decimal)
                            {
                                continue;
                            }
                        }
                        base.HandleInput(lastKeysPressed);

                        if (SettingType == SettingType.Float)
                        {
                            if (float.TryParse(RealText, out var value))
                            {
                                var newVal = value;
                                if (value > MaxValue)
                                {
                                    newVal = MaxValue;
                                }
                                else if (value < MinValue)
                                {
                                    newVal = MinValue;
                                }
                                if (newVal != value)
                                {
                                    var format = SettingType == SettingType.Int ? "0" : "0.00";
                                    RealText = newVal.ToString(format);
                                    _editableWidget?.SetCursorPosition(0, true);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                base.HandleInput(lastKeysPressed);
            }
        }
Ejemplo n.º 2
0
        public override void HandleInput(IReadOnlyList <int> lastKeysPressed)
        {
            if (Input.IsKeyDown(InputKey.LeftControl) && Input.IsKeyPressed(InputKey.V))
            {
                return;
            }
            if (lastKeysPressed == null)
            {
                return;
            }

            if (lastKeysPressed.Count > 0)
            {
                for (int i = 0; i < lastKeysPressed.Count; i++)
                {
                    int key = lastKeysPressed[i];
                    if (Enum.IsDefined(typeof(KeyCodes), key))
                    {
                        if (key == (int)KeyCodes.Minus)
                        {
                            if (editableText.SelectedTextBegin != 0)
                            {
                                continue;
                            }
                        }
                        else if (SettingType == SettingType.Float)
                        {
                            //Handle input for float types
                            if (key == (int)KeyCodes.Decimal)
                            {
                                if (RealText.Count('.') >= 1)
                                {
                                    continue;
                                }
                            }
                        }
                        else if (SettingType == SettingType.Int)
                        {
                            //Handle input for int types.
                            if (key == (int)KeyCodes.Decimal)
                            {
                                continue;
                            }
                        }
                        base.HandleInput(lastKeysPressed);
                        float value;
                        if (float.TryParse(RealText, out value))
                        {
                            float newVal = value;
                            if (value > MaxValue)
                            {
                                newVal = MaxValue;
                            }
                            else if (value < MinValue)
                            {
                                newVal = MinValue;
                            }
                            if (newVal != value)
                            {
                                string format = SettingType == SettingType.Int ? "0" : "0.00";
                                RealText = newVal.ToString(format);
                                editableText.SetCursorPosition(0, true);
                            }
                        }
                    }
                }
            }
            else
            {
                base.HandleInput(lastKeysPressed);
            }
        }