<Page xmlns:local="clr-namespace:ForzaUI"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      x:Class="ForzaUI.A_PostRaceFinishPositionPanel"
      mc:Ignorable="d"
      DataContext="{Binding RelativeSource={RelativeSource Self}}"
      Width="1920"
      Height="540"
      ClipToBounds="True">
    
    <Page.Resources>
        <local:OffsetKeyTime x:Key="A_KeyTime_Begin"
                             KeyTime="0:0:0" />

        <local:OffsetKeyTime x:Key="A_KeyTime_PlayVideo"
                             KeyTime="{StaticResource A_KeyTime_Begin}" />

        <local:OffsetKeyTime x:Key="A_KeyTime_Gamertag_In_Begin"
                             KeyTime="{StaticResource A_KeyTime_Begin}" />
        <local:OffsetKeyTime x:Key="A_KeyTime_Finished_In_Begin"
                             KeyTime="{StaticResource A_KeyTime_Gamertag_In_Begin}" />
        
        <System:TimeSpan x:Key="A_TimeSpan_FinishDuration">0:0:1.7</System:TimeSpan>
        <System:TimeSpan x:Key="A_TimeSpan_PositionDuration">0:0:2</System:TimeSpan>
        
        <local:OffsetKeyTime x:Key="A_KeyTime_Gamertag_Transition_Begin"
                             KeyTime="{StaticResource A_KeyTime_Begin}"
                             Offset="{StaticResource A_TimeSpan_FinishDuration}"/>

        <local:OffsetKeyTime x:Key="A_KeyTime_Finished_Out_Begin"
                             KeyTime="{StaticResource A_KeyTime_Gamertag_Transition_Begin}"
                             Offset="0:0:0" />
        <local:OffsetKeyTime x:Key="A_KeyTime_Position_In_Begin"
                             KeyTime="{StaticResource A_KeyTime_Gamertag_Transition_Begin}"
                             Offset="0:0:0"/>

        <local:OffsetKeyTime x:Key="A_KeyTime_Position_Entered"
                             KeyTime="{StaticResource A_KeyTime_Gamertag_Transition_Begin}"
                             Offset="0:0:0.3"/>
        
        <local:OffsetKeyTime x:Key="A_KeyTime_Gamertag_Transition_End"
                             KeyTime="{StaticResource A_KeyTime_Position_In_Begin}"
                             Offset="{StaticResource A_TimeSpan_WhooshDuration}" />
        
        <local:OffsetKeyTime x:Key="A_KeyTime_Gamertag_Out_Begin"
                             KeyTime="{StaticResource A_KeyTime_Gamertag_Transition_End}"
                             Offset="{StaticResource A_TimeSpan_PositionDuration}" />


        <System:Double x:Key="A_Double_Gamertag_Offset_Initial">-80</System:Double>
        <System:Double x:Key="A_Double_Gamertag_Offset_Transition_Begin">-65</System:Double>
        <System:Double x:Key="A_Double_Gamertag_Offset_Transition_End">-15</System:Double>
        <System:Double x:Key="A_Double_Gamertag_Offset_Final">0</System:Double>

        <System:Double x:Key="A_Double_BigText_Offset_Initial">0</System:Double>
        <System:Double x:Key="A_Double_BigText_Offset_Transition_Begin">-20</System:Double>
        <System:Double x:Key="A_Double_BigText_Offset_Transition_End">20</System:Double>
        <System:Double x:Key="A_Double_BigText_Offset_Final">0</System:Double>

        <local:UIStoryboard x:Key="A_Storyboard_FinishPosition">
            <local:UIStoryboard.TriggerAnimation>
                <local:BeginUIStoryboard Storyboard="{StaticResource A_Storyboard_PostRace_WhooshInFromLeft}"
                                         Storyboard.TargetName="Gamertag"
                                         local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_Gamertag_In_Begin}"/>
                <local:BeginUIStoryboard Storyboard="{StaticResource A_Storyboard_PostRace_WhooshInFromRight}"
                                         Storyboard.TargetName="Finished"
                                         local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_Finished_In_Begin}" />
                <local:BeginUIStoryboard Storyboard="{StaticResource A_Storyboard_PostRace_WhooshOutToLeft}"
                                         Storyboard.TargetName="Finished"
                                         local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_Finished_Out_Begin}" />
                <local:RaiseFzEvent EventName="GetFinishPosition"
                                    local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_Position_In_Begin}" />
                <local:BeginUIStoryboard Storyboard="{StaticResource A_Storyboard_PostRace_WhooshInFromRight}"
                                         Storyboard.TargetName="Position"
                                         local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_Position_In_Begin}" />
                <local:BeginUIStoryboard Storyboard="{StaticResource A_Storyboard_PostRace_WhooshOutToLeft}"
                                         Storyboard.TargetName="Position"
                                         local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_Gamertag_Out_Begin}" />
                <local:BeginUIStoryboard Storyboard="{StaticResource A_Storyboard_PostRace_WhooshOutToRight}"
                                         Storyboard.TargetName="Gamertag"
                                         local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_Gamertag_Out_Begin}" />
            </local:UIStoryboard.TriggerAnimation>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Video"
                                           Storyboard.TargetProperty="Tag">
                <DiscreteObjectKeyFrame KeyTime="{StaticResource A_KeyTime_PlayVideo}"
                                        Value="SourceSet" />
            </ObjectAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="GamertagSlide"
                                           Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="{StaticResource A_Double_Gamertag_Offset_Initial}" />
                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Gamertag_In_Begin}"
                                        Value="{StaticResource A_Double_Gamertag_Offset_Initial}" />
                <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Gamertag_Transition_Begin}"
                                      Value="{StaticResource A_Double_Gamertag_Offset_Transition_Begin}" />
                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Gamertag_Transition_End}"
                                      Value="{StaticResource A_Double_Gamertag_Offset_Transition_End}"
                                      EasingFunction="{local:QuadraticEasing EasingMode=EaseInOut}" />
                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Gamertag_Out_Begin}"
                                      Value="{StaticResource A_Double_Gamertag_Offset_Final}"
                                      EasingFunction="{local:LinearEasing}"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BigTextSlide"
                                           Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="{StaticResource A_Double_BigText_Offset_Initial}" />
                <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Finished_In_Begin}"
                                        Value="{StaticResource A_Double_BigText_Offset_Initial}" />
                <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Gamertag_Transition_Begin}"
                                      Value="{StaticResource A_Double_BigText_Offset_Transition_Begin}" />
                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Gamertag_Transition_End}"
                                      Value="{StaticResource A_Double_BigText_Offset_Transition_End}"
                                      EasingFunction="{local:LinearEasing}" />
                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_Gamertag_Out_Begin}"
                                      Value="{StaticResource A_Double_BigText_Offset_Final}"
                                      EasingFunction="{local:LinearEasing}" />
            </DoubleAnimationUsingKeyFrames>
        </local:UIStoryboard>



        <Style x:Key="A_Style_FZTextBlock_PostRace_GamertagText"
               TargetType="local:FZTextBlock"
               BasedOn="{StaticResource A_Style_FZTextBlock_HorizonB}">
            <Setter Property="Color"
                    Value="#FFFFFF" />
            <Setter Property="CapHeight"
                    Value="41" />
        </Style>

        <Style x:Key="A_Style_Control_PostRace_Gamertag"
               TargetType="Control"
               BasedOn="{StaticResource A_Style_FrameworkElement_PostRace_TotalLabelBlock}">
            <Setter Property="Tag"
                    Value="{local:Loc InGame.IDS_Total_SubHeading}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Decorator RenderTransform="{StaticResource A_Transform_Italic}"
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center">
                            <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_PostRace_GamertagText}"
                                               Text="{TemplateBinding Tag}"
                                               Effect="{StaticResource A_Effect_HighContrastModeDropShadow_Large}"/>
                        </Decorator>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="local:ZPanel.Transform">
                <Setter.Value>
                    <Transform3DGroup>
                        <RotateTransform3D />
                        <TranslateTransform3D />
                    </Transform3DGroup>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="A_Style_FZTextBlock_PostRace_BigText"
               TargetType="local:FZTextBlock"
               BasedOn="{StaticResource A_Style_FZTextBlock_HorizonA}">
            <Setter Property="Color"
                    Value="#FFFFFF" />
            <Setter Property="CapHeight"
                    Value="108" />
            <Setter Property="Effect"
                    Value="{StaticResource A_Effect_HighContrastModeDropShadow_Large}" />
        </Style>

        <Style x:Key="A_Style_Control_PostRace_BigText"
               TargetType="Control"
               BasedOn="{StaticResource A_Style_FrameworkElement_PostRace_TotalLabelBlock}">
            <Setter Property="Tag"
                    Value="{local:Loc InGame.IDS_Total_SubHeading}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Decorator RenderTransform="{StaticResource A_Transform_Italic}"
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center">
                            <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_PostRace_BigText}"
                                               Text="{TemplateBinding Tag}" />
                        </Decorator>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="local:ZPanel.Transform">
                <Setter.Value>
                    <Transform3DGroup>
                        <RotateTransform3D />
                        <TranslateTransform3D />
                    </Transform3DGroup>
                </Setter.Value>
            </Setter>
        </Style>

        <System:Double x:Key="A_Double_LargeTextSpacerHeight">9</System:Double>
        <System:Double x:Key="A_Double_LargeTextSpacerHeight_CHS">45</System:Double>
    </Page.Resources>
    
    <Grid>
        <local:FZMaterial>
            <local:FZMaterial.Preset>
                <local:FZMaterialPresetRoundtangle
                    GradientColorA="{Binding InfluenceThread.StringID, Converter={StaticResource A_Converter_InfluenceThreadIdToBackgroundGradientA}, FallbackValue=#FF0864CB}"
                    GradientColorB="{Binding InfluenceThread.StringID, Converter={StaticResource A_Converter_InfluenceThreadIdToBackgroundGradientB}, FallbackValue=#FF00C87A}"
                    GradientAngle="90" />
            </local:FZMaterial.Preset>
        </local:FZMaterial>

        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_PostRace_Hatching}" />

        <!-- Intentionally set LoadedBehavior="Play" so the video starts as soon as the source is set -->
        <local:FZMediaElement Preset="{StaticResource A_FZMaterialPresetAdditive}"
                              LoadedBehavior="Play"
                              UnloadedBehavior="Stop"
                              x:Name="Video"
                              Tag="SourceNotSet">
            <FrameworkElement.Style>
                <Style TargetType="local:FZMediaElement">
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsInitialized}" Value="{StaticResource A_Boolean_True}"/>
                                <Condition Binding="{Binding Tag, RelativeSource={RelativeSource Self}}" Value="SourceSet"/>
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Source"
                                    Value="game:/Media/UI/Videos/Finishline_Motion_Graphics.bk2" />
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </FrameworkElement.Style>
        </local:FZMediaElement>

        <!--Whooshy text elements -->
        <Grid RenderTransformOrigin="0.5,0.5">
            <UIElement.RenderTransform>
                <RotateTransform Angle="-6" />
            </UIElement.RenderTransform>

            <StackPanel VerticalAlignment="Center">
                <Decorator x:Name="GamertagSlide">
                    <UIElement.RenderTransform>
                        <TranslateTransform />
                    </UIElement.RenderTransform>

                    <Control x:Name="Gamertag"
                             Style="{StaticResource A_Style_Control_PostRace_Gamertag}"
                             Tag="{Binding LocalUserProfile.FormattedGamertag, Converter={StaticResource A_StringToUpper}, FallbackValue={local:Loc Demo.IDS_E3PostRaceFinishedGamertag}}" />
                </Decorator>
                <Decorator Height="{local:LocalizedResource A_Double_LargeTextSpacerHeight}" />

                <Decorator x:Name="BigTextSlide">
                    <UIElement.RenderTransform>
                        <TranslateTransform />
                    </UIElement.RenderTransform>

                    <Grid>
                        <Control x:Name="Finished"
                                 Margin="20,0,-20,0"
                                 Style="{StaticResource A_Style_Control_PostRace_BigText}"
                                 Tag="{Binding Source={local:Loc InGame.IDS_PostRace_Finished}, Converter={StaticResource A_StringToUpper}}" />
                        <Control x:Name="Position"
                                 Style="{StaticResource A_Style_Control_PostRace_BigText}"
                                 Tag="{Binding FinishPosition, Converter={StaticResource A_StringToUpper}}" />
                    </Grid>
                </Decorator>
            </StackPanel>
        </Grid>

        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_PostRacePanel_Vignette}" />

        <local:FZMaterial x:Name="Glow"
                          Preset="{StaticResource A_FZMaterialPresetAdditive}"
                          ImageSource="/ForzaUI;component/Textures/Data_Bound/PostRace/Glow.png" 
                          Opacity="0"
                          RenderTransformOrigin="0.5,0.5"
                          Width="1716"
                          Height="540"
                          HorizontalAlignment="Center"
                          VerticalAlignment="Center">
            <UIElement.RenderTransform>
                <ScaleTransform />
            </UIElement.RenderTransform>
        </local:FZMaterial>
    </Grid>

    <local:EventFire.FzTriggers>
        <local:BeginUIStoryboard Storyboard="{StaticResource A_Storyboard_FinishPosition}"
                                 local:EventFireTrigger.Event="StartPanelAnimation" />
        <local:RaiseEntityModelEvent local:EventFireTrigger.Event="StartPanelAnimation"
                                     EventName="PostRaceFinishPositionPanel" />
    </local:EventFire.FzTriggers>
</Page>
