Ejemplo n.º 1
0
        public override void HandleInput(InputManager input)
        {
            base.HandleInput(input);

            Vector2f      mousePos;
            bool          mouse  = input.GetMousePosition(out mousePos);
            Vector2i      origin = new Vector2i(0, 0);
            MenuComponent bubble = parent;

            while (bubble != null)
            {
                origin += bubble.position;
                bubble  = bubble.parent;
            }
            bool collided = BoundingBox.CheckPointMenuCollision(mousePos.X, mousePos.Y, collisionBox, new Vector2f((position + origin).X, (origin + position).Y));

            if (mouse && (fieldState == FieldState.Normal || fieldState == FieldState.Modified) && collided && input.GetMouseClicked(InputBindings.primary, true))
            {
                fieldState = FieldState.Focused;
            }
            if (fieldState == FieldState.Focused)
            {
                string updated;
                if (input.GetKeyPressed(InputBindings.backSpace, true))
                {
                    if (fieldValue.Length > 1)
                    {
                        fieldValue = fieldValue.Substring(0, fieldValue.Length - 1);
                        parseField(tag, fieldValue, out updated);
                        textField.SetText(updated);
                        fieldValue = updated;
                    }
                    else
                    {
                        fieldValue = "";
                        parseField(tag, fieldValue, out updated);
                        textField.SetText(fieldValue);
                        fieldValue = updated;
                    }
                }
                else
                {
                    string inputString = input.GetKeyString(true);
                    fieldValue = fieldValue + inputString;
                    if (inputString != "")
                    {
                        bool success = parseField.Invoke(tag, fieldValue, out updated);
                        textField.SetText(updated);
                        fieldValue = updated;
                    }
                }
            }
            if (fieldState == FieldState.Focused && !collided && input.GetMouseClickedIgnoreConsume(InputBindings.primary))
            {
                fieldState = FieldState.Modified;
            }
        }