Пример #1
0
        private void ScreenFlash_Loaded(object sender, RoutedEventArgs e)
        {
            var grid = Parent as Panel;

            while (grid is not Grid)
            {
                grid = (Panel)grid.Parent;
            }

            var rect = new Rectangle();

            rect.Fill             = new SolidColorBrush(Colors.White);
            rect.Opacity          = strength;
            rect.IsHitTestVisible = false;
            Panel.SetZIndex(rect, 1);

            grid.Children.Add(rect);

            Add(Lerp.Time(strength, 0, Duration, t => rect.Opacity = t).Then(() =>
            {
                grid.Children.Remove(rect);
                OnCompleted();
                Destroy();
            }));
        }
Пример #2
0
        public UserControl Overlay(UserControl screen)
        {
            screen.Opacity = 0;
            Add(Lerp.Time(0, 1, TRANSITION_DURATION, t => screen.Opacity = t));
            Add(screen);

            return(screen);
        }
Пример #3
0
        private void ScreenShake_Loaded(object sender, RoutedEventArgs e)
        {
            var parent = Parent as Panel;

            Add(Lerp.Time(strength, 0, duration, t =>
            {
                Matrix matrix = parent.RenderTransform.Value;
                matrix.TranslatePrepend(-shakeOffset.X, -shakeOffset.Y);
                shakeOffset = new Vector(Random(-1, 1), Random(-1, 1)) * (double)t;
                matrix.TranslatePrepend(shakeOffset.X, shakeOffset.Y);
                parent.RenderTransform = new MatrixTransform(matrix);
            }).Then(() =>
            {
                OnCompleted();
                Destroy();
            }));
        }
Пример #4
0
        public UserControl Switch(UserControl screen)
        {
            var lastScreen = CurrentScreen;

            CurrentScreen  = screen;
            screen.Opacity = 0;

            var animation =
                Lerp.Time(0, 1, TRANSITION_DURATION, t => screen.Opacity     = t) *
                Lerp.Time(1, 0, TRANSITION_DURATION, t => lastScreen.Opacity = t) +
                (() => Remove(lastScreen));

            Add(screen);
            Add(animation);

            InvalidateMeasure();

            return(screen);
        }
Пример #5
0
        public event Action <Vector, double> Payload; //is passed position and radius

        public Explosion(Vector position, double radius, double duration)
        {
            circle      = new Ellipse();
            circle.Fill = new SolidColorBrush(Colors.White);

            Position = position;

            var animation =
                // Expand
                Lerp.Time(0, radius, duration, r =>
            {
                Radius        = r;
                circle.Width  = r * 2;
                circle.Height = r * 2;
                Canvas.SetLeft(circle, position.X - r + Random(-1, 1) * SHAKE_FACTOR);
                Canvas.SetTop(circle, position.Y - r + Random(-1, 1) * SHAKE_FACTOR);
                Exploding?.Invoke(Position, Radius);
            }, Lerp.CubeRoot)

                // Contract
                + Lerp.Time(radius, 0, duration, r =>
            {
                Radius        = r;
                circle.Width  = r * 2;
                circle.Height = r * 2;
                Canvas.SetLeft(circle, position.X - r + Random(-1, 1) * SHAKE_FACTOR);
                Canvas.SetTop(circle, position.Y - r + Random(-1, 1) * SHAKE_FACTOR);
                Exploding?.Invoke(Position, Radius);
            })

                // Fade
                * Lerp.Time(1, 0, duration + FADE_DURATION, o => circle.Opacity = o)

                // Destroy
                + (() => this.Destroy());

            Add(animation);
            Add(circle);
            AddToParent(new ScreenFlash(0.1, 0.5));
        }
Пример #6
0
 public void CloseOverlay(UserControl screen)
 {
     Add(Lerp.Time(1, 0, TRANSITION_DURATION, t => screen.Opacity = t).Then(() => Remove(screen)));
 }