<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:ForzaUI"
    mc:Ignorable="d"
    x:Class="ForzaUI.HUDPressButtonControl"
    Margin="0,0,0,14"
    VerticalAlignment="Bottom"
    HorizontalAlignment="Center"
    x:Name="UserControl">

    <UserControl.Resources>
        <ExponentialEase x:Key="A_EasingFunction_EaseIn" EasingMode="EaseIn"/>
        <CircleEase x:Key="A_EasingFunction_EaseOut" EasingMode="EaseOut"/>
        <CircleEase x:Key="A_EasingFunction_EaseInOut" EasingMode="EaseInOut"/>
        <Style x:Key="A_Style_FZMaterial_ButtonShine"
               TargetType="local:FZMaterial">
            <Setter Property="Width"
                    Value="48" />
            <Setter Property="Height"
                    Value="48" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsControllerActiveInput, RelativeSource={RelativeSource AncestorType=Page}}"
                             Value="False" >
                    <Setter Property="Width"
                        Value="40" />
                    <Setter Property="Height"
                            Value="40" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="A_Style_FrameworkElement_CollapseIfButtonTextureNull"
               TargetType="FrameworkElement">
            <Style.Triggers>
                <DataTrigger Binding="{Binding SilhouetteTexture}"
                             Value="{x:Null}" >
                    <Setter Property="Visibility"
                        Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_FrameworkElement_CollapseIfButtonTextureNull_KeyboardOnly"
               TargetType="FrameworkElement" BasedOn="{StaticResource A_Style_FrameworkElement_CollapseIfButtonTextureNull}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsControllerActiveInput, RelativeSource={RelativeSource AncestorType=Page}}" Value="{StaticResource A_Boolean_True}" >
                    <Setter Property="Visibility" Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="{x:Type FrameworkElement}"
               x:Key="A_Style_FrameworkElement_PressButtonPromptFormat">
            <Setter Property="local:MultiStringFormatter.Param0" Value="{Binding LeftText}"/>
            <Setter Property="local:MultiStringFormatter.Param1" Value="{Binding ScreenReaderName, ElementName=ButtonControl}"/>
            <Setter Property="local:MultiStringFormatter.Param2" Value="{Binding RightText}"/>
            <Setter Property="local:MultiStringFormatter.Format" Value="{local:Loc Main.IDS_ScreenReader_ButtonPrompt_Format}"/>
            <Setter Property="local:ScreenReader.LineType" Value="NotificationPrompt"/>
            <Setter Property="local:ScreenReader.Event" Value="OnChange"/>
            <Setter Property="local:ManualPassthroughProperty.Input" Value="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}"/>
            <Setter Property="local:ManualPassthroughProperty.Allowed" Value="True"/>
            <Setter Property="local:ScreenReader.Line" Value="{Binding (local:ManualPassthroughProperty.Output), RelativeSource={RelativeSource Self}}"/>
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding IsControllerActiveInput, RelativeSource={RelativeSource AncestorType=Page}}" Value="{StaticResource A_Boolean_False}" />
                        <Condition Binding="{Binding IsKeyboardLinear, ElementName=ButtonControl}" Value="True"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="local:MultiStringFormatter.Param1" Value="{Binding ScreenReaderName, ElementName=ButtonControl_High}"/>
                </MultiDataTrigger>

                <DataTrigger Binding="{Binding LeftText}" Value="{x:Null}">
                    <Setter Property="local:MultiStringFormatter.Param0" Value="{local:Loc Main.IDS_ScreenReader_EmptyString}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding SilhouetteTexture}" Value="{x:Null}">
                    <Setter Property="local:MultiStringFormatter.Param1" Value="{local:Loc Main.IDS_ScreenReader_EmptyString}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding RightText}" Value="{x:Null}">
                    <Setter Property="local:MultiStringFormatter.Param2" Value="{local:Loc Main.IDS_ScreenReader_EmptyString}"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Opacity, ElementName=LayoutRoot}" Value="0">
                    <Setter Property="local:ManualPassthroughProperty.Allowed" Value="False"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>

    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" ClipToBounds="True" Height="100">
        
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="Hide">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="LayoutRoot">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="LayoutRoot">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="{x:Static Visibility.Collapsed}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ButtonIconShine">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ButtonIconShine_High">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>

                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="DisplayPanel">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.9"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="DisplayPanel">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.9"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Show">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="DisplayPanel">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="-100"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0" EasingFunction="{StaticResource A_EasingFunction_EaseOut}"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="ButtonIconContainer">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="1.2"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:1.8" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="ButtonIconContainer">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="1.2"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:1.8" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>

                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="ButtonIconContainer_LinearHigh">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="1.2"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:1.8" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="ButtonIconContainer_LinearHigh">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="1.2"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:1.8" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>

                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ButtonIconShine">
                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.0" Value="0"/>
                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                        <SingleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(FadeInStart)" Storyboard.TargetName="ButtonIconShine">
                            <EasingSingleKeyFrame KeyTime="0:0:0.0" Value="-0.25"/>
                            <EasingSingleKeyFrame KeyTime="0:0:1.4" Value="1" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                        </SingleAnimationUsingKeyFrames>
                        <SingleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(FadeInEnd)" Storyboard.TargetName="ButtonIconShine">
                            <EasingSingleKeyFrame KeyTime="0:0:0.0" Value="-0.14"/>
                            <EasingSingleKeyFrame KeyTime="0:0:1.4" Value="1.11" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                        </SingleAnimationUsingKeyFrames>
                        <SingleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(FadeOutStart)" Storyboard.TargetName="ButtonIconShine">
                            <EasingSingleKeyFrame KeyTime="0:0:0.0" Value="0"/>
                            <EasingSingleKeyFrame KeyTime="0:0:1.4" Value="1.25" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                        </SingleAnimationUsingKeyFrames>
                        <SingleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(FadeOutEnd)" Storyboard.TargetName="ButtonIconShine">
                            <EasingSingleKeyFrame KeyTime="0:0:0.0" Value="0.11"/>
                            <EasingSingleKeyFrame KeyTime="0:0:1.4" Value="1.36" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                        </SingleAnimationUsingKeyFrames>

                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ButtonIconShine_High">
                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.0" Value="0"/>
                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                        <SingleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(FadeInStart)" Storyboard.TargetName="ButtonIconShine_High">
                            <EasingSingleKeyFrame KeyTime="0:0:0.0" Value="-0.25"/>
                            <EasingSingleKeyFrame KeyTime="0:0:1.4" Value="1" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                        </SingleAnimationUsingKeyFrames>
                        <SingleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(FadeInEnd)" Storyboard.TargetName="ButtonIconShine_High">
                            <EasingSingleKeyFrame KeyTime="0:0:0.0" Value="-0.14"/>
                            <EasingSingleKeyFrame KeyTime="0:0:1.4" Value="1.11" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                        </SingleAnimationUsingKeyFrames>
                        <SingleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(FadeOutStart)" Storyboard.TargetName="ButtonIconShine_High">
                            <EasingSingleKeyFrame KeyTime="0:0:0.0" Value="0"/>
                            <EasingSingleKeyFrame KeyTime="0:0:1.4" Value="1.25" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                        </SingleAnimationUsingKeyFrames>
                        <SingleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(FadeOutEnd)" Storyboard.TargetName="ButtonIconShine_High">
                            <EasingSingleKeyFrame KeyTime="0:0:0.0" Value="0.11"/>
                            <EasingSingleKeyFrame KeyTime="0:0:1.4" Value="1.36" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                        </SingleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <StackPanel x:Name="DisplayPanel" Orientation="Horizontal" RenderTransformOrigin="0.5,0.5">
            
            <StackPanel.RenderTransform>
                <TransformGroup>
                    <ScaleTransform />
                    <SkewTransform />
                    <RotateTransform />
                    <TranslateTransform />
                </TransformGroup>
            </StackPanel.RenderTransform>

            <Decorator Style="{StaticResource A_Style_FrameworkElement_CollapseIfButtonTextureNull}">
                <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_HudMedium}" Text="{Binding LeftText}" VerticalAlignment="Center" Color="{StaticResource A_Color_HUD_Text_NoBackground}" CapHeight="28"/>
            </Decorator>
            <Grid x:Name="ButtonIconContainer" Style="{StaticResource A_Style_FrameworkElement_CollapseIfButtonTextureNull}" RenderTransformOrigin="0.5,0.5" Opacity="1">
            
                <Grid.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform />
                        <SkewTransform />
                        <RotateTransform />
                        <TranslateTransform />
                    </TransformGroup>
                </Grid.RenderTransform>

                <Grid Margin="10,0,0,0">
                    <local:ControllerButtonControl AllowMouseClick="False"
                                                   UseLargeIcon="True"
                                                   MinWidth="42"
                                                   Height="42"
                                                   InputOverride="{Binding Input}"
                                                   RenderTransformOrigin="0.5,0.5"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center"
                                                   Visibility="Visible"
                                                   x:Name="ButtonControl"/>
                    <local:FZMaterial x:Name="ButtonIconShine"
                                      Style="{StaticResource A_Style_FZMaterial_ButtonShine}"
                                      HorizontalAlignment="Center" 
                                      VerticalAlignment="Center"
                                      Opacity="0"
                                      Width="{Binding ActualWidth, ElementName=ButtonControl}"
                                      Height="{Binding ActualWidth, ElementName=ButtonControl}"
                                      RenderTransformOrigin="0.5,0.5">
                        <local:FZMaterial.Effect>
                            <local:TextureMaskEffect>
                                <local:TextureMaskEffect.Texture>
                                    <ImageBrush ImageSource="{Binding SilhouetteTexture}" />
                                </local:TextureMaskEffect.Texture>
                                <local:TextureMaskEffect.Mask>
                                    <ImageBrush ImageSource="/ForzaUI;component/Textures/Anthem/TextureMaskGradients/Diagonal_Gradient.png" />
                                </local:TextureMaskEffect.Mask>
                            </local:TextureMaskEffect>
                        </local:FZMaterial.Effect>
                    </local:FZMaterial>
                </Grid>
            </Grid>
            <Grid x:Name="ButtonIconContainer_LinearHigh" Style="{StaticResource A_Style_FrameworkElement_CollapseIfButtonTextureNull_KeyboardOnly}" 
                  RenderTransformOrigin="0.5,0.5" Opacity="1">

                <Grid.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform />
                        <SkewTransform />
                        <RotateTransform />
                        <TranslateTransform />
                    </TransformGroup>
                </Grid.RenderTransform>

                <Grid Margin="2,0,0,0" Visibility="{Binding IsKeyboardLinear, ElementName=ButtonControl, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}">
                    <local:ControllerButtonControl AllowMouseClick="False"
                                                   UseLargeIcon="True"
                                                   MinWidth="42"
                                                   Height="42"
                                                   InputOverride="{Binding Input}"
                                                   RenderTransformOrigin="0.5,0.5"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center"
                                                   Visibility="Visible"
                                                   UseHighKeyIfLinearCommand="True"
                                                   x:Name="ButtonControl_High"/>
                    <local:FZMaterial x:Name="ButtonIconShine_High"
                                      Style="{StaticResource A_Style_FZMaterial_ButtonShine}"
                                      HorizontalAlignment="Center" 
                                      VerticalAlignment="Center"
                                      Opacity="0"
                                      Width="{Binding ActualWidth, ElementName=ButtonControl}"
                                      Height="{Binding ActualWidth, ElementName=ButtonControl}"
                                      RenderTransformOrigin="0.5,0.5">
                        <local:FZMaterial.Effect>
                            <local:TextureMaskEffect>
                                <local:TextureMaskEffect.Texture>
                                    <ImageBrush ImageSource="{Binding SilhouetteTexture}" />
                                </local:TextureMaskEffect.Texture>
                                <local:TextureMaskEffect.Mask>
                                    <ImageBrush ImageSource="/ForzaUI;component/Textures/Anthem/TextureMaskGradients/Diagonal_Gradient.png" />
                                </local:TextureMaskEffect.Mask>
                            </local:TextureMaskEffect>
                        </local:FZMaterial.Effect>
                    </local:FZMaterial>
                </Grid>
            </Grid>

            <local:FZTextBlock Margin="10,0,0,0" Style="{StaticResource A_Style_FZTextBlock_HudMedium}" Text="{Binding RightText}" VerticalAlignment="Center" Color="{StaticResource A_Color_HUD_Text_NoBackground}" CapHeight="28"/>

            <FrameworkElement Style="{StaticResource A_Style_FrameworkElement_PressButtonPromptFormat}"/>
        </StackPanel>
    </Grid>
</UserControl>