using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace CPSC581___Tutorial_I
{
    /// <summary>
    /// Interaction logic for WASDKeyboard.xaml
    /// </summary>
    public partial class WASDKeyboard : UserControl
    {
        public event EventHandler<WASDEventArgs> OnWASDSelected;

        public WASDKeyboard()
        {
            InitializeComponent();
        }


        //This is a better method of handling the click event (BUT NOT THE BEST!)
        //In this version, we assume that whatever is clicked is a button (done with the cast)
        //and then pass the content to WASDEventArgs
        private void wasdButton_Click(object sender, RoutedEventArgs e)
        {
            //If the P button is selected, send the event and the number in the textbox 
            if ((sender as Button).Content.Equals("P"))
                try
                {
                    //Convert.ToInt32 converts the number in the textbox to an int
                    OnWASDSelected(this, new WASDEventArgs((sender as Button).Content as String, Convert.ToInt32(numTextBox.Text)));
                }
                    //The exception is for the cases where either nothing is entered or an invalid number (ie: text) is entered
                    //in the textbox
                catch (Exception)
                {
                    MessageBox.Show("Enter a number only!");
                }
            else
                //For other buttons, send the button clicked and pass the value of 0
                OnWASDSelected(this, new WASDEventArgs((sender as Button).Content as String, 0));
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            //Create a new animation, that will have a value go from 0 to 35
            //This type of animation is typically used for animations where a double value is changed (such as height/width or size)
            DoubleAnimation da = new DoubleAnimation();
            da.From = 0;
            da.To = 35;

            //Make the animation last 1 second
            da.Duration = new Duration(TimeSpan.FromSeconds(1));


            //Create a new animation, that will have a value go from 0 to 1
            DoubleAnimation da2 = new DoubleAnimation();
            da2.From = 0;
            da2.To = 1;

            //Make the animation last 1 second
            da2.Duration = new Duration(TimeSpan.FromSeconds(5));

            //Create a color animation, where a color of an object will go from hot pink to blue
            ColorAnimation colorAnimation = new ColorAnimation();
            colorAnimation.From = Colors.HotPink;
            colorAnimation.To = Colors.Blue;

            //Make the animation last 3 seconds
            colorAnimation.Duration = new Duration(TimeSpan.FromSeconds(3));


            //Create a new storyboard that will contain all the animations
            Storyboard animationStoryBoard = new Storyboard();

            //Set the color animation to happen to the S button
            Storyboard.SetTarget(colorAnimation, sButton);

            //For the color animation, we are trying to animate the text color, which is set by button.foreground
            //Thus, we must set the color animation to animate a Button's foreground property and set its color
            Storyboard.SetTargetProperty(colorAnimation, new PropertyPath("(Button.Foreground).(SolidColorBrush.Color)"));

            //Add the color animation to the storyboard
            animationStoryBoard.Children.Add(colorAnimation);

            //Much like the color animation, we want to set the animation to happen to a button, in this case, the wButton
            Storyboard.SetTarget(da, wButton);

            //Now, as we want the height of the button to expand, we can assign the double animation to happen to the
            //Height property of a button
            Storyboard.SetTargetProperty(da, new PropertyPath("(Button.Height)"));

            //Then addd the height animation to the storyboard
            animationStoryBoard.Children.Add(da);

            //Much like the above animation, we want to set the animation to happen to a button, in this case, the dButton
            Storyboard.SetTarget(da2, dButton);

            //Now, as we want the button to "magically" appear, we can assign the double animation to happen to the
            //Opacity property of a button
            Storyboard.SetTargetProperty(da2, new PropertyPath("(Button.Opacity)"));

            //Then add the opacity animation to the storyboard
            animationStoryBoard.Children.Add(da2);

            //Once all the animations are added to the storyboard, you can begin animating
            animationStoryBoard.Begin();
  
        }
    }
}
