<Page xmlns:local="clr-namespace:ForzaUI;assembly="
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      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"
      x:Class="ForzaUI.A_PreRaceEventInfo"
      DataContext="{Binding RelativeSource={RelativeSource Self}}"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}">

    <local:UIPageTransitionManager.TransitionManager>
        <local:UIPageTransitionManager>
            <local:UIPageTransitionManager.Preset>
                <local:UIPageTransitionManagerPreset>
                    <local:UIPageTransitionManagerPreset.TransitionInForwards>
                        <local:UIPageTransition x:Name="PART_TransitionIn" TransitionName="transition_in_0" />
                    </local:UIPageTransitionManagerPreset.TransitionInForwards>
                </local:UIPageTransitionManagerPreset>
            </local:UIPageTransitionManager.Preset>
        </local:UIPageTransitionManager>
    </local:UIPageTransitionManager.TransitionManager>

    <Page.Resources>
        <!-- 
        There are multiple animations to look good with long and short strings. Transition0 is for shorter, Transition1 is for longer, etc.

        The PART_Int32_TransitionVariationCount defines how many animation variations there are.
        PART_Int32_MaxCharLength_Transition0 defines the max number of characters to use transition_in_0 up to, ..Transition1 etc.

        There is also a hidden text element set to the maximum size to force a viewbox to shrink down all the content in exceptional circumstances.
        -->
        <System:Int32 x:Key="PART_Int32_TransitionVariationCount">2</System:Int32>

        <System:Int32 x:Key="PART_Int32_MaxCharLength_Transition0">20</System:Int32>

        <Style x:Key="A_Style_Animations"
               TargetType="{x:Type FrameworkElement}">
            <Style.Resources>
                <KeyTime x:Key="A_KeyTime_ShowStart">0:0:0.5</KeyTime>
                <KeyTime x:Key="A_KeyTime_ShowEnd">0:0:1.0</KeyTime>
                <KeyTime x:Key="A_KeyTime_HideStart">0:0:3.5</KeyTime>
                <KeyTime x:Key="A_KeyTime_HideEnd">0:0:4.0</KeyTime>

                <System:Double x:Key="A_Double_Line2StartTrackingAdjust_Transition0">0.1</System:Double>
                <System:Double x:Key="A_Double_Line2FinalTrackingAdjust_Transition0">0.21</System:Double>
                <System:Double x:Key="A_Double_Line2FinalScale_Transition0">1.08</System:Double>

                <local:UIStoryboard x:Key="transition_in_0">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="TextContainer">
                        <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
                        <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_ShowStart}" Value="0"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_ShowEnd}" Value="1"/>
                        <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideStart}" Value="1"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideEnd}" Value="0"/>
                    </DoubleAnimationUsingKeyFrames>                    
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="TextScaler">
                        <DiscreteDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideEnd}" Value="1.08"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="TextScaler">
                        <DiscreteDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideEnd}" Value="1.08"/>
                    </DoubleAnimationUsingKeyFrames>
                
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="TrackingAdjust" Storyboard.TargetName="Line1Text">
                        <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_ShowStart}" Value="0.15"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideEnd}" Value="0.25"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="TrackingAdjust" Storyboard.TargetName="Line2Text">
                        <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_ShowStart}" Value="{StaticResource A_Double_Line2StartTrackingAdjust_Transition0}"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideEnd}" Value="{StaticResource A_Double_Line2FinalTrackingAdjust_Transition0}"/>
                    </DoubleAnimationUsingKeyFrames>
                    
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="FinalStateTextScaler">
                        <LinearDoubleKeyFrame KeyTime="0:0:0" Value="{StaticResource A_Double_Line2FinalScale_Transition0}"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="TrackingAdjust" Storyboard.TargetName="FinalStateLine2Text">
                        <LinearDoubleKeyFrame KeyTime="0:0:0" Value="{StaticResource A_Double_Line2FinalTrackingAdjust_Transition0}"/>
                    </DoubleAnimationUsingKeyFrames>    
                </local:UIStoryboard>     

                <System:Double x:Key="A_Double_Line2StartTrackingAdjust_Transition1">0.08</System:Double>
                <System:Double x:Key="A_Double_Line2FinalTrackingAdjust_Transition1">0.16</System:Double>
                <System:Double x:Key="A_Double_Line2FinalScale_Transition1">1.03</System:Double>

                <local:UIStoryboard x:Key="transition_in_1">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="TextContainer">
                        <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
                        <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_ShowStart}" Value="0"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_ShowEnd}" Value="1"/>
                        <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideStart}" Value="1"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideEnd}" Value="0"/>
                    </DoubleAnimationUsingKeyFrames>                    
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="TextScaler">
                        <DiscreteDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideEnd}" Value="{StaticResource A_Double_Line2FinalScale_Transition1}"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="TextScaler">
                        <DiscreteDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideEnd}" Value="{StaticResource A_Double_Line2FinalScale_Transition1}"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="TrackingAdjust" Storyboard.TargetName="Line1Text">
                        <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_ShowStart}" Value="0.15"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideEnd}" Value="0.2"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="TrackingAdjust" Storyboard.TargetName="Line2Text">
                        <DiscreteDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_ShowStart}" Value="{StaticResource A_Double_Line2StartTrackingAdjust_Transition1}"/>
                        <LinearDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_HideEnd}" Value="{StaticResource A_Double_Line2FinalTrackingAdjust_Transition1}"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="FinalStateTextScaler">
                        <LinearDoubleKeyFrame KeyTime="0:0:0" Value="{StaticResource A_Double_Line2FinalScale_Transition1}"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="TrackingAdjust" Storyboard.TargetName="FinalStateLine2Text">
                        <LinearDoubleKeyFrame KeyTime="0:0:0" Value="{StaticResource A_Double_Line2FinalTrackingAdjust_Transition1}"/>
                    </DoubleAnimationUsingKeyFrames>  
                </local:UIStoryboard>
            </Style.Resources>

            <Setter Property="local:UIPageTransitionManager.TransitionIndex"
                    Value="0" />
        </Style>

        <Style x:Key="A_Style_FZTextBlock_LineBase"
               TargetType="{x:Type local:FZTextBlock}">
            <Setter Property="LineAdjust" Value="0"/>
            <Setter Property="Color" Value="#E5E5E5" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="TextAlignment" Value="Center" />
            <Setter Property="MaxWidth" Value="1700" />
        </Style>

        <Style x:Key="A_Style_FZTextBlock_Line1"
               TargetType="{x:Type local:FZTextBlock}"
               BasedOn="{StaticResource A_Style_FZTextBlock_LineBase}">
            <Setter Property="FontFamily" Value="Horizon_C"/>
            <Setter Property="CapHeight" Value="28" />
            <Setter Property="TrackingAdjust" Value="0.23" />
        </Style>

        <Style x:Key="A_Style_FZTextBlock_Line2"
               TargetType="{x:Type local:FZTextBlock}"
               BasedOn="{StaticResource A_Style_FZTextBlock_LineBase}">
            <Setter Property="FontFamily" Value="Horizon_E"/>
            <Setter Property="CapHeight" Value="47" />
            <Setter Property="TrackingAdjust" Value="0.2" />
        </Style>

        <ControlTemplate x:Key="A_ControlTemplate_Story11">
            <local:FZMaterial x:Name="Story11_Logo"
                ImageSource="/ForzaUI;component/Textures/Data_Bound\Series11\Story11\Story11_PreRaceLogo.png" 
                Stretch="Uniform" StretchDirection="DownOnly" GreedyMeasure="True"/>
        </ControlTemplate>

        <local:MappingConverter x:Key="A_MappingConverter_Bool_IsOveride_From_OverrideId" Default="{StaticResource A_Boolean_False}">
            <local:MappingConverterEntry Key="story_11" Value="{StaticResource A_Boolean_True}"/>
        </local:MappingConverter>

        <local:MappingConverter x:Key="A_MappingConverter_ToplineTemplate_From_OverrideId" Default="{x:Null}">
            <local:MappingConverterEntry Key="story_11" Value="{StaticResource A_ControlTemplate_Story11}"/>
        </local:MappingConverter>

        <local:MultiConverter x:Key="A_Converter_Hide_If_Overridden" ConvertNullValues="True">
            <local:MultiConverterEntry Converter="{StaticResource A_MappingConverter_Bool_IsOveride_From_OverrideId}" />
            <local:MultiConverterEntry Converter="{StaticResource A_FZBooleanToVisibilityConverter_Inverse}" />
        </local:MultiConverter>

        <Style x:Key="A_Style_Control_Override_TopLine" TargetType="Control">
            <Setter Property="Visibility" Value="Collapsed"/>
            <Setter Property="Template" Value="{x:Null}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding TopLineOverrideId, Converter={StaticResource A_MappingConverter_Bool_IsOveride_From_OverrideId}}" Value="{StaticResource A_Boolean_True}">
                    <Setter Property="Visibility" Value="Visible"/>
                    <Setter Property="Template" Value="{Binding TopLineOverrideId, Converter={StaticResource A_MappingConverter_ToplineTemplate_From_OverrideId}}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Page.Resources>

    <Grid x:Name="LayoutRoot">

        <Grid Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}">
            <Viewbox Style="{StaticResource A_Style_Animations}"
                     StretchDirection="DownOnly"
                     VerticalAlignment="Center"
                     HorizontalAlignment="Center"
                     Margin="30,0,30,0">
                <Grid x:Name="TextContainer"
                        Margin="0,10,0,-10"
                        Opacity="0" 
                        RenderTransformOrigin="0.5,0.5">
                    <Grid.RenderTransform>
                        <ScaleTransform x:Name="TextScaler" />
                    </Grid.RenderTransform>

                    <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Anthem/Gradients/PreEventShadow.png" Opacity="{StaticResource A_Double_PreRaceIntro_UnderlayOpacity}" RenderTransformOrigin="0.5,0.5">
                        <local:FZMaterial.RenderTransform>
                            <ScaleTransform ScaleX="1.5" ScaleY="4.5" />
                        </local:FZMaterial.RenderTransform>
                    </local:FZMaterial>

                    <StackPanel>
                        <Decorator>
                            <local:FZTextBlock x:Name="Line1Text"
                                               Visibility="{Binding TopLineOverrideId, Converter={StaticResource A_Converter_Hide_If_Overridden}, FallbackValue=Visible}"
                                               Text="{Binding Line1, Converter={StaticResource A_StringToUpper}}"
                                               Style="{StaticResource A_Style_FZTextBlock_Line1}" />
                        </Decorator>
                        <Control Style="{StaticResource A_Style_Control_Override_TopLine}" />
                        <Decorator Height="22" />
                        <Decorator RenderTransformOrigin="0.5,0.5">
                            <Decorator.RenderTransform>
                                <ScaleTransform ScaleX="1.25" ScaleY="1.0" />
                            </Decorator.RenderTransform>
                            <local:FZTextBlock x:Name="Line2Text"
                                               Text="{Binding Line2, Converter={StaticResource A_StringToUpper}}"
                                               Style="{StaticResource A_Style_FZTextBlock_Line2}" />
                        </Decorator>
                    </StackPanel>

                    <Decorator Visibility="Hidden">
                        <Decorator.LayoutTransform>
                            <TransformGroup>
                                <ScaleTransform x:Name="FinalStateTextScaler" /> 
                                <ScaleTransform ScaleX="1.25" ScaleY="1.0" />
                            </TransformGroup>
                        </Decorator.LayoutTransform>
                        <local:FZTextBlock x:Name="FinalStateLine2Text"
                                           Text="{Binding Text, ElementName=Line2Text}"
                                           Color="#FF0000"
                                           Style="{StaticResource A_Style_FZTextBlock_Line2}"/>
                    </Decorator>
                </Grid>
            </Viewbox>
        </Grid>

        <ContentControl x:Name="BottomBar"
                        Style="{StaticResource A_Style_ButtonBar}">
            <local:ControllerButtonPanel x:Name="HelpPanel"
                                         Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <local:ControllerButtonControl Button="A"
                                               Description="{local:Loc HelpButtons.IDS_Skip}"
                                               Visibility="{Binding CanSkip, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}" />
            </local:ControllerButtonPanel>
        </ContentControl>
    </Grid>
</Page>
