Ejemplo n.º 1
0
        public override void Update()
        {
            switch (DisplayState)
            {
            case DisplayState.Opening:
                if (Transform.Scale.X >= 1f || Transform.Scale.Y >= 1f)
                {
                    DisplayState = DisplayState.Opened;
                }
                Transform.Scale += new Vector2(.05f);
                break;

            case DisplayState.Opened:
                var origin = Transform.Position;
                if (Text.Centered)
                {
                    origin -= (Bounds.Size.ToVector2() * .5f);
                }
                if (new Rectangle(origin.ToPoint(), Bounds.Size).Contains(Data.MousePosition))
                {
                    if (Transform.Scale == Vector2.One)
                    {
                        ButtonState = UI_ButtonState.Hovering;
                    }

                    if (_buttonPress.Pressed())
                    {
                        _hasBeenPressed = true;
                        ButtonState     = UI_ButtonState.Pressed;
                    }
                    else if (_buttonPress.Held() && _hasBeenPressed)
                    {
                        ButtonState = UI_ButtonState.Down;
                    }
                    else if (_buttonPress.Released() && _hasBeenPressed)
                    {
                        ButtonState = UI_ButtonState.Released;
                        _callBack.Invoke();
                    }
                }
                else
                {
                    ButtonState = UI_ButtonState.Idle;
                }

                switch (ButtonState)
                {
                case UI_ButtonState.Idle:
                    Text.Colour     = Color.Lerp(Text.Colour, IdleTextColour, .25f);
                    Transform.Scale = Vector2.Lerp(Transform.Scale, Vector2.One, .5f);

                    if (Transform.Scale.X >= .95 && Transform.Scale.Y >= .95 && Transform.Scale.X <= 1.05f && Transform.Scale.Y <= 1.05f)
                    {
                        Transform.Scale = Vector2.One;
                    }

                    _tick = 0f;
                    break;

                case UI_ButtonState.Hovering:
                    Text.Colour     = Color.Lerp(Text.Colour, HoveringTextColour, .25f);
                    Transform.Scale = Vector2.Lerp(Transform.Scale, new Vector2(1.25f) - new Vector2(MathF.Sin(_tick)) * .05f, .25f);
                    _tick          += .1f;
                    break;

                case UI_ButtonState.Down:
                    Text.Colour     = Color.Lerp(Text.Colour, PressedTextColour, .5f);
                    Transform.Scale = Vector2.Lerp(Transform.Scale, Vector2.One, .5f);
                    break;

                case UI_ButtonState.Released:
                    Transform.Scale = new Vector2(1.25f);
                    ButtonState     = UI_ButtonState.Hovering;
                    break;
                }
                break;

            case DisplayState.Closing:
                Transform.Scale = Vector2.Lerp(Transform.Scale, new Vector2(.75f), .1f);
                Text.Colour.A   = (byte)MathHelper.Lerp(Text.Colour.A, 0f, .1f);

                if (Text.Colour.A == 0)
                {
                    DisplayState = DisplayState.Closed;
                }
                break;

            case DisplayState.Closed:
                break;
            }
        }